prefix . 'redirection_items'; } public function counts(): array { global $wpdb; $counts = array( 'posts' => 0, 'terms' => 0, 'redirects' => 0, 'settings' => false ); if ( ! $this->table_exists( $this->table() ) ) { return $counts; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $counts['redirects'] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM %i WHERE status = 'enabled'", $this->table() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- table name from this plugin's own Database class/adapter, never from input; values go through $wpdb->prepare(). return $counts; } public function post_record( int $post_id ): array { return array(); } public function redirects( int $after, int $limit ): array { global $wpdb; if ( ! $this->table_exists( $this->table() ) ) { return array(); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $rows = $wpdb->get_results( $wpdb->prepare( "SELECT id, url, action_data, action_code, match_type FROM %i WHERE status = 'enabled' AND id > %d ORDER BY id ASC LIMIT %d", $this->table(), $after, max( 1, $limit ) ) ); $out = array(); foreach ( (array) $rows as $row ) { $target = (string) $row->action_data; // Newer versions store the target as JSON ({"url":"/x"}). if ( str_starts_with( trim( $target ), '{' ) ) { $decoded = json_decode( $target, true ); $target = is_array( $decoded ) ? (string) ( $decoded['url'] ?? '' ) : ''; } $out[] = array( 'id' => (int) $row->id, 'source' => (string) $row->url, 'target' => $target, 'type' => (int) $row->action_code > 0 ? (int) $row->action_code : 301, ); } return $out; } }