prefix . 'astr_posts_history'; $per_page = 10; $paged = astr_safe_get( 'paged', 'int', 1, 'manage_options', false ); $offset = ( $paged - 1 ) * $per_page; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $search = astr_safe_get( 's', 'text', '', 'manage_options', false ); $status = astr_safe_get( 'post_status', 'text', '', 'manage_options', false ); $month = 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 = ( strtolower( $order_raw ) === 'asc' ) ? 'ASC' : 'DESC'; $allowed_orderby = [ 'title' => 'post_title', 'status' => 'status', 'post_type' => 'post_type', '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_filter', 'key', '' ), 'month' => $month, 'cat' => $cat, 'status' => $status, 'search' => $search, ]; list( $where, $args ) = astr_build_where_clause( $wpdb, $table, $filters ); // --- Prepare final SQL --- $rows = astr_get_latest_rows($wpdb, $table, $where, $args, $orderby_sql, $order, $per_page, $offset); // --- 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 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count_published_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') AND t.status LIKE 'Published%'"; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $count_published = (int) $wpdb->get_var( $count_published_sql ); $page = astr_safe_get( 'page', 'key', 'astr-posts-history', 'manage_options', false ); $total_pages = max( 1, ceil( $count_all / $per_page ) ); // --- Begin Output --- echo '
| Revisions | '; echo '|||||
|---|---|---|---|---|---|
| ' . esc_html( $row->post_title ) . ' | '; $status_label = astr_get_status_label( $row->status ); echo '' . esc_html( $status_label ) . ' | '; $post_type_label = $row->post_type; $post_type_obj = get_post_type_object( $row->post_type ); if ( $post_type_obj && ! empty( $post_type_obj->labels->singular_name ) ) { $post_type_label = $post_type_obj->labels->singular_name; } echo '' . esc_html( $post_type_label ) . ' | '; echo '' . esc_html( mysql2date( 'd-m-Y H:i:s', $row->time ) ) . ' | '; echo '' . esc_html( $row->user_name ) . ' | '; echo '' . wp_kses_post( $button ) . ' | '; echo '
| No post history found. | |||||