|
7 | 7 | <![CDATA[
|
8 | 8 | When using `add_option()`, `update_option()`, `wp_set_options_autoload()`,
|
9 | 9 | `wp_set_option_autoload()`, or `wp_set_option_autoload_values()`, it is recommended to
|
10 |
| - explicitly set the autoload parameter to ensure predictable behavior. This parameter determines whether |
11 |
| - the option is automatically loaded on every page load, which can impact site performance. |
| 10 | + explicitly set the autoload parameter to ensure predictable behavior. This parameter determines |
| 11 | + whether the option is automatically loaded on every page load, which can impact site performance. |
12 | 12 | ]]>
|
13 | 13 | </standard>
|
14 | 14 | <standard>
|
15 | 15 | <![CDATA[
|
16 |
| - Even though the autoload parameter is optional for `add_option()` and `update_option()`, it is |
17 |
| - recommended to always explicitly set it. |
| 16 | + The following values should be used when setting the autoload parameter depending on the function: |
| 17 | +
|
| 18 | + - For `add_option()` and `update_option()`: `true`, `false`, or `null`. |
| 19 | + - For `wp_set_option_autoload_values()`, `wp_set_option_autoload()`, and |
| 20 | + `wp_set_options_autoload()`: `true` or `false`. |
| 21 | +
|
| 22 | + Using 'yes' or 'no' is deprecated since WordPress 6.6.0. Using 'auto', 'auto-on', 'auto-off', |
| 23 | + 'on', or 'off' in plugin/theme code is strongly discouraged as those values are meant for |
| 24 | + internal-use only. |
| 25 | +
|
| 26 | + Any other values, including `null` for functions other than `add_option()` and `update_option()` |
| 27 | + are invalid. |
18 | 28 | ]]>
|
19 | 29 | </standard>
|
20 | 30 | <code_comparison>
|
21 |
| - <code title="Valid: Explicitly setting the autoload parameter."> |
| 31 | + <code title="Valid: Using a boolean value or `null`"> |
22 | 32 | <![CDATA[
|
23 | 33 | add_option(
|
24 | 34 | 'my_option',
|
25 | 35 | 'value',
|
26 | 36 | '',
|
27 | 37 | <em>true</em>
|
28 | 38 | );
|
29 |
| - ]]> |
30 |
| - </code> |
31 |
| - <code title="Invalid: Autoload parameter missing."> |
32 |
| - <![CDATA[ |
33 |
| -add_option( |
34 |
| - 'my_option', |
35 |
| - 'value', |
36 |
| - '' |
37 |
| -); |
38 |
| - ]]> |
39 |
| - </code> |
40 |
| - </code_comparison> |
41 |
| - <standard> |
42 |
| - <![CDATA[ |
43 |
| - When calling the `add_option()` or `update_option()` functions, use `true`, `false` or `null` |
44 |
| - as the value for the autoload parameter. For the `wp_set_option_autoload_values()`, |
45 |
| - `wp_set_option_autoload()`, or `wp_set_options_autoload()` functions, use `true` or `false`. |
46 | 39 |
|
47 |
| - Using 'yes' or 'no' as the value for the autoload parameter is deprecated since WordPress 6.6.0. |
48 |
| - ]]> |
49 |
| - </standard> |
50 |
| - <code_comparison> |
51 |
| - <code title="Valid: Using a boolean value."> |
52 |
| - <![CDATA[ |
53 | 40 | update_option(
|
54 | 41 | 'my_option',
|
55 | 42 | 'value',
|
56 |
| - <em>true</em> |
| 43 | + <em>null</em> |
57 | 44 | );
|
58 | 45 | ]]>
|
59 | 46 | </code>
|
60 |
| - <code title="Invalid: Using a deprecated value."> |
| 47 | + <code title="Invalid: Using deprecated, internal-only, or invalid values"> |
61 | 48 | <![CDATA[
|
62 |
| -update_option( |
| 49 | +add_option( |
63 | 50 | 'my_option',
|
64 | 51 | 'value',
|
| 52 | + '', |
65 | 53 | <em>'yes'</em>
|
66 | 54 | );
|
67 |
| - ]]> |
68 |
| - </code> |
69 |
| - </code_comparison> |
70 |
| - <standard> |
71 |
| - <![CDATA[ |
72 |
| - Use `true`|`false`|`null` if using `add_option()` or `update_option()` or `true`|`false` if |
73 |
| - using `wp_set_option_autoload_values()`, `wp_set_option_autoload()`, or |
74 |
| - `wp_set_options_autoload()`. It is strongly discouraged to use internal-only values ('auto', |
75 |
| - 'auto-on', 'auto-off', 'on', 'off') in plugin or theme code. |
76 |
| - ]]> |
77 |
| - </standard> |
78 |
| - <code_comparison> |
79 |
| - <code title="Valid: Using boolean values."> |
80 |
| - <![CDATA[ |
81 |
| -wp_set_option_autoload_values( |
82 |
| - array( |
83 |
| - 'my_option_1' => <em>true</em>, |
84 |
| - 'my_option_2' => <em>false</em> |
85 |
| - ) |
| 55 | +
|
| 56 | +wp_set_option_autoload( |
| 57 | + 'my_option', |
| 58 | + <em>null</em> |
86 | 59 | );
|
87 |
| - ]]> |
88 |
| - </code> |
89 |
| - <code title="Invalid: Using internal-only values."> |
90 |
| - <![CDATA[ |
| 60 | +
|
91 | 61 | wp_set_option_autoload_values(
|
92 | 62 | array(
|
93 |
| - 'my_option_1' => <em>'auto-on'</em>, |
94 |
| - 'my_option_2' => <em>'auto-off'</em> |
| 63 | + 'option1' => <em>'auto-on'</em>, |
| 64 | + 'option2' => <em>'off'</em> |
95 | 65 | )
|
96 | 66 | );
|
| 67 | +
|
| 68 | +wp_set_options_autoload( |
| 69 | + array('option1', 'option2'), |
| 70 | + <em>1</em> |
| 71 | +); |
97 | 72 | ]]>
|
98 | 73 | </code>
|
99 | 74 | </code_comparison>
|
100 | 75 | <standard>
|
101 | 76 | <![CDATA[
|
102 |
| - Only `true` and `false` are valid values for the autoload parameter, with one exception: `null` |
103 |
| - is also valid for `add_option()` and `update_option()`. |
| 77 | + Even though the autoload parameter is optional for `add_option()` and `update_option()`, it is |
| 78 | + recommended to always explicitly set it. |
104 | 79 | ]]>
|
105 | 80 | </standard>
|
106 | 81 | <code_comparison>
|
107 |
| - <code title="Valid: Using `true`, `false`, or `null`."> |
| 82 | + <code title="Valid: Explicitly setting the autoload parameter."> |
108 | 83 | <![CDATA[
|
109 |
| -wp_set_options_autoload( |
110 |
| - array( 'my_option_1', 'my_option_2' ), |
111 |
| - <em>false</em> |
112 |
| -); |
113 |
| -
|
114 |
| -wp_set_option_autoload( |
| 84 | +add_option( |
115 | 85 | 'my_option',
|
| 86 | + 'value', |
| 87 | + '', |
116 | 88 | <em>true</em>
|
117 | 89 | );
|
118 | 90 | ]]>
|
119 | 91 | </code>
|
120 |
| - <code title="Invalid: Using invalid values."> |
| 92 | + <code title="Invalid: Autoload parameter missing."> |
121 | 93 | <![CDATA[
|
122 |
| -wp_set_options_autoload( |
123 |
| - array( 'my_option_1', 'my_option_2' ), |
124 |
| - <em>1</em> |
125 |
| -); |
126 |
| -
|
127 |
| -wp_set_option_autoload( |
| 94 | +add_option( |
128 | 95 | 'my_option',
|
129 |
| - <em>null</em> // `null` is invalid for this function. |
| 96 | + 'value', |
| 97 | + '' |
130 | 98 | );
|
131 | 99 | ]]>
|
132 | 100 | </code>
|
|
0 commit comments