' . esc_html__( 'No active meta tags.', 'ai-for-seo' ) . '

'; return; } $ai4seo_can_administer_plugin = ai4seo_can_administer_plugin(); $ai4seo_metadata_field_states_by_post_ids = array(); $ai4seo_metadata_coverage_read_succeeded = false; require_once __DIR__ . '/list-filters.php'; $ai4seo_list_status_snapshot = ai4seo_read_content_type_status_snapshot( AI4SEO_BULK_GENERATION_QUEUE_CONTEXT_METADATA, true ); $ai4seo_list_read_failures = ai4seo_content_type_list_read_failures(); $ai4seo_list_coverage_issues = array(); // ___________________________________________________________________________________________ \\ // === PREPARE =============================================================================== \\ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ \\ $ai4seo_supported_post_types = ai4seo_get_supported_post_types(); $ai4seo_post_type = ai4seo_get_active_post_type_subpage(); if ( ! in_array( $ai4seo_post_type, $ai4seo_supported_post_types, true ) ) { echo 'Unknown post type: ' . esc_html( $ai4seo_post_type ); return; } $ai4seo_post_type_label_singular = ai4seo_get_post_type_singular_label( $ai4seo_post_type ); $ai4seo_translated_post_type_plural = ai4seo_get_post_type_translation( $ai4seo_post_type, true ); // sanitize and get current page (pagination). // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Capability-gated read-only pagination cursor; no state is changed. $ai4seo_current_page = absint( wp_unslash( $_REQUEST['ai4seo_page'] ?? 1 ) ); if ( $ai4seo_current_page < 1 ) { $ai4seo_current_page = 1; } $ai4seo_account_readiness = ai4seo_get_account_readiness(); $ai4seo_current_credits_balance = $ai4seo_account_readiness['credits']; // Define variable for the label of the failed-metadata-generations-link. $ai4seo_retry_all_failed_metadata_generations_link_label = __( 'Retry all failed', 'ai-for-seo' ); // retry all failed metadata generations link. $ai4seo_retry_all_failed_metadata_generations_link_tag = $ai4seo_can_administer_plugin ? ai4seo_get_small_icon_button_tag( 'rotate', $ai4seo_retry_all_failed_metadata_generations_link_label, '', "ai4seo_retry_all_failed_metadata(this, '" . esc_js( $ai4seo_post_type ) . "'); return false;" ) : ''; // Give AJAX hydration a stable target that is scoped to this post-type table. $ai4seo_retry_all_failed_metadata_generations_container_id = 'ai4seo-retry-all-failed-metadata-' . sanitize_html_class( $ai4seo_post_type ); $ai4seo_consider_purchasing_more_credits_link_tag = $ai4seo_can_administer_plugin ? ai4seo_get_small_icon_button_tag( 'circle-plus', __( 'Get more Credits', 'ai-for-seo' ), 'ai4seo-primary-button', 'ai4seo_close_all_modals(); ai4seo_open_get_more_credits_modal();' ) : ''; // get value for bulk toggle checkbox. $ai4seo_is_bulk_generation_activated = ai4seo_is_bulk_generation_enabled( $ai4seo_post_type ); $ai4seo_is_bulk_generation_checked_phrase = ( $ai4seo_is_bulk_generation_activated ? 'checked' : '' ); $ai4seo_should_auto_queue_bulk_generation_entries = ai4seo_should_auto_queue_bulk_generation_entries(); $ai4seo_disabled_post_author_ids = ai4seo_get_disabled_post_author_ids(); $ai4seo_disabled_taxonomy_terms = ai4seo_get_enforced_disabled_taxonomy_terms(); // Read metadata WPML exclusions once so filters, status counts, and queue previews use the same scope. $ai4seo_disabled_metadata_wpml_language_codes = ai4seo_get_disabled_metadata_wpml_language_codes(); $ai4seo_do_generate_metadata_for_fully_covered_entries = ai4seo_do_generate_metadata_for_fully_covered_entries(); // ___________________________________________________________________________________________ \\ // === READ POSTS ============================================================================ \\ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ \\ // Prepare arguments for the wp-query. $ai4seo_posts_query_arguments = array( 'post_status' => array( 'publish', 'future' ), 'post_type' => $ai4seo_post_type, 'posts_per_page' => 20, 'orderby' => 'ID', 'order' => 'DESC', 'perm' => 'editable', // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters -- The editable content inventory deliberately includes every language. 'suppress_filters' => true, 'lang' => 'all', ); if ( $ai4seo_disabled_post_author_ids ) { $ai4seo_posts_query_arguments['author__not_in'] = $ai4seo_disabled_post_author_ids; } // Build the shared filter context first; post lists defer search IDs to the optimized resolver. $ai4seo_filter_setup_arguments = array( 'form_action' => ai4seo_get_post_type_page_url( $ai4seo_post_type, 1 ), 'nonce_action' => 'ai4seo_content_type_filter_form', 'nonce_name' => 'ai4seo_content_type_filter_nonce', 'post_types' => array( $ai4seo_post_type ), 'post_status' => array( 'publish', 'future' ), 'author_not_in' => $ai4seo_disabled_post_author_ids, 'disabled_taxonomy_terms' => $ai4seo_disabled_taxonomy_terms, 'disabled_wpml_language_codes' => $ai4seo_disabled_metadata_wpml_language_codes, 'defer_search_ids' => true, 'per_page' => 20, ); $ai4seo_filter_context = ai4seo_setup_content_type_filters( $ai4seo_filter_setup_arguments ); $ai4seo_filter_status = $ai4seo_filter_context['filter_status']; $ai4seo_filter_language = $ai4seo_filter_context['filter_language']; // Reuse the shared sort normalizer so rows, links, and AJAX-hydrated filters stay in sync. $ai4seo_sort_args = ai4seo_normalize_content_type_sort_args( $ai4seo_filter_context['orderby'] ?? 'id', $ai4seo_filter_context['order'] ?? 'desc' ); $ai4seo_orderby = $ai4seo_sort_args['orderby']; $ai4seo_order = $ai4seo_sort_args['order']; $ai4seo_search_ids = $ai4seo_filter_context['search_ids']; $ai4seo_items_per_page = (int) $ai4seo_filter_context['per_page']; if ( $ai4seo_items_per_page < 1 ) { $ai4seo_items_per_page = 20; } // Pagination reuses the exact active filter args produced by the shared filter helper. $ai4seo_filter_query_args = ai4seo_get_content_type_filter_query_args( $ai4seo_filter_context ); $ai4seo_bulk_generation_new_or_existing_filter = ai4seo_get_setting( AI4SEO_SETTING_BULK_GENERATION_NEW_OR_EXISTING_FILTER ); $ai4seo_bulk_generation_new_or_existing_filter_reference_timestamp = ai4seo_read_environmental_variable( AI4SEO_ENVIRONMENTAL_VARIABLE_BULK_GENERATION_NEW_OR_EXISTING_FILTER_REFERENCE_TIME ); $ai4seo_bulk_generation_date_filter_state = ai4seo_get_bulk_generation_date_filter_state( $ai4seo_bulk_generation_new_or_existing_filter, $ai4seo_bulk_generation_new_or_existing_filter_reference_timestamp ); $ai4seo_metadata_credits_costs_per_post = ai4seo_calculate_metadata_credits_cost_per_post(); // Start with empty per-page state; the optimized resolver fills only what row rendering needs. $ai4seo_pending_metadata_post_ids = array(); $ai4seo_processing_metadata_post_ids = array(); $ai4seo_all_failed_metadata_post_ids = array(); $ai4seo_hidden_metadata_post_ids = array(); $ai4seo_auto_queue_disallowed_metadata_post_ids = array(); $ai4seo_missing_metadata_post_ids = array(); $ai4seo_fully_covered_metadata_post_ids = array(); $ai4seo_generated_metadata_post_ids = array(); $ai4seo_waiting_to_get_queued_metadata_post_ids = array(); $ai4seo_status_filter_counts = array(); $ai4seo_total_items = 0; $ai4seo_total_pages = 1; $ai4seo_current_page_post_ids = array(); $ai4seo_sort_value_map = array(); $ai4seo_should_derive_current_page_metadata_status_ids = false; $ai4seo_should_defer_status_filters = false; // Optimized SQL has no per-user capability clause, so ownership-restricted users keep the exact WP_Query path. $ai4seo_content_type_list_result = array( 'is_optimized' => false ); if ( ai4seo_uses_post_state_tables() || ai4seo_can_edit_others_posts_for_post_types( array( $ai4seo_post_type ) ) ) { $ai4seo_content_type_list_result = ai4seo_resolve_optimized_post_content_type_list( array( 'post_type' => $ai4seo_post_type, 'post_status' => array( 'publish', 'future' ), 'author_not_in' => $ai4seo_disabled_post_author_ids, 'disabled_taxonomy_terms' => $ai4seo_disabled_taxonomy_terms, 'disabled_wpml_language_codes' => $ai4seo_disabled_metadata_wpml_language_codes, 'filter_status' => $ai4seo_filter_status, 'filter_text' => (string) ( $ai4seo_filter_context['filter_text'] ?? '' ), 'filter_language' => $ai4seo_filter_language, 'orderby' => $ai4seo_orderby, 'order' => $ai4seo_order, 'current_page' => $ai4seo_current_page, 'per_page' => $ai4seo_items_per_page, 'status_options' => $ai4seo_filter_context['status_options'], 'is_bulk_generation_activated' => $ai4seo_is_bulk_generation_activated, 'should_auto_queue_bulk_generation_entries' => $ai4seo_should_auto_queue_bulk_generation_entries, 'has_enough_credits' => ( $ai4seo_account_readiness['credits_ready'] && $ai4seo_current_credits_balance >= $ai4seo_metadata_credits_costs_per_post ), 'new_or_existing_filter' => $ai4seo_bulk_generation_new_or_existing_filter, 'new_or_existing_filter_reference_timestamp' => $ai4seo_bulk_generation_new_or_existing_filter_reference_timestamp, ) ); } if ( ! empty( $ai4seo_content_type_list_result['is_optimized'] ) ) { // The optimized resolver returns row IDs, counts, and current-page status membership as one coherent snapshot. $ai4seo_current_page = (int) ( $ai4seo_content_type_list_result['current_page'] ?? $ai4seo_current_page ); $ai4seo_current_page_post_ids = ai4seo_filter_editable_post_ids( (array) ( $ai4seo_content_type_list_result['post_ids'] ?? array() ) ); $ai4seo_total_items = (int) ( $ai4seo_content_type_list_result['total_items'] ?? 0 ); $ai4seo_total_pages = (int) ( $ai4seo_content_type_list_result['total_pages'] ?? 1 ); $ai4seo_status_filter_counts = (array) ( $ai4seo_content_type_list_result['status_counts'] ?? array() ); $ai4seo_sort_value_map = (array) ( $ai4seo_content_type_list_result['sort_value_map'] ?? array() ); $ai4seo_should_derive_current_page_metadata_status_ids = (bool) ( $ai4seo_content_type_list_result['should_derive_current_page_metadata_status_ids'] ?? false ); $ai4seo_should_defer_status_filters = (bool) ( $ai4seo_content_type_list_result['should_defer_status_counts'] ?? false ); $ai4seo_current_page_status_ids = (array) ( $ai4seo_content_type_list_result['current_page_status_ids'] ?? array() ); $ai4seo_pending_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['queued'] ?? array() ); $ai4seo_processing_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['processing'] ?? array() ); $ai4seo_all_failed_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['failed'] ?? array() ); $ai4seo_hidden_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['hidden'] ?? array() ); $ai4seo_auto_queue_disallowed_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['auto_queue_disallowed'] ?? array() ); $ai4seo_missing_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['missing'] ?? array() ); $ai4seo_fully_covered_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['complete'] ?? array() ); $ai4seo_generated_metadata_post_ids = (array) ( $ai4seo_current_page_status_ids['generated'] ?? array() ); } else { // Complex filters keep the legacy exact path so WPML/taxonomy/SEO-progress behavior remains unchanged. if ( '' !== $ai4seo_filter_context['filter_text'] ) { $ai4seo_filter_setup_arguments['defer_search_ids'] = false; $ai4seo_filter_context = ai4seo_setup_content_type_filters( $ai4seo_filter_setup_arguments ); $ai4seo_filter_status = $ai4seo_filter_context['filter_status']; $ai4seo_filter_language = $ai4seo_filter_context['filter_language']; // Re-normalize after the legacy search setup rebuilds the filter context. $ai4seo_sort_args = ai4seo_normalize_content_type_sort_args( $ai4seo_filter_context['orderby'] ?? 'id', $ai4seo_filter_context['order'] ?? 'desc' ); $ai4seo_orderby = $ai4seo_sort_args['orderby']; $ai4seo_order = $ai4seo_sort_args['order']; $ai4seo_search_ids = $ai4seo_filter_context['search_ids']; $ai4seo_filter_query_args = ai4seo_get_content_type_filter_query_args( $ai4seo_filter_context ); } // The legacy path reads global status options because it must match the old all-candidate behavior exactly. $ai4seo_pending_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['queued']; $ai4seo_processing_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['processing']; $ai4seo_all_failed_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['failed']; $ai4seo_hidden_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['hidden']; $ai4seo_auto_queue_disallowed_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['auto_queue_disallowed']; $ai4seo_missing_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['missing']; $ai4seo_fully_covered_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['complete']; $ai4seo_generated_metadata_post_ids = $ai4seo_list_status_snapshot['ids']['generated']; // Search fallbacks can reuse precomputed search IDs; otherwise they intentionally use the old full candidate scan. if ( is_array( $ai4seo_search_ids ) ) { $ai4seo_candidate_post_ids = $ai4seo_search_ids; } else { $ai4seo_candidate_arguments = $ai4seo_posts_query_arguments; $ai4seo_candidate_arguments['fields'] = 'ids'; $ai4seo_candidate_arguments['posts_per_page'] = -1; $ai4seo_candidate_arguments['no_found_rows'] = true; $ai4seo_candidate_arguments['lang'] = 'all'; $ai4seo_candidate_post_ids = ai4seo_with_wpml_all_languages( function () use ( $ai4seo_candidate_arguments ) { $posts = get_posts( $ai4seo_candidate_arguments ); if ( $GLOBALS['wpdb']->last_error ) { ai4seo_content_type_list_read_failures( true ); } return $posts; } ); } $ai4seo_candidate_post_ids = ai4seo_filter_editable_post_ids( (array) $ai4seo_candidate_post_ids ); rsort( $ai4seo_candidate_post_ids, SORT_NUMERIC ); $ai4seo_candidate_post_ids = ai4seo_filter_post_ids_by_disabled_taxonomy_terms( $ai4seo_candidate_post_ids, $ai4seo_disabled_taxonomy_terms ); $ai4seo_candidate_post_ids = ai4seo_filter_post_ids_by_language( $ai4seo_candidate_post_ids, $ai4seo_filter_language ); // Apply WPML active-language scope after the selected-language filter because both rely on per-entry WPML details. $ai4seo_candidate_post_ids = ai4seo_filter_post_ids_by_disabled_wpml_languages( $ai4seo_candidate_post_ids, $ai4seo_disabled_metadata_wpml_language_codes ); $ai4seo_visible_candidate_post_ids = array_values( array_diff( $ai4seo_candidate_post_ids, $ai4seo_hidden_metadata_post_ids ) ); // Waiting-to-queue is derived after hidden/language/taxonomy filters because it depends on visible missing entries. $ai4seo_waiting_to_get_queued_metadata_post_ids = ai4seo_get_content_type_waiting_to_get_queued_post_ids( $ai4seo_visible_candidate_post_ids, $ai4seo_missing_metadata_post_ids, $ai4seo_pending_metadata_post_ids, $ai4seo_processing_metadata_post_ids, $ai4seo_all_failed_metadata_post_ids, array( 'is_bulk_generation_activated' => $ai4seo_is_bulk_generation_activated, 'should_auto_queue_bulk_generation_entries' => $ai4seo_should_auto_queue_bulk_generation_entries, 'has_enough_credits' => ( $ai4seo_account_readiness['credits_ready'] && $ai4seo_current_credits_balance >= $ai4seo_metadata_credits_costs_per_post ), 'new_or_existing_filter' => $ai4seo_bulk_generation_new_or_existing_filter, 'new_or_existing_filter_reference_timestamp' => $ai4seo_bulk_generation_new_or_existing_filter_reference_timestamp, 'hidden_ids' => $ai4seo_hidden_metadata_post_ids, 'auto_queue_disallowed_ids' => $ai4seo_auto_queue_disallowed_metadata_post_ids, ) ); $ai4seo_search_status_map = array( 'complete' => $ai4seo_fully_covered_metadata_post_ids, 'missing' => $ai4seo_missing_metadata_post_ids, 'waiting_to_queue' => $ai4seo_waiting_to_get_queued_metadata_post_ids, 'queued' => $ai4seo_pending_metadata_post_ids, 'processing' => $ai4seo_processing_metadata_post_ids, 'failed' => $ai4seo_all_failed_metadata_post_ids, 'hidden' => $ai4seo_hidden_metadata_post_ids, ); // Legacy counters and row filtering share the same status map to preserve old tab behavior. $ai4seo_status_filter_counts = ai4seo_get_content_type_filter_status_counts( $ai4seo_candidate_post_ids, $ai4seo_search_status_map, $ai4seo_filter_context['status_options'], $ai4seo_hidden_metadata_post_ids ); $ai4seo_filtered_candidate_post_ids = ai4seo_filter_post_ids_by_status( $ai4seo_candidate_post_ids, 'unverified' === $ai4seo_filter_status ? 'all' : $ai4seo_filter_status, $ai4seo_search_status_map, $ai4seo_hidden_metadata_post_ids ); $ai4seo_filtered_candidate_post_ids = array_values( array_unique( array_map( 'intval', $ai4seo_filtered_candidate_post_ids ) ) ); $ai4seo_sort_value_map = array(); if ( 'seo_progress' === $ai4seo_orderby ) { $ai4seo_sort_value_map = ai4seo_read_percentage_of_available_metadata_by_post_ids( $ai4seo_filtered_candidate_post_ids, 0, $ai4seo_metadata_coverage_read_succeeded, $ai4seo_metadata_field_states_by_post_ids, $ai4seo_list_coverage_issues ); } $ai4seo_filtered_candidate_post_ids = ai4seo_sort_content_type_ids( $ai4seo_filtered_candidate_post_ids, $ai4seo_orderby, $ai4seo_order, $ai4seo_sort_value_map ); $ai4seo_total_items = count( $ai4seo_filtered_candidate_post_ids ); $ai4seo_total_pages = $ai4seo_total_items ? (int) ceil( $ai4seo_total_items / $ai4seo_items_per_page ) : 1; if ( $ai4seo_total_pages < 1 ) { $ai4seo_total_pages = 1; } if ( $ai4seo_current_page > $ai4seo_total_pages ) { $ai4seo_current_page = $ai4seo_total_pages; } if ( $ai4seo_current_page < 1 ) { $ai4seo_current_page = 1; } $ai4seo_offset = ( $ai4seo_current_page - 1 ) * $ai4seo_items_per_page; $ai4seo_current_page_post_ids = array_slice( $ai4seo_filtered_candidate_post_ids, $ai4seo_offset, $ai4seo_items_per_page ); } ai4seo_prepare_content_type_list_view( $ai4seo_filter_context, $ai4seo_status_filter_counts, $ai4seo_current_page_post_ids, $ai4seo_list_status_snapshot, $ai4seo_list_read_failures ); if ( 'unverified' === $ai4seo_filter_status ) { $ai4seo_list_status_snapshot['actions_available'] = false; } $ai4seo_all_posts = array(); // Fetch only the resolved current-page posts; both optimized and fallback paths provide IDs in display order. if ( $ai4seo_current_page_post_ids ) { $ai4seo_posts_query_arguments['post__in'] = $ai4seo_current_page_post_ids; $ai4seo_posts_query_arguments['orderby'] = 'post__in'; $ai4seo_posts_query_arguments['order'] = 'DESC'; $ai4seo_posts_query_arguments['posts_per_page'] = count( $ai4seo_current_page_post_ids ); $ai4seo_post_data = ai4seo_with_wpml_all_languages( function () use ( $ai4seo_posts_query_arguments ) { $query = new WP_Query( $ai4seo_posts_query_arguments ); if ( $GLOBALS['wpdb']->last_error ) { ai4seo_content_type_list_read_failures( true ); } return $query; } ); $ai4seo_all_posts = ( $ai4seo_post_data instanceof WP_Query ) ? ( $ai4seo_post_data->posts ?? array() ) : array(); unset( $ai4seo_post_data ); } // fetch all post ids from this page. ai4seo_prepare_content_type_list_view( $ai4seo_filter_context, $ai4seo_status_filter_counts, $ai4seo_current_page_post_ids, $ai4seo_list_status_snapshot, $ai4seo_list_read_failures ); $ai4seo_current_post_ids = array_map( function ( $post ) { return (int) $post->ID; }, $ai4seo_all_posts ); $ai4seo_recent_metadata_activity_entries_by_post_id = ai4seo_get_latest_activity_entries_by_post_id( array( 'metadata-bulk-generated', ) ); // get percentage of active metadata for all posts. $ai4seo_percentage_of_active_metadata_by_post_ids = ( 'seo_progress' === $ai4seo_orderby ) && $ai4seo_sort_value_map ? array_intersect_key( $ai4seo_sort_value_map, array_flip( $ai4seo_current_post_ids ) ) : ai4seo_read_percentage_of_available_metadata_by_post_ids( $ai4seo_current_post_ids, 0, $ai4seo_metadata_coverage_read_succeeded, $ai4seo_metadata_field_states_by_post_ids, $ai4seo_list_coverage_issues ); // Retain only the visible rows after a coverage sort has inspected the candidate batch. $ai4seo_metadata_field_states_by_post_ids = array_intersect_key( $ai4seo_metadata_field_states_by_post_ids, array_flip( $ai4seo_current_post_ids ) ); // Large all-lists avoid global coverage options and derive complete/missing state from the rendered page only. if ( $ai4seo_should_derive_current_page_metadata_status_ids ) { $ai4seo_generated_metadata_post_ids = ai4seo_read_post_ids_with_postmeta_key( $ai4seo_current_post_ids, AI4SEO_POST_META_GENERATED_DATA_META_KEY ); $ai4seo_generated_metadata_post_id_lookup = array_flip( array_map( 'intval', $ai4seo_generated_metadata_post_ids ) ); $ai4seo_fully_covered_metadata_post_ids = array(); $ai4seo_missing_metadata_post_ids = array(); foreach ( $ai4seo_current_post_ids as $ai4seo_this_current_post_id ) { if ( ! isset( $ai4seo_percentage_of_active_metadata_by_post_ids[ $ai4seo_this_current_post_id ] ) ) { continue; } $ai4seo_this_current_post_id = (int) $ai4seo_this_current_post_id; $ai4seo_this_current_post_coverage = (int) ( $ai4seo_percentage_of_active_metadata_by_post_ids[ $ai4seo_this_current_post_id ] ?? 0 ); $ai4seo_this_current_post_is_generated = isset( $ai4seo_generated_metadata_post_id_lookup[ $ai4seo_this_current_post_id ] ); if ( $ai4seo_this_current_post_coverage >= 100 && ( ! $ai4seo_do_generate_metadata_for_fully_covered_entries || $ai4seo_this_current_post_is_generated ) ) { $ai4seo_fully_covered_metadata_post_ids[] = $ai4seo_this_current_post_id; continue; } $ai4seo_missing_metadata_post_ids[] = $ai4seo_this_current_post_id; } } // read all key phrases for all posts in $ai4seo_this_page_post_ids. $ai4seo_third_party_seo_plugin_key_phrases = ai4seo_read_third_party_seo_plugin_key_phrases( $ai4seo_current_post_ids ); // remove entries from $ai4seo_failed_to_fill_post_ids that are not on this page. // Canonicalize status sources once before every strict row-level membership check below. $ai4seo_all_failed_metadata_post_ids = ai4seo_normalize_post_ids_from_option_value( $ai4seo_all_failed_metadata_post_ids ); $ai4seo_fully_covered_metadata_post_ids = ai4seo_normalize_post_ids_from_option_value( $ai4seo_fully_covered_metadata_post_ids ); $ai4seo_generated_metadata_post_ids = ai4seo_normalize_post_ids_from_option_value( $ai4seo_generated_metadata_post_ids ); $ai4seo_current_page_failed_to_fill_post_ids = array(); if ( $ai4seo_all_posts ) { foreach ( $ai4seo_all_posts as $ai4seo_this_post ) { $ai4seo_this_post_id = (int) $ai4seo_this_post->ID; if ( in_array( $ai4seo_this_post_id, $ai4seo_all_failed_metadata_post_ids, true ) ) { $ai4seo_current_page_failed_to_fill_post_ids[] = $ai4seo_this_post_id; } } } $ai4seo_all_failed_metadata_post_ids = $ai4seo_current_page_failed_to_fill_post_ids; // Retry-all visibility follows the same count-backed rule that makes the Failed status filter visible. $ai4seo_should_show_retry_all_failed_metadata_generations_link = $ai4seo_can_administer_plugin && ai4seo_should_show_content_type_retry_all_failed_button( $ai4seo_filter_context['status_options'], $ai4seo_status_filter_counts ); $ai4seo_retry_all_failed_metadata_generations_container_class = $ai4seo_should_show_retry_all_failed_metadata_generations_link ? '' : ' ai4seo-display-none'; $ai4seo_active_meta_tags = ai4seo_get_active_meta_tags(); $ai4seo_active_meta_tags_names = array(); foreach ( $ai4seo_metadata_field_descriptors as $ai4seo_field_identifier => $ai4seo_field_details ) { if ( in_array( $ai4seo_field_identifier, $ai4seo_active_meta_tags, true ) && isset( $ai4seo_field_details['name'] ) ) { $ai4seo_active_meta_tags_names[ $ai4seo_field_identifier ] = $ai4seo_field_details['name']; } } $ai4seo_bulk_generation_queue_checkbox_name = 'ai4seo_bulk_generation_queue_post_ids'; $ai4seo_bulk_generation_queue_action_controls = ai4seo_get_bulk_generation_queue_action_controls( AI4SEO_BULK_GENERATION_QUEUE_CONTEXT_METADATA, $ai4seo_bulk_generation_queue_checkbox_name, $ai4seo_filter_status ); $ai4seo_content_type_filter_controls_html = ai4seo_get_content_type_filter_controls_html( $ai4seo_filter_context, $ai4seo_status_filter_counts, $ai4seo_total_items, $ai4seo_all_posts ? $ai4seo_bulk_generation_queue_action_controls : '', array( 'defer_status_filters' => $ai4seo_should_defer_status_filters, 'content_context' => AI4SEO_BULK_GENERATION_QUEUE_CONTEXT_METADATA, 'post_type' => $ai4seo_post_type, 'retry_all_failed_button_target' => $ai4seo_can_administer_plugin ? $ai4seo_retry_all_failed_metadata_generations_container_id : '', ) ); // ___________________________________________________________________________________________ \\ // === OUTPUT ================================================================================ \\ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ \\ // === TABLE WITH ALL POSTS ================================================================== \\ ai4seo_echo_wp_kses( $ai4seo_content_type_filter_controls_html ); ai4seo_echo_wp_kses( ai4seo_get_account_quality_notice() ); if ( ! $ai4seo_filter_context['view_available'] ) { echo '

