�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: Options.php Size: 18.97 KB
/home/m/c/i/mciraet/www/wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/src/Options/Options.php
<?php
/**
 * @package Polylang
 */

namespace WP_Syntex\Polylang\Options;

use WP_Error;
use ArrayAccess;
use ArrayIterator;
use IteratorAggregate;
use WP_Syntex\Polylang\Options\Abstract_Option;
use WP_Syntex\Polylang\Options\Primitive\Abstract_Map;
use WP_Syntex\Polylang\Options\Primitive\Abstract_List;

defined( 'ABSPATH' ) || exit;

/**
 * Class that manages Polylang's options:
 * - Automatically stores the options into the database on `shutdown` if they have been modified.
 * - Behaves almost like an array, meaning only values can be get/set (implements `ArrayAccess`).
 * - Handles `switch_to_blog()`.
 * - Options are always defined: it is not possible to unset them from the list, they are set to their default value instead.
 * - If an option is not registered but exists in database, its raw value will be kept and remain untouched.
 *
 * @since 3.7
 *
 * @implements ArrayAccess<non-falsy-string, mixed>
 * @implements IteratorAggregate<non-empty-string, mixed>
 *
 * @phpstan-import-type Schema from Abstract_Option as OptionSchema
 * @phpstan-type Schema array{
 *     '$schema': non-falsy-string,
 *     title: non-falsy-string,
 *     description: string,
 *     type: 'object',
 *     properties: array<non-falsy-string, OptionSchema>,
 *     additionalProperties: false
 * }
 */
class Options implements ArrayAccess, IteratorAggregate {
	public const OPTION_NAME = 'polylang';

	/**
	 * Polylang's options, by blog ID.
	 * Raw value if option is not registered yet, `Abstract_Option` instance otherwise.
	 *
	 * @var Abstract_Option[][]|mixed[][]
	 * @phpstan-var array<int, array<non-falsy-string, mixed>>
	 */
	private $options = array();

	/**
	 * Tells if the options have been modified, by blog ID.
	 *
	 * @var bool[]
	 * @phpstan-var array<int, true>
	 */
	private $modified = array();

	/**
	 * The original blog ID.
	 *
	 * @var int
	 */
	private $blog_id;

	/**
	 * The current blog ID.
	 *
	 * @var int
	 */
	private $current_blog_id;

	/**
	 * Map of memoized values of blog IDs to tell if Polylang is active.
	 *
	 * @var bool[]
	 * @phpstan-var array<int, bool>
	 */
	private $is_plugin_active = array();

	/**
	 * Cached options JSON schema by blog ID.
	 *
	 * @var array[]|null
	 * @phpstan-var array<int, Schema>|null
	 */
	private $schema;

	/**
	 * Constructor.
	 *
	 * @since 3.7
	 */
	public function __construct() {
		// Keep track of the blog ID.
		$this->blog_id          = (int) get_current_blog_id();
		$this->current_blog_id  = $this->blog_id;
		$this->is_plugin_active = array( $this->blog_id => true );

		// Handle options.
		$this->init_options_for_current_blog();

		add_filter( 'pre_update_option_polylang', array( $this, 'protect_wp_option_storage' ), 1 );
		add_action( 'switch_blog', array( $this, 'on_blog_switch' ), -1000 ); // Options must be ready early.
		add_action( 'shutdown', array( $this, 'save_all' ), 1000 ); // Make sure to save options after everything.
	}

	/**
	 * Registers an option.
	 * Options must be registered in the right order: some options depend on other options' value.
	 *
	 * @since 3.7
	 *
	 * @param string $class_name  Option class to register.
	 * @return self
	 *
	 * @phpstan-param class-string<Abstract_Option> $class_name
	 */
	public function register( string $class_name ): self {
		$key = $class_name::key();

		if ( ! array_key_exists( $key, $this->options[ $this->current_blog_id ] ) ) {
			// Option raw value doesn't exist in database, use default instead.
			$this->options[ $this->current_blog_id ][ $key ] = $this->maybe_make_option_inactive(
				new $class_name()
			);
			return $this;
		}

		// If option exists in database, use this value.
		if ( $this->options[ $this->current_blog_id ][ $key ] instanceof Abstract_Option ) {
			// Already registered, do nothing.
			$this->options[ $this->current_blog_id ][ $key ] = $this->maybe_make_option_inactive(
				$this->options[ $this->current_blog_id ][ $key ]
			);
			return $this;
		}

		// Option raw value exists in database, use it.
		$this->options[ $this->current_blog_id ][ $key ] = $this->maybe_make_option_inactive(
			new $class_name( $this->options[ $this->current_blog_id ][ $key ] )
		);

		return $this;
	}

