我试图在Elementor中创建基本的小部件。在遵循开发人员文档创建新小部件时,将引发以下错误:
致命错误:找不到类“Elementor\Widget_Base”
这是我的代码(大部分是从官方文档中复制的)
Main插件扩展类:
=' ) ) {
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小部件类:
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 '';
}
}发布于 2018-05-21 04:57:58
我也有同样的问题。取$this->include();退出init方法,并将其放入register_widgets方法中:
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() );
}发布于 2020-05-20 19:12:58
转到/var/www/wordpress/wp-content/themes/ReservoirLabs_v2
并打开functions.php文件
和评论require( get_template_directory()
https://wordpress.stackexchange.com/questions/303752
复制相似问题