�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`�
Warning: session_start(): Session cannot be started after headers have already been sent in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 124

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 131

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 132

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 133

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 134

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 135
0x0x
PHP 8.2.31
Preview: WCEmailTemplateAutoApplier.php Size: 14.29 KB
/home/mciraet/www/wp-content/plugins/woocommerce/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateAutoApplier.php
<?php

declare( strict_types=1 );

namespace Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails;

use Automattic\WooCommerce\EmailEditor\Engine\Logger\Email_Editor_Logger_Interface;
use Automattic\WooCommerce\Internal\EmailEditor\Logger;

/**
 * Auto-applies the current core block template to `woo_email` posts that have
 * been classified `core_updated_uncustomized` by {@see WCEmailTemplateDivergenceDetector}.
 *
 * Mirrors how legacy static-file emails always reflected the latest core
 * template: when the merchant has not customised a generated post since it was
 * last stamped, we silently rewrite its content to the new core render and
 * flip its status meta back to `in_sync`.
 *
 * The per-post atom ({@see self::apply_to_post()}) is shared with the
 * `POST /woocommerce-email-editor/v1/emails/{id}/reset` endpoint
 * (see {@see \Automattic\WooCommerce\Internal\EmailEditor\EmailApiController::reset_response()})
 * so reset and auto-apply share one canonical-write code path.
 *
 * @package Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
 * @since 10.8.0
 */
class WCEmailTemplateAutoApplier {
	/**
	 * Action Scheduler hook name for the batched auto-apply runner.
	 *
	 * Internal AS plumbing — not intended for extension consumption. To react to
	 * the upgrade-time signal, hook {@see 'woocommerce_email_template_divergence_sweep_complete'}
	 * instead.
	 *
	 * @var string
	 */
	public const AUTO_APPLY_AS_HOOK = 'woocommerce_email_template_auto_apply_uncustomized';

	/**
	 * Action Scheduler group for the batched auto-apply runner.
	 *
	 * Internal AS plumbing — not intended for extension consumption. The
	 * `woocommerce-email-editor` namespace is reserved for the standalone email
	 * editor package; integration glue lives under
	 * `woocommerce-email-editor-integration` to keep the boundary explicit.
	 *
	 * @var string
	 */
	public const AUTO_APPLY_AS_GROUP = 'woocommerce-email-editor-integration';

	/**
	 * Re-entrancy flag set while the atom rewrites a post.
	 *
	 * Future `save_post` listeners (e.g. RSM-143's customised-post detector,
	 * RSM-145's Tracks event firing) should consult {@see self::is_auto_applying()}
	 * before interpreting a write as a merchant edit.
	 *
	 * @var bool
	 */
	private static bool $is_auto_applying = false;

	/**
	 * Logger instance. Lazily instantiated on first use; overridable for tests.
	 *
	 * @var Email_Editor_Logger_Interface|null
	 */
	private static ?Email_Editor_Logger_Interface $logger = null;

	/**
	 * Apply the current core template render to a single `woo_email` post and stamp sync meta.
	 *
	 * Two callers, two modes:
	 *   - Auto-applier (default): `$opts['require_uncustomized'] === true`. Rejects with
	 *     `WP_Error` when the post has no stored hash, has been edited since stamping,
	 *     or belongs to a non-sync-enabled email.
	 *   - Reset endpoint: `$opts['require_uncustomized'] === false`. Unconditional rewrite.
	 *     Non-sync-enabled emails receive a content-only reset and the return shape carries
	 *     `null` for the four sync fields (BC contract with the pre-RSM-139 reset endpoint).
	 *
	 * The four meta writes are skipped entirely if `wp_update_post` fails, so a
	 * `WP_Error` return leaves the post and existing meta untouched. Matches the
	 * pre-RSM-139 reset endpoint shape (see PR #64355 review on `2fa660b3b9`).
	 *
	 * @param \WC_Email $email   The transactional email instance.
	 * @param int       $post_id The post ID.
	 * @param array     $opts    Options. Recognised keys:
	 *                           - `require_uncustomized` (bool, default true): see above.
	 * @return array|\WP_Error On success, an array with keys `content`, `version`,
	 *                         `source_hash`, `synced_at`, `status`. On failure, a `WP_Error`.
	 *
	 * @since 10.8.0
	 */
	public static function apply_to_post( \WC_Email $email, int $post_id, array $opts = array() ) {
		$require_uncustomized = ! isset( $opts['require_uncustomized'] ) || (bool) $opts['require_uncustomized'];

		$sync_config = WCEmailTemplateSyncRegistry::get_email_sync_config( (string) $email->id );

		if ( $require_uncustomized && null === $sync_config ) {
			return new \WP_Error(
				'not_sync_enabled',
				sprintf(
					/* translators: %s: email ID */
					__( 'Email "%s" is not registered for template sync.', 'woocommerce' ),
					(string) $email->id
				)
			);
		}

		$post = get_post( $post_id );
		if ( ! $post instanceof \WP_Post || \Automattic\WooCommerce\Internal\EmailEditor\Integration::EMAIL_POST_TYPE !== $post->post_type ) {
			return new \WP_Error(
				'post_not_found',
				sprintf(
					/* translators: %d: post ID */
					__( 'No woo_email post found for ID %d.', 'woocommerce' ),
					$post_id
				)
			);
		}

		$stored_source_hash = '';
		if ( $require_uncustomized ) {
			$stored_source_hash = (string) get_post_meta( $post_id, WCEmailTemplateDivergenceDetector::SOURCE_HASH_META_KEY, true );
			if ( '' === $stored_source_hash || ! self::is_sha1_hash( $stored_source_hash ) ) {
				return new \WP_Error(
					'no_stored_hash',
					sprintf(
						/* translators: %d: post ID */
						__( 'Post %d has no stored source hash; cannot safely auto-apply.', 'woocommerce' ),
						$post_id
					)
				);
			}
		}//end if

		$canonical   = WCTransactionalEmailPostsGenerator::compute_canonical_post_content( $email );
		$source_hash = null;
		$synced_at   = null;
		$status      = null;
		$version     = null;

		self::$is_auto_applying = true;
		try {
			// Re-hash post_content immediately before the write to minimise the
			// TOCTOU gap between the snapshot and wp_update_post. The first $post
			// load above is too early — `compute_canonical_post_content` runs in
			// between and yields the window where a merchant save could otherwise
			// be silently overwritten.
			if ( $require_uncustomized ) {
				$latest_post = get_post( $post_id );
				if ( ! $latest_post instanceof \WP_Post
					|| sha1( (string) $latest_post->post_content ) !== $stored_source_hash
				) {
					return new \WP_Error(
						'post_modified_since_stamp',
						sprintf(
							/* translators: %d: post ID */
							__( 'Post %d has been modified since the last sync stamp; skipping auto-apply.', 'woocommerce' ),
							$post_id
						)
					);
				}
			}

			$updated = wp_update_post(
				array(
					'ID'           => $post_id,
					'post_content' => $canonical,
				),
				true
			);

			if ( is_wp_error( $updated ) ) {
				return $updated;
			}

			// Read back the persisted post_content. The `content_save_pre` filter
			// chain can mutate `$canonical` between the in-memory string and what
			// lands in the DB, so both the returned `content` field and the
			// stamped source hash must reflect what the database actually holds.
			// See the same note in `WCEmailTemplateSelectiveApplier::apply_selectively()`.
			$saved_post = get_post( $post_id );
			$saved_body = $saved_post instanceof \WP_Post ? (string) $saved_post->post_content : $canonical;
			$canonical  = $saved_body;

			if ( null !== $sync_config ) {
				$source_hash = sha1( $canonical );
				$synced_at   = gmdate( 'Y-m-d H:i:s' );
				$version     = (string) $sync_config['version'];

				update_post_meta( $post_id, WCEmailTemplateDivergenceDetector::VERSION_META_KEY, $version );
				update_post_meta( $post_id, WCEmailTemplateDivergenceDetector::SOURCE_HASH_META_KEY, $source_hash );
				update_post_meta( $post_id, WCEmailTemplateDivergenceDetector::LAST_SYNCED_AT_META_KEY, $synced_at );
				update_post_meta( $post_id, WCEmailTemplateDivergenceDetector::LAST_CORE_RENDER_META_KEY, $canonical );

				// Status comes from the classifier so all writers stay consistent.
				// In this path we always write canonical, so the classifier returns
				// IN_SYNC, but going through the same helper as the selective applier
				// avoids drift if a future partial-apply path is added here.
				$status = WCEmailTemplateDivergenceDetector::reclassify( $post_id );
			}//end if
		} finally {
			self::$is_auto_applying = false;
		}//end try

		// Fire `_update_applied` for the auto-applier path. Static extensions:
		// the auto-applier only acts on `core_updated_uncustomized` posts, so
		// `had_customizations` is always false and `auto_resolved` is always true.
		// Gate on `$require_uncustomized`: this method is also reused by the
		// reset endpoint (with `require_uncustomized = false`) — the reset
		// surface is not in RSM-145's event taxonomy and must not be tagged
		// as `applied_from='auto'`.
		if ( $require_uncustomized ) {
			WCEmailTemplateSyncTracker::record_auto_applied( $post_id );
		}

		return array(
			'content'     => $canonical,
			'version'     => $version,
			'source_hash' => $source_hash,
			'synced_at'   => $synced_at,
			'status'      => $status,
		);
	}

	/**
	 * Enqueue the batched auto-apply runner as an Action Scheduler async action.
	 *
	 * Hooked to {@see 'woocommerce_email_template_divergence_sweep_complete'}. The
	 * `as_has_scheduled_action()` short-circuit guards against double-enqueueing
	 * when the detector sweep runs twice in one request — once on
	 * `woocommerce_updated`, once on `BACKFILL_COMPLETE_ACTION`.
	 *
	 * @since 10.8.0
	 */
	public static function schedule(): void {
		if ( as_has_scheduled_action( self::AUTO_APPLY_AS_HOOK, array(), self::AUTO_APPLY_AS_GROUP ) ) {
			return;
		}

		as_enqueue_async_action( self::AUTO_APPLY_AS_HOOK, array(), self::AUTO_APPLY_AS_GROUP );
	}

	/**
	 * Action Scheduler callback. Apply the canonical core render to every
	 * `woo_email` post whose status meta is `core_updated_uncustomized`.
	 *
	 * Per-post `try`/`catch` ensures one bad post never breaks the rest of the
	 * batch (acceptance criterion). Status meta is never mutated by this method
	 * on failure — the next sweep re-classifies.
	 *
	 * Declared `void` because Action Scheduler async-action callbacks discard
	 * the return value; a return type would just be noise (and trip PHPStan's
	 * `return.void` rule on `add_action`).
	 *
	 * @since 10.8.0
	 */
	public static function run(): void {
		if ( 'yes' !== get_option( WCEmailTemplateDivergenceDetector::BACKFILL_COMPLETE_OPTION ) ) {
			return;
		}

		// `post_status=any` includes draft / private / pending / future and
		// excludes trash / auto-draft / inherit — anything not in the trash bucket
		// is fair game for auto-apply.
		$candidate_ids = get_posts(
			array(
				'post_type'      => \Automattic\WooCommerce\Internal\EmailEditor\Integration::EMAIL_POST_TYPE,
				'post_status'    => 'any',
				'posts_per_page' => -1,
				'fields'         => 'ids',
				'no_found_rows'  => true,
				'meta_query'     => array(  // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- bounded set; sync-registered emails only.
					array(
						'key'   => WCEmailTemplateDivergenceDetector::STATUS_META_KEY,
						'value' => WCEmailTemplateDivergenceDetector::STATUS_CORE_UPDATED_UNCUSTOMIZED,
					),
				),
			)
		);

		if ( empty( $candidate_ids ) ) {
			return;
		}

		$registry      = WCEmailTemplateSyncRegistry::get_sync_enabled_emails();
		$posts_manager = WCTransactionalEmailPostsManager::get_instance();
		$emails_by_id  = $posts_manager->get_emails_by_id();

		foreach ( $candidate_ids as $post_id ) {
			$post_id = (int) $post_id;
			try {
				$email_id = (string) $posts_manager->get_email_type_from_post_id( $post_id );
				if ( '' === $email_id || ! isset( $registry[ $email_id ] ) ) {
					continue;
				}

				$email = $emails_by_id[ $email_id ] ?? null;
				if ( ! $email instanceof \WC_Email ) {
					continue;
				}

				$result = self::apply_to_post( $email, $post_id );

				if ( is_wp_error( $result ) ) {
					self::log_apply_error( $result, $post_id, $email_id );
				}
			} catch ( \Throwable $e ) {
				self::get_logger()->error(
					sprintf(
						'Email template auto-apply failed for post %d: %s',
						$post_id,
						$e->getMessage()
					),
					array(
						'post_id' => $post_id,
						'context' => 'email_template_auto_applier',
					)
				);
				continue;
			}//end try
		}//end foreach
	}

	/**
	 * Map a per-post `WP_Error` from {@see self::apply_to_post()} to the right
	 * log severity and emit it.
	 *
	 * `post_modified_since_stamp` is the expected race outcome (merchant edit in
	 * the AS lag window) and is logged at `info`. Everything else is at `warning`
	 * or `error` so it surfaces in the default WC log UI.
	 *
	 * @param \WP_Error $error    The error returned by apply_to_post.
	 * @param int       $post_id  Post ID being processed.
	 * @param string    $email_id Email ID being processed.
	 */
	private static function log_apply_error( \WP_Error $error, int $post_id, string $email_id ): void {
		$message = sprintf(
			'Email template auto-apply skipped post %d for email "%s": %s',
			$post_id,
			$email_id,
			$error->get_error_message()
		);

		$context = array(
			'post_id'  => $post_id,
			'email_id' => $email_id,
			'context'  => 'email_template_auto_applier',
		);

		switch ( $error->get_error_code() ) {
			case 'post_modified_since_stamp':
				self::get_logger()->info( $message, $context );
				return;
			case 'no_stored_hash':
			case 'not_sync_enabled':
				self::get_logger()->warning( $message, $context );
				return;
			default:
				self::get_logger()->error( $message, $context );
		}
	}

	/**
	 * Whether the auto-applier is currently rewriting a post.
	 *
	 * Future `save_post` listeners (RSM-143, RSM-145) should consult this flag
	 * to differentiate merchant edits from system-initiated writes.
	 *
	 * @return bool
	 *
	 * @since 10.8.0
	 */
	public static function is_auto_applying(): bool {
		return self::$is_auto_applying;
	}

	/**
	 * Override the logger implementation. Intended for tests only.
	 *
	 * @internal
	 *
	 * @param Email_Editor_Logger_Interface|null $logger The logger implementation, or null to restore the default.
	 */
	public static function set_logger( ?Email_Editor_Logger_Interface $logger ): void {
		self::$logger = $logger;
	}

	/**
	 * Return the logger instance, lazily creating it the first time.
	 *
	 * @return Email_Editor_Logger_Interface
	 */
	private static function get_logger(): Email_Editor_Logger_Interface {
		if ( null === self::$logger ) {
			self::$logger = new Logger( wc_get_logger() );
		}

		return self::$logger;
	}

	/**
	 * Validate that a string is shaped like a SHA-1 hex digest.
	 *
	 * @param string $hash Candidate hash value.
	 * @return bool True when the value is a 40-character hex string.
	 */
	private static function is_sha1_hash( string $hash ): bool {
		return 40 === strlen( $hash ) && ctype_xdigit( $hash );
	}
}

Directory Contents

Dirs: 0 × Files: 10
Name Size Perms Modified Actions
14.29 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
44.46 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
21.83 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
33.57 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
15.82 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
8.70 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
13.87 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
14.40 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
11.29 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
3.01 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI