| @@ -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'; |
| @@ -29,9 +31,8 @@ | ||
| 29 | 31 | const CLICK_TRACKING_NONCE = 'elementor-conversion-center-click'; |
| 30 | 32 | const FLOATING_BUTTONS_DOCUMENT_TYPE = 'floating-buttons'; |
| 31 | 33 | const CPT_FLOATING_BUTTONS = 'e-floating-buttons'; |
| 32 | 34 | const ADMIN_PAGE_SLUG_CONTACT = 'edit.php?post_type=e-floating-buttons'; |
| 33 | - const WIDGET_HAS_CUSTOM_BREAKPOINTS = true; | |
| 34 | 35 | |
| 35 | 36 | private $has_contact_pages = null; |
| 36 | 37 | private $trashed_contact_pages; |
| 37 | 38 | |
| @@ -45,10 +46,22 @@ | ||
| 45 | 46 | 'floating-bars' => esc_html__( 'Floating Bars', 'elementor' ), |
| 46 | 47 | ]; |
| 47 | 48 | } |
| 48 | 49 | |
| 50 | + // TODO: This is a hidden experiment which needs to remain enabled like this until 3.26 for pro compatibility. | |
| 51 | + public static function get_experimental_data() { | |
| 52 | + return [ | |
| 53 | + 'name' => self::EXPERIMENT_NAME, | |
| 54 | + 'title' => esc_html__( 'Floating Buttons', 'elementor' ), | |
| 55 | + 'hidden' => true, | |
| 56 | + 'default' => Manager::STATE_ACTIVE, | |
| 57 | + 'release_status' => Manager::RELEASE_STATUS_STABLE, | |
| 58 | + 'mutable' => false, | |
| 59 | + ]; | |
| 60 | + } | |
| 61 | + | |
| 49 | 62 | public function get_name(): string { |
| 50 | - return 'floating-buttons'; | |
| 63 | + return static::EXPERIMENT_NAME; | |
| 51 | 64 | } |
| 52 | 65 | |
| 53 | 66 | public function get_widgets(): array { |
| 54 | 67 | |
| @@ -57,10 +70,17 @@ | ||
| 57 | 70 | 'Floating_Bars_Var_1', |
| 58 | 71 | ]; |
| 59 | 72 | } |
| 60 | 73 | |
| 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() ); | |
| 74 | + private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) { | |
| 75 | + $menu_args = $this->get_contact_menu_args(); | |
| 76 | + $function = $menu_args['function']; | |
| 77 | + if ( is_callable( $function ) ) { | |
| 78 | + $admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Empty_View_Menu_Item( $function ) ); | |
| 79 | + } else { | |
| 80 | + $admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Menu_Item() ); | |
| 81 | + }; | |
| 82 | + | |
| 63 | 83 | } |
| 64 | 84 | |
| 65 | 85 | public function __construct() { |
| 66 | 86 | parent::__construct(); |
| @@ -78,14 +98,16 @@ | ||
| 78 | 98 | } |
| 79 | 99 | |
| 80 | 100 | $this->register_contact_pages_cpt(); |
| 81 | 101 | |
| 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 | - } ); | |
| 102 | + if ( ! ElementorUtils::has_pro() ) { | |
| 103 | + add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) { | |
| 104 | + $documents_manager->register_document_type( | |
| 105 | + static::FLOATING_BUTTONS_DOCUMENT_TYPE, | |
| 106 | + Floating_Buttons::get_class_full_name() | |
| 107 | + ); | |
| 108 | + } ); | |
| 109 | + } | |
| 88 | 110 | |
| 89 | 111 | add_action( 'current_screen', function() { |
| 90 | 112 | $screen = get_current_screen(); |
| 91 | 113 | if ( $screen && 'edit-e-floating-buttons' === $screen->id ) { |
| @@ -92,16 +114,8 @@ | ||
| 92 | 114 | $this->flush_permalinks_on_elementor_version_change(); |
| 93 | 115 | } |
| 94 | 116 | }); |
| 95 | 117 | |
| 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 | 118 | add_action( 'wp_ajax_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); |
| 105 | 119 | add_action( 'wp_ajax_nopriv_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); |
| 106 | 120 | |
| 107 | 121 | add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] ); |
| @@ -152,11 +166,11 @@ | ||
| 152 | 166 | |
| 153 | 167 | return $is_top_bar_active; |
| 154 | 168 | }, 10, 2 ); |
| 155 | 169 | |
| 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 | - } ); | |
| 170 | + add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) { | |
| 171 | + $this->register_admin_menu_legacy( $admin_menu ); | |
| 172 | + }, Source_Local::ADMIN_MENU_PRIORITY + 20 ); | |
| 159 | 173 | |
| 160 | 174 | add_action( 'elementor/admin/localize_settings', function ( array $settings ) { |
| 161 | 175 | return $this->admin_localize_settings( $settings ); |
| 162 | 176 | } ); |
| @@ -171,14 +185,46 @@ | ||
| 171 | 185 | return $cpts; |
| 172 | 186 | } ); |
| 173 | 187 | |
| 174 | 188 | add_action( 'admin_init', function () { |
| 175 | - $action = sanitize_text_field( filter_input( INPUT_GET, 'action' ) ); | |
| 189 | + $action = filter_input( INPUT_GET, 'action' ); | |
| 190 | + $menu_args = $this->get_contact_menu_args(); | |
| 176 | 191 | |
| 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(); | |
| 192 | + switch ( $action ) { | |
| 193 | + case 'remove_from_entire_site': | |
| 194 | + $post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); | |
| 195 | + check_admin_referer( 'remove_from_entire_site_' . $post ); | |
| 196 | + delete_post_meta( $post, '_elementor_conditions' ); | |
| 197 | + | |
| 198 | + wp_redirect( $menu_args['menu_slug'] ); | |
| 199 | + exit; | |
| 200 | + case 'set_as_entire_site': | |
| 201 | + $post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); | |
| 202 | + check_admin_referer( 'set_as_entire_site_' . $post ); | |
| 203 | + | |
| 204 | + $posts = get_posts( [ | |
| 205 | + 'post_type' => static::CPT_FLOATING_BUTTONS, | |
| 206 | + 'posts_per_page' => -1, | |
| 207 | + 'post_status' => 'publish', | |
| 208 | + 'fields' => 'ids', | |
| 209 | + 'no_found_rows' => true, | |
| 210 | + 'update_post_term_cache' => false, | |
| 211 | + 'update_post_meta_cache' => false, | |
| 212 | + 'meta_query' => Floating_Buttons::get_meta_query_for_floating_buttons( | |
| 213 | + Floating_Buttons::get_floating_element_type( $post ) | |
| 214 | + ), | |
| 215 | + ] ); | |
| 216 | + | |
| 217 | + foreach ( $posts as $post_id ) { | |
| 218 | + delete_post_meta( $post_id, '_elementor_conditions' ); | |
| 219 | + } | |
| 220 | + | |
| 221 | + update_post_meta( $post, '_elementor_conditions', [ 'include/general' ] ); | |
| 222 | + | |
| 223 | + wp_redirect( $menu_args['menu_slug'] ); | |
| 224 | + exit; | |
| 225 | + default: | |
| 226 | + break; | |
| 181 | 227 | } |
| 182 | 228 | } ); |
| 183 | 229 | |
| 184 | 230 | add_action( 'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_columns', function( $posts_columns ) { |
| @@ -237,20 +283,12 @@ | ||
| 237 | 283 | if ( ! isset( $posts_to_update[ $post_id ] ) ) { |
| 238 | 284 | $starting_clicks = (int) get_post_meta( $post_id, static::META_CLICK_TRACKING, true ); |
| 239 | 285 | $posts_to_update[ $post_id ] = $starting_clicks ? $starting_clicks : 0; |
| 240 | 286 | } |
| 241 | - ++$posts_to_update[ $post_id ]; | |
| 287 | + $posts_to_update[ $post_id ] ++; | |
| 242 | 288 | } |
| 243 | 289 | |
| 244 | 290 | foreach ( $posts_to_update as $post_id => $clicks ) { |
| 245 | - if ( self::CPT_FLOATING_BUTTONS !== get_post_type( $post_id ) ) { | |
| 246 | - continue; | |
| 247 | - } | |
| 248 | - | |
| 249 | - if ( 'publish' !== get_post_status( $post_id ) ) { | |
| 250 | - continue; | |
| 251 | - } | |
| 252 | - | |
| 253 | 291 | update_post_meta( $post_id, static::META_CLICK_TRACKING, $clicks ); |
| 254 | 292 | } |
| 255 | 293 | |
| 256 | 294 | wp_send_json_success(); |
| @@ -347,10 +385,10 @@ | ||
| 347 | 385 | if ( ! empty( $trashed_posts ) ) : ?> |
| 348 | 386 | <div class="e-trashed-items"> |
| 349 | 387 | <?php |
| 350 | 388 | printf( |
| 351 | - /* translators: %1$s Link open tag, %2$s: Link close tag. */ | |
| 352 | - esc_html__( 'Or view %1$sTrashed Items%2$s', 'elementor' ), | |
| 389 | + /* translators: %1$s Link open tag, %2$s: Link close tag. */ | |
| 390 | + esc_html__( 'Or view %1$sTrashed Items%1$s', 'elementor' ), | |
| 353 | 391 | '<a href="' . esc_url( admin_url( 'edit.php?post_status=trash&post_type=' . self::CPT_FLOATING_BUTTONS ) ) . '">', |
| 354 | 392 | '</a>' |
| 355 | 393 | ); |
| 356 | 394 | ?> |
| @@ -392,20 +430,10 @@ | ||
| 392 | 430 | 'labels' => $labels, |
| 393 | 431 | 'public' => true, |
| 394 | 432 | 'show_in_menu' => 'edit.php?post_type=elementor_library&tabs_group=library', |
| 395 | 433 | '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 | - ], | |
| 434 | + 'capability_type' => 'page', | |
| 406 | 435 | 'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ], |
| 407 | - 'show_in_rest' => true, | |
| 408 | 436 | 'supports' => [ |
| 409 | 437 | 'title', |
| 410 | 438 | 'editor', |
| 411 | 439 | 'comments', |
| @@ -447,8 +475,9 @@ | ||
| 447 | 475 | 'meta_value' => $document_type, |
| 448 | 476 | ] ); |
| 449 | 477 | |
| 450 | 478 | return $posts_query->post_count > 0; |
| 479 | + | |
| 451 | 480 | } |
| 452 | 481 | |
| 453 | 482 | private function get_contact_menu_args(): array { |
| 454 | 483 | if ( $this->has_contact_pages() ) { |
| @@ -526,44 +555,18 @@ | ||
| 526 | 555 | |
| 527 | 556 | /** |
| 528 | 557 | * Register styles. |
| 529 | 558 | * |
| 530 | - * At build time, Elementor compiles `/modules/floating-buttons/assets/scss/widgets/*.scss` | |
| 531 | - * to `/assets/css/widget-*.min.css`. | |
| 559 | + * At build time, Elementor compiles `/modules/floating-buttons/assets/scss/frontend.scss` | |
| 560 | + * to `/assets/css/widget-floating-buttons.min.css`. | |
| 532 | 561 | * |
| 533 | 562 | * @return void |
| 534 | 563 | */ |
| 535 | 564 | public function register_styles() { |
| 536 | - $direction_suffix = is_rtl() ? '-rtl' : ''; | |
| 537 | - $widget_styles = $this->get_widgets_style_list(); | |
| 538 | - $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints(); | |
| 539 | - | |
| 540 | - foreach ( $widget_styles as $widget_style_name => $widget_has_responsive_style ) { | |
| 541 | - $should_load_responsive_css = $widget_has_responsive_style ? $has_custom_breakpoints : false; | |
| 542 | - | |
| 543 | - wp_register_style( | |
| 544 | - $widget_style_name, | |
| 545 | - $this->get_frontend_file_url( "{$widget_style_name}{$direction_suffix}.min.css", $should_load_responsive_css ), | |
| 546 | - [ 'elementor-frontend', 'elementor-icons' ], | |
| 547 | - $should_load_responsive_css ? null : ELEMENTOR_VERSION | |
| 548 | - ); | |
| 549 | - } | |
| 550 | - } | |
| 551 | - | |
| 552 | - private function get_widgets_style_list(): array { | |
| 553 | - return [ | |
| 554 | - 'widget-floating-buttons' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, // TODO: Remove in v3.27.0 [ED-15717] | |
| 555 | - 'widget-floating-bars-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 556 | - 'widget-floating-bars-var-2' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 557 | - 'widget-floating-bars-var-3' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 558 | - 'widget-contact-buttons-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 559 | - 'widget-contact-buttons-var-1' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 560 | - 'widget-contact-buttons-var-3' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 561 | - 'widget-contact-buttons-var-4' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 562 | - 'widget-contact-buttons-var-6' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 563 | - 'widget-contact-buttons-var-7' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 564 | - 'widget-contact-buttons-var-8' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 565 | - 'widget-contact-buttons-var-9' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 566 | - 'widget-contact-buttons-var-10' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, | |
| 567 | - ]; | |
| 565 | + wp_register_style( | |
| 566 | + 'widget-floating-buttons', | |
| 567 | + $this->get_css_assets_url( 'widget-floating-buttons', null, true, true ), | |
| 568 | + [ 'elementor-icons' ], | |
| 569 | + ELEMENTOR_VERSION | |
| 570 | + ); | |
| 568 | 571 | } |
| 569 | 572 | } |