(string) $type, 'target' => (string) $target, 'time' => current_time( 'mysql', true ), ); // Trim to the most recent MAX_ENTRIES. if ( count( $entries ) > self::MAX_ENTRIES ) { $entries = array_slice( $entries, -self::MAX_ENTRIES ); } update_option( self::OPTION_KEY, $entries, false ); } /** * Return change entries within the last $seconds before $before. * * @param string $before MySQL UTC datetime anchor. * @param int $seconds Lookback window in seconds. * @return array */ public static function changes_before( $before, $seconds = 600 ) { $entries = get_option( self::OPTION_KEY, array() ); if ( ! is_array( $entries ) ) { return array(); } $anchor = strtotime( $before . ' UTC' ); if ( false === $anchor ) { return array(); } $out = array(); foreach ( $entries as $entry ) { if ( empty( $entry['time'] ) ) { continue; } $ts = strtotime( $entry['time'] . ' UTC' ); if ( false === $ts ) { continue; } if ( $ts <= $anchor && $ts >= ( $anchor - $seconds ) ) { $out[] = $entry; } } return $out; } /** * Plugin activated. * * @param string $plugin Plugin basename. */ public static function on_plugin_activated( $plugin ) { self::record( 'plugin_activated', $plugin ); } /** * Plugin deactivated. * * @param string $plugin Plugin basename. */ public static function on_plugin_deactivated( $plugin ) { self::record( 'plugin_deactivated', $plugin ); } /** * Theme switched. * * @param string $new_name New theme name. */ public static function on_theme_switched( $new_name ) { self::record( 'theme_switched', $new_name ); } /** * An update completed (plugin/theme/core). * * @param object $upgrader Upgrader instance (unused). * @param array $data Upgrade data. */ public static function on_upgrade( $upgrader, $data ) { unset( $upgrader ); if ( ! is_array( $data ) ) { return; } $type = isset( $data['type'] ) ? $data['type'] : 'unknown'; self::record( 'updated_' . $type, isset( $data['action'] ) ? $data['action'] : 'update' ); } }