wordpress-widgets.php (2774B)
1 <?php 2 namespace Elementor; 3 4 if ( ! defined( 'ABSPATH' ) ) { 5 exit; // Exit if accessed directly. 6 } 7 8 /** 9 * Elementor WordPress widgets manager. 10 * 11 * Elementor WordPress widgets manager handler class is responsible for 12 * registering and initializing all the supported controls, both regular 13 * controls and the group controls. 14 * 15 * @since 1.5.0 16 */ 17 class WordPress_Widgets_Manager { 18 19 /** 20 * WordPress widgets manager constructor. 21 * 22 * Initializing the WordPress widgets manager in Elementor editor. 23 * 24 * @since 1.5.0 25 * @access public 26 */ 27 public function __construct() { 28 if ( version_compare( get_bloginfo( 'version' ), '4.8', '<' ) ) { 29 return; 30 } 31 32 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'before_enqueue_scripts' ] ); 33 add_action( 'elementor/editor/footer', [ $this, 'footer' ] ); 34 } 35 36 /** 37 * Before enqueue scripts. 38 * 39 * Prints custom scripts required to run WordPress widgets in Elementor 40 * editor. 41 * 42 * Fired by `elementor/editor/before_enqueue_scripts` action. 43 * 44 * @since 1.5.0 45 * @access public 46 */ 47 public function before_enqueue_scripts() { 48 global $wp_scripts; 49 50 $suffix = Utils::is_script_debug() ? '' : '.min'; 51 52 // TODO: after WP >= 4.9 - it's no needed, Keep for Backward compatibility. 53 $wp_scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views' ) ); 54 $wp_scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' ); 55 56 $wp_scripts->add( 'media-audio-widget', "/wp-admin/js/widgets/media-audio-widget$suffix.js", array( 'media-widgets', 'media-audiovideo' ) ); 57 $wp_scripts->add( 'media-image-widget', "/wp-admin/js/widgets/media-image-widget$suffix.js", array( 'media-widgets' ) ); 58 $wp_scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo' ) ); 59 $wp_scripts->add( 'text-widgets', "/wp-admin/js/widgets/text-widgets$suffix.js", array( 'jquery', 'editor', 'wp-util' ) ); 60 $wp_scripts->add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' ); 61 62 wp_enqueue_style( 'widgets' ); 63 wp_enqueue_style( 'media-views' ); 64 // End TODO. 65 66 // Don't enqueue `code-editor` for WP Custom HTML widget. 67 wp_get_current_user()->syntax_highlighting = 'false'; 68 69 /** This action is documented in wp-admin/admin-header.php */ 70 do_action( 'admin_print_scripts-widgets.php' ); 71 } 72 73 /** 74 * WordPress widgets footer. 75 * 76 * Prints WordPress widgets scripts in Elementor editor footer. 77 * 78 * Fired by `elementor/editor/footer` action. 79 * 80 * @since 1.5.0 81 * @access public 82 */ 83 public function footer() { 84 /** This action is documented in wp-admin/admin-footer.php */ 85 do_action( 'admin_footer-widgets.php' ); 86 } 87 }