' . esc_html( ai4seo_get_content_type_list_unavailable_message( $ai4seo_filter_context ) ) . '

'; return; } ai4seo_echo_wp_kses( ai4seo_get_content_type_selection_notice( $ai4seo_current_post_ids, array_keys( $ai4seo_percentage_of_active_metadata_by_post_ids ), $ai4seo_list_status_snapshot ) ); // Explain why automatic queuing is paused when persisted date-filter state cannot be used safely. if ( empty( $ai4seo_bulk_generation_date_filter_state['is_valid'] ) ) { echo "

" . esc_html__( 'SEO Autopilot paused:', 'ai-for-seo' ) . ' '; echo esc_html( ai4seo_get_invalid_bulk_generation_date_filter_message() ); echo '

'; } // Stop script if no posts have been found -> show message and stop page rendering. if ( ! $ai4seo_all_posts ) { $ai4seo_remove_filters_button_html = ai4seo_get_content_type_remove_filters_button_html( $ai4seo_filter_context ); echo '

'; if ( '' !== $ai4seo_filter_context['filter_text'] && 'all' !== $ai4seo_filter_status ) { printf( /* translators: 1: post type plural name, 2: selected status filter label. */ esc_html__( 'No %1$s match your search in %2$s.', 'ai-for-seo' ), esc_html( $ai4seo_translated_post_type_plural ), esc_html( $ai4seo_filter_context['status_options'][ $ai4seo_filter_status ] ), ); } else { printf( /* translators: %s: post type plural name */ esc_html__( 'No %s found.', 'ai-for-seo' ), esc_html( $ai4seo_translated_post_type_plural ), ); } if ( $ai4seo_remove_filters_button_html ) { echo ' '; ai4seo_echo_wp_kses( $ai4seo_remove_filters_button_html ); } echo '

