admin管理员组

文章数量:1122846

If there's no child theme available, I use a custom plugin for some minor changes. The following code for hiding update notifications etc. has always worked perfectly. However, if I switch from PHP 7.0 to 7.1 it breaks the site. This is true even in my test installation with no other plugins activated and the latest Twenty17 theme. I can't figure out the problem. Any ideas? Thank you!

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' );

This is what the WP error log says:

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

If there's no child theme available, I use a custom plugin for some minor changes. The following code for hiding update notifications etc. has always worked perfectly. However, if I switch from PHP 7.0 to 7.1 it breaks the site. This is true even in my test installation with no other plugins activated and the latest Twenty17 theme. I can't figure out the problem. Any ideas? Thank you!

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' );

This is what the WP error log says:

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
Share Improve this question edited May 25, 2018 at 12:36 user2516117 asked May 25, 2018 at 11:41 user2516117user2516117 771 silver badge8 bronze badges 2
  • You must be getting an error somewhere. What does it say? Check the error log if it doesn't appear on screen. – Jacob Peattie Commented May 25, 2018 at 11:43
  • In your context have the var $plugins no handover. The hook init haven't any parameter and is not clear how to set the var $plugins. In php7 need the parameter in the function a default value there you can set in the function or you add them on the call of the function. – bueltge Commented May 25, 2018 at 13:10
Add a comment  | 

1 Answer 1

Reset to default 0

I changed the master function to:

function master() {
    updates();
    remove_core_updates();
    hide_plugins($plugins);
    nstrm_remove_admin_submenus();
}

Now it works. Is this the right way to to it?

本文标签: actionsaddaction init breaks site on PHP 71