ID, self::META_KEY, true ); ?>
$id !== $post_id ) ); if ( $enabled ) { $order[] = $post_id; } SG7G_Settings::update_featured_order( $order ); } public static function remove_from_order( int $post_id ): void { if ( 'sg7g_media' !== get_post_type( $post_id ) ) { return; } $order = SG7G_Settings::featured_order(); $clean = array_values( array_filter( $order, static fn( int $id ): bool => $id !== $post_id ) ); if ( $clean !== $order ) { SG7G_Settings::update_featured_order( $clean ); } } /** * Return all contents marked as featured in the stored order. * * @param bool $published_only Limit results to public, non-password posts. * @return int[] */ public static function ordered_ids( bool $published_only = true ): array { $query_args = array( 'post_type' => 'sg7g_media', 'post_status' => $published_only ? 'publish' : array( 'publish', 'draft', 'pending', 'private', 'future' ), 'posts_per_page' => -1, 'fields' => 'ids', 'orderby' => 'date', 'order' => 'DESC', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Plugin-owned featured flag. 'meta_key' => self::META_KEY, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Plugin-owned featured flag. 'meta_value' => '1', 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ); if ( $published_only ) { $query_args['has_password'] = false; } $marked = get_posts( $query_args ); $marked = array_values( array_unique( array_map( 'absint', $marked ) ) ); if ( empty( $marked ) ) { return array(); } $stored = SG7G_Settings::featured_order(); $ordered = array_values( array_intersect( $stored, $marked ) ); foreach ( $marked as $post_id ) { if ( ! in_array( $post_id, $ordered, true ) ) { $ordered[] = $post_id; } } return $ordered; } /** * Return the contents currently visible in the featured area. * * @return int[] */ public static function display_ids(): array { if ( ! SG7G_Settings::enabled( 'show_featured' ) ) { return array(); } return array_slice( self::ordered_ids( true ), 0, self::visible_count() ); } /** * Return the number of featured items required by the selected layout. */ public static function visible_count(): int { return 5; } public static function render_settings_order(): void { $ids = self::ordered_ids( false ); $published_positions = array_flip( self::ordered_ids( true ) ); ?>