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
|
1 Answer
Reset to default 0I 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
版权声明:本文标题:actions - add_action init breaks site on PHP 7.1 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736297996a1930132.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$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