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