PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.1-beta5
Secure Custom Fields v6.4.1-beta5
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / acf-hook-functions.php
secure-custom-fields / includes Last commit date
Blocks 1 year ago admin 1 year ago ajax 1 year ago api 1 year ago fields 1 year ago forms 1 year ago legacy 1 year ago locations 1 year ago post-types 1 year ago rest-api 1 year ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 1 year ago acf-field-group-functions.php 1 year ago acf-form-functions.php 1 year ago acf-helper-functions.php 1 year ago acf-hook-functions.php 1 year ago acf-input-functions.php 1 year ago acf-internal-post-type-functions.php 1 year ago acf-meta-functions.php 1 year ago acf-post-functions.php 1 year ago acf-post-type-functions.php 1 year ago acf-taxonomy-functions.php 1 year ago acf-user-functions.php 1 year ago acf-utility-functions.php 1 year ago acf-value-functions.php 1 year ago acf-wp-functions.php 1 year ago assets.php 1 year ago blocks.php 1 year ago class-acf-data.php 1 year ago class-acf-internal-post-type.php 1 year ago class-acf-options-page.php 1 year ago class-acf-site-health.php 1 year ago compatibility.php 1 year ago deprecated.php 1 year ago fields.php 1 year ago index.php 1 year ago l10n.php 1 year ago local-fields.php 1 year ago local-json.php 1 year ago local-meta.php 1 year ago locations.php 1 year ago loop.php 1 year ago media.php 1 year ago rest-api.php 1 year ago revisions.php 1 year ago scf-ui-options-page-functions.php 1 year ago third-party.php 1 year ago upgrades.php 1 year ago validation.php 1 year ago wpml.php 1 year ago
acf-hook-functions.php
222 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 ACF 5.7.11
13 *
14 * @param string $filter The filter name.
15 * @param array $variations An array variation keys.
16 * @param integer $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 ACF 5.7.11
43 *
44 * @param string $action The action name.
45 * @param array $variations An array variation keys.
46 * @param integer $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 ACF 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 ACF 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 ACF 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 ACF 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 // Apply the item/do the action.
211 if ( $hook['type'] === 'filter' ) {
212 $args[0] = apply_filters_ref_array( $hook['deprecated'], $args );
213 } else {
214 do_action_ref_array( $hook['deprecated'], $args );
215 }
216 }
217 }
218
219 // Return first arg.
220 return $args[0];
221 }
222