WordPress 5.2 & ACF 5.8 Updates

This week was pretty busy in terms of updates. WordPress updates its core to version 5.2 and Advanced Custom Fields introduces its anticipated Block Type feature. Let’s take a look at what it changes for developers, and compatibility with ACF Extended.

WordPress 5.2 “Jaco”

WP Tavern described pretty well what’s new in this version. Most noticeable changes are: Site Health Check feature, PHP Fatal Error Recovery and the minimum PHP version bumping to 5.6.20.

The Site Health Check introduced a new data type in the wp_options table: Json data type. Adjustments have been made to the ACF Extended Options module to manage them easily.

Advanced Custom Fields 5.8

After two months of beta testing, ACF pushed the new 5.8 version packaged in ACF pro, codename “ACF Blocks”. It introduces the long awaited PHP block types for Gutenberg which brings a PHP framework to the Gutenberg block API.

The community has been very excited about it because JavaScript is not required to create blocks anymore. All ACF fields are compatible, including Repeater and Clones.

Block Type Declaration

The new function acf_register_block_type() is now available to create block types and is documented on the ACF website.

add_action('acf/init', 'acf_block_testimonial');
function acf_block_testimonial(){

    acf_register_block_type(array(
        'name'              => 'testimonial',
        'title'             => __('Testimonial'),
        'description'       => __('A custom testimonial block.'),
        'category'          => 'formatting',
        'render_template'   => 'blocks/testimonial/template.php',
        'enqueue_style'     => get_template_directory_uri() . '/blocks/testimonial/style.css',
        'enqueue_script'    => get_template_directory_uri() . '/blocks/testimonial/script.js'
    ));
    
}

Notable changes to functions & filters

If you’re using advanced ACF functions, you may noticed some changes to acf_match_location_rule(). It now requires three parameters $rule, $screen and a new one: $field_group. This parameter is then added to the filters acf/location/rule_match.

/*
 * advanced-custom-fields-pro/includes/locations.php:305
 */
function acf_match_location_rule( $rule, $screen, $field_group ) {

    // vars
    $result = false;

    // filter
    $result = apply_filters( "acf/location/match_rule/type={$rule['param']}", $result, $rule, $screen, $field_group );
    $result = apply_filters( "acf/location/match_rule", $result, $rule, $screen, $field_group );
    $result = apply_filters( "acf/location/rule_match/{$rule['param']}", $result, $rule, $screen, $field_group );
    $result = apply_filters( "acf/location/rule_match", $result, $rule, $screen, $field_group );

    // return
    return $result;

}