I'm using WAMP on Windows 8.1 64 bits to develop a custom theme.
Right now, I'm getting the following errors when trying to create a custom control with the WP_Customize_Image_Control
class:
Fatal error: Uncaught Error: Class 'Ivana\Api\Customizer\WP_Customize_Image_Control' not found in C:\wamp64\www\ivana-5.2\wp-content\themes\ivana\inc\Api\Customizer\FeaturedCategories.php on line 115
Error: Class 'Ivana\Api\Customizer\WP_Customize_Image_Control' not found in C:\wamp64\www\ivana-5.2\wp-content\themes\ivana\inc\Api\Customizer\FeaturedCategories.php on line 115
I'm using an object oriented design, got from this starter theme:
inc/Api/Customizer.php namespace Ivana\Api;
class Customizer
{
public function register()
{
add_action( 'customize_register', [ $this, 'setup' ] );
}
public function get_classes()
{
return [
Customizer\FeaturedCategories::class
];
}
public function setup( $wp_customize )
{
foreach ( $this->get_classes() as $class )
{
if ( method_exists( $class, 'register' ) )
{
$service = new $class;
$service->register( $wp_customize );
}
}
}
}
inc/Api/Customizer/FeaturedCategories.php
namespace Ivana\Api\Customizer;
use Ivana\Helpers;
class FeaturedCategories
{
public function register( $wp_customize )
{
$this->add_panels( $wp_customize );
$this->add_sections( $wp_customize );
$this->add_settings( $wp_customize );
$this->add_controls( $wp_customize );
}
private function add_panels( $wp_customize )
{
$wp_customize->add_panel( 'featured_categories', [
'title' => 'Featured Categories',
'description' => 'I\'m looking for a good placeholder',
'priority' => 100
] );
}
private function add_sections( $wp_customize )
{
$wp_customize->add_section( 'featured_category_0', [
'title' => 'Featured Category 1',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
$wp_customize->add_section( 'featured_category_1', [
'title' => 'Featured Category 2',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
$wp_customize->add_section( 'featured_category_2', [
'title' => 'Featured Category 3',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
}
private function add_settings( $wp_customize )
{
$wp_customize->add_setting( 'category_slug_0', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_slug_1', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_slug_2', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_0', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_1', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_2', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
}
private function add_controls( $wp_customize )
{
// var_dump( $wp_customize );
// echo $wp_customize->registered_control_types;
$wp_customize->add_control( 'category_slug_2', [
'section' => 'featured_category_0',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( 'category_slug_1', [
'section' => 'featured_category_1',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( 'category_slug_0', [
'section' => 'featured_category_2',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'category_image_2', [
'section' => 'featured_category_0',
'label' => 'Featured Category Image 1'
] ) );
}
}
Why is WordPress unable to find the WP_Customize_Image_Control
class, or any of those classes, for that matter? (Also tried with color and media with no success).
If you see Customizer.php, the register method is calling the 'customize_register'
action, and setup receives $wp_customize.
This works perfectly if not trying to use custom controls.
I'm using WAMP on Windows 8.1 64 bits to develop a custom theme.
Right now, I'm getting the following errors when trying to create a custom control with the WP_Customize_Image_Control
class:
Fatal error: Uncaught Error: Class 'Ivana\Api\Customizer\WP_Customize_Image_Control' not found in C:\wamp64\www\ivana-5.2\wp-content\themes\ivana\inc\Api\Customizer\FeaturedCategories.php on line 115
Error: Class 'Ivana\Api\Customizer\WP_Customize_Image_Control' not found in C:\wamp64\www\ivana-5.2\wp-content\themes\ivana\inc\Api\Customizer\FeaturedCategories.php on line 115
I'm using an object oriented design, got from this starter theme: https://github.com/Alecaddd/awps
inc/Api/Customizer.php namespace Ivana\Api;
class Customizer
{
public function register()
{
add_action( 'customize_register', [ $this, 'setup' ] );
}
public function get_classes()
{
return [
Customizer\FeaturedCategories::class
];
}
public function setup( $wp_customize )
{
foreach ( $this->get_classes() as $class )
{
if ( method_exists( $class, 'register' ) )
{
$service = new $class;
$service->register( $wp_customize );
}
}
}
}
inc/Api/Customizer/FeaturedCategories.php
namespace Ivana\Api\Customizer;
use Ivana\Helpers;
class FeaturedCategories
{
public function register( $wp_customize )
{
$this->add_panels( $wp_customize );
$this->add_sections( $wp_customize );
$this->add_settings( $wp_customize );
$this->add_controls( $wp_customize );
}
private function add_panels( $wp_customize )
{
$wp_customize->add_panel( 'featured_categories', [
'title' => 'Featured Categories',
'description' => 'I\'m looking for a good placeholder',
'priority' => 100
] );
}
private function add_sections( $wp_customize )
{
$wp_customize->add_section( 'featured_category_0', [
'title' => 'Featured Category 1',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
$wp_customize->add_section( 'featured_category_1', [
'title' => 'Featured Category 2',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
$wp_customize->add_section( 'featured_category_2', [
'title' => 'Featured Category 3',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
}
private function add_settings( $wp_customize )
{
$wp_customize->add_setting( 'category_slug_0', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_slug_1', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_slug_2', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_0', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_1', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_2', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
}
private function add_controls( $wp_customize )
{
// var_dump( $wp_customize );
// echo $wp_customize->registered_control_types;
$wp_customize->add_control( 'category_slug_2', [
'section' => 'featured_category_0',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( 'category_slug_1', [
'section' => 'featured_category_1',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( 'category_slug_0', [
'section' => 'featured_category_2',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'category_image_2', [
'section' => 'featured_category_0',
'label' => 'Featured Category Image 1'
] ) );
}
}
Why is WordPress unable to find the WP_Customize_Image_Control
class, or any of those classes, for that matter? (Also tried with color and media with no success).
If you see Customizer.php, the register method is calling the 'customize_register'
action, and setup receives $wp_customize.
This works perfectly if not trying to use custom controls.
Solved by adding use WP_Customize_Image_Control;
to inc\Customizer\FeaturedCategories.php:
namespace Ivana\Api\Customizer;
use WP_Customize_Image_Control;
use Ivana\Helpers;
class FeaturedCategories
{
public function register( $wp_customize )
{
$this->add_panels( $wp_customize );
$this->add_sections( $wp_customize );
$this->add_settings( $wp_customize );
$this->add_controls( $wp_customize );
}
public function add_panels( $wp_customize )
{
$wp_customize->add_panel( 'featured_categories', [
'title' => 'Featured Categories',
'description' => 'I\'m looking for a lady',
'priority' => 100
] );
}
public function add_sections( $wp_customize )
{
$wp_customize->add_section( 'featured_category_0', [
'title' => 'Featured Category 1',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
$wp_customize->add_section( 'featured_category_1', [
'title' => 'Featured Category 2',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
$wp_customize->add_section( 'featured_category_2', [
'title' => 'Featured Category 3',
'panel' => 'featured_categories',
'description' => 'Highlight categories on your front page.'
] );
}
public function add_settings( $wp_customize )
{
$wp_customize->add_setting( 'category_slug_0', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_slug_1', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_slug_2', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_0', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_1', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
$wp_customize->add_setting( 'category_image_2', [
'default' => '',
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
] );
}
public function add_controls( $wp_customize )
{
$wp_customize->add_control( 'category_slug_2', [
'section' => 'featured_category_0',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( 'category_slug_1', [
'section' => 'featured_category_1',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( 'category_slug_0', [
'section' => 'featured_category_2',
'label' => 'Category slug',
// 'description' => 'Not the animal',
'type' => 'text'
] );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'category_image_2', [
'section' => 'featured_category_0',
'label' => 'Featured Category Image 1'
] ) );
}
}
I found the solution by copying and pasting the Customizer classes from the source code of the mentioned theme (AWPS): https://github.com/Alecaddd/awps/blob/master/inc/Api/Customizer/Footer.php