1, 'first' => $now, 'last' => $now ); } if ( count( $all ) > self::MAX ) { uasort( $all, static function ( $a, $b ) { return (int) $a['last'] <=> (int) $b['last']; } ); $all = array_slice( $all, count( $all ) - self::MAX, null, true ); } update_option( self::OPTION, $all, false ); } public static function clear( $page_id ) { $id = sanitize_key( (string) $page_id ); $all = self::rows(); if ( ! isset( $all[ $id ] ) ) { return; } unset( $all[ $id ] ); if ( empty( $all ) ) { delete_option( self::OPTION ); } else { update_option( self::OPTION, $all, false ); } } public static function observe( $page_id, array $envelope, array $request ) { if ( isset( $envelope['error'] ) ) { return; } $filtered = ( (int) ( $request['page'] ?? 1 ) > 1 ) || '' !== trim( (string) ( $request['search'] ?? '' ) ); if ( $filtered ) { return; } $rows = isset( $envelope['rows_assoc'] ) ? (array) $envelope['rows_assoc'] : ( isset( $envelope['rows'] ) ? (array) $envelope['rows'] : array() ); $total = isset( $envelope['total'] ) ? (int) $envelope['total'] : count( $rows ); if ( 0 === $total && empty( $rows ) ) { self::log( $page_id ); } else { self::clear( $page_id ); } } }