PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.1-beta5
Secure Custom Fields v6.4.1-beta5
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 / 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
844 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: 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-beta5
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-beta5';
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', 'secure-custom-fields' ),
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 forms.
211 acf_include( 'includes/forms/form-attachment.php' );
212 acf_include( 'includes/forms/form-comment.php' );
213 acf_include( 'includes/forms/form-customizer.php' );
214 acf_include( 'includes/forms/form-front.php' );
215 acf_include( 'includes/forms/form-nav-menu.php' );
216 acf_include( 'includes/forms/form-post.php' );
217 acf_include( 'includes/forms/form-gutenberg.php' );
218 acf_include( 'includes/forms/form-taxonomy.php' );
219 acf_include( 'includes/forms/form-user.php' );
220 acf_include( 'includes/forms/form-widget.php' );
221
222 // Include admin.
223 if ( is_admin() ) {
224 acf_include( 'includes/admin/admin.php' );
225 acf_include( 'includes/admin/admin-internal-post-type-list.php' );
226 acf_include( 'includes/admin/admin-internal-post-type.php' );
227 acf_include( 'includes/admin/admin-notices.php' );
228 acf_include( 'includes/admin/admin-tools.php' );
229 acf_include( 'includes/admin/admin-upgrade.php' );
230 acf_include( 'includes/admin/admin-options-page.php' );
231 }
232
233 // Include legacy.
234 acf_include( 'includes/legacy/legacy-locations.php' );
235
236 // Include PRO.
237 acf_include( 'pro/acf-pro.php' );
238
239 // Add actions.
240 add_action( 'init', array( $this, 'register_post_status' ), 4 );
241 add_action( 'init', array( $this, 'init' ), 5 );
242 add_action( 'init', array( $this, 'register_post_types' ), 5 );
243
244 // Add filters.
245 add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );
246 }
247
248 /**
249 * Completes the setup process on "init" of earlier.
250 *
251 * @date 28/09/13
252 * @since ACF 5.0.0
253 */
254 public function init() {
255
256 // Bail early if called directly from functions.php or plugin file.
257 if ( ! did_action( 'plugins_loaded' ) ) {
258 return;
259 }
260
261 // This function may be called directly from template functions. Bail early if already did this.
262 if ( acf_did( 'init' ) ) {
263 return;
264 }
265
266 // Update url setting. Allows other plugins to modify the URL (force SSL).
267 acf_update_setting( 'url', plugin_dir_url( __FILE__ ) );
268
269 // Load textdomain file.
270 acf_load_textdomain();
271
272 // Include 3rd party compatiblity.
273 acf_include( 'includes/third-party.php' );
274
275 // Include wpml support.
276 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
277 acf_include( 'includes/wpml.php' );
278 }
279
280 // Add post types and taxonomies.
281 if ( acf_get_setting( 'enable_post_types' ) ) {
282 acf_include( 'includes/post-types/class-acf-taxonomy.php' );
283 acf_include( 'includes/post-types/class-acf-post-type.php' );
284 }
285
286 if ( acf_get_setting( 'enable_options_pages_ui' ) ) {
287 acf_include( 'includes/post-types/class-acf-ui-options-page.php' );
288 }
289 // Add other ACF internal post types.
290 do_action( 'acf/init_internal_post_types' );
291
292 // Include fields.
293 acf_include( 'includes/fields/class-acf-field-text.php' );
294 acf_include( 'includes/fields/class-acf-field-textarea.php' );
295 acf_include( 'includes/fields/class-acf-field-number.php' );
296 acf_include( 'includes/fields/class-acf-field-range.php' );
297 acf_include( 'includes/fields/class-acf-field-email.php' );
298 acf_include( 'includes/fields/class-acf-field-url.php' );
299 acf_include( 'includes/fields/class-acf-field-password.php' );
300 acf_include( 'includes/fields/class-acf-field-image.php' );
301 acf_include( 'includes/fields/class-acf-field-file.php' );
302 acf_include( 'includes/fields/class-acf-field-wysiwyg.php' );
303 acf_include( 'includes/fields/class-acf-field-oembed.php' );
304 acf_include( 'includes/fields/class-acf-field-select.php' );
305 acf_include( 'includes/fields/class-acf-field-checkbox.php' );
306 acf_include( 'includes/fields/class-acf-field-radio.php' );
307 acf_include( 'includes/fields/class-acf-field-button-group.php' );
308 acf_include( 'includes/fields/class-acf-field-true_false.php' );
309 acf_include( 'includes/fields/class-acf-field-link.php' );
310 acf_include( 'includes/fields/class-acf-field-post_object.php' );
311 acf_include( 'includes/fields/class-acf-field-page_link.php' );
312 acf_include( 'includes/fields/class-acf-field-relationship.php' );
313 acf_include( 'includes/fields/class-acf-field-taxonomy.php' );
314 acf_include( 'includes/fields/class-acf-field-user.php' );
315 acf_include( 'includes/fields/class-acf-field-google-map.php' );
316 acf_include( 'includes/fields/class-acf-field-date_picker.php' );
317 acf_include( 'includes/fields/class-acf-field-date_time_picker.php' );
318 acf_include( 'includes/fields/class-acf-field-time_picker.php' );
319 acf_include( 'includes/fields/class-acf-field-color_picker.php' );
320 acf_include( 'includes/fields/class-acf-field-icon_picker.php' );
321 acf_include( 'includes/fields/class-acf-field-message.php' );
322 acf_include( 'includes/fields/class-acf-field-accordion.php' );
323 acf_include( 'includes/fields/class-acf-field-tab.php' );
324 acf_include( 'includes/fields/class-acf-field-group.php' );
325 acf_include( 'includes/fields/class-acf-repeater-table.php' );
326 acf_include( 'includes/fields/class-acf-field-repeater.php' );
327 acf_include( 'includes/fields/class-acf-field-flexible-content.php' );
328 acf_include( 'includes/fields/class-acf-field-gallery.php' );
329 acf_include( 'includes/fields/class-acf-field-clone.php' );
330
331 /**
332 * Fires after field types have been included.
333 *
334 * @date 28/09/13
335 * @since ACF 5.0.0
336 *
337 * @param int ACF_FIELD_API_VERSION The field API version.
338 */
339 do_action( 'acf/include_field_types', ACF_FIELD_API_VERSION );
340
341 // Include locations.
342 acf_include( 'includes/locations/class-acf-location-post-type.php' );
343 acf_include( 'includes/locations/class-acf-location-post-template.php' );
344 acf_include( 'includes/locations/class-acf-location-post-status.php' );
345 acf_include( 'includes/locations/class-acf-location-post-format.php' );
346 acf_include( 'includes/locations/class-acf-location-post-category.php' );
347 acf_include( 'includes/locations/class-acf-location-post-taxonomy.php' );
348 acf_include( 'includes/locations/class-acf-location-post.php' );
349 acf_include( 'includes/locations/class-acf-location-page-template.php' );
350 acf_include( 'includes/locations/class-acf-location-page-type.php' );
351 acf_include( 'includes/locations/class-acf-location-page-parent.php' );
352 acf_include( 'includes/locations/class-acf-location-page.php' );
353 acf_include( 'includes/locations/class-acf-location-current-user.php' );
354 acf_include( 'includes/locations/class-acf-location-current-user-role.php' );
355 acf_include( 'includes/locations/class-acf-location-user-form.php' );
356 acf_include( 'includes/locations/class-acf-location-user-role.php' );
357 acf_include( 'includes/locations/class-acf-location-taxonomy.php' );
358 acf_include( 'includes/locations/class-acf-location-attachment.php' );
359 acf_include( 'includes/locations/class-acf-location-comment.php' );
360 acf_include( 'includes/locations/class-acf-location-widget.php' );
361 acf_include( 'includes/locations/class-acf-location-nav-menu.php' );
362 acf_include( 'includes/locations/class-acf-location-nav-menu-item.php' );
363 acf_include( 'includes/locations/class-acf-location-block.php' );
364 acf_include( 'includes/locations/class-acf-location-options-page.php' );
365
366 /**
367 * Fires after location types have been included.
368 *
369 * @date 28/09/13
370 * @since ACF 5.0.0
371 *
372 * @param int ACF_FIELD_API_VERSION The field API version.
373 */
374 do_action( 'acf/include_location_rules', ACF_FIELD_API_VERSION );
375
376 /**
377 * Fires during initialization. Used to add local fields.
378 *
379 * @date 28/09/13
380 * @since ACF 5.0.0
381 *
382 * @param int ACF_FIELD_API_VERSION The field API version.
383 */
384 do_action( 'acf/include_fields', ACF_FIELD_API_VERSION );
385
386 /**
387 * Fires during initialization. Used to add local post types.
388 *
389 * @since ACF 6.1
390 *
391 * @param int ACF_MAJOR_VERSION The major version of ACF.
392 */
393 do_action( 'acf/include_post_types', ACF_MAJOR_VERSION );
394
395 /**
396 * Fires during initialization. Used to add local taxonomies.
397 *
398 * @since ACF 6.1
399 *
400 * @param int ACF_MAJOR_VERSION The major version of ACF.
401 */
402 do_action( 'acf/include_taxonomies', ACF_MAJOR_VERSION );
403
404 /**
405 * Fires during initialization. Used to add local option pages.
406 *
407 * @param int ACF_MAJOR_VERSION The major version of ACF.
408 */
409 do_action( 'acf/include_options_pages', ACF_MAJOR_VERSION );
410
411 // If we're on 6.5 or newer, load block bindings. This will move to an autoloader in 6.3.
412 if ( version_compare( get_bloginfo( 'version' ), '6.5-beta1', '>=' ) ) {
413 acf_include( 'includes/Blocks/Bindings.php' );
414 new ACF\Blocks\Bindings();
415 }
416
417 /**
418 * Fires after ACF is completely "initialized".
419 *
420 * @date 28/09/13
421 * @since ACF 5.0.0
422 *
423 * @param int ACF_MAJOR_VERSION The major version of ACF.
424 */
425 do_action( 'acf/init', ACF_MAJOR_VERSION );
426 }
427
428 /**
429 * Registers the ACF post types.
430 *
431 * @date 22/10/2015
432 * @since ACF 5.3.2
433 */
434 public function register_post_types() {
435 $cap = acf_get_setting( 'capability' );
436
437 // Register the Field Group post type.
438 register_post_type(
439 'acf-field-group',
440 array(
441 'labels' => array(
442 'name' => __( 'Field Groups', 'secure-custom-fields' ),
443 'singular_name' => __( 'Field Group', 'secure-custom-fields' ),
444 'add_new' => __( 'Add New', 'secure-custom-fields' ),
445 'add_new_item' => __( 'Add New Field Group', 'secure-custom-fields' ),
446 'edit_item' => __( 'Edit Field Group', 'secure-custom-fields' ),
447 'new_item' => __( 'New Field Group', 'secure-custom-fields' ),
448 'view_item' => __( 'View Field Group', 'secure-custom-fields' ),
449 'search_items' => __( 'Search Field Groups', 'secure-custom-fields' ),
450 'not_found' => __( 'No Field Groups found', 'secure-custom-fields' ),
451 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'secure-custom-fields' ),
452 ),
453 'public' => false,
454 'hierarchical' => true,
455 'show_ui' => true,
456 'show_in_menu' => false,
457 '_builtin' => false,
458 'capability_type' => 'post',
459 'capabilities' => array(
460 'edit_post' => $cap,
461 'delete_post' => $cap,
462 'edit_posts' => $cap,
463 'delete_posts' => $cap,
464 ),
465 'supports' => false,
466 'rewrite' => false,
467 'query_var' => false,
468 )
469 );
470
471 // Register the Field post type.
472 register_post_type(
473 'acf-field',
474 array(
475 'labels' => array(
476 'name' => __( 'Fields', 'secure-custom-fields' ),
477 'singular_name' => __( 'Field', 'secure-custom-fields' ),
478 'add_new' => __( 'Add New', 'secure-custom-fields' ),
479 'add_new_item' => __( 'Add New Field', 'secure-custom-fields' ),
480 'edit_item' => __( 'Edit Field', 'secure-custom-fields' ),
481 'new_item' => __( 'New Field', 'secure-custom-fields' ),
482 'view_item' => __( 'View Field', 'secure-custom-fields' ),
483 'search_items' => __( 'Search Fields', 'secure-custom-fields' ),
484 'not_found' => __( 'No Fields found', 'secure-custom-fields' ),
485 'not_found_in_trash' => __( 'No Fields found in Trash', 'secure-custom-fields' ),
486 ),
487 'public' => false,
488 'hierarchical' => true,
489 'show_ui' => false,
490 'show_in_menu' => false,
491 '_builtin' => false,
492 'capability_type' => 'post',
493 'capabilities' => array(
494 'edit_post' => $cap,
495 'delete_post' => $cap,
496 'edit_posts' => $cap,
497 'delete_posts' => $cap,
498 ),
499 'supports' => array( 'title' ),
500 'rewrite' => false,
501 'query_var' => false,
502 )
503 );
504 }
505
506 /**
507 * Registers the ACF post statuses.
508 *
509 * @date 22/10/2015
510 * @since ACF 5.3.2
511 */
512 public function register_post_status() {
513
514 // Register the Inactive post status.
515 register_post_status(
516 'acf-disabled',
517 array(
518 'label' => _x( 'Inactive', 'post status', 'secure-custom-fields' ),
519 'public' => true,
520 'exclude_from_search' => false,
521 'show_in_admin_all_list' => true,
522 'show_in_admin_status_list' => true,
523 /* translators: counts for inactive field groups */
524 'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'secure-custom-fields' ),
525 )
526 );
527 }
528
529 /**
530 * Filters the $where clause allowing for custom WP_Query args.
531 *
532 * @date 31/8/19
533 * @since ACF 5.8.1
534 *
535 * @param string $where The WHERE clause.
536 * @param WP_Query $wp_query The query object.
537 * @return string
538 */
539 public function posts_where( $where, $wp_query ) {
540 global $wpdb;
541
542 $field_key = $wp_query->get( 'acf_field_key' );
543 $field_name = $wp_query->get( 'acf_field_name' );
544 $group_key = $wp_query->get( 'acf_group_key' );
545 $options_page_key = $wp_query->get( 'acf_ui_options_page_key' );
546 $post_type_key = $wp_query->get( 'acf_post_type_key' );
547 $taxonomy_key = $wp_query->get( 'acf_taxonomy_key' );
548
549 // Add custom "acf_field_key" arg.
550 if ( $field_key ) {
551 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key );
552 }
553
554 // Add custom "acf_field_name" arg.
555 if ( $field_name ) {
556 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name );
557 }
558
559 // Add custom "acf_group_key" arg.
560 if ( $group_key ) {
561 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key );
562 }
563
564 // Add custom "acf_post_type_key" arg.
565 if ( $post_type_key ) {
566 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $post_type_key );
567 }
568
569 // Add custom "acf_options_page_key" arg.
570 if ( $options_page_key ) {
571 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $options_page_key );
572 }
573
574 // Add custom "acf_taxonomy_key" arg.
575 if ( $taxonomy_key ) {
576 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $taxonomy_key );
577 }
578
579 return $where;
580 }
581
582 /**
583 * Defines a constant if doesnt already exist.
584 *
585 * @date 3/5/17
586 * @since ACF 5.5.13
587 *
588 * @param string $name The constant name.
589 * @param mixed $value The constant value.
590 * @return void
591 */
592 public function define( $name, $value = true ) {
593 if ( ! defined( $name ) ) {
594 define( $name, $value );
595 }
596 }
597
598 /**
599 * Returns true if a setting exists for this name.
600 *
601 * @date 2/2/18
602 * @since ACF 5.6.5
603 *
604 * @param string $name The setting name.
605 * @return boolean
606 */
607 public function has_setting( $name ) {
608 return isset( $this->settings[ $name ] );
609 }
610
611 /**
612 * Returns a setting or null if doesn't exist.
613 *
614 * @date 28/09/13
615 * @since ACF 5.0.0
616 *
617 * @param string $name The setting name.
618 * @return mixed
619 */
620 public function get_setting( $name ) {
621 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
622 }
623
624 /**
625 * Updates a setting for the given name and value.
626 *
627 * @date 28/09/13
628 * @since ACF 5.0.0
629 *
630 * @param string $name The setting name.
631 * @param mixed $value The setting value.
632 * @return true
633 */
634 public function update_setting( $name, $value ) {
635 $this->settings[ $name ] = $value;
636 return true;
637 }
638
639 /**
640 * Returns data or null if doesn't exist.
641 *
642 * @date 28/09/13
643 * @since ACF 5.0.0
644 *
645 * @param string $name The data name.
646 * @return mixed
647 */
648 public function get_data( $name ) {
649 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
650 }
651
652 /**
653 * Sets data for the given name and value.
654 *
655 * @date 28/09/13
656 * @since ACF 5.0.0
657 *
658 * @param string $name The data name.
659 * @param mixed $value The data value.
660 * @return void
661 */
662 public function set_data( $name, $value ) {
663 $this->data[ $name ] = $value;
664 }
665
666 /**
667 * Returns an instance or null if doesn't exist.
668 *
669 * @date 13/2/18
670 * @since ACF 5.6.9
671 *
672 * @param string $class The instance class name.
673 * @return object
674 */
675 public function get_instance( $class ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound -- Opting not to rename due to PHP 8.0 named arugments.
676 $name = strtolower( $class );
677 return isset( $this->instances[ $name ] ) ? $this->instances[ $name ] : null;
678 }
679
680 /**
681 * Creates and stores an instance of the given class.
682 *
683 * @date 13/2/18
684 * @since ACF 5.6.9
685 *
686 * @param string $class The instance class name.
687 * @return object
688 */
689 public function new_instance( $class ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound -- Opting not to rename due to PHP 8.0 named arugments.
690 $instance = new $class();
691 $name = strtolower( $class );
692 $this->instances[ $name ] = $instance;
693 return $instance;
694 }
695
696 /**
697 * Magic __isset method for backwards compatibility.
698 *
699 * @date 24/4/20
700 * @since ACF 5.9.0
701 *
702 * @param string $key Key name.
703 * @return boolean
704 */
705 public function __isset( $key ) {
706 return in_array( $key, array( 'locations', 'json' ), true );
707 }
708
709 /**
710 * Magic __get method for backwards compatibility.
711 *
712 * @date 24/4/20
713 * @since ACF 5.9.0
714 *
715 * @param string $key Key name.
716 * @return mixed
717 */
718 public function __get( $key ) {
719 switch ( $key ) {
720 case 'locations':
721 return acf_get_instance( 'ACF_Legacy_Locations' );
722 case 'json':
723 return acf_get_instance( 'ACF_Local_JSON' );
724 }
725 return null;
726 }
727
728 /**
729 * Plugin Activation Hook
730 *
731 * @since ACF 6.2.6
732 */
733 public function acf_plugin_activated() {
734 // Set the first activated version of ACF.
735 if ( null === get_option( 'acf_first_activated_version', null ) ) {
736 // If acf_version is set, this isn't the first activated version, so leave it unset so it's legacy.
737 if ( null === get_option( 'acf_version', null ) ) {
738 update_option( 'acf_first_activated_version', ACF_VERSION, true );
739
740 do_action( 'acf/first_activated' );
741 }
742 }
743 }
744 }
745
746 /**
747 * The main function responsible for returning the one true acf Instance to functions everywhere.
748 * Use this function like you would a global variable, except without needing to declare the global.
749 *
750 * Example: <?php $acf = acf(); ?>
751 *
752 * @date 4/09/13
753 * @since ACF 4.3.0
754 *
755 * @return ACF
756 */
757 function acf() {
758 global $acf;
759
760 // Instantiate only once.
761 if ( ! isset( $acf ) ) {
762 $acf = new ACF();
763 $acf->initialize();
764 }
765 return $acf;
766 }
767
768 // Instantiate.
769 acf();
770 } // class_exists check
771
772 if ( ! function_exists( 'scf_deactivate_other_instances' ) ) {
773 /**
774 * Checks if another version of ACF/ACF PRO is active and deactivates it.
775 * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated.
776 */
777 function scf_deactivate_other_instances() {
778
779 $plugin_to_deactivate = 'advanced-custom-fields/acf.php';
780 $deactivated_notice_id = '1';
781
782 // Check if the plugin to deactivate is installed.
783 if ( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
784 $plugin_to_deactivate = 'advanced-custom-fields-pro/acf.php';
785 $deactivated_notice_id = '2';
786 } elseif ( is_plugin_active( 'advanced-custom-fields/acf.php' ) ) {
787 // Check if the plugin to deactivate is 'advanced-custom-fields/acf.php' but the title is 'Secure Custom Fields'.
788 if ( ! function_exists( 'get_plugin_data' ) ) {
789 require_once ABSPATH . 'wp-admin/includes/plugin.php';
790 }
791 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_to_deactivate );
792 if ( 'Secure Custom Fields' === $plugin_data['Name'] ) {
793 $deactivated_notice_id = '3';
794 }
795 }
796
797 if ( is_multisite() && is_network_admin() ) {
798 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
799 $active_plugins = array_keys( $active_plugins );
800 } else {
801 $active_plugins = (array) get_option( 'active_plugins', array() );
802 }
803
804 foreach ( $active_plugins as $plugin_basename ) {
805 if ( $plugin_to_deactivate === $plugin_basename ) {
806 set_transient( 'acf_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS );
807 deactivate_plugins( $plugin_basename );
808 return;
809 }
810 }
811 }
812
813 add_action( 'activated_plugin', 'scf_deactivate_other_instances' );
814 }
815
816 if ( ! function_exists( 'scf_plugin_deactivated_notice' ) ) {
817 /**
818 * Displays a notice when either ACF or ACF PRO is automatically deactivated.
819 */
820 function scf_plugin_deactivated_notice() {
821 $deactivated_notice_id = (int) get_transient( 'acf_deactivated_notice_id' );
822 if ( ! in_array( $deactivated_notice_id, array( 1, 2, 3 ), true ) ) {
823 return;
824 }
825
826 $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' );
827 if ( 2 === $deactivated_notice_id ) {
828 $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' );
829 } elseif ( 3 === $deactivated_notice_id ) {
830 $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' );
831 }
832
833 ?>
834 <div class="updated" style="border-left: 4px solid #ffba00;">
835 <p><?php echo esc_html( $message ); ?></p>
836 </div>
837 <?php
838
839 delete_transient( 'acf_deactivated_notice_id' );
840 }
841
842 add_action( 'pre_current_active_plugins', 'scf_plugin_deactivated_notice' );
843 }
844