acf.php
| 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.0.4 |
| 13 | * Author: WP Engine |
| 14 | * Author URI: https://www.advancedcustomfields.com |
| 15 | * Text Domain: acf |
| 16 | * Domain Path: /lang |
| 17 | */ |
| 18 | |
| 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | exit; // Exit if accessed directly. |
| 21 | } |
| 22 | |
| 23 | if ( ! class_exists( 'ACF' ) ) { |
| 24 | |
| 25 | /** |
| 26 | * The main ACF class |
| 27 | */ |
| 28 | class ACF { |
| 29 | |
| 30 | /** |
| 31 | * The plugin version number. |
| 32 | * |
| 33 | * @var string |
| 34 | */ |
| 35 | public $version = '6.0.4'; |
| 36 | |
| 37 | /** |
| 38 | * The plugin settings array. |
| 39 | * |
| 40 | * @var array |
| 41 | */ |
| 42 | public $settings = array(); |
| 43 | |
| 44 | /** |
| 45 | * The plugin data array. |
| 46 | * |
| 47 | * @var array |
| 48 | */ |
| 49 | public $data = array(); |
| 50 | |
| 51 | /** |
| 52 | * Storage for class instances. |
| 53 | * |
| 54 | * @var array |
| 55 | */ |
| 56 | public $instances = array(); |
| 57 | |
| 58 | /** |
| 59 | * A dummy constructor to ensure ACF is only setup once. |
| 60 | * |
| 61 | * @date 23/06/12 |
| 62 | * @since 5.0.0 |
| 63 | * |
| 64 | * @return void |
| 65 | */ |
| 66 | public function __construct() { |
| 67 | // Do nothing. |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Sets up the ACF plugin. |
| 72 | * |
| 73 | * @date 28/09/13 |
| 74 | * @since 5.0.0 |
| 75 | * |
| 76 | * @return void |
| 77 | */ |
| 78 | public function initialize() { |
| 79 | |
| 80 | // Define constants. |
| 81 | $this->define( 'ACF', true ); |
| 82 | $this->define( 'ACF_PATH', plugin_dir_path( __FILE__ ) ); |
| 83 | $this->define( 'ACF_BASENAME', plugin_basename( __FILE__ ) ); |
| 84 | $this->define( 'ACF_VERSION', $this->version ); |
| 85 | $this->define( 'ACF_MAJOR_VERSION', 6 ); |
| 86 | $this->define( 'ACF_FIELD_API_VERSION', 5 ); |
| 87 | $this->define( 'ACF_UPGRADE_VERSION', '5.5.0' ); // Highest version with an upgrade routine. See upgrades.php. |
| 88 | |
| 89 | // Define settings. |
| 90 | $this->settings = array( |
| 91 | 'name' => __( 'Advanced Custom Fields', 'acf' ), |
| 92 | 'slug' => dirname( ACF_BASENAME ), |
| 93 | 'version' => ACF_VERSION, |
| 94 | 'basename' => ACF_BASENAME, |
| 95 | 'path' => ACF_PATH, |
| 96 | 'file' => __FILE__, |
| 97 | 'url' => plugin_dir_url( __FILE__ ), |
| 98 | 'show_admin' => true, |
| 99 | 'show_updates' => true, |
| 100 | 'stripslashes' => false, |
| 101 | 'local' => true, |
| 102 | 'json' => true, |
| 103 | 'save_json' => '', |
| 104 | 'load_json' => array(), |
| 105 | 'default_language' => '', |
| 106 | 'current_language' => '', |
| 107 | 'capability' => 'manage_options', |
| 108 | 'uploader' => 'wp', |
| 109 | 'autoload' => false, |
| 110 | 'l10n' => true, |
| 111 | 'l10n_textdomain' => '', |
| 112 | 'google_api_key' => '', |
| 113 | 'google_api_client' => '', |
| 114 | 'enqueue_google_maps' => true, |
| 115 | 'enqueue_select2' => true, |
| 116 | 'enqueue_datepicker' => true, |
| 117 | 'enqueue_datetimepicker' => true, |
| 118 | 'select2_version' => 4, |
| 119 | 'row_index_offset' => 1, |
| 120 | 'remove_wp_meta_box' => true, |
| 121 | 'rest_api_enabled' => true, |
| 122 | 'rest_api_format' => 'light', |
| 123 | 'rest_api_embed_links' => true, |
| 124 | 'preload_blocks' => true, |
| 125 | 'enable_shortcode' => true, |
| 126 | ); |
| 127 | |
| 128 | // Include utility functions. |
| 129 | include_once ACF_PATH . 'includes/acf-utility-functions.php'; |
| 130 | |
| 131 | // Include previous API functions. |
| 132 | acf_include( 'includes/api/api-helpers.php' ); |
| 133 | acf_include( 'includes/api/api-template.php' ); |
| 134 | acf_include( 'includes/api/api-term.php' ); |
| 135 | |
| 136 | // Include classes. |
| 137 | acf_include( 'includes/class-acf-data.php' ); |
| 138 | acf_include( 'includes/fields/class-acf-field.php' ); |
| 139 | acf_include( 'includes/locations/abstract-acf-legacy-location.php' ); |
| 140 | acf_include( 'includes/locations/abstract-acf-location.php' ); |
| 141 | |
| 142 | // Include functions. |
| 143 | acf_include( 'includes/acf-helper-functions.php' ); |
| 144 | acf_include( 'includes/acf-hook-functions.php' ); |
| 145 | acf_include( 'includes/acf-field-functions.php' ); |
| 146 | acf_include( 'includes/acf-field-group-functions.php' ); |
| 147 | acf_include( 'includes/acf-form-functions.php' ); |
| 148 | acf_include( 'includes/acf-meta-functions.php' ); |
| 149 | acf_include( 'includes/acf-post-functions.php' ); |
| 150 | acf_include( 'includes/acf-user-functions.php' ); |
| 151 | acf_include( 'includes/acf-value-functions.php' ); |
| 152 | acf_include( 'includes/acf-input-functions.php' ); |
| 153 | acf_include( 'includes/acf-wp-functions.php' ); |
| 154 | |
| 155 | // Include core. |
| 156 | acf_include( 'includes/fields.php' ); |
| 157 | acf_include( 'includes/locations.php' ); |
| 158 | acf_include( 'includes/assets.php' ); |
| 159 | acf_include( 'includes/compatibility.php' ); |
| 160 | acf_include( 'includes/deprecated.php' ); |
| 161 | acf_include( 'includes/l10n.php' ); |
| 162 | acf_include( 'includes/local-fields.php' ); |
| 163 | acf_include( 'includes/local-meta.php' ); |
| 164 | acf_include( 'includes/local-json.php' ); |
| 165 | acf_include( 'includes/loop.php' ); |
| 166 | acf_include( 'includes/media.php' ); |
| 167 | acf_include( 'includes/revisions.php' ); |
| 168 | acf_include( 'includes/updates.php' ); |
| 169 | acf_include( 'includes/upgrades.php' ); |
| 170 | acf_include( 'includes/validation.php' ); |
| 171 | acf_include( 'includes/rest-api.php' ); |
| 172 | |
| 173 | // Include ajax. |
| 174 | acf_include( 'includes/ajax/class-acf-ajax.php' ); |
| 175 | acf_include( 'includes/ajax/class-acf-ajax-check-screen.php' ); |
| 176 | acf_include( 'includes/ajax/class-acf-ajax-user-setting.php' ); |
| 177 | acf_include( 'includes/ajax/class-acf-ajax-upgrade.php' ); |
| 178 | acf_include( 'includes/ajax/class-acf-ajax-query.php' ); |
| 179 | acf_include( 'includes/ajax/class-acf-ajax-query-users.php' ); |
| 180 | acf_include( 'includes/ajax/class-acf-ajax-local-json-diff.php' ); |
| 181 | |
| 182 | // Include forms. |
| 183 | acf_include( 'includes/forms/form-attachment.php' ); |
| 184 | acf_include( 'includes/forms/form-comment.php' ); |
| 185 | acf_include( 'includes/forms/form-customizer.php' ); |
| 186 | acf_include( 'includes/forms/form-front.php' ); |
| 187 | acf_include( 'includes/forms/form-nav-menu.php' ); |
| 188 | acf_include( 'includes/forms/form-post.php' ); |
| 189 | acf_include( 'includes/forms/form-gutenberg.php' ); |
| 190 | acf_include( 'includes/forms/form-taxonomy.php' ); |
| 191 | acf_include( 'includes/forms/form-user.php' ); |
| 192 | acf_include( 'includes/forms/form-widget.php' ); |
| 193 | |
| 194 | // Include admin. |
| 195 | if ( is_admin() ) { |
| 196 | acf_include( 'includes/admin/admin.php' ); |
| 197 | acf_include( 'includes/admin/admin-field-group.php' ); |
| 198 | acf_include( 'includes/admin/admin-field-groups.php' ); |
| 199 | acf_include( 'includes/admin/admin-notices.php' ); |
| 200 | acf_include( 'includes/admin/admin-tools.php' ); |
| 201 | acf_include( 'includes/admin/admin-upgrade.php' ); |
| 202 | } |
| 203 | |
| 204 | // Include legacy. |
| 205 | acf_include( 'includes/legacy/legacy-locations.php' ); |
| 206 | |
| 207 | // Include PRO. |
| 208 | acf_include( 'pro/acf-pro.php' ); |
| 209 | |
| 210 | // Add actions. |
| 211 | add_action( 'init', array( $this, 'init' ), 5 ); |
| 212 | add_action( 'init', array( $this, 'register_post_types' ), 5 ); |
| 213 | add_action( 'init', array( $this, 'register_post_status' ), 5 ); |
| 214 | add_action( 'activated_plugin', array( $this, 'deactivate_other_instances' ) ); |
| 215 | add_action( 'pre_current_active_plugins', array( $this, 'plugin_deactivated_notice' ) ); |
| 216 | |
| 217 | // Add filters. |
| 218 | add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 ); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Completes the setup process on "init" of earlier. |
| 223 | * |
| 224 | * @date 28/09/13 |
| 225 | * @since 5.0.0 |
| 226 | * |
| 227 | * @return void |
| 228 | */ |
| 229 | public function init() { |
| 230 | |
| 231 | // Bail early if called directly from functions.php or plugin file. |
| 232 | if ( ! did_action( 'plugins_loaded' ) ) { |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | // This function may be called directly from template functions. Bail early if already did this. |
| 237 | if ( acf_did( 'init' ) ) { |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | // Update url setting. Allows other plugins to modify the URL (force SSL). |
| 242 | acf_update_setting( 'url', plugin_dir_url( __FILE__ ) ); |
| 243 | |
| 244 | // Load textdomain file. |
| 245 | acf_load_textdomain(); |
| 246 | |
| 247 | // Include 3rd party compatiblity. |
| 248 | acf_include( 'includes/third-party.php' ); |
| 249 | |
| 250 | // Include wpml support. |
| 251 | if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { |
| 252 | acf_include( 'includes/wpml.php' ); |
| 253 | } |
| 254 | |
| 255 | // Include fields. |
| 256 | acf_include( 'includes/fields/class-acf-field-text.php' ); |
| 257 | acf_include( 'includes/fields/class-acf-field-textarea.php' ); |
| 258 | acf_include( 'includes/fields/class-acf-field-number.php' ); |
| 259 | acf_include( 'includes/fields/class-acf-field-range.php' ); |
| 260 | acf_include( 'includes/fields/class-acf-field-email.php' ); |
| 261 | acf_include( 'includes/fields/class-acf-field-url.php' ); |
| 262 | acf_include( 'includes/fields/class-acf-field-password.php' ); |
| 263 | acf_include( 'includes/fields/class-acf-field-image.php' ); |
| 264 | acf_include( 'includes/fields/class-acf-field-file.php' ); |
| 265 | acf_include( 'includes/fields/class-acf-field-wysiwyg.php' ); |
| 266 | acf_include( 'includes/fields/class-acf-field-oembed.php' ); |
| 267 | acf_include( 'includes/fields/class-acf-field-select.php' ); |
| 268 | acf_include( 'includes/fields/class-acf-field-checkbox.php' ); |
| 269 | acf_include( 'includes/fields/class-acf-field-radio.php' ); |
| 270 | acf_include( 'includes/fields/class-acf-field-button-group.php' ); |
| 271 | acf_include( 'includes/fields/class-acf-field-true_false.php' ); |
| 272 | acf_include( 'includes/fields/class-acf-field-link.php' ); |
| 273 | acf_include( 'includes/fields/class-acf-field-post_object.php' ); |
| 274 | acf_include( 'includes/fields/class-acf-field-page_link.php' ); |
| 275 | acf_include( 'includes/fields/class-acf-field-relationship.php' ); |
| 276 | acf_include( 'includes/fields/class-acf-field-taxonomy.php' ); |
| 277 | acf_include( 'includes/fields/class-acf-field-user.php' ); |
| 278 | acf_include( 'includes/fields/class-acf-field-google-map.php' ); |
| 279 | acf_include( 'includes/fields/class-acf-field-date_picker.php' ); |
| 280 | acf_include( 'includes/fields/class-acf-field-date_time_picker.php' ); |
| 281 | acf_include( 'includes/fields/class-acf-field-time_picker.php' ); |
| 282 | acf_include( 'includes/fields/class-acf-field-color_picker.php' ); |
| 283 | acf_include( 'includes/fields/class-acf-field-message.php' ); |
| 284 | acf_include( 'includes/fields/class-acf-field-accordion.php' ); |
| 285 | acf_include( 'includes/fields/class-acf-field-tab.php' ); |
| 286 | acf_include( 'includes/fields/class-acf-field-group.php' ); |
| 287 | |
| 288 | /** |
| 289 | * Fires after field types have been included. |
| 290 | * |
| 291 | * @date 28/09/13 |
| 292 | * @since 5.0.0 |
| 293 | * |
| 294 | * @param int ACF_FIELD_API_VERSION The field API version. |
| 295 | */ |
| 296 | do_action( 'acf/include_field_types', ACF_FIELD_API_VERSION ); |
| 297 | |
| 298 | // Include locations. |
| 299 | acf_include( 'includes/locations/class-acf-location-post-type.php' ); |
| 300 | acf_include( 'includes/locations/class-acf-location-post-template.php' ); |
| 301 | acf_include( 'includes/locations/class-acf-location-post-status.php' ); |
| 302 | acf_include( 'includes/locations/class-acf-location-post-format.php' ); |
| 303 | acf_include( 'includes/locations/class-acf-location-post-category.php' ); |
| 304 | acf_include( 'includes/locations/class-acf-location-post-taxonomy.php' ); |
| 305 | acf_include( 'includes/locations/class-acf-location-post.php' ); |
| 306 | acf_include( 'includes/locations/class-acf-location-page-template.php' ); |
| 307 | acf_include( 'includes/locations/class-acf-location-page-type.php' ); |
| 308 | acf_include( 'includes/locations/class-acf-location-page-parent.php' ); |
| 309 | acf_include( 'includes/locations/class-acf-location-page.php' ); |
| 310 | acf_include( 'includes/locations/class-acf-location-current-user.php' ); |
| 311 | acf_include( 'includes/locations/class-acf-location-current-user-role.php' ); |
| 312 | acf_include( 'includes/locations/class-acf-location-user-form.php' ); |
| 313 | acf_include( 'includes/locations/class-acf-location-user-role.php' ); |
| 314 | acf_include( 'includes/locations/class-acf-location-taxonomy.php' ); |
| 315 | acf_include( 'includes/locations/class-acf-location-attachment.php' ); |
| 316 | acf_include( 'includes/locations/class-acf-location-comment.php' ); |
| 317 | acf_include( 'includes/locations/class-acf-location-widget.php' ); |
| 318 | acf_include( 'includes/locations/class-acf-location-nav-menu.php' ); |
| 319 | acf_include( 'includes/locations/class-acf-location-nav-menu-item.php' ); |
| 320 | |
| 321 | /** |
| 322 | * Fires after location types have been included. |
| 323 | * |
| 324 | * @date 28/09/13 |
| 325 | * @since 5.0.0 |
| 326 | * |
| 327 | * @param int ACF_FIELD_API_VERSION The field API version. |
| 328 | */ |
| 329 | do_action( 'acf/include_location_rules', ACF_FIELD_API_VERSION ); |
| 330 | |
| 331 | /** |
| 332 | * Fires during initialization. Used to add local fields. |
| 333 | * |
| 334 | * @date 28/09/13 |
| 335 | * @since 5.0.0 |
| 336 | * |
| 337 | * @param int ACF_FIELD_API_VERSION The field API version. |
| 338 | */ |
| 339 | do_action( 'acf/include_fields', ACF_FIELD_API_VERSION ); |
| 340 | |
| 341 | /** |
| 342 | * Fires after ACF is completely "initialized". |
| 343 | * |
| 344 | * @date 28/09/13 |
| 345 | * @since 5.0.0 |
| 346 | * |
| 347 | * @param int ACF_MAJOR_VERSION The major version of ACF. |
| 348 | */ |
| 349 | do_action( 'acf/init', ACF_MAJOR_VERSION ); |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Registers the ACF post types. |
| 354 | * |
| 355 | * @date 22/10/2015 |
| 356 | * @since 5.3.2 |
| 357 | * |
| 358 | * @return void |
| 359 | */ |
| 360 | public function register_post_types() { |
| 361 | |
| 362 | // Vars. |
| 363 | $cap = acf_get_setting( 'capability' ); |
| 364 | |
| 365 | // Register the Field Group post type. |
| 366 | register_post_type( |
| 367 | 'acf-field-group', |
| 368 | array( |
| 369 | 'labels' => array( |
| 370 | 'name' => __( 'Field Groups', 'acf' ), |
| 371 | 'singular_name' => __( 'Field Group', 'acf' ), |
| 372 | 'add_new' => __( 'Add New', 'acf' ), |
| 373 | 'add_new_item' => __( 'Add New Field Group', 'acf' ), |
| 374 | 'edit_item' => __( 'Edit Field Group', 'acf' ), |
| 375 | 'new_item' => __( 'New Field Group', 'acf' ), |
| 376 | 'view_item' => __( 'View Field Group', 'acf' ), |
| 377 | 'search_items' => __( 'Search Field Groups', 'acf' ), |
| 378 | 'not_found' => __( 'No Field Groups found', 'acf' ), |
| 379 | 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ), |
| 380 | ), |
| 381 | 'public' => false, |
| 382 | 'hierarchical' => true, |
| 383 | 'show_ui' => true, |
| 384 | 'show_in_menu' => false, |
| 385 | '_builtin' => false, |
| 386 | 'capability_type' => 'post', |
| 387 | 'capabilities' => array( |
| 388 | 'edit_post' => $cap, |
| 389 | 'delete_post' => $cap, |
| 390 | 'edit_posts' => $cap, |
| 391 | 'delete_posts' => $cap, |
| 392 | ), |
| 393 | 'supports' => false, |
| 394 | 'rewrite' => false, |
| 395 | 'query_var' => false, |
| 396 | ) |
| 397 | ); |
| 398 | |
| 399 | // Register the Field post type. |
| 400 | register_post_type( |
| 401 | 'acf-field', |
| 402 | array( |
| 403 | 'labels' => array( |
| 404 | 'name' => __( 'Fields', 'acf' ), |
| 405 | 'singular_name' => __( 'Field', 'acf' ), |
| 406 | 'add_new' => __( 'Add New', 'acf' ), |
| 407 | 'add_new_item' => __( 'Add New Field', 'acf' ), |
| 408 | 'edit_item' => __( 'Edit Field', 'acf' ), |
| 409 | 'new_item' => __( 'New Field', 'acf' ), |
| 410 | 'view_item' => __( 'View Field', 'acf' ), |
| 411 | 'search_items' => __( 'Search Fields', 'acf' ), |
| 412 | 'not_found' => __( 'No Fields found', 'acf' ), |
| 413 | 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ), |
| 414 | ), |
| 415 | 'public' => false, |
| 416 | 'hierarchical' => true, |
| 417 | 'show_ui' => false, |
| 418 | 'show_in_menu' => false, |
| 419 | '_builtin' => false, |
| 420 | 'capability_type' => 'post', |
| 421 | 'capabilities' => array( |
| 422 | 'edit_post' => $cap, |
| 423 | 'delete_post' => $cap, |
| 424 | 'edit_posts' => $cap, |
| 425 | 'delete_posts' => $cap, |
| 426 | ), |
| 427 | 'supports' => array( 'title' ), |
| 428 | 'rewrite' => false, |
| 429 | 'query_var' => false, |
| 430 | ) |
| 431 | ); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Registers the ACF post statuses. |
| 436 | * |
| 437 | * @date 22/10/2015 |
| 438 | * @since 5.3.2 |
| 439 | * |
| 440 | * @return void |
| 441 | */ |
| 442 | public function register_post_status() { |
| 443 | |
| 444 | // Register the Inactive post status. |
| 445 | register_post_status( |
| 446 | 'acf-disabled', |
| 447 | array( |
| 448 | 'label' => _x( 'Inactive', 'post status', 'acf' ), |
| 449 | 'public' => true, |
| 450 | 'exclude_from_search' => false, |
| 451 | 'show_in_admin_all_list' => true, |
| 452 | 'show_in_admin_status_list' => true, |
| 453 | /* translators: counts for inactive field groups */ |
| 454 | 'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'acf' ), |
| 455 | ) |
| 456 | ); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Checks if another version of ACF/ACF PRO is active and deactivates it. |
| 461 | * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated. |
| 462 | * |
| 463 | * @param string $plugin The plugin being activated. |
| 464 | */ |
| 465 | public function deactivate_other_instances( $plugin ) { |
| 466 | if ( ! in_array( $plugin, array( 'advanced-custom-fields/acf.php', 'advanced-custom-fields-pro/acf.php' ), true ) ) { |
| 467 | return; |
| 468 | } |
| 469 | |
| 470 | $plugin_to_deactivate = 'advanced-custom-fields/acf.php'; |
| 471 | $deactivated_notice_id = '1'; |
| 472 | |
| 473 | // If we just activated the free version, deactivate the pro version. |
| 474 | if ( $plugin === $plugin_to_deactivate ) { |
| 475 | $plugin_to_deactivate = 'advanced-custom-fields-pro/acf.php'; |
| 476 | $deactivated_notice_id = '2'; |
| 477 | } |
| 478 | |
| 479 | if ( is_multisite() && is_network_admin() ) { |
| 480 | $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
| 481 | $active_plugins = array_keys( $active_plugins ); |
| 482 | } else { |
| 483 | $active_plugins = (array) get_option( 'active_plugins', array() ); |
| 484 | } |
| 485 | |
| 486 | foreach ( $active_plugins as $plugin_basename ) { |
| 487 | if ( $plugin_to_deactivate === $plugin_basename ) { |
| 488 | set_transient( 'acf_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS ); |
| 489 | deactivate_plugins( $plugin_basename ); |
| 490 | return; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Displays a notice when either ACF or ACF PRO is automatically deactivated. |
| 497 | */ |
| 498 | public function plugin_deactivated_notice() { |
| 499 | $deactivated_notice_id = (int) get_transient( 'acf_deactivated_notice_id' ); |
| 500 | if ( ! in_array( $deactivated_notice_id, array( 1, 2 ), true ) ) { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | $message = __( "Advanced Custom Fields and Advanced Custom Fields should not be active at the same time. We've automatically deactivated Advanced Custom Fields.", 'acf' ); |
| 505 | if ( 2 === $deactivated_notice_id ) { |
| 506 | $message = __( "Advanced Custom Fields and Advanced Custom Fields should not be active at the same time. We've automatically deactivated Advanced Custom Fields PRO.", 'acf' ); |
| 507 | } |
| 508 | |
| 509 | ?> |
| 510 | <div class="updated" style="border-left: 4px solid #ffba00;"> |
| 511 | <p><?php echo esc_html( $message ); ?></p> |
| 512 | </div> |
| 513 | <?php |
| 514 | |
| 515 | delete_transient( 'acf_deactivated_notice_id' ); |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Filters the $where clause allowing for custom WP_Query args. |
| 520 | * |
| 521 | * @date 31/8/19 |
| 522 | * @since 5.8.1 |
| 523 | * |
| 524 | * @param string $where The WHERE clause. |
| 525 | * @param WP_Query $wp_query The query object. |
| 526 | * @return WP_Query $wp_query The query object. |
| 527 | */ |
| 528 | public function posts_where( $where, $wp_query ) { |
| 529 | global $wpdb; |
| 530 | |
| 531 | $field_key = $wp_query->get( 'acf_field_key' ); |
| 532 | $field_name = $wp_query->get( 'acf_field_name' ); |
| 533 | $group_key = $wp_query->get( 'acf_group_key' ); |
| 534 | |
| 535 | // Add custom "acf_field_key" arg. |
| 536 | if ( $field_key ) { |
| 537 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key ); |
| 538 | } |
| 539 | |
| 540 | // Add custom "acf_field_name" arg. |
| 541 | if ( $field_name ) { |
| 542 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name ); |
| 543 | } |
| 544 | |
| 545 | // Add custom "acf_group_key" arg. |
| 546 | if ( $group_key ) { |
| 547 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key ); |
| 548 | } |
| 549 | |
| 550 | // Return. |
| 551 | return $where; |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * Defines a constant if doesnt already exist. |
| 556 | * |
| 557 | * @date 3/5/17 |
| 558 | * @since 5.5.13 |
| 559 | * |
| 560 | * @param string $name The constant name. |
| 561 | * @param mixed $value The constant value. |
| 562 | * @return void |
| 563 | */ |
| 564 | public function define( $name, $value = true ) { |
| 565 | if ( ! defined( $name ) ) { |
| 566 | define( $name, $value ); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Returns true if a setting exists for this name. |
| 572 | * |
| 573 | * @date 2/2/18 |
| 574 | * @since 5.6.5 |
| 575 | * |
| 576 | * @param string $name The setting name. |
| 577 | * @return boolean |
| 578 | */ |
| 579 | public function has_setting( $name ) { |
| 580 | return isset( $this->settings[ $name ] ); |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Returns a setting or null if doesn't exist. |
| 585 | * |
| 586 | * @date 28/09/13 |
| 587 | * @since 5.0.0 |
| 588 | * |
| 589 | * @param string $name The setting name. |
| 590 | * @return mixed |
| 591 | */ |
| 592 | public function get_setting( $name ) { |
| 593 | return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null; |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * Updates a setting for the given name and value. |
| 598 | * |
| 599 | * @date 28/09/13 |
| 600 | * @since 5.0.0 |
| 601 | * |
| 602 | * @param string $name The setting name. |
| 603 | * @param mixed $value The setting value. |
| 604 | * @return true |
| 605 | */ |
| 606 | public function update_setting( $name, $value ) { |
| 607 | $this->settings[ $name ] = $value; |
| 608 | return true; |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Returns data or null if doesn't exist. |
| 613 | * |
| 614 | * @date 28/09/13 |
| 615 | * @since 5.0.0 |
| 616 | * |
| 617 | * @param string $name The data name. |
| 618 | * @return mixed |
| 619 | */ |
| 620 | public function get_data( $name ) { |
| 621 | return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null; |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * Sets data for the given name and value. |
| 626 | * |
| 627 | * @date 28/09/13 |
| 628 | * @since 5.0.0 |
| 629 | * |
| 630 | * @param string $name The data name. |
| 631 | * @param mixed $value The data value. |
| 632 | * @return void |
| 633 | */ |
| 634 | public function set_data( $name, $value ) { |
| 635 | $this->data[ $name ] = $value; |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Returns an instance or null if doesn't exist. |
| 640 | * |
| 641 | * @date 13/2/18 |
| 642 | * @since 5.6.9 |
| 643 | * |
| 644 | * @param string $class The instance class name. |
| 645 | * @return object |
| 646 | */ |
| 647 | public function get_instance( $class ) { |
| 648 | $name = strtolower( $class ); |
| 649 | return isset( $this->instances[ $name ] ) ? $this->instances[ $name ] : null; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Creates and stores an instance of the given class. |
| 654 | * |
| 655 | * @date 13/2/18 |
| 656 | * @since 5.6.9 |
| 657 | * |
| 658 | * @param string $class The instance class name. |
| 659 | * @return object |
| 660 | */ |
| 661 | public function new_instance( $class ) { |
| 662 | $instance = new $class(); |
| 663 | $name = strtolower( $class ); |
| 664 | $this->instances[ $name ] = $instance; |
| 665 | return $instance; |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Magic __isset method for backwards compatibility. |
| 670 | * |
| 671 | * @date 24/4/20 |
| 672 | * @since 5.9.0 |
| 673 | * |
| 674 | * @param string $key Key name. |
| 675 | * @return bool |
| 676 | */ |
| 677 | public function __isset( $key ) { |
| 678 | return in_array( $key, array( 'locations', 'json' ), true ); |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * Magic __get method for backwards compatibility. |
| 683 | * |
| 684 | * @date 24/4/20 |
| 685 | * @since 5.9.0 |
| 686 | * |
| 687 | * @param string $key Key name. |
| 688 | * @return mixed |
| 689 | */ |
| 690 | public function __get( $key ) { |
| 691 | switch ( $key ) { |
| 692 | case 'locations': |
| 693 | return acf_get_instance( 'ACF_Legacy_Locations' ); |
| 694 | case 'json': |
| 695 | return acf_get_instance( 'ACF_Local_JSON' ); |
| 696 | } |
| 697 | return null; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * The main function responsible for returning the one true acf Instance to functions everywhere. |
| 703 | * Use this function like you would a global variable, except without needing to declare the global. |
| 704 | * |
| 705 | * Example: <?php $acf = acf(); ?> |
| 706 | * |
| 707 | * @date 4/09/13 |
| 708 | * @since 4.3.0 |
| 709 | * |
| 710 | * @return ACF |
| 711 | */ |
| 712 | function acf() { |
| 713 | global $acf; |
| 714 | |
| 715 | // Instantiate only once. |
| 716 | if ( ! isset( $acf ) ) { |
| 717 | $acf = new ACF(); |
| 718 | $acf->initialize(); |
| 719 | } |
| 720 | return $acf; |
| 721 | } |
| 722 | |
| 723 | // Instantiate. |
| 724 | acf(); |
| 725 | |
| 726 | } // class_exists check |
| 727 |