balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

wordpress.php (7479B)


      1 <?php
      2 namespace Elementor;
      3 
      4 if ( ! defined( 'ABSPATH' ) ) {
      5 	exit; // Exit if accessed directly.
      6 }
      7 
      8 /**
      9  * Elementor WordPress widget.
     10  *
     11  * Elementor widget that displays all the WordPress widgets.
     12  *
     13  * @since 1.0.0
     14  */
     15 class Widget_WordPress extends Widget_Base {
     16 
     17 	/**
     18 	 * WordPress widget name.
     19 	 *
     20 	 * @access private
     21 	 *
     22 	 * @var string
     23 	 */
     24 	private $_widget_name = null;
     25 
     26 	/**
     27 	 * WordPress widget instance.
     28 	 *
     29 	 * @access private
     30 	 *
     31 	 * @var \WP_Widget
     32 	 */
     33 	private $_widget_instance = null;
     34 
     35 	/**
     36 	 * Whether the widget is a Pojo widget or not.
     37 	 *
     38 	 * @since 2.0.0
     39 	 * @access private
     40 	 *
     41 	 * @return bool
     42 	 */
     43 	private function is_pojo_widget() {
     44 		return $this->get_widget_instance() instanceof \Pojo_Widget_Base;
     45 	}
     46 
     47 	/**
     48 	 * Get widget name.
     49 	 *
     50 	 * Retrieve WordPress/Pojo widget name.
     51 	 *
     52 	 * @since 1.0.0
     53 	 * @access public
     54 	 *
     55 	 * @return string Widget name.
     56 	 */
     57 	public function get_name() {
     58 		return 'wp-widget-' . $this->get_widget_instance()->id_base;
     59 	}
     60 
     61 	/**
     62 	 * Get widget title.
     63 	 *
     64 	 * Retrieve WordPress/Pojo widget title.
     65 	 *
     66 	 * @since 1.0.0
     67 	 * @access public
     68 	 *
     69 	 * @return string Widget title.
     70 	 */
     71 	public function get_title() {
     72 		return $this->get_widget_instance()->name;
     73 	}
     74 
     75 	/**
     76 	 * Get widget categories.
     77 	 *
     78 	 * Retrieve the list of categories the WordPress/Pojo widget belongs to.
     79 	 *
     80 	 * Used to determine where to display the widget in the editor.
     81 	 *
     82 	 * @since 1.0.0
     83 	 * @access public
     84 	 *
     85 	 * @return array Widget categories. Returns either a WordPress category or Pojo category.
     86 	 */
     87 	public function get_categories() {
     88 		if ( $this->is_pojo_widget() ) {
     89 			$category = 'pojo';
     90 		} else {
     91 			$category = 'wordpress';
     92 		}
     93 		return [ $category ];
     94 	}
     95 
     96 	/**
     97 	 * Get widget icon.
     98 	 *
     99 	 * Retrieve WordPress/Pojo widget icon.
    100 	 *
    101 	 * @since 1.0.0
    102 	 * @access public
    103 	 *
    104 	 * @return string Widget icon. Returns either a WordPress icon or Pojo icon.
    105 	 */
    106 	public function get_icon() {
    107 		if ( $this->is_pojo_widget() ) {
    108 			return 'eicon-pojome';
    109 		}
    110 		return 'eicon-wordpress';
    111 	}
    112 
    113 	/**
    114 	 * Get widget keywords.
    115 	 *
    116 	 * Retrieve the list of keywords the widget belongs to.
    117 	 *
    118 	 * @since 2.1.0
    119 	 * @access public
    120 	 *
    121 	 * @return array Widget keywords.
    122 	 */
    123 	public function get_keywords() {
    124 		return [ 'wordpress', 'widget' ];
    125 	}
    126 
    127 	public function get_help_url() {
    128 		return '';
    129 	}
    130 
    131 	/**
    132 	 * Whether the reload preview is required or not.
    133 	 *
    134 	 * Used to determine whether the reload preview is required.
    135 	 *
    136 	 * @since 1.0.0
    137 	 * @access public
    138 	 *
    139 	 * @return bool Whether the reload preview is required.
    140 	 */
    141 	public function is_reload_preview_required() {
    142 		return true;
    143 	}
    144 
    145 	/**
    146 	 * Retrieve WordPress/Pojo widget form.
    147 	 *
    148 	 * Returns the WordPress widget form, to be used in Elementor.
    149 	 *
    150 	 * @since 1.0.0
    151 	 * @access public
    152 	 *
    153 	 * @return string Widget form.
    154 	 */
    155 	public function get_form() {
    156 		$instance = $this->get_widget_instance();
    157 
    158 		ob_start();
    159 		echo '<div class="widget-inside media-widget-control"><div class="form wp-core-ui">';
    160 		echo '<input type="hidden" class="id_base" value="' . esc_attr( $instance->id_base ) . '" />';
    161 		echo '<input type="hidden" class="widget-id" value="widget-' . esc_attr( $this->get_id() ) . '" />';
    162 		echo '<div class="widget-content">';
    163 		$widget_data = $this->get_settings( 'wp' );
    164 		$instance->form( $widget_data );
    165 		do_action( 'in_widget_form', $instance, null, $widget_data );
    166 		echo '</div></div></div>';
    167 		return ob_get_clean();
    168 	}
    169 
    170 	/**
    171 	 * Retrieve WordPress/Pojo widget instance.
    172 	 *
    173 	 * Returns an instance of WordPress widget, to be used in Elementor.
    174 	 *
    175 	 * @since 1.0.0
    176 	 * @access public
    177 	 *
    178 	 * @return \WP_Widget
    179 	 */
    180 	public function get_widget_instance() {
    181 		if ( is_null( $this->_widget_instance ) ) {
    182 			global $wp_widget_factory;
    183 
    184 			if ( isset( $wp_widget_factory->widgets[ $this->_widget_name ] ) ) {
    185 				$this->_widget_instance = $wp_widget_factory->widgets[ $this->_widget_name ];
    186 				$this->_widget_instance->_set( 'REPLACE_TO_ID' );
    187 			} elseif ( class_exists( $this->_widget_name ) ) {
    188 				$this->_widget_instance = new $this->_widget_name();
    189 				$this->_widget_instance->_set( 'REPLACE_TO_ID' );
    190 			}
    191 		}
    192 		return $this->_widget_instance;
    193 	}
    194 
    195 	/**
    196 	 * Retrieve WordPress/Pojo widget parsed settings.
    197 	 *
    198 	 * Returns the WordPress widget settings, to be used in Elementor.
    199 	 *
    200 	 * @access protected
    201 	 * @since 2.3.0
    202 	 *
    203 	 * @return array Parsed settings.
    204 	 */
    205 	protected function get_init_settings() {
    206 		$settings = parent::get_init_settings();
    207 
    208 		if ( ! empty( $settings['wp'] ) ) {
    209 			$widget = $this->get_widget_instance();
    210 			$instance = $widget->update( $settings['wp'], [] );
    211 			/** This filter is documented in wp-includes/class-wp-widget.php */
    212 			$settings['wp'] = apply_filters( 'widget_update_callback', $instance, $settings['wp'], [], $widget );
    213 		}
    214 
    215 		return $settings;
    216 	}
    217 
    218 	/**
    219 	 * Register WordPress/Pojo widget controls.
    220 	 *
    221 	 * Adds different input fields to allow the user to change and customize the widget settings.
    222 	 *
    223 	 * @since 3.1.0
    224 	 * @access protected
    225 	 */
    226 	protected function register_controls() {
    227 		$this->add_control(
    228 			'wp',
    229 			[
    230 				'label' => esc_html__( 'Form', 'elementor' ),
    231 				'type' => Controls_Manager::WP_WIDGET,
    232 				'widget' => $this->get_name(),
    233 				'id_base' => $this->get_widget_instance()->id_base,
    234 			]
    235 		);
    236 	}
    237 
    238 	/**
    239 	 * Render WordPress/Pojo widget output on the frontend.
    240 	 *
    241 	 * Written in PHP and used to generate the final HTML.
    242 	 *
    243 	 * @since 1.0.0
    244 	 * @access protected
    245 	 */
    246 	protected function render() {
    247 		$default_widget_args = [
    248 			'widget_id' => $this->get_name(),
    249 			'before_widget' => '',
    250 			'after_widget' => '',
    251 			'before_title' => '<h5>',
    252 			'after_title' => '</h5>',
    253 		];
    254 
    255 		/**
    256 		 * WordPress widget args.
    257 		 *
    258 		 * Filters the WordPress widget arguments when they are rendered in Elementor panel.
    259 		 *
    260 		 * @since 1.0.0
    261 		 *
    262 		 * @param array            $default_widget_args Default widget arguments.
    263 		 * @param Widget_WordPress $this                The WordPress widget.
    264 		 */
    265 		$default_widget_args = apply_filters( 'elementor/widgets/wordpress/widget_args', $default_widget_args, $this );
    266 		$is_gallery_widget = 'wp-widget-media_gallery' === $this->get_name();
    267 
    268 		if ( $is_gallery_widget ) {
    269 			add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
    270 		}
    271 
    272 		$this->get_widget_instance()->widget( $default_widget_args, $this->get_settings( 'wp' ) );
    273 
    274 		if ( $is_gallery_widget ) {
    275 			remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
    276 		}
    277 	}
    278 
    279 	/**
    280 	 * Render WordPress/Pojo widget output in the editor.
    281 	 *
    282 	 * Written as a Backbone JavaScript template and used to generate the live preview.
    283 	 *
    284 	 * @since 2.9.0
    285 	 * @access protected
    286 	 */
    287 	protected function content_template() {}
    288 
    289 	/**
    290 	 * WordPress/Pojo widget constructor.
    291 	 *
    292 	 * Used to run WordPress widget constructor.
    293 	 *
    294 	 * @since 1.0.0
    295 	 * @access public
    296 	 *
    297 	 * @param array $data Widget data. Default is an empty array.
    298 	 * @param array $args Widget arguments. Default is null.
    299 	 */
    300 	public function __construct( $data = [], $args = null ) {
    301 		$this->_widget_name = $args['widget_name'];
    302 
    303 		parent::__construct( $data, $args );
    304 	}
    305 
    306 	/**
    307 	 * Render WordPress/Pojo widget as plain content.
    308 	 *
    309 	 * Override the default render behavior, don't render widget content.
    310 	 *
    311 	 * @since 1.0.0
    312 	 * @access public
    313 	 *
    314 	 * @param array $instance Widget instance. Default is empty array.
    315 	 */
    316 	public function render_plain_content( $instance = [] ) {}
    317 }