PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.1
Secure Custom Fields v6.9.1
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 week ago Datastore 1 month ago Meta 1 year ago abilities 1 week ago admin 1 week ago ajax 1 month ago api 2 days ago fields 2 days ago forms 2 days ago legacy 1 year ago locations 1 year ago post-types 2 months ago rest-api 1 week ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 2 months ago acf-field-group-functions.php 7 months 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 7 months ago acf-internal-post-type-functions.php 7 months ago acf-meta-functions.php 3 weeks 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 week ago acf-utility-functions.php 1 year ago acf-value-functions.php 1 year ago acf-wp-functions.php 2 days ago assets.php 1 week ago blocks-auto-inline-editing.php 2 months ago blocks.php 3 weeks ago class-acf-data.php 10 months ago class-acf-internal-post-type.php 1 week ago class-acf-options-page.php 1 year ago class-acf-site-health.php 3 months ago class-scf-json-schema-validator.php 6 months ago class-scf-schema-builder.php 2 months ago compatibility.php 1 year ago datastore.php 1 month ago deprecated.php 1 year ago fields.php 10 months ago index.php 1 year ago l10n.php 1 year ago local-fields.php 1 year ago local-json.php 1 month ago local-meta.php 1 year ago locations.php 1 year ago loop.php 10 months ago media.php 1 year ago rest-api.php 10 months ago revisions.php 1 month ago scf-ui-options-page-functions.php 1 year ago third-party.php 7 months ago upgrades.php 3 weeks ago validation.php 10 months ago wpml.php 1 year ago
acf-hook-functions.php
223 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 priority 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 priority of 10, and accepted args of 10 (ignored by WP).
63 // @phpstan-ignore return.void
64 add_action( $action, '_acf_apply_hook_variations', 10, 10 );
65 }
66
67 /**
68 * _acf_apply_hook_variations
69 *
70 * Applies hook variations during apply_filters() or do_action().
71 *
72 * @date 25/1/19
73 * @since ACF 5.7.11
74 *
75 * @param mixed
76 * @return mixed
77 */
78 function _acf_apply_hook_variations() {
79
80 // Get current filter.
81 $filter = current_filter();
82
83 // Get args provided.
84 $args = func_get_args();
85
86 // Get variation information.
87 $variations = acf_get_store( 'hook-variations' )->get( $filter );
88 $index = $variations['index'];
89 $type = $variations['type'];
90 $variations = $variations['variations'];
91
92 // Find field in args using index.
93 $field = $args[ $index ];
94
95 // Loop over variations and apply filters.
96 foreach ( $variations as $variation ) {
97
98 // Get value from field.
99 // First look for "backup" value ("_name", "_key").
100 if ( isset( $field[ "_$variation" ] ) ) {
101 $value = $field[ "_$variation" ];
102 } elseif ( isset( $field[ $variation ] ) ) {
103 $value = $field[ $variation ];
104 } else {
105 continue;
106 }
107
108 // Apply filters.
109 if ( 'filter' === $type ) {
110 $args[0] = apply_filters_ref_array( "$filter/$variation=$value", $args );
111
112 // Or do action.
113 } else {
114 do_action_ref_array( "$filter/$variation=$value", $args );
115 }
116 }
117
118 // Return first arg.
119 return $args[0];
120 }
121
122 // Register store.
123 acf_register_store( 'deprecated-hooks' );
124
125 /**
126 * acf_add_deprecated_filter
127 *
128 * Registers a deprecated filter to run during the replacement.
129 *
130 * @date 25/1/19
131 * @since ACF 5.7.11
132 *
133 * @param string $deprecated The deprecated hook.
134 * @param string $version The version this hook was deprecated.
135 * @param string $replacement The replacement hook.
136 * @return void
137 */
138 function acf_add_deprecated_filter( $deprecated, $version, $replacement ) {
139
140 // Store replacement data.
141 acf_get_store( 'deprecated-hooks' )->append(
142 array(
143 'type' => 'filter',
144 'deprecated' => $deprecated,
145 'replacement' => $replacement,
146 'version' => $version,
147 )
148 );
149
150 // Add generic handler.
151 // Use a priority of 10, and accepted args of 10 (ignored by WP).
152 add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
153 }
154
155 /**
156 * acf_add_deprecated_action
157 *
158 * Registers a deprecated action to run during the replacement.
159 *
160 * @date 25/1/19
161 * @since ACF 5.7.11
162 *
163 * @param string $deprecated The deprecated hook.
164 * @param string $version The version this hook was deprecated.
165 * @param string $replacement The replacement hook.
166 * @return void
167 */
168 function acf_add_deprecated_action( $deprecated, $version, $replacement ) {
169
170 // Store replacement data.
171 acf_get_store( 'deprecated-hooks' )->append(
172 array(
173 'type' => 'action',
174 'deprecated' => $deprecated,
175 'replacement' => $replacement,
176 'version' => $version,
177 )
178 );
179
180 // Add generic handler.
181 // Use a priority of 10, and accepted args of 10 (ignored by WP).
182 add_filter( $replacement, '_acf_apply_deprecated_hook', 10, 10 );
183 }
184
185 /**
186 * Applies a deprecated filter during apply_filters() or do_action().
187 *
188 * @date 25/1/19
189 * @since ACF 5.7.11
190 *
191 * @param mixed
192 * @return mixed
193 */
194 function _acf_apply_deprecated_hook() {
195 // Get current hook.
196 $current_hook = current_filter();
197
198 // Get args provided.
199 $args = func_get_args();
200
201 // Get deprecated items for this hook.
202 $deprecated_hooks = acf_get_store( 'deprecated-hooks' )->query( array( 'replacement' => $current_hook ) );
203
204 // Loop over results.
205 foreach ( $deprecated_hooks as $hook ) {
206 // Check if anyone is hooked into this deprecated hook.
207 if ( isset( $hook['deprecated'] ) && has_filter( $hook['deprecated'] ) ) {
208
209 // Log warning.
210 // _deprecated_hook( $deprecated, $version, $hook );
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