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