【问题标题】:Fatal error: Call to undefined function when deactivate the plugin致命错误:停用插件时调用未定义的函数
【发布时间】:2016-04-28 23:37:09
【问题描述】:

我有以下代码供 php 管理员使用。这段代码放在我的 WordPress 主题上,与一个插件有关:

$custom_css_style = mytheme_custom_css();
/* Enqueue The Font CSS */
$custom_font_css_style = upfw_enqueue_font_css();
//add custom style
wp_add_inline_style( 'main-stylesheet', $custom_css_style );
wp_add_inline_style( 'main-stylesheet', $custom_font_css_style );

一切正常,但当插件停用时,我收到 2 个错误:

致命错误:在第 198 行调用 D:\mytheme\SERVER-mytheme\InstantWP_4.3.1\iwpserver\htdocs\wordpress\wp-content\themes\mytheme\library\bones.php 中的未定义函数 upfw_enqueue_font_css()

第 198 行是:

 $custom_font_css_style = upfw_enqueue_font_css();

第二个通知:

注意:未定义变量:第 201 行 D:\mytheme\SERVER-mytheme\InstantWP_4.3.1\iwpserver\htdocs\wordpress\wp-content\themes\mytheme\library\bones.php 中的 custom_font_css_style

第 201 行是:

wp_add_inline_style( 'main-stylesheet', $custom_font_css_style );

需要一个想法和帮助来解决我的问题。

感谢您的帮助。

问候

【问题讨论】:

    标签: wordpress function plugins


    【解决方案1】:

    我认为你只需要在做更多事情之前检查该函数是否存在。

    所以示例代码可以是:

    $custom_css_style = mytheme_custom_css();
    
    //add custom style
    wp_add_inline_style( 'main-stylesheet', $custom_css_style );
    
    /* Enqueue The Font CSS */
    if( function_exists('upfw_enqueue_font_css') )
    {
        $custom_font_css_style = upfw_enqueue_font_css();
        wp_add_inline_style( 'main-stylesheet', $custom_font_css_style );
    }
    

    希望这是有道理的。

    【讨论】:

    • 我之前尝试过 condition 和 isset 但失败了。我到家时会试试你的想法,@tuongpg.jz。谢谢。
    • 听你这么说真是太好了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 2012-07-18
    相关资源
    最近更新 更多