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