prefix . 'astr_pages_history'; $per_page = 10; $paged = astr_safe_get( 'paged', 'int', 1, 'manage_options', false ); $offset = ( $paged - 1 ) * $per_page; $search = astr_safe_get( 's', 'text', '', 'manage_options', false ); $status = astr_safe_get( 'status', 'text', '', 'manage_options', false ); $m = astr_safe_get( 'm', 'text', '', 'manage_options', false ); $cat = astr_safe_get( 'cat', 'int', 0, 'manage_options', false ); $orderby = astr_safe_get( 'orderby', 'key', 'date', 'manage_options', false ); $order_raw = astr_safe_get( 'order', 'key', 'desc', 'manage_options', false ); $order = ( $order_raw === 'asc' ) ? 'ASC' : 'DESC'; $allowed_orderby = [ 'title' => 'post_title', 'status' => 'status', 'date' => 'time', 'author' => 'user_name', ]; if ( ! isset( $allowed_orderby[ $orderby ] ) ) { $orderby = 'date'; } $orderby_sql = $allowed_orderby[ $orderby ]; // --- WHERE conditions --- $filters = [ 'post_type' => astr_safe_get( 'post_type', 'key', 'page' ), 'month' => $m, 'cat' => $cat, 'status' => $status, 'search' => $search, ]; list( $where, $args ) = astr_build_where_clause( $wpdb, $table, $filters ); // --- Counts --- $rev_where = $where . " AND EXISTS (SELECT 1 FROM {$wpdb->posts} p WHERE p.post_parent = t.post_id AND p.post_type = 'revision')"; $total = astr_get_total_count( $wpdb, $table, $where, $args ); // --- Counts --- // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $total = astr_get_total_count( $wpdb, $table, $where, $args ); $count_all_sql = " SELECT COUNT(*) FROM (SELECT post_id, MAX(time) as max_time FROM $table GROUP BY post_id) latest INNER JOIN $table t ON t.post_id = latest.post_id AND t.time = latest.max_time WHERE EXISTS (SELECT 1 FROM {$wpdb->posts} p WHERE p.post_parent = t.post_id AND p.post_type = 'revision')"; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter $count_all = (int) $wpdb->get_var( $count_all_sql ); // === COUNT PUBLISHED === $sql_count_published_base = " SELECT COUNT(*) FROM ( SELECT post_id, MAX(time) as max_time FROM {$table} GROUP BY post_id ) latest INNER JOIN {$table} t ON t.post_id = latest.post_id AND t.time = latest.max_time {$rev_where} AND t.status LIKE %s"; $params = ! empty( $args ) ? array_merge( $args, [ 'Published%' ] ) : [ 'Published%' ]; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $sql_count_published = $wpdb->prepare( $sql_count_published_base, ...$params ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $count_published = (int) $wpdb->get_var( $sql_count_published ); // --- Get rows --- $rows = astr_get_latest_rows( $wpdb, $table, $where, $args, $orderby_sql, $order, $per_page, $offset ); $total_pages = max( 1, ceil( $total / $per_page ) ); // --- Begin Output --- echo '
'; echo '

Pages History

'; echo '
'; $base_url = esc_url( admin_url( 'admin.php?page=astr-pages-history' ) ); $page = astr_safe_get( 'page', 'key', 'astr-pages-history', 'manage_options', false ); // === FILTERS: All | Published + Search === echo '
'; // LEFT: All | Published echo '
'; echo ''; // RIGHT: Search echo '
'; echo '
'; wp_nonce_field( 'astr_filter_action', '_astr_nonce' ); echo ''; if ( ! empty( $m ) ) { echo ''; } if ( $cat > 0 ) { echo ''; } if ( ! empty( $status ) ) { echo ''; } if ( ! empty( $orderby ) ) { echo ''; } if ( ! empty( $order ) ) { echo ''; } echo ''; echo '
'; echo '
'; echo '
'; echo '
'; // === Top table nav === echo '
'; echo '
'; echo '
'; wp_nonce_field( 'astr_filter_action', '_astr_nonce' ); echo '
'; echo ''; if ( ! empty( $search ) ) { echo ''; } if ( ! empty( $order ) ) { echo ''; } if ( ! empty( $order ) ) { echo ''; } echo ' '; // select status echo ''; submit_button( 'Filter', '', '', false ); echo '
'; echo '
'; // === Pagination Top (identical to bottom) === echo '
'; if ( $total >= $per_page ) { astr_pagination( $total, $total_pages, $paged ); } /*if ( false ) { astr_pagination( $total, $total_pages, $paged ); }*/ /*echo '
';*/ echo '
'; echo '
'; // === Table === echo ''; echo ''; echo wp_kses_post( astr_sortable_th( 'Title', 'title', $orderby, $order ) ); echo wp_kses_post( astr_sortable_th( 'Status', 'status', $orderby, $order ) ); echo wp_kses_post( astr_sortable_th( 'Date', 'date', $orderby, $order ) ); echo wp_kses_post( astr_sortable_th( 'Author', 'author', $orderby, $order ) ); echo ''; echo ''; if ( ! empty( $rows ) ) { foreach ( $rows as $row ) { $button = astr_get_revision_or_restore_button( $row->post_id, $wpdb ); if ( empty( $button ) ) { continue; } echo ''; echo ''; $status_label = astr_get_status_label( $row->status ); echo ''; echo ''; echo ''; echo ''; echo ''; } } else { echo ''; } echo '
Revisions
' . esc_html( $row->post_title ) . '' . esc_html( $status_label ) . '' . esc_html( mysql2date( 'd-m-Y H:i:s', $row->time ) ) . '' . esc_html( $row->user_name ) . '' . wp_kses_post( $button ) . '
No page history found.
'; // === Bottom pagination === echo '
'; if ( $total >= $per_page ) { astr_pagination( $total, $total_pages, $paged ); } echo '
'; echo '
'; }