admin管理员组文章数量:1023571
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
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
-
2
was the function formerly named
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 - Thank you, for some reason it was looking for both set_page_default_template and set_default_page_template. I just made an empty function for the opposite that wont be called. – Tyler Commented Jul 26, 2018 at 19:42
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
本文标签: Error in custom php function doesn39t exist
版权声明:本文标题:Error in custom php function doesn't exist 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745514017a2153956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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