首页 文章

当需要文件时,写入路径的方式会影响WordPress功能的可用性

提问于
浏览
0

我在我的WordPress主题中使用 WPAlchemy 类,我已将其移动到主题文件夹中(作者指示用户将其放在内容目录中,但我希望它在主题文件夹中) .

当我以这种方式包含文件时,一切都按预期工作:

require_once WP_CONTENT_DIR . '/themes/efs/inc/metaboxes/wpalchemy/MetaBox.php';

但如果我将声明改为:

require_once get_template_directory_uri() . '/inc/metaboxes/wpalchemy/MetaBox.php';

该文件加载正常,但在文件 MetaBox.php 中的 add_action() 上抛出"undefined function"错误 .

为什么我写URL的方式会影响WordPress功能的可用性?

2 回答

  • 0

    我不知道答案,但我会用echo语句打印两个路径:

    echo WP_CONTENT_DIR . '/themes/efs/inc/metaboxes/wpalchemy/MetaBox.php';
    
    echo get_template_directory_uri() . '/inc/metaboxes/wpalchemy/MetaBox.php';
    

    我确信两个字符串都不同 .

  • 0

    如果你在uri / url上使用require_once,那么你需要设置php.ini

    ; Whether to allow include/require to open 
    ; URLs (like http:// or ftp://) as files.
    ; @SEE http://php.net/allow-url-include
    allow_url_include = On
    

    默认情况下它是关闭的(有充分理由)

相关问题