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