我在wordpress中注册自定义程序函数时尝试使用PHP命名空间,我的文件名是'customizer.php',它包含在functions.php中。我通过自定义程序上传徽标,它会出现以下错误
“致命错误:在customizer.php中找不到类'Roots \ Sage \ Customizer \ WP_Customize_Upload_Control'”
这是我正在使用的代码。
namespace Roots\Sage\Customizer;
add_action('customize_register',__NAMESPACE__.'\\sageCustomizeRegister');
function sageCustomizeRegister( $wp_customize ) {
$wp_customize->add_setting( 'site_logo', [
'type' => 'theme_mod',
'default' => NULL,
] );
$wp_customize->add_control(
new WP_Customize_Upload_Control(
$wp_customize,
'site_logo',
[
'label' => __( 'Site Logo', 'sage' ),
'section' => 'title_tagline',
'description' => 'Please upload site logo to show in header'
] )
);
}
请指导我如何解决此问题。
答案 0 :(得分:4)
你遇到的问题是这一行:
public ActionResult userrights()
{
IEnumerable<MenuListModel> _MenuListModel = _ftwCommonMethods.GetMenuItems();
IEnumerable<SubMenuListModel> _SubMenuListModel = _ftwCommonMethods.GetSubMenuItems("1");
UserRightViewSearch _UserRightViewSearch = new UserRightViewSearch();
UserRightPartialView _UserRightPartialView = new UserRightPartialView();
_UserRightPartialView._SubMenuListModel = _SubMenuListModel;
_UserRightViewSearch._UserRightPartialView = _UserRightPartialView;
_UserRightViewSearch._menu = _MenuListModel;
_UserRightViewSearch.selectedMenu = 0;
return View(_UserRightViewSearch);
}
文件顶部的命名空间意味着您要实例化一个不存在的类。它相当于:
new WP_Customize_Upload_Control(
您需要在全局空间中引用该类。只需在您使用反斜杠调用的课程前加上前缀。
new \Roots\Sage\Customizer\WP_Customize_Upload_Control(