正如@hrsetyono所说,插件可以注册任何主题可以注册的内容,包括小部件边栏。
然而,我们不建议使用匿名闭包函数,因为这不能被其他插件删除-而是使用公共函数(挂钩到公共类方法也可以)。
add_action( \'widgets_init\', \'wpse_381433_widget\', 10 );
function wpse_381433_widget(){
register_sidebar([
\'name\' => \'Your Sidebar\',
\'id\' => \'your-sidebar\',
]);
};
还请注意,您应该尝试向其他人可能希望使用的所有值添加过滤器
apply_filters - 这为其他插件提供了一条干净的路径来更改值,而无需更改插件代码。
例如:
// assign variable value ##
$number = 10;
// allow value to be filtered ##
$number = apply_filters( \'plugin/function/variable\', $number );
https://developer.wordpress.org/reference/functions/apply_filters/