| @@ -2,28 +2,30 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\FloatingButtons; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Controls_Manager; |
| 6 | +use Elementor\Core\Admin\Menu\Admin_Menu_Manager; | |
| 6 | 7 | use Elementor\Core\Base\Document; |
| 7 | 8 | use Elementor\Core\Base\Module as BaseModule; |
| 8 | 9 | use Elementor\Core\Documents_Manager; |
| 10 | +use Elementor\Core\Experiments\Manager; | |
| 9 | 11 | use Elementor\Modules\FloatingButtons\Base\Widget_Floating_Bars_Base; |
| 12 | +use Elementor\Modules\FloatingButtons\AdminMenuItems\Floating_Buttons_Empty_View_Menu_Item; | |
| 13 | +use Elementor\Modules\FloatingButtons\AdminMenuItems\Floating_Buttons_Menu_Item; | |
| 10 | 14 | use Elementor\Modules\FloatingButtons\Base\Widget_Contact_Button_Base; |
| 11 | -use Elementor\Modules\FloatingButtons\Classes\Action\Action_Handler; | |
| 12 | 15 | use Elementor\Modules\FloatingButtons\Control\Hover_Animation_Floating_Buttons; |
| 13 | 16 | use Elementor\Modules\FloatingButtons\Documents\Floating_Buttons; |
| 14 | 17 | use Elementor\Plugin; |
| 15 | 18 | use Elementor\TemplateLibrary\Source_Local; |
| 16 | 19 | use Elementor\Utils as ElementorUtils; |
| 17 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 18 | -use Elementor\Modules\FloatingButtons\AdminMenuItems\Editor_One_Floating_Elements_Menu; | |
| 19 | 20 | |
| 20 | 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | - exit; // Exit if accessed directly. | |
| 22 | + exit; // Exit if accessed directly | |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | class Module extends BaseModule { |
| 25 | 26 | |
| 27 | + const EXPERIMENT_NAME = 'floating-buttons'; | |
| 26 | 28 | const FLOATING_ELEMENTS_TYPE_META_KEY = '_elementor_floating_elements_type'; |
| 27 | 29 | const ROUTER_OPTION_KEY = 'elementor_floating_buttons_router_version'; |
| 28 | 30 | const META_CLICK_TRACKING = '_elementor_click_tracking'; |
| 29 | 31 | const CLICK_TRACKING_NONCE = 'elementor-conversion-center-click'; |
| @@ -45,10 +47,22 @@ | ||
| 45 | 47 | 'floating-bars' => esc_html__( 'Floating Bars', 'elementor' ), |
| 46 | 48 | ]; |
| 47 | 49 | } |
| 48 | 50 | |
| 51 | + // TODO: This is a hidden experiment which needs to remain enabled like this until 3.26 for pro compatibility. | |
| 52 | + public static function get_experimental_data() { | |
| 53 | + return [ | |
| 54 | + 'name' => self::EXPERIMENT_NAME, | |
| 55 | + 'title' => esc_html__( 'Floating Buttons', 'elementor' ), | |
| 56 | + 'hidden' => true, | |
| 57 | + 'default' => Manager::STATE_ACTIVE, | |
| 58 | + 'release_status' => Manager::RELEASE_STATUS_STABLE, | |
| 59 | + 'mutable' => false, | |
| 60 | + ]; | |
| 61 | + } | |
| 62 | + | |
| 49 | 63 | public function get_name(): string { |
| 50 | - return 'floating-buttons'; | |
| 64 | + return static::EXPERIMENT_NAME; | |
| 51 | 65 | } |
| 52 | 66 | |
| 53 | 67 | public function get_widgets(): array { |
| 54 | 68 | |
| @@ -57,10 +71,17 @@ | ||
| 57 | 71 | 'Floating_Bars_Var_1', |
| 58 | 72 | ]; |
| 59 | 73 | } |
| 60 | 74 | |
| 61 | - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) { | |
| 62 | - $menu_data_provider->register_menu( new Editor_One_Floating_Elements_Menu() ); | |
| 75 | + private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) { | |
| 76 | + $menu_args = $this->get_contact_menu_args(); | |
| 77 | + $function = $menu_args['function']; | |
| 78 | + if ( is_callable( $function ) ) { | |
| 79 | + $admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Empty_View_Menu_Item( $function ) ); | |
| 80 | + } else { | |
| 81 | + $admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Menu_Item() ); | |
| 82 | + }; | |
| 83 | + | |
| 63 | 84 | } |
| 64 | 85 | |
| 65 | 86 | public function __construct() { |
| 66 | 87 | parent::__construct(); |
| @@ -78,14 +99,16 @@ | ||
| 78 | 99 | } |
| 79 | 100 | |
| 80 | 101 | $this->register_contact_pages_cpt(); |
| 81 | 102 | |
| 82 | - add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) { | |
| 83 | - $documents_manager->register_document_type( | |
| 84 | - static::FLOATING_BUTTONS_DOCUMENT_TYPE, | |
| 85 | - Floating_Buttons::get_class_full_name() | |
| 86 | - ); | |
| 87 | - } ); | |
| 103 | + if ( ! ElementorUtils::has_pro() ) { | |
| 104 | + add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) { | |
| 105 | + $documents_manager->register_document_type( | |
| 106 | + static::FLOATING_BUTTONS_DOCUMENT_TYPE, | |
| 107 | + Floating_Buttons::get_class_full_name() | |
| 108 | + ); | |
| 109 | + } ); | |
| 110 | + } | |
| 88 | 111 | |
| 89 | 112 | add_action( 'current_screen', function() { |
| 90 | 113 | $screen = get_current_screen(); |
| 91 | 114 | if ( $screen && 'edit-e-floating-buttons' === $screen->id ) { |
| @@ -92,16 +115,8 @@ | ||
| 92 | 115 | $this->flush_permalinks_on_elementor_version_change(); |
| 93 | 116 | } |
| 94 | 117 | }); |
| 95 | 118 | |
| 96 | - add_filter( 'elementor/editor-one/menu/elementor_post_types', function ( array $elementor_post_types ): array { | |
| 97 | - $elementor_post_types[ static::CPT_FLOATING_BUTTONS ] = [ | |
| 98 | - 'menu_slug' => 'elementor-editor-templates', | |
| 99 | - 'child_slug' => 'edit.php?post_type=e-floating-buttons', | |
| 100 | - ]; | |
| 101 | - return $elementor_post_types; | |
| 102 | - } ); | |
| 103 | - | |
| 104 | 119 | add_action( 'wp_ajax_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); |
| 105 | 120 | add_action( 'wp_ajax_nopriv_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); |
| 106 | 121 | |
| 107 | 122 | add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] ); |
| @@ -152,11 +167,11 @@ | ||
| 152 | 167 | |
| 153 | 168 | return $is_top_bar_active; |
| 154 | 169 | }, 10, 2 ); |
| 155 | 170 | |
| 156 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 157 | - $this->register_editor_one_menu( $menu_data_provider ); | |
| 158 | - } ); | |
| 171 | + add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) { | |
| 172 | + $this->register_admin_menu_legacy( $admin_menu ); | |
| 173 | + }, Source_Local::ADMIN_MENU_PRIORITY + 20 ); | |
| 159 | 174 | |
| 160 | 175 | add_action( 'elementor/admin/localize_settings', function ( array $settings ) { |
| 161 | 176 | return $this->admin_localize_settings( $settings ); |
| 162 | 177 | } ); |
| @@ -171,14 +186,46 @@ | ||
| 171 | 186 | return $cpts; |
| 172 | 187 | } ); |
| 173 | 188 | |
| 174 | 189 | add_action( 'admin_init', function () { |
| 175 | - $action = sanitize_text_field( filter_input( INPUT_GET, 'action' ) ); | |
| 190 | + $action = filter_input( INPUT_GET, 'action' ); | |
| 191 | + $menu_args = $this->get_contact_menu_args(); | |
| 176 | 192 | |
| 177 | - if ( $action ) { | |
| 178 | - $menu_args = $this->get_contact_menu_args(); | |
| 179 | - $action_handler = new Action_Handler( $action, $menu_args ); | |
| 180 | - $action_handler->process_action(); | |
| 193 | + switch ( $action ) { | |
| 194 | + case 'remove_from_entire_site': | |
| 195 | + $post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); | |
| 196 | + check_admin_referer( 'remove_from_entire_site_' . $post ); | |
| 197 | + delete_post_meta( $post, '_elementor_conditions' ); | |
| 198 | + | |
| 199 | + wp_redirect( $menu_args['menu_slug'] ); | |
| 200 | + exit; | |
| 201 | + case 'set_as_entire_site': | |
| 202 | + $post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); | |
| 203 | + check_admin_referer( 'set_as_entire_site_' . $post ); | |
| 204 | + | |
| 205 | + $posts = get_posts( [ | |
| 206 | + 'post_type' => static::CPT_FLOATING_BUTTONS, | |
| 207 | + 'posts_per_page' => -1, | |
| 208 | + 'post_status' => 'publish', | |
| 209 | + 'fields' => 'ids', | |
| 210 | + 'no_found_rows' => true, | |
| 211 | + 'update_post_term_cache' => false, | |
| 212 | + 'update_post_meta_cache' => false, | |
| 213 | + 'meta_query' => Floating_Buttons::get_meta_query_for_floating_buttons( | |
| 214 | + Floating_Buttons::get_floating_element_type( $post ) | |
| 215 | + ), | |
| 216 | + ] ); | |
| 217 | + | |
| 218 | + foreach ( $posts as $post_id ) { | |
| 219 | + delete_post_meta( $post_id, '_elementor_conditions' ); | |
| 220 | + } | |
| 221 | + | |
| 222 | + update_post_meta( $post, '_elementor_conditions', [ 'include/general' ] ); | |
| 223 | + | |
| 224 | + wp_redirect( $menu_args['menu_slug'] ); | |
| 225 | + exit; | |
| 226 | + default: | |
| 227 | + break; | |
| 181 | 228 | } |
| 182 | 229 | } ); |
| 183 | 230 | |
| 184 | 231 | add_action( 'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_columns', function( $posts_columns ) { |
| @@ -237,9 +284,9 @@ | ||
| 237 | 284 | if ( ! isset( $posts_to_update[ $post_id ] ) ) { |
| 238 | 285 | $starting_clicks = (int) get_post_meta( $post_id, static::META_CLICK_TRACKING, true ); |
| 239 | 286 | $posts_to_update[ $post_id ] = $starting_clicks ? $starting_clicks : 0; |
| 240 | 287 | } |
| 241 | - ++$posts_to_update[ $post_id ]; | |
| 288 | + $posts_to_update[ $post_id ] ++; | |
| 242 | 289 | } |
| 243 | 290 | |
| 244 | 291 | foreach ( $posts_to_update as $post_id => $clicks ) { |
| 245 | 292 | if ( self::CPT_FLOATING_BUTTONS !== get_post_type( $post_id ) ) { |
| @@ -347,10 +394,10 @@ | ||
| 347 | 394 | if ( ! empty( $trashed_posts ) ) : ?> |
| 348 | 395 | <div class="e-trashed-items"> |
| 349 | 396 | <?php |
| 350 | 397 | printf( |
| 351 | - /* translators: %1$s Link open tag, %2$s: Link close tag. */ | |
| 352 | - esc_html__( 'Or view %1$sTrashed Items%2$s', 'elementor' ), | |
| 398 | + /* translators: %1$s Link open tag, %2$s: Link close tag. */ | |
| 399 | + esc_html__( 'Or view %1$sTrashed Items%1$s', 'elementor' ), | |
| 353 | 400 | '<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT_FLOATING_BUTTONS ) ) . '">', |
| 354 | 401 | '</a>' |
| 355 | 402 | ); |
| 356 | 403 | ?> |
| @@ -392,20 +439,10 @@ | ||
| 392 | 439 | 'labels' => $labels, |
| 393 | 440 | 'public' => true, |
| 394 | 441 | 'show_in_menu' => 'edit.php?post_type=elementor_library&tabs_group=library', |
| 395 | 442 | 'show_in_nav_menus' => false, |
| 396 | - 'capabilities' => [ | |
| 397 | - 'edit_post' => 'manage_options', | |
| 398 | - 'read_post' => 'manage_options', | |
| 399 | - 'delete_post' => 'manage_options', | |
| 400 | - 'edit_posts' => 'manage_options', | |
| 401 | - 'edit_others_posts' => 'manage_options', | |
| 402 | - 'publish_posts' => 'manage_options', | |
| 403 | - 'read_private_posts' => 'manage_options', | |
| 404 | - 'create_posts' => 'manage_options', | |
| 405 | - ], | |
| 443 | + 'capability_type' => 'page', | |
| 406 | 444 | 'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ], |
| 407 | - 'show_in_rest' => true, | |
| 408 | 445 | 'supports' => [ |
| 409 | 446 | 'title', |
| 410 | 447 | 'editor', |
| 411 | 448 | 'comments', |
| @@ -447,8 +484,9 @@ | ||
| 447 | 484 | 'meta_value' => $document_type, |
| 448 | 485 | ] ); |
| 449 | 486 | |
| 450 | 487 | return $posts_query->post_count > 0; |
| 488 | + | |
| 451 | 489 | } |
| 452 | 490 | |
| 453 | 491 | private function get_contact_menu_args(): array { |
| 454 | 492 | if ( $this->has_contact_pages() ) { |
| @@ -548,9 +586,9 @@ | ||
| 548 | 586 | ); |
| 549 | 587 | } |
| 550 | 588 | } |
| 551 | 589 | |
| 552 | - private function get_widgets_style_list(): array { | |
| 590 | + private function get_widgets_style_list():array { | |
| 553 | 591 | return [ |
| 554 | 592 | 'widget-floating-buttons' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, // TODO: Remove in v3.27.0 [ED-15717] |
| 555 | 593 | 'widget-floating-bars-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |
| 556 | 594 | 'widget-floating-bars-var-2' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, |