123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <?php
- acf_register_store( 'values' )->prop( 'multisite', true );
- function acf_get_reference( $field_name, $post_id ) {
-
- $reference = apply_filters( 'acf/pre_load_reference', null, $field_name, $post_id );
- if ( $reference !== null ) {
- return $reference;
- }
-
- $reference = acf_get_metadata( $post_id, $field_name, true );
-
- return apply_filters( 'acf/load_reference', $reference, $field_name, $post_id );
- }
- function acf_get_value( $post_id, $field ) {
-
- $value = apply_filters( 'acf/pre_load_value', null, $post_id, $field );
- if ( $value !== null ) {
- return $value;
- }
-
- $field_name = $field['name'];
-
- $decoded = acf_decode_post_id( $post_id );
- $allow_load = true;
-
- if ( empty( $field['type'] ) && empty( $field['key'] ) ) {
-
- do_action( 'acf/get_invalid_field_value', $field, __FUNCTION__ );
- if ( apply_filters( 'acf/prevent_access_to_unknown_fields', false ) || ( 'option' === $decoded['type'] && 'options' !== $decoded['id'] ) ) {
- $allow_load = false;
- }
- }
-
- if ( 'option' === $decoded['type'] && 'options' !== $decoded['id'] ) {
- $meta = acf_get_metadata( $post_id, $field_name, true );
- if ( ! $meta ) {
- $allow_load = false;
- } elseif ( $meta !== $field['key'] ) {
- if ( ! isset( $field['__key'] ) || $meta !== $field['__key'] ) {
- $allow_load = false;
- }
- }
- }
-
- $store = acf_get_store( 'values' );
-
- if ( $allow_load ) {
- if ( $store->has( "$post_id:$field_name" ) ) {
- return $store->get( "$post_id:$field_name" );
- }
- $value = acf_get_metadata( $post_id, $field_name );
- }
-
- if ( $value === null && isset( $field['default_value'] ) ) {
- $value = $field['default_value'];
- }
-
- $value = apply_filters( 'acf/load_value', $value, $post_id, $field );
-
- if ( $allow_load ) {
- $store->set( "$post_id:$field_name", $value );
- }
-
- return $value;
- }
- acf_add_filter_variations( 'acf/load_value', array( 'type', 'name', 'key' ), 2 );
- function acf_format_value( $value, $post_id, $field ) {
-
- $check = apply_filters( 'acf/pre_format_value', null, $value, $post_id, $field );
- if ( $check !== null ) {
- return $check;
- }
-
- $field_name = $field['name'];
-
- $store = acf_get_store( 'values' );
- if ( $store->has( "$post_id:$field_name:formatted" ) ) {
- return $store->get( "$post_id:$field_name:formatted" );
- }
-
- $value = apply_filters( 'acf/format_value', $value, $post_id, $field );
-
- $store->set( "$post_id:$field_name:formatted", $value );
-
- return $value;
- }
- acf_add_filter_variations( 'acf/format_value', array( 'type', 'name', 'key' ), 2 );
- function acf_update_value( $value, $post_id, $field ) {
-
- $check = apply_filters( 'acf/pre_update_value', null, $value, $post_id, $field );
- if ( $check !== null ) {
- return $check;
- }
-
- $value = apply_filters( 'acf/update_value', $value, $post_id, $field, $value );
-
- if ( $value === null ) {
- return acf_delete_value( $post_id, $field );
- }
-
- $return = acf_update_metadata( $post_id, $field['name'], $value );
-
- acf_update_metadata( $post_id, $field['name'], $field['key'], true );
-
- acf_flush_value_cache( $post_id, $field['name'] );
-
- return $return;
- }
- acf_add_filter_variations( 'acf/update_value', array( 'type', 'name', 'key' ), 2 );
- function acf_update_values( $values, $post_id ) {
-
- foreach ( $values as $key => $value ) {
-
- $field = acf_get_field( $key );
-
- if ( $field ) {
- acf_update_value( $value, $post_id, $field );
- }
- }
- }
- function acf_flush_value_cache( $post_id = 0, $field_name = '' ) {
-
- acf_get_store( 'values' )
- ->remove( "$post_id:$field_name" )
- ->remove( "$post_id:$field_name:formatted" );
- }
- function acf_delete_value( $post_id, $field ) {
-
- do_action( 'acf/delete_value', $post_id, $field['name'], $field );
-
- $return = acf_delete_metadata( $post_id, $field['name'] );
-
- acf_delete_metadata( $post_id, $field['name'], true );
-
- acf_flush_value_cache( $post_id, $field['name'] );
-
- return $return;
- }
- acf_add_filter_variations( 'acf/delete_value', array( 'type', 'name', 'key' ), 2 );
- function acf_preview_value( $value, $post_id, $field ) {
-
- return apply_filters( 'acf/preview_value', $value, $post_id, $field );
- }
- acf_add_filter_variations( 'acf/preview_value', array( 'type', 'name', 'key' ), 2 );
- function acf_log_invalid_field_notice( $field, $function ) {
-
- if ( did_action( 'init' ) ) {
- return;
- }
- $error_text = sprintf(
- __( '<strong>%1$s</strong> - We\'ve detected one or more calls to retrieve ACF field values before ACF has been initialized. This is not supported and can result in malformed or missing data. <a href="%2$s" target="_blank">Learn how to fix this</a>.', 'acf' ),
- acf_get_setting( 'name' ),
- acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/acf-field-functions/', 'docs', 'early_init_warning' )
- );
- _doing_it_wrong( $function, $error_text, '5.11.1' );
- }
- add_action( 'acf/get_invalid_field_value', 'acf_log_invalid_field_notice', 10, 2 );
|