e ) ) { $this->update_taxonomy_settings_controls( $source_type ); } else { $this->update_post_settings_controls( $source_type ); } } /** * @param array $new_categories * @return array */ private static function insert_categories_after_favorites( array $new_categories ) { $existing_categories = parent::get_editor_panel_categories(); $category_keys = array_keys( $existing_categories ); $index = array_search( 'favorites', $category_keys, true ); return array_splice( $existing_categories, 0, $index + 1 ) + $new_categories + array_splice( $existing_categories, $index + 1 ); } private function update_post_settings_controls( $source_type ) { $this->update_control( self::PREVIEW_TYPE, [ 'default' => self::SINGLE_PREFIX . $source_type, 'label' => esc_html__( 'Preview a specific post or item', 'elementor-pro' ), ] ); $latest_posts = get_posts( [ 'posts_per_page' => 1, 'post_type' => $source_type, ] ); if ( ! empty( $latest_posts ) ) { $this->update_control( self::PREVIEW_ID, [ 'default' => $latest_posts[0]->ID, ] ); } } private function update_taxonomy_settings_controls( $source_type ) { $this->update_taxonomy_preview_type_control( $source_type ); $this->update_taxonomy_preview_id_control( $source_type ); } private function update_taxonomy_preview_type_control( $source_type ) { $post_type_slug = $this->extract_taxonomy_type( $source_type ); $allowed_post_types = Taxonomy_Loop_Provider::get_supported_cpts( $post_type_slug ); $options_prefix = $source_type . '/'; $taxonomy_options = $this->get_taxonomy_options( $allowed_post_types, $options_prefix ); $this->update_control( self::PREVIEW_TYPE, [ 'default' => Taxonomy_Loop_Provider::get_default_source_type( $source_type, $options_prefix ), 'groups' => [ 'archive' => [ 'label' => esc_html__( 'Archive', 'elementor-pro' ), 'options' => $taxonomy_options, ], ], 'label' => esc_html__( 'Preview a specific post or item', 'elementor-pro' ), ] ); } private function update_taxonomy_preview_id_control( $source_type ) { $term_id = $this->get_settings_for_display( self::PREVIEW_ID ) ?? null; $filter_args = [ 'taxonomy' => Taxonomy_Loop_Provider::get_default_source_type( $source_type ), 'show_empty_items' => 'yes', 'show_child_taxonomy' => 'yes', ]; if ( $term_id ) { $filter_args['term_taxonomy_id'] = $term_id; } $latest_terms = $this->get_filtered_taxonomies( $filter_args, [] ); if ( ! empty( $latest_terms ) ) { $term = array_values( $latest_terms )[0]; $this->update_control( self::PREVIEW_ID, [ 'default' => $term->term_id, 'autocomplete' => [ 'object' => QueryModule::QUERY_OBJECT_TAX, ], ], ); } } private function extract_taxonomy_type( $source_type ) { return str_replace( '_taxonomy', '', $source_type ); } }