Blocks
1 week ago
Datastore
1 month ago
Meta
1 year ago
abilities
1 week ago
admin
1 week ago
ajax
1 month ago
api
3 days ago
fields
3 days ago
forms
3 days ago
legacy
1 year ago
locations
1 year ago
post-types
2 months ago
rest-api
1 week ago
walkers
1 year ago
acf-bidirectional-functions.php
1 year ago
acf-field-functions.php
2 months ago
acf-field-group-functions.php
7 months ago
acf-form-functions.php
1 year ago
acf-helper-functions.php
1 year ago
acf-hook-functions.php
1 year ago
acf-input-functions.php
7 months ago
acf-internal-post-type-functions.php
7 months ago
acf-meta-functions.php
3 weeks ago
acf-post-functions.php
1 year ago
acf-post-type-functions.php
1 year ago
acf-taxonomy-functions.php
1 year ago
acf-user-functions.php
1 week ago
acf-utility-functions.php
1 year ago
acf-value-functions.php
1 year ago
acf-wp-functions.php
3 days ago
assets.php
1 week ago
blocks-auto-inline-editing.php
2 months ago
blocks.php
3 weeks ago
class-acf-data.php
10 months ago
class-acf-internal-post-type.php
1 week ago
class-acf-options-page.php
1 year ago
class-acf-site-health.php
3 months ago
class-scf-json-schema-validator.php
6 months ago
class-scf-schema-builder.php
2 months ago
compatibility.php
1 year ago
datastore.php
1 month ago
deprecated.php
1 year ago
fields.php
10 months ago
index.php
1 year ago
l10n.php
1 year ago
local-fields.php
1 year ago
local-json.php
1 month ago
local-meta.php
1 year ago
locations.php
1 year ago
loop.php
10 months ago
media.php
1 year ago
rest-api.php
10 months ago
revisions.php
1 month ago
scf-ui-options-page-functions.php
1 year ago
third-party.php
7 months ago
upgrades.php
3 weeks ago
validation.php
10 months ago
wpml.php
1 year ago
acf-utility-functions.php
155 lines
| 1 | <?php |
| 2 | |
| 3 | // Globals. |
| 4 | global $acf_stores, $acf_instances; |
| 5 | |
| 6 | // Initialize placeholders. |
| 7 | $acf_stores = array(); |
| 8 | $acf_instances = array(); |
| 9 | |
| 10 | /** |
| 11 | * acf_new_instance |
| 12 | * |
| 13 | * Creates a new instance of the given class and stores it in the instances data store. |
| 14 | * |
| 15 | * @date 9/1/19 |
| 16 | * @since ACF 5.7.10 |
| 17 | * |
| 18 | * @param string $class The class name. |
| 19 | * @return object The instance. |
| 20 | */ |
| 21 | function acf_new_instance( $class = '' ) { |
| 22 | global $acf_instances; |
| 23 | return $acf_instances[ $class ] = new $class(); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Returns an instance for the given class. |
| 28 | * |
| 29 | * @date 9/1/19 |
| 30 | * @since ACF 5.7.10 |
| 31 | * |
| 32 | * @param string $class The class name. |
| 33 | * @return object The instance. |
| 34 | */ |
| 35 | function acf_get_instance( $class = '' ) { |
| 36 | global $acf_instances; |
| 37 | if ( ! isset( $acf_instances[ $class ] ) ) { |
| 38 | $acf_instances[ $class ] = new $class(); |
| 39 | } |
| 40 | return $acf_instances[ $class ]; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * acf_register_store |
| 45 | * |
| 46 | * Registers a data store. |
| 47 | * |
| 48 | * @date 9/1/19 |
| 49 | * @since ACF 5.7.10 |
| 50 | * |
| 51 | * @param string $name The store name. |
| 52 | * @param array $data Array of data to start the store with. |
| 53 | * @return ACF_Data |
| 54 | */ |
| 55 | function acf_register_store( $name = '', $data = false ) { |
| 56 | |
| 57 | // Create store. |
| 58 | $store = new ACF_Data( $data ); |
| 59 | |
| 60 | // Register store. |
| 61 | global $acf_stores; |
| 62 | $acf_stores[ $name ] = $store; |
| 63 | |
| 64 | // Return store. |
| 65 | return $store; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * acf_get_store |
| 70 | * |
| 71 | * Returns a data store. |
| 72 | * |
| 73 | * @date 9/1/19 |
| 74 | * @since ACF 5.7.10 |
| 75 | * |
| 76 | * @param string $name The store name. |
| 77 | * @return ACF_Data |
| 78 | */ |
| 79 | function acf_get_store( $name = '' ) { |
| 80 | global $acf_stores; |
| 81 | return isset( $acf_stores[ $name ] ) ? $acf_stores[ $name ] : false; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * acf_switch_stores |
| 86 | * |
| 87 | * Triggered when switching between sites on a multisite installation. |
| 88 | * |
| 89 | * @date 13/2/19 |
| 90 | * @since ACF 5.7.11 |
| 91 | * |
| 92 | * @param integer $site_id New blog ID. |
| 93 | * @param int prev_blog_id Prev blog ID. |
| 94 | * @return void |
| 95 | */ |
| 96 | function acf_switch_stores( $site_id, $prev_site_id ) { |
| 97 | |
| 98 | // Loop over stores and call switch_site(). |
| 99 | global $acf_stores; |
| 100 | foreach ( $acf_stores as $store ) { |
| 101 | $store->switch_site( $site_id, $prev_site_id ); |
| 102 | } |
| 103 | } |
| 104 | add_action( 'switch_blog', 'acf_switch_stores', 10, 2 ); |
| 105 | |
| 106 | /** |
| 107 | * acf_get_path |
| 108 | * |
| 109 | * Returns the plugin path to a specified file. |
| 110 | * |
| 111 | * @date 28/9/13 |
| 112 | * @since ACF 5.0.0 |
| 113 | * |
| 114 | * @param string $filename The specified file. |
| 115 | * @return string |
| 116 | */ |
| 117 | function acf_get_path( $filename = '' ) { |
| 118 | return ACF_PATH . ltrim( $filename, '/' ); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * acf_get_url |
| 123 | * |
| 124 | * Returns the plugin url to a specified file. |
| 125 | * This function also defines the ACF_URL constant. |
| 126 | * |
| 127 | * @date 12/12/17 |
| 128 | * @since ACF 5.6.8 |
| 129 | * |
| 130 | * @param string $filename The specified file. |
| 131 | * @return string |
| 132 | */ |
| 133 | function acf_get_url( $filename = '' ) { |
| 134 | if ( ! defined( 'ACF_URL' ) ) { |
| 135 | define( 'ACF_URL', acf_get_setting( 'url' ) ); |
| 136 | } |
| 137 | return ACF_URL . ltrim( $filename, '/' ); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Includes a file within the ACF plugin. |
| 142 | * |
| 143 | * @date 10/3/14 |
| 144 | * @since ACF 5.0.0 |
| 145 | * |
| 146 | * @param string $filename The specified file. |
| 147 | * @return void |
| 148 | */ |
| 149 | function acf_include( $filename = '' ) { |
| 150 | $file_path = acf_get_path( $filename ); |
| 151 | if ( file_exists( $file_path ) ) { |
| 152 | include_once $file_path; |
| 153 | } |
| 154 | } |
| 155 |