How to call a WP Class inside my theme
I wrote a WP theme using namespaces and autoload. Everything went smooth until I started to use WP classes which I understand of course because I understand how namespacing works.
My question is, is there a way possible to use a Wordpress class inside one of my theme classes, for example I want to use $wp_customize
, an instance of WP_Customize_Manager
? How would I achieve that, keeping my OOP theme structure.
UPDATE:
Thanks to Pat J. I was able to solve it. It works perfectly and this is how it looks like:
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'),
)));
}
}
Topic namespace autoloading settings-api php Wordpress
Category Web