PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.8.2
Secure Custom Fields v6.8.2
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 / secure-custom-fields.php
secure-custom-fields Last commit date
assets 3 months ago includes 3 months ago lang 7 months ago pro 6 months ago schemas 6 months ago vendor 3 months ago SECURITY.md 1 year ago acf.php 7 months ago composer.json 3 months ago index.php 1 year ago license.txt 1 year ago readme.txt 3 months ago secure-custom-fields.php 3 months ago
secure-custom-fields.php
933 lines
1 <?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName -- This file contains procedural code for now.
2 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- This file contains both procedural and object-oriented code for now.
3 /**
4 * Secure Custom Fields
5 *
6 * Plugin Name: Secure Custom Fields
7 * Plugin URI: https://developer.wordpress.org/secure-custom-fields/
8 * Description: Secure Custom Fields (SCF) offers an intuitive way for developers to enhance WordPress content management by adding extra fields and options without coding requirements.
9 * Version: 6.8.2
10 * Author: WordPress.org
11 * Author URI: https://wordpress.org/
12 * Text Domain: secure-custom-fields
13 * Domain Path: /lang
14 * Requires PHP: 7.4
15 * Requires at least: 6.2
16 *
17 * @package wordpress/secure-custom-fields
18 */
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit; // Exit if accessed directly.
22 }
23
24 if ( ! class_exists( 'ACF' ) ) {
25
26 /**
27 * The main ACF class
28 */
29 #[AllowDynamicProperties]
30 class ACF {
31 /**
32 * The plugin version number.
33 *
34 * @var string
35 */
36 public $version = '6.8.2';
37
38 /**
39 * The plugin settings array.
40 *
41 * @var array
42 */
43 public $settings = array();
44
45 /**
46 * The plugin data array.
47 *
48 * @var array
49 */
50 public $data = array();
51
52 /**
53 * Storage for class instances.
54 *
55 * @var array
56 */
57 public $instances = array();
58
59 /**
60 * The loop instance.
61 *
62 * @var acf_loop
63 */
64 public $loop;
65
66 /**
67 * The revisions instance.
68 *
69 * @var acf_revisions
70 */
71 public $revisions;
72
73 /**
74 * The fields instance.
75 *
76 * @var acf_fields
77 */
78 public $fields;
79
80 /**
81 * The form front instance.
82 *
83 * @var acf_form_front
84 */
85 public $form_front;
86
87 /**
88 * The validation instance.
89 *
90 * @var acf_validation
91 */
92 public $validation;
93
94 /**
95 * The admin tools instance.
96 *
97 * @var acf_admin_tools
98 */
99 public $admin_tools;
100
101 /**
102 * A dummy constructor to ensure ACF is only setup once.
103 *
104 * @date 23/06/12
105 * @since ACF 5.0.0
106 */
107 public function __construct() {
108 // Do nothing.
109 }
110
111 /**
112 * Sets up the ACF plugin.
113 *
114 * @date 28/09/13
115 * @since ACF 5.0.0
116 */
117 public function initialize() {
118
119 // Define constants.
120 defined( 'ACF' ) || define( 'ACF', true );
121 defined( 'ACF_PATH' ) || define( 'ACF_PATH', plugin_dir_path( __FILE__ ) );
122 defined( 'ACF_BASENAME' ) || define( 'ACF_BASENAME', plugin_basename( __FILE__ ) );
123 defined( 'ACF_VERSION' ) || define( 'ACF_VERSION', $this->version );
124 defined( 'ACF_MAJOR_VERSION' ) || define( 'ACF_MAJOR_VERSION', 6 );
125 defined( 'ACF_FIELD_API_VERSION' ) || define( 'ACF_FIELD_API_VERSION', 5 );
126 defined( 'ACF_UPGRADE_VERSION' ) || define( 'ACF_UPGRADE_VERSION', '5.5.0' ); // Highest version with an upgrade routine. See upgrades.php.
127 defined( 'ACF_PRO' ) || define( 'ACF_PRO', true );
128
129 // Register activation hook.
130 register_activation_hook( __FILE__, array( $this, 'acf_plugin_activated' ) );
131
132 // Define settings.
133 $this->settings = array(
134 'name' => 'Secure Custom Fields', // Will be updated in the init hook to i18n string.
135 'slug' => dirname( ACF_BASENAME ),
136 'version' => ACF_VERSION,
137 'basename' => ACF_BASENAME,
138 'path' => ACF_PATH,
139 'file' => __FILE__,
140 'url' => plugin_dir_url( __FILE__ ),
141 'show_admin' => true,
142 'show_updates' => true,
143 'enable_post_types' => true,
144 'enable_options_pages_ui' => true,
145 'stripslashes' => false,
146 'local' => true,
147 'json' => true,
148 'save_json' => '',
149 'load_json' => array(),
150 'default_language' => '',
151 'current_language' => '',
152 'capability' => 'manage_options',
153 'uploader' => 'wp',
154 'autoload' => false,
155 'l10n' => true,
156 'l10n_textdomain' => '',
157 'google_api_key' => '',
158 'google_api_client' => '',
159 'enqueue_google_maps' => true,
160 'enqueue_select2' => true,
161 'enqueue_datepicker' => true,
162 'enqueue_datetimepicker' => true,
163 'select2_version' => 4,
164 'row_index_offset' => 1,
165 'remove_wp_meta_box' => true,
166 'rest_api_enabled' => true,
167 'rest_api_format' => 'light',
168 'rest_api_embed_links' => true,
169 'preload_blocks' => true,
170 'enable_shortcode' => true,
171 'enable_bidirection' => true,
172 'enable_block_bindings' => true,
173 'pro' => true,
174 );
175
176 // Include autoloader.
177 include_once __DIR__ . '/vendor/autoload.php';
178
179 // Include utility functions.
180 include_once ACF_PATH . 'includes/acf-utility-functions.php';
181
182 // Include previous API functions.
183 acf_include( 'includes/api/api-helpers.php' );
184 acf_include( 'includes/api/api-template.php' );
185 acf_include( 'includes/api/api-term.php' );
186
187 // Include classes.
188 acf_include( 'includes/class-acf-data.php' );
189 acf_include( 'includes/class-acf-internal-post-type.php' );
190 acf_include( 'includes/class-acf-options-page.php' );
191 acf_include( 'includes/class-acf-site-health.php' );
192 acf_include( 'includes/class-scf-json-schema-validator.php' );
193 acf_include( 'includes/class-scf-schema-builder.php' );
194 acf_include( 'includes/abilities/class-scf-abilities-integration.php' );
195 acf_include( 'includes/fields/class-acf-field.php' );
196 acf_include( 'includes/locations/abstract-acf-legacy-location.php' );
197 acf_include( 'includes/locations/abstract-acf-location.php' );
198
199 // Include functions.
200 acf_include( 'includes/acf-helper-functions.php' );
201
202 acf_new_instance( 'SCF\Meta\Comment' );
203 acf_new_instance( 'SCF\Meta\Post' );
204 acf_new_instance( 'SCF\Meta\Term' );
205 acf_new_instance( 'SCF\Meta\User' );
206 acf_new_instance( 'SCF\Meta\Option' );
207
208 acf_include( 'includes/acf-hook-functions.php' );
209 acf_include( 'includes/acf-field-functions.php' );
210 acf_include( 'includes/acf-bidirectional-functions.php' );
211 acf_include( 'includes/acf-internal-post-type-functions.php' );
212 acf_include( 'includes/acf-post-type-functions.php' );
213 acf_include( 'includes/acf-taxonomy-functions.php' );
214 acf_include( 'includes/acf-field-group-functions.php' );
215 acf_include( 'includes/acf-form-functions.php' );
216 acf_include( 'includes/acf-meta-functions.php' );
217 acf_include( 'includes/acf-post-functions.php' );
218 acf_include( 'includes/acf-user-functions.php' );
219 acf_include( 'includes/acf-value-functions.php' );
220 acf_include( 'includes/acf-input-functions.php' );
221 acf_include( 'includes/acf-wp-functions.php' );
222 acf_include( 'includes/scf-ui-options-page-functions.php' );
223
224 // Override the shortcode default value based on the version when installed.
225 $first_activated_version = acf_get_version_when_first_activated();
226
227 // Only enable shortcode by default for versions prior to 6.3.
228 if ( $first_activated_version && version_compare( $first_activated_version, '6.3', '>=' ) ) {
229 $this->settings['enable_shortcode'] = false;
230 }
231
232 // Include core.
233 acf_include( 'includes/fields.php' );
234 acf_include( 'includes/locations.php' );
235 acf_include( 'includes/assets.php' );
236 acf_include( 'includes/compatibility.php' );
237 acf_include( 'includes/deprecated.php' );
238 acf_include( 'includes/l10n.php' );
239 acf_include( 'includes/local-fields.php' );
240 acf_include( 'includes/local-meta.php' );
241 acf_include( 'includes/local-json.php' );
242 acf_include( 'includes/loop.php' );
243 acf_include( 'includes/media.php' );
244 acf_include( 'includes/revisions.php' );
245 acf_include( 'includes/upgrades.php' );
246 acf_include( 'includes/validation.php' );
247 acf_include( 'includes/rest-api.php' );
248 acf_include( 'includes/blocks.php' );
249 acf_include( 'includes/class-acf-options-page.php' );
250
251 // Include field group and field manager classes.
252 acf_include( 'includes/post-types/class-acf-field-group.php' );
253 acf_include( 'includes/post-types/class-scf-field-manager.php' );
254
255 // Include ajax.
256 acf_include( 'includes/ajax/class-acf-ajax.php' );
257 acf_include( 'includes/ajax/class-acf-ajax-check-screen.php' );
258 acf_include( 'includes/ajax/class-acf-ajax-user-setting.php' );
259 acf_include( 'includes/ajax/class-acf-ajax-upgrade.php' );
260 acf_include( 'includes/ajax/class-acf-ajax-query.php' );
261 acf_include( 'includes/ajax/class-acf-ajax-query-users.php' );
262 acf_include( 'includes/ajax/class-acf-ajax-local-json-diff.php' );
263
264 // Include admin.
265 if ( is_admin() ) {
266 acf_include( 'includes/admin/admin.php' );
267 acf_include( 'includes/admin/admin-internal-post-type-list.php' );
268 acf_include( 'includes/admin/admin-internal-post-type.php' );
269 acf_include( 'includes/admin/admin-notices.php' );
270 acf_include( 'includes/admin/admin-tools.php' );
271 acf_include( 'includes/admin/admin-upgrade.php' );
272 acf_include( 'includes/admin/admin-commands.php' );
273 acf_include( 'includes/admin/beta-features.php' );
274 acf_include( 'includes/admin/class-acf-admin-options-page.php' );
275 }
276
277 // Include legacy.
278 acf_include( 'includes/legacy/legacy-locations.php' );
279
280 // Include PRO.
281 acf_include( 'pro/acf-pro.php' );
282
283 // Add actions.
284 add_action( 'init', array( $this, 'register_post_status' ), 4 );
285 add_action( 'init', array( $this, 'init' ), 5 );
286 add_action( 'init', array( $this, 'register_post_types' ), 5 );
287 add_action( 'woocommerce_init', array( $this, 'init_hpos_integration' ), 99 );
288
289 // Add filters.
290 add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );
291 }
292
293
294 /**
295 * Completes the setup process on "init" of earlier.
296 *
297 * @date 28/09/13
298 * @since ACF 5.0.0
299 */
300 public function init() {
301
302 // Bail early if called directly from functions.php or plugin file.
303 if ( ! did_action( 'plugins_loaded' ) ) {
304 return;
305 }
306
307 // This function may be called directly from template functions. Bail early if already did this.
308 if ( acf_did( 'init' ) ) {
309 return;
310 }
311
312 // Update url setting. Allows other plugins to modify the URL (force SSL).
313 acf_update_setting( 'url', plugin_dir_url( __FILE__ ) );
314
315 // Load textdomain file.
316 acf_load_textdomain();
317
318 // Update the name setting now that we're in the init hook.
319 acf_update_setting( 'name', __( 'Secure Custom Fields', 'secure-custom-fields' ) );
320
321 // Include 3rd party compatibility.
322 acf_include( 'includes/third-party.php' );
323
324 // Include wpml support.
325 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
326 acf_include( 'includes/wpml.php' );
327 }
328
329 // Include forms.
330 acf_include( 'includes/forms/form-attachment.php' );
331 acf_include( 'includes/forms/form-comment.php' );
332 acf_include( 'includes/forms/form-customizer.php' );
333 acf_include( 'includes/forms/form-front.php' );
334 acf_include( 'includes/forms/form-nav-menu.php' );
335 acf_include( 'includes/forms/form-post.php' );
336 acf_include( 'includes/forms/form-gutenberg.php' );
337 acf_include( 'includes/forms/form-taxonomy.php' );
338 acf_include( 'includes/forms/form-user.php' );
339 acf_include( 'includes/forms/form-widget.php' );
340
341 // Add post types and taxonomies.
342 if ( acf_get_setting( 'enable_post_types' ) ) {
343 acf_include( 'includes/post-types/class-acf-taxonomy.php' );
344 acf_include( 'includes/post-types/class-acf-post-type.php' );
345 }
346
347 if ( acf_get_setting( 'enable_options_pages_ui' ) ) {
348 acf_include( 'includes/post-types/class-acf-ui-options-page.php' );
349 }
350 // Add other ACF internal post types.
351 do_action( 'acf/init_internal_post_types' );
352
353 // Include fields.
354 acf_include( 'includes/fields/class-acf-field-text.php' );
355 acf_include( 'includes/fields/class-acf-field-textarea.php' );
356 acf_include( 'includes/fields/class-acf-field-number.php' );
357 acf_include( 'includes/fields/class-acf-field-range.php' );
358 acf_include( 'includes/fields/class-acf-field-email.php' );
359 acf_include( 'includes/fields/class-acf-field-url.php' );
360 acf_include( 'includes/fields/class-acf-field-password.php' );
361 acf_include( 'includes/fields/class-acf-field-image.php' );
362 acf_include( 'includes/fields/class-acf-field-file.php' );
363 acf_include( 'includes/fields/class-acf-field-wysiwyg.php' );
364 acf_include( 'includes/fields/class-acf-field-oembed.php' );
365 acf_include( 'includes/fields/class-acf-field-select.php' );
366 acf_include( 'includes/fields/class-acf-field-checkbox.php' );
367 acf_include( 'includes/fields/class-acf-field-radio.php' );
368 acf_include( 'includes/fields/class-acf-field-button-group.php' );
369 acf_include( 'includes/fields/class-acf-field-true_false.php' );
370 acf_include( 'includes/fields/class-acf-field-link.php' );
371 acf_include( 'includes/fields/class-acf-field-post_object.php' );
372 acf_include( 'includes/fields/class-acf-field-page_link.php' );
373 acf_include( 'includes/fields/class-acf-field-relationship.php' );
374 acf_include( 'includes/fields/class-acf-field-taxonomy.php' );
375 acf_include( 'includes/fields/class-acf-field-user.php' );
376 acf_include( 'includes/fields/class-acf-field-google-map.php' );
377 acf_include( 'includes/fields/class-acf-field-date_picker.php' );
378 acf_include( 'includes/fields/class-acf-field-date_time_picker.php' );
379 acf_include( 'includes/fields/class-acf-field-time_picker.php' );
380 acf_include( 'includes/fields/class-acf-field-color_picker.php' );
381 acf_include( 'includes/fields/class-acf-field-icon_picker.php' );
382 acf_include( 'includes/fields/class-acf-field-message.php' );
383 acf_include( 'includes/fields/class-acf-field-accordion.php' );
384 acf_include( 'includes/fields/class-acf-field-tab.php' );
385 acf_include( 'includes/fields/class-acf-field-group.php' );
386 acf_include( 'includes/fields/class-acf-repeater-table.php' );
387 acf_include( 'includes/fields/class-acf-field-repeater.php' );
388 acf_include( 'includes/fields/class-acf-field-flexible-content.php' );
389 acf_include( 'includes/fields/class-acf-field-gallery.php' );
390 acf_include( 'includes/fields/class-acf-field-clone.php' );
391 acf_include( 'includes/fields/class-acf-field-nav-menu.php' );
392
393 /**
394 * Fires after field types have been included.
395 *
396 * @since ACF 5.0.0
397 *
398 * @param int $version The field API version.
399 */
400 do_action( 'acf/include_field_types', ACF_FIELD_API_VERSION );
401
402 // Include locations.
403 acf_include( 'includes/locations/class-acf-location-post-type.php' );
404 acf_include( 'includes/locations/class-acf-location-post-template.php' );
405 acf_include( 'includes/locations/class-acf-location-post-status.php' );
406 acf_include( 'includes/locations/class-acf-location-post-format.php' );
407 acf_include( 'includes/locations/class-acf-location-post-category.php' );
408 acf_include( 'includes/locations/class-acf-location-post-taxonomy.php' );
409 acf_include( 'includes/locations/class-acf-location-post.php' );
410 acf_include( 'includes/locations/class-acf-location-page-template.php' );
411 acf_include( 'includes/locations/class-acf-location-page-type.php' );
412 acf_include( 'includes/locations/class-acf-location-page-parent.php' );
413 acf_include( 'includes/locations/class-acf-location-page.php' );
414 acf_include( 'includes/locations/class-acf-location-current-user.php' );
415 acf_include( 'includes/locations/class-acf-location-current-user-role.php' );
416 acf_include( 'includes/locations/class-acf-location-user-form.php' );
417 acf_include( 'includes/locations/class-acf-location-user-role.php' );
418 acf_include( 'includes/locations/class-acf-location-taxonomy.php' );
419 acf_include( 'includes/locations/class-acf-location-attachment.php' );
420 acf_include( 'includes/locations/class-acf-location-comment.php' );
421 acf_include( 'includes/locations/class-acf-location-widget.php' );
422 acf_include( 'includes/locations/class-acf-location-nav-menu.php' );
423 acf_include( 'includes/locations/class-acf-location-nav-menu-item.php' );
424 acf_include( 'includes/locations/class-acf-location-block.php' );
425 acf_include( 'includes/locations/class-acf-location-options-page.php' );
426
427 /**
428 * Fires after location types have been included.
429 *
430 * @since ACF 5.0.0
431 *
432 * @param int $version The field API version.
433 */
434 do_action( 'acf/include_location_rules', ACF_FIELD_API_VERSION );
435
436 /**
437 * Fires during initialization. Used to add local fields.
438 *
439 * @since ACF 5.0.0
440 *
441 * @param int $version The field API version.
442 */
443 do_action( 'acf/include_fields', ACF_FIELD_API_VERSION );
444
445 /**
446 * Fires during initialization. Used to add local post types.
447 *
448 * @since ACF 6.1
449 *
450 * @param int $version The major version of ACF.
451 */
452 do_action( 'acf/include_post_types', ACF_MAJOR_VERSION );
453
454 /**
455 * Fires during initialization. Used to add local taxonomies.
456 *
457 * @since ACF 6.1
458 *
459 * @param int $version The major version of ACF.
460 */
461 do_action( 'acf/include_taxonomies', ACF_MAJOR_VERSION );
462
463 /**
464 * Fires during initialization. Used to add local option pages.
465 *
466 * @param int $version The major version of ACF.
467 */
468 do_action( 'acf/include_options_pages', ACF_MAJOR_VERSION );
469
470 // If we're on WP 6.5 or newer, load block bindings. This will move to an autoloader in ACF 6.3.
471 if ( version_compare( get_bloginfo( 'version' ), '6.5-beta1', '>=' ) ) {
472 acf_include( 'includes/Blocks/Bindings.php' );
473 new ACF\Blocks\Bindings();
474 }
475
476 /**
477 * Fires after ACF is completely "initialized".
478 *
479 * @since ACF 5.0.0
480 *
481 * @param int $version The major version of ACF.
482 */
483 do_action( 'acf/init', ACF_MAJOR_VERSION );
484 }
485
486 /**
487 * Registers the ACF post types.
488 *
489 * @date 22/10/2015
490 * @since ACF 5.3.2
491 */
492 public function register_post_types() {
493 $cap = acf_get_setting( 'capability' );
494
495 // Register the Field Group post type.
496 register_post_type(
497 'acf-field-group',
498 array(
499 'labels' => array(
500 'name' => __( 'Field Groups', 'secure-custom-fields' ),
501 'singular_name' => __( 'Field Group', 'secure-custom-fields' ),
502 'add_new' => __( 'Add New', 'secure-custom-fields' ),
503 'add_new_item' => __( 'Add New Field Group', 'secure-custom-fields' ),
504 'edit_item' => __( 'Edit Field Group', 'secure-custom-fields' ),
505 'new_item' => __( 'New Field Group', 'secure-custom-fields' ),
506 'view_item' => __( 'View Field Group', 'secure-custom-fields' ),
507 'search_items' => __( 'Search Field Groups', 'secure-custom-fields' ),
508 'not_found' => __( 'No Field Groups found', 'secure-custom-fields' ),
509 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'secure-custom-fields' ),
510 ),
511 'public' => false,
512 'hierarchical' => true,
513 'show_ui' => true,
514 'show_in_menu' => false,
515 '_builtin' => false,
516 'capability_type' => 'post',
517 'capabilities' => array(
518 'edit_post' => $cap,
519 'delete_post' => $cap,
520 'edit_posts' => $cap,
521 'delete_posts' => $cap,
522 ),
523 'supports' => false,
524 'rewrite' => false,
525 'query_var' => false,
526 )
527 );
528
529 // Register the Field post type.
530 register_post_type(
531 'acf-field',
532 array(
533 'labels' => array(
534 'name' => __( 'Fields', 'secure-custom-fields' ),
535 'singular_name' => __( 'Field', 'secure-custom-fields' ),
536 'add_new' => __( 'Add New', 'secure-custom-fields' ),
537 'add_new_item' => __( 'Add New Field', 'secure-custom-fields' ),
538 'edit_item' => __( 'Edit Field', 'secure-custom-fields' ),
539 'new_item' => __( 'New Field', 'secure-custom-fields' ),
540 'view_item' => __( 'View Field', 'secure-custom-fields' ),
541 'search_items' => __( 'Search Fields', 'secure-custom-fields' ),
542 'not_found' => __( 'No Fields found', 'secure-custom-fields' ),
543 'not_found_in_trash' => __( 'No Fields found in Trash', 'secure-custom-fields' ),
544 ),
545 'public' => false,
546 'hierarchical' => true,
547 'show_ui' => false,
548 'show_in_menu' => false,
549 '_builtin' => false,
550 'capability_type' => 'post',
551 'capabilities' => array(
552 'edit_post' => $cap,
553 'delete_post' => $cap,
554 'edit_posts' => $cap,
555 'delete_posts' => $cap,
556 ),
557 'supports' => array( 'title' ),
558 'rewrite' => false,
559 'query_var' => false,
560 )
561 );
562 }
563
564 /**
565 * Registers the ACF post statuses.
566 *
567 * @date 22/10/2015
568 * @since ACF 5.3.2
569 */
570 public function register_post_status() {
571
572 // Register the Inactive post status.
573 register_post_status(
574 'acf-disabled',
575 array(
576 'label' => _x( 'Inactive', 'post status', 'secure-custom-fields' ),
577 'public' => true,
578 'exclude_from_search' => false,
579 'show_in_admin_all_list' => true,
580 'show_in_admin_status_list' => true,
581 /* translators: counts for inactive field groups */
582 'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'secure-custom-fields' ),
583 )
584 );
585 }
586
587 /**
588 * Filters the $where clause allowing for custom WP_Query args.
589 *
590 * @date 31/8/19
591 * @since ACF 5.8.1
592 *
593 * @param string $where The WHERE clause.
594 * @param WP_Query $wp_query The query object.
595 * @return string
596 */
597 public function posts_where( $where, $wp_query ) {
598 global $wpdb;
599
600 $field_key = $wp_query->get( 'acf_field_key' );
601 $field_name = $wp_query->get( 'acf_field_name' );
602 $group_key = $wp_query->get( 'acf_group_key' );
603 $options_page_key = $wp_query->get( 'acf_ui_options_page_key' );
604 $post_type_key = $wp_query->get( 'acf_post_type_key' );
605 $taxonomy_key = $wp_query->get( 'acf_taxonomy_key' );
606
607 // Add custom "acf_field_key" arg.
608 if ( $field_key ) {
609 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key );
610 }
611
612 // Add custom "acf_field_name" arg.
613 if ( $field_name ) {
614 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name );
615 }
616
617 // Add custom "acf_group_key" arg.
618 if ( $group_key ) {
619 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key );
620 }
621
622 // Add custom "acf_post_type_key" arg.
623 if ( $post_type_key ) {
624 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $post_type_key );
625 }
626
627 // Add custom "acf_options_page_key" arg.
628 if ( $options_page_key ) {
629 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $options_page_key );
630 }
631
632 // Add custom "acf_taxonomy_key" arg.
633 if ( $taxonomy_key ) {
634 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $taxonomy_key );
635 }
636
637 return $where;
638 }
639
640 /**
641 * Defines a constant if doesnt already exist.
642 *
643 * @since ACF 5.5.13
644 * @deprecated 6.5.0 -- Use vanilla PHP defined() || define() instead.
645 *
646 * @param string $name The constant name.
647 * @param mixed $value The constant value.
648 * @return void
649 */
650 public function define( $name, $value = true ) {
651 _deprecated_function( __METHOD__, '6.5.0', 'defined() || define()' );
652 if ( ! defined( $name ) ) {
653 define( $name, $value );
654 }
655 }
656
657 /**
658 * Returns true if a setting exists for this name.
659 *
660 * @date 2/2/18
661 * @since ACF 5.6.5
662 *
663 * @param string $name The setting name.
664 * @return boolean
665 */
666 public function has_setting( $name ) {
667 return isset( $this->settings[ $name ] );
668 }
669
670 /**
671 * Returns a setting or null if doesn't exist.
672 *
673 * @date 28/09/13
674 * @since ACF 5.0.0
675 *
676 * @param string $name The setting name.
677 * @return mixed
678 */
679 public function get_setting( $name ) {
680 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
681 }
682
683 /**
684 * Updates a setting for the given name and value.
685 *
686 * @date 28/09/13
687 * @since ACF 5.0.0
688 *
689 * @param string $name The setting name.
690 * @param mixed $value The setting value.
691 * @return true
692 */
693 public function update_setting( $name, $value ) {
694 $this->settings[ $name ] = $value;
695 return true;
696 }
697
698 /**
699 * Returns data or null if doesn't exist.
700 *
701 * @date 28/09/13
702 * @since ACF 5.0.0
703 *
704 * @param string $name The data name.
705 * @return mixed
706 */
707 public function get_data( $name ) {
708 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
709 }
710
711 /**
712 * Sets data for the given name and value.
713 *
714 * @date 28/09/13
715 * @since ACF 5.0.0
716 *
717 * @param string $name The data name.
718 * @param mixed $value The data value.
719 * @return void
720 */
721 public function set_data( $name, $value ) {
722 $this->data[ $name ] = $value;
723 }
724
725 /**
726 * Returns an instance or null if doesn't exist.
727 *
728 * @date 13/2/18
729 * @since ACF 5.6.9
730 *
731 * @param string $class The instance class name.
732 * @return object
733 */
734 public function get_instance( $class ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound -- Opting not to rename due to PHP 8.0 named arguments.
735 $name = strtolower( $class );
736 return isset( $this->instances[ $name ] ) ? $this->instances[ $name ] : null;
737 }
738
739 /**
740 * Creates and stores an instance of the given class.
741 *
742 * @date 13/2/18
743 * @since ACF 5.6.9
744 *
745 * @param string $class The instance class name.
746 * @return object
747 */
748 public function new_instance( $class ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound -- Opting not to rename due to PHP 8.0 named arguments.
749 $instance = new $class();
750 $name = strtolower( $class );
751 $this->instances[ $name ] = $instance;
752 return $instance;
753 }
754
755 /**
756 * Magic __isset method for backwards compatibility.
757 *
758 * @date 24/4/20
759 * @since ACF 5.9.0
760 *
761 * @param string $key Key name.
762 * @return boolean
763 */
764 public function __isset( $key ) {
765 return in_array( $key, array( 'locations', 'json' ), true );
766 }
767
768 /**
769 * Magic __get method for backwards compatibility.
770 *
771 * @date 24/4/20
772 * @since ACF 5.9.0
773 *
774 * @param string $key Key name.
775 * @return mixed
776 */
777 public function __get( $key ) {
778 switch ( $key ) {
779 case 'locations':
780 return acf_get_instance( 'ACF_Legacy_Locations' );
781 case 'json':
782 return acf_get_instance( 'ACF_Local_JSON' );
783 }
784 return null;
785 }
786
787 /**
788 * Plugin Activation Hook
789 *
790 * @since ACF 6.2.6
791 */
792 public function acf_plugin_activated() {
793 // Set the first activated version of ACF.
794 if ( null === get_option( 'acf_first_activated_version', null ) ) {
795 // If acf_version is set, this isn't the first activated version, so leave it unset so it's legacy.
796 if ( null === get_option( 'acf_version', null ) ) {
797 update_option( 'acf_first_activated_version', ACF_VERSION, true );
798
799 do_action( 'acf/first_activated' );
800 }
801 }
802 }
803
804 /**
805 * Initializes the ACF WooCommerce HPOS integration.
806 *
807 * @since 6.5
808 *
809 * @return void
810 */
811 public function init_hpos_integration() {
812 acf_new_instance( 'SCF\Meta\WooOrder' );
813 acf_new_instance( 'SCF\Forms\WC_Order' );
814 }
815 }
816
817 /**
818 * The main function responsible for returning the one true acf Instance to functions everywhere.
819 * Use this function like you would a global variable, except without needing to declare the global.
820 *
821 * Example: <?php $acf = acf(); ?>
822 *
823 * @date 4/09/13
824 * @since ACF 4.3.0
825 *
826 * @return ACF
827 */
828 function acf() {
829 global $acf;
830
831 // Instantiate only once.
832 if ( ! isset( $acf ) ) {
833 $acf = new ACF();
834 $acf->initialize();
835 }
836 return $acf;
837 }
838
839 // Instantiate.
840 acf();
841 } // class_exists check
842
843 if ( ! function_exists( 'scf_deactivate_other_instances' ) ) {
844 /**
845 * Checks if another version of ACF/ACF PRO is active and deactivates it.
846 * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated.
847 */
848 function scf_deactivate_other_instances() {
849
850 $plugin_to_deactivate = 'advanced-custom-fields/acf.php';
851 $deactivated_notice_id = '1';
852
853 // Check if the plugin to deactivate is installed.
854 if ( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
855 $plugin_to_deactivate = 'advanced-custom-fields-pro/acf.php';
856 $deactivated_notice_id = '2';
857 } elseif ( is_plugin_active( 'advanced-custom-fields/acf.php' ) ) {
858 // Check if the plugin to deactivate is 'advanced-custom-fields/acf.php' but the title is 'Secure Custom Fields'.
859 if ( ! function_exists( 'get_plugin_data' ) ) {
860 require_once ABSPATH . 'wp-admin/includes/plugin.php';
861 }
862 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_to_deactivate );
863 if ( 'Secure Custom Fields' === $plugin_data['Name'] ) {
864 $deactivated_notice_id = '3';
865 }
866 }
867
868 if ( is_multisite() && is_network_admin() ) {
869 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
870 $active_plugins = array_keys( $active_plugins );
871 } else {
872 $active_plugins = (array) get_option( 'active_plugins', array() );
873 }
874
875 foreach ( $active_plugins as $plugin_basename ) {
876 if ( $plugin_to_deactivate === $plugin_basename ) {
877 set_transient( 'acf_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS );
878 deactivate_plugins( $plugin_basename );
879 return;
880 }
881 }
882 }
883
884 add_action( 'activated_plugin', 'scf_deactivate_other_instances' );
885 }
886
887 if ( ! function_exists( 'scf_plugin_deactivated_notice' ) ) {
888 /**
889 * Displays a notice when either ACF or ACF PRO is automatically deactivated.
890 */
891 function scf_plugin_deactivated_notice() {
892 $deactivated_notice_id = (int) get_transient( 'acf_deactivated_notice_id' );
893 if ( ! in_array( $deactivated_notice_id, array( 1, 2, 3 ), true ) ) {
894 return;
895 }
896
897 $message = __( "Secure Custom Fields and Advanced Custom Fields should not be active at the same time. We've automatically deactivated Advanced Custom Fields.", 'secure-custom-fields' );
898 if ( 2 === $deactivated_notice_id ) {
899 $message = __( "Secure Custom Fields and Advanced Custom Fields PRO should not be active at the same time. We've automatically deactivated Advanced Custom Fields PRO.", 'secure-custom-fields' );
900 } elseif ( 3 === $deactivated_notice_id ) {
901 $message = __( "This version of Secure Custom Fields cannot work with the legacy version of Secure Custom Fields. We've automatically deactivated your previous version of Secure Custom Fields.", 'secure-custom-fields' );
902 }
903
904 ?>
905 <div class="updated" style="border-left: 4px solid #ffba00;">
906 <p><?php echo esc_html( $message ); ?></p>
907 </div>
908 <?php
909
910 delete_transient( 'acf_deactivated_notice_id' );
911 }
912
913 add_action( 'pre_current_active_plugins', 'scf_plugin_deactivated_notice' );
914 }
915 /**
916 * Clean up plugin data on uninstall
917 */
918 register_uninstall_hook( __FILE__, 'scf_plugin_uninstall' );
919
920 /**
921 * Cleanup function that runs when the plugin is uninstalled
922 */
923 function scf_plugin_uninstall() {
924 // List of known beta features.
925 $beta_features = array(
926 'editor_sidebar',
927 );
928
929 foreach ( $beta_features as $beta_feature ) {
930 delete_option( 'scf_beta_feature_' . $beta_feature . '_enabled' );
931 }
932 }
933