嗨,我正在使用wordpress
和elementor
插件,我制作了自定义小部件。
但是我需要在编辑器面板上的按钮上有一个JavaScript代码onclick
,隐藏的输入值会发生变化。
我在wp_register_script
类中尝试了elementor
但似乎转到了“预览”标签而不是编辑器。
在Google上进行了很多研究,但似乎没有太多信息。
我找到了此页面 https://developers.elementor.com/creating-a-new-widget/adding-javascript-to-elementor-widgets/
但是我无法与我一起工作。
这是我的课程
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if(defined('ELEMENTOR_VERSION')):
include_once 'manager/controls.php';
class reMAG_Elementor {
public static $_instance;
public function __construct(){
if(!class_exists('ElementsKit')){
add_action('elementor/controls/controls_registered', array( $this, 'control_image_choose' ), 13 );
}
add_action('elementor/init', array($this, 'remag_elementor_unit'));
add_action('elementor/widgets/widgets_registered', array($this, 'remag_shortcode_elements'));
}
public function reMAG_Elementor_unit(){
\Elementor\Plugin::$instance->elements_manager->add_category(
'remag-elements',
[
'title' =>esc_html__( 're:MAG', 're_MAG' ),
'icon' => 'fa fa-plug',
],
1
);
add_action( 'elementor/frontend/after_register_scripts', [ $this, 'widget_scripts' ] );
}
public function widget_scripts() {
wp_register_script( 'widget-2', plugins_url( 'js/helper.js', __FILE__ ), [ 'jquery', 'some-library' ] );
}
public function control_image_choose( $controls_manager ) {
require_once 'controls/choose.php';
$controls_manager->register_control( 'imagechoose', new \Control_Image_Choose() );
}
public function remag_shortcode_elements($widgets_manager){
require_once 'widgets/post-block.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Post_Block_widget());
require_once 'widgets/post-slider.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Post_Slider_widget());
require_once 'widgets/post-recent.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Post_Recent_widget());
require_once 'widgets/social-media.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Social_Media_widget());
require_once 'widgets/categories.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Categories_widget());
require_once 'widgets/tags.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Tags_widget());
require_once 'widgets/subscribe.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Subscribe_widget());
require_once 'widgets/recent-comments.php';
$widgets_manager->register_widget_type(new Elementor\reMAG_Recent_Comments_widget());
}
public static function remag_get_instance() {
if (!isset(self::$_instance)) {
self::$_instance = new reMAG_Elementor();
}
return self::$_instance;
}
}
$reMAG_Elementor = reMAG_Elementor::remag_get_instance();
endif;
任何帮助或信息都将受到欢迎