我使用名称空间和自动加载编写了一个WP主题。在我开始使用WP类之前,一切都很顺利,我当然理解WP类,因为我了解名称空间是如何工作的。我的问题是,有没有一种方法可以在我的主题类中使用Wordpress类,例如我想使用$wp_customize
, 的实例WP_Customize_Manager
? 我如何做到这一点,保持我的OOP主题结构。
UPDATE:
多亏了帕特·J,我才解决了这个问题。它工作得很好,看起来是这样的:
class ColorController extends BaseController
{
public function register()
{
add_action(\'customize_register\', array($this, \'theme_customize_register\'));
}
public function theme_customize_register($wp_customize)
{
// Text color
$wp_customize->add_setting(\'text_color\', array(
\'default\' => \'\',
\'transport\' => \'refresh\',
));
$wp_customize->add_control(new \\WP_Customize_Color_Control($wp_customize, \'text_color\', array(
\'section\' => \'colors\',
\'label\' => esc_html__(\'Text color\', \'theme\'),
)));
// Link color
$wp_customize->add_setting(\'link_color\', array(
\'default\' => \'\',
\'transport\' => \'refresh\',
\'sanitize_callback\' => \'sanitize_hex_color\',
));
$wp_customize->add_control(new \\WP_Customize_Color_Control($wp_customize, \'link_color\', array(
\'section\' => \'colors\',
\'label\' => esc_html__(\'Link color\', \'theme\'),
)));
// Accent color
$wp_customize->add_setting(\'accent_color\', array(
\'default\' => \'\',
\'transport\' => \'refresh\',
\'sanitize_callback\' => \'sanitize_hex_color\',
));
$wp_customize->add_control(new \\WP_Customize_Color_Control($wp_customize, \'accent_color\', array(
\'section\' => \'colors\',
\'label\' => esc_html__(\'Accent color\', \'theme\'),
)));
// Border color
$wp_customize->add_setting(\'border_color\', array(
\'default\' => \'\',
\'transport\' => \'refresh\',
\'sanitize_callback\' => \'sanitize_hex_color\',
));
$wp_customize->add_control(new \\WP_Customize_Color_Control($wp_customize, \'border_color\', array(
\'section\' => \'colors\',
\'label\' => esc_html__(\'Border color\', \'theme\'),
)));
// Sidebar background
$wp_customize->add_setting(\'sidebar_background\', array(
\'default\' => \'\',
\'transport\' => \'refresh\',
\'sanitize_callback\' => \'sanitize_hex_color\',
));
$wp_customize->add_control(new \\WP_Customize_Color_Control($wp_customize, \'sidebar_background\', array(
\'section\' => \'colors\',
\'label\' => esc_html__(\'Sidebar Background\', \'theme\'),
)));
}
}