self::MAX_DIMENSION ) ); return $cached_url ?: $url; } /** * Maybe clean up cached avatar when actor is deleted. * * @param int $post_id The post ID being deleted. */ public static function maybe_cleanup( $post_id ) { if ( Remote_Actors::POST_TYPE !== \get_post_type( $post_id ) ) { return; } self::invalidate_entity( $post_id ); } /** * Save an avatar for an actor. * * This is a convenience method that wraps get_or_cache with the correct options. * It also invalidates any existing avatar before caching the new one. * * @param int $actor_id The actor post ID. * @param string $avatar_url The remote avatar URL. * * @return string|false The local avatar URL on success, false on failure. */ public static function save( $actor_id, $avatar_url ) { // Validate actor_id is a positive integer. $actor_id = (int) $actor_id; if ( $actor_id <= 0 ) { return false; } if ( empty( $avatar_url ) || ! \filter_var( $avatar_url, FILTER_VALIDATE_URL ) ) { return false; } // Delete existing avatar files before saving new one. self::invalidate_entity( $actor_id ); return self::cache( $avatar_url, $actor_id, array( 'max_dimension' => self::MAX_DIMENSION ) ); } }