Useful Code Snippets for WordPress 6.0

Code Snippets WordPress 6.0

The WordPress 6.0, scheduled to be released on May 24th, 2022, will include several feature improvements.

WordPress 6.0

WordPress 6.0 - What's New!

Disable “Lock Blocks” in WordPress 6.0

When editing content using the block editor, a new UI element allows blocks to be locked to prevent changes from being made on a site, but there is a setting that can be used to disable block locking by user role, specific users, or globally.

To disable block locking globally on posts and pages then, you can use the following code snippet;

add_filter(
    'block_editor_settings_all',
    function( $settings, $context ) {
        
        // Disable for posts/pages.
        if ( $context->post && $context->post->post_type === 'page' ) {
            $settings['canLockBlocks'] = false;
        }
 
        return $settings;
    },
    10,
    2
);

Get Old WordPress Post Comments Block

There is now a comments block that will display the comments of a post. The legacy post comments block has been depreciated and is now hidden by default, but it can be set to be re-enabled using the following code snippet;

function wporg_enable_post_comments_legacy_block( $metadata ) {
    if ( 'core/post-comments' === $metadata['name'] ) {
        $metadata['title'] = esc_html__( 'Post Comments', 'textdomain' );
    $metadata['supports']['inserter'] = true;
    }
    return $metadata;
}

add_filter( 'block_type_metadata', 'wporg_enable_post_comments_legacy_block' );

WordPress 6.0 now allows the do_parse_request filter to be bypassed when return false is set, which will cut down on queries being run when not needed. The code snippet to set the do parse request filter as false;

add_filter( 'do_parse_request', '__return_false' );

WordPress 6.0 also includes several improvements and features that can not all be covered in this article; the field guide is the best way to read up on those.

Apply Changes to Selected Child Sites at Once

MainWP has a solid extension to save and execute code snippets on all or some of the connected Child Sites. The code snippets that have been saved to execute or, if no longer needed, can be removed on all connected Child Sites.

Use can find more useful code snippets in the MainWP community.

Useful links

Looking for something?

Privacy laws apply to businesses that collect personal information. Since no personal information is collected by the MainWP plugins, no privacy laws apply to the MainWP plugins. This includes GDPR, UK DPA 2018, PIPEDA, Australia Privacy Act 1988, LGPD, PIPL, and other privacy laws.
Donata Stroink-Skillrud
Donata Stroink-Skillrud
President of Agency Attorneys