'; return; } // Display table with entries. // Resolve active ARIA states once so table headers and their direction-toggle links stay synchronized. $ai4seo_id_column_aria_sort = ai4seo_get_content_type_sortable_column_aria_sort_value( 'id', $ai4seo_filter_context ); $ai4seo_title_column_aria_sort = ai4seo_get_content_type_sortable_column_aria_sort_value( 'title', $ai4seo_filter_context ); $ai4seo_seo_progress_column_aria_sort = ai4seo_get_content_type_sortable_column_aria_sort_value( 'seo_progress', $ai4seo_filter_context ); echo "
"; echo ""; echo ''; echo "'; echo "'; echo "'; echo "'; // Label the otherwise visual-only per-row action column for assistive technology. echo ''; echo ''; // Resolve the display timezone once before rendering post rows. $ai4seo_post_timestamp_timezone = ai4seo_get_timezone()->getName(); foreach ( $ai4seo_all_posts as $ai4seo_this_post ) { // Get post-ID. $ai4seo_this_post_id = (int) $ai4seo_this_post->ID; // Get post-title. $ai4seo_single_post_title = $ai4seo_this_post->post_title; $ai4seo_this_post_language = ai4seo_try_get_post_language_by_checking_multilanguage_plugins( $ai4seo_this_post_id ); $ai4seo_single_post_title_with_language = $ai4seo_single_post_title; if ( '' !== $ai4seo_this_post_language ) { $ai4seo_single_post_title_with_language .= ' (' . $ai4seo_this_post_language . ')'; } // Get post-link. $ai4seo_single_post_link = get_permalink( $ai4seo_this_post_id ); $ai4seo_this_post_date_gmt = (string) ( $ai4seo_this_post->post_date_gmt ?? '' ); $ai4seo_this_post_date = (string) ( $ai4seo_this_post->post_date ?? '' ); $ai4seo_this_post_modified_gmt = (string) ( $ai4seo_this_post->post_modified_gmt ?? '' ); $ai4seo_this_post_modified = (string) ( $ai4seo_this_post->post_modified ?? '' ); // Parse the absolute GMT value once; invalid and WordPress zero dates remain explicit missing data. $ai4seo_this_post_date_timestamp = false; $ai4seo_this_post_date_display = '-'; if ( ai4seo_is_valid_mysql_datetime( $ai4seo_this_post_date_gmt ) ) { $ai4seo_this_post_date_timestamp = strtotime( $ai4seo_this_post_date_gmt . ' UTC' ); } if ( false !== $ai4seo_this_post_date_timestamp ) { $ai4seo_this_post_date_display = ai4seo_format_unix_timestamp( $ai4seo_this_post_date_timestamp, 'auto', 'auto', ' ', $ai4seo_post_timestamp_timezone ); } // Keep row-level exclusion aligned with queue SQL and the waiting-to-queue status resolver. $ai4seo_is_excluded_by_new_or_existing_filter = ! empty( $ai4seo_bulk_generation_date_filter_state['is_valid'] ) && ! ai4seo_does_bulk_generation_date_filter_include_timestamp( $ai4seo_bulk_generation_date_filter_state, (int) $ai4seo_this_post_date_timestamp ); // this post meta coverage summary. if ( $ai4seo_active_meta_tags ) { $ai4seo_this_active_metadata_coverage_percentage = $ai4seo_percentage_of_active_metadata_by_post_ids[ $ai4seo_this_post_id ] ?? null; } else { $ai4seo_this_active_metadata_coverage_percentage = 100; } $ai4seo_this_post_is_fully_covered = null !== $ai4seo_this_active_metadata_coverage_percentage && $ai4seo_this_active_metadata_coverage_percentage >= 100 && in_array( $ai4seo_this_post_id, $ai4seo_fully_covered_metadata_post_ids, true ); $ai4seo_this_metadata_generation_is_not_finished = ! $ai4seo_this_post_is_fully_covered; $ai4seo_this_post_is_generated = $ai4seo_list_status_snapshot['quality']['generated'] ? in_array( $ai4seo_this_post_id, $ai4seo_generated_metadata_post_ids, true ) : null; $ai4seo_this_post_sub_info_rows = array(); $ai4seo_this_post_is_failed_to_fill = in_array( $ai4seo_this_post_id, $ai4seo_current_page_failed_to_fill_post_ids, true ); $ai4seo_this_post_has_recent_activity = isset( $ai4seo_recent_metadata_activity_entries_by_post_id[ $ai4seo_this_post_id ] ); $ai4seo_this_recent_activity_details_subtext_tag = ''; // Recent activity entries should link directly to the editor where details can be inspected. if ( $ai4seo_this_post_has_recent_activity ) { $ai4seo_this_recent_activity_details_onclick = 'ai4seo_open_metadata_editor_modal(' . absint( $ai4seo_this_post_id ) . ', false'; if ( $ai4seo_current_post_ids ) { $ai4seo_this_recent_activity_details_onclick .= ', ' . wp_json_encode( array_values( array_map( 'intval', $ai4seo_current_post_ids ) ) ); } $ai4seo_this_recent_activity_details_onclick .= ');'; $ai4seo_this_recent_activity_details_subtext_tag = ai4seo_get_recent_activity_details_subtext_tag( $ai4seo_this_recent_activity_details_onclick, $ai4seo_recent_metadata_activity_entries_by_post_id[ $ai4seo_this_post_id ] ); } // Retain raw UTC/local creation and modification values for diagnostics, with markers for missing data. $ai4seo_this_post_timestamp_tooltip = sprintf( /* translators: 1: post_date_gmt, 2: post_date, 3: post_modified_gmt, 4: post_modified */ __( "post_date_gmt: %1\$s\npost_date: %2\$s\npost_modified_gmt: %3\$s\npost_modified: %4\$s", 'ai-for-seo' ), $ai4seo_this_post_date_gmt ? $ai4seo_this_post_date_gmt : '-', $ai4seo_this_post_date ? $ai4seo_this_post_date : '-', $ai4seo_this_post_modified_gmt ? $ai4seo_this_post_modified_gmt : '-', $ai4seo_this_post_modified ? $ai4seo_this_post_modified : '-' ); $ai4seo_this_post_sub_info_rows[] = "" . sprintf( /* translators: %s: publish timestamp */ esc_html__( 'Publish time: %s', 'ai-for-seo' ), esc_html( $ai4seo_this_post_date_display ) ) . ''; $ai4seo_this_post_sub_info_rows[] = null === $ai4seo_this_post_is_generated ? esc_html__( 'Generation status unavailable.', 'ai-for-seo' ) : ( $ai4seo_this_post_is_generated ? sprintf( /* translators: %s: plugin name */ esc_html__( '%s has generated data for this entry.', 'ai-for-seo' ), esc_html( AI4SEO_PLUGIN_NAME ) ) : sprintf( /* translators: %s: plugin name */ __( "%s has not generated data for this entry yet.", 'ai-for-seo' ), esc_html( AI4SEO_PLUGIN_NAME ) ) ); $ai4seo_this_post_sub_info_html = "
" . implode( ' • ', $ai4seo_this_post_sub_info_rows ) . '
'; // Check queue state separately, so Pending and Processing can have different visuals. $ai4seo_is_post_missing = in_array( $ai4seo_this_post_id, $ai4seo_missing_metadata_post_ids, true ); $ai4seo_is_post_pending = in_array( $ai4seo_this_post_id, $ai4seo_pending_metadata_post_ids, true ); $ai4seo_is_post_processing = in_array( $ai4seo_this_post_id, $ai4seo_processing_metadata_post_ids, true ); $ai4seo_is_post_auto_queue_disallowed = in_array( $ai4seo_this_post_id, $ai4seo_auto_queue_disallowed_metadata_post_ids, true ); $ai4seo_is_post_waiting_to_get_queued = false; $ai4seo_is_insufficient_credits = false; $ai4seo_should_show_auto_queue_disallowed_note = false; // Failed entries should keep their failed state even if stale queue data exists. if ( $ai4seo_this_post_is_failed_to_fill ) { $ai4seo_is_post_pending = false; $ai4seo_is_post_processing = false; } // Missing entries are waiting for SEO Autopilot excavation only when auto queueing can actually pick them up. $ai4seo_row_readiness = ai4seo_get_content_type_row_readiness( $ai4seo_this_post_id, null !== $ai4seo_this_active_metadata_coverage_percentage, $ai4seo_list_status_snapshot ); $ai4seo_can_post_get_auto_queued = $ai4seo_is_bulk_generation_activated && $ai4seo_row_readiness['selectable'] && null !== $ai4seo_this_post_is_generated && $ai4seo_should_auto_queue_bulk_generation_entries && $ai4seo_is_post_missing && ! $ai4seo_is_post_pending && ! $ai4seo_is_post_processing && ! $ai4seo_this_post_is_failed_to_fill && ! $ai4seo_is_post_auto_queue_disallowed && ! $ai4seo_is_excluded_by_new_or_existing_filter && ( $ai4seo_this_metadata_generation_is_not_finished || ( ! $ai4seo_this_post_is_generated && $ai4seo_do_generate_metadata_for_fully_covered_entries ) ); if ( $ai4seo_can_post_get_auto_queued && $ai4seo_account_readiness['credits_ready'] ) { if ( $ai4seo_current_credits_balance < $ai4seo_metadata_credits_costs_per_post ) { $ai4seo_is_insufficient_credits = true; } else { $ai4seo_is_post_waiting_to_get_queued = true; } } // Display table-row for this post. echo ''; // Use the shared renderer so Posts and Pages receive identical labeled bulk-selection markup. echo "'; // Post-ID. echo ''; // Post-Title. echo "'; // Generation Coverage. echo "'; // Post-Edit-Link. echo ''; echo ''; } echo '
"; ai4seo_echo_wp_kses( ai4seo_get_select_all_checkbox( $ai4seo_bulk_generation_queue_checkbox_name, '' ) ); echo ''; ai4seo_echo_wp_kses( ai4seo_get_content_type_sortable_column_label_html( __( 'ID', 'ai-for-seo' ), 'id', $ai4seo_filter_context ) ); echo ''; ai4seo_echo_wp_kses( ai4seo_get_content_type_sortable_column_label_html( __( 'Title and key phrase', 'ai-for-seo' ), 'title', $ai4seo_filter_context ) ); echo ''; ai4seo_echo_wp_kses( ai4seo_get_content_type_sortable_column_label_html( __( 'Metadata coverage', 'ai-for-seo' ), 'seo_progress', $ai4seo_filter_context ) ); echo " / "; echo esc_html__( 'Title and key phrase', 'ai-for-seo' ); echo ''; // Keep the global retry action aligned with the Failed status filter, including deferred AJAX hydration. if ( $ai4seo_can_administer_plugin && ( $ai4seo_should_show_retry_all_failed_metadata_generations_link || $ai4seo_should_defer_status_filters ) ) { echo ''; echo "" . esc_html__( 'Actions', 'ai-for-seo' ) . ''; echo '
"; ai4seo_echo_wp_kses( ai4seo_get_bulk_generation_queue_entry_checkbox( $ai4seo_bulk_generation_queue_checkbox_name, $ai4seo_this_post_id, $ai4seo_single_post_title_with_language, $ai4seo_row_readiness['reason'] ) ); echo ''; echo esc_html( $ai4seo_this_post_id ); echo '"; echo ''; echo ""; echo esc_html( $ai4seo_single_post_title_with_language ); echo ''; if ( isset( $ai4seo_third_party_seo_plugin_key_phrases[ $ai4seo_this_post_id ] ) ) { echo " (" . esc_html( $ai4seo_third_party_seo_plugin_key_phrases[ $ai4seo_this_post_id ] ) . ')'; } echo ''; ai4seo_echo_wp_kses( $ai4seo_this_post_sub_info_html ); echo '"; if ( ! empty( $ai4seo_row_readiness['reason'] ) ) { echo '

