• Hello, I need all blocks in field block.

    <?php

    if ( ! function_exists( 'get_prefix_css' ) ) {
    function get_prefix_css( $css,$prefix ) {
    # Wipe all block comments
    $css = preg_replace('!/\*.*?\*/!s', '', $css);

    $parts = explode( '}', $css);
    $keyframeStarted = false;
    $mediaQueryStarted = false;

    foreach( $parts as &$part ) {

    $part = trim( $part ); # Wht not trim immediately .. ?
    if ( empty( $part ) ) {
    $keyframeStarted = false;
    continue;
    } else {
    $partDetails = explode( '{', $part );

    if (strpos( $part, 'keyframes') !== false ) {
    $keyframeStarted = true;
    continue;
    }

    if ( $keyframeStarted) {
    continue;
    }

    if ( substr_count( $part, "{" )==2) {
    $mediaQuery = $partDetails[0] . "{";
    $partDetails[0] = $partDetails[1];
    $mediaQueryStarted = true;
    }

    $subParts = explode( ',', $partDetails[0] );
    foreach( $subParts as &$subPart ) {
    if ( trim( $subPart ) === "@font-face" ) continue;
    else $subPart = $prefix . ' ' . trim( $subPart );
    }

    if ( substr_count( $part, "{" ) == 2 ) {
    $part = $mediaQuery . "\n" . implode( ', ', $subParts ) . "{".$partDetails[2];
    } elseif ( empty( $part[0] ) && $mediaQueryStarted ) {
    $mediaQueryStarted = false;
    $part = implode( ', ', $subParts) . "{" . $partDetails[2] . "}\n"; //finish media query
    } else {
    if ( isset( $partDetails[1] ) ) {
    # Sometimes, without this check,
    # there is an error-notice, we don't need that..
    $part = implode( ', ', $subParts ) . "{" . $partDetails[1];
    }
    }

    unset( $partDetails, $mediaQuery, $subParts ); # Kill those three ..
    } unset( $part ); # Kill this one as well
    }

    # Finish with the whole new prefixed string/file in one line
    return(preg_replace( '/\s+/',' ',implode("} ", $parts ) ));
    }
    }


    add_filter( 'acfe/fields/block_editor/settings', 'core_plugin_acfe_fields_block_editor_settings', 10, 2 );
    function core_plugin_acfe_fields_block_editor_settings( $settings, $field ) {

    if ( count( $settings['iso']['blocks']['allowBlocks'] ) < 12 ) {
    $settings['iso']['blocks']['allowBlocks'] = array_values( array_map( function( $block ) {
    return $block->name;
    }, WP_Block_Type_Registry::get_instance()->get_all_registered() ) );
    }

    foreach( $settings['editor']['styles'] as $k => $style ) {
    $settings['editor']['styles'][ $k ]['css'] = get_prefix_css( $style['css'], '#wpbody-content .editor-styles-wrapper' );
    }

    add_action( 'admin_footer', function() use ( $settings ) {

    if ( did_action( current_filter() ) === 1 ) :

    $styles = join( '', array_map(function( $style ) {
    return $style['css'];
    }, $settings['editor']['styles'] ) );

    ?>
    <style>
    #edittag {
    max-width: inherit;
    }
    <?php echo str_replace(
    '.editor-styles-wrapper body',
    '.editor-styles-wrapper ',
    $styles
    ); ?>
    </style>
    <?php
    endif;
    } );

    return $settings;
    }


    ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Block field with all blocks’ is closed to new replies.