	/**
	 * Prevents storing an instance of `Options` into the database.
	 *
	 * @since 3.7
	 *
	 * @param array|Options $value The options to store.
	 * @return array
	 */
	public function protect_wp_option_storage( $value ) {
		if ( $value instanceof self ) {
			return $value->get_all();
		}
		return $value;
	}

	/**
	 * Initializes options for the newly switched blog if applicable.
	 *
	 * @since 3.7
	 *
	 * @param int $blog_id The blog ID.
	 * @return void
	 */
	public function on_blog_switch( $blog_id ): void {
		$this->current_blog_id = (int) $blog_id;

		if ( isset( $this->options[ $blog_id ] ) ) {
			return;
		}

		$this->init_options_for_current_blog();
	}

	/**
	 * Stores the options into the database for all blogs.
	 * Hooked to `shutdown`.
	 *
	 * @since 3.7
	 *
	 * @return void
	 */
	public function save_all(): void {
		// Find blog with modified options.
		$modified = $this->get_modified();

		if ( empty( $modified ) ) {
			// Not modified.
			return;
		}

		remove_action( 'switch_blog', array( $this, 'on_blog_switch' ), -1000 );

		// Handle the original blog first, maybe this will prevent the use of `switch_to_blog()`.
		if ( isset( $modified[ $this->blog_id ] ) && $this->current_blog_id === $this->blog_id ) {
			$this->save();
			unset( $modified[ $this->blog_id ] );

			if ( empty( $modified ) ) {
				// All done, no need of `switch_to_blog()`.
				return;
			}
		}

		foreach ( $modified as $blog_id => $_yup ) {
			switch_to_blog( $blog_id );
			$this->save();
			restore_current_blog();
		}
	}

	/**
	 * Stores the options into the database.
	 *
	 * @since 3.7
	 *
	 * @return bool True if the options were updated, false otherwise.
	 */
	public function save(): bool {
		if ( empty( $this->modified[ $this->current_blog_id ] ) ) {
			return false;
		}

		unset( $this->modified[ $this->current_blog_id ] );

		if ( is_multisite() && ! get_site( $this->current_blog_id ) ) { // Cached by `$this->get_modified()` if called from `$this->save_all()`.
			// Deleted. Should not happen if called from `$this->save_all()`.
			return false;
		}

		$options = get_option( self::OPTION_NAME, array() );

		if ( is_array( $options ) ) {
			// Preserve options that are not from Polylang.
			$options = array_merge( $options, $this->get_all() );
		} else {
			$options = $this->get_all();
		}

		return update_option( self::OPTION_NAME, $options );
	}

	/**
	 * Returns all options.
	 *
	 * @since 3.7
	 *
	 * @return mixed[] All options values.
	 */
	public function get_all(): array {
		if ( empty( $this->options[ $this->current_blog_id ] ) ) {
			// No options.
			return array();
		}

		return array_map(
			function ( $value ) {
				return $value->get();
			},
			array_filter(
				$this->options[ $this->current_blog_id ],
				function ( $value ) {
					return $value instanceof Abstract_Option;
				}
			)
		);
	}

	/**
	 * Merges a subset of options into the current blog ones.
	 *
	 * @since 3.7
	 *
	 * @param array $values Array of raw options.
	 * @return WP_Error
	 */
	public function merge( array $values ): WP_Error {
		$errors = new WP_Error();

		foreach ( $this->options[ $this->current_blog_id ] as $key => $option ) {
			if ( ! isset( $values[ $key ] ) || ! $this->has( $key ) ) {
				continue;
			}

			$option_errors = $this->set( $key, $values[ $key ] );

			if ( $option_errors->has_errors() ) {
				// Blocking and non-blocking errors.
				$errors->merge_from( $option_errors );
			}

			unset( $values[ $key ] );
		}

		if ( empty( $values ) ) {
			return $errors;
		}

		// Merge all "unknown option" errors into a single error message.
		if ( 1 === count( $values ) ) {
			/* translators: %s is the name of an option. */
			$message = __( 'Unknown option key %s.', 'polylang' );
		} else {
			/* translators: %s is a list of option names. */
			$message = __( 'Unknown option keys %s.', 'polylang' );
		}

		$errors->add(
			'pll_unknown_option_keys',
			sprintf(
				$message,
				wp_sprintf_l(
					'%l',
					array_map(
						function ( $value ) {
							return "'$value'";
						},
						array_keys( $values )
					)
				)
			)
		);

		return $errors;
	}

