From f69cdd53f800a40b524fe3cfbd88210d422a741f Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 28 Jan 2019 08:45:11 -0500 Subject: [PATCH] Plugin: Remove redundant core compatibility from plugin (#13442) --- .../backward-compatibility/deprecations.md | 6 + lib/compat.php | 268 ++---------------- 2 files changed, 33 insertions(+), 241 deletions(-) diff --git a/docs/designers-developers/developers/backward-compatibility/deprecations.md b/docs/designers-developers/developers/backward-compatibility/deprecations.md index 699dd190cd885f..b3a007565f0c85 100644 --- a/docs/designers-developers/developers/backward-compatibility/deprecations.md +++ b/docs/designers-developers/developers/backward-compatibility/deprecations.md @@ -38,6 +38,12 @@ The Gutenberg project's deprecation policy is intended to support backward compa - The `gutenberg` theme support option has been removed. Use [`align-wide`](https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/#wide-alignment) instead. - The PHP function `gutenberg_prepare_blocks_for_js` has been removed. Use [`get_block_editor_server_block_settings`](https://developer.wordpress.org/reference/functions/get_block_editor_server_block_settings/) instead. - The PHP function `gutenberg_load_list_reusable_blocks` has been removed. +- The PHP function `_gutenberg_utf8_split` has been removed. Use `_mb_substr` instead. +- The PHP function `gutenberg_disable_editor_settings_wpautop` has been removed. +- The PHP function `gutenberg_add_rest_nonce_to_heartbeat_response_headers` has been removed. +- The PHP function `gutenberg_check_if_classic_needs_warning_about_blocks` has been removed. +- The PHP function `gutenberg_warn_classic_about_blocks` has been removed. +- The PHP function `gutenberg_show_privacy_policy_help_text` has been removed. ## 4.5.0 - `Dropdown.refresh()` has been deprecated as the contained `Popover` is now automatically refreshed. diff --git a/lib/compat.php b/lib/compat.php index 03af8d9302af14..dc090cfe047de0 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -14,277 +14,67 @@ * Splits a UTF-8 string into an array of UTF-8-encoded codepoints. * * @since 0.5.0 + * @deprecated 5.0.0 _mb_substr * - * Based on WordPress' _mb_substr() compat function. - * - * @param string $str The string to split. - * @return array + * @param string $str The string to split. + * @return string Extracted substring. */ function _gutenberg_utf8_split( $str ) { - if ( _wp_can_use_pcre_u() ) { - // Use the regex unicode support to separate the UTF-8 characters into - // an array. - preg_match_all( '/./us', $str, $match ); - return $match[0]; - } - - $regex = '/( - [\x00-\x7F] # single-byte sequences 0xxxxxxx - | [\xC2-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx - | \xE0[\xA0-\xBF][\x80-\xBF] # triple-byte sequences 1110xxxx 10xxxxxx * 2 - | [\xE1-\xEC][\x80-\xBF]{2} - | \xED[\x80-\x9F][\x80-\xBF] - | [\xEE-\xEF][\x80-\xBF]{2} - | \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3 - | [\xF1-\xF3][\x80-\xBF]{3} - | \xF4[\x80-\x8F][\x80-\xBF]{2} - )/x'; - - // Start with 1 element instead of 0 since the first thing we do is pop. - $chars = array( '' ); - do { - // We had some string left over from the last round, but we counted it - // in that last round. - array_pop( $chars ); - - // Split by UTF-8 character, limit to 1000 characters (last array - // element will contain the rest of the string). - $pieces = preg_split( - $regex, - $str, - 1000, - PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY - ); - - $chars = array_merge( $chars, $pieces ); + _deprecated_function( __FUNCTION__, '5.0.0', '_mb_substr' ); - // If there's anything left over, repeat the loop. - if ( count( $pieces ) > 1 ) { - $str = array_pop( $pieces ); - } else { - break; - } - } while ( $str ); - - return $chars; + return _mb_substr( $str ); } /** * 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. + * @link https://core.trac.wordpress.org/ticket/45113 + * @link https://core.trac.wordpress.org/changeset/43758 + * @deprecated 5.0.0 + * + * @param array $settings Original editor settings. + * @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; - } +function gutenberg_disable_editor_settings_wpautop( $settings ) { + _deprecated_function( __FUNCTION__, '5.0.0' ); 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. + * @link https://core.trac.wordpress.org/ticket/45113 + * @link https://core.trac.wordpress.org/changeset/43939 + * @deprecated 5.0.0 + * + * @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' ); + _deprecated_function( __FUNCTION__, '5.0.0' ); + 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 + * @deprecated 5.0.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' ); + _deprecated_function( __FUNCTION__, '5.0.0' ); } -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 + * @deprecated 5.0.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 ) ); - } - } - ?> - - -
-
-
-
-

- -

- browse previous revisions and restore a version of the post before it was edited in Gutenberg.', 'gutenberg' ), esc_url( $revisions_link ) ); - ?> -

- -

- -
-

- - -

-
-
- - -