*/ public static function all(): array { $stored = get_option( self::OPTION, array() ); $out = array(); foreach ( is_array( $stored ) ? $stored : array() as $entry ) { if ( ! is_array( $entry ) || ! isset( $entry['name'], $entry['action'] ) || ! is_string( $entry['name'] ) || ! in_array( $entry['action'], self::ACTIONS, true ) ) { continue; } $out[] = array( 'name' => $entry['name'], 'action' => $entry['action'], 'from' => isset( $entry['from'] ) && is_string( $entry['from'] ) ? $entry['from'] : '', 'size' => isset( $entry['size'] ) && is_numeric( $entry['size'] ) ? (int) $entry['size'] : 0, 'owner' => isset( $entry['owner'] ) && is_string( $entry['owner'] ) ? $entry['owner'] : '', 'user' => isset( $entry['user'] ) && is_numeric( $entry['user'] ) ? (int) $entry['user'] : 0, 'time' => isset( $entry['time'] ) && is_numeric( $entry['time'] ) ? (int) $entry['time'] : 0, ); } return array_slice( $out, 0, self::MAX ); } /** * Add an entry (keeps the newest MAX). * * @since 1.0.0 * @param string $name Option name. * @param string $action `off`, `on` or `deleted`. * @param string $from Autoload flag before the change. * @param int $size Value size in bytes. * @param string $owner Owner name shown at the time. * @return void */ public static function add( string $name, string $action, string $from, int $size, string $owner ) { $list = self::all(); array_unshift( $list, array( 'name' => $name, 'action' => in_array( $action, self::ACTIONS, true ) ? $action : 'off', 'from' => $from, 'size' => $size, 'owner' => $owner, 'user' => get_current_user_id(), 'time' => time(), ) ); $list = array_slice( $list, 0, self::MAX ); if ( false === get_option( self::OPTION ) ) { add_option( self::OPTION, $list, '', false ); } else { update_option( self::OPTION, $list, false ); } } /** * The newest entry for an option, or null. * * @since 1.0.0 * @param string $name Option name (case ignored). * @return array|null */ public static function latest( string $name ) { foreach ( self::all() as $entry ) { if ( 0 === strcasecmp( $entry['name'], $name ) ) { return $entry; } } return null; } /** * Whether the analyzer switched this option's autoload off (its newest entry), so "Autoload * again" may switch it back on. * * @since 1.0.0 * @param string $name Option name. * @return bool */ public static function switched_off_here( string $name ): bool { $latest = self::latest( $name ); return is_array( $latest ) && 'off' === $latest['action']; } }