acf-extended / ACF-Extended

🚀 All-in-one enhancement suite that improves WordPress & Advanced Custom Fields
https://www.acf-extended.com
239 stars 27 forks source link

ACF Extended Block type Enqueu assets GUI #92

Closed hik200 closed 3 years ago

hik200 commented 3 years ago

Describe the bug How to work ACF-Extended block type editor in GUI rather enqueue assets.

To Reproduce Go to ACF menu-> Block Type -> Enqueu->Enqueu assets.

Expected behavior Unknow

Screenshots If applicable, add screenshots to help explain your problem. image

WordPress & ACF WordPress version: 5.8.2 ACF Pro version: 5.10.0 ACF add-ons: ACF Extened 0.8.8.6

No see any useful instruction about this field. Or better make some kind "+" button in style and script tab of this section. The issue may resolve by adding some filter in function but I don't understand how to work with GUI option.

add_filter('acf/register_block_type_args', 'my_acf_register_block_type_args');
function my_acf_register_block_type_args($args){
    if($args['name'] == 'acf/two-column') { 
        $args['enqueue_assets'] = function (){
            wp_enqueue_script( 'bgtest2-swiper', get_template_directory_uri() . '/js/swiper/swiper-bundle.js', array(), _S_VERSION, true );
            wp_enqueue_script( 'block-swiper-carousle', get_template_directory_uri() . '/js/scripts/swiper-carousel.js', array(), '', true );
        };

    }
    return $args;
}
acf-extended commented 3 years ago

Hello,

Thanks for the feedback!

The Block Type UI is just an UI that use acf_register_block_type() behind the scene. As explained in the ACF documentation:

_enqueue_assets (Callable) (Optional) A callback function that runs whenever your block is displayed (front-end and back-end) and enqueues scripts and/or styles._

So for example, in the Block Type UI you can set Enqueue Assets = my_block_type_assets, and then add in your functions.php file:

function my_block_type_assets(){
    wp_enqueue_script( 'bgtest2-swiper', get_template_directory_uri() . '/js/swiper/swiper-bundle.js', array(), _S_VERSION, true );
    wp_enqueue_script( 'block-swiper-carousle', get_template_directory_uri() . '/js/scripts/swiper-carousel.js', array(), '', true );
}

Hope it helps!

Have a nice day!

Regards.