	/**
	 * Returns JSON schema for all options of the current blog.
	 *
	 * @since 3.7
	 *
	 * @return array The schema.
	 *
	 * @phpstan-return Schema
	 */
	public function get_schema(): array {
		if ( isset( $this->schema[ $this->current_blog_id ] ) ) {
			return $this->schema[ $this->current_blog_id ];
		}

		$properties = array();

		if ( $this->is_plugin_active() ) {
			foreach ( $this->options[ $this->current_blog_id ] as $option ) {
				if ( ! $option instanceof Abstract_Option || empty( $option->get_schema() ) ) {
					continue;
				}

				$properties[ $option->key() ] = $option->get_schema();
			}
		}

		$this->schema[ $this->current_blog_id ] = array(
			'$schema'              => 'http://json-schema.org/draft-04/schema#',
			'title'                => static::OPTION_NAME,
			'description'          => __( 'Polylang options', 'polylang' ),
			'type'                 => 'object',
			'properties'           => $properties,
			'additionalProperties' => false,
		);

		return $this->schema[ $this->current_blog_id ];
	}

	/**
	 * Tells if an option exists.
	 *
	 * @since 3.7
	 *
	 * @param string $key The name of the option to check for.
	 * @return bool
	 */
	public function has( string $key ): bool {
		return isset( $this->options[ $this->current_blog_id ][ $key ] ) && $this->options[ $this->current_blog_id ][ $key ] instanceof Abstract_Option;
	}

	/**
	 * Returns the value of the specified option.
	 *
	 * @since 3.7
	 *
	 * @param string $key The name of the option to retrieve.
	 * @return mixed
	 */
	public function get( string $key ) {
		if ( ! $this->has( $key ) ) {
			$v = null;
			return $v;
		}

		/** @var Abstract_Option */
		$option = $this->options[ $this->current_blog_id ][ $key ];
		return $option->get();
	}

	/**
	 * Assigns a value to the specified option.
	 *
	 * This doesn't allow to set an unknown option.
	 * When doing multiple `set()`, options must be set in the right order: some options depend on other options' value.
	 *
	 * @since 3.7
	 *
	 * @param string $key   The name of the option to assign the value to.
	 * @param mixed  $value The value to set.
	 * @return WP_Error
	 */
	public function set( string $key, $value ): WP_Error {
		if ( ! $this->has( $key ) ) {
			/* translators: %s is the name of an option. */
			return new WP_Error( 'pll_unknown_option_key', sprintf( __( 'Unknown option key %s.', 'polylang' ), "'$key'" ) );
		}

		/** @var Abstract_Option */
		$option    = $this->options[ $this->current_blog_id ][ $key ];
		$old_value = $option->get();

		if ( $option->set( $value, $this ) && $option->get() !== $old_value ) {
			// No blocking errors: the value can be stored.
			$this->modified[ $this->current_blog_id ] = true;
		}

		// Return errors.
		return $option->get_errors();
	}

	/**
	 * Resets an option to its default value.
	 *
	 * @since 3.7
	 *
	 * @param string $key The name of the option to reset.
	 * @return mixed The new value.
	 */
	public function reset( string $key ) {
		if ( ! $this->has( $key ) ) {
			return null;
		}

		/** @var Abstract_Option */
		$option = $this->options[ $this->current_blog_id ][ $key ];

		if ( $option->get() !== $option->reset() ) {
			$this->modified[ $this->current_blog_id ] = true;
		}

		return $option->get();
	}

