translated words. */ public static function labels(): array { return array( 'started' => __( 'Optimization started', 'affstackdev-image-manager' ), 'scan_started' => __( 'Discovery started', 'affstackdev-image-manager' ), 'paused' => __( 'Processing paused', 'affstackdev-image-manager' ), 'resumed' => __( 'Processing resumed', 'affstackdev-image-manager' ), 'cancelled' => __( 'Run stopped; originals and prepared copies retained', 'affstackdev-image-manager' ), 'completed' => __( 'Run completed', 'affstackdev-image-manager' ), 'retry' => __( 'Temporary problem; retry scheduled', 'affstackdev-image-manager' ), 'failed' => __( 'Retry limit reached; image needs attention', 'affstackdev-image-manager' ), 'recovered' => __( 'Interrupted work recovered', 'affstackdev-image-manager' ), 'probe_started' => __( 'Background check scheduled', 'affstackdev-image-manager' ), 'probe_passed' => __( 'Background check executed', 'affstackdev-image-manager' ), 'schedule_failed' => __( 'Background task could not be scheduled', 'affstackdev-image-manager' ), 'worker_paused' => __( 'Processing paused for a system problem', 'affstackdev-image-manager' ), 'upgraded' => __( 'Existing settings and image records preserved during upgrade', 'affstackdev-image-manager' ), 'cdn_on' => __( 'CDN checked and switched on', 'affstackdev-image-manager' ), 'cdn_off' => __( 'CDN switched off', 'affstackdev-image-manager' ), 'cdn_stopped' => __( 'The daily CDN check failed; pictures come from the site again', 'affstackdev-image-manager' ), ); } // The codes of labels(). add() checks against these untranslated: it also runs before init (upgrades on plugins_loaded). private const CODES = array( 'started', 'scan_started', 'paused', 'resumed', 'cancelled', 'completed', 'retry', 'failed', 'recovered', 'probe_started', 'probe_passed', 'schedule_failed', 'worker_paused', 'upgraded', 'cdn_on', 'cdn_off', 'cdn_stopped' ); /** * Record one event in the history (the newest 40 are kept); skipped when the history is busy, so it never holds up * image work. * * @param string $code The event code (one of CODES). * @param int $source The source row it is about, or 0. */ public static function add( string $code, int $source = 0 ): void { if ( ! in_array( $code, self::CODES, true ) ) { return; } $token = Repository::acquire( 'activity' ); if ( ! $token ) { return; } // History must not interfere with image publication. try { $rows = (array) Settings::fresh_option( self::OPTION, array() ); $rows[] = array( 'time' => time(), 'code' => $code, 'source' => max( 0, $source ), ); Reviewed_Store::update_option( self::OPTION, array_slice( $rows, -40 ), false ); } finally { Repository::release( $token, 'activity' ); } } /** * The newest 40 events, newest first. * * @return array Events with time, code and source. */ public static function recent(): array { return array_reverse( array_slice( (array) get_option( self::OPTION, array() ), -40 ) ); } }