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.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / includes / acf-hook-functions.php
advanced-custom-fields / includes Last commit date
admin 2 years ago ajax 3 years ago api 2 years ago fields 2 years ago forms 2 years ago legacy 4 years ago locations 3 years ago post-types 2 years ago rest-api 3 years ago walkers 2 years ago acf-bidirectional-functions.php 2 years ago acf-field-functions.php 3 years ago acf-field-group-functions.php 3 years ago acf-form-functions.php 3 years ago acf-helper-functions.php 2 years ago acf-hook-functions.php 4 years ago acf-input-functions.php 3 years ago acf-internal-post-type-functions.php 2 years ago acf-meta-functions.php 3 years ago acf-post-functions.php 4 years ago acf-post-type-functions.php 2 years ago acf-taxonomy-functions.php 3 years ago acf-user-functions.php 4 years ago acf-utility-functions.php 3 years ago acf-value-functions.php 2 years ago acf-wp-functions.php 2 years ago assets.php 2 years ago class-acf-data.php 3 years ago class-acf-internal-post-type.php 2 years ago compatibility.php 4 years ago deprecated.php 4 years ago fields.php 2 years ago l10n.php 3 years ago local-fields.php 2 years ago local-json.php 2 years ago local-meta.php 4 years ago locations.php 3 years ago loop.php 3 years ago media.php 3 years ago rest-api.php 4 years ago revisions.php 3 years ago third-party.php 3 years ago upgrades.php 3 years ago validation.php 2 years ago wpml.php 3 years ago
acf-hook-functions.php
224 lines
1 <?php
2
3 // Register store.
4 acf_register_store( 'hook-variations' );
5
6 /**
7 * acf_add_filter_variations
8 *
9 * Registers variations for the given filter.
10 *
11 * @date 26/1/19
12 * @since 5.7.11
13 *
14 * @param string $filter The filter name.
15 * @param array $variations An array variation keys.
16 * @param int $index The param index to find variation values.
17 * @return void
18 */
19 function acf_add_filter_variations( $filter = '', $variations = array(), $index = 0 ) {
20
21 // Store replacement data.
22 acf_get_store( 'hook-variations' )->set(
23 $filter,
24 array(
25 'type' => 'filter',
26 'variations' => $variations,
27 'index' => $index,
28 )
29 );
30
31 // Add generic handler.
32 // Use a priotiry of 10, and accepted args of 10 (ignored by WP).
33 add_filter( $filter, '_acf_apply_hook_variations', 10, 10 );
34 }
35
36 /**
37 * acf_add_action_variations
38 *
39 * Registers variations for the given action.
40 *
41 * @date 26/1/19
42 * @since 5.7.11
43 *
44 * @param string $action The action name.
45 * @param array $variations An array variation keys.
46 * @param int $index The param index to find variation values.
47 * @return void
48 */
49 function acf_add_action_variations( $action = '', $variations = array(), $index = 0 ) {
50
51 // Store replacement data.
52 acf_get_store( 'hook-variations' )->set(
53 $action,
54 array(
55 'type' => 'action',
56 'variations' => $variations,
57 'index' => $index,
58 )
59 );
60
61 // Add generic handler.
62 // Use a priotiry of 10, and accepted args of 10 (ignored by WP).
63 add_action( $action, '_acf_apply_hook_variations', 10, 10 );
64 }
65
66 /**
67 * _acf_apply_hook_variations
68 *
69 * Applies hook variations during apply_filters() or do_action().
70 *
71 * @date 25/1/19
72 * @since 5.7.11
73 *
74 * @param mixed
75 * @return mixed
76 */
77 function _acf_apply_hook_variations() {
78
79 // Get current filter.
80 $filter = current_filter();
81
82 // Get args provided.
83 $args = func_get_args();
84
85 // Get variation information.
86 $variations = acf_get_store( 'hook-variations' )->get( $filter );
87 $index = $variations['index'];
88 $type = $variations['type'];
89 $variations = $variations['variations'];
90
91 // Find field in args using index.
92 $field = $args[ $index ];
93
94 // Loop over variations and apply filters.
95 foreach ( $variations as $variation ) {
96
97 // Get value from field.
98 // First look for "backup" value ("_name", "_key").
99 if ( isset( $field[ "_$variation" ] ) ) {
100 $value = $field[ "_$variation" ];
101 } elseif ( isset( $field[ $variation ] ) ) {
102 $value = $field[ $variation ];
103 } else {
104 continue;
105 }
106
107 // Apply filters.
108 if ( $type === 'filter' ) {
109 $args[0] = apply_filters_ref_array( "$filter/$variation=$value", $args );
110
111 // Or do action.
112 } else {
113 do_action_ref_array( "$filter/$variation=$value", $args );
114 }
115 }
116
117 // Return first arg.
118 return $args[0];
119 }
120
121 // Register store.
122 acf_register_store( 'deprecated-hooks' );
123
124 /**
125 * acf_add_deprecated_filter
126 *
127 * Registers a deprecated filter to run during the replacement.
128 *
129 * @date 25/1/19
130 * @since 5.7.11
131 *
132 * @param string $deprecated The deprecated hook.
133 * @param string $version The version this hook was deprecated.
134 * @param string $replacement The replacement hook.
135 * @return void
136 */
137 function acf_add_deprecated_filter( $deprecated, $version, $replacement ) {
138
139 // Store replacement data.
140 acf_get_store( 'deprecated-hooks' )->append(
141 array(
142 'type' => 'filter',
143 'deprecated' => $deprecated,
144 'replacement' => $replacement,
145 'version' => $version,
146 )
147 );
148
149 // Add generic handler.
150 // Use a priority of 10, and accepted args of 10 (ignored by WP).
151 add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
152 }
153
154 /**
155 * acf_add_deprecated_action
156 *
157 * Registers a deprecated action to run during the replacement.
158 *
159 * @date 25/1/19
160 * @since 5.7.11
161 *
162 * @param string $deprecated The deprecated hook.
163 * @param string $version The version this hook was deprecated.
164 * @param string $replacement The replacement hook.
165 * @return void
166 */
167 function acf_add_deprecated_action( $deprecated, $version, $replacement ) {
168
169 // Store replacement data.
170 acf_get_store( 'deprecated-hooks' )->append(
171 array(
172 'type' => 'action',
173 'deprecated' => $deprecated,
174 'replacement' => $replacement,
175 'version' => $version,
176 )
177 );
178
179 // Add generic handler.
180 // Use a priority of 10, and accepted args of 10 (ignored by WP).
181 add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
182 }
183
184 /**
185 * Applies a deprecated filter during apply_filters() or do_action().
186 *
187 * @date 25/1/19
188 * @since 5.7.11
189 *
190 * @param mixed
191 * @return mixed
192 */
193 function _acf_apply_deprecated_hook() {
194 // Get current hook.
195 $current_hook = current_filter();
196
197 // Get args provided.
198 $args = func_get_args();
199
200 // Get deprecated items for this hook.
201 $deprecated_hooks = acf_get_store( 'deprecated-hooks' )->query( array( 'replacement' => $current_hook ) );
202
203 // Loop over results.
204 foreach ( $deprecated_hooks as $hook ) {
205 // Check if anyone is hooked into this deprecated hook.
206 if ( isset( $hook['deprecated'] ) && has_filter( $hook['deprecated'] ) ) {
207
208 // Log warning.
209 // _deprecated_hook( $deprecated, $version, $hook );
210
211 // Apply the item/do the action.
212 if ( $hook['type'] === 'filter' ) {
213 $args[0] = apply_filters_ref_array( $hook['deprecated'], $args );
214 } else {
215 do_action_ref_array( $hook['deprecated'], $args );
216 }
217 }
218 }
219
220 // Return first arg.
221 return $args[0];
222 }
223
224