wp/wp-includes/option.php
author ymh <ymh.work@gmail.com>
Tue, 27 Sep 2022 16:37:53 +0200
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
permissions -rw-r--r--
upgrade wordpress to 6.0.2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Option API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     6
 * @subpackage Option
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    10
 * Retrieves an option value based on an option name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    12
 * If the option does not exist, and a default value is not provided,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    13
 * boolean false is returned. This could be used to check whether you need
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    14
 * to initialize an option during installation of a plugin, however that
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    15
 * can be done better by using add_option() which will not overwrite
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    16
 * existing options.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    17
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    18
 * Not initializing an option and using boolean `false` as a return value
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    19
 * is a bad practice as it triggers an additional database query.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    20
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    21
 * The type of the returned value can be different from the type that was passed
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    22
 * when saving or updating the option. If the option value was serialized,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    23
 * then it will be unserialized when it is returned. In this case the type will
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    24
 * be the same. For example, storing a non-scalar value like an array will
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    25
 * return the same array.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    26
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    27
 * In most cases non-string scalar and null values will be converted and returned
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    28
 * as string equivalents.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    30
 * Exceptions:
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    31
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    32
 * 1. When the option has not been saved in the database, the `$default` value
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    33
 *    is returned if provided. If not, boolean `false` is returned.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    34
 * 2. When one of the Options API filters is used: {@see 'pre_option_$option'},
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    35
 *    {@see 'default_option_$option'}, or {@see 'option_$option'}, the returned
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    36
 *    value may not match the expected type.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    37
 * 3. When the option has just been saved in the database, and get_option()
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    38
 *    is used right after, non-string scalar and null values are not converted to
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    39
 *    string equivalents and the original type is returned.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    40
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    41
 * Examples:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    42
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    43
 * When adding options like this: `add_option( 'my_option_name', 'value' )`
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    44
 * and then retrieving them with `get_option( 'my_option_name' )`, the returned
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    45
 * values will be:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    47
 *   - `false` returns `string(0) ""`
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    48
 *   - `true`  returns `string(1) "1"`
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    49
 *   - `0`     returns `string(1) "0"`
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    50
 *   - `1`     returns `string(1) "1"`
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    51
 *   - `'0'`   returns `string(1) "0"`
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    52
 *   - `'1'`   returns `string(1) "1"`
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    53
 *   - `null`  returns `string(0) ""`
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    54
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    55
 * When adding options with non-scalar values like
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    56
 * `add_option( 'my_array', array( false, 'str', null ) )`, the returned value
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    57
 * will be identical to the original as it is serialized before saving
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    58
 * it in the database:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    59
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    60
 *     array(3) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    61
 *         [0] => bool(false)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    62
 *         [1] => string(3) "str"
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    63
 *         [2] => NULL
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    64
 *     }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    65
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    68
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    69
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    70
 * @param string $option  Name of the option to retrieve. Expected to not be SQL-escaped.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    71
 * @param mixed  $default Optional. Default value to return if the option does not exist.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    72
 * @return mixed Value of the option. A value of any type may be returned, including
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    73
 *               scalar (string, boolean, float, integer), null, array, object.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    74
 *               Scalar and null values will be returned as strings as long as they originate
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    75
 *               from a database stored option value. If there is no option in the database,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    76
 *               boolean `false` is returned.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
