es' => [ 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options', 'create_posts' => 'manage_options', ], 'taxonomies' => [ Source_Local::TAXONOMY_TYPE_SLUG ], 'show_in_rest' => true, 'supports' => [ 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields', 'post-formats', 'elementor', ], ]; register_post_type( $cpt, $args ); } private function has_contact_pages(): bool { if ( null !== $this->has_contact_pages ) { return $this->has_contact_pages; } $this->has_contact_pages = $this->has_pages( static::CPT_FLOATING_BUTTONS, static::FLOATING_BUTTONS_DOCUMENT_TYPE ); return $this->has_contact_pages; } private function has_pages( string $cpt, string $document_type ): bool { $posts_query = new \WP_Query( [ 'no_found_rows' => true, 'post_type' => $cpt, 'post_status' => 'any', 'posts_per_page' => 1, 'meta_key' => '_elementor_template_type', 'meta_value' => $document_type, ] ); return $posts_query->post_count > 0; } private function get_contact_menu_args(): array { if ( $this->has_contact_pages() ) { $menu_slug = static::ADMIN_PAGE_SLUG_CONTACT; $function = null; } else { $menu_slug = static::CPT_FLOATING_BUTTONS; $function = [ $this, 'print_empty_contact_pages_page' ]; } return [ 'menu_slug' => $menu_slug, 'function' => $function, ]; } public function override_admin_bar_add_contact( $admin_bar ): void { $new_contact_page_node = $admin_bar->get_node( 'new-e-floating-buttons' ); if ( $new_contact_page_node ) { $new_contact_page_node->href = $this->get_add_new_contact_page_url(); $admin_bar->add_node( $new_contact_page_node ); } } private function editor_localize_settings( $data ) { $data['admin_floating_button_admin_url'] = admin_url( $this->get_contact_menu_args()['menu_slug'] ); return $data; } private function render_floating_buttons(): void { if ( Plugin::$instance->preview->is_preview_mode() ) { $post_id = ElementorUtils::get_super_global_value( $_GET, 'elementor-preview' ); $document = Plugin::$instance->documents->get( $post_id ); if ( $document instanceof Document && $document->get_name() === static::FLOATING_BUTTONS_DOCUMENT_TYPE ) { return; } } $query = new \WP_Query( [ 'post_type' => static::CPT_FLOATING_BUTTONS, 'posts_per_page' => - 1, 'post_status' => 'publish', 'fields' => 'ids', 'meta_key' => '_elementor_conditions', 'meta_compare' => 'EXISTS', ] ); if ( ! $query->have_posts() ) { return; } foreach ( $query->posts as $post_id ) { $conditions = get_post_meta( $post_id, '_elementor_conditions', true ); if ( ! $conditions ) { continue; } if ( in_array( 'include/general', $conditions ) && ! $this->is_preview_for_document( $post_id ) && get_the_ID() !== $post_id ) { $document = Plugin::$instance->documents->get( $post_id ); $document->print_content(); } } } /** * Register styles. * * At build time, Elementor compiles `/modules/floating-buttons/assets/scss/widgets/*.scss` * to `/assets/css/widget-*.min.css`. * * @return void */ public function register_styles() { $direction_suffix = is_rtl() ? '-rtl' : ''; $widget_styles = $this->get_widgets_style_list(); $has_custom_breakpoints = Plugin::$instance->breakpoints->has_custom_breakpoints(); foreach ( $widget_styles as $widget_style_name => $widget_has_responsive_style ) { $should_load_responsive_css = $widget_has_responsive_style ? $has_custom_breakpoints : false; wp_register_style( $widget_style_name, $this->get_frontend_file_url( "{$widget_style_name}{$direction_suffix}.min.css", $should_load_responsive_css ), [ 'elementor-frontend', 'elementor-icons' ], $should_load_responsive_css ? null : ELEMENTOR_VERSION ); } } private function get_widgets_style_list(): array { return [ 'widget-floating-buttons' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, // TODO: Remove in v3.27.0 [ED-15717] 'widget-floating-bars-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-floating-bars-var-2' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-floating-bars-var-3' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-base' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-1' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-3' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-4' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-6' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-7' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-8' => ! self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-9' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, 'widget-contact-buttons-var-10' => self::WIDGET_HAS_CUSTOM_BREAKPOINTS, ]; } }