Block Gutenberg Editor manually by User Roles with a Filter with code

This is working perfectly for me but, is this an acceptable WP way to do it?

If it works and you didn’t modify core or internal WP private objects then the way you did it is fine.

I’m asking because somewhere I read you should not use wp_get_current_user for something like this but since it’s just a Filter, I thought it would be OK.

That’s not what you did though, and it’s likely a misinterpretation. The problem with wp_get_current_user is that if you call it too early it might not work.

Just trying to check that based on user role that the Gutenberg Editor blocked from showing up, like when creating a post, or page.

This is likely the issue though, it would be better to prevent all roles or no roles for maximum compatibility, especially since the editor is disabled conditionally, and plugins are expected to be written with the assumption of the block editor going forwards.

While there are issues with users opening posts edited with the block editor in the classic editor erasing HTML comments in the post content, you would need to ask in an ACF community if ACF has similar issues.

There is also the problem of new roles being added that would not be accounted for by the code. It would be better to have a list of roles that can access the block editor than a list of roles that can’t.

However, I see no reason not to whittle down the code to just this:

add_filter( 'use_block_editor_for_post', '__return_false' );

It would be more compatible, simpler, faster, and can be used in more places and earlier hooks.

error code: 521