function get_option( $option, $default = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    81
	if ( is_scalar( $option ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    82
		$option = trim( $option );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    83
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    84
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    85
	if ( empty( $option ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    87
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    89
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    90
	 * Until a proper _deprecated_option() function can be introduced,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    91
	 * redirect requests to deprecated keys to the new, correct ones.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    92
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    93
	$deprecated_keys = array(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    94
		'blacklist_keys'    => 'disallowed_keys',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    95
		'comment_whitelist' => 'comment_previously_approved',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    96
	);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    97
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    98
	if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    99
		_deprecated_argument(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   100
			__FUNCTION__,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   101
			'5.5.0',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   102
			sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   103
				/* translators: 1: Deprecated option key, 2: New option key. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   104
				__( 'The "%1$s" option key has been renamed to "%2$s".' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   105
				$option,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   106
				$deprecated_keys[ $option ]
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   107
			)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   108
		);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   109
		return get_option( $deprecated_keys[ $option ], $default );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   110
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   111
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   113
	 * Filters the value of an existing option before it is retrieved.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   117
	 * Returning a truthy value from the filter will effectively short-circuit retrieval
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   118
	 * and return the passed value instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	 * @since 1.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   121
	 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   122
	 * @since 4.9.0 The `$default` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   124
	 * @param mixed  $pre_option The value to return instead of the option value. This differs
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   125
	 *                           from `$default`, which is used as the fallback value in the event
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   126
	 *                           the option doesn't exist elsewhere in get_option().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   127
	 *                           Default false (to skip past the short-circuit).
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   128
	 * @param string $option     Option name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   129
	 * @param mixed  $default    The fallback value to return if the option does not exist.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   130
	 *                           Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   132
	$pre = apply_filters( "pre_option_{$option}", false, $option, $default );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   133
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   134
	if ( false !== $pre ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		return $pre;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   136
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   138
	if ( defined( 'WP_SETUP_CONFIG' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   140
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   142
	// Distinguish between `false` as a default, and not passing one.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   143
	$passed_default = func_num_args() > 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   144
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   145
	if ( ! wp_installing() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   146
		// Prevent non-existent options from triggering multiple queries.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
		$notoptions = wp_cache_get( 'notoptions', 'options' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   148
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
		if ( isset( $notoptions[ $option ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
			/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
			 * Filters the default value for an option.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
			 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
			 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   156
			 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   157
			 * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
			 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   159
			 * @param mixed  $default The default value to return if the option does not exist
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   160
			 *                        in the database.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   161
			 * @param string $option  Option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
			 * @param bool   $passed_default Was `get_option()` passed a default value?
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
			 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   164
			return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		$alloptions = wp_load_alloptions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   169
		if ( isset( $alloptions[ $option ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   170
			$value = $alloptions[ $option ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			$value = wp_cache_get( $option, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
			if ( false === $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
				$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   177
				// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				if ( is_object( $row ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
					$value = $row->option_value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
					wp_cache_add( $option, $value, 'options' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   181
				} else { // Option does not exist, so we must cache its non-existence.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
					if ( ! is_array( $notoptions ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   183
						$notoptions = array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   184
					}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   185
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   186
					$notoptions[ $option ] = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
					wp_cache_set( 'notoptions', $notoptions, 'options' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
					/** This filter is documented in wp-includes/option.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   190
					return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		$suppress = $wpdb->suppress_errors();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   196
		$row      = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		$wpdb->suppress_errors( $suppress );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   198
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
		if ( is_object( $row ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			$value = $row->option_value;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
			/** This filter is documented in wp-includes/option.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   203
			return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   207
	// If home is not set, use siteurl.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   208
	if ( 'home' === $option && '' === $value ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
		return get_option( 'siteurl' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   210
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   212
	if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
		$value = untrailingslashit( $value );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   214
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
	 * Filters the value of an existing option.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
	 * @since 1.5.0 As 'option_' . $setting
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
	 * @since 4.4.0 The `$option` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
	 * @param mixed  $value  Value of the option. If stored serialized, it will be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   226
	 *                       unserialized prior to being returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   227
	 * @param string $option Option name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
	return apply_filters( "option_{$option}", maybe_unserialize( $value ), $option );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   233
 * Protects WordPress special option from being modified.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 * Will die if $option is in protected list. Protected options are 'alloptions'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 * and 'notoptions' options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 * @param string $option Option name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
function wp_protect_special_option( $option ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   243
	if ( 'alloptions' === $option || 'notoptions' === $option ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   244
		wp_die(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   245
			sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   246
				/* translators: %s: Option name. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   247
				__( '%s is a protected WP option and may not be modified' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   248
				esc_html( $option )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   249
			)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   250
		);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   251
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   255
 * Prints option value after sanitizing for forms.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 * @param string $option Option name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
function form_option( $option ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	echo esc_attr( get_option( $option ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 * Loads and caches all autoloaded options, if available or all options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 * @since 2.2.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   269
 * @since 5.3.1 The `$force_cache` parameter was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   272
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   273
 * @param bool $force_cache Optional. Whether to force an update of the local cache
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   274
 *                          from the persistent cache. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
 * @return array List of all options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   277
function wp_load_alloptions( $force_cache = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   280
	if ( ! wp_installing() || ! is_multisite() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   281
		$alloptions = wp_cache_get( 'alloptions', 'options', $force_cache );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   282
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
		$alloptions = false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   284
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   286
	if ( ! $alloptions ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   287
		$suppress      = $wpdb->suppress_errors();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   288
		$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   289
		if ( ! $alloptions_db ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
			$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   291
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   292
		$wpdb->suppress_errors( $suppress );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   293
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
		$alloptions = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
		foreach ( (array) $alloptions_db as $o ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   296
			$alloptions[ $o->option_name ] = $o->option_value;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   298
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   299
		if ( ! wp_installing() || ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   300
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   301
			 * Filters all options before caching them.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   302
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   303
			 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   305
			 * @param array $alloptions Array with all options.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   306
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   307
			$alloptions = apply_filters( 'pre_cache_alloptions', $alloptions );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   308
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
			wp_cache_add( 'alloptions', $alloptions, 'options' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   310
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   313
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   314
	 * Filters all options after retrieving them.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   316
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   317
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   318
	 * @param array $alloptions Array with all options.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   319
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   320
	return apply_filters( 'alloptions', $alloptions );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   330
 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   332
function wp_load_core_site_options( $network_id = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   335
	if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   337
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   339
	if ( empty( $network_id ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
		$network_id = get_current_network_id();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   341
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   343
	$core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   344
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   345
	$core_options_in = "'" . implode( "', '", $core_options ) . "'";
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   346
	$options         = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   348
	$data = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	foreach ( $options as $option ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   350
		$key                = $option->meta_key;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   351
		$cache_key          = "{$network_id}:$key";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		$option->meta_value = maybe_unserialize( $option->meta_value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   354
		$data[ $cache_key ] = $option->meta_value;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
	}
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   356
	wp_cache_set_multiple( $data, 'site-options' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   360
 * Updates the value of an option that was already added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   362
 * You do not need to serialize values. If the value needs to be serialized,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   363
 * then it will be serialized before it is inserted into the database.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   364
 * Remember, resources cannot be serialized or added as an option.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   366
 * If the option does not exist, it will be created.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   367
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   368
 * This function is designed to work with or without a logged-in user. In terms of security,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   369
 * plugin developers should check the current user's capabilities before updating any options.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 * @since 1.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
 * @since 4.2.0 The `$autoload` parameter was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   374
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   375
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   376
 * @param string      $option   Name of the option to update. Expected to not be SQL-escaped.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
 * @param mixed       $value    Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
 * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
 *                              `$autoload` can only be updated using `update_option()` if `$value` is also changed.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   380
 *                              Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   381
 *                              the default value is 'yes'. Default null.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   382
 * @return bool True if the value was updated, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
function update_option( $option, $value, $autoload = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   387
	if ( is_scalar( $option ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   388
		$option = trim( $option );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   389
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   390
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   391
	if ( empty( $option ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   393
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   395
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   396
	 * Until a proper _deprecated_option() function can be introduced,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   397
	 * redirect requests to deprecated keys to the new, correct ones.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   398
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   399
	$deprecated_keys = array(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   400
		'blacklist_keys'    => 'disallowed_keys',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   401
		'comment_whitelist' => 'comment_previously_approved',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   402
	);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   403
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   404
	if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   405
		_deprecated_argument(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   406
			__FUNCTION__,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   407
			'5.5.0',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   408
			sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   409
				/* translators: 1: Deprecated option key, 2: New option key. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   410
				__( 'The "%1$s" option key has been renamed to "%2$s".' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   411
				$option,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   412
				$deprecated_keys[ $option ]
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   413
			)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   414
		);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   415
		return update_option( $deprecated_keys[ $option ], $value, $autoload );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   416
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   417
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	wp_protect_special_option( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   420
	if ( is_object( $value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		$value = clone $value;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   422
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   424
	$value     = sanitize_option( $option, $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	$old_value = get_option( $option );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   428
	 * Filters a specific option before its value is (maybe) serialized and updated.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
	 * @since 2.6.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
	 * @since 4.4.0 The `$option` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   435
	 * @param mixed  $value     The new, unserialized option value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   436
	 * @param mixed  $old_value The old option value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
	 * @param string $option    Option name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
	$value = apply_filters( "pre_update_option_{$option}", $value, $old_value, $option );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   442
	 * Filters an option before its value is (maybe) serialized and updated.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
	 * @param mixed  $value     The new, unserialized option value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
	 * @param string $option    Name of the option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
	 * @param mixed  $old_value The old option value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
	$value = apply_filters( 'pre_update_option', $value, $option, $old_value );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   452
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   453
	 * If the new and old values are the same, no need to update.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   454
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   455
	 * Unserialized values will be adequate in most cases. If the unserialized
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   456
	 * data differs, the (maybe) serialized data is checked to avoid
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   457
	 * unnecessary database calls for otherwise identical object instances.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   458
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   459
	 * See https://core.trac.wordpress.org/ticket/38903
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   460
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   461
	if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   463
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
	/** This filter is documented in wp-includes/option.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   466
	if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
		// Default setting for new options is 'yes'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
		if ( null === $autoload ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
			$autoload = 'yes';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
		return add_option( $option, $value, '', $autoload );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	$serialized_value = maybe_serialize( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
	 * Fires immediately before an option value is updated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
	 * @param string $option    Name of the option to update.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
	 * @param mixed  $old_value The old option value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
	 * @param mixed  $value     The new option value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	do_action( 'update_option', $option, $old_value, $value );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
	$update_args = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
		'option_value' => $serialized_value,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
	if ( null !== $autoload ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
		$update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	$result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => $option ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   497
	if ( ! $result ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   499
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	$notoptions = wp_cache_get( 'notoptions', 'options' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   502
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   503
	if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   504
		unset( $notoptions[ $option ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		wp_cache_set( 'notoptions', $notoptions, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   508
	if ( ! wp_installing() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   509
		$alloptions = wp_load_alloptions( true );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   510
		if ( isset( $alloptions[ $option ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
			$alloptions[ $option ] = $serialized_value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
			wp_cache_set( 'alloptions', $alloptions, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
			wp_cache_set( $option, $serialized_value, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
	 * Fires after the value of a specific option has been successfully updated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
	 * @since 2.0.1
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   524
	 * @since 4.4.0 The `$option` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   526
	 * @param mixed  $old_value The old option value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   527
	 * @param mixed  $value     The new option value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   528
	 * @param string $option    Option name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   530
	do_action( "update_option_{$option}", $old_value, $value, $option );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
	 * Fires after the value of an option has been successfully updated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
	 * @param string $option    Name of the updated option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
	 * @param mixed  $old_value The old option value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
	 * @param mixed  $value     The new option value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	do_action( 'updated_option', $option, $old_value, $value );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   542
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   547
 * Adds a new option.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   549
 * You do not need to serialize values. If the value needs to be serialized,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   550
 * then it will be serialized before it is inserted into the database.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   551
 * Remember, resources cannot be serialized or added as an option.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
 * You can create options without values and then update the values later.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
 * Existing options will not be updated and checks are performed to ensure that you
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
 * aren't adding a protected WordPress option. Care should be taken to not name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
 * options the same as the ones which are protected.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   560
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   561
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   562
 * @param string      $option     Name of the option to add. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   563
 * @param mixed       $value      Optional. Option value. Must be serializable if non-scalar.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   564
 *                                Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   565
 * @param string      $deprecated Optional. Description. Not used anymore.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   566
 * @param string|bool $autoload   Optional. Whether to load the option when WordPress starts up.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   567
 *                                Default is enabled. Accepts 'no' to disable for legacy reasons.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   568
 * @return bool True if the option was added, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   573
	if ( ! empty( $deprecated ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   574
		_deprecated_argument( __FUNCTION__, '2.3.0' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   575
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   577
	if ( is_scalar( $option ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   578
		$option = trim( $option );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   579
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   580
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   581
	if ( empty( $option ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   583
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   585
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   586
	 * Until a proper _deprecated_option() function can be introduced,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   587
	 * redirect requests to deprecated keys to the new, correct ones.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   588
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   589
	$deprecated_keys = array(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   590
		'blacklist_keys'    => 'disallowed_keys',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   591
		'comment_whitelist' => 'comment_previously_approved',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   592
	);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   593
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   594
	if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   595
		_deprecated_argument(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   596
			__FUNCTION__,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   597
			'5.5.0',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   598
			sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   599
				/* translators: 1: Deprecated option key, 2: New option key. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   600
				__( 'The "%1$s" option key has been renamed to "%2$s".' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   601
				$option,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   602
				$deprecated_keys[ $option ]
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   603
			)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   604
		);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   605
		return add_option( $deprecated_keys[ $option ], $value, $deprecated, $autoload );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   606
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   607
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	wp_protect_special_option( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   610
	if ( is_object( $value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
		$value = clone $value;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   612
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	$value = sanitize_option( $option, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   616
	// Make sure the option doesn't already exist.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   617
	// We can check the 'notoptions' cache before we ask for a DB query.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	$notoptions = wp_cache_get( 'notoptions', 'options' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   619
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   620
	if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
		/** This filter is documented in wp-includes/option.php */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   622
		if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   624
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   625
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	$serialized_value = maybe_serialize( $value );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   628
	$autoload         = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   629
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   630
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   631
	 * Fires before an option is added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   632
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   634
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   635
	 * @param string $option Name of the option to add.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   636
	 * @param mixed  $value  Value of the option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
	do_action( 'add_option', $option, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	$result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   641
	if ( ! $result ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   643
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   645
	if ( ! wp_installing() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   646
		if ( 'yes' === $autoload ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   647
			$alloptions            = wp_load_alloptions( true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
			$alloptions[ $option ] = $serialized_value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
			wp_cache_set( 'alloptions', $alloptions, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
			wp_cache_set( $option, $serialized_value, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   655
	// This option exists now.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   656
	$notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   657
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   658
	if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   659
		unset( $notoptions[ $option ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
		wp_cache_set( 'notoptions', $notoptions, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   663
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   664
	 * Fires after a specific option has been added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   665
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   666
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   667
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   668
	 * @since 2.5.0 As "add_option_{$name}"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   669
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
	 * @param string $option Name of the option to add.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   672
	 * @param mixed  $value  Value of the option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   673
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	do_action( "add_option_{$option}", $option, $value );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
	 * Fires after an option has been added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   680
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
	 * @param string $option Name of the added option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
	 * @param mixed  $value  Value of the option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	do_action( 'added_option', $option, $value );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   685
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
 * Removes option by name. Prevents removal of protected WordPress options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   694
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   695
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   696
 * @param string $option Name of the option to delete. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   697
 * @return bool True if the option was deleted, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
function delete_option( $option ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   702
	if ( is_scalar( $option ) ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   703
		$option = trim( $option );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   704
	}
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   705
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   706
	if ( empty( $option ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   708
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
	wp_protect_special_option( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   712
	// Get the ID, if no ID then return.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	$row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   714
	if ( is_null( $row ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   716
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   717
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   718
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   719
	 * Fires immediately before an option is deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
	 * @param string $option Name of the option to delete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
	do_action( 'delete_option', $option );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
	$result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   728
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   729
	if ( ! wp_installing() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   730
		if ( 'yes' === $row->autoload ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   731
			$alloptions = wp_load_alloptions( true );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   732
			if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   733
				unset( $alloptions[ $option ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
				wp_cache_set( 'alloptions', $alloptions, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
			wp_cache_delete( $option, 'options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   740
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
	if ( $result ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   742
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   743
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   744
		 * Fires after a specific option has been deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   746
		 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   747
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   748
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   750
		 * @param string $option Name of the deleted option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   752
		do_action( "delete_option_{$option}", $option );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   754
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
		 * Fires after an option has been deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   756
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
		 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   758
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   759
		 * @param string $option Name of the deleted option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   760
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		do_action( 'deleted_option', $option );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   762
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   765
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   770
 * Deletes a transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
 * @param string $transient Transient name. Expected to not be SQL-escaped.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   775
 * @return bool True if the transient was deleted, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
function delete_transient( $transient ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
	 * Fires immediately before a specific transient is deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   785
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
	 * @param string $transient Transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   787
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   788
	do_action( "delete_transient_{$transient}", $transient );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   790
	if ( wp_using_ext_object_cache() || wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
		$result = wp_cache_delete( $transient, 'transient' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		$option_timeout = '_transient_timeout_' . $transient;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   794
		$option         = '_transient_' . $transient;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   795
		$result         = delete_option( $option );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   796
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   797
		if ( $result ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
			delete_option( $option_timeout );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   799
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   802
	if ( $result ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   803
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   804
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
		 * Fires after a transient is deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   808
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
		 * @param string $transient Deleted transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		do_action( 'deleted_transient', $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   812
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   818
 * Retrieves the value of a transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
 * If the transient does not exist, does not have a value, or has expired,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
 * then the return value will be false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
 * @param string $transient Transient name. Expected to not be SQL-escaped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
 * @return mixed Value of transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
function get_transient( $transient ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   830
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   831
	 * Filters the value of an existing transient before it is retrieved.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   835
	 * Returning a truthy value from the filter will effectively short-circuit retrieval
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   836
	 * and return the passed value instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
	 * @since 2.8.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   839
	 * @since 4.4.0 The `$transient` parameter was added
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   841
	 * @param mixed  $pre_transient The default value to return if the transient does not exist.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   842
	 *                              Any value other than false will short-circuit the retrieval
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   843
	 *                              of the transient, and return that value.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   844
	 * @param string $transient     Transient name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   845
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   846
	$pre = apply_filters( "pre_transient_{$transient}", false, $transient );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   847
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   848
	if ( false !== $pre ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
		return $pre;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   850
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   852
	if ( wp_using_ext_object_cache() || wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
		$value = wp_cache_get( $transient, 'transient' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
		$transient_option = '_transient_' . $transient;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   856
		if ( ! wp_installing() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   857
			// If option is not in alloptions, it is not autoloaded and thus has a timeout.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
			$alloptions = wp_load_alloptions();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   859
			if ( ! isset( $alloptions[ $transient_option ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
				$transient_timeout = '_transient_timeout_' . $transient;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   861
				$timeout           = get_option( $transient_timeout );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   862
				if ( false !== $timeout && $timeout < time() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   863
					delete_option( $transient_option );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
					delete_option( $transient_timeout );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
					$value = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   870
		if ( ! isset( $value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
			$value = get_option( $transient_option );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   872
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   876
	 * Filters an existing transient's value.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
	 * @since 2.8.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   881
	 * @since 4.4.0 The `$transient` parameter was added
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   883
	 * @param mixed  $value     Value of transient.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   884
	 * @param string $transient Transient name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   886
	return apply_filters( "transient_{$transient}", $value, $transient );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   890
 * Sets/updates the value of a transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   892
 * You do not need to serialize values. If the value needs to be serialized,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   893
 * then it will be serialized before it is set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   897
 * @param string $transient  Transient name. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   898
 *                           Must be 172 characters or fewer in length.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   899
 * @param mixed  $value      Transient value. Must be serializable if non-scalar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
 *                           Expected to not be SQL-escaped.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   901
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   902
 * @return bool True if the value was set, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
function set_transient( $transient, $value, $expiration = 0 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	$expiration = (int) $expiration;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   908
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   909
	 * Filters a specific transient before its value is set.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   911
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   912
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   914
	 * @since 4.2.0 The `$expiration` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   915
	 * @since 4.4.0 The `$transient` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   917
	 * @param mixed  $value      New value of transient.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   918
	 * @param int    $expiration Time until expiration in seconds.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   919
	 * @param string $transient  Transient name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   921
	$value = apply_filters( "pre_set_transient_{$transient}", $value, $expiration, $transient );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   922
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   923
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   924
	 * Filters the expiration for a transient before its value is set.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   925
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   926
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   927
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   928
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   929
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   930
	 * @param int    $expiration Time until expiration in seconds. Use 0 for no expiration.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   931
	 * @param mixed  $value      New value of transient.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   932
	 * @param string $transient  Transient name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   933
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   934
	$expiration = apply_filters( "expiration_of_transient_{$transient}", $expiration, $value, $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   935
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   936
	if ( wp_using_ext_object_cache() || wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
		$result = wp_cache_set( $transient, $value, 'transient', $expiration );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
		$transient_timeout = '_transient_timeout_' . $transient;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   940
		$transient_option  = '_transient_' . $transient;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   941
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   942
		if ( false === get_option( $transient_option ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
			$autoload = 'yes';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
			if ( $expiration ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
				$autoload = 'no';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
				add_option( $transient_timeout, time() + $expiration, '', 'no' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   948
			$result = add_option( $transient_option, $value, '', $autoload );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
		} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   950
			// If expiration is requested, but the transient has no timeout option,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   951
			// delete, then re-create transient rather than update.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   952
			$update = true;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   953
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   954
			if ( $expiration ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   955
				if ( false === get_option( $transient_timeout ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   956
					delete_option( $transient_option );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   957
					add_option( $transient_timeout, time() + $expiration, '', 'no' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   958
					$result = add_option( $transient_option, $value, '', 'no' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   959
					$update = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   960
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
					update_option( $transient_timeout, time() + $expiration );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   963
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   964
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   965
			if ( $update ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   966
				$result = update_option( $transient_option, $value );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   967
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   970
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
	if ( $result ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   972
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   973
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   974
		 * Fires after the value for a specific transient has been set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   975
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   976
		 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   977
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   979
		 * @since 3.6.0 The `$value` and `$expiration` parameters were added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   980
		 * @since 4.4.0 The `$transient` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   981
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   982
		 * @param mixed  $value      Transient value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   983
		 * @param int    $expiration Time until expiration in seconds.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   984
		 * @param string $transient  The name of the transient.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   985
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   986
		do_action( "set_transient_{$transient}", $value, $expiration, $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   988
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   989
		 * Fires after the value for a transient has been set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   990
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   991
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   992
		 * @since 3.6.0 The `$value` and `$expiration` parameters were added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   993
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
		 * @param string $transient  The name of the transient.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
		 * @param mixed  $value      Transient value.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   996
		 * @param int    $expiration Time until expiration in seconds.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   997
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
		do_action( 'setted_transient', $transient, $value, $expiration );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1000
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1005
 * Deletes all expired transients.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1006
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1007
 * The multi-table delete syntax is used to delete the transient record
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1008
 * from table a, and the corresponding transient_timeout record from table b.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1009
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1010
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1011
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1012
 * @param bool $force_db Optional. Force cleanup to run against the database even when an external object cache is used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1013
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1014
function delete_expired_transients( $force_db = false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1015
	global $wpdb;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1016
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1017
	if ( ! $force_db && wp_using_ext_object_cache() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1018
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1019
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1020
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1021
	$wpdb->query(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1022
		$wpdb->prepare(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1023
			"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1024
			WHERE a.option_name LIKE %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1025
			AND a.option_name NOT LIKE %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1026
			AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1027
			AND b.option_value < %d",
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1028
			$wpdb->esc_like( '_transient_' ) . '%',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1029
			$wpdb->esc_like( '_transient_timeout_' ) . '%',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1030
			time()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1031
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1032
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1033
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1034
	if ( ! is_multisite() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1035
		// Single site stores site transients in the options table.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1036
		$wpdb->query(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1037
			$wpdb->prepare(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1038
				"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1039
				WHERE a.option_name LIKE %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1040
				AND a.option_name NOT LIKE %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1041
				AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1042
				AND b.option_value < %d",
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1043
				$wpdb->esc_like( '_site_transient_' ) . '%',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1044
				$wpdb->esc_like( '_site_transient_timeout_' ) . '%',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1045
				time()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1046
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1047
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1048
	} elseif ( is_multisite() && is_main_site() && is_main_network() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1049
		// Multisite stores site transients in the sitemeta table.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1050
		$wpdb->query(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1051
			$wpdb->prepare(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1052
				"DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1053
				WHERE a.meta_key LIKE %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1054
				AND a.meta_key NOT LIKE %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1055
				AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1056
				AND b.meta_value < %d",
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1057
				$wpdb->esc_like( '_site_transient_' ) . '%',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1058
				$wpdb->esc_like( '_site_transient_timeout_' ) . '%',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1059
				time()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1060
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1061
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1062
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1063
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1064
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1065
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
 * Saves and restores user interface settings stored in a cookie.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
 * Checks if the current user-settings cookie is updated and stores it. When no
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
 * cookie exists (different browser used), adds the last saved cookie restoring
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
 * the settings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
function wp_user_settings() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1076
	if ( ! is_admin() || wp_doing_ajax() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1078
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1080
	$user_id = get_current_user_id();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1081
	if ( ! $user_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1083
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1085
	if ( ! is_user_member_of_blog() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
	$settings = (string) get_user_option( 'user-settings', $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1091
	if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1092
		$cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1094
		// No change or both empty.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1095
		if ( $cookie == $settings ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
			return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1097
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
		$last_saved = (int) get_user_option( 'user-settings-time', $user_id );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1100
		$current    = isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] ) : 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1102
		// The cookie is newer than the saved value. Update the user_option and leave the cookie as-is.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
		if ( $current > $last_saved ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
			update_user_option( $user_id, 'user-settings', $cookie, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
			update_user_option( $user_id, 'user-settings-time', time() - 5, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
	// The cookie is not set in the current browser or the saved value is newer.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1111
	$secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1112
	setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1113
	setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1114
	$_COOKIE[ 'wp-settings-' . $user_id ] = $settings;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1118
 * Retrieves user interface setting value based on setting name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1122
 * @param string       $name    The name of the setting.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1123
 * @param string|false $default Optional. Default value to return when $name is not set. Default false.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1124
 * @return mixed The last saved user setting or the default value/false if it doesn't exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
function get_user_setting( $name, $default = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
	$all_user_settings = get_all_user_settings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1129
	return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1133
 * Adds or updates user interface setting.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1135
 * Both $name and $value can contain only ASCII letters, numbers, hyphens, and underscores.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1136
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
 * This function has to be used before any output has started as it calls setcookie().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1141
 * @param string $name  The name of the setting.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
 * @param string $value The value for the setting.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1143
 * @return bool|null True if set successfully, false otherwise.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1144
 *                   Null if the current user is not a member of the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
function set_user_setting( $name, $value ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
	if ( headers_sent() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1151
	$all_user_settings          = get_all_user_settings();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1152
	$all_user_settings[ $name ] = $value;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
	return wp_set_all_user_settings( $all_user_settings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1158
 * Deletes user interface settings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
 * Deleting settings would reset them to the defaults.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1161
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
 * This function has to be used before any output has started as it calls setcookie().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
 * @param string $names The name or array of names of the setting to be deleted.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1167
 * @return bool|null True if deleted successfully, false otherwise.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1168
 *                   Null if the current user is not a member of the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
function delete_user_setting( $names ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1171
	if ( headers_sent() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1173
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
	$all_user_settings = get_all_user_settings();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1176
	$names             = (array) $names;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1177
	$deleted           = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
	foreach ( $names as $name ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1180
		if ( isset( $all_user_settings[ $name ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1181
			unset( $all_user_settings[ $name ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
			$deleted = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1186
	if ( $deleted ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
		return wp_set_all_user_settings( $all_user_settings );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1188
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1194
 * Retrieves all user interface settings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1198
 * @global array $_updated_user_settings
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1199
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1200
 * @return array The last saved user settings or empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
function get_all_user_settings() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
	global $_updated_user_settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1205
	$user_id = get_current_user_id();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1206
	if ( ! $user_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
		return array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1208
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
	if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
		return $_updated_user_settings;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
	$user_settings = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1216
	if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1217
		$cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1219
		if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
			parse_str( $cookie, $user_settings );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
		$option = get_user_option( 'user-settings', $user_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
		if ( $option && is_string( $option ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
			parse_str( $option, $user_settings );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
	$_updated_user_settings = $user_settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
	return $user_settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1235
 * Private. Sets all user interface settings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
 * @since 2.8.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1238
 * @access private
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1240
 * @global array $_updated_user_settings
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1241
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1242
 * @param array $user_settings User settings.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1243
 * @return bool|null True if set successfully, false if the current user could not be found.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1244
 *                   Null if the current user is not a member of the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
function wp_set_all_user_settings( $user_settings ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
	global $_updated_user_settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1249
	$user_id = get_current_user_id();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1250
	if ( ! $user_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1252
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1254
	if ( ! is_user_member_of_blog() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1256
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
	$settings = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
	foreach ( $user_settings as $name => $value ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1260
		$_name  = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1261
		$_value = preg_replace( '/[^A-Za-z0-9_-]+/', '', $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1263
		if ( ! empty( $_name ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
			$settings .= $_name . '=' . $_value . '&';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1265
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
	$settings = rtrim( $settings, '&' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
	parse_str( $settings, $_updated_user_settings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
	update_user_option( $user_id, 'user-settings', $settings, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
	update_user_option( $user_id, 'user-settings-time', time(), false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1278
 * Deletes the user settings of the current user.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
function delete_all_user_settings() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1283
	$user_id = get_current_user_id();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1284
	if ( ! $user_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1286
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
	update_user_option( $user_id, 'user-settings', '', false );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1289
	setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1293
 * Retrieve an option value for the current network based on name of option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1294
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1295
 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1296
 * @since 4.4.0 The `$use_cache` parameter was deprecated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1297
 * @since 4.4.0 Modified into wrapper for get_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1298
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1299
 * @see get_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1300
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1301
 * @param string $option     Name of the option to retrieve. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1302
 * @param mixed  $default    Optional. Value to return if the option doesn't exist. Default false.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1303
 * @param bool   $deprecated Whether to use cache. Multisite only. Always set to true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1304
 * @return mixed Value set for the option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1305
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1306
function get_site_option( $option, $default = false, $deprecated = true ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1307
	return get_network_option( null, $option, $default );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1308
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1309
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1310
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1311
 * Adds a new option for the current network.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1312
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1313
 * Existing options will not be updated. Note that prior to 3.3 this wasn't the case.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
 * @since 2.8.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1316
 * @since 4.4.0 Modified into wrapper for add_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1317
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1318
 * @see add_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1319
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1320
 * @param string $option Name of the option to add. Expected to not be SQL-escaped.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1321
 * @param mixed  $value  Option value, can be anything. Expected to not be SQL-escaped.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1322
 * @return bool True if the option was added, false otherwise.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1323
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1324
function add_site_option( $option, $value ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1325
	return add_network_option( null, $option, $value );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1326
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1327
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1328
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1329
 * Removes a option by name for the current network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1330
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1331
 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1332
 * @since 4.4.0 Modified into wrapper for delete_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1333
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1334
 * @see delete_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1335
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1336
 * @param string $option Name of the option to delete. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1337
 * @return bool True if the option was deleted, false otherwise.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1338
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1339
function delete_site_option( $option ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1340
	return delete_network_option( null, $option );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1341
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1342
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1343
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1344
 * Updates the value of an option that was already added for the current network.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1345
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1346
 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1347
 * @since 4.4.0 Modified into wrapper for update_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1348
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1349
 * @see update_network_option()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1350
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1351
 * @param string $option Name of the option. Expected to not be SQL-escaped.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1352
 * @param mixed  $value  Option value. Expected to not be SQL-escaped.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1353
 * @return bool True if the value was updated, false otherwise.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1354
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1355
function update_site_option( $option, $value ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1356
	return update_network_option( null, $option, $value );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1357
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1358
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1359
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1360
 * Retrieves a network's option value based on the option name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1361
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1362
 * @since 4.4.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1364
 * @see get_option()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1366
 * @global wpdb $wpdb WordPress database abstraction object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1367
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1368
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1369
 * @param string $option     Name of the option to retrieve. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1370
 * @param mixed  $default    Optional. Value to return if the option doesn't exist. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
 * @return mixed Value set for the option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1373
function get_network_option( $network_id, $option, $default = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1376
	if ( $network_id && ! is_numeric( $network_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1377
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1378
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1379
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1380
	$network_id = (int) $network_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1381
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1382
	// Fallback to the current network if a network ID is not specified.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1383
	if ( ! $network_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1384
		$network_id = get_current_network_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1385
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1386
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1388
	 * Filters the value of an existing network option before it is retrieved.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1392
	 * Returning a truthy value from the filter will effectively short-circuit retrieval
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1393
	 * and return the passed value instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
	 * @since 2.9.0 As 'pre_site_option_' . $key
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1396
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1397
	 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1398
	 * @since 4.7.0 The `$network_id` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1399
	 * @since 4.9.0 The `$default` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1400
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1401
	 * @param mixed  $pre_option The value to return instead of the option value. This differs
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1402
	 *                           from `$default`, which is used as the fallback value in the event
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1403
	 *                           the option doesn't exist elsewhere in get_network_option().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1404
	 *                           Default false (to skip past the short-circuit).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1405
	 * @param string $option     Option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1406
	 * @param int    $network_id ID of the network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1407
	 * @param mixed  $default    The fallback value to return if the option does not exist.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1408
	 *                           Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1410
	$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1412
	if ( false !== $pre ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1413
		return $pre;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1414
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1416
	// Prevent non-existent options from triggering multiple queries.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1417
	$notoptions_key = "$network_id:notoptions";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1418
	$notoptions     = wp_cache_get( $notoptions_key, 'site-options' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1419
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1420
	if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1421
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1422
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1423
		 * Filters a specific default network option.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1424
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
		 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1426
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1427
		 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1428
		 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1429
		 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1431
		 * @param mixed  $default    The value to return if the site option does not exist
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1432
		 *                           in the database.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1433
		 * @param string $option     Option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1434
		 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1435
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1436
		return apply_filters( "default_site_option_{$option}", $default, $option, $network_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1437
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
	if ( ! is_multisite() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1440
		/** This filter is documented in wp-includes/option.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1441
		$default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1442
		$value   = get_option( $option, $default );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
	} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1444
		$cache_key = "$network_id:$option";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1445
		$value     = wp_cache_get( $cache_key, 'site-options' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1447
		if ( ! isset( $value ) || false === $value ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1448
			$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1450
			// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
			if ( is_object( $row ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
				$value = $row->meta_value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
				$value = maybe_unserialize( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
				wp_cache_set( $cache_key, $value, 'site-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
			} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1456
				if ( ! is_array( $notoptions ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1457
					$notoptions = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1458
				}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1459
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1460
				$notoptions[ $option ] = true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
				wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1462
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1463
				/** This filter is documented in wp-includes/option.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1464
				$value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1469
	if ( ! is_array( $notoptions ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1470
		$notoptions = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1471
		wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1472
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1473
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1475
	 * Filters the value of an existing network option.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1478
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
	 * @since 2.9.0 As 'site_option_' . $key
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1481
	 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1482
	 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1484
	 * @param mixed  $value      Value of network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1485
	 * @param string $option     Option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1486
	 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1488
	return apply_filters( "site_option_{$option}", $value, $option, $network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1492
 * Adds a new network option.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1494
 * Existing options will not be updated.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1496
 * @since 4.4.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
 * @see add_option()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1500
 * @global wpdb $wpdb WordPress database abstraction object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1501
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1502
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1503
 * @param string $option     Name of the option to add. Expected to not be SQL-escaped.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1504
 * @param mixed  $value      Option value, can be anything. Expected to not be SQL-escaped.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1505
 * @return bool True if the option was added, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1507
function add_network_option( $network_id, $option, $value ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1510
	if ( $network_id && ! is_numeric( $network_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1511
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1512
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1513
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1514
	$network_id = (int) $network_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1515
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1516
	// Fallback to the current network if a network ID is not specified.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1517
	if ( ! $network_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1518
		$network_id = get_current_network_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1519
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1520
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
	wp_protect_special_option( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1523
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1524
	 * Filters the value of a specific network option before it is added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1525
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1526
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1527
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1528
	 * @since 2.9.0 As 'pre_add_site_option_' . $key
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1529
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1530
	 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1531
	 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1532
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1533
	 * @param mixed  $value      Value of network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1534
	 * @param string $option     Option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1535
	 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1536
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1537
	$value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1539
	$notoptions_key = "$network_id:notoptions";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1540
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1541
	if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1542
		$result = add_option( $option, $value, '', 'no' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
	} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1544
		$cache_key = "$network_id:$option";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1546
		// Make sure the option doesn't already exist.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1547
		// We can check the 'notoptions' cache before we ask for a DB query.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1548
		$notoptions = wp_cache_get( $notoptions_key, 'site-options' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1549
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1550
		if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1551
			if ( false !== get_network_option( $network_id, $option, false ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
				return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1553
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1554
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
		$value = sanitize_option( $option, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
		$serialized_value = maybe_serialize( $value );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1559
		$result           = $wpdb->insert(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1560
			$wpdb->sitemeta,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1561
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1562
				'site_id'    => $network_id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1563
				'meta_key'   => $option,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1564
				'meta_value' => $serialized_value,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1565
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1566
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1568
		if ( ! $result ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
			return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1570
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
		wp_cache_set( $cache_key, $value, 'site-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1574
		// This option exists now.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1575
		$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // Yes, again... we need it to be fresh.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1576
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1577
		if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1578
			unset( $notoptions[ $option ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1579
			wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
	if ( $result ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1584
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1585
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1586
		 * Fires after a specific network option has been successfully added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1587
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1588
		 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1589
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1590
		 * @since 2.9.0 As "add_site_option_{$key}"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1591
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1592
		 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1593
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1594
		 * @param string $option     Name of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1595
		 * @param mixed  $value      Value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1596
		 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1597
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1598
		do_action( "add_site_option_{$option}", $option, $value, $network_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1599
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1600
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1601
		 * Fires after a network option has been successfully added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1602
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1603
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1604
		 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1605
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1606
		 * @param string $option     Name of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1607
		 * @param mixed  $value      Value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1608
		 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1609
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1610
		do_action( 'add_site_option', $option, $value, $network_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1611
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1614
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1619
 * Removes a network option by name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1621
 * @since 4.4.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1623
 * @see delete_option()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1625
 * @global wpdb $wpdb WordPress database abstraction object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1626
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1627
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1628
 * @param string $option     Name of the option to delete. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1629
 * @return bool True if the option was deleted, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1631
function delete_network_option( $network_id, $option ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1634
	if ( $network_id && ! is_numeric( $network_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1635
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1636
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1637
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1638
	$network_id = (int) $network_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1639
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1640
	// Fallback to the current network if a network ID is not specified.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1641
	if ( ! $network_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1642
		$network_id = get_current_network_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1643
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1645
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1646
	 * Fires immediately before a specific network option is deleted.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1647
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1648
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1649
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1650
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1651
	 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1652
	 * @since 4.7.0 The `$network_id` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1653
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1654
	 * @param string $option     Option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1655
	 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1656
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1657
	do_action( "pre_delete_site_option_{$option}", $option, $network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1659
	if ( ! is_multisite() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
		$result = delete_option( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
	} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1662
		$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1663
		if ( is_null( $row ) || ! $row->meta_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
			return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1665
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1666
		$cache_key = "$network_id:$option";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
		wp_cache_delete( $cache_key, 'site-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1669
		$result = $wpdb->delete(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1670
			$wpdb->sitemeta,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1671
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1672
				'meta_key' => $option,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1673
				'site_id'  => $network_id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1674
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1675
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
	if ( $result ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1679
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1680
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1681
		 * Fires after a specific network option has been deleted.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1682
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1683
		 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1684
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1685
		 * @since 2.9.0 As "delete_site_option_{$key}"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1686
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1687
		 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1688
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1689
		 * @param string $option     Name of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1690
		 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1691
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1692
		do_action( "delete_site_option_{$option}", $option, $network_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1693
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1694
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1695
		 * Fires after a network option has been deleted.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1696
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1697
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1698
		 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1699
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1700
		 * @param string $option     Name of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1701
		 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1702
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1703
		do_action( 'delete_site_option', $option, $network_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1704
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1707
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1712
 * Updates the value of a network option that was already added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1714
 * @since 4.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1715
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
 * @see update_option()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1718
 * @global wpdb $wpdb WordPress database abstraction object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1719
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1720
 * @param int    $network_id ID of the network. Can be null to default to the current network ID.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1721
 * @param string $option     Name of the option. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1722
 * @param mixed  $value      Option value. Expected to not be SQL-escaped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1723
 * @return bool True if the value was updated, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1725
function update_network_option( $network_id, $option, $value ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1728
	if ( $network_id && ! is_numeric( $network_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1729
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1730
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1731
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1732
	$network_id = (int) $network_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1733
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1734
	// Fallback to the current network if a network ID is not specified.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1735
	if ( ! $network_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1736
		$network_id = get_current_network_id();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1737
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1738
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
	wp_protect_special_option( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1741
	$old_value = get_network_option( $network_id, $option, false );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1742
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1743
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1744
	 * Filters a specific network option before its value is updated.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1745
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1746
	 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1747
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1748
	 * @since 2.9.0 As 'pre_update_site_option_' . $key
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1749
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1750
	 * @since 4.4.0 The `$option` parameter was added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1751
	 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1752
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1753
	 * @param mixed  $value      New value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1754
	 * @param mixed  $old_value  Old value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1755
	 * @param string $option     Option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1756
	 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1757
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1758
	$value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1760
	/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1761
	 * If the new and old values are the same, no need to update.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1762
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1763
	 * Unserialized values will be adequate in most cases. If the unserialized
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1764
	 * data differs, the (maybe) serialized data is checked to avoid
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1765
	 * unnecessary database calls for otherwise identical object instances.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1766
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1767
	 * See https://core.trac.wordpress.org/ticket/44956
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1768
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1769
	if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1771
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1773
	if ( false === $old_value ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1774
		return add_network_option( $network_id, $option, $value );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1775
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1776
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1777
	$notoptions_key = "$network_id:notoptions";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1778
	$notoptions     = wp_cache_get( $notoptions_key, 'site-options' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1779
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1780
	if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1781
		unset( $notoptions[ $option ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1782
		wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1785
	if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1786
		$result = update_option( $option, $value, 'no' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
		$value = sanitize_option( $option, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
		$serialized_value = maybe_serialize( $value );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1791
		$result           = $wpdb->update(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1792
			$wpdb->sitemeta,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1793
			array( 'meta_value' => $serialized_value ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1794
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1795
				'site_id'  => $network_id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1796
				'meta_key' => $option,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1797
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1798
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
		if ( $result ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1801
			$cache_key = "$network_id:$option";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
			wp_cache_set( $cache_key, $value, 'site-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
	if ( $result ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1807
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1808
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1809
		 * Fires after the value of a specific network option has been successfully updated.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1810
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1811
		 * The dynamic portion of the hook name, `$option`, refers to the option name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1812
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1813
		 * @since 2.9.0 As "update_site_option_{$key}"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1814
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1815
		 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1816
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1817
		 * @param string $option     Name of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1818
		 * @param mixed  $value      Current value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1819
		 * @param mixed  $old_value  Old value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1820
		 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1821
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1822
		do_action( "update_site_option_{$option}", $option, $value, $old_value, $network_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1823
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1824
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1825
		 * Fires after the value of a network option has been successfully updated.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1826
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1827
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1828
		 * @since 4.7.0 The `$network_id` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1829
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1830
		 * @param string $option     Name of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1831
		 * @param mixed  $value      Current value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1832
		 * @param mixed  $old_value  Old value of the network option.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1833
		 * @param int    $network_id ID of the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1834
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1835
		do_action( 'update_site_option', $option, $value, $old_value, $network_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1836
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1839
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1840
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1844
 * Deletes a site transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
 * @param string $transient Transient name. Expected to not be SQL-escaped.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1849
 * @return bool True if the transient was deleted, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
function delete_site_transient( $transient ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1852
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1853
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1854
	 * Fires immediately before a specific site transient is deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1855
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1856
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1857
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1858
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1859
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1860
	 * @param string $transient Transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1861
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1862
	do_action( "delete_site_transient_{$transient}", $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1863
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1864
	if ( wp_using_ext_object_cache() || wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
		$result = wp_cache_delete( $transient, 'site-transient' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
		$option_timeout = '_site_transient_timeout_' . $transient;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1868
		$option         = '_site_transient_' . $transient;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1869
		$result         = delete_site_option( $option );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1870
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1871
		if ( $result ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
			delete_site_option( $option_timeout );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1873
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1875
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1876
	if ( $result ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1877
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1878
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1879
		 * Fires after a transient is deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1880
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1881
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1882
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1883
		 * @param string $transient Deleted transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1884
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
		do_action( 'deleted_site_transient', $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1886
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1887
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1892
 * Retrieves the value of a site transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1894
 * If the transient does not exist, does not have a value, or has expired,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1895
 * then the return value will be false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1896
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1897
 * @since 2.9.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
 * @see get_transient()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
 * @param string $transient Transient name. Expected to not be SQL-escaped.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1902
 * @return mixed Value of transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
function get_site_transient( $transient ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1905
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1906
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1907
	 * Filters the value of an existing site transient before it is retrieved.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1908
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1909
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1910
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1911
	 * Returning a truthy value from the filter will effectively short-circuit retrieval
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1912
	 * and return the passed value instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1913
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1914
	 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1915
	 * @since 4.4.0 The `$transient` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1916
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1917
	 * @param mixed  $pre_site_transient The default value to return if the site transient does not exist.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1918
	 *                                   Any value other than false will short-circuit the retrieval
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1919
	 *                                   of the transient, and return that value.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1920
	 * @param string $transient          Transient name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1921
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1922
	$pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1923
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1924
	if ( false !== $pre ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
		return $pre;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1926
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1927
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1928
	if ( wp_using_ext_object_cache() || wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
		$value = wp_cache_get( $transient, 'site-transient' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
		// Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1932
		$no_timeout       = array( 'update_core', 'update_plugins', 'update_themes' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
		$transient_option = '_site_transient_' . $transient;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1934
		if ( ! in_array( $transient, $no_timeout, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
			$transient_timeout = '_site_transient_timeout_' . $transient;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1936
			$timeout           = get_site_option( $transient_timeout );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
			if ( false !== $timeout && $timeout < time() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1938
				delete_site_option( $transient_option );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
				delete_site_option( $transient_timeout );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
				$value = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1944
		if ( ! isset( $value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
			$value = get_site_option( $transient_option );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1946
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1949
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1950
	 * Filters the value of an existing site transient.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1951
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1952
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1953
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1954
	 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1955
	 * @since 4.4.0 The `$transient` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1956
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1957
	 * @param mixed  $value     Value of site transient.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1958
	 * @param string $transient Transient name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1959
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1960
	return apply_filters( "site_transient_{$transient}", $value, $transient );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1964
 * Sets/updates the value of a site transient.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1966
 * You do not need to serialize values. If the value needs to be serialized,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1967
 * then it will be serialized before it is set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1969
 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1970
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
 * @see set_transient()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1973
 * @param string $transient  Transient name. Expected to not be SQL-escaped. Must be
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1974
 *                           167 characters or fewer in length.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1975
 * @param mixed  $value      Transient value. Expected to not be SQL-escaped.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1976
 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1977
 * @return bool True if the value was set, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
function set_site_transient( $transient, $value, $expiration = 0 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1980
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1981
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1982
	 * Filters the value of a specific site transient before it is set.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1983
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1984
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1985
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1986
	 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1987
	 * @since 4.4.0 The `$transient` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1988
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1989
	 * @param mixed  $value     New value of site transient.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1990
	 * @param string $transient Transient name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1991
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1992
	$value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1993
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
	$expiration = (int) $expiration;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1996
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1997
	 * Filters the expiration for a site transient before its value is set.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1998
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1999
	 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2000
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2001
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2002
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2003
	 * @param int    $expiration Time until expiration in seconds. Use 0 for no expiration.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2004
	 * @param mixed  $value      New value of site transient.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2005
	 * @param string $transient  Transient name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2006
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2007
	$expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2008
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2009
	if ( wp_using_ext_object_cache() || wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
		$result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
		$transient_timeout = '_site_transient_timeout_' . $transient;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2013
		$option            = '_site_transient_' . $transient;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2014
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
		if ( false === get_site_option( $option ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2016
			if ( $expiration ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
				add_site_option( $transient_timeout, time() + $expiration );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2018
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
			$result = add_site_option( $option, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
		} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2021
			if ( $expiration ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
				update_site_option( $transient_timeout, time() + $expiration );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2023
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
			$result = update_site_option( $option, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2027
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
	if ( $result ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2029
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2030
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2031
		 * Fires after the value for a specific site transient has been set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2032
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2033
		 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2034
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2035
		 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2036
		 * @since 4.4.0 The `$transient` parameter was added
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2037
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2038
		 * @param mixed  $value      Site transient value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2039
		 * @param int    $expiration Time until expiration in seconds.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2040
		 * @param string $transient  Transient name.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2041
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2042
		do_action( "set_site_transient_{$transient}", $value, $expiration, $transient );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2043
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2044
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2045
		 * Fires after the value for a site transient has been set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2046
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2047
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2048
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2049
		 * @param string $transient  The name of the site transient.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2050
		 * @param mixed  $value      Site transient value.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2051
		 * @param int    $expiration Time until expiration in seconds.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2052
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
		do_action( 'setted_site_transient', $transient, $value, $expiration );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2055
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2058
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2059
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2060
 * Registers default settings available in WordPress.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2061
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2062
 * The settings registered here are primarily useful for the REST API, so this
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2063
 * does not encompass all settings available in WordPress.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2064
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2065
 * @since 4.7.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2066
 * @since 6.0.1 The `show_on_front`, `page_on_front`, and `page_for_posts` options were added.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2067
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2068
function register_initial_settings() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2069
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2070
		'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2071
		'blogname',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2072
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2073
			'show_in_rest' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2074
				'name' => 'title',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2075
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2076
			'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2077
			'description'  => __( 'Site title.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2078
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2079
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2080
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2081
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2082
		'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2083
		'blogdescription',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2084
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2085
			'show_in_rest' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2086
				'name' => 'description',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2087
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2088
			'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2089
			'description'  => __( 'Site tagline.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2090
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2091
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2092
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2093
	if ( ! is_multisite() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2094
		register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2095
			'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2096
			'siteurl',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2097
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2098
				'show_in_rest' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2099
					'name'   => 'url',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2100
					'schema' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2101
						'format' => 'uri',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2102
					),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2103
				),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2104
				'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2105
				'description'  => __( 'Site URL.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2106
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2107
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2108
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2109
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2110
	if ( ! is_multisite() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2111
		register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2112
			'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2113
			'admin_email',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2114
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2115
				'show_in_rest' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2116
					'name'   => 'email',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2117
					'schema' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2118
						'format' => 'email',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2119
					),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2120
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2121
				'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2122
				'description'  => __( 'This address is used for admin purposes, like new user notification.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2123
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2124
		);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2125
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2126
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2127
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2128
		'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2129
		'timezone_string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2130
		array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2131
			'show_in_rest' => array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2132
				'name' => 'timezone',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2133
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2134
			'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2135
			'description'  => __( 'A city in the same timezone as you.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2136
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2137
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2138
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2139
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2140
		'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2141
		'date_format',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2142
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2143
			'show_in_rest' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2144
			'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2145
			'description'  => __( 'A date format for all date strings.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2146
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2147
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2148
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2149
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2150
		'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2151
		'time_format',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2152
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2153
			'show_in_rest' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2154
			'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2155
			'description'  => __( 'A time format for all time strings.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2156
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2157
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2158
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2159
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2160
		'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2161
		'start_of_week',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2162
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2163
			'show_in_rest' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2164
			'type'         => 'integer',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2165
			'description'  => __( 'A day number of the week that the week should start on.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2166
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2167
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2168
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2169
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2170
		'general',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2171
		'WPLANG',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2172
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2173
			'show_in_rest' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2174
				'name' => 'language',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2175
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2176
			'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2177
			'description'  => __( 'WordPress locale code.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2178
			'default'      => 'en_US',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2179
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2180
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2181
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2182
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2183
		'writing',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2184
		'use_smilies',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2185
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2186
			'show_in_rest' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2187
			'type'         => 'boolean',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2188
			'description'  => __( 'Convert emoticons like :-) and :-P to graphics on display.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2189
			'default'      => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2190
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2191
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2192
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2193
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2194
		'writing',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2195
		'default_category',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2196
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2197
			'show_in_rest' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2198
			'type'         => 'integer',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2199
			'description'  => __( 'Default post category.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2200
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2201
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2202
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2203
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2204
		'writing',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2205
		'default_post_format',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2206
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2207
			'show_in_rest' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2208
			'type'         => 'string',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2209
			'description'  => __( 'Default post format.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2210
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2211
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2212
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2213
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2214
		'reading',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2215
		'posts_per_page',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2216
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2217
			'show_in_rest' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2218
			'type'         => 'integer',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2219
			'description'  => __( 'Blog pages show at most.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2220
			'default'      => 10,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2221
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2222
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2223
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2224
	register_setting(
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2225
		'reading',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2226
		'show_on_front',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2227
		array(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2228
			'show_in_rest' => true,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2229
			'type'         => 'string',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2230
			'description'  => __( 'What to show on the front page' ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2231
		)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2232
	);
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2233
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2234
	register_setting(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2235
		'reading',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2236
		'page_on_front',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2237
		array(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2238
			'show_in_rest' => true,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2239
			'type'         => 'integer',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2240
			'description'  => __( 'The ID of the page that should be displayed on the front page' ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2241
		)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2242
	);
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2243
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2244
	register_setting(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2245
		'reading',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2246
		'page_for_posts',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2247
		array(
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2248
			'show_in_rest' => true,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2249
			'type'         => 'integer',
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2250
			'description'  => __( 'The ID of the page that should display the latest posts' ),
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2251
		)
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2252
	);
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2253
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2254
	register_setting(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2255
		'discussion',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2256
		'default_ping_status',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2257
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2258
			'show_in_rest' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2259
				'schema' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2260
					'enum' => array( 'open', 'closed' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2261
				),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2262
			),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2263
			'type'         => 'string',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2264
			'description'  => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2265
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2266
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2267
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2268
	register_setting(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2269
		'discussion',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2270
		'default_comment_status',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2271
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2272
			'show_in_rest' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2273
				'schema' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2274
					'enum' => array( 'open', 'closed' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2275
				),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2276
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2277
			'type'         => 'string',
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2278
			'description'  => __( 'Allow people to submit comments on new posts.' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2279
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2280
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2281
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2282
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2283
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2284
 * Registers a setting and its data.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2285
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2286
 * @since 2.7.0
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2287
 * @since 3.0.0 The `misc` option group was deprecated.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2288
 * @since 3.5.0 The `privacy` option group was deprecated.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2289
 * @since 4.7.0 `$args` can be passed to set flags on the setting, similar to `register_meta()`.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2290
 * @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2291
 *              Please consider writing more inclusive code.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2292
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2293
 * @global array $new_allowed_options
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2294
 * @global array $wp_registered_settings
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2295
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2296
 * @param string $option_group A settings group name. Should correspond to an allowed option key name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2297
 *                             Default allowed option key names include 'general', 'discussion', 'media',
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2298
 *                             'reading', 'writing', and 'options'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2299
 * @param string $option_name The name of an option to sanitize and save.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2300
 * @param array  $args {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2301
 *     Data used to describe the setting when registered.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2302
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2303
 *     @type string     $type              The type of data associated with this setting.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2304
 *                                         Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2305
 *     @type string     $description       A description of the data attached to this setting.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2306
 *     @type callable   $sanitize_callback A callback function that sanitizes the option's value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2307
 *     @type bool|array $show_in_rest      Whether data associated with this setting should be included in the REST API.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2308
 *                                         When registering complex settings, this argument may optionally be an
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2309
 *                                         array with a 'schema' key.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2310
 *     @type mixed      $default           Default value when calling `get_option()`.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2311
 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2312
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2313
function register_setting( $option_group, $option_name, $args = array() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2314
	global $new_allowed_options, $wp_registered_settings;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2315
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2316
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2317
	 * In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2318
	 * Please consider writing more inclusive code.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2319
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2320
	$GLOBALS['new_whitelist_options'] = &$new_allowed_options;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2321
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2322
	$defaults = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2323
		'type'              => 'string',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2324
		'group'             => $option_group,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2325
		'description'       => '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2326
		'sanitize_callback' => null,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2327
		'show_in_rest'      => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2328
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2329
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2330
	// Back-compat: old sanitize callback is added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2331
	if ( is_callable( $args ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2332
		$args = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2333
			'sanitize_callback' => $args,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2334
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2335
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2336
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2337
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2338
	 * Filters the registration arguments when registering a setting.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2339
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2340
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2341
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2342
	 * @param array  $args         Array of setting registration arguments.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2343
	 * @param array  $defaults     Array of default arguments.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2344
	 * @param string $option_group Setting group.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2345
	 * @param string $option_name  Setting name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2346
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2347
	$args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2348
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2349
	$args = wp_parse_args( $args, $defaults );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2350
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2351
	// Require an item schema when registering settings with an array type.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2352
	if ( false !== $args['show_in_rest'] && 'array' === $args['type'] && ( ! is_array( $args['show_in_rest'] ) || ! isset( $args['show_in_rest']['schema']['items'] ) ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2353
		_doing_it_wrong( __FUNCTION__, __( 'When registering an "array" setting to show in the REST API, you must specify the schema for each array item in "show_in_rest.schema.items".' ), '5.4.0' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2354
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2355
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2356
	if ( ! is_array( $wp_registered_settings ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2357
		$wp_registered_settings = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2358
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2359
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2360
	if ( 'misc' === $option_group ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2361
		_deprecated_argument(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2362
			__FUNCTION__,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2363
			'3.0.0',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2364
			sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2365
				/* translators: %s: misc */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2366
				__( 'The "%s" options group has been removed. Use another settings group.' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2367
				'misc'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2368
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2369
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2370
		$option_group = 'general';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2371
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2372
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2373
	if ( 'privacy' === $option_group ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2374
		_deprecated_argument(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2375
			__FUNCTION__,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2376
			'3.5.0',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2377
			sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2378
				/* translators: %s: privacy */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2379
				__( 'The "%s" options group has been removed. Use another settings group.' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2380
				'privacy'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2381
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2382
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2383
		$option_group = 'reading';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2384
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2385
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2386
	$new_allowed_options[ $option_group ][] = $option_name;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2387
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2388
	if ( ! empty( $args['sanitize_callback'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2389
		add_filter( "sanitize_option_{$option_name}", $args['sanitize_callback'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2390
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2391
	if ( array_key_exists( 'default', $args ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2392
		add_filter( "default_option_{$option_name}", 'filter_default_option', 10, 3 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2393
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2394
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2395
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2396
	 * Fires immediately before the setting is registered but after its filters are in place.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2397
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2398
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2399
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2400
	 * @param string $option_group Setting group.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2401
	 * @param string $option_name  Setting name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2402
	 * @param array  $args         Array of setting registration arguments.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2403
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2404
	do_action( 'register_setting', $option_group, $option_name, $args );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2405
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2406
	$wp_registered_settings[ $option_name ] = $args;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2407
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2408
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2409
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2410
 * Unregisters a setting.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2411
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2412
 * @since 2.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2413
 * @since 4.7.0 `$sanitize_callback` was deprecated. The callback from `register_setting()` is now used instead.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2414
 * @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2415
 *              Please consider writing more inclusive code.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2416
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2417
 * @global array $new_allowed_options
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2418
 * @global array $wp_registered_settings
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2419
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2420
 * @param string   $option_group The settings group name used during registration.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2421
 * @param string   $option_name  The name of the option to unregister.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  2422
 * @param callable $deprecated   Optional. Deprecated.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2423
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2424
function unregister_setting( $option_group, $option_name, $deprecated = '' ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2425
	global $new_allowed_options, $wp_registered_settings;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2426
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2427
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2428
	 * In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2429
	 * Please consider writing more inclusive code.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2430
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2431
	$GLOBALS['new_whitelist_options'] = &$new_allowed_options;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2432
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2433
	if ( 'misc' === $option_group ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2434
		_deprecated_argument(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2435
			__FUNCTION__,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2436
			'3.0.0',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2437
			sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2438
				/* translators: %s: misc */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2439
				__( 'The "%s" options group has been removed. Use another settings group.' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2440
				'misc'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2441
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2442
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2443
		$option_group = 'general';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2444
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2445
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2446
	if ( 'privacy' === $option_group ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2447
		_deprecated_argument(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2448
			__FUNCTION__,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2449
			'3.5.0',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2450
			sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2451
				/* translators: %s: privacy */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2452
				__( 'The "%s" options group has been removed. Use another settings group.' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2453
				'privacy'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2454
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2455
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2456
		$option_group = 'reading';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2457
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2458
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2459
	$pos = array_search( $option_name, (array) $new_allowed_options[ $option_group ], true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2460
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2461
	if ( false !== $pos ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2462
		unset( $new_allowed_options[ $option_group ][ $pos ] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2463
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2464
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2465
	if ( '' !== $deprecated ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2466
		_deprecated_argument(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2467
			__FUNCTION__,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2468
			'4.7.0',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2469
			sprintf(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2470
				/* translators: 1: $sanitize_callback, 2: register_setting() */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2471
				__( '%1$s is deprecated. The callback from %2$s is used instead.' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2472
				'<code>$sanitize_callback</code>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2473
				'<code>register_setting()</code>'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2474
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2475
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2476
		remove_filter( "sanitize_option_{$option_name}", $deprecated );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2477
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2478
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2479
	if ( isset( $wp_registered_settings[ $option_name ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2480
		// Remove the sanitize callback if one was set during registration.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2481
		if ( ! empty( $wp_registered_settings[ $option_name ]['sanitize_callback'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2482
			remove_filter( "sanitize_option_{$option_name}", $wp_registered_settings[ $option_name ]['sanitize_callback'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2483
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2484
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2485
		// Remove the default filter if a default was provided during registration.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2486
		if ( array_key_exists( 'default', $wp_registered_settings[ $option_name ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2487
			remove_filter( "default_option_{$option_name}", 'filter_default_option', 10 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2488
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2489
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2490
		/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2491
		 * Fires immediately before the setting is unregistered and after its filters have been removed.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2492
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2493
		 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2494
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2495
		 * @param string $option_group Setting group.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2496
		 * @param string $option_name  Setting name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2497
		 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2498
		do_action( 'unregister_setting', $option_group, $option_name );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2499
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2500
		unset( $wp_registered_settings[ $option_name ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2501
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2502
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2503
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2504
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2505
 * Retrieves an array of registered settings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2506
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2507
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2508
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2509
 * @global array $wp_registered_settings
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2510
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2511
 * @return array List of registered settings, keyed by option name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2512
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2513
function get_registered_settings() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2514
	global $wp_registered_settings;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2515
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2516
	if ( ! is_array( $wp_registered_settings ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2517
		return array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2518
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2519
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2520
	return $wp_registered_settings;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2521
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2522
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2523
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2524
 * Filters the default value for the option.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2525
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2526
 * For settings which register a default setting in `register_setting()`, this
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2527
 * function is added as a filter to `default_option_{$option}`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2528
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2529
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2530
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2531
 * @param mixed  $default        Existing default value to return.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2532
 * @param string $option         Option name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2533
 * @param bool   $passed_default Was `get_option()` passed a default value?
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2534
 * @return mixed Filtered default value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2535
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2536
function filter_default_option( $default, $option, $passed_default ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2537
	if ( $passed_default ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2538
		return $default;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2539
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2540
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2541
	$registered = get_registered_settings();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2542
	if ( empty( $registered[ $option ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2543
		return $default;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2544
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2545
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2546
	return $registered[ $option ]['default'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2547
}