如何解决PHP 弃用:非静态方法 RestrictAllowedPlugins::filter() 不应在第 292
使用 PHP 7.4.21,wordpress core5.7.2。找到弃用警告提到的两段代码,但为什么会出现问题以及如何解决?
$value = call_user_func_array( $the_['function'],$args );
这是第 292 行 class-wp-hook.PHP 的片段......
// Avoid the array_slice() if possible.
if ( 0 == $the_['accepted_args'] ) {
$value = call_user_func( $the_['function'] );
} elseif ( $the_['accepted_args'] >= $num_args ) {
$value = call_user_func_array( $the_['function'],$args );
} else {
$value = call_user_func_array( $the_['function'],array_slice( $args,(int) $the_['accepted_args'] ) );
}
RestrictAllowedplugins 插件的问题过滤功能在这里:
if( !class_exists('RestrictAllowedplugins') ) {
class RestrictAllowedplugins {
function filter($plugins) {
if( current_user_can( 'manage_network_plugins' ) ) // disable restrictions for network admins
return $plugins;
$allowed_plugins = get_site_option( 'allowedplugins' );
if( !is_array( $allowed_plugins ) )
return $plugins;
unset( $plugins[ plugin_basename(__FILE__) ] );
foreach( array_keys($plugins) as $key ) {
$plugin_key = str_replace( '/',':',$key );
if( !isset( $allowed_plugins[ $plugin_key ] ) )
unset( $plugins[ $key ] );
}
return $plugins;
}
这是一个带有回调的过滤器:
add_filter( 'all_plugins',array('RestrictAllowedplugins','filter') );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。