在PHP 7.1上添加操作初始化中断站点

时间:2018-05-25 作者:user2516117

如果没有可用的子主题,我会使用自定义插件进行一些小的更改。以下用于隐藏更新通知等的代码始终运行良好。然而,如果我从PHP 7.0切换到7.1,就会破坏网站。即使在没有激活其他插件和最新的2017主题的情况下,我的测试安装也是如此。我想不出这个问题。有什么想法吗?非常感谢。

function remove_core_updates() {
  global $wp_version;return(object) array(\'last_checked\'=> time(),\'version_checked\'=> $wp_version,);
}
function nstrm_remove_admin_submenus() {
  remove_submenu_page( \'options-general.php\', \'mainwp_child_tab\' );
}
function hide_plugins($plugins) {
  if(is_plugin_active(\'mainwp-child/mainwp-child.php\')) {
    unset( $plugins[\'mainwp-child/mainwp-child.php\'] );
  }
  return $plugins;
}
function updates() {    
  $current_user = wp_get_current_user();
  if (\'user-x\' != $current_user->user_login) {
    add_filter(\'pre_site_transient_update_core\', \'remove_core_updates\');
    add_filter(\'pre_site_transient_update_plugins\', \'remove_core_updates\');
    add_filter(\'pre_site_transient_update_themes\', \'remove_core_updates\');
    add_filter( \'all_plugins\', \'hide_plugins\');
    add_action( \'admin_menu\', \'nstrm_remove_admin_submenus\', 999 );
    }
}
function master() {
    updates();
    remove_core_updates();
    hide_plugins();
    nstrm_remove_admin_submenus();
}
add_action( \'init\', \'master\' );
WP错误日志是这样说的:

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function hide_plugins(), 0 passed in /www/htdocs/w0131417/wp-content/plugins/myplugins2.php on line 74 and exactly 1 expected in /www/htdocs/w0131417/wp-content/plugins/myplugins2.php:55
Stack trace:
#0 /www/htdocs/w0131417/wp-content/plugins/myplugins2.php(74): hide_plugins()
#1 /www/htdocs/w0131417/wp-includes/class-wp-hook.php(286): master(\'\')
#2 /www/htdocs/w0131417/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#3 /www/htdocs/w0131417/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#4 /www/htdocs/w0131417/wp-settings.php(450): do_action(\'init\')
#5 /www/htdocs/w0131417/wp-config.php(61): require_once(\'/www/htdocs/w01...\')
#6 /www/htdocs/w0131417/wp-load.php(37): require_once(\'/www/htdocs/w01...\')
#7 /www/htdocs/w0131417/wp-blog-header.php(13): require_once(\'/www/htdocs/w01...\')
#8 /www/htdocs/w0131417/index.php(17): require(\'/www/htdocs/w01...\')
#9 {main}
  thrown in /www/htdocs/w0131417/wp-content/plugins/myplugins2.php on line 55

1 个回复
SO网友:user2516117

我将主功能更改为:

function master() {
    updates();
    remove_core_updates();
    hide_plugins($plugins);
    nstrm_remove_admin_submenus();
}
现在它工作了。这是去的路吗?

结束

相关推荐

自定义设置字段值在Add_action init挂接中不起作用

我已经在WordPress设置下添加了自定义设置选项页面,这些设置工作得很好。我也测试了他们的价值观。但当我在add\\u action init hook中的函数文件中使用这些值来执行表单提交时,这些值返回为null。除了那些返回为null的值外,其他一切都正常。举几个例子对我很有帮助!提前感谢:) add_action(\'init\', \'myFunc\'); function myFunc(){ $myoptions = get_option(