Skip to content

Commit

Permalink
Fix: Potential fatal error if Block Compatibility is off (#1272)
Browse files Browse the repository at this point in the history
* Fix undeclared class error

* Update docblock

---------

Co-authored-by: xxsimoxx <simone@gieffeedizioni.it>
  • Loading branch information
xxsimoxx and xxsimoxx committed Dec 14, 2023
1 parent a34a158 commit e63b63f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/wp-admin/includes/class-wp-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ public function in_admin( $admin = null ) {
* @return bool False.
*/
public function is_block_editor( ...$args ) {
WP_Compat::using_block_function();
if ( class_exists( 'WP_Compat' ) ) {
WP_Compat::using_block_function();
}
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/wp-includes/classicpress/class-wp-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public function delete_themes_using_blocks() {
* This function have to be called from a polyfill
* to map themes and plugins calling those functions.
*
* Make sure that class WP_Compat exists before calling the function
* because it's not defined if Blocks Compatibility option is set to "off".
*
* @return void
*/
public static function using_block_function() {
Expand Down
8 changes: 6 additions & 2 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7822,7 +7822,9 @@ function wp_untrash_post_set_previous_status( $new_status, $post_id, $previous_s
* @return bool Whether the post can be edited in the block editor.
*/
function use_block_editor_for_post( $post ) {
WP_Compat::using_block_function();
if ( class_exists( 'WP_Compat' ) ) {
WP_Compat::using_block_function();
}
return false;
}

Expand All @@ -7839,6 +7841,8 @@ function use_block_editor_for_post( $post ) {
* @return bool Whether the post type can be edited with the block editor.
*/
function use_block_editor_for_post_type( $post_type ) {
WP_Compat::using_block_function();
if ( class_exists( 'WP_Compat' ) ) {
WP_Compat::using_block_function();
}
return false;
}

0 comments on commit e63b63f

Please sign in to comment.