'keyword', 'plural' => 'keywords', 'ajax' => false, ) ); } /** * @since 1.0.0 * * @return array */ public function get_columns(): array { return array( 'post_id' => __( 'Post', 'postlinkly' ), 'phrase' => __( 'Keyword', 'postlinkly' ), 'source' => __( 'Source', 'postlinkly' ), ); } /** * @since 1.0.0 * * @return void */ public function prepare_items(): void { global $wpdb; $per_page = 25; $current_page = $this->get_pagenum(); $offset = ( $current_page - 1 ) * $per_page; $table = TableNames::target_keywords(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $total = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $this->items = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i ORDER BY post_id ASC, source ASC LIMIT %d OFFSET %d', $table, $per_page, $offset ) ); $this->set_pagination_args( array( 'total_items' => $total, 'per_page' => $per_page, 'total_pages' => (int) ceil( $total / $per_page ), ) ); $this->_column_headers = array( $this->get_columns(), array(), array() ); } /** * @since 1.0.0 * * @param object $item Row data. * @param string $column_name Column key. * * @return string */ public function column_default( $item, $column_name ): string { switch ( $column_name ) { case 'post_id': $title = get_the_title( (int) $item->post_id ); return '' . esc_html( '' !== $title ? $title : (string) $item->post_id ) . ''; case 'phrase': return '' . esc_html( (string) $item->phrase ) . ''; case 'source': return esc_html( (string) $item->source ); default: return ''; } } }