1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132 |
- <?php
- defined( 'ABSPATH' ) || exit;
- acf_register_store( 'block-types' );
- acf_register_store( 'block-cache' );
- add_filter( 'block_type_metadata', 'acf_add_block_namespace' );
- add_filter( 'block_type_metadata_settings', 'acf_handle_json_block_registration', 99, 2 );
- add_action( 'acf_block_render_template', 'acf_block_render_template', 10, 6 );
- function acf_add_block_namespace( $metadata ) {
- if ( acf_is_acf_block_json( $metadata ) ) {
-
- if ( strpos( $metadata['name'], '/' ) === false ) {
- $metadata['name'] = 'acf/' . acf_slugify( $metadata['name'] );
- }
- }
- return $metadata;
- }
- function acf_handle_json_block_registration( $settings, $metadata ) {
- if ( ! acf_is_acf_block_json( $metadata ) ) {
- return $settings;
- }
-
- $settings = wp_parse_args(
- $settings,
- array(
- 'render_template' => false,
- 'render_callback' => false,
- 'enqueue_style' => false,
- 'enqueue_script' => false,
- 'enqueue_assets' => false,
- 'post_types' => array(),
- 'uses_context' => array(),
- 'supports' => array(),
- 'attributes' => array(),
- 'acf_block_version' => 2,
- 'api_version' => 2,
- )
- );
-
- $settings['attributes'] = wp_parse_args(
- acf_get_block_type_default_attributes( $metadata ),
- $settings['attributes']
- );
-
- $settings['supports'] = wp_parse_args(
- $settings['supports'],
- array(
- 'align' => true,
- 'html' => false,
- 'mode' => true,
- 'jsx' => true,
- )
- );
-
- $settings['uses_context'] = array_unique(
- array_merge(
- $settings['uses_context'],
- array(
- 'postId',
- 'postType',
- )
- )
- );
-
- $property_mappings = array(
- 'renderCallback' => 'render_callback',
- 'renderTemplate' => 'render_template',
- 'mode' => 'mode',
- 'blockVersion' => 'acf_block_version',
- 'postTypes' => 'post_types',
- );
- $textdomain = ! empty( $metadata['textdomain'] ) ? $metadata['textdomain'] : 'acf';
- $i18n_schema = get_block_metadata_i18n_schema();
- foreach ( $property_mappings as $key => $mapped_key ) {
- if ( isset( $metadata['acf'][ $key ] ) ) {
- unset( $settings[ $key ] );
- $settings[ $mapped_key ] = $metadata['acf'][ $key ];
- if ( $textdomain && isset( $i18n_schema->$key ) ) {
- $settings[ $mapped_key ] = translate_settings_using_i18n_schema( $i18n_schema->$key, $settings[ $key ], $textdomain );
- }
- }
- }
-
- $settings['name'] = $metadata['name'];
- $settings['path'] = dirname( $metadata['file'] );
- acf_get_store( 'block-types' )->set( $metadata['name'], $settings );
- add_action( 'enqueue_block_editor_assets', 'acf_enqueue_block_assets' );
-
- $settings['render_callback'] = 'acf_render_block_callback';
- return $settings;
- }
- function acf_is_acf_block_json( $metadata ) {
- return ( isset( $metadata['acf'] ) && $metadata['acf'] );
- }
- function acf_register_block_type( $block ) {
-
- $block = acf_validate_block_type( $block );
-
- $block = apply_filters( 'acf/register_block_type_args', $block );
-
- if ( ! $block['name'] ) {
- $message = __( 'Block type name is required.', 'acf' );
- _doing_it_wrong( __FUNCTION__, $message, '5.8.0' );
- return false;
- }
-
- if ( acf_has_block_type( $block['name'] ) ) {
-
- $message = sprintf( __( 'Block type "%s" is already registered.', 'acf' ), $block['name'] );
- _doing_it_wrong( __FUNCTION__, $message, '5.8.0' );
- return false;
- }
-
- $block['attributes'] = acf_get_block_type_default_attributes( $block );
- if ( ! isset( $block['api_version'] ) ) {
- $block['api_version'] = 2;
- }
- if ( ! isset( $block['acf_block_version'] ) ) {
- $block['acf_block_version'] = 1;
- }
-
- acf_get_store( 'block-types' )->set( $block['name'], $block );
-
- $block['render_callback'] = 'acf_render_block_callback';
-
- if ( function_exists( 'register_block_type' ) ) {
- register_block_type(
- $block['name'],
- $block
- );
- }
-
- add_action( 'enqueue_block_editor_assets', 'acf_enqueue_block_assets' );
-
- return $block;
- }
- function acf_register_block( $block ) {
- return acf_register_block_type( $block );
- }
- function acf_has_block_type( $name ) {
- return acf_get_store( 'block-types' )->has( $name );
- }
- function acf_get_block_types() {
- return acf_get_store( 'block-types' )->get();
- }
- function acf_get_block_type( $name ) {
- return acf_get_store( 'block-types' )->get( $name );
- }
- function acf_remove_block_type( $name ) {
- acf_get_store( 'block-types' )->remove( $name );
- }
- function acf_get_block_type_default_attributes( $block_type ) {
- $attributes = array(
- 'name' => array(
- 'type' => 'string',
- 'default' => '',
- ),
- 'data' => array(
- 'type' => 'object',
- 'default' => array(),
- ),
- 'align' => array(
- 'type' => 'string',
- 'default' => '',
- ),
- 'mode' => array(
- 'type' => 'string',
- 'default' => '',
- ),
- );
- foreach ( acf_get_block_back_compat_attribute_key_array() as $new => $old ) {
- if ( isset( $block_type['supports'][ $old ] ) ) {
- $block_type['supports'][ $new ] = $block_type['supports'][ $old ];
- unset( $block_type['supports'][ $old ] );
- }
- }
- if ( ! empty( $block_type['supports']['alignText'] ) ) {
- $attributes['alignText'] = array(
- 'type' => 'string',
- 'default' => '',
- );
- }
- if ( ! empty( $block_type['supports']['alignContent'] ) ) {
- $attributes['alignContent'] = array(
- 'type' => 'string',
- 'default' => '',
- );
- }
- if ( ! empty( $block_type['supports']['fullHeight'] ) ) {
- $attributes['fullHeight'] = array(
- 'type' => 'boolean',
- 'default' => '',
- );
- }
-
- if ( isset( $block_type['attributes'] ) && is_array( $block_type['attributes'] ) ) {
- foreach ( array_keys( $attributes ) as $key ) {
- if ( isset( $block_type['attributes'][ $key ] ) && is_array( $block_type['attributes'][ $key ] ) && isset( $block_type['attributes'][ $key ]['default'] ) ) {
- $attributes[ $key ]['default'] = $block_type['attributes'][ $key ]['default'];
- }
- }
- }
- return $attributes;
- }
- function acf_validate_block_type( $block ) {
-
- $block = wp_parse_args(
- $block,
- array(
- 'name' => '',
- 'title' => '',
- 'description' => '',
- 'category' => 'common',
- 'icon' => '',
- 'mode' => 'preview',
- 'keywords' => array(),
- 'supports' => array(),
- 'post_types' => array(),
- 'uses_context' => array(),
- 'render_template' => false,
- 'render_callback' => false,
- 'enqueue_style' => false,
- 'enqueue_script' => false,
- 'enqueue_assets' => false,
- )
- );
-
- if ( acf_version_compare( 'wp', '<', '5.2' ) ) {
- $block['keywords'] = array_slice( $block['keywords'], 0, 3 );
- }
-
- if ( $block['name'] ) {
- $block['name'] = 'acf/' . acf_slugify( $block['name'] );
- }
-
- $block['supports'] = wp_parse_args(
- $block['supports'],
- array(
- 'align' => true,
- 'html' => false,
- 'mode' => true,
- )
- );
-
- $block['uses_context'] = wp_parse_args(
- $block['uses_context'],
- array(
- 'postId',
- 'postType',
- )
- );
-
- if ( isset( $block['supports']['__experimental_jsx'] ) ) {
- $block['supports']['jsx'] = $block['supports']['__experimental_jsx'];
- }
-
- return $block;
- }
- function acf_prepare_block( $block ) {
-
- if ( ! isset( $block['name'] ) ) {
- return false;
- }
-
- $block_type = acf_get_block_type( $block['name'] );
- if ( ! $block_type ) {
- return false;
- }
-
- $attributes = array();
- foreach ( acf_get_block_type_default_attributes( $block_type ) as $k => $v ) {
- $attributes[ $k ] = $v['default'];
- }
-
- $block = array_merge( $block_type, $attributes, $block );
-
- $block = acf_add_back_compat_attributes( $block );
-
- return $block;
- }
- function acf_add_back_compat_attributes( $block ) {
- foreach ( acf_get_block_back_compat_attribute_key_array() as $new => $old ) {
- if ( ! empty( $block[ $new ] ) || ( isset( $block[ $new ] ) && ! isset( $block[ $old ] ) ) ) {
- $block[ $old ] = $block[ $new ];
- }
- }
- return $block;
- }
- function acf_get_block_back_compat_attribute_key_array() {
- return array(
- 'fullHeight' => 'full_height',
- 'alignText' => 'align_text',
- 'alignContent' => 'align_content',
- );
- }
- function acf_render_block_callback( $attributes, $content = '', $wp_block = null ) {
- $is_preview = false;
- $post_id = get_the_ID();
-
- if ( is_admin() && acf_is_block_editor() ) {
- $is_preview = true;
- }
-
- return acf_rendered_block( $attributes, $content, $is_preview, $post_id, $wp_block );
- }
- function acf_rendered_block( $attributes, $content = '', $is_preview = false, $post_id = 0, $wp_block = null, $context = false ) {
- $mode = isset( $attributes['mode'] ) ? $attributes['mode'] : 'auto';
- $form = ( 'edit' === $mode && $is_preview );
-
- if ( empty( $context ) && ! empty( $wp_block->context ) ) {
- $context = $wp_block->context;
- }
-
- $attributes['id'] = acf_get_block_id( $attributes, $context );
-
- if ( $is_preview ) {
- $cached_block = acf_get_store( 'block-cache' )->get( $attributes['id'] );
- if ( $cached_block ) {
- if ( $form ) {
- if ( $cached_block['form'] ) {
- return $cached_block['html'];
- }
- } else {
- if ( ! $cached_block['form'] ) {
- return $cached_block['html'];
- }
- }
- }
- }
- ob_start();
- if ( $form ) {
-
-
- acf_set_data( 'acf_did_render_block_form', true );
- $block = acf_prepare_block( $attributes );
- acf_setup_meta( $block['data'], $block['id'], true );
- $fields = acf_get_block_fields( $block );
- if ( $fields ) {
- acf_prefix_fields( $fields, "acf-{$block['id']}" );
- echo '<div class="acf-block-fields acf-fields">';
- acf_render_fields( $fields, $block['id'], 'div', 'field' );
- echo '</div>';
- } else {
- echo acf_get_empty_block_form_html( $attributes['name'] );
- }
- } else {
-
- acf_render_block( $attributes, $content, $is_preview, $post_id, $wp_block, $context );
- }
- $html = ob_get_clean();
-
- if ( ! $is_preview || doing_action( 'acf_block_render_template' ) ) {
-
- $content = str_replace( '$', '\$', $content );
-
- if ( $wp_block && $wp_block->block_type->acf_block_version > 1 && apply_filters( 'acf/blocks/wrap_frontend_innerblocks', true, $attributes['name'] ) ) {
-
- $matches = array();
- if ( preg_match( '/<InnerBlocks(?:[^<]+?)(?:class|className)=(?:["\']\W+\s*(?:\w+)\()?["\']([^\'"]+)[\'"]/', $html, $matches ) ) {
- $class = isset( $matches[1] ) ? $matches[1] : 'acf-innerblocks-container';
- } else {
- $class = 'acf-innerblocks-container';
- }
- $content = '<div class="' . $class . '">' . $content . '</div>';
- }
- $html = preg_replace( '/<InnerBlocks([\S\s]*?)\/>/', $content, $html );
- }
-
- acf_get_store( 'block-cache' )->set(
- $attributes['id'],
- array(
- 'form' => $form,
- 'html' => $html,
- )
- );
-
- if ( $form && acf_get_data( 'acf_inside_rest_call' ) && apply_filters( 'acf/blocks/prevent_edit_forms_on_rest_endpoints', true ) ) {
- return '';
- }
- return $html;
- }
- function acf_render_block( $attributes, $content = '', $is_preview = false, $post_id = 0, $wp_block = null, $context = false ) {
-
- $block = acf_prepare_block( $attributes );
- if ( ! $block ) {
- return '';
- }
-
- if ( ! $post_id ) {
- $post_id = get_the_ID();
- }
-
- acf_enqueue_block_type_assets( $block );
-
- $block['id'] = acf_ensure_block_id_prefix( $block['id'] );
-
- acf_setup_meta( $block['data'], $block['id'], true );
-
- if ( is_callable( $block['render_callback'] ) ) {
- call_user_func( $block['render_callback'], $block, $content, $is_preview, $post_id, $wp_block, $context );
-
- } elseif ( $block['render_template'] ) {
- do_action( 'acf_block_render_template', $block, $content, $is_preview, $post_id, $wp_block, $context );
- }
-
- acf_reset_meta( $block['id'] );
- }
- function acf_block_render_template( $block, $content, $is_preview, $post_id, $wp_block, $context ) {
-
- if ( isset( $block['path'] ) && file_exists( $block['path'] . '/' . $block['render_template'] ) ) {
- $path = $block['path'] . '/' . $block['render_template'];
- } elseif ( file_exists( $block['render_template'] ) ) {
- $path = $block['render_template'];
- } else {
- $path = locate_template( $block['render_template'] );
- }
-
- if ( file_exists( $path ) ) {
- include $path;
- }
- }
- function acf_get_block_fields( $block ) {
-
- $fields = array();
-
- $field_groups = acf_get_field_groups(
- array(
- 'block' => $block['name'],
- )
- );
-
- if ( $field_groups ) {
- foreach ( $field_groups as $field_group ) {
- $fields = array_merge( $fields, acf_get_fields( $field_group ) );
- }
- }
-
- return $fields;
- }
- function acf_enqueue_block_assets() {
-
- acf_localize_text(
- array(
- 'Switch to Edit' => __( 'Switch to Edit', 'acf' ),
- 'Switch to Preview' => __( 'Switch to Preview', 'acf' ),
- 'Change content alignment' => __( 'Change content alignment', 'acf' ),
-
- '%s settings' => __( '%s settings', 'acf' ),
- )
- );
-
- $block_types = acf_get_block_types();
-
- acf_localize_data(
- array(
- 'blockTypes' => array_values( $block_types ),
- 'postType' => get_post_type(),
- )
- );
-
- $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
- if ( acf_version_compare( 'wp', '<', '5.6' ) ) {
- $blocks_js_path = acf_get_url( "assets/build/js/pro/acf-pro-blocks-legacy{$min}.js" );
- } else {
- $blocks_js_path = acf_get_url( "assets/build/js/pro/acf-pro-blocks{$min}.js" );
- }
- wp_enqueue_script( 'acf-blocks', $blocks_js_path, array( 'acf-input', 'wp-blocks' ), ACF_VERSION, true );
-
- array_map( 'acf_enqueue_block_type_assets', $block_types );
-
-
- if ( acf_get_setting( 'preload_blocks' ) ) {
- $preloaded_blocks = acf_get_store( 'block-cache' )->get_data();
- acf_localize_data(
- array(
- 'preloadedBlocks' => $preloaded_blocks,
- )
- );
- }
- }
- function acf_enqueue_block_type_assets( $block_type ) {
-
- $handle = 'block-' . acf_slugify( $block_type['name'] );
-
- if ( $block_type['enqueue_style'] ) {
- wp_enqueue_style( $handle, $block_type['enqueue_style'], array(), ACF_VERSION, 'all' );
- }
-
- if ( $block_type['enqueue_script'] ) {
- wp_enqueue_script( $handle, $block_type['enqueue_script'], array(), ACF_VERSION, true );
- }
-
- if ( $block_type['enqueue_assets'] && is_callable( $block_type['enqueue_assets'] ) ) {
- call_user_func( $block_type['enqueue_assets'], $block_type );
- }
- }
- function acf_ajax_fetch_block() {
-
- if ( ! acf_verify_ajax() ) {
- wp_send_json_error();
- }
-
- $args = acf_request_args(
- array(
- 'post_id' => 0,
- 'clientId' => null,
- 'query' => array(),
- )
- );
- $args['block'] = isset( $_REQUEST['block'] ) ? $_REQUEST['block'] : false;
- $args['context'] = isset( $_REQUEST['context'] ) ? $_REQUEST['context'] : array();
- $block = $args['block'];
- $query = $args['query'];
- $client_id = $args['clientId'];
- $raw_context = $args['context'];
- $post_id = $args['post_id'];
-
- if ( ! $block ) {
- wp_send_json_error();
- }
-
- $block = wp_unslash( $block );
- $block = json_decode( $block, true );
- $context = false;
- if ( ! empty( $raw_context ) ) {
- $raw_context = wp_unslash( $raw_context );
- $raw_context = json_decode( $raw_context, true );
- if ( is_array( $raw_context ) ) {
- $context = $raw_context;
-
- $post_id = isset( $context['postId'] ) ? intval( $context['postId'] ) : intval( $args['post_id'] );
- }
- }
-
- if ( empty( $block['id'] ) && ! empty( $client_id ) ) {
- $block['id'] = $client_id;
- }
-
- $block = acf_prepare_block( $block );
- if ( ! $block ) {
- wp_send_json_error();
- }
-
- if ( ! empty( $query['preview'] ) && ! $block['data'] ) {
- $fields = acf_get_block_fields( $block );
- foreach ( $fields as $field ) {
- $block['data'][ "_{$field['name']}" ] = $field['key'];
- }
- }
-
- acf_setup_meta( $block['data'], acf_ensure_block_id_prefix( $block['id'] ), true );
-
- global $post;
-
- $post = get_post( $post_id );
- setup_postdata( $post );
-
- $response = array( 'clientId' => $client_id );
-
- if ( ! empty( $query['form'] ) ) {
-
- $fields = acf_get_block_fields( $block );
-
- acf_prefix_fields( $fields, "acf-{$block['id']}" );
- if ( $fields ) {
-
- ob_start();
-
- echo '<div class="acf-block-fields acf-fields">';
- acf_render_fields( $fields, acf_ensure_block_id_prefix( $block['id'] ), 'div', 'field' );
- echo '</div>';
-
- $response['form'] = ob_get_clean();
- } else {
-
- $response['form'] = acf_get_empty_block_form_html( $block['name'] );
- }
- }
-
- if ( ! empty( $query['preview'] ) ) {
-
- $content = '';
- $is_preview = true;
-
- $response['preview'] = acf_rendered_block( $block, $content, $is_preview, $post_id, null, $context );
- }
-
- wp_send_json_success( $response );
- }
- acf_register_ajax( 'fetch-block', 'acf_ajax_fetch_block' );
- function acf_get_empty_block_form_html( $block_name ) {
- $message = __( 'This block contains no editable fields.', 'acf' );
- if ( acf_current_user_can_admin() ) {
- $message .= ' ';
- $message .= sprintf(
-
- __( 'Assign a <a href="%s" target="_blank">field group</a> to add fields to this block.', 'acf' ),
- admin_url( 'edit.php?post_type=acf-field-group' )
- );
- }
- $message = apply_filters( 'acf/blocks/no_fields_assigned_message', $message, $block_name );
- return empty( $message ) ? '' : acf_esc_html( '<div class="acf-block-fields acf-fields acf-empty-block-fields">' . $message . '</div>' );
- }
- function acf_parse_save_blocks( $text = '' ) {
-
- return addslashes(
- preg_replace_callback(
- '/<!--\s+wp:(?P<name>[\S]+)\s+(?P<attrs>{[\S\s]+?})\s+(?P<void>\/)?-->/',
- 'acf_parse_save_blocks_callback',
- stripslashes( $text )
- )
- );
- }
- add_filter( 'content_save_pre', 'acf_parse_save_blocks', 5, 1 );
- function acf_parse_save_blocks_callback( $matches ) {
-
- $name = isset( $matches['name'] ) ? $matches['name'] : '';
- $attrs = isset( $matches['attrs'] ) ? json_decode( $matches['attrs'], true ) : '';
- $void = isset( $matches['void'] ) ? $matches['void'] : '';
-
- if ( ! $name || ! $attrs || ! acf_has_block_type( $name ) ) {
- return $matches[0];
- }
-
- $block_id = acf_get_block_id( $attrs );
-
-
- if ( isset( $attrs['data'] ) ) {
- $attrs['data'] = acf_setup_meta( $attrs['data'], acf_ensure_block_id_prefix( $block_id ) );
- }
-
- $attrs = apply_filters( 'acf/pre_save_block', $attrs );
-
- $attrs = acf_serialize_block_attributes( $attrs );
- return '<!-- wp:' . $name . ' ' . $attrs . ' ' . $void . '-->';
- }
- function acf_get_block_id( $attributes, $context = array() ) {
- $attributes['_acf_context'] = $context;
- if ( empty( $attributes['id'] ) ) {
- unset( $attributes['id'] );
-
- foreach ( $attributes as $key => $value ) {
- if ( '' === $value ) {
- unset( $attributes[ $key ] );
- }
- }
-
- if ( isset( $attributes['data'] ) && empty( $attributes['data'] ) ) {
- unset( $attributes['data'] );
- }
- ksort( $attributes );
- return md5( wp_json_encode( $attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
- }
- return $attributes['id'];
- }
- function acf_ensure_block_id_prefix( $block_id ) {
- if ( substr( $block_id, 0, 6 ) === 'block_' ) {
- return $block_id;
- }
- return 'block_' . $block_id;
- }
- function acf_serialize_block_attributes( $block_attributes ) {
- $encoded_attributes = wp_json_encode( $block_attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
- $encoded_attributes = preg_replace( '/--/', '\\u002d\\u002d', $encoded_attributes );
- $encoded_attributes = preg_replace( '/</', '\\u003c', $encoded_attributes );
- $encoded_attributes = preg_replace( '/>/', '\\u003e', $encoded_attributes );
- $encoded_attributes = preg_replace( '/&/', '\\u0026', $encoded_attributes );
-
- $encoded_attributes = preg_replace( '/\\\\"/', '\\u0022', $encoded_attributes );
- return $encoded_attributes;
- }
- function acf_set_after_rest_media_enqueue_reset_flag( $response ) {
- global $wp_actions;
- acf_set_data( 'acf_inside_rest_call', true );
- acf_set_data( 'acf_should_reset_media_enqueue', empty( $wp_actions['wp_enqueue_media'] ) );
- acf_set_data( 'acf_did_render_block_form', false );
- return $response;
- }
- add_filter( 'rest_request_before_callbacks', 'acf_set_after_rest_media_enqueue_reset_flag' );
- function acf_reset_media_enqueue_after_rest( $response ) {
- acf_set_data( 'acf_inside_rest_call', false );
- if ( acf_get_data( 'acf_should_reset_media_enqueue' ) && acf_get_data( 'acf_did_render_block_form' ) ) {
- global $wp_actions;
-
- $wp_actions['wp_enqueue_media'] = 0;
- }
- return $response;
- }
- add_filter( 'rest_request_after_callbacks', 'acf_reset_media_enqueue_after_rest' );
|