	/**
	 * Removes an option sub value from its array.
	 *
	 * @since 3.8
	 *
	 * @param string $key   The name of the option to splice.
	 * @param mixed  $value The value to remove.
	 * @return WP_Error An error object, empty if the value was removed successfully.
	 */
	public function remove( string $key, $value ): WP_Error {
		if ( ! $this->has( $key ) ) {
			return new WP_Error(
				'pll_unknown_option_key',
				/* translators: %s is the name of an option. */
				sprintf( __( 'Unknown option key %s.', 'polylang' ), "'$key'" )
			);
		}

		$option = $this->options[ $this->current_blog_id ][ $key ];

		if ( ! $option instanceof Abstract_List && ! $option instanceof Abstract_Map ) {
			return new WP_Error(
				'pll_invalid_option_type',
				/* translators: %s is the name of an option. */
				sprintf( __( 'Option %s is not a list or map.', 'polylang' ), "'$key'" )
			);
		}

		if ( $option->remove( $value ) ) {
			$this->modified[ $this->current_blog_id ] = true;
			return new WP_Error();
		}

		return new WP_Error(
			'pll_remove_failed',
			/* translators: %1$s is the value to remove. %2$s is the name of an option. */
			sprintf( __( 'Failed to remove %1$s from %2$s.', 'polylang' ), print_r( $value, true ), "'$key'" ) // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
		);
	}


	/**
	 * Adds a value to an option.
	 *
	 * @since 3.8
	 *
	 * @param string $key   The name of the option to add the value to.
	 * @param mixed  $value The value to add.
	 * @return WP_Error An error object, empty if the value was added successfully.
	 */
	public function add( string $key, $value ): WP_Error {
		if ( ! $this->has( $key ) ) {
			return new WP_Error(
				'pll_unknown_option_key',
				/* translators: %s is the name of an option. */
				sprintf( __( 'Unknown option key %s.', 'polylang' ), "'$key'" )
			);
		}

		$option = $this->options[ $this->current_blog_id ][ $key ];

		if ( ! $option instanceof Abstract_List && ! $option instanceof Abstract_Map ) {
			return new WP_Error(
				'pll_invalid_option_type',
				/* translators: %s is the name of an option. */
				sprintf( __( 'Option %s is not a list or map.', 'polylang' ), "'$key'" )
			);
		}

		if ( $option->add( $value, $this ) ) {
			$this->modified[ $this->current_blog_id ] = true;
			return new WP_Error();
		}

		return new WP_Error(
			'pll_add_failed',
			/* translators: %1$s is the value to add. %2$s is the name of an option. */
			sprintf( __( 'Failed to add %1$s to %2$s.', 'polylang' ), print_r( $value, true ), "'$key'" ) // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
		);
	}

	/**
	 * Tells if an option exists.
	 * Required by interface `ArrayAccess`.
	 *
	 * @since 3.7
	 *
	 * @param string $offset The name of the option to check for.
	 * @return bool
	 */
	public function offsetExists( $offset ): bool {
		return $this->has( (string) $offset );
	}

	/**
	 * Returns the value of the specified option.
	 * Required by interface `ArrayAccess`.
	 *
	 * @since 3.7
	 *
	 * @param string $offset The name of the option to retrieve.
	 * @return mixed
	 */
	#[\ReturnTypeWillChange]
	public function offsetGet( $offset ) {
		return $this->get( (string) $offset );
	}

	/**
	 * Assigns a value to the specified option.
	 * This doesn't allow to set an unknown option.
	 * Required by interface `ArrayAccess`.
	 *
	 * @since 3.7
	 *
	 * @param string $offset The name of the option to assign the value to.
	 * @param mixed  $value  The value to set.
	 * @return void
	 */
	public function offsetSet( $offset, $value ): void {
		$this->set( (string) $offset, $value );
	}

	/**
	 * Resets an option.
	 * This doesn't allow to unset an option, this resets it to its default value instead.
	 * Required by interface `ArrayAccess`.
	 *
	 * @since 3.7
	 *
	 * @param string $offset The name of the option to unset.
	 * @return void
	 */
	public function offsetUnset( $offset ): void {
		$this->reset( (string) $offset );
	}

	/**
	 * Returns all current site's option values.
	 * Required by interface `IteratorAggregate`.
	 *
	 * @since 3.7
	 *
	 * @return ArrayIterator
	 *
	 * @phpstan-return ArrayIterator<non-empty-string, mixed>
	 */
	public function getIterator(): ArrayIterator {
		return new ArrayIterator( $this->get_all() );
	}

