1 ) { $str = array_pop( $pieces ); } else { break; } } while ( $str ); return $chars; } /** * Disables wpautop behavior in classic editor when post contains blocks, to * prevent removep from invalidating paragraph blocks. * * @param array $settings Original editor settings. * @param string $editor_id ID for the editor instance. * @return array Filtered settings. */ function gutenberg_disable_editor_settings_wpautop( $settings, $editor_id ) { $post = get_post(); if ( 'content' === $editor_id && is_object( $post ) && has_blocks( $post ) ) { $settings['wpautop'] = false; } return $settings; } add_filter( 'wp_editor_settings', 'gutenberg_disable_editor_settings_wpautop', 10, 2 ); /** * Add rest nonce to the heartbeat response. * * @param array $response Original heartbeat response. * @return array New heartbeat response. */ function gutenberg_add_rest_nonce_to_heartbeat_response_headers( $response ) { $response['rest-nonce'] = wp_create_nonce( 'wp_rest' ); return $response; } add_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' ); /** * Check if we need to load the block warning in the Classic Editor. * * @since 3.4.0 */ function gutenberg_check_if_classic_needs_warning_about_blocks() { global $pagenow; if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) || ! isset( $_REQUEST['classic-editor'] ) ) { return; } $post = get_post(); if ( ! $post ) { return; } if ( ! has_blocks( $post ) ) { return; } // Enqueue the JS we're going to need in the dialog. wp_enqueue_script( 'wp-a11y' ); wp_enqueue_script( 'wp-sanitize' ); add_action( 'admin_footer', 'gutenberg_warn_classic_about_blocks' ); } add_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' ); /** * Adds a warning to the Classic Editor when trying to edit a post containing blocks. * * @since 3.4.0 */ function gutenberg_warn_classic_about_blocks() { $post = get_post(); $gutenberg_edit_link = get_edit_post_link( $post->ID, 'raw' ); $classic_edit_link = $gutenberg_edit_link; $classic_edit_link = add_query_arg( array( 'classic-editor' => '', 'hide-block-warning' => '', ), $classic_edit_link ); $revisions_link = ''; if ( wp_revisions_enabled( $post ) ) { $revisions = wp_get_post_revisions( $post ); // If there's only one revision, that won't help. if ( count( $revisions ) > 1 ) { reset( $revisions ); // Reset pointer for key(). $revisions_link = get_edit_post_link( key( $revisions ) ); } } ?>