首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >元素或致命错误:找不到类'Elementor\Widget_Base‘

元素或致命错误:找不到类'Elementor\Widget_Base‘
EN

WordPress Development用户
提问于 2018-05-17 01:11:24
回答 2查看 13.6K关注 0票数 4

我试图在Elementor中创建基本的小部件。在遵循开发人员文档创建新小部件时,将引发以下错误:

致命错误:找不到类“Elementor\Widget_Base”

这是我的代码(大部分是从官方文档中复制的)

Main插件扩展类:

代码语言:javascript
复制
=' ) ) {
            add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
            return;
        }

        // Check for required PHP version
        if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
            add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
            return;
        }

        // Include plugin files
    $this->includes();

    // Register widgets
     add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_widgets' ] );

    }

    /**
     * Admin notice
     *
     * Warning when the site doesn't have Elementor installed or activated.
     *
     * @since 1.0.0
     *
     * @access public
     */
    public function admin_notice_missing_main_plugin() {

        if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

        $message = sprintf(
            /* translators: 1: Plugin name 2: Elementor */
            esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'elementor-test-extension' ),
            '' . esc_html__( 'Elementor Test Extension', 'elementor-test-extension' ) . '',
            '' . esc_html__( 'Elementor', 'elementor-test-extension' ) . ''
        );

        printf( '%1$s', $message );

    }

    /**
     * Admin notice
     *
     * Warning when the site doesn't have a minimum required Elementor version.
     *
     * @since 1.0.0
     *
     * @access public
     */
    public function admin_notice_minimum_elementor_version() {

        if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

        $message = sprintf(
            /* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */
            esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'elementor-test-extension' ),
            '' . esc_html__( 'Elementor Test Extension', 'elementor-test-extension' ) . '',
            '' . esc_html__( 'Elementor', 'elementor-test-extension' ) . '',
             self::MINIMUM_ELEMENTOR_VERSION
        );

        printf( '%1$s', $message );

    }

    /**
     * Admin notice
     *
     * Warning when the site doesn't have a minimum required PHP version.
     *
     * @since 1.0.0
     *
     * @access public
     */
    public function admin_notice_minimum_php_version() {

        if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );

        $message = sprintf(
            /* translators: 1: Plugin name 2: PHP 3: Required PHP version */
            esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'elementor-test-extension' ),
            '' . esc_html__( 'Elementor Test Extension', 'elementor-test-extension' ) . '',
            '' . esc_html__( 'PHP', 'elementor-test-extension' ) . '',
             self::MINIMUM_PHP_VERSION
        );

        printf( '%1$s', $message );

    }

    /**
     * Include Files
     *
     * Load required plugin core files.
     *
     * @since 1.0.0
     *
     * @access public
     */
    public function includes() {

        require_once( __DIR__ . '/widgets/test-widget.php' );
        //require_once( __DIR__ . '/controls/test-control.php' );

  }


  public function register_widgets() {

    \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_oEmbed_Widget() );

  }


}

Elementor_Test_Extension::instance();

Test小部件类:

代码语言:javascript
复制
start_controls_section(
            'content_section',
            [
                'label' => __( 'Content', 'plugin-name' ),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'url',
            [
                'label' => __( 'URL to embed', 'plugin-name' ),
                'type' => \Elementor\Controls_Manager::TEXT,
                'input_type' => 'url',
                'placeholder' => __( 'https://your-link.com', 'plugin-name' ),
            ]
        );

        $this->end_controls_section();

    }

    /**
     * Render oEmbed widget output on the frontend.
     *
     * Written in PHP and used to generate the final HTML.
     *
     * @since 1.0.0
     * @access protected
     */
    protected function render() {

        $settings = $this->get_settings_for_display();

        $html = wp_oembed_get( $settings['url'] );

        echo '';

        echo ( $html ) ? $html : $settings['url'];

        echo '';

    }

}
EN

回答 2

WordPress Development用户

回答已采纳

发布于 2018-05-21 04:57:58

我也有同样的问题。取$this->include();退出init方法,并将其放入register_widgets方法中:

代码语言:javascript
复制
public function init() {

   ...

   // Include plugin files
   // $this->includes(); // <-- remove this

}

public function register_widgets() {

    $this->includes(); // <- put it here
    \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor_oEmbed_Widget() );

}
票数 5
EN

WordPress Development用户

发布于 2020-05-20 19:12:58

转到/var/www/wordpress/wp-content/themes/ReservoirLabs_v2

并打开functions.php文件

和评论require( get_template_directory()

票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/303752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档