' . esc_html( $ai4seo_row_readiness['reason'] ) . '

'; } if ( $ai4seo_active_meta_tags ) { $ai4seo_should_show_auto_queue_disallowed_note = $ai4seo_is_bulk_generation_activated && $ai4seo_should_auto_queue_bulk_generation_entries && $ai4seo_is_post_auto_queue_disallowed && $ai4seo_this_metadata_generation_is_not_finished && ! $ai4seo_is_post_pending && ! $ai4seo_is_post_processing; $ai4seo_should_show_autopilot_pending_note = $ai4seo_is_post_pending && ! $ai4seo_is_post_processing; // Reuse the list-wide progress helper so post and attachment rows expose identical accessibility metadata. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Static progress markup escapes every dynamic attribute with esc_attr(). echo ai4seo_get_seo_coverage_progress_bar_tag( $ai4seo_this_post_id, $ai4seo_this_active_metadata_coverage_percentage, '', $ai4seo_this_metadata_generation_is_not_finished, $ai4seo_post_type_label_singular, $ai4seo_active_meta_tags_names, $ai4seo_metadata_field_states_by_post_ids[ $ai4seo_this_post_id ] ?? array() ); if ( $ai4seo_is_post_waiting_to_get_queued ) { echo "
"; echo esc_html__( 'Waiting to get queued by SEO Autopilot...', 'ai-for-seo' ); echo '
'; } elseif ( $ai4seo_should_show_autopilot_pending_note ) { if ( $ai4seo_is_bulk_generation_activated ) { echo "
"; echo esc_html__( 'Queued for SEO Autopilot. Processing starts with a future SEO Autopilot run.', 'ai-for-seo' ); echo '
'; } else { echo "
"; echo esc_html__( 'Queued, but SEO Autopilot is deactivated for this content type.', 'ai-for-seo' ); echo '
'; } } elseif ( $ai4seo_is_post_processing ) { echo "
"; echo esc_html__( 'This entry is currently being processed.', 'ai-for-seo' ); echo '
'; } elseif ( $ai4seo_is_insufficient_credits ) { echo "
"; echo esc_html__( 'Insufficient Credits', 'ai-for-seo' ) . '.'; echo ' '; if ( $ai4seo_can_administer_plugin ) { ai4seo_echo_wp_kses( $ai4seo_consider_purchasing_more_credits_link_tag ); } echo '
'; } elseif ( $ai4seo_this_post_is_failed_to_fill && $ai4seo_this_metadata_generation_is_not_finished ) { echo "
"; echo '' . esc_html__( 'Failed to automatically fill metadata.', 'ai-for-seo' ) . ''; echo ' '; ai4seo_echo_wp_kses( ai4seo_get_small_icon_button_tag( 'arrow-up-right-from-square', __( 'Try it manually', 'ai-for-seo' ), '', 'ai4seo_open_metadata_editor_modal("' . esc_js( $ai4seo_this_post_id ) . '");' ) ); echo '
'; } elseif ( $ai4seo_is_excluded_by_new_or_existing_filter && $ai4seo_this_metadata_generation_is_not_finished ) { $ai4seo_new_or_existing_filter_reference_timestamp_formatted = ai4seo_format_unix_timestamp( (int) $ai4seo_bulk_generation_date_filter_state['reference_timestamp'] ); echo "
"; if ( 'new' === $ai4seo_bulk_generation_new_or_existing_filter ) { printf( /* translators: %s: reference timestamp */ esc_html__( "Excluded by 'New or existing entries' filter: Published before %s.", 'ai-for-seo' ), esc_html( $ai4seo_new_or_existing_filter_reference_timestamp_formatted ) ); } elseif ( 'existing' === $ai4seo_bulk_generation_new_or_existing_filter ) { printf( /* translators: %s: reference timestamp */ esc_html__( "Excluded by 'New or existing entries' filter: Published after %s.", 'ai-for-seo' ), esc_html( $ai4seo_new_or_existing_filter_reference_timestamp_formatted ) ); } else { echo esc_html__( "Excluded by 'New or existing entries' filter.", 'ai-for-seo' ); } echo '
'; } elseif ( $ai4seo_this_post_is_fully_covered && false === $ai4seo_this_post_is_generated && ! $ai4seo_do_generate_metadata_for_fully_covered_entries ) { echo "
"; echo esc_html__( 'All active metadata fields are filled. SEO Autopilot is leaving existing values unchanged under your overwrite settings.', 'ai-for-seo' ); echo '
'; } if ( $ai4seo_should_show_auto_queue_disallowed_note ) { echo "
"; echo esc_html__( 'Auto Queue will ignore this entry because it was excluded with a bulk action.', 'ai-for-seo' ); echo '
'; } // Title display for mobile version. echo "
"; echo ''; echo ""; echo esc_html( $ai4seo_single_post_title_with_language ); echo ''; if ( isset( $ai4seo_third_party_seo_plugin_key_phrases[ $ai4seo_this_post_id ] ) ) { echo " (" . esc_html( $ai4seo_third_party_seo_plugin_key_phrases[ $ai4seo_this_post_id ] ) . ')'; } echo ''; ai4seo_echo_wp_kses( $ai4seo_this_post_sub_info_html ); echo '
'; } else { echo "
"; echo esc_html__( 'No active meta tags.', 'ai-for-seo' ); echo '
'; } if ( $ai4seo_this_recent_activity_details_subtext_tag ) { ai4seo_echo_wp_kses( $ai4seo_this_recent_activity_details_subtext_tag ); } echo '
'; // Keep plugin and WordPress row actions in one wrapper so the options stay on one line. echo "
"; // Metadata editor. if ( $ai4seo_active_meta_tags ) { ai4seo_echo_wp_kses( ai4seo_get_edit_metadata_button( $ai4seo_this_post_id, $ai4seo_current_post_ids, $ai4seo_post_type_label_singular, null !== $ai4seo_this_active_metadata_coverage_percentage && $ai4seo_metadata_coverage_read_succeeded && $ai4seo_this_active_metadata_coverage_percentage < 100 ) ); } // Keep related-media discovery and native editing available independently of active metadata. ai4seo_echo_wp_kses( ai4seo_get_related_attachments_button( $ai4seo_this_post_id ) ); ai4seo_echo_wp_kses( ai4seo_get_wordpress_post_edit_link_button( $ai4seo_this_post_id ) ); echo '
'; echo '
'; echo '
'; // Pagination. $ai4seo_pagination_base_argument = add_query_arg( array( 'page' => AI4SEO_PLUGIN_IDENTIFIER, 'ai4seo_subpage' => AI4SEO_POST_TYPES_PLUGIN_PAGE_NAME, // e.g. 'post'. 'ai4seo_post_type' => $ai4seo_post_type, 'ai4seo_page' => '%#%', // placeholder for paginate_links(). ), admin_url( 'admin.php' ) ); // Normalize page bounds and preserve WordPress's placeholder when a concrete pagination base cannot be built. $ai4seo_total_pages = max( 1, $ai4seo_total_pages ); $ai4seo_current_page = max( 1, $ai4seo_current_page ); $ai4seo_pagination_base_argument = $ai4seo_pagination_base_argument ? $ai4seo_pagination_base_argument : '%_%'; $ai4seo_pagination_arguments = array( 'base' => $ai4seo_pagination_base_argument, 'total' => $ai4seo_total_pages, 'current' => $ai4seo_current_page, 'show_all' => false, 'end_size' => 2, 'mid_size' => 0, 'prev_text' => '← ' . __( 'Previous', 'ai-for-seo' ), 'next_text' => __( 'Next', 'ai-for-seo' ) . ' →', 'add_args' => ( $ai4seo_filter_query_args ? $ai4seo_filter_query_args : false ), ); $ai4seo_pagination_links = paginate_links( $ai4seo_pagination_arguments ); if ( ! empty( $ai4seo_pagination_links ) ) { $ai4seo_pagination_links = ai4seo_normalize_pagination_links( $ai4seo_pagination_links ); echo "
"; ai4seo_echo_wp_kses( $ai4seo_pagination_links ); echo '
'; }