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