experiments->is_feature_active( 'container' ); } public static function get_floating_elements_types() { return [ 'floating-buttons' => esc_html__( 'Floating Buttons', 'elementor' ), 'floating-bars' => esc_html__( 'Floating Bars', 'elementor' ), ]; } // TODO: This is a hidden experiment which needs to remain enabled like this until 3.26 for pro compatibility. public static function get_experimental_data() { return [ 'name' => self::EXPERIMENT_NAME, 'title' => esc_html__( 'Floating Buttons', 'elementor' ), 'hidden' => true, 'default' => Manager::STATE_ACTIVE, 'release_status' => Manager::RELEASE_STATUS_STABLE, 'mutable' => false, ]; } public function get_name(): string { return static::EXPERIMENT_NAME; } public function get_widgets(): array { return [ 'Contact_Buttons', 'Floating_Bars_Var_1', ]; } private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) { $menu_args = $this->get_contact_menu_args(); $function = $menu_args['function']; if ( is_callable( $function ) ) { $admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Empty_View_Menu_Item( $function ) ); } else { $admin_menu->register( $menu_args['menu_slug'], new Floating_Buttons_Menu_Item() ); }; } public function __construct() { parent::__construct(); if ( Floating_Buttons::is_creating_floating_buttons_page() || Floating_Buttons::is_editing_existing_floating_buttons_page() ) { Controls_Manager::add_tab( Widget_Contact_Button_Base::TAB_ADVANCED, esc_html__( 'Advanced', 'elementor' ) ); Controls_Manager::add_tab( Widget_Floating_Bars_Base::TAB_ADVANCED, esc_html__( 'Advanced', 'elementor' ) ); } $this->register_contact_pages_cpt(); if ( ! ElementorUtils::has_pro() ) { add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) { $documents_manager->register_document_type( static::FLOATING_BUTTONS_DOCUMENT_TYPE, Floating_Buttons::get_class_full_name() ); } ); } add_action( 'current_screen', function() { $screen = get_current_screen(); if ( $screen && 'edit-e-floating-buttons' === $screen->id ) { $this->flush_permalinks_on_elementor_version_change(); } }); add_action( 'wp_ajax_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); add_action( 'wp_ajax_nopriv_elementor_send_clicks', [ $this, 'handle_click_tracking' ] ); add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] ); add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) { $controls_manager->register( new Hover_Animation_Floating_Buttons() ); }); add_filter( 'elementor/widget/common/register_css_attributes_control', function ( $common_controls ) { if ( Floating_Buttons::is_creating_floating_buttons_page() || Floating_Buttons::is_editing_existing_floating_buttons_page() ) { return false; } return $common_controls; } ); add_filter( 'elementor/settings/controls/checkbox_list_cpt/post_type_objects', function ( $post_types ) { unset( $post_types[ static::CPT_FLOATING_BUTTONS ] ); return $post_types; } ); add_filter( 'elementor/template_library/sources/local/is_valid_template_type', function ( $is_valid_template_type, $cpt ) { if ( in_array( static::CPT_FLOATING_BUTTONS, $cpt, true ) ) { return true; } return $is_valid_template_type; }, 10, 2 ); if ( ! ElementorUtils::has_pro() ) { add_action( 'wp_footer', function () { $this->render_floating_buttons(); } ); } add_action( 'elementor/admin-top-bar/is-active', function ( $is_top_bar_active, $current_screen ) { if ( strpos( $current_screen->id ?? '', static::CPT_FLOATING_BUTTONS ) !== false ) { return true; } return $is_top_bar_active; }, 10, 2 ); add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) { $this->register_admin_menu_legacy( $admin_menu ); }, Source_Local::ADMIN_MENU_PRIORITY + 20 ); add_action( 'elementor/admin/localize_settings', function ( array $settings ) { return $this->admin_localize_settings( $settings ); } ); add_action( 'elementor/editor/localize_settings', function ( $data ) { return $this->editor_localize_settings( $data ); } ); add_filter( 'elementor/template_library/sources/local/register_taxonomy_cpts', function ( array $cpts ) { $cpts[] = static::CPT_FLOATING_BUTTONS; return $cpts; } ); add_action( 'admin_init', function () { $action = filter_input( INPUT_GET, 'action' ); $menu_args = $this->get_contact_menu_args(); switch ( $action ) { case 'remove_from_entire_site': $post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); check_admin_referer( 'remove_from_entire_site_' . $post ); delete_post_meta( $post, '_elementor_conditions' ); wp_redirect( $menu_args['menu_slug'] ); exit; case 'set_as_entire_site': $post = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT ); check_admin_referer( 'set_as_entire_site_' . $post ); $posts = get_posts( [ 'post_type' => static::CPT_FLOATING_BUTTONS, 'posts_per_page' => -1, 'post_status' => 'publish', 'fields' => 'ids', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'meta_query' => Floating_Buttons::get_meta_query_for_floating_buttons( Floating_Buttons::get_floating_element_type( $post ) ), ] ); foreach ( $posts as $post_id ) { delete_post_meta( $post_id, '_elementor_conditions' ); } update_post_meta( $post, '_elementor_conditions', [ 'include/general' ] ); wp_redirect( $menu_args['menu_slug'] ); exit; default: break; } } ); add_action( 'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_columns', function( $posts_columns ) { $source_local = Plugin::$instance->templates_manager->get_source( 'local' ); unset( $posts_columns['date'] ); unset( $posts_columns['comments'] ); $posts_columns['click_tracking'] = esc_html__( 'Click Tracking', 'elementor' ); if ( ! ElementorUtils::has_pro() ) { $posts_columns['instances'] = esc_html__( 'Instances', 'elementor' ); } return $source_local->admin_columns_headers( $posts_columns ); } ); add_action( 'manage_' . static::CPT_FLOATING_BUTTONS . '_posts_custom_column', [ $this, 'set_admin_columns_content' ], 10, 2 ); add_action( 'admin_bar_menu', function ( $admin_bar ) { $this->override_admin_bar_add_contact( $admin_bar ); }, 100 ); } public function is_preview_for_document( $post_id ) { $preview_id = ElementorUtils::get_super_global_value( $_GET, 'preview_id' ); $preview = ElementorUtils::get_super_global_value( $_GET, 'preview' ); return 'true' === $preview && (int) $post_id === (int) $preview_id; } public function handle_click_tracking() { $data = filter_input_array( INPUT_POST, [ 'clicks' => [ 'filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY, ], '_nonce' => FILTER_UNSAFE_RAW, ] ); if ( ! wp_verify_nonce( $data['_nonce'], static::CLICK_TRACKING_NONCE ) ) { wp_send_json_error( [ 'message' => 'Invalid nonce' ] ); } if ( ! check_ajax_referer( static::CLICK_TRACKING_NONCE, '_nonce', false ) ) { wp_send_json_error( [ 'message' => 'Invalid referrer' ] ); } $posts_to_update = []; foreach ( $data['clicks'] as $post_id ) { if ( ! isset( $posts_to_update[ $post_id ] ) ) { $starting_clicks = (int) get_post_meta( $post_id, static::META_CLICK_TRACKING, true ); $posts_to_update[ $post_id ] = $starting_clicks ? $starting_clicks : 0; } $posts_to_update[ $post_id ] ++; } foreach ( $posts_to_update as $post_id => $clicks ) { if ( self::CPT_FLOATING_BUTTONS !== get_post_type( $post_id ) ) { continue; } if ( 'publish' !== get_post_status( $post_id ) ) { continue; } update_post_meta( $post_id, static::META_CLICK_TRACKING, $clicks ); } wp_send_json_success(); } public function set_admin_columns_content( $column_name, $post_id ) { $document = Plugin::$instance->documents->get( $post_id ); if ( method_exists( $document, 'admin_columns_content' ) ) { $document->admin_columns_content( $column_name ); } switch ( $column_name ) { case 'click_tracking': $click_tracking = get_post_meta( $post_id, static::META_CLICK_TRACKING, true ); echo esc_html( $click_tracking ); break; case 'instances': if ( ElementorUtils::has_pro() ) { break; } $instances = get_post_meta( $post_id, '_elementor_conditions', true ); if ( $instances ) { echo esc_html__( 'Entire Site', 'elementor' ); } break; default: break; } } public function flush_permalinks_on_elementor_version_change() { if ( get_option( static::ROUTER_OPTION_KEY ) !== ELEMENTOR_VERSION ) { flush_rewrite_rules(); update_option( static::ROUTER_OPTION_KEY, ELEMENTOR_VERSION ); } } private function get_trashed_contact_posts(): array { if ( $this->trashed_contact_pages ) { return $this->trashed_contact_pages; } $this->trashed_contact_pages = $this->get_trashed_posts( static::CPT_FLOATING_BUTTONS, static::FLOATING_BUTTONS_DOCUMENT_TYPE ); return $this->trashed_contact_pages; } private function get_trashed_posts( string $cpt, string $document_type ) { $query = new \WP_Query( [ 'no_found_rows' => true, 'post_type' => $cpt, 'post_status' => 'trash', 'posts_per_page' => 1, 'meta_key' => '_elementor_template_type', 'meta_value' => $document_type, ] ); return $query->posts; } private function get_add_new_contact_page_url() { if ( ElementorUtils::has_pro() ) { return Plugin::$instance->documents->get_create_new_post_url( static::CPT_FLOATING_BUTTONS, static::FLOATING_BUTTONS_DOCUMENT_TYPE ); } return Plugin::$instance->documents->get_create_new_post_url( static::CPT_FLOATING_BUTTONS, static::FLOATING_BUTTONS_DOCUMENT_TYPE ) . '#library'; } public function print_empty_contact_pages_page() { $template_sources = Plugin::$instance->templates_manager->get_registered_sources(); $source_local = $template_sources['local']; $trashed_posts = $this->get_trashed_contact_posts(); ?>