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