|WP_Error */ public static function listing( int $limit, int $page, string $search, string $orderby, string $order ) { $available = self::assert_available(); if ( is_wp_error( $available ) ) { return $available; } $result = \RankMath\Monitor\DB::get_logs( array( 'limit' => $limit, 'paged' => max( 1, $page ), 'search' => $search, 'orderby' => $orderby, 'order' => $order, ) ); $rows = isset( $result['logs'] ) && is_array( $result['logs'] ) ? $result['logs'] : array(); $total = isset( $result['count'] ) ? (int) $result['count'] : count( $rows ); $logs = array(); foreach ( $rows as $row ) { if ( ! is_array( $row ) ) { continue; } $logs[] = array( 'id' => isset( $row['id'] ) ? (int) $row['id'] : 0, 'uri' => isset( $row['uri'] ) ? (string) $row['uri'] : '', 'accessed' => isset( $row['accessed'] ) ? (string) $row['accessed'] : '', 'times_accessed' => isset( $row['times_accessed'] ) ? (int) $row['times_accessed'] : 0, 'referer' => isset( $row['referer'] ) ? (string) $row['referer'] : '', 'user_agent' => isset( $row['user_agent'] ) ? (string) $row['user_agent'] : '', 'ip' => isset( $row['ip'] ) ? (string) $row['ip'] : '', ); } return array( 'logs' => $logs, 'count' => count( $logs ), 'total' => $total, 'page' => max( 1, $page ), ); } /** * Total logged 404s. * * @return int */ public static function count(): int { if ( ! class_exists( '\RankMath\Monitor\DB' ) ) { return 0; } return (int) \RankMath\Monitor\DB::get_count(); } /** * Delete specific log entries. * * @param int[] $ids Log ids. * @return array|WP_Error */ public static function delete( array $ids ) { $available = self::assert_available(); if ( is_wp_error( $available ) ) { return $available; } $ids = array_values( array_filter( array_map( 'absint', $ids ) ) ); if ( array() === $ids ) { return new WP_Error( 'invalid_input', __( 'Supply at least one log id.', 'acrossai-abilities-manager' ) ); } $before = self::count(); \RankMath\Monitor\DB::delete_log( $ids ); $after = self::count(); return array( 'ids' => $ids, 'deleted' => max( 0, $before - $after ), 'remaining' => $after, ); } }