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