	/**
	 * Retrieves site health information based on the current blog's options.
	 *
	 * @since 3.8
	 *
	 * @return array The site health information array.
	 */
	public function get_site_health_info(): array {
		$infos = array();
		foreach ( $this->options[ $this->current_blog_id ] as $option ) {
			if ( ! $option instanceof Abstract_Option ) {
				continue;
			}

			$info = $option->get_site_health_info( $this );

			if ( ! empty( $info ) ) {
				$infos[ $option::key() ] = $info;
			}
		}

		return $infos;
	}

	/**
	 * Returns the list of modified sites.
	 * On multisite, sites are cached.
	 * /!\ At this point, some sites may have been deleted. They are removed from `$this->modified` here.
	 *
	 * @since 3.7
	 *
	 * @return bool[]
	 * @phpstan-return array<int, true>
	 */
	private function get_modified(): array {
		if ( empty( $this->modified ) ) {
			// Not modified.
			return $this->modified;
		}

		// Cleanup deleted sites and cache existing ones.
		if ( ! is_multisite() ) {
			// Not multisite: no need to cache or verify existence.
			return $this->modified;
		}

		// Fetch all the data instead of only the IDs, so it is cached.
		$sites = get_sites(
			array(
				'site__in' => array_keys( $this->modified ),
				'number'   => count( $this->modified ),
			)
		);

		// Keep only existing blogs.
		$this->modified = array();
		foreach ( $sites as $site ) {
			$this->modified[ $site->id ] = true;
		}

		return $this->modified;
	}

	/**
	 * Initializes options for the current blog.
	 *
	 * @since 3.7
	 *
	 * @return void
	 */
	private function init_options_for_current_blog(): void {
		if ( ! $this->is_plugin_active() ) {
			// Don't try to get the options from the DB.
			$this->options[ $this->current_blog_id ] = array();
		} else {
			$options = get_option( self::OPTION_NAME );

			if ( empty( $options ) || ! is_array( $options ) ) {
				$this->options[ $this->current_blog_id ]  = array();
				$this->modified[ $this->current_blog_id ] = true;
			} else {
				$this->options[ $this->current_blog_id ] = $options;
			}
		}

		/**
		 * Fires after the options have been init for the current blog.
		 * This is the best place to register options.
		 *
		 * @since 3.7
		 * @since 3.8 New parameter `$is_plugin_active`.
		 *
		 * @param Options $options          Instance of the options.
		 * @param int     $current_blog_id  Current blog ID.
		 * @param bool    $is_plugin_active True if Polylang is active on the current site, false otherwise.
		 *                                      This can be false after calling `switch_to_blog()`.
		 */
		do_action( 'pll_init_options_for_blog', $this, $this->current_blog_id, $this->is_plugin_active() );
	}

	/**
	 * Tells if Polylang is active on the current blog.
	 *
	 * @since 3.8
	 *
	 * @return bool
	 */
	private function is_plugin_active(): bool {
		if ( isset( $this->is_plugin_active[ $this->current_blog_id ] ) ) {
			return $this->is_plugin_active[ $this->current_blog_id ];
		}

		$this->is_plugin_active[ $this->current_blog_id ] = pll_is_plugin_active( POLYLANG_BASENAME ) || doing_action( 'activate_' . POLYLANG_BASENAME );

		return $this->is_plugin_active[ $this->current_blog_id ];
	}

	/**
	 * Decorates options if we are on a site where Polylang is not active.
	 *
	 * @since 3.8
	 *
	 * @param Abstract_Option $option The option to decorate.
	 * @return Abstract_Option
	 */
	private function maybe_make_option_inactive( Abstract_Option $option ): Abstract_Option {
		if ( $this->is_plugin_active() || $option instanceof Inactive_Option ) {
			return $option;
		}

		return new Inactive_Option( $option );
	}
}

Directory Contents

Dirs: 2 × Files: 4
Name Size Perms Modified Actions
Business DIR
- drwxr-xr-x 2026-08-16 07:30:00
Edit Download
Primitive DIR
- drwxr-xr-x 2026-08-16 07:30:00
Edit Download
7.04 KB lrw-r--r-- 2026-06-02 09:29:18
Edit Download
2.56 KB lrw-r--r-- 2026-06-02 09:29:18
Edit Download
18.97 KB lrw-r--r-- 2026-06-02 09:29:18
Edit Download
1.07 KB lrw-r--r-- 2026-06-02 09:29:18
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