*/ public function get( int $id ): array { $state = get_post_meta( $id, self::META_STATE, true ); return is_array( $state ) ? $state : array(); } /** * Stores the state and keeps the filterable status key in sync. * * @param int $id Attachment ID. * @param array $state State to store. * @return void */ public function save( int $id, array $state ): void { update_post_meta( $id, self::META_STATE, $state ); if ( isset( $state['status'] ) && is_string( $state['status'] ) ) { $this->set_status( $id, $state['status'] ); } } /** * Returns the status, or an empty string for an image never processed. * * @param int $id Attachment ID. * @return string */ public function status( int $id ): string { return (string) get_post_meta( $id, self::META_STATUS, true ); } /** * Sets the status. * * @param int $id Attachment ID. * @param string $status New status. * @return void */ public function set_status( int $id, string $status ): void { update_post_meta( $id, self::META_STATUS, $status ); } /** * Drops cached meta, so a long-running worker sees what other processes wrote. * * @param int $id Attachment ID. * @return void */ public function refresh( int $id ): void { wp_cache_delete( $id, 'post_meta' ); } }