最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Error in custom php function doesn't exist

programmeradmin0浏览0评论

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 to set_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
Add a comment  | 

1 Answer 1

Reset to default 0

You 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

发布评论

评论列表(0)

  1. 暂无评论