致命错误:找不到类WP_Customize_Image_Control

时间:2019-06-16 作者:ManuAlvarado22

我正在使用Windows 8.1 64位上的WAMP来开发自定义主题。

现在,我在尝试使用创建自定义控件时遇到以下错误WP_Customize_Image_Control 类别:

致命错误:未捕获错误:在C:\\wamp64\\www\\Ivana-5.2\\WP content\\themes\\Ivana\\inc\\Api\\Customizer\\WP\\u Customizer\\u Image\\u Control中找不到类“Ivana\\Api\\Customizer\\WP\\u Image\\u Control”。php第115行

错误:在C:\\wamp64\\www\\Ivana-5.2\\WP-content\\themes\\Ivana\\inc\\Api\\Customizer\\WP\\u Customizer\\u Image\\u-Control中找不到类“Ivana\\Api\\Customizer\\WP\\u-Image\\u-Control”。php第115行

我使用的是一种面向对象的设计,源于此入门主题:https://github.com/Alecaddd/awps

inc/Api/Customizer。php名称空间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\'
        ] ) );
    }
}
为什么WordPress无法找到WP_Customize_Image_Control 类,或任何此类类,就此而言?(也尝试了颜色和介质,但没有成功)。

如果您看到Customizer。php中,register方法调用\'customize_register\' 操作,安装程序收到$wp_customize.

如果不尝试使用自定义控件,这将非常有效。

1 个回复
SO网友:ManuAlvarado22

通过添加解决use WP_Customize_Image_Control; 添加\\自定义程序\\功能类别。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\'
        ] ) );
    }
}
我通过复制和粘贴上述主题(AWPS)源代码中的Customizer类找到了解决方案:https://github.com/Alecaddd/awps/blob/master/inc/Api/Customizer/Footer.php

相关推荐