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