PK!>7 endpoint.phpnu[controller; } /** * Get current parent. * * @return \Elementor\Data\V2\Base\Controller|\Elementor\Data\V2\Base\Endpoint */ public function get_parent() { return $this->parent; } /** * Get public name. * * @return string */ public function get_public_name() { return $this->get_name(); } /** * Get full command name ( including index ). * * @return string */ public function get_full_command() { $parent = $this->get_parent(); if ( $parent instanceof Controller ) { return $this->controller->get_full_name() . '/' . $this->get_name(); } return $this->get_name_ancestry(); } /** * Get name ancestry format, example: 'alpha/beta/delta'. * * @return string */ public function get_name_ancestry() { $ancestors = $this->get_ancestors(); $ancestors_names = []; foreach ( $ancestors as $ancestor ) { $ancestors_names [] = $ancestor->get_name(); } return implode( '/', $ancestors_names ); } /** * Register sub endpoint. * * @param \Elementor\Data\V2\Base\Endpoint $endpoint * * @return \Elementor\Data\V2\Base\Endpoint */ public function register_sub_endpoint( Endpoint $endpoint ) { $command = $endpoint->get_full_command(); $format = $endpoint->get_format(); $this->sub_endpoints[ $command ] = $endpoint; Manager::instance()->register_endpoint_format( $command, $format ); return $endpoint; } /** * Get ancestors. * * @return \Elementor\Data\V2\Base\Endpoint[] */ private function get_ancestors() { $ancestors = []; $current = $this; do { if ( $current ) { $ancestors [] = $current; } $current = $current->get_parent(); } while ( $current ); return array_reverse( $ancestors ); } /** * Endpoint constructor. * * @param \Elementor\Data\V2\Base\Controller|\Elementor\Data\V2\Base\Endpoint $parent * @param string $route */ public function __construct( $parent, $route = '/' ) { $controller = $parent; $this->parent = $parent; // In case, its behave like sub-endpoint. if ( ! ( $parent instanceof Controller ) ) { $controller = $parent->get_controller(); } parent::__construct( $controller, $route ); } } PK!Hcgg processor.phpnu[controller = $controller; } } PK!e!!processor/after.phpnu[parent ) { return $this->get_name(); } return $this->parent->get_name() . '/' . $this->get_name(); } /** * Get controller namespace. * * @return string */ public function get_namespace() { return $this->namespace; } /** * Get controller reset base. * * @return string */ public function get_base_route() { if ( ! $this->parent ) { return $this->rest_base; } return $this->parent->get_base_route() . '/' . $this->get_name(); } /** * Get controller route. * * @return string */ public function get_controller_route() { return $this->get_namespace() . '/' . $this->get_base_route(); } /** * Retrieves rest route(s) index for current controller. * * @return \WP_REST_Response|\WP_Error */ public function get_controller_index() { $server = rest_get_server(); $routes = $server->get_routes(); $endpoints = array_intersect_key( $server->get_routes(), $routes ); $controller_route = $this->get_controller_route(); array_walk( $endpoints, function ( &$item, $endpoint ) use ( &$endpoints, $controller_route ) { if ( ! strstr( $endpoint, $controller_route ) ) { unset( $endpoints[ $endpoint ] ); } } ); $data = [ 'namespace' => $this->get_namespace(), 'controller' => $controller_route, 'routes' => $server->get_data_for_routes( $endpoints ), ]; $response = rest_ensure_response( $data ); // Link to the root index. $response->add_link( 'up', rest_url( '/' ) ); return $response; } /** * Get items args of index endpoint. * * Is method is used when `get_collection_params()` is not enough, and need of knowing the methods is required. * * @param string $methods * * @return array */ public function get_items_args( $methods ) { if ( \WP_REST_Server::READABLE === $methods ) { return $this->get_collection_params(); } return []; } /** * Get item args of index endpoint. * * @param string $methods * * @return array */ public function get_item_args( $methods ) { return []; } /** * Get permission callback. * * Default controller permission callback. * By default endpoint will inherit the permission callback from the controller. * * @param \WP_REST_Request $request * * @return bool */ public function get_permission_callback( $request ) { $is_multi = (bool) $request->get_param( 'is_multi' ); $result = false; // The function is public since endpoint need to access it. // Utilize 'WP_REST_Controller' get_permission_check methods. switch ( $request->get_method() ) { case 'GET': $result = $is_multi ? $this->get_items_permissions_check( $request ) : $this->get_item_permissions_check( $request ); break; case 'POST': $result = $is_multi ? $this->create_items_permissions_check( $request ) : $this->create_item_permissions_check( $request ); break; case 'UPDATE': case 'PUT': case 'PATCH': $result = $is_multi ? $this->update_items_permissions_check( $request ) : $this->update_item_permissions_check( $request ); break; case 'DELETE': $result = $is_multi ? $this->delete_items_permissions_check( $request ) : $this->delete_item_permissions_check( $request ); break; } if ( $result instanceof \WP_Error ) { throw new WP_Error_Exception( $result ); } return $result; } /** * Checks if a given request has access to create items. ** * * @param \WP_REST_Request $request Full details about the request. * * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. */ public function create_items_permissions_check( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Checks if a given request has access to update items. * * @param \WP_REST_Request $request Full details about the request. * * @return true|\WP_Error True if the request has access to update the item, WP_Error object otherwise. */ public function update_items_permissions_check( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Checks if a given request has access to delete items. * * @param \WP_REST_Request $request Full details about the request. * * @return true|\WP_Error True if the request has access to delete the item, WP_Error object otherwise. */ public function delete_items_permissions_check( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } public function get_items( $request ) { return $this->get_controller_index(); } /** * Creates multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ public function create_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Updates multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ public function update_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Delete multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ public function delete_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Get the parent controller. * * @return \Elementor\Data\V2\Base\Controller|null */ public function get_parent() { return $this->parent; } /** * Get sub controller(s). * * @return \Elementor\Data\V2\Base\Controller[] */ public function get_sub_controllers() { return $this->sub_controllers; } /** * Get processors. * * @param string $command * * @return \Elementor\Data\V2\Base\Processor[] */ public function get_processors( $command ) { $result = []; if ( isset( $this->processors[ $command ] ) ) { $result = $this->processors[ $command ]; } return $result; } /** * Register processors. */ public function register_processors() { } /** * Register index endpoint. */ protected function register_index_endpoint() { if ( ! $this->parent ) { $this->register_endpoint( new Endpoint\Index( $this ) ); return; } $this->register_endpoint( new Endpoint\Index\Sub_Index_Endpoint( $this ) ); } /** * Register endpoint. * * @param \Elementor\Data\V2\Base\Endpoint $endpoint * * @return \Elementor\Data\V2\Base\Endpoint */ protected function register_endpoint( Endpoint $endpoint ) { $command = $endpoint->get_full_command(); if ( $endpoint instanceof Endpoint\Index ) { $this->index_endpoint = $endpoint; } else { $this->endpoints[ $command ] = $endpoint; } $format = $endpoint->get_format(); // `$e.data.registerFormat()`. Manager::instance()->register_endpoint_format( $command, $format ); return $endpoint; } /** * Register a processor. * * That will be later attached to the endpoint class. * * @param Processor $processor * * @return \Elementor\Data\V2\Base\Processor $processor_instance */ protected function register_processor( Processor $processor ) { $command = $processor->get_command(); if ( ! isset( $this->processors[ $command ] ) ) { $this->processors[ $command ] = []; } $this->processors[ $command ] [] = $processor; return $processor; } /** * Register. * * Endpoints & processors. */ protected function register() { $this->register_index_endpoint(); $this->register_endpoints(); // Aka hooks. $this->register_processors(); } /** * Get collection params by 'additionalProperties' context. * * @param string $context * * @return array */ protected function get_collection_params_by_additional_props_context( $context ) { $result = []; $collection_params = $this->get_collection_params(); foreach ( $collection_params as $collection_param_key => $collection_param ) { if ( isset( $collection_param['additionalProperties']['context'] ) && $context === $collection_param['additionalProperties']['context'] ) { $result[ $collection_param_key ] = $collection_param; } } return $result; } /** * When `$this->get_parent_name` is extended, the controller will have a parent, and will know to behave like a sub-controller. * * @param string $parent_name */ private function act_as_sub_controller( $parent_name ) { $this->parent = Manager::instance()->get_controller( $parent_name ); if ( ! $this->parent ) { trigger_error( "Cannot find parent controller: '$parent_name'", E_USER_ERROR ); // phpcs:ignore } $this->parent->sub_controllers [] = $this; } /** * Controller constructor. * * Register endpoints on 'rest_api_init'. */ public function __construct() { $this->namespace = static::get_default_namespace() . '/v' . static::get_default_version(); $this->rest_base = $this->get_name(); add_action( 'rest_api_init', function () { $this->register(); // Because 'register' is protected. } ); /** * Since all actions were removed for custom internal REST server. * Re-add the actions. */ add_action( 'elementor_rest_api_before_init', function () { add_action( 'rest_api_init', function () { $this->register(); } ); } ); $parent_name = $this->get_parent_name(); if ( $parent_name ) { $this->act_as_sub_controller( $parent_name ); } } } PK!UW{sub-endpoint.phpnu[parent_endpoint = $parent_endpoint; $this->parent_route = $parent_route; parent::__construct( $this->parent_endpoint->controller ); } /** * Get parent route. * * @return \Elementor\Data\Base\Endpoint */ public function get_parent() { return $this->parent_endpoint; } public function get_base_route() { $controller_name = $this->controller->get_name(); return $controller_name . '/' . $this->parent_route . $this->get_name(); } } PK![]YYwidget-base.phpnu[is_type_instance(); if ( ! $is_type_instance && null === $args ) { throw new \Exception( 'An `$args` argument is required when initializing a full widget instance.' ); } if ( $is_type_instance ) { if ( $this->has_own_method( '_register_skins', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_register_skins', '3.1.0', __CLASS__ . '::register_skins()' ); $this->_register_skins(); } else { $this->register_skins(); } $widget_name = $this->get_name(); /** * Widget skin init. * * Fires when Elementor widget is being initialized. * * The dynamic portion of the hook name, `$widget_name`, refers to the widget name. * * @since 1.0.0 * * @param Widget_Base $this The current widget. */ do_action( "elementor/widget/{$widget_name}/skins_init", $this ); } } /** * Get stack. * * Retrieve the widget stack of controls. * * @since 1.9.2 * @access public * * @param bool $with_common_controls Optional. Whether to include the common controls. Default is true. * * @return array Widget stack of controls. */ public function get_stack( $with_common_controls = true ) { $stack = parent::get_stack(); if ( $with_common_controls && 'common' !== $this->get_unique_name() ) { /** @var Widget_Common $common_widget */ $common_widget = Plugin::$instance->widgets_manager->get_widget_types( 'common' ); $stack['controls'] = array_merge( $stack['controls'], $common_widget->get_controls() ); $stack['tabs'] = array_merge( $stack['tabs'], $common_widget->get_tabs_controls() ); } return $stack; } /** * Get widget controls pointer index. * * Retrieve widget pointer index where the next control should be added. * * While using injection point, it will return the injection point index. Otherwise index of the last control of the * current widget itself without the common controls, plus one. * * @since 1.9.2 * @access public * * @return int Widget controls pointer index. */ public function get_pointer_index() { $injection_point = $this->get_injection_point(); if ( null !== $injection_point ) { return $injection_point['index']; } return count( $this->get_stack( false )['controls'] ); } /** * Show in panel. * * Whether to show the widget in the panel or not. By default returns true. * * @since 1.0.0 * @access public * * @return bool Whether to show the widget in the panel or not. */ public function show_in_panel() { return true; } /** * Hide on search. * * Whether to hide the widget on search in the panel or not. By default returns false. * * @access public * * @return bool Whether to hide the widget when searching for widget or not. */ public function hide_on_search() { return false; } /** * Start widget controls section. * * Used to add a new section of controls to the widget. Regular controls and * skin controls. * * Note that when you add new controls to widgets they must be wrapped by * `start_controls_section()` and `end_controls_section()`. * * @since 1.0.0 * @access public * * @param string $section_id Section ID. * @param array $args Section arguments Optional. */ public function start_controls_section( $section_id, array $args = [] ) { parent::start_controls_section( $section_id, $args ); if ( $this->is_first_section ) { $this->register_skin_control(); $this->is_first_section = false; } } /** * Register the Skin Control if the widget has skins. * * An internal method that is used to add a skin control to the widget. * Added at the top of the controls section. * * @since 2.0.0 * @access private */ private function register_skin_control() { $skins = $this->get_skins(); if ( ! empty( $skins ) ) { $skin_options = []; if ( $this->_has_template_content ) { $skin_options[''] = esc_html__( 'Default', 'elementor' ); } foreach ( $skins as $skin_id => $skin ) { $skin_options[ $skin_id ] = $skin->get_title(); } // Get the first item for default value $default_value = array_keys( $skin_options ); $default_value = array_shift( $default_value ); if ( 1 >= count( $skin_options ) ) { $this->add_control( '_skin', [ 'label' => esc_html__( 'Skin', 'elementor' ), 'type' => Controls_Manager::HIDDEN, 'default' => $default_value, ] ); } else { $this->add_control( '_skin', [ 'label' => esc_html__( 'Skin', 'elementor' ), 'type' => Controls_Manager::SELECT, 'default' => $default_value, 'options' => $skin_options, ] ); } } } /** * Register widget skins - deprecated prefixed method * * @since 1.7.12 * @access protected * @deprecated 3.1.0 Use `register_skins()` method instead. */ protected function _register_skins() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_skins()' ); $this->register_skins(); } /** * Register widget skins. * * This method is activated while initializing the widget base class. It is * used to assign skins to widgets with `add_skin()` method. * * Usage: * * protected function register_skins() { * $this->add_skin( new Skin_Classic( $this ) ); * } * * @since 3.1.0 * @access protected */ protected function register_skins() {} /** * Get initial config. * * Retrieve the current widget initial configuration. * * Adds more configuration on top of the controls list, the tabs assigned to * the control, element name, type, icon and more. This method also adds * widget type, keywords and categories. * * @since 2.9.0 * @access protected * * @return array The initial widget config. */ protected function get_initial_config() { $config = [ 'widget_type' => $this->get_name(), 'keywords' => $this->get_keywords(), 'categories' => $this->get_categories(), 'html_wrapper_class' => $this->get_html_wrapper_class(), 'show_in_panel' => $this->show_in_panel(), 'hide_on_search' => $this->hide_on_search(), 'upsale_data' => $this->get_upsale_data(), 'is_dynamic_content' => $this->is_dynamic_content(), ]; if ( isset( $config['upsale_data'] ) && is_array( $config['upsale_data'] ) ) { $filter_name = 'elementor/widgets/' . $this->get_name() . '/custom_promotion'; $config['upsale_data'] = Filtered_Promotions_Manager::get_filtered_promotion_data( $config['upsale_data'], $filter_name, 'upgrade_url' ); } if ( isset( $config['upsale_data']['image'] ) ) { $config['upsale_data']['image'] = esc_url( $config['upsale_data']['image'] ); } $stack = Plugin::$instance->controls_manager->get_element_stack( $this ); if ( $stack ) { $config['controls'] = $this->get_stack( false )['controls']; $config['tabs_controls'] = $this->get_tabs_controls(); } return array_replace_recursive( parent::get_initial_config(), $config ); } /** * @since 2.3.1 * @access protected */ protected function should_print_empty() { return false; } /** * Print widget content template. * * Used to generate the widget content template on the editor, using a * Backbone JavaScript template. * * @since 2.0.0 * @access protected * * @param string $template_content Template content. */ protected function print_template_content( $template_content ) { ?>
get_settings() ); $content = shortcode_unautop( $content ); $content = do_shortcode( $content ); $content = wptexturize( $content ); if ( $GLOBALS['wp_embed'] instanceof \WP_Embed ) { $content = $GLOBALS['wp_embed']->autoembed( $content ); } return $content; } /** * Safe print parsed text editor. * * @uses static::parse_text_editor. * * @access protected * * @param string $content Text editor content. */ final protected function print_text_editor( $content ) { // PHPCS - the method `parse_text_editor` is safe. echo static::parse_text_editor( $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Get HTML wrapper class. * * Retrieve the widget container class. Can be used to override the * container class for specific widgets. * * @since 2.0.9 * @access protected */ protected function get_html_wrapper_class() { return 'elementor-widget-' . $this->get_name(); } /** * Add widget render attributes. * * Used to add attributes to the current widget wrapper HTML tag. * * @since 1.0.0 * @access protected */ protected function add_render_attributes() { parent::add_render_attributes(); $this->add_render_attribute( '_wrapper', 'class', [ 'elementor-widget', $this->get_html_wrapper_class(), ] ); $settings = $this->get_settings(); $this->add_render_attribute( '_wrapper', 'data-widget_type', $this->get_name() . '.' . ( ! empty( $settings['_skin'] ) ? $settings['_skin'] : 'default' ) ); } /** * Add lightbox data to image link. * * Used to add lightbox data attributes to image link HTML. * * @since 2.9.1 * @access public * * @param string $link_html Image link HTML. * @param string $id Attachment id. * * @return string Image link HTML with lightbox data attributes. */ public function add_lightbox_data_to_image_link( $link_html, $id ) { $settings = $this->get_settings_for_display(); $open_lightbox = isset( $settings['open_lightbox'] ) ? $settings['open_lightbox'] : null; if ( Plugin::$instance->editor->is_edit_mode() ) { $this->add_render_attribute( 'link', 'class', 'elementor-clickable', true ); } $this->add_lightbox_data_attributes( 'link', $id, $open_lightbox, $this->get_id(), true ); return preg_replace( '/^get_render_attribute_string( 'link' ), $link_html ); } /** * Add Light-Box attributes. * * Used to add Light-Box-related data attributes to links that open media files. * * @param array|string $element The link HTML element. * @param int $id The ID of the image * @param string $lightbox_setting_key The setting key that dictates whether to open the image in a lightbox * @param string $group_id Unique ID for a group of lightbox images * @param bool $overwrite Optional. Whether to overwrite existing * attribute. Default is false, not to overwrite. * * @return Widget_Base Current instance of the widget. * @since 2.9.0 * @access public * */ public function add_lightbox_data_attributes( $element, $id = null, $lightbox_setting_key = null, $group_id = null, $overwrite = false ) { $kit = Plugin::$instance->kits_manager->get_active_kit(); $is_global_image_lightbox_enabled = 'yes' === $kit->get_settings( 'global_image_lightbox' ); if ( 'no' === $lightbox_setting_key ) { if ( $is_global_image_lightbox_enabled ) { $this->add_render_attribute( $element, 'data-elementor-open-lightbox', 'no', $overwrite ); } return $this; } if ( 'yes' !== $lightbox_setting_key && ! $is_global_image_lightbox_enabled ) { return $this; } $attributes['data-elementor-open-lightbox'] = 'yes'; $action_hash_params = []; if ( $id ) { $action_hash_params['id'] = $id; $action_hash_params['url'] = wp_get_attachment_url( $id ); } if ( $group_id ) { $attributes['data-elementor-lightbox-slideshow'] = $group_id; $action_hash_params['slideshow'] = $group_id; } if ( $id ) { $lightbox_image_attributes = Plugin::$instance->images_manager->get_lightbox_image_attributes( $id ); if ( isset( $lightbox_image_attributes['title'] ) ) { $attributes['data-elementor-lightbox-title'] = $lightbox_image_attributes['title']; } if ( isset( $lightbox_image_attributes['description'] ) ) { $attributes['data-elementor-lightbox-description'] = $lightbox_image_attributes['description']; } } $attributes['data-e-action-hash'] = Plugin::instance()->frontend->create_action_hash( 'lightbox', $action_hash_params ); $this->add_render_attribute( $element, $attributes, null, $overwrite ); return $this; } /** * Render widget output on the frontend. * * Used to generate the final HTML displayed on the frontend. * * Note that if skin is selected, it will be rendered by the skin itself, * not the widget. * * @since 1.0.0 * @access public */ public function render_content() { /** * Before widget render content. * * Fires before Elementor widget is being rendered. * * @since 1.0.0 * * @param Widget_Base $this The current widget. */ do_action( 'elementor/widget/before_render_content', $this ); ob_start(); $skin = $this->get_current_skin(); if ( $skin ) { $skin->set_parent( $this ); $skin->render_by_mode(); } else { $this->render_by_mode(); } $widget_content = ob_get_clean(); if ( empty( $widget_content ) ) { return; } ?>
is_widget_first_render( $this->get_group_name() ) ) { $this->register_runtime_widget( $this->get_group_name() ); } // $this->print_widget_css(); // get_name /** * Render widget content. * * Filters the widget content before it's rendered. * * @since 1.0.0 * * @param string $widget_content The content of the widget. * @param Widget_Base $this The widget. */ $widget_content = apply_filters( 'elementor/widget/render_content', $widget_content, $this ); echo $widget_content; // XSS ok. ?>
render_content(); } /** * Before widget rendering. * * Used to add stuff before the widget `_wrapper` element. * * @since 1.0.0 * @access public */ public function before_render() { ?>
print_render_attribute_string( '_wrapper' ); ?>>
get_data( 'widgetType' ); if ( $with_html_content ) { ob_start(); $this->render_content(); $data['htmlCache'] = ob_get_clean(); } return $data; } /** * Print widget content. * * Output the widget final HTML on the frontend. * * @since 1.0.0 * @access protected */ protected function print_content() { $this->render_content(); } /** * Print a setting content without escaping. * * Script tags are allowed on frontend according to the WP theme securing policy. * * @param string $setting * @param null $repeater_name * @param null $index */ final public function print_unescaped_setting( $setting, $repeater_name = null, $index = null ) { if ( $repeater_name ) { $repeater = $this->get_settings_for_display( $repeater_name ); $output = $repeater[ $index ][ $setting ]; } else { $output = $this->get_settings_for_display( $setting ); } echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Get default data. * * Retrieve the default widget data. Used to reset the data on initialization. * * @since 1.0.0 * @access protected * * @return array Default data. */ protected function get_default_data() { $data = parent::get_default_data(); $data['widgetType'] = ''; return $data; } /** * Get default child type. * * Retrieve the widget child type based on element data. * * @since 1.0.0 * @access protected * * @param array $element_data Widget ID. * * @return array|false Child type or false if it's not a valid widget. */ protected function _get_default_child_type( array $element_data ) { return Plugin::$instance->elements_manager->get_element_types( 'section' ); } /** * Get repeater setting key. * * Retrieve the unique setting key for the current repeater item. Used to connect the current element in the * repeater to it's settings model and it's control in the panel. * * PHP usage (inside `Widget_Base::render()` method): * * $tabs = $this->get_settings( 'tabs' ); * foreach ( $tabs as $index => $item ) { * $tab_title_setting_key = $this->get_repeater_setting_key( 'tab_title', 'tabs', $index ); * $this->add_inline_editing_attributes( $tab_title_setting_key, 'none' ); * echo '
get_render_attribute_string( $tab_title_setting_key ) . '>' . $item['tab_title'] . '
'; * } * * @since 1.8.0 * @access protected * * @param string $setting_key The current setting key inside the repeater item (e.g. `tab_title`). * @param string $repeater_key The repeater key containing the array of all the items in the repeater (e.g. `tabs`). * @param int $repeater_item_index The current item index in the repeater array (e.g. `3`). * * @return string The repeater setting key (e.g. `tabs.3.tab_title`). */ protected function get_repeater_setting_key( $setting_key, $repeater_key, $repeater_item_index ) { return implode( '.', [ $repeater_key, $repeater_item_index, $setting_key ] ); } /** * Add inline editing attributes. * * Define specific area in the element to be editable inline. The element can have several areas, with this method * you can set the area inside the element that can be edited inline. You can also define the type of toolbar the * user will see, whether it will be a basic toolbar or an advanced one. * * Note: When you use wysiwyg control use the advanced toolbar, with textarea control use the basic toolbar. Text * control should not have toolbar. * * PHP usage (inside `Widget_Base::render()` method): * * $this->add_inline_editing_attributes( 'text', 'advanced' ); * echo '
get_render_attribute_string( 'text' ) . '>' . $this->get_settings( 'text' ) . '
'; * * @since 1.8.0 * @access protected * * @param string $key Element key. * @param string $toolbar Optional. Toolbar type. Accepted values are `advanced`, `basic` or `none`. Default is * `basic`. */ protected function add_inline_editing_attributes( $key, $toolbar = 'basic' ) { if ( ! Plugin::$instance->editor->is_edit_mode() ) { return; } $this->add_render_attribute( $key, [ 'class' => 'elementor-inline-editing', 'data-elementor-setting-key' => $key, ] ); if ( 'basic' !== $toolbar ) { $this->add_render_attribute( $key, [ 'data-elementor-inline-editing-toolbar' => $toolbar, ] ); } } /** * Add new skin. * * Register new widget skin to allow the user to set custom designs. Must be * called inside the `register_skins()` method. * * @since 1.0.0 * @access public * * @param Skin_Base $skin Skin instance. */ public function add_skin( Skin_Base $skin ) { Plugin::$instance->skins_manager->add_skin( $this, $skin ); } /** * Get single skin. * * Retrieve a single skin based on skin ID, from all the skin assigned to * the widget. If the skin does not exist or not assigned to the widget, * return false. * * @since 1.0.0 * @access public * * @param string $skin_id Skin ID. * * @return string|false Single skin, or false. */ public function get_skin( $skin_id ) { $skins = $this->get_skins(); if ( isset( $skins[ $skin_id ] ) ) { return $skins[ $skin_id ]; } return false; } /** * Get current skin ID. * * Retrieve the ID of the current skin. * * @since 1.0.0 * @access public * * @return string Current skin. */ public function get_current_skin_id() { return $this->get_settings( '_skin' ); } /** * Get current skin. * * Retrieve the current skin, or if non exist return false. * * @since 1.0.0 * @access public * * @return Skin_Base|false Current skin or false. */ public function get_current_skin() { return $this->get_skin( $this->get_current_skin_id() ); } /** * Remove widget skin. * * Unregister an existing skin and remove it from the widget. * * @since 1.0.0 * @access public * * @param string $skin_id Skin ID. * * @return \WP_Error|true Whether the skin was removed successfully from the widget. */ public function remove_skin( $skin_id ) { return Plugin::$instance->skins_manager->remove_skin( $this, $skin_id ); } /** * Get widget skins. * * Retrieve all the skin assigned to the widget. * * @since 1.0.0 * @access public * * @return Skin_Base[] */ public function get_skins() { return Plugin::$instance->skins_manager->get_skins( $this ); } /** * Get group name. * * Some widgets need to use group names, this method allows you to create them. * By default it retrieves the regular name. * * @since 3.3.0 * @access public * * @return string Unique name. */ public function get_group_name() { return $this->get_name(); } /** * Get Inline CSS dependencies. * * Retrieve a list of inline CSS dependencies that the element requires. * * @since 3.3.0 * @access public * * @return array. */ public function get_inline_css_depends() { return []; } /** * @param string $plugin_title Plugin's title * @param string $since Plugin version widget was deprecated * @param string $last Plugin version in which the widget will be removed * @param string $replacement Widget replacement */ protected function deprecated_notice( $plugin_title, $since, $last = '', $replacement = '' ) { $this->start_controls_section( 'Deprecated', [ 'label' => esc_html__( 'Deprecated', 'elementor' ), ] ); $this->add_control( 'deprecated_notice', [ 'type' => Controls_Manager::DEPRECATED_NOTICE, 'widget' => $this->get_title(), 'since' => $since, 'last' => $last, 'plugin' => $plugin_title, 'replacement' => $replacement, ] ); $this->end_controls_section(); } /** * Init controls. * * Reset the `is_first_section` flag to true, so when the Stacks are cleared * all the controls will be registered again with their skins and settings. * * @since 3.14.0 * @access protected */ protected function init_controls() { $this->is_first_section = true; parent::init_controls(); } public function register_runtime_widget( $widget_name ) { self::$registered_runtime_widgets[] = $widget_name; } public function get_widget_css_config( $widget_name ) { $direction = is_rtl() ? '-rtl' : ''; $has_custom_breakpoints = $this->is_custom_breakpoints_widget(); $file_name = 'widget-' . $widget_name . $direction . '.min.css'; // The URL of the widget's external CSS file that is loaded in case that the CSS content is too large to be printed inline. $file_url = Plugin::$instance->frontend->get_frontend_file_url( $file_name, $has_custom_breakpoints ); // The local path of the widget's CSS file that is being read and saved in the DB when the CSS content should be printed inline. $file_path = Plugin::$instance->frontend->get_frontend_file_path( $file_name, $has_custom_breakpoints ); $file_timestamp = file_exists( $file_path ) ? filemtime( $file_path ) : ELEMENTOR_VERSION; return [ 'key' => $widget_name, 'version' => ELEMENTOR_VERSION, 'file_path' => $file_path, 'data' => [ 'file_url' => $file_url . '?ver=' . $file_timestamp, ], ]; } public function get_css_config() { return $this->get_widget_css_config( $this->get_group_name() ); } public function get_responsive_widgets_config() { $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager(); return [ 'key' => $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_DATABASE_KEY, 'version' => ELEMENTOR_VERSION, 'file_path' => ELEMENTOR_ASSETS_PATH . $responsive_widgets_data_manager::RESPONSIVE_WIDGETS_FILE_PATH, ]; } public function get_responsive_widgets() { $responsive_widgets_data_manager = $this->get_responsive_widgets_data_manager(); $config = $this->get_responsive_widgets_config(); return $responsive_widgets_data_manager->get_asset_data_from_config( $config ); } /** * Mark widget as deprecated. * * Use `get_deprecation_message()` method to print the message control at specific location in register_controls(). * * @param $version string The version of Elementor that deprecated the widget. * @param $message string A message regarding the deprecation. * @param $replacement string The widget that should be used instead. */ protected function add_deprecation_message( $version, $message, $replacement ) { // Expose the config for handling in JS. $this->set_config( 'deprecation', [ 'version' => $version, 'message' => $message, 'replacement' => $replacement, ] ); $this->add_control( 'deprecation_message', [ 'type' => Controls_Manager::ALERT, 'alert_type' => 'info', 'content' => $message, 'separator' => 'after', ] ); } /** * Get Responsive Widgets Data Manager. * * Retrieve the data manager that handles widgets that are using media queries for custom-breakpoints values. * * @since 3.5.0 * @access protected * * @return Responsive_Widgets_Data_Manager */ protected function get_responsive_widgets_data_manager() { if ( ! self::$responsive_widgets_data_manager ) { self::$responsive_widgets_data_manager = new Responsive_Widgets_Data_Manager(); } return self::$responsive_widgets_data_manager; } /** * Is Custom Breakpoints Widget. * * Checking if there are active custom-breakpoints and if the widget use them. * * @since 3.5.0 * @access protected * * @return boolean */ protected function is_custom_breakpoints_widget() { $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints(); if ( $has_custom_breakpoints ) { $responsive_widgets = $this->get_responsive_widgets(); // The $widget_name can also represents a widgets group name, therefore we need to use the current widget name to check if it's responsive widget. $current_widget_name = $this->get_name(); // If the widget is not implementing custom-breakpoints media queries then it has no custom- css file. if ( ! isset( $responsive_widgets[ $current_widget_name ] ) ) { $has_custom_breakpoints = false; } } return $has_custom_breakpoints; } private function get_widget_css() { $widgets_css_data_manager = $this->get_widgets_css_data_manager(); $widgets_list = $this->get_inline_css_depends(); $widgets_list[] = $this->get_group_name(); $widget_css = ''; foreach ( $widgets_list as $widget_data ) { $widget_name = isset( $widget_data['name'] ) ? $widget_data['name'] : $widget_data; if ( ! in_array( $widget_name, self::$registered_inline_css_widgets, true ) ) { if ( $this->get_group_name() === $widget_name ) { $config = $this->get_css_config(); } else { /** * The core-dependency allowing to create a dependency specifically with the core widgets. * Otherwise, the config will be taken from the class that inherits from Widget_Base. */ $is_core_dependency = isset( $widget_data['is_core_dependency'] ) ? true : false; $config = $is_core_dependency ? self::get_widget_css_config( $widget_name ) : $this->get_widget_css_config( $widget_name ); } $widget_css .= $widgets_css_data_manager->get_asset_data_from_config( $config ); self::$registered_inline_css_widgets[] = $widget_name; } } return $widget_css; } private function is_inline_css_mode() { static $is_active; if ( null === $is_active ) { $is_edit_mode = Plugin::$instance->editor->is_edit_mode(); $is_preview_mode = Plugin::$instance->preview->is_preview_mode(); $is_optimized_mode = Plugin::$instance->experiments->is_feature_active( 'e_optimized_css_loading' ); $is_active = ( Utils::is_script_debug() || $is_edit_mode || $is_preview_mode || ! $is_optimized_mode ) ? false : true; } return $is_active; } private function print_widget_css() { if ( ! $this->is_inline_css_mode() ) { return; } Utils::print_unescaped_internal_string( $this->get_widget_css() ); } private function get_widgets_css_data_manager() { if ( ! self::$widgets_css_data_manager ) { self::$widgets_css_data_manager = new Widgets_Css_Data_Manager(); } return self::$widgets_css_data_manager; } } PK!?Y00controls-stack.phpnu[get_name(); } /** * Get element ID. * * Retrieve the element generic ID. * * @since 1.4.0 * @access public * * @return string The ID. */ public function get_id() { return $this->id; } /** * Get element ID. * * Retrieve the element generic ID as integer. * * @since 1.8.0 * @access public * * @return string The converted ID. */ public function get_id_int() { /** We ignore possible notices, in order to support elements created prior to v1.8.0 and might include * non-base 16 characters as part of their ID. */ return @hexdec( $this->id ); } /** * Get widget number. * * Get the first three numbers of the element converted ID. * * @since 3.16 * @access public * * @return string The widget number. */ public function get_widget_number(): string { return substr( $this->get_id_int(), 0, 3 ); } /** * Get the type. * * Retrieve the type, e.g. 'stack', 'section', 'widget' etc. * * @since 1.4.0 * @access public * @static * * @return string The type. */ public static function get_type() { return 'stack'; } /** * @since 2.9.0 * @access public * * @return bool */ public function is_editable() { return true; } /** * Get current section. * * When inserting new controls, this method will retrieve the current section. * * @since 1.7.1 * @access public * * @return null|array Current section. */ public function get_current_section() { return $this->current_section; } /** * Get current tab. * * When inserting new controls, this method will retrieve the current tab. * * @since 1.7.1 * @access public * * @return null|array Current tab. */ public function get_current_tab() { return $this->current_tab; } /** * Get controls. * * Retrieve all the controls or, when requested, a specific control. * * @since 1.4.0 * @access public * * @param string $control_id The ID of the requested control. Optional field, * when set it will return a specific control. * Default is null. * * @return mixed Controls list. */ public function get_controls( $control_id = null ) { $stack = $this->get_stack(); if ( null !== $control_id ) { $control_data = self::get_items( $stack['controls'], $control_id ); if ( null === $control_data && ! empty( $stack['style_controls'] ) ) { $control_data = self::get_items( $stack['style_controls'], $control_id ); } return $control_data; } $controls = $stack['controls']; if ( Performance::is_use_style_controls() && ! empty( $stack['style_controls'] ) ) { $controls += $stack['style_controls']; } return self::get_items( $controls, $control_id ); } /** * Get active controls. * * Retrieve an array of active controls that meet the condition field. * * If specific controls was given as a parameter, retrieve active controls * from that list, otherwise check for all the controls available. * * @since 1.4.0 * @since 2.0.9 Added the `controls` and the `settings` parameters. * @access public * @deprecated 3.0.0 * * @param array $controls Optional. An array of controls. Default is null. * @param array $settings Optional. Controls settings. Default is null. * * @return array Active controls. */ public function get_active_controls( array $controls = null, array $settings = null ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' ); if ( ! $controls ) { $controls = $this->get_controls(); } if ( ! $settings ) { $settings = $this->get_controls_settings(); } $active_controls = array_reduce( array_keys( $controls ), function( $active_controls, $control_key ) use ( $controls, $settings ) { $control = $controls[ $control_key ]; if ( $this->is_control_visible( $control, $settings, $controls ) ) { $active_controls[ $control_key ] = $control; } return $active_controls; }, [] ); return $active_controls; } /** * Get controls settings. * * Retrieve the settings for all the controls that represent them. * * @since 1.5.0 * @access public * * @return array Controls settings. */ public function get_controls_settings() { return array_intersect_key( $this->get_settings(), $this->get_controls() ); } /** * Add new control to stack. * * Register a single control to allow the user to set/update data. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $id Control ID. * @param array $args Control arguments. * @param array $options Optional. Control options. Default is an empty array. * * @return bool True if control added, False otherwise. */ public function add_control( $id, array $args, $options = [] ) { $default_options = [ 'overwrite' => false, 'position' => null, ]; if ( isset( $args['scheme'] ) ) { $args['global'] = [ 'default' => Plugin::$instance->kits_manager->convert_scheme_to_global( $args['scheme'] ), ]; unset( $args['scheme'] ); } $options = array_merge( $default_options, $options ); if ( $options['position'] ) { $this->start_injection( $options['position'] ); } if ( $this->injection_point ) { $options['index'] = $this->injection_point['index']++; } if ( empty( $args['type'] ) || ! in_array( $args['type'], [ Controls_Manager::SECTION, Controls_Manager::WP_WIDGET ], true ) ) { $args = $this->handle_control_position( $args, $id, $options['overwrite'] ); } if ( $options['position'] ) { $this->end_injection(); } unset( $options['position'] ); if ( $this->current_popover ) { $args['popover'] = []; if ( ! $this->current_popover['initialized'] ) { $args['popover']['start'] = true; $this->current_popover['initialized'] = true; } } if ( Performance::should_optimize_controls() ) { $ui_controls = [ Controls_Manager::RAW_HTML, Controls_Manager::DIVIDER, Controls_Manager::HEADING, Controls_Manager::BUTTON, Controls_Manager::ALERT, Controls_Manager::NOTICE, Controls_Manager::DEPRECATED_NOTICE, ]; if ( ! empty( $args['type'] ) && ! empty( $args['section'] ) && in_array( $args['type'], $ui_controls ) ) { $args = [ 'type' => $args['type'], 'section' => $args['section'], ]; } unset( $args['label_block'], $args['label'], $args['title'], $args['tab'], $args['options'], $args['placeholder'], $args['separator'], $args['size_units'], $args['range'], $args['toggle'], $args['ai'], $args['classes'], $args['style_transfer'], $args['show_label'], $args['description'], $args['label_on'], $args['label_off'], $args['labels'], $args['handles'], $args['editor_available'], ); } return Plugin::$instance->controls_manager->add_control_to_stack( $this, $id, $args, $options ); } /** * Remove control from stack. * * Unregister an existing control and remove it from the stack. * * @since 1.4.0 * @access public * * @param string $control_id Control ID. * * @return bool|\WP_Error */ public function remove_control( $control_id ) { return Plugin::$instance->controls_manager->remove_control_from_stack( $this->get_unique_name(), $control_id ); } /** * Update control in stack. * * Change the value of an existing control in the stack. When you add new * control you set the `$args` parameter, this method allows you to update * the arguments by passing new data. * * @since 1.4.0 * @since 1.8.1 New `$options` parameter added. * * @access public * * @param string $control_id Control ID. * @param array $args Control arguments. Only the new fields you want * to update. * @param array $options Optional. Some additional options. Default is * an empty array. * * @return bool */ public function update_control( $control_id, array $args, array $options = [] ) { $is_updated = Plugin::$instance->controls_manager->update_control_in_stack( $this, $control_id, $args, $options ); if ( ! $is_updated ) { return false; } $control = $this->get_controls( $control_id ); if ( Controls_Manager::SECTION === $control['type'] ) { $section_args = $this->get_section_args( $control_id ); $section_controls = $this->get_section_controls( $control_id ); foreach ( $section_controls as $section_control_id => $section_control ) { $this->update_control( $section_control_id, $section_args, $options ); } } return true; } /** * Get stack. * * Retrieve the stack of controls. * * @since 1.9.2 * @access public * * @return array Stack of controls. */ public function get_stack() { $stack = Plugin::$instance->controls_manager->get_element_stack( $this ); if ( null === $stack ) { $this->init_controls(); return Plugin::$instance->controls_manager->get_element_stack( $this ); } return $stack; } /** * Get position information. * * Retrieve the position while injecting data, based on the element type. * * @since 1.7.0 * @access public * * @param array $position { * The injection position. * * @type string $type Injection type, either `control` or `section`. * Default is `control`. * @type string $at Where to inject. If `$type` is `control` accepts * `before` and `after`. If `$type` is `section` * accepts `start` and `end`. Default values based on * the `type`. * @type string $of Control/Section ID. * @type array $fallback Fallback injection position. When the position is * not found it will try to fetch the fallback * position. * } * * @return bool|array Position info. */ final public function get_position_info( array $position ) { $default_position = [ 'type' => 'control', 'at' => 'after', ]; if ( ! empty( $position['type'] ) && 'section' === $position['type'] ) { $default_position['at'] = 'end'; } $position = array_merge( $default_position, $position ); if ( 'control' === $position['type'] && in_array( $position['at'], [ 'start', 'end' ], true ) || 'section' === $position['type'] && in_array( $position['at'], [ 'before', 'after' ], true ) ) { _doing_it_wrong( sprintf( '%s::%s', get_called_class(), __FUNCTION__ ), 'Invalid position arguments. Use `before` / `after` for control or `start` / `end` for section.', '1.7.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return false; } $target_control_index = $this->get_control_index( $position['of'] ); if ( false === $target_control_index ) { if ( ! empty( $position['fallback'] ) ) { return $this->get_position_info( $position['fallback'] ); } return false; } $target_section_index = $target_control_index; $registered_controls = $this->get_controls(); $controls_keys = array_keys( $registered_controls ); while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_section_index ] ]['type'] ) { $target_section_index--; } if ( 'section' === $position['type'] ) { $target_control_index++; if ( 'end' === $position['at'] ) { while ( Controls_Manager::SECTION !== $registered_controls[ $controls_keys[ $target_control_index ] ]['type'] ) { if ( ++$target_control_index >= count( $registered_controls ) ) { break; } } } } $target_control = $registered_controls[ $controls_keys[ $target_control_index ] ]; if ( 'after' === $position['at'] ) { $target_control_index++; } $section_id = $registered_controls[ $controls_keys[ $target_section_index ] ]['name']; $position_info = [ 'index' => $target_control_index, 'section' => $this->get_section_args( $section_id ), ]; if ( ! empty( $target_control['tabs_wrapper'] ) ) { $position_info['tab'] = [ 'tabs_wrapper' => $target_control['tabs_wrapper'], 'inner_tab' => $target_control['inner_tab'], ]; } return $position_info; } /** * Get control key. * * Retrieve the key of the control based on a given index of the control. * * @since 1.9.2 * @access public * * @param string $control_index Control index. * * @return int Control key. */ final public function get_control_key( $control_index ) { $registered_controls = $this->get_controls(); $controls_keys = array_keys( $registered_controls ); return $controls_keys[ $control_index ]; } /** * Get control index. * * Retrieve the index of the control based on a given key of the control. * * @since 1.7.6 * @access public * * @param string $control_key Control key. * * @return false|int Control index. */ final public function get_control_index( $control_key ) { $controls = $this->get_controls(); $controls_keys = array_keys( $controls ); return array_search( $control_key, $controls_keys ); } /** * Get section controls. * * Retrieve all controls under a specific section. * * @since 1.7.6 * @access public * * @param string $section_id Section ID. * * @return array Section controls */ final public function get_section_controls( $section_id ) { $section_index = $this->get_control_index( $section_id ); $section_controls = []; $registered_controls = $this->get_controls(); $controls_keys = array_keys( $registered_controls ); while ( true ) { $section_index++; if ( ! isset( $controls_keys[ $section_index ] ) ) { break; } $control_key = $controls_keys[ $section_index ]; if ( Controls_Manager::SECTION === $registered_controls[ $control_key ]['type'] ) { break; } $section_controls[ $control_key ] = $registered_controls[ $control_key ]; }; return $section_controls; } /** * Add new group control to stack. * * Register a set of related controls grouped together as a single unified * control. For example grouping together like typography controls into a * single, easy-to-use control. * * @since 1.4.0 * @access public * * @param string $group_name Group control name. * @param array $args Group control arguments. Default is an empty array. * @param array $options Optional. Group control options. Default is an * empty array. */ final public function add_group_control( $group_name, array $args = [], array $options = [] ) { $group = Plugin::$instance->controls_manager->get_control_groups( $group_name ); if ( ! $group ) { wp_die( sprintf( '%s::%s: Group "%s" not found.', get_called_class(), __FUNCTION__, $group_name ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $group->add_controls( $this, $args, $options ); } /** * Get style controls. * * Retrieve style controls for all active controls or, when requested, from * a specific set of controls. * * @since 1.4.0 * @since 2.0.9 Added the `settings` parameter. * @access public * @deprecated 3.0.0 * * @param array $controls Optional. Controls list. Default is null. * @param array $settings Optional. Controls settings. Default is null. * * @return array Style controls. */ final public function get_style_controls( array $controls = null, array $settings = null ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.0.0' ); $controls = $this->get_active_controls( $controls, $settings ); $style_controls = []; foreach ( $controls as $control_name => $control ) { $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); if ( ! $control_obj instanceof Base_Data_Control ) { continue; } $control = array_merge( $control_obj->get_settings(), $control ); if ( $control_obj instanceof Control_Repeater ) { $style_fields = []; foreach ( $this->get_settings( $control_name ) as $item ) { $style_fields[] = $this->get_style_controls( $control['fields'], $item ); } $control['style_fields'] = $style_fields; } if ( ! empty( $control['selectors'] ) || ! empty( $control['dynamic'] ) || ! empty( $control['style_fields'] ) ) { $style_controls[ $control_name ] = $control; } } return $style_controls; } /** * Get tabs controls. * * Retrieve all the tabs assigned to the control. * * @since 1.4.0 * @access public * * @return array Tabs controls. */ final public function get_tabs_controls() { return $this->get_stack()['tabs']; } /** * Add new responsive control to stack. * * Register a set of controls to allow editing based on user screen size. * This method registers one or more controls per screen size/device, depending on the current Responsive Control * Duplication Mode. There are 3 control duplication modes: * * 'off' - Only a single control is generated. In the Editor, this control is duplicated in JS. * * 'on' - Multiple controls are generated, one control per enabled device/breakpoint + a default/desktop control. * * 'dynamic' - If the control includes the `'dynamic' => 'active' => true` property - the control is duplicated, * once for each device/breakpoint + default/desktop. * If the control doesn't include the `'dynamic' => 'active' => true` property - the control is not duplicated. * * @since 1.4.0 * @access public * * @param string $id Responsive control ID. * @param array $args Responsive control arguments. * @param array $options Optional. Responsive control options. Default is * an empty array. */ final public function add_responsive_control( $id, array $args, $options = [] ) { $args['responsive'] = []; $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints(); $devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true, 'desktop_first' => true, ] ); if ( isset( $args['devices'] ) ) { $devices = array_intersect( $devices, $args['devices'] ); $args['responsive']['devices'] = $devices; unset( $args['devices'] ); } $control_to_check = $args; if ( ! empty( $options['overwrite'] ) ) { $existing_control = Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $id ); if ( ! is_wp_error( $existing_control ) ) { $control_to_check = $existing_control; } } $responsive_duplication_mode = Plugin::$instance->breakpoints->get_responsive_control_duplication_mode(); $additional_breakpoints_active = Plugin::$instance->experiments->is_feature_active( 'additional_custom_breakpoints' ); $control_is_dynamic = ! empty( $control_to_check['dynamic']['active'] ); $is_frontend_available = ! empty( $control_to_check['frontend_available'] ); $has_prefix_class = ! empty( $control_to_check['prefix_class'] ); // If the new responsive controls experiment is active, create only one control - duplicates per device will // be created in JS in the Editor. if ( $additional_breakpoints_active && ( 'off' === $responsive_duplication_mode || ( 'dynamic' === $responsive_duplication_mode && ! $control_is_dynamic ) ) // Some responsive controls need responsive settings to be available to the widget handler, even when empty. && ! $is_frontend_available && ! $has_prefix_class ) { $args['is_responsive'] = true; if ( ! empty( $options['overwrite'] ) ) { $this->update_control( $id, $args, [ 'recursive' => ! empty( $options['recursive'] ), ] ); } else { $this->add_control( $id, $args, $options ); } return; } if ( isset( $args['default'] ) ) { $args['desktop_default'] = $args['default']; unset( $args['default'] ); } foreach ( $devices as $device_name ) { $control_args = $args; // Set parent using the name from previous iteration. if ( isset( $control_name ) ) { // If $control_name end with _widescreen use desktop name instead $control_args['parent'] = '_widescreen' === substr( $control_name, -strlen( '_widescreen' ) ) ? $id : $control_name; } else { $control_args['parent'] = null; } if ( isset( $control_args['device_args'] ) ) { if ( ! empty( $control_args['device_args'][ $device_name ] ) ) { $control_args = array_merge( $control_args, $control_args['device_args'][ $device_name ] ); } unset( $control_args['device_args'] ); } if ( ! empty( $args['prefix_class'] ) ) { $device_to_replace = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '-' . $device_name; $control_args['prefix_class'] = sprintf( $args['prefix_class'], $device_to_replace ); } $direction = 'max'; if ( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP !== $device_name ) { $direction = $active_breakpoints[ $device_name ]->get_direction(); } $control_args['responsive'][ $direction ] = $device_name; if ( isset( $control_args['min_affected_device'] ) ) { if ( ! empty( $control_args['min_affected_device'][ $device_name ] ) ) { $control_args['responsive']['min'] = $control_args['min_affected_device'][ $device_name ]; } unset( $control_args['min_affected_device'] ); } if ( isset( $control_args[ $device_name . '_default' ] ) ) { $control_args['default'] = $control_args[ $device_name . '_default' ]; } foreach ( $devices as $device ) { unset( $control_args[ $device . '_default' ] ); } $id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name; $control_name = $id . $id_suffix; // Set this control as child of previous iteration control. if ( ! empty( $control_args['parent'] ) ) { $this->update_control( $control_args['parent'], [ 'inheritors' => [ $control_name ] ] ); } if ( ! empty( $options['overwrite'] ) ) { $this->update_control( $control_name, $control_args, [ 'recursive' => ! empty( $options['recursive'] ), ] ); } else { $this->add_control( $control_name, $control_args, $options ); } } } /** * Update responsive control in stack. * * Change the value of an existing responsive control in the stack. When you * add new control you set the `$args` parameter, this method allows you to * update the arguments by passing new data. * * @since 1.4.0 * @access public * * @param string $id Responsive control ID. * @param array $args Responsive control arguments. * @param array $options Optional. Additional options. */ final public function update_responsive_control( $id, array $args, array $options = [] ) { $this->add_responsive_control( $id, $args, [ 'overwrite' => true, 'recursive' => ! empty( $options['recursive'] ), ] ); } /** * Remove responsive control from stack. * * Unregister an existing responsive control and remove it from the stack. * * @since 1.4.0 * @access public * * @param string $id Responsive control ID. */ final public function remove_responsive_control( $id ) { $devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] ); foreach ( $devices as $device_name ) { $id_suffix = Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP === $device_name ? '' : '_' . $device_name; $this->remove_control( $id . $id_suffix ); } } /** * Get class name. * * Retrieve the name of the current class. * * @since 1.4.0 * @access public * * @return string Class name. */ final public function get_class_name() { return get_called_class(); } /** * Get the config. * * Retrieve the config or, if non set, use the initial config. * * @since 1.4.0 * @access public * * @return array|null The config. */ final public function get_config() { if ( null === $this->config ) { // TODO: This is for backwards compatibility starting from 2.9.0 // This if statement should be removed when the method is hard-deprecated if ( $this->has_own_method( '_get_initial_config', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_get_initial_config', '2.9.0', __CLASS__ . '::get_initial_config()' ); $this->config = $this->_get_initial_config(); } else { $this->config = $this->get_initial_config(); } foreach ( $this->additional_config as $key => $value ) { if ( isset( $this->config[ $key ] ) ) { $this->config[ $key ] = wp_parse_args( $value, $this->config[ $key ] ); } else { $this->config[ $key ] = $value; } } } return $this->config; } /** * Set a config property. * * Set a specific property of the config list for this controls-stack. * * @since 3.5.0 * @access public */ public function set_config( $key, $value ) { if ( isset( $this->additional_config[ $key ] ) ) { $this->additional_config[ $key ] = wp_parse_args( $value, $this->additional_config[ $key ] ); } else { $this->additional_config[ $key ] = $value; } } /** * Get frontend settings keys. * * Retrieve settings keys for all frontend controls. * * @since 1.6.0 * @access public * * @return array Settings keys for each control. */ final public function get_frontend_settings_keys() { $controls = []; foreach ( $this->get_controls() as $control ) { if ( ! empty( $control['frontend_available'] ) ) { $controls[] = $control['name']; } } return $controls; } /** * Get controls pointer index. * * Retrieve pointer index where the next control should be added. * * While using injection point, it will return the injection point index. * Otherwise index of the last control plus one. * * @since 1.9.2 * @access public * * @return int Controls pointer index. */ public function get_pointer_index() { if ( null !== $this->injection_point ) { return $this->injection_point['index']; } return count( $this->get_controls() ); } /** * Get the raw data. * * Retrieve all the items or, when requested, a specific item. * * @since 1.4.0 * @access public * * @param string $item Optional. The requested item. Default is null. * * @return mixed The raw data. */ public function get_data( $item = null ) { if ( ! $this->settings_sanitized && ( ! $item || 'settings' === $item ) ) { $this->data['settings'] = $this->sanitize_settings( $this->data['settings'] ); $this->settings_sanitized = true; } return self::get_items( $this->data, $item ); } /** * @since 2.0.14 * @access public */ public function get_parsed_dynamic_settings( $setting = null, $settings = null ) { if ( null === $settings ) { $settings = $this->get_settings(); } if ( null === $this->parsed_dynamic_settings ) { $this->parsed_dynamic_settings = $this->parse_dynamic_settings( $settings ); } return self::get_items( $this->parsed_dynamic_settings, $setting ); } /** * Get active settings. * * Retrieve the settings from all the active controls. * * @since 1.4.0 * @since 2.1.0 Added the `controls` and the `settings` parameters. * @access public * * @param array $controls Optional. An array of controls. Default is null. * @param array $settings Optional. Controls settings. Default is null. * * @return array Active settings. */ public function get_active_settings( $settings = null, $controls = null ) { $is_first_request = ! $settings && ! $this->active_settings; if ( ! $settings ) { if ( $this->active_settings ) { return $this->active_settings; } $settings = $this->get_controls_settings(); $controls = $this->get_controls(); } $active_settings = []; $controls_objs = Plugin::$instance->controls_manager->get_controls(); foreach ( $settings as $setting_key => $setting ) { if ( ! isset( $controls[ $setting_key ] ) ) { $active_settings[ $setting_key ] = $setting; continue; } $control = $controls[ $setting_key ]; if ( $this->is_control_visible( $control, $settings, $controls ) ) { $control_obj = $controls_objs[ $control['type'] ] ?? null; if ( $control_obj instanceof Control_Repeater ) { foreach ( $setting as & $item ) { $item = $this->get_active_settings( $item, $control['fields'] ); } } $active_settings[ $setting_key ] = $setting; } else { $active_settings[ $setting_key ] = null; } } if ( $is_first_request ) { $this->active_settings = $active_settings; } return $active_settings; } /** * Get settings for display. * * Retrieve all the settings or, when requested, a specific setting for display. * * Unlike `get_settings()` method, this method retrieves only active settings * that passed all the conditions, rendered all the shortcodes and all the dynamic * tags. * * @since 2.0.0 * @access public * * @param string $setting_key Optional. The key of the requested setting. * Default is null. * * @return mixed The settings. */ public function get_settings_for_display( $setting_key = null ) { if ( ! $this->parsed_active_settings ) { $this->parsed_active_settings = $this->get_active_settings( $this->get_parsed_dynamic_settings(), $this->get_controls() ); } return self::get_items( $this->parsed_active_settings, $setting_key ); } /** * Parse dynamic settings. * * Retrieve the settings with rendered dynamic tags. * * @since 2.0.0 * @access public * * @param array $settings Optional. The requested setting. Default is null. * @param array $controls Optional. The controls array. Default is null. * @param array $all_settings Optional. All the settings. Default is null. * * @return array The settings with rendered dynamic tags. */ public function parse_dynamic_settings( $settings, $controls = null, $all_settings = null ) { if ( null === $all_settings ) { $all_settings = $this->get_settings(); } if ( null === $controls ) { $controls = $this->get_controls(); } $controls_objs = Plugin::$instance->controls_manager->get_controls(); foreach ( $controls as $control ) { $control_name = $control['name']; $control_obj = $controls_objs[ $control['type'] ] ?? null; if ( ! $control_obj instanceof Base_Data_Control ) { continue; } if ( $control_obj instanceof Control_Repeater ) { if ( ! isset( $settings[ $control_name ] ) ) { continue; } foreach ( $settings[ $control_name ] as & $field ) { $field = $this->parse_dynamic_settings( $field, $control['fields'], $field ); } continue; } $dynamic_settings = $control_obj->get_settings( 'dynamic' ); if ( ! $dynamic_settings ) { $dynamic_settings = []; } if ( ! empty( $control['dynamic'] ) ) { $dynamic_settings = array_merge( $dynamic_settings, $control['dynamic'] ); } if ( empty( $dynamic_settings ) || ! isset( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ] ) ) { continue; } if ( ! empty( $dynamic_settings['active'] ) && ! empty( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ] ) ) { $parsed_value = $control_obj->parse_tags( $all_settings[ Manager::DYNAMIC_SETTING_KEY ][ $control_name ], $dynamic_settings ); $dynamic_property = ! empty( $dynamic_settings['property'] ) ? $dynamic_settings['property'] : null; if ( $dynamic_property ) { $settings[ $control_name ][ $dynamic_property ] = $parsed_value; } else { $settings[ $control_name ] = $parsed_value; } } } return $settings; } /** * Get frontend settings. * * Retrieve the settings for all frontend controls. * * @since 1.6.0 * @access public * * @return array Frontend settings. */ public function get_frontend_settings() { $frontend_settings = array_intersect_key( $this->get_settings_for_display(), array_flip( $this->get_frontend_settings_keys() ) ); foreach ( $frontend_settings as $key => $setting ) { if ( in_array( $setting, [ null, '' ], true ) ) { unset( $frontend_settings[ $key ] ); } } return $frontend_settings; } /** * Filter controls settings. * * Receives controls, settings and a callback function to filter the settings by * and returns filtered settings. * * @since 1.5.0 * @access public * * @param callable $callback The callback function. * @param array $settings Optional. Control settings. Default is an empty * array. * @param array $controls Optional. Controls list. Default is an empty * array. * * @return array Filtered settings. */ public function filter_controls_settings( callable $callback, array $settings = [], array $controls = [] ) { if ( ! $settings ) { $settings = $this->get_settings(); } if ( ! $controls ) { $controls = $this->get_controls(); } return array_reduce( array_keys( $settings ), function( $filtered_settings, $setting_key ) use ( $controls, $settings, $callback ) { if ( isset( $controls[ $setting_key ] ) ) { $result = $callback( $settings[ $setting_key ], $controls[ $setting_key ] ); if ( null !== $result ) { $filtered_settings[ $setting_key ] = $result; } } return $filtered_settings; }, [] ); } /** * Get Responsive Control Device Suffix * * @deprecated 3.7.6 Use `Elementor\Controls_Manager::get_responsive_control_device_suffix()` instead. * @param array $control * @return string $device suffix */ protected function get_responsive_control_device_suffix( $control ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.7.6', 'Elementor\Controls_Manager::get_responsive_control_device_suffix()' ); return Controls_Manager::get_responsive_control_device_suffix( $control ); } /** * Whether the control is visible or not. * * Used to determine whether the control is visible or not. * * @since 1.4.0 * @access public * * @param array $control The control. * @param array $values Optional. Condition values. Default is null. * * @return bool Whether the control is visible. */ public function is_control_visible( $control, $values = null, $controls = null ) { if ( null === $values ) { $values = $this->get_settings(); } if ( ! empty( $control['conditions'] ) && ! Conditions::check( $control['conditions'], $values ) ) { return false; } if ( empty( $control['condition'] ) ) { return true; } if ( ! $controls ) { $controls = $this->get_controls(); } foreach ( $control['condition'] as $condition_key => $condition_value ) { preg_match( '/([a-z_\-0-9]+)(?:\[([a-z_]+)])?(!?)$/i', $condition_key, $condition_key_parts ); $pure_condition_key = $condition_key_parts[1]; $condition_sub_key = $condition_key_parts[2]; $is_negative_condition = ! ! $condition_key_parts[3]; if ( ! isset( $values[ $pure_condition_key ] ) || null === $values[ $pure_condition_key ] ) { return false; } $are_control_and_condition_responsive = isset( $control['responsive'] ) && ! empty( $controls[ $pure_condition_key ]['responsive'] ); $condition_name_to_check = $pure_condition_key; if ( $are_control_and_condition_responsive ) { $device_suffix = Controls_Manager::get_responsive_control_device_suffix( $control ); $condition_name_to_check = $pure_condition_key . $device_suffix; // If the control is not desktop, and a conditioning control for the corresponding device exists, use it. $instance_value = $values[ $pure_condition_key . $device_suffix ] ?? $values[ $pure_condition_key ]; } else { $instance_value = $values[ $pure_condition_key ]; } if ( $condition_sub_key && is_array( $instance_value ) ) { if ( ! isset( $instance_value[ $condition_sub_key ] ) ) { return false; } $instance_value = $instance_value[ $condition_sub_key ]; } if ( ! $instance_value ) { $parent = isset( $controls[ $condition_name_to_check ]['parent'] ) ? $controls[ $condition_name_to_check ]['parent'] : false; while ( $parent ) { $instance_value = $values[ $parent ]; if ( $instance_value ) { if ( ! is_array( $instance_value ) ) { break; } if ( $condition_sub_key && isset( $instance_value[ $condition_sub_key ] ) ) { $instance_value = $instance_value[ $condition_sub_key ]; if ( '' !== $instance_value ) { break; } } } $parent = isset( $controls[ $parent ]['parent'] ) ? $controls[ $parent ]['parent'] : false; } } /** * If the $condition_value is a non empty array - check if the $condition_value contains the $instance_value, * If the $instance_value is a non empty array - check if the $instance_value contains the $condition_value * otherwise check if they are equal. ( and give the ability to check if the value is an empty array ) */ if ( is_array( $condition_value ) && ! empty( $condition_value ) ) { $is_contains = in_array( $instance_value, $condition_value, true ); } elseif ( is_array( $instance_value ) && ! empty( $instance_value ) ) { $is_contains = in_array( $condition_value, $instance_value, true ); } else { $is_contains = $instance_value === $condition_value; } if ( $is_negative_condition && $is_contains || ! $is_negative_condition && ! $is_contains ) { return false; } } return true; } /** * Start controls section. * * Used to add a new section of controls. When you use this method, all the * registered controls from this point will be assigned to this section, * until you close the section using `end_controls_section()` method. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $section_id Section ID. * @param array $args Section arguments Optional. */ public function start_controls_section( $section_id, array $args = [] ) { $stack_name = $this->get_name(); /** * Before section start. * * Fires before Elementor section starts in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/before_section_start', $this, $section_id, $args ); /** * Before section start. * * Fires before Elementor section starts in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_start", $this, $args ); $args['type'] = Controls_Manager::SECTION; $this->add_control( $section_id, $args ); if ( null !== $this->current_section ) { wp_die( sprintf( 'Elementor: You can\'t start a section before the end of the previous section "%s".', $this->current_section['section'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $this->current_section = $this->get_section_args( $section_id ); if ( $this->injection_point ) { $this->injection_point['section'] = $this->current_section; } /** * After section start. * * Fires after Elementor section starts in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/after_section_start', $this, $section_id, $args ); /** * After section start. * * Fires after Elementor section starts in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_start", $this, $args ); } /** * End controls section. * * Used to close an existing open controls section. When you use this method * it stops adding new controls to this section. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public */ public function end_controls_section() { $stack_name = $this->get_name(); // Save the current section for the action. $current_section = $this->current_section; $section_id = $current_section['section']; $args = [ 'tab' => $current_section['tab'], ]; /** * Before section end. * * Fires before Elementor section ends in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/before_section_end', $this, $section_id, $args ); /** * Before section end. * * Fires before Elementor section ends in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/before_section_end", $this, $args ); $this->current_section = null; /** * After section end. * * Fires after Elementor section ends in the editor panel. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param string $section_id Section ID. * @param array $args Section arguments. */ do_action( 'elementor/element/after_section_end', $this, $section_id, $args ); /** * After section end. * * Fires after Elementor section ends in the editor panel. * * The dynamic portions of the hook name, `$stack_name` and `$section_id`, refers to the stack name and section ID, respectively. * * @since 1.4.0 * * @param Controls_Stack $this The control. * @param array $args Section arguments. */ do_action( "elementor/element/{$stack_name}/{$section_id}/after_section_end", $this, $args ); } /** * Start controls tabs. * * Used to add a new set of tabs inside a section. You should use this * method before adding new individual tabs using `start_controls_tab()`. * Each tab added after this point will be assigned to this group of tabs, * until you close it using `end_controls_tabs()` method. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $tabs_id Tabs ID. * @param array $args Tabs arguments. */ public function start_controls_tabs( $tabs_id, array $args = [] ) { if ( null !== $this->current_tab ) { wp_die( sprintf( 'Elementor: You can\'t start tabs before the end of the previous tabs "%s".', $this->current_tab['tabs_wrapper'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $args['type'] = Controls_Manager::TABS; $this->add_control( $tabs_id, $args ); $this->current_tab = [ 'tabs_wrapper' => $tabs_id, ]; foreach ( [ 'condition', 'conditions' ] as $key ) { if ( ! empty( $args[ $key ] ) ) { $this->current_tab[ $key ] = $args[ $key ]; } } if ( $this->injection_point ) { $this->injection_point['tab'] = $this->current_tab; } } /** * End controls tabs. * * Used to close an existing open controls tabs. When you use this method it * stops adding new controls to this tabs. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public */ public function end_controls_tabs() { $this->current_tab = null; } /** * Start controls tab. * * Used to add a new tab inside a group of tabs. Use this method before * adding new individual tabs using `start_controls_tab()`. * Each tab added after this point will be assigned to this group of tabs, * until you close it using `end_controls_tab()` method. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public * * @param string $tab_id Tab ID. * @param array $args Tab arguments. */ public function start_controls_tab( $tab_id, $args ) { if ( ! empty( $this->current_tab['inner_tab'] ) ) { wp_die( sprintf( 'Elementor: You can\'t start a tab before the end of the previous tab "%s".', $this->current_tab['inner_tab'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $args['type'] = Controls_Manager::TAB; $args['tabs_wrapper'] = $this->current_tab['tabs_wrapper']; $this->add_control( $tab_id, $args ); $this->current_tab['inner_tab'] = $tab_id; if ( $this->injection_point ) { $this->injection_point['tab']['inner_tab'] = $this->current_tab['inner_tab']; } } /** * End controls tab. * * Used to close an existing open controls tab. When you use this method it * stops adding new controls to this tab. * * This method should be used inside `register_controls()`. * * @since 1.4.0 * @access public */ public function end_controls_tab() { unset( $this->current_tab['inner_tab'] ); } /** * Start popover. * * Used to add a new set of controls in a popover. When you use this method, * all the registered controls from this point will be assigned to this * popover, until you close the popover using `end_popover()` method. * * This method should be used inside `register_controls()`. * * @since 1.9.0 * @access public */ final public function start_popover() { $this->current_popover = [ 'initialized' => false, ]; } /** * End popover. * * Used to close an existing open popover. When you use this method it stops * adding new controls to this popover. * * This method should be used inside `register_controls()`. * * @since 1.9.0 * @access public */ final public function end_popover() { $this->current_popover = null; $last_control_key = $this->get_control_key( $this->get_pointer_index() - 1 ); $args = [ 'popover' => [ 'end' => true, ], ]; $options = [ 'recursive' => true, ]; $this->update_control( $last_control_key, $args, $options ); } /** * Add render attribute. * * Used to add attributes to a specific HTML element. * * The HTML tag is represented by the element parameter, then you need to * define the attribute key and the attribute key. The final result will be: * ``. * * Example usage: * * `$this->add_render_attribute( 'wrapper', 'class', 'custom-widget-wrapper-class' );` * `$this->add_render_attribute( 'widget', 'id', 'custom-widget-id' );` * `$this->add_render_attribute( 'button', [ 'class' => 'custom-button-class', 'id' => 'custom-button-id' ] );` * * @since 1.0.0 * @access public * * @param array|string $element The HTML element. * @param array|string $key Optional. Attribute key. Default is null. * @param array|string $value Optional. Attribute value. Default is null. * @param bool $overwrite Optional. Whether to overwrite existing * attribute. Default is false, not to overwrite. * * @return self Current instance of the element. */ public function add_render_attribute( $element, $key = null, $value = null, $overwrite = false ) { if ( is_array( $element ) ) { foreach ( $element as $element_key => $attributes ) { $this->add_render_attribute( $element_key, $attributes, null, $overwrite ); } return $this; } if ( is_array( $key ) ) { foreach ( $key as $attribute_key => $attributes ) { $this->add_render_attribute( $element, $attribute_key, $attributes, $overwrite ); } return $this; } if ( empty( $this->render_attributes[ $element ][ $key ] ) ) { $this->render_attributes[ $element ][ $key ] = []; } settype( $value, 'array' ); if ( $overwrite ) { $this->render_attributes[ $element ][ $key ] = $value; } else { $this->render_attributes[ $element ][ $key ] = array_merge( $this->render_attributes[ $element ][ $key ], $value ); } return $this; } /** * Get Render Attributes * * Used to retrieve render attribute. * * The returned array is either all elements and their attributes if no `$element` is specified, an array of all * attributes of a specific element or a specific attribute properties if `$key` is specified. * * Returns null if one of the requested parameters isn't set. * * @since 2.2.6 * @access public * @param string $element * @param string $key * * @return array */ public function get_render_attributes( $element = '', $key = '' ) { $attributes = $this->render_attributes; if ( $element ) { if ( ! isset( $attributes[ $element ] ) ) { return null; } $attributes = $attributes[ $element ]; if ( $key ) { if ( ! isset( $attributes[ $key ] ) ) { return null; } $attributes = $attributes[ $key ]; } } return $attributes; } /** * Set render attribute. * * Used to set the value of the HTML element render attribute or to update * an existing render attribute. * * @since 1.0.0 * @access public * * @param array|string $element The HTML element. * @param array|string $key Optional. Attribute key. Default is null. * @param array|string $value Optional. Attribute value. Default is null. * * @return self Current instance of the element. */ public function set_render_attribute( $element, $key = null, $value = null ) { return $this->add_render_attribute( $element, $key, $value, true ); } /** * Remove render attribute. * * Used to remove an element (with its keys and their values), key (with its values), * or value/s from an HTML element's render attribute. * * @since 2.7.0 * @access public * * @param string $element The HTML element. * @param string $key Optional. Attribute key. Default is null. * @param array|string $values Optional. Attribute value/s. Default is null. */ public function remove_render_attribute( $element, $key = null, $values = null ) { if ( $key && ! isset( $this->render_attributes[ $element ][ $key ] ) ) { return; } if ( $values ) { $values = (array) $values; $this->render_attributes[ $element ][ $key ] = array_diff( $this->render_attributes[ $element ][ $key ], $values ); return; } if ( $key ) { unset( $this->render_attributes[ $element ][ $key ] ); return; } if ( isset( $this->render_attributes[ $element ] ) ) { unset( $this->render_attributes[ $element ] ); } } /** * Get render attribute string. * * Used to retrieve the value of the render attribute. * * @since 1.0.0 * @access public * * @param string $element The element. * * @return string Render attribute string, or an empty string if the attribute * is empty or not exist. */ public function get_render_attribute_string( $element ) { if ( empty( $this->render_attributes[ $element ] ) ) { return ''; } return Utils::render_html_attributes( $this->render_attributes[ $element ] ); } /** * Print render attribute string. * * Used to output the rendered attribute. * * @since 2.0.0 * @access public * * @param array|string $element The element. */ public function print_render_attribute_string( $element ) { echo $this->get_render_attribute_string( $element ); // XSS ok. } /** * Print element template. * * Used to generate the element template on the editor. * * @since 2.0.0 * @access public */ public function print_template() { ob_start(); // TODO: This is for backwards compatibility starting from 2.9.0 // This `if` statement should be removed when the method is removed if ( $this->has_own_method( '_content_template', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_content_template', '2.9.0', __CLASS__ . '::content_template()' ); $this->_content_template(); } else { $this->content_template(); } $template_content = ob_get_clean(); $element_type = $this->get_type(); /** * Template content. * * Filters the controls stack template content before it's printed in the editor. * * The dynamic portion of the hook name, `$element_type`, refers to the element type. * * @since 1.0.0 * * @param string $content_template The controls stack template in the editor. * @param Controls_Stack $this The controls stack. */ $template_content = apply_filters( "elementor/{$element_type}/print_template", $template_content, $this ); if ( empty( $template_content ) ) { return; } ?> injection_point ) { wp_die( 'A controls injection is already opened. Please close current injection before starting a new one (use `end_injection`).' ); } $this->injection_point = $this->get_position_info( $position ); } /** * End injection. * * Used to close an existing opened injection point. * * When you use this method it stops adding new controls and sections to * this point and continue to add controls to the regular position in the * stack. * * @since 1.7.1 * @access public */ final public function end_injection() { $this->injection_point = null; } /** * Get injection point. * * Retrieve the injection point in the stack where new controls and sections * will be inserted. * * @since 1.9.2 * @access public * * @return array|null An array when an injection point is defined, null * otherwise. */ final public function get_injection_point() { return $this->injection_point; } /** * Register controls. * * Used to add new controls to any element type. For example, external * developers use this method to register controls in a widget. * * Should be inherited and register new controls using `add_control()`, * `add_responsive_control()` and `add_group_control()`, inside control * wrappers like `start_controls_section()`, `start_controls_tabs()` and * `start_controls_tab()`. * * @since 1.4.0 * @access protected * @deprecated 3.1.0 Use `register_controls()` method instead. */ protected function _register_controls() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'register_controls()' ); $this->register_controls(); } /** * Register controls. * * Used to add new controls to any element type. For example, external * developers use this method to register controls in a widget. * * Should be inherited and register new controls using `add_control()`, * `add_responsive_control()` and `add_group_control()`, inside control * wrappers like `start_controls_section()`, `start_controls_tabs()` and * `start_controls_tab()`. * * @since 3.1.0 * @access protected */ protected function register_controls() {} /** * Get default data. * * Retrieve the default data. Used to reset the data on initialization. * * @since 1.4.0 * @access protected * * @return array Default data. */ protected function get_default_data() { return [ 'id' => 0, 'settings' => [], ]; } /** * @since 2.3.0 * @access protected */ protected function get_init_settings() { $settings = $this->get_data( 'settings' ); $controls_objs = Plugin::$instance->controls_manager->get_controls(); foreach ( $this->get_controls() as $control ) { $control_obj = $controls_objs[ $control['type'] ] ?? null; if ( ! $control_obj instanceof Base_Data_Control ) { continue; } $control = array_merge_recursive( $control_obj->get_settings(), $control ); $settings[ $control['name'] ] = $control_obj->get_value( $control, $settings ); } return $settings; } /** * Get initial config. * * Retrieve the current element initial configuration - controls list and * the tabs assigned to the control. * * @since 2.9.0 * @access protected * * @return array The initial config. */ protected function get_initial_config() { return [ 'controls' => $this->get_controls(), ]; } /** * Get initial config. * * Retrieve the current element initial configuration - controls list and * the tabs assigned to the control. * * @since 1.4.0 * @deprecated 2.9.0 Use `get_initial_config()` method instead. * @access protected * * @return array The initial config. */ protected function _get_initial_config() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'get_initial_config()' ); return $this->get_initial_config(); } /** * Get section arguments. * * Retrieve the section arguments based on section ID. * * @since 1.4.0 * @access protected * * @param string $section_id Section ID. * * @return array Section arguments. */ protected function get_section_args( $section_id ) { $section_control = $this->get_controls( $section_id ); $section_args_keys = [ 'tab', 'condition' ]; $args = array_intersect_key( $section_control, array_flip( $section_args_keys ) ); $args['section'] = $section_id; return $args; } /** * Render element. * * Generates the final HTML on the frontend. * * @since 2.0.0 * @access protected */ protected function render() {} /** * Render element in static mode. * * If not inherent will call the base render. */ protected function render_static() { $this->render(); } /** * Determine the render logic. */ protected function render_by_mode() { if ( Plugin::$instance->frontend->is_static_render_mode() ) { $this->render_static(); return; } $this->render(); } /** * Print content template. * * Used to generate the content template on the editor, using a * Backbone JavaScript template. * * @access protected * @since 2.0.0 * * @param string $template_content Template content. */ protected function print_template_content( $template_content ) { echo $template_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Render element output in the editor. * * Used to generate the live preview, using a Backbone JavaScript template. * * @since 2.9.0 * @access protected */ protected function content_template() {} /** * Render element output in the editor. * * Used to generate the live preview, using a Backbone JavaScript template. * * @since 2.0.0 * @deprecated 2.9.0 Use `content_template()` method instead. * @access protected */ protected function _content_template() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'content_template()' ); $this->content_template(); } /** * Initialize controls. * * Register the all controls added by `register_controls()`. * * @since 2.0.0 * @access protected */ protected function init_controls() { Plugin::$instance->controls_manager->open_stack( $this ); // TODO: This is for backwards compatibility starting from 2.9.0 // This `if` statement should be removed when the method is removed if ( $this->has_own_method( '_register_controls', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_register_controls', '3.1.0', __CLASS__ . '::register_controls()' ); $this->_register_controls(); } else { $this->register_controls(); } } protected function handle_control_position( array $args, $control_id, $overwrite ) { if ( isset( $args['type'] ) && in_array( $args['type'], [ Controls_Manager::SECTION, Controls_Manager::WP_WIDGET ], true ) ) { return $args; } $target_section_args = $this->current_section; $target_tab = $this->current_tab; if ( $this->injection_point ) { $target_section_args = $this->injection_point['section']; if ( ! empty( $this->injection_point['tab'] ) ) { $target_tab = $this->injection_point['tab']; } } if ( null !== $target_section_args ) { if ( ! empty( $args['section'] ) || ! empty( $args['tab'] ) ) { _doing_it_wrong( sprintf( '%s::%s', get_called_class(), __FUNCTION__ ), sprintf( 'Cannot redeclare control with `tab` or `section` args inside section "%s".', $control_id ), '1.0.0' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $args = array_replace_recursive( $target_section_args, $args ); if ( null !== $target_tab ) { $args = array_replace_recursive( $target_tab, $args ); } } elseif ( empty( $args['section'] ) && ( ! $overwrite || is_wp_error( Plugin::$instance->controls_manager->get_control_from_stack( $this->get_unique_name(), $control_id ) ) ) ) { if ( ! Performance::should_optimize_controls() ) { wp_die( sprintf( '%s::%s: Cannot add a control outside of a section (use `start_controls_section`).', get_called_class(), __FUNCTION__ ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } return $args; } /** * Initialize the class. * * Set the raw data, the ID and the parsed settings. * * @since 2.9.0 * @access protected * * @param array $data Initial data. */ protected function init( $data ) { $this->data = array_merge( $this->get_default_data(), $data ); $this->id = $data['id']; } /** * Initialize the class. * * Set the raw data, the ID and the parsed settings. * * @since 1.4.0 * @deprecated 2.9.0 Use `init()` method instead. * @access protected * * @param array $data Initial data. */ protected function _init( $data ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '2.9.0', 'init()' ); $this->init( $data ); } /** * Sanitize initial data. * * Performs settings cleaning and sanitization. * * @since 2.1.5 * @access private * * @param array $settings Settings to sanitize. * @param array $controls Optional. An array of controls. Default is an * empty array. * * @return array Sanitized settings. */ private function sanitize_settings( array $settings, array $controls = [] ) { if ( ! $controls ) { $controls = $this->get_controls(); } foreach ( $controls as $control ) { $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); if ( $control_obj instanceof Control_Repeater ) { if ( empty( $settings[ $control['name'] ] ) ) { continue; } foreach ( $settings[ $control['name'] ] as $index => $repeater_row_data ) { $sanitized_row_data = $this->sanitize_settings( $repeater_row_data, $control['fields'] ); $settings[ $control['name'] ][ $index ] = $sanitized_row_data; } continue; } $is_dynamic = isset( $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ); if ( ! $is_dynamic ) { continue; } $value_to_check = $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ]; $tag_text_data = Plugin::$instance->dynamic_tags->tag_text_to_tag_data( $value_to_check ); if ( ! Plugin::$instance->dynamic_tags->get_tag_info( $tag_text_data['name'] ) ) { unset( $settings[ Manager::DYNAMIC_SETTING_KEY ][ $control['name'] ] ); } } return $settings; } /** * Controls stack constructor. * * Initializing the control stack class using `$data`. The `$data` is required * for a normal instance. It is optional only for internal `type instance`. * * @since 1.4.0 * @access public * * @param array $data Optional. Control stack data. Default is an empty array. */ public function __construct( array $data = [] ) { if ( $data ) { // TODO: This is for backwards compatibility starting from 2.9.0 // This if statement should be removed when the method is hard-deprecated if ( $this->has_own_method( '_init', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_init', '2.9.0', __CLASS__ . '::init()' ); $this->_init( $data ); } else { $this->init( $data ); } } } } PK!#m skin-base.phpnu[_register_controls_actions(); } /** * Render skin. * * Generates the final HTML on the frontend. * * @since 1.0.0 * @access public * @abstract */ abstract public function render(); /** * Render element in static mode. * * If not inherent will call the base render. */ public function render_static() { $this->render(); } /** * Determine the render logic. */ public function render_by_mode() { if ( Plugin::$instance->frontend->is_static_render_mode() ) { $this->render_static(); return; } $this->render(); } /** * Register skin controls actions. * * Run on init and used to register new skins to be injected to the widget. * This method is used to register new actions that specify the location of * the skin in the widget. * * Example usage: * `add_action( 'elementor/element/{widget_id}/{section_id}/before_section_end', [ $this, 'register_controls' ] );` * * @since 1.0.0 * @access protected */ protected function _register_controls_actions() {} /** * Get skin control ID. * * Retrieve the skin control ID. Note that skin controls have special prefix * to distinguish them from regular controls, and from controls in other * skins. * * @since 1.0.0 * @access protected * * @param string $control_base_id Control base ID. * * @return string Control ID. */ protected function get_control_id( $control_base_id ) { $skin_id = str_replace( '-', '_', $this->get_id() ); return $skin_id . '_' . $control_base_id; } /** * Get skin settings. * * Retrieve all the skin settings or, when requested, a specific setting. * * @since 1.0.0 * @TODO: rename to get_setting() and create backward compatibility. * * @access public * * @param string $control_base_id Control base ID. * * @return mixed */ public function get_instance_value( $control_base_id ) { $control_id = $this->get_control_id( $control_base_id ); return $this->parent->get_settings( $control_id ); } /** * Start skin controls section. * * Used to add a new section of controls to the skin. * * @since 1.3.0 * @access public * * @param string $id Section ID. * @param array $args Section arguments. */ public function start_controls_section( $id, $args = [] ) { $args['condition']['_skin'] = $this->get_id(); parent::start_controls_section( $id, $args ); } /** * Add new skin control. * * Register a single control to the allow the user to set/update skin data. * * @param string $id Control ID. * @param array $args Control arguments. * @param array $options * * @return bool True if skin added, False otherwise. * @since 3.0.0 New `$options` parameter added. * @access public * */ public function add_control( $id, $args = [], $options = [] ) { $args['condition']['_skin'] = $this->get_id(); return parent::add_control( $id, $args, $options ); } /** * Update skin control. * * Change the value of an existing skin control. * * @since 1.3.0 * @since 1.8.1 New `$options` parameter added. * * @access public * * @param string $id Control ID. * @param array $args Control arguments. Only the new fields you want to update. * @param array $options Optional. Some additional options. */ public function update_control( $id, $args, array $options = [] ) { $args['condition']['_skin'] = $this->get_id(); parent::update_control( $id, $args, $options ); } /** * Add new responsive skin control. * * Register a set of controls to allow editing based on user screen size. * * @param string $id Responsive control ID. * @param array $args Responsive control arguments. * @param array $options * * @since 1.0.5 * @access public * */ public function add_responsive_control( $id, $args, $options = [] ) { $args['condition']['_skin'] = $this->get_id(); parent::add_responsive_control( $id, $args ); } /** * Start skin controls tab. * * Used to add a new tab inside a group of tabs. * * @since 1.5.0 * @access public * * @param string $id Control ID. * @param array $args Control arguments. */ public function start_controls_tab( $id, $args ) { $args['condition']['_skin'] = $this->get_id(); parent::start_controls_tab( $id, $args ); } /** * Start skin controls tabs. * * Used to add a new set of tabs inside a section. * * @since 1.5.0 * @access public * * @param string $id Control ID. */ public function start_controls_tabs( $id ) { $args['condition']['_skin'] = $this->get_id(); parent::start_controls_tabs( $id ); } /** * Add new group control. * * Register a set of related controls grouped together as a single unified * control. * * @param string $group_name Group control name. * @param array $args Group control arguments. Default is an empty array. * @param array $options * * @since 1.0.0 * @access public * */ final public function add_group_control( $group_name, $args = [], $options = [] ) { $args['condition']['_skin'] = $this->get_id(); parent::add_group_control( $group_name, $args ); } /** * Set parent widget. * * Used to define the parent widget of the skin. * * @since 1.0.0 * @access public * * @param Widget_Base $parent Parent widget. */ public function set_parent( $parent ) { $this->parent = $parent; } } PK!sub-controls-stack.phpnu[parent = $parent; } /** * Get control ID. * * Retrieve the control ID. Note that the sub controls stack may have a special prefix * to distinguish them from regular controls, and from controls in other * sub stack. * * By default do nothing, and return the original id. * * @access protected * * @param string $control_base_id Control base ID. * * @return string Control ID. */ protected function get_control_id( $control_base_id ) { return $control_base_id; } /** * Add new control. * * Register a single control to allow the user to set/update data. * * @access public * * @param string $id Control ID. * @param array $args Control arguments. * @param array $options * * @return bool True if added, False otherwise. */ public function add_control( $id, $args, $options = [] ) { return $this->parent->add_control( $this->get_control_id( $id ), $args, $options ); } /** * Update control. * * Change the value of an existing control. * * @access public * * @param string $id Control ID. * @param array $args Control arguments. Only the new fields you want to update. * @param array $options Optional. Some additional options. */ public function update_control( $id, $args, array $options = [] ) { $this->parent->update_control( $this->get_control_id( $id ), $args, $options ); } /** * Remove control. * * Unregister an existing control. * * @access public * * @param string $id Control ID. */ public function remove_control( $id ) { $this->parent->remove_control( $this->get_control_id( $id ) ); } /** * Add new group control. * * Register a set of related controls grouped together as a single unified * control. * * @access public * * @param string $group_name Group control name. * @param array $args Group control arguments. Default is an empty array. * @param array $options * */ public function add_group_control( $group_name, $args, $options = [] ) { $args['name'] = $this->get_control_id( $args['name'] ); $this->parent->add_group_control( $group_name, $args, $options ); } /** * Add new responsive control. * * Register a set of controls to allow editing based on user screen size. * * @access public * * @param string $id Responsive control ID. * @param array $args Responsive control arguments. * @param array $options */ public function add_responsive_control( $id, $args, $options = [] ) { $this->parent->add_responsive_control( $this->get_control_id( $id ), $args, $options ); } /** * Update responsive control. * * Change the value of an existing responsive control. * * @access public * * @param string $id Responsive control ID. * @param array $args Responsive control arguments. */ public function update_responsive_control( $id, $args ) { $this->parent->update_responsive_control( $this->get_control_id( $id ), $args ); } /** * Remove responsive control. * * Unregister an existing responsive control. * * @access public * * @param string $id Responsive control ID. */ public function remove_responsive_control( $id ) { $this->parent->remove_responsive_control( $this->get_control_id( $id ) ); } /** * Start controls section. * * Used to add a new section of controls to the stack. * * @access public * * @param string $id Section ID. * @param array $args Section arguments. */ public function start_controls_section( $id, $args = [] ) { $this->parent->start_controls_section( $this->get_control_id( $id ), $args ); } /** * End controls section. * * Used to close an existing open controls section. * * @access public */ public function end_controls_section() { $this->parent->end_controls_section(); } /** * Start controls tabs. * * Used to add a new set of tabs inside a section. * * @access public * * @param string $id Control ID. */ public function start_controls_tabs( $id ) { $this->parent->start_controls_tabs( $this->get_control_id( $id ) ); } public function start_controls_tab( $id, $args ) { $this->parent->start_controls_tab( $this->get_control_id( $id ), $args ); } /** * End controls tabs. * * Used to close an existing open controls tabs. * * @access public */ public function end_controls_tab() { $this->parent->end_controls_tab(); } /** * End controls tabs. * * Used to close an existing open controls tabs. * * @access public */ public function end_controls_tabs() { $this->parent->end_controls_tabs(); } } PK!_5element-base.phpnu[depended_scripts[] = $handler; } /** * Add style depends. * * Register new style to enqueue by the handler. * * @since 1.9.0 * @access public * * @param string $handler Depend style handler. */ public function add_style_depends( $handler ) { $this->depended_styles[] = $handler; } /** * Get script dependencies. * * Retrieve the list of script dependencies the element requires. * * @since 1.3.0 * @access public * * @return array Element scripts dependencies. */ public function get_script_depends() { return $this->depended_scripts; } /** * Enqueue scripts. * * Registers all the scripts defined as element dependencies and enqueues * them. Use `get_script_depends()` method to add custom script dependencies. * * @since 1.3.0 * @access public */ final public function enqueue_scripts() { $deprecated_scripts = [ //Insert here when you have a deprecated script ]; foreach ( $this->get_script_depends() as $script ) { if ( isset( $deprecated_scripts[ $script ] ) ) { Utils::handle_deprecation( $script, $deprecated_scripts[ $script ]['version'], $deprecated_scripts[ $script ]['replacement'] ); } wp_enqueue_script( $script ); } } /** * Get style dependencies. * * Retrieve the list of style dependencies the element requires. * * @since 1.9.0 * @access public * * @return array Element styles dependencies. */ public function get_style_depends() { return $this->depended_styles; } /** * Enqueue styles. * * Registers all the styles defined as element dependencies and enqueues * them. Use `get_style_depends()` method to add custom style dependencies. * * @since 1.9.0 * @access public */ final public function enqueue_styles() { foreach ( $this->get_style_depends() as $style ) { wp_enqueue_style( $style ); } } /** * @since 1.0.0 * @deprecated 2.6.0 * @access public * @static */ final public static function add_edit_tool() {} /** * @since 2.2.0 * @deprecated 2.6.0 * @access public * @static */ final public static function is_edit_buttons_enabled() { return get_option( 'elementor_edit_buttons' ); } /** * Get default child type. * * Retrieve the default child type based on element data. * * Note that not all elements support children. * * @since 1.0.0 * @access protected * @abstract * * @param array $element_data Element data. * * @return Element_Base */ abstract protected function _get_default_child_type( array $element_data ); /** * Before element rendering. * * Used to add stuff before the element. * * @since 1.0.0 * @access public */ public function before_render() {} /** * After element rendering. * * Used to add stuff after the element. * * @since 1.0.0 * @access public */ public function after_render() {} /** * Get element title. * * Retrieve the element title. * * @since 1.0.0 * @access public * * @return string Element title. */ public function get_title() { return ''; } /** * Get element icon. * * Retrieve the element icon. * * @since 1.0.0 * @access public * * @return string Element icon. */ public function get_icon() { return 'eicon-columns'; } public function get_help_url() { return 'https://go.elementor.com/widget-' . $this->get_name(); } public function get_custom_help_url() { return ''; } /** * Whether the reload preview is required. * * Used to determine whether the reload preview is required or not. * * @since 1.0.0 * @access public * * @return bool Whether the reload preview is required. */ public function is_reload_preview_required() { return false; } /** * @since 2.3.1 * @access protected */ protected function should_print_empty() { return true; } /** * Whether the element returns dynamic content. * * set to determine whether to cache the element output or not. * * @since 3.22.0 * @access protected * * @return bool Whether to cache the element output. */ protected function is_dynamic_content(): bool { return true; } /** * Get child elements. * * Retrieve all the child elements of this element. * * @since 1.0.0 * @access public * * @return Element_Base[] Child elements. */ public function get_children() { if ( null === $this->children ) { $this->init_children(); } return $this->children; } /** * Get default arguments. * * Retrieve the element default arguments. Used to return all the default * arguments or a specific default argument, if one is set. * * @since 1.0.0 * @access public * * @param array $item Optional. Default is null. * * @return array Default argument(s). */ public function get_default_args( $item = null ) { return self::get_items( $this->default_args, $item ); } /** * Get panel presets. * * Used for displaying the widget in the panel multiple times, but with different defaults values, * icon, title etc. * * @since 3.16.0 * @access public * * @return array */ public function get_panel_presets() { return []; } /** * Add new child element. * * Register new child element to allow hierarchy. * * @since 1.0.0 * @access public * @param array $child_data Child element data. * @param array $child_args Child element arguments. * * @return Element_Base|false Child element instance, or false if failed. */ public function add_child( array $child_data, array $child_args = [] ) { if ( null === $this->children ) { $this->init_children(); } $child_type = $this->get_child_type( $child_data ); if ( ! $child_type ) { return false; } $child = Plugin::$instance->elements_manager->create_element_instance( $child_data, $child_args, $child_type ); if ( $child ) { $this->children[] = $child; } return $child; } /** * Add link render attributes. * * Used to add link tag attributes to a specific HTML element. * * The HTML link tag is represented by the element parameter. The `url_control` parameter * needs to be an array of link settings in the same format they are set by Elementor's URL control. * * Example usage: * * `$this->add_link_attributes( 'button', $settings['link'] );` * * @since 2.8.0 * @access public * * @param array|string $element The HTML element. * @param array $url_control Array of link settings. * @param bool $overwrite Optional. Whether to overwrite existing * attribute. Default is false, not to overwrite. * * @return Element_Base Current instance of the element. */ public function add_link_attributes( $element, array $url_control, $overwrite = false ) { $attributes = []; if ( ! empty( $url_control['url'] ) ) { $allowed_protocols = array_merge( wp_allowed_protocols(), [ 'skype', 'viber' ] ); $attributes['href'] = esc_url( $url_control['url'], $allowed_protocols ); } if ( ! empty( $url_control['is_external'] ) ) { $attributes['target'] = '_blank'; } if ( ! empty( $url_control['nofollow'] ) ) { $attributes['rel'] = 'nofollow'; } if ( ! empty( $url_control['custom_attributes'] ) ) { // Custom URL attributes should come as a string of comma-delimited key|value pairs $attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) ); } if ( $attributes ) { $this->add_render_attribute( $element, $attributes, null, $overwrite ); } return $this; } /** * Print element. * * Used to generate the element final HTML on the frontend and the editor. * * @since 1.0.0 * @access public */ public function print_element() { $element_type = $this->get_type(); if ( $this->should_render_shortcode() ) { echo '[elementor-element data="' . esc_attr( base64_encode( wp_json_encode( $this->get_raw_data() ) ) ) . '"]'; return; } /** * Before frontend element render. * * Fires before Elementor element is rendered in the frontend. * * @since 2.2.0 * * @param Element_Base $this The element. */ do_action( 'elementor/frontend/before_render', $this ); /** * Before frontend element render. * * Fires before Elementor element is rendered in the frontend. * * The dynamic portion of the hook name, `$element_type`, refers to the element type. * * @since 1.0.0 * * @param Element_Base $this The element. */ do_action( "elementor/frontend/{$element_type}/before_render", $this ); ob_start(); if ( $this->has_own_method( '_print_content', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_print_content', '3.1.0', __CLASS__ . '::print_content()' ); $this->_print_content(); } else { $this->print_content(); } $content = ob_get_clean(); $should_render = ( ! empty( $content ) || $this->should_print_empty() ); /** * Should the element be rendered for frontend * * Filters if the element should be rendered on frontend. * * @since 2.3.3 * * @param bool true The element. * @param Element_Base $this The element. */ $should_render = apply_filters( "elementor/frontend/{$element_type}/should_render", $should_render, $this ); if ( $should_render ) { if ( $this->has_own_method( '_add_render_attributes', self::class ) ) { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( '_add_render_attributes', '3.1.0', __CLASS__ . '::add_render_attributes()' ); $this->_add_render_attributes(); } else { $this->add_render_attributes(); } $this->before_render(); // PHPCS - The content has already been escaped by the `render` method. echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $this->after_render(); // TODO: Remove this in the future // Since version 3.24.0 page scripts/styles are handled by `page_assets`. $this->enqueue_scripts(); $this->enqueue_styles(); } /** * After frontend element render. * * Fires after Elementor element is rendered in the frontend. * * The dynamic portion of the hook name, `$element_type`, refers to the element type. * * @since 1.0.0 * * @param Element_Base $this The element. */ do_action( "elementor/frontend/{$element_type}/after_render", $this ); /** * After frontend element render. * * Fires after Elementor element is rendered in the frontend. * * @since 2.3.0 * * @param Element_Base $this The element. */ do_action( 'elementor/frontend/after_render', $this ); } protected function should_render_shortcode() { $should_render_shortcode = apply_filters( 'elementor/element/should_render_shortcode', false ); if ( ! $should_render_shortcode ) { return false; } $raw_data = $this->get_raw_data(); if ( ! empty( $raw_data['settings']['_element_cache'] ) ) { return 'yes' === $raw_data['settings']['_element_cache']; } if ( $this->is_dynamic_content() ) { return true; } $is_dynamic_content = apply_filters( 'elementor/element/is_dynamic_content', false, $raw_data, $this ); $has_dynamic_tag = $this->has_element_dynamic_tag( $raw_data['settings'] ); if ( $is_dynamic_content || $has_dynamic_tag ) { return true; } return false; } private function has_element_dynamic_tag( $element_settings ): bool { if ( is_array( $element_settings ) ) { if ( ! empty( $element_settings['__dynamic__'] ) ) { return true; } foreach ( $element_settings as $value ) { $has_dynamic = $this->has_element_dynamic_tag( $value ); if ( $has_dynamic ) { return true; } } } return false; } /** * Get the element raw data. * * Retrieve the raw element data, including the id, type, settings, child * elements and whether it is an inner element. * * The data with the HTML used always to display the data, but the Elementor * editor uses the raw data without the HTML in order not to render the data * again. * * @since 1.0.0 * @access public * * @param bool $with_html_content Optional. Whether to return the data with * HTML content or without. Used for caching. * Default is false, without HTML. * * @return array Element raw data. */ public function get_raw_data( $with_html_content = false ) { $data = $this->get_data(); $elements = []; foreach ( $this->get_children() as $child ) { $elements[] = $child->get_raw_data( $with_html_content ); } $raw_data = [ 'id' => $this->get_id(), 'elType' => $data['elType'], 'settings' => $data['settings'], 'elements' => $elements, 'isInner' => $data['isInner'], ]; if ( ! empty( $data['isLocked'] ) ) { $raw_data['isLocked'] = $data['isLocked']; } return $raw_data; } public function get_data_for_save() { $data = $this->get_raw_data(); $elements = []; foreach ( $this->get_children() as $child ) { $elements[] = $child->get_data_for_save(); } if ( ! empty( $elements ) ) { $data['elements'] = $elements; } if ( ! empty( $data['settings'] ) ) { $data['settings'] = $this->on_save( $data['settings'] ); } return $data; } /** * Get unique selector. * * Retrieve the unique selector of the element. Used to set a unique HTML * class for each HTML element. This way Elementor can set custom styles for * each element. * * @since 1.0.0 * @access public * * @return string Unique selector. */ public function get_unique_selector() { return '.elementor-element-' . $this->get_id(); } /** * Is type instance. * * Used to determine whether the element is an instance of that type or not. * * @since 1.0.0 * @access public * * @return bool Whether the element is an instance of that type. */ public function is_type_instance() { return $this->is_type_instance; } /** * On import update dynamic content (e.g. post and term IDs). * * @since 3.8.0 * * @param array $config The config of the passed element. * @param array $data The data that requires updating/replacement when imported. * @param array|null $controls The available controls. * * @return array Element data. */ public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array { $tags_manager = Plugin::$instance->dynamic_tags; if ( empty( $config['settings'][ $tags_manager::DYNAMIC_SETTING_KEY ] ) ) { return $config; } foreach ( $config['settings'][ $tags_manager::DYNAMIC_SETTING_KEY ] as $dynamic_name => $dynamic_value ) { $tag_config = $tags_manager->tag_text_to_tag_data( $dynamic_value ); $tag_instance = $tags_manager->create_tag( $tag_config['id'], $tag_config['name'], $tag_config['settings'] ); if ( is_null( $tag_instance ) ) { continue; } if ( $tag_instance->has_own_method( 'on_import_replace_dynamic_content' ) ) { // TODO: Remove this check in the future. $tag_config = $tag_instance->on_import_replace_dynamic_content( $tag_config, $data['post_ids'] ); } else { $tag_config = $tag_instance->on_import_update_dynamic_content( $tag_config, $data, $tag_instance->get_controls() ); } $config['settings'][ $tags_manager::DYNAMIC_SETTING_KEY ][ $dynamic_name ] = $tags_manager->tag_data_to_tag_text( $tag_config['id'], $tag_config['name'], $tag_config['settings'] ); } return $config; } /** * Add render attributes. * * Used to add attributes to the current element wrapper HTML tag. * * @since 1.3.0 * @access protected * @deprecated 3.1.0 Use `add_render_attribute()` method instead. */ protected function _add_render_attributes() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'add_render_attributes()' ); return $this->add_render_attributes(); } /** * Add render attributes. * * Used to add attributes to the current element wrapper HTML tag. * * @since 3.1.0 * @access protected */ protected function add_render_attributes() { $id = $this->get_id(); $settings = $this->get_settings_for_display(); $frontend_settings = $this->get_frontend_settings(); $controls = $this->get_controls(); $this->add_render_attribute( '_wrapper', [ 'class' => [ 'elementor-element', 'elementor-element-' . $id, ], 'data-id' => $id, 'data-element_type' => $this->get_type(), ] ); $class_settings = []; foreach ( $settings as $setting_key => $setting ) { if ( isset( $controls[ $setting_key ]['prefix_class'] ) ) { if ( isset( $controls[ $setting_key ]['classes_dictionary'][ $setting ] ) ) { $value = $controls[ $setting_key ]['classes_dictionary'][ $setting ]; } else { $value = $setting; } $class_settings[ $setting_key ] = $value; } } foreach ( $class_settings as $setting_key => $setting ) { if ( empty( $setting ) && '0' !== $setting ) { continue; } $this->add_render_attribute( '_wrapper', 'class', $controls[ $setting_key ]['prefix_class'] . $setting ); } $_animation = ! empty( $settings['_animation'] ); $animation = ! empty( $settings['animation'] ); $has_animation = $_animation && 'none' !== $settings['_animation'] || $animation && 'none' !== $settings['animation']; if ( $has_animation ) { $is_static_render_mode = Plugin::$instance->frontend->is_static_render_mode(); if ( ! $is_static_render_mode ) { // Hide the element until the animation begins $this->add_render_attribute( '_wrapper', 'class', 'elementor-invisible' ); } } if ( ! empty( $settings['_element_id'] ) ) { $this->add_render_attribute( '_wrapper', 'id', trim( $settings['_element_id'] ) ); } if ( $frontend_settings ) { $this->add_render_attribute( '_wrapper', 'data-settings', wp_json_encode( $frontend_settings ) ); } /** * After element attribute rendered. * * Fires after the attributes of the element HTML tag are rendered. * * @since 2.3.0 * * @param Element_Base $this The element. */ do_action( 'elementor/element/after_add_attributes', $this ); } /** * Register the Transform controls in the advanced tab of the element. * * Previously registered under the Widget_Common class, but registered a more fundamental level now to enable access from other widgets. * * @since 3.9.0 * @access protected * @return void */ protected function register_transform_section( $element_selector = '' ) { $default_unit_values_deg = []; $default_unit_values_ms = []; // Set the default unit sizes for all active breakpoints. foreach ( Breakpoints_Manager::get_default_config() as $breakpoint_name => $breakpoint_config ) { $default_unit_values_deg[ $breakpoint_name ] = [ 'default' => [ 'unit' => 'deg', ], ]; $default_unit_values_ms[ $breakpoint_name ] = [ 'default' => [ 'unit' => 'ms', ], ]; } $this->start_controls_section( '_section_transform', [ 'label' => esc_html__( 'Transform', 'elementor' ), 'tab' => Controls_Manager::TAB_ADVANCED, ] ); $this->start_controls_tabs( '_tabs_positioning' ); $transform_prefix_class = 'e-'; $transform_return_value = 'transform'; $transform_selector_class = ' > .elementor-widget-container'; $transform_css_modifier = ''; if ( 'con' === $element_selector ) { $transform_selector_class = '.e-' . $element_selector; $transform_css_modifier = $element_selector . '-'; } foreach ( [ '', '_hover' ] as $tab ) { $state = '_hover' === $tab ? ':hover' : ''; $this->start_controls_tab( "_tab_positioning{$tab}", [ 'label' => '' === $tab ? esc_html__( 'Normal', 'elementor' ) : esc_html__( 'Hover', 'elementor' ), ] ); $this->add_control( "_transform_rotate_popover{$tab}", [ 'label' => esc_html__( 'Rotate', 'elementor' ), 'type' => Controls_Manager::POPOVER_TOGGLE, 'prefix_class' => $transform_prefix_class, 'return_value' => $transform_return_value, ] ); $this->start_popover(); $this->add_responsive_control( "_transform_rotateZ_effect{$tab}", [ 'label' => esc_html__( 'Rotate', 'elementor' ) . ' (deg)', 'type' => Controls_Manager::SLIDER, 'device_args' => $default_unit_values_deg, 'range' => [ 'px' => [ 'min' => -360, 'max' => 360, ], ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateZ: {{SIZE}}deg', ], 'condition' => [ "_transform_rotate_popover{$tab}!" => '', ], 'frontend_available' => true, ] ); $this->add_control( "_transform_rotate_3d{$tab}", [ 'label' => esc_html__( '3D Rotate', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'On', 'elementor' ), 'label_off' => esc_html__( 'Off', 'elementor' ), 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateX: 1{{UNIT}}; --e-' . $transform_css_modifier . 'transform-perspective: 20px;', ], 'condition' => [ "_transform_rotate_popover{$tab}!" => '', ], ] ); $this->add_responsive_control( "_transform_rotateX_effect{$tab}", [ 'label' => esc_html__( 'Rotate X', 'elementor' ) . ' (deg)', 'type' => Controls_Manager::SLIDER, 'device_args' => $default_unit_values_deg, 'range' => [ 'px' => [ 'min' => -360, 'max' => 360, ], ], 'condition' => [ "_transform_rotate_3d{$tab}!" => '', "_transform_rotate_popover{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateX: {{SIZE}}deg;', ], 'frontend_available' => true, ] ); $this->add_responsive_control( "_transform_rotateY_effect{$tab}", [ 'label' => esc_html__( 'Rotate Y', 'elementor' ) . ' (deg)', 'type' => Controls_Manager::SLIDER, 'device_args' => $default_unit_values_deg, 'range' => [ 'px' => [ 'min' => -360, 'max' => 360, ], ], 'condition' => [ "_transform_rotate_3d{$tab}!" => '', "_transform_rotate_popover{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-rotateY: {{SIZE}}deg;', ], 'frontend_available' => true, ] ); $this->add_responsive_control( "_transform_perspective_effect{$tab}", [ 'label' => esc_html__( 'Perspective', 'elementor' ) . ' (px)', 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'max' => 1000, ], ], 'condition' => [ "_transform_rotate_popover{$tab}!" => '', "_transform_rotate_3d{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-perspective: {{SIZE}}px', ], 'frontend_available' => true, ] ); $this->end_popover(); $this->add_control( "_transform_translate_popover{$tab}", [ 'label' => esc_html__( 'Offset', 'elementor' ), 'type' => Controls_Manager::POPOVER_TOGGLE, 'prefix_class' => $transform_prefix_class, 'return_value' => $transform_return_value, ] ); $this->start_popover(); $this->add_responsive_control( "_transform_translateX_effect{$tab}", [ 'label' => esc_html__( 'Offset X', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ], 'range' => [ '%' => [ 'min' => -100, 'max' => 100, ], 'px' => [ 'min' => -1000, 'max' => 1000, ], ], 'condition' => [ "_transform_translate_popover{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-translateX: {{SIZE}}{{UNIT}};', ], 'frontend_available' => true, ] ); $this->add_responsive_control( "_transform_translateY_effect{$tab}", [ 'label' => esc_html__( 'Offset Y', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', '%', 'em', 'rem', 'vh', 'custom' ], 'range' => [ '%' => [ 'min' => -100, 'max' => 100, ], 'px' => [ 'min' => -1000, 'max' => 1000, ], ], 'condition' => [ "_transform_translate_popover{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-translateY: {{SIZE}}{{UNIT}};', ], 'frontend_available' => true, ] ); $this->end_popover(); $this->add_control( "_transform_scale_popover{$tab}", [ 'label' => esc_html__( 'Scale', 'elementor' ), 'type' => Controls_Manager::POPOVER_TOGGLE, 'prefix_class' => $transform_prefix_class, 'return_value' => $transform_return_value, ] ); $this->start_popover(); $this->add_control( "_transform_keep_proportions{$tab}", [ 'label' => esc_html__( 'Keep Proportions', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'On', 'elementor' ), 'label_off' => esc_html__( 'Off', 'elementor' ), 'default' => 'yes', ] ); $this->add_responsive_control( "_transform_scale_effect{$tab}", [ 'label' => esc_html__( 'Scale', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'max' => 2, 'step' => 0.1, ], ], 'condition' => [ "_transform_scale_popover{$tab}!" => '', "_transform_keep_proportions{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-scale: {{SIZE}};', ], 'frontend_available' => true, ] ); $this->add_responsive_control( "_transform_scaleX_effect{$tab}", [ 'label' => esc_html__( 'Scale X', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'max' => 2, 'step' => 0.1, ], ], 'condition' => [ "_transform_scale_popover{$tab}!" => '', "_transform_keep_proportions{$tab}" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-scaleX: {{SIZE}};', ], 'frontend_available' => true, ] ); $this->add_responsive_control( "_transform_scaleY_effect{$tab}", [ 'label' => esc_html__( 'Scale Y', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'max' => 2, 'step' => 0.1, ], ], 'condition' => [ "_transform_scale_popover{$tab}!" => '', "_transform_keep_proportions{$tab}" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-scaleY: {{SIZE}};', ], 'frontend_available' => true, ] ); $this->end_popover(); $this->add_control( "_transform_skew_popover{$tab}", [ 'label' => esc_html__( 'Skew', 'elementor' ), 'type' => Controls_Manager::POPOVER_TOGGLE, 'prefix_class' => $transform_prefix_class, 'return_value' => $transform_return_value, ] ); $this->start_popover(); $this->add_responsive_control( "_transform_skewX_effect{$tab}", [ 'label' => esc_html__( 'Skew X', 'elementor' ) . ' (deg)', 'type' => Controls_Manager::SLIDER, 'device_args' => $default_unit_values_deg, 'range' => [ 'px' => [ 'min' => -360, 'max' => 360, ], ], 'condition' => [ "_transform_skew_popover{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-skewX: {{SIZE}}deg;', ], 'frontend_available' => true, ] ); $this->add_responsive_control( "_transform_skewY_effect{$tab}", [ 'label' => esc_html__( 'Skew Y', 'elementor' ) . ' (deg)', 'type' => Controls_Manager::SLIDER, 'device_args' => $default_unit_values_deg, 'range' => [ 'px' => [ 'min' => -360, 'max' => 360, ], ], 'condition' => [ "_transform_skew_popover{$tab}!" => '', ], 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-skewY: {{SIZE}}deg;', ], 'frontend_available' => true, ] ); $this->end_popover(); $this->add_control( "_transform_flipX_effect{$tab}", [ 'label' => esc_html__( 'Flip Horizontal', 'elementor' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'transform' => [ 'title' => esc_html__( 'Flip Horizontal', 'elementor' ), 'icon' => 'eicon-flip eicon-tilted', ], ], 'prefix_class' => $transform_prefix_class, 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-flipX: -1', ], 'frontend_available' => true, ] ); $this->add_control( "_transform_flipY_effect{$tab}", [ 'label' => esc_html__( 'Flip Vertical', 'elementor' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'transform' => [ 'title' => esc_html__( 'Flip Vertical', 'elementor' ), 'icon' => 'eicon-flip', ], ], 'prefix_class' => $transform_prefix_class, 'selectors' => [ "{{WRAPPER}}{$transform_selector_class}{$state}" => '--e-' . $transform_css_modifier . 'transform-flipY: -1', ], 'frontend_available' => true, ] ); if ( '_hover' === $tab ) { $this->add_control( '_transform_transition_hover', [ 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (ms)', 'type' => Controls_Manager::SLIDER, 'device_args' => $default_unit_values_ms, 'range' => [ 'px' => [ 'min' => 0, 'max' => 10000, 'step' => 100, ], ], 'selectors' => [ '{{WRAPPER}}' => '--e-' . $transform_css_modifier . 'transform-transition-duration: {{SIZE}}ms', ], ] ); } ${"transform_origin_conditions{$tab}"} = [ [ 'name' => "_transform_scale_popover{$tab}", 'operator' => '!=', 'value' => '', ], [ 'name' => "_transform_rotate_popover{$tab}", 'operator' => '!=', 'value' => '', ], [ 'name' => "_transform_flipX_effect{$tab}", 'operator' => '!=', 'value' => '', ], [ 'name' => "_transform_flipY_effect{$tab}", 'operator' => '!=', 'value' => '', ], ]; $this->end_controls_tab(); } $this->end_controls_tabs(); $transform_origin_conditions = [ 'relation' => 'or', 'terms' => array_merge( $transform_origin_conditions, $transform_origin_conditions_hover ), ]; // Will override motion effect transform-origin $this->add_responsive_control( 'motion_fx_transform_x_anchor_point', [ 'label' => esc_html__( 'X Anchor Point', 'elementor' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'left' => [ 'title' => esc_html__( 'Left', 'elementor' ), 'icon' => 'eicon-h-align-left', ], 'center' => [ 'title' => esc_html__( 'Center', 'elementor' ), 'icon' => 'eicon-h-align-center', ], 'right' => [ 'title' => esc_html__( 'Right', 'elementor' ), 'icon' => 'eicon-h-align-right', ], ], 'conditions' => $transform_origin_conditions, 'separator' => 'before', 'selectors' => [ '{{WRAPPER}}' => '--e-' . $transform_css_modifier . 'transform-origin-x: {{VALUE}}', ], ] ); // Will override motion effect transform-origin $this->add_responsive_control( 'motion_fx_transform_y_anchor_point', [ 'label' => esc_html__( 'Y Anchor Point', 'elementor' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'top' => [ 'title' => esc_html__( 'Top', 'elementor' ), 'icon' => 'eicon-v-align-top', ], 'center' => [ 'title' => esc_html__( 'Center', 'elementor' ), 'icon' => 'eicon-v-align-middle', ], 'bottom' => [ 'title' => esc_html__( 'Bottom', 'elementor' ), 'icon' => 'eicon-v-align-bottom', ], ], 'conditions' => $transform_origin_conditions, 'selectors' => [ '{{WRAPPER}}' => '--e-' . $transform_css_modifier . 'transform-origin-y: {{VALUE}}', ], ] ); $this->end_controls_section(); } /** * Add Hidden Device Controls * * Adds controls for hiding elements within certain devices' viewport widths. Adds a control for each active device. * * @since 3.4.0 * @access protected */ protected function add_hidden_device_controls() { // The 'Hide On X' controls are displayed from largest to smallest, while the method returns smallest to largest. $active_devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] ); $active_breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints(); foreach ( $active_devices as $breakpoint_key ) { $label = 'desktop' === $breakpoint_key ? esc_html__( 'Desktop', 'elementor' ) : $active_breakpoints[ $breakpoint_key ]->get_label(); $this->add_control( 'hide_' . $breakpoint_key, [ 'label' => sprintf( /* translators: %s: Device name. */ esc_html__( 'Hide On %s', 'elementor' ), $label ), 'type' => Controls_Manager::SWITCHER, 'default' => '', 'prefix_class' => 'elementor-', 'label_on' => esc_html__( 'Hide', 'elementor' ), 'label_off' => esc_html__( 'Show', 'elementor' ), 'return_value' => 'hidden-' . $breakpoint_key, ] ); } } /** * Get default data. * * Retrieve the default element data. Used to reset the data on initialization. * * @since 1.0.0 * @access protected * * @return array Default data. */ protected function get_default_data() { $data = parent::get_default_data(); return array_merge( $data, [ 'elements' => [], 'isInner' => false, ] ); } /** * Print element content. * * Output the element final HTML on the frontend. * * @since 1.0.0 * @access protected * @deprecated 3.1.0 Use `print_content()` method instead. */ protected function _print_content() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0', 'print_content()' ); $this->print_content(); } /** * Print element content. * * Output the element final HTML on the frontend. * * @since 3.1.0 * @access protected */ protected function print_content() { foreach ( $this->get_children() as $child ) { $child->print_element(); } } /** * Get initial config. * * Retrieve the current element initial configuration. * * Adds more configuration on top of the controls list and the tabs assigned * to the control. This method also adds element name, type, icon and more. * * @since 2.9.0 * @access protected * * @return array The initial config. */ protected function get_initial_config() { $config = [ 'name' => $this->get_name(), 'elType' => $this->get_type(), 'title' => $this->get_title(), 'icon' => $this->get_icon(), 'reload_preview' => $this->is_reload_preview_required(), ]; if ( preg_match( '/^' . __NAMESPACE__ . '(Pro)?\\\\/', get_called_class() ) ) { $config['help_url'] = $this->get_help_url(); } else { $config['help_url'] = $this->get_custom_help_url(); } if ( ! $this->is_editable() ) { $config['editable'] = false; } return $config; } /** * A Base method for sanitizing the settings before save. * This method is meant to be overridden by the element. */ protected function on_save( array $settings ) { return $settings; } /** * Get child type. * * Retrieve the element child type based on element data. * * @since 2.0.0 * @access private * * @param array $element_data Element ID. * * @return Element_Base|false Child type or false if type not found. */ private function get_child_type( $element_data ) { $child_type = $this->_get_default_child_type( $element_data ); // If it's not a valid widget ( like a deactivated plugin ) if ( ! $child_type ) { return false; } /** * Element child type. * * Filters the child type of the element. * * @since 1.0.0 * * @param Element_Base $child_type The child element. * @param array $element_data The original element ID. * @param Element_Base $this The original element. */ $child_type = apply_filters( 'elementor/element/get_child_type', $child_type, $element_data, $this ); return $child_type; } /** * Initialize children. * * Initializing the element child elements. * * @since 2.0.0 * @access private */ private function init_children() { $this->children = []; $children_data = $this->get_data( 'elements' ); if ( ! $children_data ) { return; } foreach ( $children_data as $child_data ) { if ( ! $child_data ) { continue; } $this->add_child( $child_data ); } } /** * Element base constructor. * * Initializing the element base class using `$data` and `$args`. * * The `$data` parameter is required for a normal instance because of the * way Elementor renders data when initializing elements. * * @since 1.0.0 * @access public * * @param array $data Optional. Element data. Default is an empty array. * @param array|null $args Optional. Element default arguments. Default is null. **/ public function __construct( array $data = [], array $args = null ) { if ( $data ) { $this->is_type_instance = false; } elseif ( $args ) { $this->default_args = $args; } parent::__construct( $data ); } } PK! module.phpnu[reflection ) { $this->reflection = new \ReflectionClass( $this ); } return $this->reflection; } /** * Add module component. * * Add new component to the current module. * * @since 1.7.0 * @access public * * @param string $id Component ID. * @param mixed $instance An instance of the component. */ public function add_component( $id, $instance ) { $this->components[ $id ] = $instance; } /** * @since 2.3.0 * @access public * @return Module[] */ public function get_components() { return $this->components; } /** * Get module component. * * Retrieve the module component. * * @since 1.7.0 * @access public * * @param string $id Component ID. * * @return mixed An instance of the component, or `false` if the component * doesn't exist. */ public function get_component( $id ) { if ( isset( $this->components[ $id ] ) ) { return $this->components[ $id ]; } return false; } /** * Get assets url. * * @since 2.3.0 * @access protected * * @param string $file_name * @param string $file_extension * @param string $relative_url Optional. Default is null. * @param string $add_min_suffix Optional. Default is 'default'. * * @return string */ final protected function get_assets_url( $file_name, $file_extension, $relative_url = null, $add_min_suffix = 'default' ) { static $is_test_mode = null; if ( null === $is_test_mode ) { $is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS; } if ( ! $relative_url ) { $relative_url = $this->get_assets_relative_url() . $file_extension . '/'; } $url = $this->get_assets_base_url() . $relative_url . $file_name; if ( 'default' === $add_min_suffix ) { $add_min_suffix = ! $is_test_mode; } if ( $add_min_suffix ) { $url .= '.min'; } return $url . '.' . $file_extension; } /** * Get js assets url * * @since 2.3.0 * @access protected * * @param string $file_name * @param string $relative_url Optional. Default is null. * @param string $add_min_suffix Optional. Default is 'default'. * * @return string */ final protected function get_js_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default' ) { return $this->get_assets_url( $file_name, 'js', $relative_url, $add_min_suffix ); } /** * Get css assets url * * @since 2.3.0 * @access protected * * @param string $file_name * @param string $relative_url Optional. Default is null. * @param string $add_min_suffix Optional. Default is 'default'. * @param bool $add_direction_suffix Optional. Default is `false` * * @return string */ final protected function get_css_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default', $add_direction_suffix = false ) { static $direction_suffix = null; if ( ! $direction_suffix ) { $direction_suffix = is_rtl() ? '-rtl' : ''; } if ( $add_direction_suffix ) { $file_name .= $direction_suffix; } return $this->get_assets_url( $file_name, 'css', $relative_url, $add_min_suffix ); } /** * Get Frontend File URL * * Returns the URL for the CSS file to be loaded in the front end. If requested via the second parameter, a custom * file is generated based on a passed template file name. Otherwise, the URL for the default CSS file is returned. * * @since 3.24.0 * * @access public * * @param string $file_name * @param boolean $has_custom_breakpoints * * @return string frontend file URL */ public function get_frontend_file_url( $file_name, $has_custom_breakpoints ) { return Plugin::$instance->frontend->get_frontend_file_url( $file_name, $has_custom_breakpoints ); } /** * Get assets base url * * @since 2.6.0 * @access protected * * @return string */ protected function get_assets_base_url() { return ELEMENTOR_URL; } /** * Get assets relative url * * @since 2.3.0 * @access protected * * @return string */ protected function get_assets_relative_url() { return 'assets/'; } /** * Get the module's associated widgets. * * @return string[] */ protected function get_widgets() { return []; } /** * Initialize the module related widgets. */ public function init_widgets() { $widget_manager = Plugin::instance()->widgets_manager; foreach ( $this->get_widgets() as $widget ) { $class_name = $this->get_reflection()->getNamespaceName() . '\Widgets\\' . $widget; $widget_manager->register( new $class_name() ); } } public function __construct() { add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] ); } } PK!%%providers/social-network-provider.phpnu[ $data ) { $icons[ $network ] = $data['icon']; } } return $icons; } public static function get_icon_mapping( string $platform ): string { static::init_social_networks_array_if_empty(); if ( isset( self::$social_networks[ $platform ]['icon'] ) ) { return self::$social_networks[ $platform ]['icon']; } return ''; } public static function get_name_mapping( string $platform ): string { static::init_social_networks_array_if_empty(); if ( isset( self::$social_networks[ $platform ]['name'] ) ) { return self::$social_networks[ $platform ]['name']; } return ''; } public static function get_text_mapping( string $platform ): string { static::init_social_networks_array_if_empty(); if ( isset( self::$social_networks[ $platform ]['text'] ) ) { return self::$social_networks[ $platform ]['text']; } return ''; } public static function get_social_networks_text( $providers = [] ): array { static::init_social_networks_array_if_empty(); static $texts = []; if ( empty( $texts ) ) { foreach ( static::$social_networks as $network => $data ) { $texts[ $network ] = $data['text']; } } if ( $providers ) { return array_intersect_key( $texts, array_flip( $providers ) ); } return $texts; } private static function init_social_networks_array_if_empty(): void { if ( ! empty( static::$social_networks ) ) { return; } static::$social_networks[ static::VCF ] = [ 'text' => esc_html__( 'Save contact (vCard)', 'elementor' ), 'icon' => 'fab fa-outlook', 'name' => 'vcf', ]; static::$social_networks[ static::FACEBOOK ] = [ 'text' => esc_html__( 'Facebook', 'elementor' ), 'icon' => 'fab fa-facebook', 'name' => 'facebook', ]; static::$social_networks[ static::TWITTER ] = [ 'text' => esc_html__( 'X (Twitter)', 'elementor' ), 'icon' => 'fab fa-x-twitter', 'name' => 'x-twitter', ]; static::$social_networks[ static::INSTAGRAM ] = [ 'text' => esc_html__( 'Instagram', 'elementor' ), 'icon' => 'fab fa-instagram', 'name' => 'instagram', ]; static::$social_networks[ static::LINKEDIN ] = [ 'text' => esc_html__( 'LinkedIn', 'elementor' ), 'icon' => 'fab fa-linkedin-in', 'name' => 'linkedin', ]; static::$social_networks[ static::PINTEREST ] = [ 'text' => esc_html__( 'Pinterest', 'elementor' ), 'icon' => 'fab fa-pinterest', 'name' => 'pinterest', ]; static::$social_networks[ static::YOUTUBE ] = [ 'text' => esc_html__( 'YouTube', 'elementor' ), 'icon' => 'fab fa-youtube', 'name' => 'youtube', ]; static::$social_networks[ static::TIKTOK ] = [ 'text' => esc_html__( 'TikTok', 'elementor' ), 'icon' => 'fab fa-tiktok', 'name' => 'tiktok', ]; static::$social_networks[ static::WHATSAPP ] = [ 'text' => esc_html__( 'WhatsApp', 'elementor' ), 'icon' => 'fab fa-whatsapp', 'name' => 'whatsapp', ]; static::$social_networks[ static::APPLEMUSIC ] = [ 'text' => esc_html__( 'Apple Music', 'elementor' ), 'icon' => 'fa fa-music', 'name' => 'apple-music', ]; static::$social_networks[ static::SPOTIFY ] = [ 'text' => esc_html__( 'Spotify', 'elementor' ), 'icon' => 'fab fa-spotify', 'name' => 'spotify', ]; static::$social_networks[ static::SOUNDCLOUD ] = [ 'text' => esc_html__( 'SoundCloud', 'elementor' ), 'icon' => 'fab fa-soundcloud', 'name' => 'soundcloud', ]; static::$social_networks[ static::BEHANCE ] = [ 'text' => esc_html__( 'Behance', 'elementor' ), 'icon' => 'fab fa-behance', 'name' => 'behance', ]; static::$social_networks[ static::DRIBBBLE ] = [ 'text' => esc_html__( 'Dribbble', 'elementor' ), 'icon' => 'fab fa-dribbble', 'name' => 'dribble', ]; static::$social_networks[ static::VIMEO ] = [ 'text' => esc_html__( 'Vimeo', 'elementor' ), 'icon' => 'fab fa-vimeo-v', 'name' => 'vimeo', ]; static::$social_networks[ static::WAZE ] = [ 'text' => esc_html__( 'Waze', 'elementor' ), 'icon' => 'fab fa-waze', 'name' => 'waze', ]; static::$social_networks[ static::MESSENGER ] = [ 'text' => esc_html__( 'Messenger', 'elementor' ), 'icon' => 'fab fa-facebook-messenger', 'name' => 'messenger', ]; static::$social_networks[ static::TELEPHONE ] = [ 'text' => esc_html__( 'Telephone', 'elementor' ), 'icon' => 'fas fa-phone-alt', 'name' => 'phone', ]; static::$social_networks[ static::EMAIL ] = [ 'text' => esc_html__( 'Email', 'elementor' ), 'icon' => 'fas fa-envelope', 'name' => 'email', ]; static::$social_networks[ static::URL ] = [ 'text' => esc_html__( 'URL', 'elementor' ), 'icon' => 'fas fa-globe', 'name' => 'url', ]; static::$social_networks[ static::FILE_DOWNLOAD ] = [ 'text' => esc_html__( 'File Download', 'elementor' ), 'icon' => 'fas fa-download', 'name' => 'download', ]; static::$social_networks[ static::SMS ] = [ 'text' => esc_html__( 'SMS', 'elementor' ), 'icon' => 'fas fa-sms', 'name' => 'sms', ]; static::$social_networks[ static::VIBER ] = [ 'text' => esc_html__( 'Viber', 'elementor' ), 'icon' => 'fab fa-viber', 'name' => 'viber', ]; static::$social_networks[ static::SKYPE ] = [ 'text' => esc_html__( 'Skype', 'elementor' ), 'icon' => 'fab fa-skype', 'name' => 'skype', ]; } public static function build_messenger_link( string $username ) { return 'https://m.me/' . $username; } public static function build_email_link( array $data, string $prefix ) { $email = $data[ $prefix . '_mail' ] ?? ''; $subject = $data[ $prefix . '_mail_subject' ] ?? ''; $body = $data[ $prefix . '_mail_body' ] ?? ''; if ( ! $email ) { return ''; } $link = 'mailto:' . $email; if ( $subject ) { $link .= '?subject=' . $subject; } if ( $body ) { $link .= $subject ? '&' : '?'; $link .= 'body=' . $body; } return $link; } public static function build_viber_link( string $action, string $number ) { if ( empty( $number ) ) { return ''; } return add_query_arg( [ 'number' => urlencode( $number ), ], 'viber://' . $action ); } } PK!~Cv'traits/shared-widget-controls-trait.phpnu[ 0, 'max' => 10, 'step' => 1, ]; protected function add_html_tag_control( string $name, string $default = 'h2' ): void { $this->add_control( $name, [ 'label' => esc_html__( 'HTML Tag', 'elementor' ), 'type' => Controls_Manager::SELECT, 'options' => [ 'h1' => 'H1', 'h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'h5' => 'H5', 'h6' => 'H6', 'div' => 'div', 'span' => 'span', 'p' => 'p', ], 'default' => $default, ] ); } /** * Remove any child arrays where all properties are empty */ protected function clean_array( $input_array = [] ) { $output_array = array_filter( $input_array, function( $sub_array ) { // Use array_filter on the sub array $filtered_sub_array = array_filter( $sub_array, function( $val ) { // Filter out empty or null values return ! is_null( $val ) && '' !== $val; } ); // A non-empty result means the sub array contains some non-empty value(s) return ! empty( $filtered_sub_array ); } ); return $output_array; } protected function get_link_attributes( $link = [], $other_attributes = [] ) { $url_attrs = []; $rel_string = ''; if ( ! empty( $link['url'] ) ) { $url_attrs['href'] = esc_url( $link['url'] ); } if ( ! empty( $link['is_external'] ) ) { $url_attrs['target'] = '_blank'; $rel_string .= 'noopener '; } if ( ! empty( $link['nofollow'] ) ) { $rel_string .= 'nofollow '; } if ( ! empty( $rel_string ) ) { $url_attrs['rel'] = $rel_string; } /** * Note - we deliberately merge $other_attributes second * to allow overriding default attributes values such as a more formatted href */ $url_combined_attrs = array_merge( $url_attrs, $other_attributes, Utils::parse_custom_attributes( $link['custom_attributes'] ?? '' ), ); return $url_combined_attrs; } protected function add_icons_per_row_control( string $name = 'icons_per_row', $options = [ '2' => '2', '3' => '3', ], string $default = '3', $label = '', $selector_custom_property = '--e-link-in-bio-icon-columns' ): void { if ( ! $label ) { $label = esc_html__( 'Icons Per Row', 'elementor' ); } $this->add_control( $name, [ 'label' => $label, 'type' => Controls_Manager::SELECT, 'options' => $options, 'default' => $default, 'render_type' => 'template', 'selectors' => [ '{{WRAPPER}} .e-link-in-bio' => $selector_custom_property . ': {{VALUE}};', ], ] ); } protected function add_slider_control( string $name, array $args = [] ): void { $default_args = [ 'type' => Controls_Manager::SLIDER, 'default' => [ 'unit' => 'px', ], 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ], 'range' => [ 'px' => [ 'min' => 0, 'max' => 100, 'step' => 1, ], ], ]; $this->add_control( $name, array_merge_recursive( $default_args, $args ) ); } protected function add_borders_control( string $prefix, array $show_border_args = [], array $border_width_args = [], array $border_color_args = [] ): void { $show_border = [ 'label' => esc_html__( 'Border', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'elementor' ), 'label_off' => esc_html__( 'No', 'elementor' ), 'return_value' => 'yes', 'default' => '', ]; $this->add_control( $prefix . '_show_border', array_merge( $show_border, $show_border_args ) ); $condition = [ $prefix . '_show_border' => 'yes', ]; if ( isset( $border_width_args['condition'] ) ) { $condition = array_merge( $condition, $border_width_args['condition'] ); unset( $border_width_args['condition'] ); } $border_width = [ 'label' => esc_html__( 'Border Width', 'elementor' ) . ' (px)', 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px' ], 'range' => [ 'px' => $this->border_width_range, ], 'condition' => $condition, 'default' => [ 'unit' => 'px', 'size' => 1, ], ]; $this->add_responsive_control( $prefix . '_border_width', array_merge( $border_width, $border_width_args ), ); $condition = [ $prefix . '_show_border' => 'yes', ]; if ( isset( $border_color_args['condition'] ) ) { $condition = array_merge( $condition, $border_color_args['condition'] ); unset( $border_color_args['condition'] ); } $border_color = [ 'label' => esc_html__( 'Border Color', 'elementor' ), 'type' => Controls_Manager::COLOR, 'condition' => $condition, 'default' => '#000000', ]; $this->add_control( $prefix . '_border_color', array_merge( $border_color, $border_color_args ) ); } protected function get_shape_divider( $side = 'bottom' ) { $settings = $this->settings; $base_setting_key = "identity_section_style_cover_divider_$side"; $file_name = $settings[ $base_setting_key ]; if ( empty( $file_name ) ) { return []; } $negative = ! empty( $settings[ $base_setting_key . '_negative' ] ); $shape_path = Shapes::get_shape_path( $file_name, $negative ); if ( ! is_file( $shape_path ) || ! is_readable( $shape_path ) ) { return []; } return [ 'negative' => $negative, 'svg' => Utils::file_get_contents( $shape_path ), ]; } protected function print_shape_divider( $side = 'bottom' ) { $shape_divider = $this->get_shape_divider( $side ); if ( empty( $shape_divider ) ) { return; } ?>
breakpoints->get_active_devices_list( [ 'reverse' => true ] ); $active_breakpoint_instances = Plugin::$instance->breakpoints->get_active_breakpoints(); $devices_options = []; foreach ( $active_devices as $device_key ) { $device_label = 'desktop' === $device_key ? esc_html__( 'Desktop', 'elementor' ) : $active_breakpoint_instances[ $device_key ]->get_label(); $devices_options[ $device_key ] = $device_label; } return [ 'active_devices' => $active_devices, 'devices_options' => $devices_options, ]; } protected function add_hover_animation_control( string $name, array $args = [] ): void { $this->add_control( $name, array_merge( [ 'label' => esc_html__( 'Hover Animation', 'elementor' ), 'type' => Hover_Animation_Floating_Buttons::TYPE, 'frontend_available' => true, 'default' => 'grow', ], $args ) ); } } PK!Gapp.phpnu[get_name(); $js_var = 'elementor' . str_replace( ' ', '', ucwords( str_replace( '-', ' ', $name ) ) ) . 'Config'; $config = $this->get_settings() + $this->get_components_config(); if ( ! $handle ) { $handle = 'elementor-' . $name; } Utils::print_js_config( $handle, $js_var, $config ); } /** * Get components config. * * Retrieves the app components settings. * * @since 2.3.0 * @access private * * @return array */ private function get_components_config() { $settings = []; foreach ( $this->get_components() as $id => $instance ) { $settings[ $id ] = $instance->get_settings(); } return $settings; } } PK!` background-task-manager.phpnu[logger->get_logger(); $logger->info( $this->get_plugin_name() . '::' . $this->get_action() . ' Started' ); } public function on_runner_complete( $did_tasks = false ) { $logger = Plugin::$instance->logger->get_logger(); $logger->info( $this->get_plugin_name() . '::' . $this->get_action() . ' Completed' ); } public function get_task_runner() { if ( empty( $this->task_runner ) ) { $class_name = $this->get_task_runner_class(); $this->task_runner = new $class_name( $this ); } return $this->task_runner; } // TODO: Replace with a db settings system. protected function add_flag( $flag ) { add_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag, 1 ); } protected function get_flag( $flag ) { return get_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag ); } protected function delete_flag( $flag ) { delete_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag ); } protected function get_start_action_url() { return wp_nonce_url( add_query_arg( $this->get_action(), 'run' ), $this->get_action() . 'run' ); } protected function get_continue_action_url() { return wp_nonce_url( add_query_arg( $this->get_action(), 'continue' ), $this->get_action() . 'continue' ); } private function continue_run() { $runner = $this->get_task_runner(); $runner->continue_run(); } public function __construct() { if ( empty( $_GET[ $this->get_action() ] ) ) { return; } Plugin::$instance->init_common(); if ( 'run' === $_GET[ $this->get_action() ] && check_admin_referer( $this->get_action() . 'run' ) ) { $this->start_run(); } if ( 'continue' === $_GET[ $this->get_action() ] && check_admin_referer( $this->get_action() . 'continue' ) ) { $this->continue_run(); } wp_safe_redirect( remove_query_arg( [ $this->get_action(), '_wpnonce' ] ) ); die; } } PK!Yz#z#background-task.phpnu[get_current_item(); if ( empty( $item['total'] ) ) { $sql = preg_replace( '/^SELECT/', 'SELECT SQL_CALC_FOUND_ROWS', $sql ); } // Add offset & limit. $sql = preg_replace( '/;$/', '', $sql ); $sql .= ' LIMIT %d, %d;'; $results = $wpdb->get_col( $wpdb->prepare( $sql, $this->get_current_offset(), $this->get_limit() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared if ( ! empty( $results ) ) { $this->set_total(); } return $results; } public function should_run_again( $updated_rows ) { return count( $updated_rows ) === $this->get_limit(); } public function get_current_offset() { $limit = $this->get_limit(); return ( $this->current_item['iterate_num'] - 1 ) * $limit; } public function get_limit() { return $this->manager->get_query_limit(); } public function set_total() { global $wpdb; if ( empty( $this->current_item['total'] ) ) { $total_rows = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); $total_iterates = ceil( $total_rows / $this->get_limit() ); $this->current_item['total'] = $total_iterates; } } /** * Complete * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). */ protected function complete() { $this->manager->on_runner_complete( true ); parent::complete(); } public function continue_run() { // Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck(). // This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running. do_action( $this->cron_hook_identifier ); } /** * @return mixed */ public function get_current_item() { return $this->current_item; } /** * Get batch. * * @return \stdClass Return the first batch from the queue. */ protected function get_batch() { $batch = parent::get_batch(); $batch->data = array_filter( (array) $batch->data ); return $batch; } /** * Handle cron healthcheck * * Restart the background process if not already running * and data exists in the queue. */ public function handle_cron_healthcheck() { if ( $this->is_process_running() ) { // Background process already running. return; } if ( $this->is_queue_empty() ) { // No data to process. $this->clear_scheduled_event(); return; } $this->handle(); } /** * Schedule fallback event. */ protected function schedule_event() { if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier ); } } /** * Is the updater running? * * @return boolean */ public function is_running() { return false === $this->is_queue_empty(); } /** * See if the batch limit has been exceeded. * * @return bool */ protected function batch_limit_exceeded() { return $this->time_exceeded() || $this->memory_exceeded(); } /** * Handle. * * Pass each queue item to the task handler, while remaining * within server memory and time limit constraints. */ protected function handle() { $this->manager->on_runner_start(); $this->lock_process(); do { $batch = $this->get_batch(); foreach ( $batch->data as $key => $value ) { $task = $this->task( $value ); if ( false !== $task ) { $batch->data[ $key ] = $task; } else { unset( $batch->data[ $key ] ); } if ( $this->batch_limit_exceeded() ) { // Batch limits reached. break; } } // Update or delete current batch. if ( ! empty( $batch->data ) ) { $this->update( $batch->key, $batch->data ); } else { $this->delete( $batch->key ); } } while ( ! $this->batch_limit_exceeded() && ! $this->is_queue_empty() ); $this->unlock_process(); // Start next batch or complete process. if ( ! $this->is_queue_empty() ) { $this->dispatch(); } else { $this->complete(); } } /** * Use the protected `is_process_running` method as a public method. * @return bool */ public function is_process_locked() { return $this->is_process_running(); } public function handle_immediately( $callbacks ) { $this->manager->on_runner_start(); $this->lock_process(); foreach ( $callbacks as $callback ) { $item = [ 'callback' => $callback, ]; do { $item = $this->task( $item ); } while ( $item ); } $this->unlock_process(); } /** * Task * * Override this method to perform any actions required on each * queue item. Return the modified item for further processing * in the next pass through. Or, return false to remove the * item from the queue. * * @param array $item * * @return array|bool */ protected function task( $item ) { $result = false; if ( ! isset( $item['iterate_num'] ) ) { $item['iterate_num'] = 1; } $logger = Plugin::$instance->logger->get_logger(); $callback = $this->format_callback_log( $item ); if ( is_callable( $item['callback'] ) ) { $progress = ''; if ( 1 < $item['iterate_num'] ) { if ( empty( $item['total'] ) ) { $progress = sprintf( '(x%s)', $item['iterate_num'] ); } else { $percent = ceil( $item['iterate_num'] / ( $item['total'] / 100 ) ); $progress = sprintf( '(%s of %s, %s%%)', $item['iterate_num'], $item['total'], $percent ); } } $logger->info( sprintf( '%s Start %s', $callback, $progress ) ); $this->current_item = $item; $result = (bool) call_user_func( $item['callback'], $this ); // get back the updated item. $item = $this->current_item; $this->current_item = null; if ( $result ) { if ( empty( $item['total'] ) ) { $logger->info( sprintf( '%s callback needs to run again', $callback ) ); } elseif ( 1 === $item['iterate_num'] ) { $logger->info( sprintf( '%s callback needs to run more %d times', $callback, $item['total'] - $item['iterate_num'] ) ); } $item['iterate_num']++; } else { $logger->info( sprintf( '%s Finished', $callback ) ); } } else { $logger->notice( sprintf( 'Could not find %s callback', $callback ) ); } return $result ? $item : false; } /** * Schedule cron healthcheck. * * @param array $schedules Schedules. * @return array */ public function schedule_cron_healthcheck( $schedules ) { $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); // Adds every 5 minutes to the existing schedules. $schedules[ $this->identifier . '_cron_interval' ] = array( 'interval' => MINUTE_IN_SECONDS * $interval, 'display' => sprintf( /* translators: %d: Interval in minutes. */ esc_html__( 'Every %d minutes', 'elementor' ), $interval ), ); return $schedules; } /** * See if the batch limit has been exceeded. * * @return bool */ public function is_memory_exceeded() { return $this->memory_exceeded(); } /** * Delete all batches. * * @return self */ public function delete_all_batches() { global $wpdb; $table = $wpdb->options; $column = 'option_name'; if ( is_multisite() ) { $table = $wpdb->sitemeta; $column = 'meta_key'; } $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; $wpdb->query( $wpdb->prepare( "DELETE FROM {$table} WHERE {$column} LIKE %s", $key ) ); // @codingStandardsIgnoreLine. return $this; } /** * Kill process. * * Stop processing queue items, clear cronjob and delete all batches. */ public function kill_process() { if ( ! $this->is_queue_empty() ) { $this->delete_all_batches(); wp_clear_scheduled_hook( $this->cron_hook_identifier ); } } public function set_current_item( $item ) { $this->current_item = $item; } protected function format_callback_log( $item ) { return implode( '::', (array) $item['callback'] ); } /** * @var \Elementor\Core\Base\Background_Task_Manager */ protected $manager; public function __construct( $manager ) { $this->manager = $manager; // Uses unique prefix per blog so each blog has separate queue. $this->prefix = 'elementor_' . get_current_blog_id(); $this->action = $this->manager->get_action(); parent::__construct(); } } PK!*ˆ document.phpnu[ Utils::generate_random_string(), 'elType' => 'container', 'elements' => $internal_elements, ], ]; } /** * @param array $internal_elements * * @return array[] */ private function get_sections_elements_data( array $internal_elements ): array { return [ [ 'id' => Utils::generate_random_string(), 'elType' => 'section', 'elements' => [ [ 'id' => Utils::generate_random_string(), 'elType' => 'column', 'elements' => $internal_elements, ], ], ], ]; } /** * @since 2.1.0 * @access protected * @static */ protected static function get_editor_panel_categories() { return Plugin::$instance->elements_manager->get_categories(); } /** * Get properties. * * Retrieve the document properties. * * @since 2.0.0 * @access public * @static * * @return array Document properties. */ public static function get_properties() { return [ 'has_elements' => true, 'is_editable' => true, 'edit_capability' => '', 'show_in_finder' => true, 'show_on_admin_bar' => true, 'support_kit' => false, 'show_navigator' => true, 'allow_adding_widgets' => true, 'support_page_layout' => true, 'show_copy_and_share' => false, 'library_close_title' => esc_html__( 'Close', 'elementor' ), 'publish_button_title' => esc_html__( 'Publish', 'elementor' ), 'allow_closing_remote_library' => true, ]; } /** * @since 2.1.0 * @access public * @static */ public static function get_editor_panel_config() { $default_route = 'panel/elements/categories'; if ( ! Plugin::instance()->role_manager->user_can( 'design' ) ) { $default_route = 'panel/page-settings/settings'; } return [ 'title' => static::get_title(), // JS Container title. 'widgets_settings' => [], 'elements_categories' => self::get_filtered_editor_panel_categories(), 'default_route' => $default_route, 'has_elements' => static::get_property( 'has_elements' ), 'support_kit' => static::get_property( 'support_kit' ), 'messages' => [ 'publish_notification' => sprintf( /* translators: %s: Document title. */ esc_html__( 'Hurray! Your %s is live.', 'elementor' ), static::get_title() ), ], 'show_navigator' => static::get_property( 'show_navigator' ), 'allow_adding_widgets' => static::get_property( 'allow_adding_widgets' ), 'show_copy_and_share' => static::get_property( 'show_copy_and_share' ), 'library_close_title' => static::get_property( 'library_close_title' ), 'publish_button_title' => static::get_property( 'publish_button_title' ), 'allow_closing_remote_library' => static::get_property( 'allow_closing_remote_library' ), ]; } public static function get_filtered_editor_panel_categories(): array { $categories = static::get_editor_panel_categories(); $has_pro = Utils::has_pro(); foreach ( $categories as $index => $category ) { if ( isset( $category['promotion'] ) ) { $categories = self::get_panel_category_item( $category['promotion'], $index, $categories, $has_pro ); } } return $categories; } /** * @param $promotion * @param $index * @param array $categories * * @return array */ private static function get_panel_category_item( $promotion, $index, array $categories, bool $has_pro ): array { if ( ! $has_pro ) { $categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data( $promotion, 'elementor/panel/' . $index . '/custom_promotion', 'url' ); } else { unset( $categories[ $index ]['promotion'] ); } return $categories; } /** * Get element title. * * Retrieve the element title. * * @since 2.0.0 * @access public * @static * * @return string Element title. */ public static function get_title() { return esc_html__( 'Document', 'elementor' ); } public static function get_plural_title() { return static::get_title(); } public static function get_add_new_title() { return sprintf( /* translators: %s: Document title. */ esc_html__( 'Add New %s', 'elementor' ), static::get_title() ); } /** * Get property. * * Retrieve the document property. * * @since 2.0.0 * @access public * @static * * @param string $key The property key. * * @return mixed The property value. */ public static function get_property( $key ) { $id = static::get_class_full_name(); if ( ! isset( self::$properties[ $id ] ) ) { self::$properties[ $id ] = static::get_properties(); } return self::get_items( self::$properties[ $id ], $key ); } /** * @since 2.0.0 * @access public * @static */ public static function get_class_full_name() { return get_called_class(); } public static function get_create_url() { $properties = static::get_properties(); // BC Support - Each document should define it own CPT this code is for BC support. $cpt = Source_Local::CPT; if ( isset( $properties['cpt'][0] ) ) { $cpt = $properties['cpt'][0]; } return Plugin::$instance->documents->get_create_new_post_url( $cpt, static::get_type() ); } public function get_name() { return static::get_type(); } /** * @since 2.0.0 * @access public */ public function get_unique_name() { return static::get_type() . '-' . $this->post->ID; } /** * @since 2.3.0 * @access public */ public function get_post_type_title() { $post_type_object = get_post_type_object( $this->post->post_type ); return $post_type_object->labels->singular_name; } /** * @since 2.0.0 * @access public */ public function get_main_id() { if ( ! $this->main_id ) { $post_id = $this->post->ID; $parent_post_id = wp_is_post_revision( $post_id ); if ( $parent_post_id ) { $post_id = $parent_post_id; } $this->main_id = $post_id; } return $this->main_id; } /** * @return null|Lock_Behavior */ public static function get_lock_behavior_v2() { return null; } /** * @since 2.0.0 * @access public * * @param $data * * @throws \Exception If the widget was not found. * * @return string */ public function render_element( $data ) { // Start buffering ob_start(); /** @var Widget_Base $widget */ $widget = Plugin::$instance->elements_manager->create_element_instance( $data ); if ( ! $widget ) { throw new \Exception( 'Widget not found.' ); } $widget->render_content(); $render_html = ob_get_clean(); return $render_html; } /** * @since 2.0.0 * @access public */ public function get_main_post() { return get_post( $this->get_main_id() ); } public function get_container_attributes() { $id = $this->get_main_id(); $attributes = [ 'data-elementor-type' => $this->get_name(), 'data-elementor-id' => $id, 'class' => 'elementor elementor-' . $id, ]; $version_meta = $this->get_main_meta( '_elementor_version' ); if ( version_compare( $version_meta, '2.5.0', '<' ) ) { $attributes['class'] .= ' elementor-bc-flex-widget'; } if ( Plugin::$instance->preview->is_preview() ) { $attributes['data-elementor-title'] = static::get_title(); } else { $elementor_settings = $this->get_frontend_settings(); if ( ! empty( $elementor_settings ) ) { $attributes['data-elementor-settings'] = wp_json_encode( $elementor_settings ); } } // apply this filter to allow the attributes to be modified by different sources return apply_filters( 'elementor/document/wrapper_attributes', $attributes, $this ); } /** * @since 2.0.0 * @access public */ public function get_wp_preview_url() { $main_post_id = $this->get_main_id(); $document = $this; // Ajax request from editor. $initial_document_id = Utils::get_super_global_value( $_POST, 'initial_document_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( ! empty( $initial_document_id ) ) { $document = Plugin::$instance->documents->get( $initial_document_id ); // phpcs:ignore WordPress.Security.NonceVerification.Missing } $url = get_preview_post_link( $document->get_main_id(), [ 'preview_id' => $main_post_id, 'preview_nonce' => wp_create_nonce( 'post_preview_' . $main_post_id ), ] ); /** * Document "WordPress preview" URL. * * Filters the WordPress preview URL. * * @since 2.0.0 * * @param string $url WordPress preview URL. * @param Document $this The document instance. */ $url = apply_filters( 'elementor/document/urls/wp_preview', $url, $this ); return $url; } /** * @since 2.0.0 * @access public */ public function get_exit_to_dashboard_url() { $url = get_edit_post_link( $this->get_main_id(), 'raw' ); /** * Document "exit to dashboard" URL. * * Filters the "Exit To Dashboard" URL. * * @since 2.0.0 * * @param string $url The exit URL * @param Document $this The document instance. */ $url = apply_filters( 'elementor/document/urls/exit_to_dashboard', $url, $this ); return $url; } /** * Get All Post Type URL * * Get url of the page which display all the posts of the current active document's post type. * * @since 3.7.0 * * @return string $url */ public function get_all_post_type_url() { $post_type = get_post_type( $this->get_main_id() ); $url = get_admin_url() . 'edit.php'; if ( 'post' !== $post_type ) { $url .= '?post_type=' . $post_type; } /** * Document "display all post type" URL. * * @since 3.7.0 * * @param string $url The URL. * @param Document $this The document instance. */ $url = apply_filters( 'elementor/document/urls/all_post_type', $url, $this ); return $url; } /** * Get Main WP dashboard URL. * * @since 3.7.0 * * @return string $url */ protected function get_main_dashboard_url() { $url = get_dashboard_url(); /** * Document "Main Dashboard" URL. * * @since 3.7.0 * * @param string $url The URL. * @param Document $this The document instance. */ $url = apply_filters( 'elementor/document/urls/main_dashboard', $url, $this ); return $url; } /** * Get auto-saved post revision. * * Retrieve the auto-saved post revision that is newer than current post. * * @since 2.0.0 * @access public * * * @return bool|Document */ public function get_newer_autosave() { $autosave = $this->get_autosave(); // Detect if there exists an autosave newer than the post. if ( $autosave && mysql2date( 'U', $autosave->get_post()->post_modified_gmt, false ) > mysql2date( 'U', $this->post->post_modified_gmt, false ) ) { return $autosave; } return false; } /** * @since 2.0.0 * @access public */ public function is_autosave() { return wp_is_post_autosave( $this->post->ID ); } /** * Check if the current document is a 'revision' * * @return bool */ public function is_revision() { return 'revision' === $this->post->post_type; } /** * Checks if the current document status is 'trash'. * * @return bool */ public function is_trash() { return 'trash' === $this->post->post_status; } /** * @since 2.0.0 * @access public * * @param int $user_id * @param bool $create * * @return bool|Document */ public function get_autosave( $user_id = 0, $create = false ) { if ( ! $user_id ) { $user_id = get_current_user_id(); } $autosave_id = $this->get_autosave_id( $user_id ); if ( $autosave_id ) { $document = Plugin::$instance->documents->get( $autosave_id ); } elseif ( $create ) { $autosave_id = wp_create_post_autosave( [ 'post_ID' => $this->post->ID, 'post_type' => $this->post->post_type, 'post_title' => $this->post->post_title, 'post_excerpt' => $this->post->post_excerpt, // Hack to cause $autosave_is_different=true in `wp_create_post_autosave`. 'post_content' => '', 'post_modified' => current_time( 'mysql' ), ] ); Plugin::$instance->db->copy_elementor_meta( $this->post->ID, $autosave_id ); $document = Plugin::$instance->documents->get( $autosave_id ); $document->save_template_type(); } else { $document = false; } return $document; } /** * Add/Remove edit link in dashboard. * * Add or remove an edit link to the post/page action links on the post/pages list table. * * Fired by `post_row_actions` and `page_row_actions` filters. * * @access public * * @param array $actions An array of row action links. * * @return array An updated array of row action links. */ public function filter_admin_row_actions( $actions ) { if ( $this->is_built_with_elementor() && $this->is_editable_by_current_user() ) { $actions['edit_with_elementor'] = sprintf( '
%2$s', $this->get_edit_url(), __( 'Edit with Elementor', 'elementor' ) ); } return $actions; } /** * @since 2.0.0 * @access public */ public function is_editable_by_current_user() { $edit_capability = static::get_property( 'edit_capability' ); if ( $edit_capability && ! current_user_can( $edit_capability ) ) { return false; } return self::get_property( 'is_editable' ) && User::is_current_user_can_edit( $this->get_main_id() ); } /** * @since 2.9.0 * @access protected */ protected function get_initial_config() { // Get document data *after* the scripts hook - so plugins can run compatibility before get data, but *before* enqueue the editor script - so elements can enqueue their own scripts that depended in editor script. $locked_user = Plugin::$instance->editor->get_locked_user( $this->get_main_id() ); if ( $locked_user ) { $locked_user = $locked_user->display_name; } $post = $this->get_main_post(); $post_type_object = get_post_type_object( $post->post_type ); $settings = SettingsManager::get_settings_managers_config(); $config = [ 'id' => $this->get_main_id(), 'type' => $this->get_name(), 'version' => $this->get_main_meta( '_elementor_version' ), 'settings' => $settings['page'], 'remoteLibrary' => $this->get_remote_library_config(), 'last_edited' => $this->get_last_edited(), 'panel' => static::get_editor_panel_config(), 'container' => 'body', 'post_type_title' => $this->get_post_type_title(), 'user' => [ 'can_publish' => current_user_can( $post_type_object->cap->publish_posts ), // Deprecated config since 2.9.0. 'locked' => $locked_user, ], 'urls' => [ 'exit_to_dashboard' => $this->get_exit_to_dashboard_url(), // WP post type edit page 'all_post_type' => $this->get_all_post_type_url(), 'preview' => $this->get_preview_url(), 'wp_preview' => $this->get_wp_preview_url(), 'permalink' => $this->get_permalink(), 'have_a_look' => $this->get_have_a_look_url(), 'main_dashboard' => $this->get_main_dashboard_url(), ], ]; $post_status_object = get_post_status_object( $post->post_status ); if ( $post_status_object ) { $config['status'] = [ 'value' => $post_status_object->name, 'label' => $post_status_object->label, ]; } do_action( 'elementor/document/before_get_config', $this ); if ( static::get_property( 'has_elements' ) ) { $container_config = []; $experiments_manager = Plugin::$instance->experiments; if ( $experiments_manager->is_feature_active( 'container' ) ) { $container_config = [ 'container' => Plugin::$instance->elements_manager->get_element_types( 'container' )->get_config(), ]; } $config['elements'] = $this->get_elements_raw_data( null, true ); $config['widgets'] = $container_config + Plugin::$instance->widgets_manager->get_widget_types_config(); } $additional_config = []; /** * Additional document configuration. * * Filters the document configuration by adding additional configuration. * External developers can use this hook to add custom configuration in * addition to Elementor's initial configuration. * * Use the $post_id to add custom configuration for different pages. * * @param array $additional_config The additional document configuration. * @param int $post_id The post ID of the document. */ $additional_config = apply_filters( 'elementor/document/config', $additional_config, $this->get_main_id() ); if ( ! empty( $additional_config ) ) { $config = array_replace_recursive( $config, $additional_config ); } return $config; } /** * @since 3.1.0 * @access protected */ protected function register_controls() { $this->register_document_controls(); /** * Register document controls. * * Fires after Elementor registers the document controls. * * External developers can use this hook to add new controls to the document. * * @since 2.0.0 * * @param Document $this The document instance. */ do_action( 'elementor/documents/register_controls', $this ); } /** * @since 2.0.0 * @access public * * @param $data * * @return bool */ public function save( $data ) { /** * Set locale to "C" to avoid issues with comma as decimal separator. * * @see https://github.com/elementor/elementor/issues/10992 */ $original_lc = setlocale( LC_NUMERIC, 0 ); setlocale( LC_NUMERIC, 'C' ); /** * Document save data. * * Filter the document data before saving process starts. * * External developers can use this hook to change the data before * saving it to the database. * * @since 3.3.0 * * @param array $data The document data. * @param \Elementor\Core\Base\Document $this The document instance. */ $data = apply_filters( 'elementor/document/save/data', $data, $this ); $this->add_handle_revisions_changed_filter(); if ( ! $this->is_editable_by_current_user() ) { return false; } $this->set_is_saving( true ); /** * Before document save. * * Fires when document save starts on Elementor. * * @since 2.5.12 * * @param \Elementor\Core\Base\Document $this The current document. * @param $data. */ do_action( 'elementor/document/before_save', $this, $data ); if ( ! current_user_can( 'unfiltered_html' ) ) { $data = wp_kses_post_deep( $data ); } if ( ! empty( $data['settings'] ) ) { if ( isset( $data['settings']['post_status'] ) && self::STATUS_AUTOSAVE === $data['settings']['post_status'] ) { if ( ! defined( 'DOING_AUTOSAVE' ) ) { define( 'DOING_AUTOSAVE', true ); } } $this->save_settings( $data['settings'] ); $this->refresh_post(); } // Don't check is_empty, because an empty array should be saved. if ( isset( $data['elements'] ) && is_array( $data['elements'] ) ) { $this->save_elements( $data['elements'] ); } $this->save_template_type(); $this->save_version(); // Remove Post CSS $post_css = Post_CSS::create( $this->post->ID ); $post_css->delete(); // Remove Document Cache $this->delete_cache(); /** * After document save. * * Fires when document save is complete. * * @since 2.5.12 * * @param \Elementor\Core\Base\Document $this The current document. * @param $data. */ do_action( 'elementor/document/after_save', $this, $data ); $this->set_is_saving( false ); $this->remove_handle_revisions_changed_filter(); setlocale( LC_NUMERIC, $original_lc ); return true; } public function refresh_post() { $this->post = get_post( $this->post->ID ); } /** * @param array $new_settings * * @return static */ public function update_settings( array $new_settings ) { $document_settings = $this->get_meta( PageManager::META_KEY ); if ( ! $document_settings ) { $document_settings = []; } $this->save_settings( array_replace_recursive( $document_settings, $new_settings ) ); return $this; } /** * Is built with Elementor. * * Check whether the post was built with Elementor. * * @since 2.0.0 * @access public * * @return bool Whether the post was built with Elementor. */ public function is_built_with_elementor() { return ! ! $this->get_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); } /** * Mark the post as "built with elementor" or not. * * @param bool $is_built_with_elementor * * @return $this */ public function set_is_built_with_elementor( $is_built_with_elementor ) { if ( $is_built_with_elementor ) { // Use the string `builder` and not a boolean for rollback compatibility $this->update_meta( self::BUILT_WITH_ELEMENTOR_META_KEY, 'builder' ); } else { $this->delete_meta( self::BUILT_WITH_ELEMENTOR_META_KEY ); } return $this; } /** * @since 2.0.0 * @access public * @static * * @return mixed */ public function get_edit_url() { $url = add_query_arg( [ 'post' => $this->get_main_id(), 'action' => 'elementor', ], admin_url( 'post.php' ) ); /** * Document edit url. * * Filters the document edit url. * * @since 2.0.0 * * @param string $url The edit url. * @param Document $this The document instance. */ $url = apply_filters( 'elementor/document/urls/edit', $url, $this ); return $url; } /** * @since 2.0.0 * @access public */ public function get_preview_url() { /** * Use a static var - to avoid change the `ver` parameter on every call. */ static $url; if ( empty( $url ) ) { add_filter( 'pre_option_permalink_structure', '__return_empty_string' ); $url = set_url_scheme( add_query_arg( [ 'elementor-preview' => $this->get_main_id(), 'ver' => time(), ], $this->get_permalink() ) ); remove_filter( 'pre_option_permalink_structure', '__return_empty_string' ); /** * Document preview URL. * * Filters the document preview URL. * * @since 2.0.0 * * @param string $url The preview URL. * @param Document $this The document instance. */ $url = apply_filters( 'elementor/document/urls/preview', $url, $this ); } return $url; } /** * @since 2.0.0 * @access public * * @param string $key * * @return array */ public function get_json_meta( $key ) { $meta = get_post_meta( $this->post->ID, $key, true ); if ( is_string( $meta ) && ! empty( $meta ) ) { $meta = json_decode( $meta, true ); } if ( empty( $meta ) ) { $meta = []; } return $meta; } public function update_json_meta( $key, $value ) { $this->update_meta( $key, // `wp_slash` in order to avoid the unslashing during the `update_post_meta` wp_slash( wp_json_encode( $value ) ) ); } /** * @since 2.0.0 * @access public * * @param null $data * @param bool $with_html_content * * @return array */ public function get_elements_raw_data( $data = null, $with_html_content = false ) { if ( ! static::get_property( 'has_elements' ) ) { return []; } if ( is_null( $data ) ) { $data = $this->get_elements_data(); } // Change the current documents, so widgets can use `documents->get_current` and other post data Plugin::$instance->documents->switch_to_document( $this ); $editor_data = []; foreach ( $data as $element_data ) { if ( ! is_array( $element_data ) ) { throw new \Exception( 'Invalid data: ' . wp_json_encode( [ 'data' => $data, 'element' => $element_data, ] ) ); } $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); if ( ! $element ) { continue; } if ( $this->is_saving ) { $element_data = $element->get_data_for_save(); } else { $element_data = $element->get_raw_data( $with_html_content ); } $editor_data[] = $element_data; } // End foreach(). Plugin::$instance->documents->restore_document(); return $editor_data; } /** * @since 2.0.0 * @access public * * @param string $status * * @return array */ public function get_elements_data( $status = self::STATUS_PUBLISH ) { $elements = $this->get_json_meta( '_elementor_data' ); if ( self::STATUS_DRAFT === $status ) { $autosave = $this->get_newer_autosave(); if ( is_object( $autosave ) ) { $autosave_elements = Plugin::$instance->documents ->get( $autosave->get_post()->ID ) ->get_json_meta( '_elementor_data' ); } } if ( Plugin::$instance->editor->is_edit_mode() ) { if ( empty( $elements ) && empty( $autosave_elements ) ) { // Convert to Elementor. $elements = $this->convert_to_elementor(); if ( $this->is_autosave() ) { Plugin::$instance->db->copy_elementor_meta( $this->post->post_parent, $this->post->ID ); } } } if ( ! empty( $autosave_elements ) ) { $elements = $autosave_elements; } return $elements; } /** * Get document setting from DB. * * @return array */ public function get_db_document_settings() { return $this->get_meta( static::PAGE_META_KEY ); } /** * @since 2.3.0 * @access public */ public function convert_to_elementor() { $this->save( [] ); if ( empty( $this->post->post_content ) ) { return []; } // Check if it's only a shortcode. preg_match_all( '/' . get_shortcode_regex() . '/', $this->post->post_content, $matches, PREG_SET_ORDER ); if ( ! empty( $matches ) ) { foreach ( $matches as $shortcode ) { if ( trim( $this->post->post_content ) === $shortcode[0] ) { $widget_type = Plugin::$instance->widgets_manager->get_widget_types( 'shortcode' ); $settings = [ 'shortcode' => $this->post->post_content, ]; break; } } } if ( empty( $widget_type ) ) { $widget_type = Plugin::$instance->widgets_manager->get_widget_types( 'text-editor' ); $settings = [ 'editor' => $this->post->post_content, ]; } // TODO: Better coding to start template for editor $converted_blocks = [ [ 'id' => Utils::generate_random_string(), 'elType' => $widget_type::get_type(), 'widgetType' => $widget_type->get_name(), 'settings' => $settings, ], ]; return Plugin::$instance->experiments->is_feature_active( 'container' ) ? $this->get_container_elements_data( $converted_blocks ) : $this->get_sections_elements_data( $converted_blocks ); } /** * @since 2.1.3 * @access public */ public function print_elements_with_wrapper( $elements_data = null ) { if ( ! $elements_data ) { $elements_data = $this->get_elements_data(); } ?>
get_container_attributes() ); ?>> print_elements( $elements_data ); ?>
sprintf( /* translators: %s: Document title. */ esc_html__( '%s Settings', 'elementor' ), static::get_title() ), ]; } /** * @since 2.0.0 * @access public */ public function get_post() { return $this->post; } /** * @since 2.0.0 * @access public */ public function get_permalink() { return get_permalink( $this->get_main_id() ); } /** * @since 2.0.8 * @access public */ public function get_content( $with_css = false ) { return Plugin::$instance->frontend->get_builder_content( $this->post->ID, $with_css ); } /** * @since 2.0.0 * @access public */ public function delete() { if ( 'revision' === $this->post->post_type ) { $deleted = wp_delete_post_revision( $this->post ); } else { $deleted = wp_delete_post( $this->post->ID ); } return $deleted && ! is_wp_error( $deleted ); } public function force_delete() { $deleted = wp_delete_post( $this->post->ID, true ); return $deleted && ! is_wp_error( $deleted ); } /** * On import update dynamic content (e.g. post and term IDs). * * @since 3.8.0 * * @param array $config The config of the passed element. * @param array $data The data that requires updating/replacement when imported. * @param array|null $controls The available controls. * * @return array Element data. */ public static function on_import_update_dynamic_content( array $config, array $data, $controls = null ) : array { foreach ( $config as &$element_config ) { $element_instance = Plugin::$instance->elements_manager->create_element_instance( $element_config ); if ( is_null( $element_instance ) ) { continue; } if ( $element_instance->has_own_method( 'on_import_replace_dynamic_content' ) ) { // TODO: Remove this check in the future. $element_config = $element_instance::on_import_replace_dynamic_content( $element_config, $data['post_ids'] ); } else { $element_config = $element_instance::on_import_update_dynamic_content( $element_config, $data, $element_instance->get_controls() ); } $element_config['elements'] = static::on_import_update_dynamic_content( $element_config['elements'], $data ); } return $config; } /** * Update dynamic settings in the document for import. * * @param array $settings The settings of the document. * @param array $config Import config to update the settings. * * @return array */ public function on_import_update_settings( array $settings, array $config ): array { $controls = $this->get_controls(); $controls_manager = Plugin::$instance->controls_manager; foreach ( $settings as $key => $value ) { if ( ! isset( $controls[ $key ] ) ) { continue; } $control = $controls[ $key ]; $control_instance = $controls_manager->get_control( $control['type'] ); if ( ! $control_instance ) { continue; } $settings[ $key ] = $control_instance->on_import_update_settings( $value, $control, $config ); } return $settings; } /** * Save editor elements. * * Save data from the editor to the database. * * @since 2.0.0 * @access protected * * @param array $elements */ protected function save_elements( $elements ) { $editor_data = $this->get_elements_raw_data( $elements ); // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` $json_value = wp_slash( wp_json_encode( $editor_data ) ); // Don't use `update_post_meta` that can't handle `revision` post type $is_meta_updated = update_metadata( 'post', $this->post->ID, '_elementor_data', $json_value ); /** * Before saving data. * * Fires before Elementor saves data to the database. * * @since 1.0.0 * * @param string $status Post status. * @param int|bool $is_meta_updated Meta ID if the key didn't exist, true on successful update, false on failure. */ do_action( 'elementor/db/before_save', $this->post->post_status, $is_meta_updated ); Plugin::$instance->db->save_plain_text( $this->post->ID ); $elements_iteration_actions = $this->get_elements_iteration_actions(); if ( $elements_iteration_actions ) { $this->iterate_elements( $elements, $elements_iteration_actions, 'save' ); } /** * After saving data. * * Fires after Elementor saves data to the database. * * @since 1.0.0 * * @param int $post_id The ID of the post. * @param array $editor_data Sanitize posted data. */ do_action( 'elementor/editor/after_save', $this->post->ID, $editor_data ); } /** * @since 2.0.0 * @access public * * @param int $user_id Optional. User ID. Default value is `0`. * * @return bool|int */ public function get_autosave_id( $user_id = 0 ) { if ( ! $user_id ) { $user_id = get_current_user_id(); } $autosave = Utils::get_post_autosave( $this->post->ID, $user_id ); if ( $autosave ) { return $autosave->ID; } return false; } public function save_version() { if ( ! defined( 'IS_ELEMENTOR_UPGRADE' ) ) { // Save per revision. $this->update_meta( '_elementor_version', ELEMENTOR_VERSION ); /** * Document version save. * * Fires when document version is saved on Elementor. * Will not fire during Elementor Upgrade. * * @since 2.5.12 * * @param \Elementor\Core\Base\Document $this The current document. * */ do_action( 'elementor/document/save_version', $this ); } } /** * @since 2.3.0 * @access public */ public function save_template_type() { return $this->update_main_meta( self::TYPE_META_KEY, $this->get_name() ); } /** * @since 2.3.0 * @access public */ public function get_template_type() { return $this->get_main_meta( self::TYPE_META_KEY ); } /** * @since 2.0.0 * @access public * * @param string $key Meta data key. * * @return mixed */ public function get_main_meta( $key ) { return get_post_meta( $this->get_main_id(), $key, true ); } /** * @since 2.0.4 * @access public * * @param string $key Meta data key. * @param mixed $value Meta data value. * * @return bool|int */ public function update_main_meta( $key, $value ) { return update_post_meta( $this->get_main_id(), $key, $value ); } /** * @since 2.0.4 * @access public * * @param string $key Meta data key. * @param string $value Optional. Meta data value. Default is an empty string. * * @return bool */ public function delete_main_meta( $key, $value = '' ) { return delete_post_meta( $this->get_main_id(), $key, $value ); } /** * @since 2.0.0 * @access public * * @param string $key Meta data key. * * @return mixed */ public function get_meta( $key ) { return get_post_meta( $this->post->ID, $key, true ); } /** * @since 2.0.0 * @access public * * @param string $key Meta data key. * @param mixed $value Meta data value. * * @return bool|int */ public function update_meta( $key, $value ) { // Use `update_metadata` in order to work also with revisions. return update_metadata( 'post', $this->post->ID, $key, $value ); } /** * @since 2.0.3 * @access public * * @param string $key Meta data key. * @param string $value Meta data value. * * @return bool */ public function delete_meta( $key, $value = '' ) { // Use `delete_metadata` in order to work also with revisions. return delete_metadata( 'post', $this->post->ID, $key, $value ); } /** * @since 2.0.0 * @access public */ public function get_last_edited() { $post = $this->post; $autosave_post = $this->get_autosave(); if ( $autosave_post ) { $post = $autosave_post->get_post(); } $date = date_i18n( _x( 'M j, H:i', 'revision date format', 'elementor' ), strtotime( $post->post_modified ) ); $display_name = get_the_author_meta( 'display_name', $post->post_author ); if ( $autosave_post || 'revision' === $post->post_type ) { $last_edited = sprintf( /* translators: 1: Saving date, 2: Author display name. */ esc_html__( 'Draft saved on %1$s by %2$s', 'elementor' ), '', $display_name ); } else { $last_edited = sprintf( /* translators: 1: Editing date, 2: Author display name. */ esc_html__( 'Last edited on %1$s by %2$s', 'elementor' ), '', $display_name ); } return $last_edited; } /** * @return bool */ public function is_saving() { return $this->is_saving; } /** * @param $is_saving * * @return $this */ public function set_is_saving( $is_saving ) { $this->is_saving = $is_saving; return $this; } /** * @since 2.0.0 * @access public * * @param array $data * * @throws \Exception If the post does not exist. */ public function __construct( array $data = [] ) { if ( $data ) { if ( empty( $data['post_id'] ) ) { $this->post = new \WP_Post( (object) [] ); } else { $this->post = get_post( $data['post_id'] ); if ( ! $this->post ) { throw new \Exception( sprintf( 'Post ID #%s does not exist.', $data['post_id'] ), Exceptions::NOT_FOUND ); } } // Each Control_Stack is based on a unique ID. $data['id'] = $data['post_id']; if ( ! isset( $data['settings'] ) ) { $data['settings'] = []; } $saved_settings = get_post_meta( $this->post->ID, '_elementor_page_settings', true ); if ( ! empty( $saved_settings ) && is_array( $saved_settings ) ) { $data['settings'] += $saved_settings; } } parent::__construct( $data ); } /* * Get Export Data * * Filters a document's data on export * * @since 3.2.0 * @access public * * @return array The data to export */ public function get_export_data() { $content = Plugin::$instance->db->iterate_data( $this->get_elements_data(), function( $element_data ) { $element_data['id'] = Utils::generate_random_string(); $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); // If the widget/element does not exist, like a plugin that creates a widget but deactivated. if ( ! $element ) { return null; } return $this->process_element_import_export( $element, 'on_export' ); } ); return [ 'content' => $content, 'settings' => $this->get_data( 'settings' ), 'metadata' => $this->get_export_metadata(), ]; } public function get_export_summary() { return [ 'title' => $this->post->post_title, 'doc_type' => $this->get_name(), 'thumbnail' => get_the_post_thumbnail_url( $this->post ), ]; } /* * Get Import Data * * Filters a document's data on import * * @since 3.2.0 * @access public * * @return array The data to import */ public function get_import_data( array $data ) { $data['content'] = Plugin::$instance->db->iterate_data( $data['content'], function( $element_data ) { $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); // If the widget/element isn't exist, like a plugin that creates a widget but deactivated if ( ! $element ) { return null; } return $this->process_element_import_export( $element, 'on_import' ); } ); if ( ! empty( $data['settings'] ) ) { $template_model = new Page_Model( [ 'id' => 0, 'settings' => $data['settings'], ] ); $page_data = $this->process_element_import_export( $template_model, 'on_import' ); $data['settings'] = $page_data['settings']; } return $data; } /** * Import * * Allows to import an external data to a document * * @since 3.2.0 * @access public * * @param array $data */ public function import( array $data ) { $data = $this->get_import_data( $data ); $this->save( [ 'elements' => $data['content'], 'settings' => $data['settings'], ] ); if ( $data['import_settings']['thumbnail'] ) { $attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( [ 'url' => $data['import_settings']['thumbnail'] ] ); set_post_thumbnail( $this->get_main_post(), $attachment['id'] ); } if ( ! empty( $data['metadata'] ) ) { foreach ( $data['metadata'] as $key => $value ) { $this->update_meta( $key, $value ); } } } public function process_element_import_export( Controls_Stack $element, $method, $element_data = null ) { if ( null === $element_data ) { $element_data = $element->get_data(); } if ( method_exists( $element, $method ) ) { // TODO: Use the internal element data without parameters. $element_data = $element->{$method}( $element_data ); } foreach ( $element->get_controls() as $control ) { $control_class = Plugin::$instance->controls_manager->get_control( $control['type'] ); // If the control isn't exist, like a plugin that creates the control but deactivated. if ( ! $control_class ) { return $element_data; } // Do not add default value to the final settings, if there is no value at the // data before the methods `on_import` or `on_export` called. $has_value = isset( $element_data['settings'][ $control['name'] ] ); if ( $has_value && method_exists( $control_class, $method ) ) { $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element_data['settings'][ $control['name'] ], $control ); } // On Export, check if the control has an argument 'export' => false. if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) { unset( $element_data['settings'][ $control['name'] ] ); } } return $element_data; } protected function get_export_metadata() { $metadata = get_post_meta( $this->get_main_id() ); foreach ( $metadata as $meta_key => $meta_value ) { if ( is_protected_meta( $meta_key, 'post' ) ) { unset( $metadata[ $meta_key ] ); continue; } $metadata[ $meta_key ] = $meta_value[0]; } return $metadata; } protected function get_remote_library_config() { $config = [ 'type' => 'block', 'default_route' => 'templates/blocks', 'category' => $this->get_name(), 'autoImportSettings' => false, ]; return $config; } /** * @since 2.0.4 * @access protected * * @param $settings */ protected function save_settings( $settings ) { $page_settings_manager = SettingsManager::get_settings_managers( 'page' ); $page_settings_manager->ajax_before_save_settings( $settings, $this->post->ID ); $page_settings_manager->save_settings( $settings, $this->post->ID ); } /** * @since 2.1.3 * @access protected */ protected function print_elements( $elements_data ) { if ( ! Plugin::$instance->experiments->is_feature_active( 'e_element_cache' ) ) { $this->do_print_elements( $elements_data ); return; } $cached_data = $this->get_document_cache(); if ( false === $cached_data ) { add_filter( 'elementor/element/should_render_shortcode', '__return_true' ); $scripts_to_queue = []; $styles_to_queue = []; global $wp_scripts, $wp_styles; $should_store_scripts = $wp_scripts instanceof \WP_Scripts && $wp_styles instanceof \WP_Styles; if ( $should_store_scripts ) { $scripts_ignored = $wp_scripts->queue; $styles_ignored = $wp_styles->queue; } ob_start(); $this->do_print_elements( $elements_data ); if ( $should_store_scripts ) { $scripts_to_queue = array_values( array_diff( $wp_scripts->queue, $scripts_ignored ) ); $styles_to_queue = array_values( array_diff( $wp_styles->queue, $styles_ignored ) ); } $cached_data = [ 'content' => ob_get_clean(), 'scripts' => $scripts_to_queue, 'styles' => $styles_to_queue, ]; if ( $this->should_store_cache_elements() ) { $this->set_document_cache( $cached_data ); } remove_filter( 'elementor/element/should_render_shortcode', '__return_true' ); } else { if ( ! empty( $cached_data['scripts'] ) ) { foreach ( $cached_data['scripts'] as $script_handle ) { wp_enqueue_script( $script_handle ); } } if ( ! empty( $cached_data['styles'] ) ) { foreach ( $cached_data['styles'] as $style_handle ) { wp_enqueue_style( $style_handle ); } } } if ( ! empty( $cached_data['content'] ) ) { echo do_shortcode( $cached_data['content'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } protected function do_print_elements( $elements_data ) { // Collect all data updaters that should be updated on runtime. $runtime_elements_iteration_actions = $this->get_runtime_elements_iteration_actions(); if ( $runtime_elements_iteration_actions ) { $this->iterate_elements( $elements_data, $runtime_elements_iteration_actions, 'render' ); } foreach ( $elements_data as $element_data ) { $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); if ( ! $element ) { continue; } $element->print_element(); } } public function set_document_cache( $value ) { $expiration_hours = get_option( 'elementor_element_cache_ttl', '' ); if ( empty( $expiration_hours ) || ! is_numeric( $expiration_hours ) ) { $expiration_hours = '24'; } $expiration_hours = absint( $expiration_hours ); $expiration = '+' . $expiration_hours . ' hours'; $data = [ 'timeout' => strtotime( $expiration, current_time( 'timestamp' ) ), 'value' => $value, ]; $this->update_json_meta( static::CACHE_META_KEY, $data ); } private function get_document_cache() { $cache = $this->get_json_meta( static::CACHE_META_KEY ); if ( empty( $cache['timeout'] ) ) { return false; } if ( current_time( 'timestamp' ) > $cache['timeout'] ) { return false; } if ( ! is_array( $cache['value'] ) ) { return false; } return $cache['value']; } protected function delete_cache() { $this->delete_meta( static::CACHE_META_KEY ); } private function should_store_cache_elements() { static $should_store_cache_elements = null; if ( null === $should_store_cache_elements ) { $should_store_cache_elements = ( ! is_admin() && ! Plugin::$instance->preview->is_preview_mode() ); } return $should_store_cache_elements; } protected function register_document_controls() { $this->start_controls_section( 'document_settings', [ 'label' => esc_html__( 'General Settings', 'elementor' ), 'tab' => Controls_Manager::TAB_SETTINGS, ] ); $this->add_control( 'post_title', [ 'label' => esc_html__( 'Title', 'elementor' ), 'type' => Controls_Manager::TEXT, 'default' => $this->post->post_title, 'label_block' => true, ] ); $post_type_object = get_post_type_object( $this->post->post_type ); $can_publish = $post_type_object && current_user_can( $post_type_object->cap->publish_posts ); $is_published = self::STATUS_PUBLISH === $this->post->post_status || self::STATUS_PRIVATE === $this->post->post_status; if ( $is_published || $can_publish || ! Plugin::$instance->editor->is_edit_mode() ) { $statuses = $this->get_post_statuses(); if ( 'future' === $this->get_main_post()->post_status ) { $statuses['future'] = esc_html__( 'Future', 'elementor' ); } $this->add_control( 'post_status', [ 'label' => esc_html__( 'Status', 'elementor' ), 'type' => Controls_Manager::SELECT, 'default' => $this->get_main_post()->post_status, 'options' => $statuses, ] ); } $this->end_controls_section(); } protected function get_post_statuses() { return get_post_statuses(); } protected function get_have_a_look_url() { return $this->get_permalink(); } public function handle_revisions_changed( $post_has_changed, $last_revision, $post ) { // In case default, didn't determine the changes. if ( ! $post_has_changed ) { $last_revision_id = $last_revision->ID; $last_revision_document = Plugin::instance()->documents->get( $last_revision_id ); $post_document = Plugin::instance()->documents->get( $post->ID ); $last_revision_settings = $last_revision_document->get_settings(); $post_settings = $post_document->get_settings(); // TODO: Its better to add crc32 signature for each revision and then only compare one part of the checksum. $post_has_changed = $last_revision_settings !== $post_settings; } return $post_has_changed; } private function add_handle_revisions_changed_filter() { add_filter( 'wp_save_post_revision_post_has_changed', [ $this, 'handle_revisions_changed' ], 10, 3 ); } private function remove_handle_revisions_changed_filter() { remove_filter( 'wp_save_post_revision_post_has_changed', [ $this, 'handle_revisions_changed' ] ); } private function get_runtime_elements_iteration_actions() { $runtime_elements_iteration_actions = []; $elements_iteration_actions = $this->get_elements_iteration_actions(); foreach ( $elements_iteration_actions as $elements_iteration_action ) { if ( $elements_iteration_action->is_action_needed() ) { $runtime_elements_iteration_actions[] = $elements_iteration_action; } } return $runtime_elements_iteration_actions; } private function iterate_elements( $elements, $elements_iteration_actions, $mode ) { $unique_page_elements = []; foreach ( $elements_iteration_actions as $elements_iteration_action ) { $elements_iteration_action->set_mode( $mode ); } Plugin::$instance->db->iterate_data( $elements, function( array $element_data ) use ( &$unique_page_elements, $elements_iteration_actions ) { $element_type = 'widget' === $element_data['elType'] ? $element_data['widgetType'] : $element_data['elType']; $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); if ( $element ) { if ( ! in_array( $element_type, $unique_page_elements, true ) ) { $unique_page_elements[] = $element_type; foreach ( $elements_iteration_actions as $elements_iteration_action ) { $elements_iteration_action->unique_element_action( $element ); } } foreach ( $elements_iteration_actions as $elements_iteration_action ) { $elements_iteration_action->element_action( $element ); } } return $element_data; } ); foreach ( $elements_iteration_actions as $elements_iteration_action ) { $elements_iteration_action->after_elements_iteration(); } } private function get_elements_iteration_actions() { if ( ! $this->elements_iteration_actions ) { $this->elements_iteration_actions[] = new Assets_Iteration_Action( $this ); } return $this->elements_iteration_actions; } } PK! B 'background-process/wp-async-request.phpnu[identifier = $this->prefix . '_' . $this->action; add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); } /** * Set data used during the request * * @param array $data Data. * * @return $this */ public function data( $data ) { $this->data = $data; return $this; } /** * Dispatch the async request * * @return array|\WP_Error */ public function dispatch() { $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); $args = $this->get_post_args(); return wp_remote_post( esc_url_raw( $url ), $args ); } /** * Get query args * * @return array */ protected function get_query_args() { if ( property_exists( $this, 'query_args' ) ) { return $this->query_args; } return array( 'action' => $this->identifier, 'nonce' => wp_create_nonce( $this->identifier ), ); } /** * Get query URL * * @return string */ protected function get_query_url() { if ( property_exists( $this, 'query_url' ) ) { return $this->query_url; } return admin_url( 'admin-ajax.php' ); } /** * Get post args * * @return array */ protected function get_post_args() { if ( property_exists( $this, 'post_args' ) ) { return $this->post_args; } return array( 'timeout' => 0.01, 'blocking' => false, 'body' => $this->data, 'cookies' => $_COOKIE, /** This filter is documented in wp-includes/class-wp-http-streams.php */ 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), ); } /** * Maybe handle * * Check for correct nonce and pass to handler. */ public function maybe_handle() { // Don't lock up other requests while processing session_write_close(); check_ajax_referer( $this->identifier, 'nonce' ); $this->handle(); wp_die(); } /** * Handle * * Override this method to perform any actions required * during the async request. */ abstract protected function handle(); } PK!'ڰ H+H+,background-process/wp-background-process.phpnu[cron_hook_identifier = $this->identifier . '_cron'; $this->cron_interval_identifier = $this->identifier . '_cron_interval'; add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); } /** * Dispatch * * @access public * @return array|\WP_Error */ public function dispatch() { // Schedule the cron healthcheck. $this->schedule_event(); // Perform remote post. return parent::dispatch(); } /** * Push to queue * * @param mixed $data Data. * * @return $this */ public function push_to_queue( $data ) { $this->data[] = $data; return $this; } /** * Save queue * * @return $this */ public function save() { $key = $this->generate_key(); if ( ! empty( $this->data ) ) { update_site_option( $key, $this->data ); } return $this; } /** * Update queue * * @param string $key Key. * @param array $data Data. * * @return $this */ public function update( $key, $data ) { if ( ! empty( $data ) ) { update_site_option( $key, $data ); } return $this; } /** * Delete queue * * @param string $key Key. * * @return $this */ public function delete( $key ) { delete_site_option( $key ); return $this; } /** * Generate key * * Generates a unique key based on microtime. Queue items are * given a unique key so that they can be merged upon save. * * @param int $length Length. * * @return string */ protected function generate_key( $length = 64 ) { $unique = md5( microtime() . rand() ); $prepend = $this->identifier . '_batch_'; return substr( $prepend . $unique, 0, $length ); } /** * Maybe process queue * * Checks whether data exists within the queue and that * the process is not already running. */ public function maybe_handle() { // Don't lock up other requests while processing session_write_close(); if ( $this->is_process_running() ) { // Background process already running. wp_die(); } if ( $this->is_queue_empty() ) { // No data to process. wp_die(); } check_ajax_referer( $this->identifier, 'nonce' ); $this->handle(); wp_die(); } /** * Is queue empty * * @return bool */ protected function is_queue_empty() { global $wpdb; $table = $wpdb->options; $column = 'option_name'; if ( is_multisite() ) { $table = $wpdb->sitemeta; $column = 'meta_key'; } $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared // Can't use placeholders for table/column names, it will be wrapped by a single quote (') instead of a backquote (`). $count = $wpdb->get_var( $wpdb->prepare( " SELECT COUNT(*) FROM {$table} WHERE {$column} LIKE %s ", $key ) ); // phpcs:enable return ( $count > 0 ) ? false : true; } /** * Is process running * * Check whether the current process is already running * in a background process. */ protected function is_process_running() { if ( get_site_transient( $this->identifier . '_process_lock' ) ) { // Process already running. return true; } return false; } /** * Lock process * * Lock the process so that multiple instances can't run simultaneously. * Override if applicable, but the duration should be greater than that * defined in the time_exceeded() method. */ protected function lock_process() { $this->start_time = time(); // Set start time of current process. $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); } /** * Unlock process * * Unlock the process so that other instances can spawn. * * @return $this */ protected function unlock_process() { delete_site_transient( $this->identifier . '_process_lock' ); return $this; } /** * Get batch * * @return \stdClass Return the first batch from the queue */ protected function get_batch() { global $wpdb; $table = $wpdb->options; $column = 'option_name'; $key_column = 'option_id'; $value_column = 'option_value'; if ( is_multisite() ) { $table = $wpdb->sitemeta; $column = 'meta_key'; $key_column = 'meta_id'; $value_column = 'meta_value'; } $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared // Can't use placeholders for table/column names, it will be wrapped by a single quote (') instead of a backquote (`). $query = $wpdb->get_row( $wpdb->prepare( " SELECT * FROM {$table} WHERE {$column} LIKE %s ORDER BY {$key_column} ASC LIMIT 1 ", $key ) ); // phpcs:enable $batch = new \stdClass(); $batch->key = $query->$column; $batch->data = maybe_unserialize( $query->$value_column ); return $batch; } /** * Handle * * Pass each queue item to the task handler, while remaining * within server memory and time limit constraints. */ protected function handle() { $this->lock_process(); do { $batch = $this->get_batch(); foreach ( $batch->data as $key => $value ) { $task = $this->task( $value ); if ( false !== $task ) { $batch->data[ $key ] = $task; } else { unset( $batch->data[ $key ] ); } if ( $this->time_exceeded() || $this->memory_exceeded() ) { // Batch limits reached. break; } } // Update or delete current batch. if ( ! empty( $batch->data ) ) { $this->update( $batch->key, $batch->data ); } else { $this->delete( $batch->key ); } } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); $this->unlock_process(); // Start next batch or complete process. if ( ! $this->is_queue_empty() ) { $this->dispatch(); } else { $this->complete(); } wp_die(); } /** * Memory exceeded * * Ensures the batch process never exceeds 90% * of the maximum WordPress memory. * * @return bool */ protected function memory_exceeded() { $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory $current_memory = memory_get_usage( true ); $return = false; if ( $current_memory >= $memory_limit ) { $return = true; } return apply_filters( $this->identifier . '_memory_exceeded', $return ); } /** * Get memory limit * * @return int */ protected function get_memory_limit() { if ( function_exists( 'ini_get' ) ) { $memory_limit = ini_get( 'memory_limit' ); } else { // Sensible default. $memory_limit = '128M'; } if ( ! $memory_limit || -1 === intval( $memory_limit ) ) { // Unlimited, set to 32GB. $memory_limit = '32000M'; } return intval( $memory_limit ) * 1024 * 1024; } /** * Time exceeded. * * Ensures the batch never exceeds a sensible time limit. * A timeout limit of 30s is common on shared hosting. * * @return bool */ protected function time_exceeded() { $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds $return = false; if ( time() >= $finish ) { $return = true; } return apply_filters( $this->identifier . '_time_exceeded', $return ); } /** * Complete. * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). */ protected function complete() { // Unschedule the cron healthcheck. $this->clear_scheduled_event(); } /** * Schedule cron healthcheck * * @access public * @param mixed $schedules Schedules. * @return mixed */ public function schedule_cron_healthcheck( $schedules ) { $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); if ( property_exists( $this, 'cron_interval' ) ) { $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval ); } // Adds every 5 minutes to the existing schedules. $schedules[ $this->identifier . '_cron_interval' ] = array( 'interval' => MINUTE_IN_SECONDS * $interval, 'display' => sprintf( /* translators: %d: Interval in minutes. */ esc_html__( 'Every %d minutes', 'elementor' ), $interval, ), ); return $schedules; } /** * Handle cron healthcheck * * Restart the background process if not already running * and data exists in the queue. */ public function handle_cron_healthcheck() { if ( $this->is_process_running() ) { // Background process already running. exit; } if ( $this->is_queue_empty() ) { // No data to process. $this->clear_scheduled_event(); exit; } $this->handle(); exit; } /** * Schedule event */ protected function schedule_event() { if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); } } /** * Clear scheduled event */ protected function clear_scheduled_event() { $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); if ( $timestamp ) { wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); } } /** * Cancel Process * * Stop processing queue items, clear cronjob and delete batch. * */ public function cancel_process() { if ( ! $this->is_queue_empty() ) { $batch = $this->get_batch(); $this->delete( $batch->key ); wp_clear_scheduled_hook( $this->cron_hook_identifier ); } } /** * Task * * Override this method to perform any actions required on each * queue item. Return the modified item for further processing * in the next pass through. Or, return false to remove the * item from the queue. * * @param mixed $item Queue item to iterate over. * * @return mixed */ abstract protected function task( $item ); } PK!>~PUdb-upgrades-manager.phpnu[query_limit; } public function set_query_limit( $limit ) { $this->query_limit = $limit; } public function get_current_version() { if ( null === $this->current_version ) { $this->current_version = get_option( $this->get_version_option_name() ); } return $this->current_version; } public function should_upgrade() { $current_version = $this->get_current_version(); // It's a new install. if ( ! $current_version ) { $this->update_db_version(); return false; } return version_compare( $this->get_new_version(), $current_version, '>' ); } public function on_runner_start() { parent::on_runner_start(); if ( ! defined( 'IS_ELEMENTOR_UPGRADE' ) ) { define( 'IS_ELEMENTOR_UPGRADE', true ); } } public function on_runner_complete( $did_tasks = false ) { $logger = Plugin::$instance->logger->get_logger(); $logger->info( 'Elementor data updater process has been completed.', [ 'meta' => [ 'plugin' => $this->get_plugin_label(), 'from' => $this->current_version, 'to' => $this->get_new_version(), ], ] ); $this->clear_cache(); $this->update_db_version(); if ( $did_tasks ) { $this->add_flag( 'completed' ); } } protected function clear_cache() { Plugin::$instance->files_manager->clear_cache(); } public function admin_notice_start_upgrade() { /** * @var Admin_Notices $admin_notices */ $admin_notices = Plugin::$instance->admin->get_component( 'admin-notices' ); $options = [ 'title' => $this->get_updater_label(), 'description' => esc_html__( 'Your site database needs to be updated to the latest version.', 'elementor' ), 'type' => 'error', 'icon' => false, 'button' => [ 'text' => esc_html__( 'Update Now', 'elementor' ), 'url' => $this->get_start_action_url(), 'class' => 'e-button e-button--cta', ], ]; $admin_notices->print_admin_notice( $options ); } public function admin_notice_upgrade_is_running() { /** * @var Admin_Notices $admin_notices */ $admin_notices = Plugin::$instance->admin->get_component( 'admin-notices' ); $options = [ 'title' => $this->get_updater_label(), 'description' => esc_html__( 'Database update process is running in the background. Taking a while?', 'elementor' ), 'type' => 'warning', 'icon' => false, 'button' => [ 'text' => esc_html__( 'Click here to run it now', 'elementor' ), 'url' => $this->get_continue_action_url(), 'class' => 'e-button e-button--primary', ], ]; $admin_notices->print_admin_notice( $options ); } public function admin_notice_upgrade_is_completed() { $this->delete_flag( 'completed' ); $message = esc_html__( 'The database update process is now complete. Thank you for updating to the latest version!', 'elementor' ); /** * @var Admin_Notices $admin_notices */ $admin_notices = Plugin::$instance->admin->get_component( 'admin-notices' ); $options = [ 'description' => '' . $this->get_updater_label() . ' - ' . $message, 'type' => 'success', 'icon' => false, ]; $admin_notices->print_admin_notice( $options ); } /** * @access protected */ protected function start_run() { $updater = $this->get_task_runner(); if ( $updater->is_running() ) { return; } $upgrade_callbacks = $this->get_upgrade_callbacks(); if ( empty( $upgrade_callbacks ) ) { $this->on_runner_complete(); return; } $this->clear_cache(); foreach ( $upgrade_callbacks as $callback ) { $updater->push_to_queue( [ 'callback' => $callback, ] ); } $updater->save()->dispatch(); Plugin::$instance->logger->get_logger()->info( 'Elementor data updater process has been queued.', [ 'meta' => [ 'plugin' => $this->get_plugin_label(), 'from' => $this->current_version, 'to' => $this->get_new_version(), ], ] ); } protected function update_db_version() { update_option( $this->get_version_option_name(), $this->get_new_version() ); } public function get_upgrade_callbacks() { $prefix = '_v_'; $upgrades_class = $this->get_upgrades_class(); $upgrades_reflection = new \ReflectionClass( $upgrades_class ); $callbacks = []; foreach ( $upgrades_reflection->getMethods() as $method ) { $method_name = $method->getName(); if ( '_on_each_version' === $method_name ) { $callbacks[] = [ $upgrades_class, $method_name ]; continue; } if ( false === strpos( $method_name, $prefix ) ) { continue; } if ( ! preg_match_all( "/$prefix(\d+_\d+_\d+)/", $method_name, $matches ) ) { continue; } $method_version = str_replace( '_', '.', $matches[1][0] ); if ( ! version_compare( $method_version, $this->current_version, '>' ) ) { continue; } $callbacks[] = [ $upgrades_class, $method_name ]; } return $callbacks; } public function __construct() { // If upgrade is completed - show the notice only for admins. // Note: in this case `should_upgrade` returns false, because it's already upgraded. if ( is_admin() && current_user_can( 'update_plugins' ) && $this->get_flag( 'completed' ) ) { add_action( 'admin_notices', [ $this, 'admin_notice_upgrade_is_completed' ] ); } if ( ! $this->should_upgrade() ) { return; } $updater = $this->get_task_runner(); $this->start_run(); if ( $updater->is_running() && current_user_can( 'update_plugins' ) ) { add_action( 'admin_notices', [ $this, 'admin_notice_upgrade_is_running' ] ); } parent::__construct(); } } PK!:;44base-object.phpnu[ensure_settings(); return self::get_items( $this->settings, $setting ); } /** * Set settings. * * @since 2.3.0 * @access public * * @param array|string $key If key is an array, the settings are overwritten by that array. Otherwise, the * settings of the key will be set to the given `$value` param. * * @param mixed $value Optional. Default is null. */ final public function set_settings( $key, $value = null ) { $this->ensure_settings(); if ( is_array( $key ) ) { $this->settings = $key; } else { $this->settings[ $key ] = $value; } } /** * Delete setting. * * Deletes the settings array or a specific key of the settings array if `$key` is specified. * @since 2.3.0 * @access public * * @param string $key Optional. Default is null. */ public function delete_setting( $key = null ) { if ( $key ) { unset( $this->settings[ $key ] ); } else { $this->settings = []; } } final public function merge_properties( array $default_props, array $custom_props, array $allowed_props_keys = [] ) { $props = array_replace_recursive( $default_props, $custom_props ); if ( $allowed_props_keys ) { $props = array_intersect_key( $props, array_flip( $allowed_props_keys ) ); } return $props; } /** * Get items. * * Utility method that receives an array with a needle and returns all the * items that match the needle. If needle is not defined the entire haystack * will be returned. * * @since 2.3.0 * @access protected * @static * * @param array $haystack An array of items. * @param string $needle Optional. Needle. Default is null. * * @return mixed The whole haystack or the needle from the haystack when requested. */ final protected static function get_items( array $haystack, $needle = null ) { if ( $needle ) { return isset( $haystack[ $needle ] ) ? $haystack[ $needle ] : null; } return $haystack; } /** * Get init settings. * * Used to define the default/initial settings of the object. Inheriting classes may implement this method to define * their own default/initial settings. * * @since 2.3.0 * @access protected * * @return array */ protected function get_init_settings() { return []; } /** * Ensure settings. * * Ensures that the `$settings` member is initialized * * @since 2.3.0 * @access private */ private function ensure_settings() { if ( null === $this->settings ) { $this->settings = $this->get_init_settings(); } } /** * Has Own Method * * Used for check whether the method passed as a parameter was declared in the current instance or inherited. * If a base_class_name is passed, it checks whether the method was declared in that class. If the method's * declaring class is the class passed as $base_class_name, it returns false. Otherwise (method was NOT declared * in $base_class_name), it returns true. * * Example #1 - only $method_name is passed: * The initial declaration of `register_controls()` happens in the `Controls_Stack` class. However, all * widgets which have their own controls declare this function as well, overriding the original * declaration. If `has_own_method()` would be called by a Widget's class which implements `register_controls()`, * with 'register_controls' passed as the first parameter - `has_own_method()` will return true. If the Widget * does not declare `register_controls()`, `has_own_method()` will return false. * * Example #2 - both $method_name and $base_class_name are passed * In this example, the widget class inherits from a base class `Widget_Base`, and the base implements * `register_controls()` to add certain controls to all widgets inheriting from it. `has_own_method()` is called by * the widget, with the string 'register_controls' passed as the first parameter, and 'Elementor\Widget_Base' (its full name * including the namespace) passed as the second parameter. If the widget class implements `register_controls()`, * `has_own_method` will return true. If the widget class DOESN'T implement `register_controls()`, it will return * false (because `Widget_Base` is the declaring class for `register_controls()`, and not the class that called * `has_own_method()`). * * @since 3.1.0 * * @param string $method_name * @param string $base_class_name * * @return bool True if the method was declared by the current instance, False if it was inherited. */ public function has_own_method( $method_name, $base_class_name = null ) { try { $reflection_method = new \ReflectionMethod( $this, $method_name ); // If a ReflectionMethod is successfully created, get its declaring class. $declaring_class = $reflection_method->getDeclaringClass(); } catch ( \Exception $e ) { return false; } if ( $base_class_name ) { return $base_class_name !== $declaring_class->name; } return get_called_class() === $declaring_class->name; } } PK!(Qb#elements-iteration-actions/base.phpnu[mode = $mode; } public function __construct( $document ) { $this->document = $document; } } PK!K%elements-iteration-actions/assets.phpnu[get_active_settings(); $controls = $element_data->get_controls(); $element_assets = $this->get_assets( $settings, $controls ); $element_assets_depend = [ 'styles' => $element_data->get_style_depends(), 'scripts' => $element_data->get_script_depends(), ]; if ( $element_assets_depend ) { foreach ( $element_assets_depend as $assets_type => $assets ) { if ( empty( $assets ) ) { continue; } if ( ! isset( $element_assets[ $assets_type ] ) ) { $element_assets[ $assets_type ] = []; } foreach ( $assets as $asset_name ) { if ( ! in_array( $asset_name, $element_assets[ $assets_type ], true ) ) { $element_assets[ $assets_type ][] = $asset_name; } } } } if ( $element_assets ) { $this->update_page_assets( $element_assets ); } } public function is_action_needed() { // No need to evaluate in preview mode, will be made in the saving process. if ( Plugin::$instance->preview->is_preview_mode() ) { return false; } $page_assets = $this->get_saved_page_assets(); // When $page_assets is array it means that the assets registration has already been made at least once. if ( is_array( $page_assets ) ) { return false; } return true; } public function after_elements_iteration() { // In case that the page assets value is empty, it should still be saved as an empty array as an indication that at lease one iteration has occurred. if ( ! is_array( $this->page_assets ) ) { $this->page_assets = []; } $this->get_document_assets(); // Saving the page assets data. $this->document->update_meta( self::ASSETS_META_KEY, $this->page_assets ); if ( 'render' === $this->mode && $this->page_assets ) { Plugin::$instance->assets_loader->enable_assets( $this->page_assets ); } } private function get_saved_page_assets( $force_meta_fetch = false ) { if ( ! is_array( $this->saved_page_assets ) || $force_meta_fetch ) { $this->saved_page_assets = $this->document->get_meta( self::ASSETS_META_KEY ); } return $this->saved_page_assets; } private function update_page_assets( $new_assets ) { if ( ! is_array( $this->page_assets ) ) { $this->page_assets = []; } foreach ( $new_assets as $assets_type => $assets_type_data ) { if ( ! isset( $this->page_assets[ $assets_type ] ) ) { $this->page_assets[ $assets_type ] = []; } foreach ( $assets_type_data as $asset_name ) { if ( ! in_array( $asset_name, $this->page_assets[ $assets_type ], true ) ) { $this->page_assets[ $assets_type ][] = $asset_name; } } } } private function get_assets( $settings, $controls ) { $assets = []; foreach ( $settings as $setting_key => $setting ) { if ( ! isset( $controls[ $setting_key ] ) ) { continue; } $control = $controls[ $setting_key ]; // Enabling assets loading from the registered control fields. if ( ! empty( $control['assets'] ) ) { foreach ( $control['assets'] as $assets_type => $dependencies ) { foreach ( $dependencies as $dependency ) { if ( ! empty( $dependency['conditions'] ) ) { $is_condition_fulfilled = Conditions::check( $dependency['conditions'], $settings ); if ( ! $is_condition_fulfilled ) { continue; } } if ( ! isset( $assets[ $assets_type ] ) ) { $assets[ $assets_type ] = []; } $assets[ $assets_type ][] = $dependency['name']; } } } // Enabling assets loading from the control object. $control_obj = Plugin::$instance->controls_manager->get_control( $control['type'] ); $control_conditional_assets = $control_obj::get_assets( $setting ); if ( $control_conditional_assets ) { foreach ( $control_conditional_assets as $assets_type => $dependencies ) { foreach ( $dependencies as $dependency ) { if ( ! isset( $assets[ $assets_type ] ) ) { $assets[ $assets_type ] = []; } $assets[ $assets_type ][] = $dependency; } } } } return $assets; } private function get_document_assets() { $document_id = $this->document->get_post()->ID; // Getting the document instance in order to get the most updated settings. $updated_document = Plugin::$instance->documents->get( $document_id, false ); $document_settings = $updated_document->get_settings(); $document_controls = $this->document->get_controls(); $document_assets = $this->get_assets( $document_settings, $document_controls ); if ( $document_assets ) { $this->update_page_assets( $document_assets ); } } public function __construct( $document ) { parent::__construct( $document ); // No need to enable assets in preview mode, all assets will be loaded by default by the assets loader. if ( Plugin::$instance->preview->is_preview_mode() ) { return; } $page_assets = $this->get_saved_page_assets(); // If $page_assets is not empty then enabling the assets for loading. if ( $page_assets ) { Plugin::$instance->assets_loader->enable_assets( $page_assets ); } } } PK!5zzendpoint/index.phpnu[controller->get_full_name()}/{id}"; } public function get_public_name() { return ''; } public function get_items( $request ) { return $this->controller->get_items( $request ); } public function get_item( $id, $request ) { return $this->controller->get_item( $request ); } public function create_items( $request ) { return $this->controller->create_items( $request ); } public function create_item( $id, $request ) { return $this->controller->create_item( $request ); } public function update_items( $request ) { return $this->controller->update_items( $request ); } public function update_item( $id, $request ) { return $this->controller->update_item( $request ); } public function delete_items( $request ) { return $this->controller->delete_items( $request ); } public function delete_item( $id, $request ) { return $this->controller->delete_item( $request ); } public function register_items_route( $methods = WP_REST_Server::READABLE, $args = [] ) { parent::register_items_route( $methods, array_merge( $this->controller->get_items_args( $methods ), $args ) ); } public function register_item_route( $methods = WP_REST_Server::READABLE, $args = [], $route = '/' ) { parent::register_item_route( $methods, array_merge( $this->controller->get_item_args( $methods ), $args ), $route ); } } PK!z4xxendpoint/index/all-children.phpnu[controller->get_name() . '/index'; } /* * Retrieves a result(s) of all controller endpoint(s), items. * * Run overall endpoints of the current controller. * * Example, scenario: * 'settings' - controller * 'settings/products' - endpoint * 'settings/partners' - endpoint * Result: * [ * 'products' => [ * 0 => ... * 1 => ... * ], * 'partners' => [ * 0 => ... * 1 => ... * ], * ] */ public function get_items( $request ) { $response = []; foreach ( $this->controller->get_sub_controllers() as $controller ) { $controller_route = $this->get_controller()->get_base_route() . '/' . $controller->get_name(); $result = Manager::instance()->run_request( $controller_route ); if ( ! $result->is_error() ) { $response[ $controller->get_name() ] = $result->get_data(); } } foreach ( $this->controller->endpoints as $endpoint ) { // Skip self. if ( $endpoint === $this ) { continue; } $result = Manager::instance()->run_request( $endpoint->get_base_route() ); if ( ! $result->is_error() ) { $response[ $endpoint->get_name() ] = $result->get_data(); } } return $response; } } PK!mx%endpoint/index/sub-index-endpoint.phpnu[controller->get_parent()->get_name() . '/{id}/' . $this->controller->get_name() . '/{sub_id}'; } public function get_base_route() { $parent_controller = $this->controller->get_parent(); $parent_index_endpoint = $parent_controller->index_endpoint; $parent_controller_route = ''; // In case `$parent_index_endpoint` is AllChildren, it cannot support id_arg_name. if ( ! $parent_index_endpoint instanceof AllChildren ) { $parent_controller_route = "(?P<{$parent_index_endpoint->id_arg_name}>[\w]+)"; } return untrailingslashit('/' . implode( '/', array_filter( [ trim( $parent_index_endpoint->get_base_route(), '/' ), $parent_controller_route, $this->controller->get_name(), $this->get_public_name(), ] ) ) ); } } PK!))base-route.phpnu[ '/' * 'abc' => '/abc/' * '/abc' => '/abc/' * 'abc/' => '/abc/' * '/abc/' => '/abc/' * * @param string $route * * @return string */ private function ensure_slashes( $route ) { if ( '/' !== $route[0] ) { $route = '/' . $route; } return trailingslashit( $route ); } /** * Get base route. * This method should always return the base route starts with '/' and ends without '/'. * * @return string */ public function get_base_route() { $name = $this->get_public_name(); $parent = $this->get_parent(); $parent_base = $parent->get_base_route(); $route = '/'; if ( ! ( $parent instanceof Controller ) ) { $route = $parent->item_route ? $parent->item_route['route'] . '/' : $this->route; } return untrailingslashit( '/' . trim( $parent_base . $route . $name, '/' ) ); } /** * Get permission callback. * * By default get permission callback from the controller. * * @param \WP_REST_Request $request Full data about the request. * * @return boolean */ public function get_permission_callback( $request ) { return $this->controller->get_permission_callback( $request ); } /** * Retrieves a collection of items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function get_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Retrieves one item from the collection. * * @param string $id * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function get_item( $id, $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Creates multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function create_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Creates one item. * * @param string $id id of request item. * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function create_item( $id, $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Updates multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function update_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Updates one item. * * @param string $id id of request item. * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function update_item( $id, $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Delete multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function delete_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Delete one item. * * @param string $id id of request item. * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ protected function delete_item( $id, $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Register the endpoint. * * By default: register get items route. */ protected function register() { $this->register_items_route(); } protected function register_route( $route = '', $methods = WP_REST_Server::READABLE, $args = [] ) { if ( ! in_array( $methods, self::AVAILABLE_METHODS, true ) ) { trigger_error( "Invalid method: '$methods'.", E_USER_ERROR ); // phpcs:ignore } $route = $this->get_base_route() . $route; $this->routes [] = [ 'args' => $args, 'route' => $route, ]; /** * Determine behaviour of `base_callback()` and `get_permission_callback()`: * For `base_callback()` which applying the action. * Whether it's a one item request and should call `get_item_permission_callback()` or it's mutil items request and should call `get_items_permission_callback()`. */ $is_multi = ! empty( $args['is_multi'] ); if ( $is_multi ) { unset( $args['is_multi'] ); } $callback = function ( $request ) use ( $methods, $args, $is_multi ) { return $this->base_callback( $methods, $request, $is_multi ); }; return register_rest_route( $this->controller->get_namespace(), $route, [ [ 'args' => $args, 'methods' => $methods, 'callback' => $callback, 'permission_callback' => function ( $request ) { return $this->get_permission_callback( $request ); }, ], ] ); } /** * Register items route. * * @param string $methods * @param array $args */ public function register_items_route( $methods = WP_REST_Server::READABLE, $args = [] ) { $args['is_multi'] = true; $this->register_route( '', $methods, $args ); } /** * Register item route. * * @param string $route * @param array $args * @param string $methods */ public function register_item_route( $methods = WP_REST_Server::READABLE, $args = [], $route = '/' ) { if ( ! empty( $args['id_arg_name'] ) ) { $this->id_arg_name = $args['id_arg_name']; unset( $args['id_arg_name'] ); } if ( ! empty( $args['id_arg_type_regex'] ) ) { $this->id_arg_type_regex = $args['id_arg_type_regex']; unset( $args['id_arg_type_regex'] ); } $args = array_merge( [ $this->id_arg_name => [ 'description' => 'Unique identifier for the object.', 'type' => 'string', 'required' => true, ], ], $args ); $route .= '(?P<' . $this->id_arg_name . '>' . $this->id_arg_type_regex . ')'; $this->item_route = [ 'args' => $args, 'route' => $route, ]; $this->register_route( $route, $methods, $args ); } /** * Base callback. * All reset requests from the client should pass this function. * * @param string $methods * @param \WP_REST_Request $request * @param bool $is_multi * @param array $args * * @return mixed|\WP_Error|\WP_HTTP_Response|\WP_REST_Response */ public function base_callback( $methods, $request, $is_multi = false, $args = [] ) { if ( $request ) { $json_params = $request->get_json_params(); if ( $json_params ) { $request->set_body_params( $json_params ); } } $args = wp_parse_args( $args, [ 'is_debug' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), ] ); $result = new \WP_Error( 'invalid_methods', 'route not supported.' ); $request->set_param( 'is_multi', $is_multi ); try { switch ( $methods ) { case WP_REST_Server::READABLE: $result = $is_multi ? $this->get_items( $request ) : $this->get_item( $request->get_param( 'id' ), $request ); break; case WP_REST_Server::CREATABLE: $result = $is_multi ? $this->create_items( $request ) : $this->create_item( $request->get_param( 'id' ), $request ); break; case WP_REST_Server::EDITABLE: $result = $is_multi ? $this->update_items( $request ) : $this->update_item( $request->get_param( 'id' ), $request ); break; case WP_REST_Server::DELETABLE: $result = $is_multi ? $this->delete_items( $request ) : $this->delete_item( $request->get_param( 'id' ), $request ); break; } } catch ( Data_Exception $e ) { $result = $e->to_wp_error(); } catch ( \Exception $e ) { if ( empty( $args['is_debug'] ) ) { $result = ( new Error_500() )->to_wp_error(); } else { // For frontend. $exception_mapping = [ 'trace' => $e->getTrace(), 'file' => $e->getFile(), 'line' => $e->getLine(), ]; $e->debug = $exception_mapping; $result = ( new Data_Exception( $e->getMessage(), $e->getCode(), $e ) )->to_wp_error(); } } return rest_ensure_response( $result ); } /** * Constructor. * * run `$this->register()`. * * @param \Elementor\Data\V2\Base\Controller $controller * @param string $route */ protected function __construct( Controller $controller, $route ) { $this->controller = $controller; $this->route = $this->ensure_slashes( $route ); $this->register(); } } PK!_#[[exceptions/error-404.phpnu[get_error_message(), $wp_error->get_error_code(), [ 'status' => $wp_error->get_error_code(), ] ); } } PK!Uhmmexceptions/data-exception.phpnu[ '', 'data' => [], ]; public function get_code() { return 'reset-http-error'; } public function get_message() { return '501 Not Implemented'; } public function get_data() { return [ 'status' => $this->get_http_error_code(), // 'status' is used by WP to pass the http error code. ]; } public function to_wp_error() { return new \WP_Error( $this->custom_data['code'], $this->message, $this->custom_data['data'] ); } protected function get_http_error_code() { return 501; // 501 Not Implemented } protected function apply() {} public function __construct( $message = '', $code = '', $data = [] ) { $this->message = empty( $message ) ? $this->get_message() : $message; $this->custom_data['code'] = empty( $code ) ? $this->get_code() : $code; $this->custom_data['data'] = empty( $data ) ? $this->get_data() : $data; parent::__construct( $this->message, 0, null ); $this->apply(); } } PK!SJnnexceptions/error-500.phpnu[7 endpoint.phpnu[PK!Hcgg  processor.phpnu[PK!e!!processor/after.phpnu[PK! w%processor/before.phpnu[PK!gj..Ocontroller.phpnu[PK!UW{Csub-endpoint.phpnu[PK![]YYGFwidget-base.phpnu[PK!?Y00controls-stack.phpnu[PK!#m Qskin-base.phpnu[PK!sub-controls-stack.phpnu[PK!_5 element-base.phpnu[PK! module.phpnu[PK!%%providers/social-network-provider.phpnu[PK!~Cv'traits/shared-widget-controls-trait.phpnu[PK!Gapp.phpnu[PK!` background-task-manager.phpnu[PK!Yz#z#-background-task.phpnu[PK!*ˆ 3document.phpnu[PK! B 'background-process/wp-async-request.phpnu[PK!'ڰ H+H+, background-process/wp-background-process.phpnu[PK!>~PU.5db-upgrades-manager.phpnu[PK!:;44^Mbase-object.phpnu[PK!(Qb#celements-iteration-actions/base.phpnu[PK!K%jelements-iteration-actions/assets.phpnu[PK!5zz߀endpoint/index.phpnu[PK!z4xxendpoint/index/all-children.phpnu[PK!mx%bendpoint/index/sub-index-endpoint.phpnu[PK!))base-route.phpnu[PK!_#[[exceptions/error-404.phpnu[PK!Hqq!exceptions/wp-error-exception.phpnu[PK!UhmmLexceptions/data-exception.phpnu[PK!SJnnexceptions/error-500.phpnu[PK