I was able to successfully set the default page template for a new page, when there is not yet a defined template to be member_home_page.php.
This works perfectly on my local environment but when I uploaded the code to my site on WP Engine I get this error at the top of the admin page edit screen for WordPress.
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'set_default_page_template' not found or invalid function name in /nas/content/staging/pmbus/wp-includes/class-wp-hook.php on line 288
Both on local and live deployments the function works. But on local I don't get the error, only live. Below is the function, i'm just not sure why i'm getting this warning only on live. Thanks in advance.
function set_page_template_default() {
global $post;
if ( 'page' == $post->post_type
&& 0 != count( get_page_templates( $post ) )
&& get_option( 'page_for_posts' ) != $post->ID // Not the page for listing posts
&& '' == $post->page_template // Only when page_template is not set
) {
$post->page_template = 'member_home_page.php';
}
}
add_action('add_meta_boxes', 'set_page_template_default', 1);
I was able to successfully set the default page template for a new page, when there is not yet a defined template to be member_home_page.php.
This works perfectly on my local environment but when I uploaded the code to my site on WP Engine I get this error at the top of the admin page edit screen for WordPress.
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'set_default_page_template' not found or invalid function name in /nas/content/staging/pmbus/wp-includes/class-wp-hook.php on line 288
Both on local and live deployments the function works. But on local I don't get the error, only live. Below is the function, i'm just not sure why i'm getting this warning only on live. Thanks in advance.
function set_page_template_default() {
global $post;
if ( 'page' == $post->post_type
&& 0 != count( get_page_templates( $post ) )
&& get_option( 'page_for_posts' ) != $post->ID // Not the page for listing posts
&& '' == $post->page_template // Only when page_template is not set
) {
$post->page_template = 'member_home_page.php';
}
}
add_action('add_meta_boxes', 'set_page_template_default', 1);
Share
Improve this question
edited May 8, 2019 at 7:00
Vishwa
3762 silver badges17 bronze badges
asked Jul 26, 2018 at 17:36
TylerTyler
1031 gold badge2 silver badges6 bronze badges
2
|
1 Answer
Reset to default 0You get an error because it's looking for function named as set_default_page_template
while you seems to have function named set_page_template_default
.
I'm not sure you either don't have a function named set_default_page_template
or you later renamed it. but that's the error. WP cannot find your hook because it doesn't exist.
you should either rename your set_default_page_template
to set_default_page_template
(if this is the function what you need) or you should create a new function and name it as set_default_page_template
set_default_page_template
, then you changed it toset_page_template_default
? I'm guessing here: but if thats the case, WPEngine is likely showing you a cache of the old error. These 'dedicated WP hosts' have really good cache's, ensure they're off while developing for less headaches. – David Sword Commented Jul 26, 2018 at 19:24