-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try: Aggressive TinyMCE deprecation (#50387)
* Add experiment setting field * Set a global when experiment enabled * Load Classic block only when experiment is not enabled * Do not enqueue any TinyMCE assets if experiment is enabled * Do not enqueue editor if experiment enabled * Set and utilize a cookie when tinymce is requested * Safeer cookie access on the server side * Add a script to force TinyMCE usage for testing * Move experiment toggle to the higheest priority * Add PHP comments and fix coding standards * Rename class file * More CS * Use gutenberg_is_experiment_enabled() * Cleanup lines from rebase * Backend detection of classic block instances * Comment the cookie testing code again * Fix code style * Consider the freeform block, or any raw HTML to be Unknown block * Proper post object existence testing * Register classic block if server declares it's needed * A custom message when converting from classic block * Improve content length check `empty()` will return `true` if we pass the '0' string. * Expand comment on classic block registration * Move example TinyMCE usage code up * Use a query argument instead of a cookie * Rename proxy trap * Fix the comment * Rename another function * Improve the classic block load conditions comment * Further polish the conditions comment * Fix a fatal in the wp-admin dashboard
- Loading branch information
Showing
9 changed files
with
203 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
async function reloadWithTinymce() { | ||
const currentUrl = new URL( window.location.href ); | ||
currentUrl.searchParams.set( 'requiresTinymce', '1' ); | ||
window.location.href = currentUrl; | ||
} | ||
|
||
window.tinymce = new Proxy( | ||
{}, | ||
{ | ||
get: reloadWithTinymce, | ||
set: reloadWithTinymce, | ||
apply: reloadWithTinymce, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Contains the placeholder class to replace the default `_WP_Editors`. | ||
* | ||
* @package gutenberg | ||
* @since 6.3.0 | ||
*/ | ||
|
||
// phpcs:disable PEAR.NamingConventions.ValidClassName.StartWithCapital | ||
|
||
/** | ||
* Placeholder class. | ||
* Used to disable loading of TinyMCE assets. | ||
* | ||
* @access public | ||
*/ | ||
final class _WP_Editors { | ||
/** | ||
* Necessary to ensure no additional TinyMCE assets are enqueued. | ||
*/ | ||
public static function enqueue_default_editor() {} | ||
|
||
/** | ||
* Necessary for wp admin dashboard. | ||
*/ | ||
public static function editor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* Experiment to disable TinyMCE and the Classic block. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
// add_action( 'admin_footer', 'gutenberg_test_tinymce_access' ); // Uncomment the following line to force an external TinyMCE usage. | ||
|
||
/** | ||
* Render a variable that we'll use to declare that the editor will need the classic block. | ||
*/ | ||
function gutenberg_declare_classic_block_necessary() { | ||
if ( ! gutenberg_post_being_edited_requires_classic_block() ) { | ||
return; | ||
} | ||
echo '<script type="text/javascript">window.wp.needsClassicBlock = true;</script>'; | ||
} | ||
add_action( 'admin_footer', 'gutenberg_declare_classic_block_necessary' ); | ||
|
||
// If user has already requested TinyMCE, we're ending the experiment. | ||
if ( ! empty( $_GET['requiresTinymce'] ) || gutenberg_post_being_edited_requires_classic_block() ) { | ||
return; | ||
} | ||
|
||
|
||
/** | ||
* Disable TinyMCE by introducing a placeholder `_WP_Editors` class. | ||
*/ | ||
function gutenberg_disable_tinymce() { | ||
require __DIR__ . '/class--wp-editors.php'; | ||
} | ||
|
||
add_action( 'admin_init', 'gutenberg_disable_tinymce' ); | ||
|
||
/** | ||
* Enqueue TinyMCE proxy script. | ||
* Detects TinyMCE usage and sets the `requiresTinymce` query argument to stop disabling TinyMCE loading. | ||
*/ | ||
function gutenberg_enqueue_tinymce_proxy() { | ||
wp_enqueue_script( 'gutenberg-tinymce-proxy', plugins_url( 'assets/tinymce-proxy.js', __FILE__ ) ); | ||
} | ||
|
||
add_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_tinymce_proxy' ); | ||
|
||
/** | ||
* Example TinyMCE usage used for testing. | ||
* Uncomment line 8 in this file to enable. | ||
*/ | ||
function gutenberg_test_tinymce_access() { | ||
echo '<script type="text/javascript">const a = window.tinymce.$;</script>'; | ||
} | ||
|
||
/** | ||
* Whether the current editor contains a classic block instance. | ||
* | ||
* @return bool True if the editor contains a classic block, false otherwse. | ||
*/ | ||
function gutenberg_post_being_edited_requires_classic_block() { | ||
if ( ! is_admin() ) { | ||
return false; | ||
} | ||
|
||
// Handle the post editor. | ||
if ( ! empty( $_GET['post'] ) && ! empty( $_GET['action'] ) && 'edit' === $_GET['action'] ) { | ||
$current_post = get_post( intval( $_GET['post'] ) ); | ||
if ( ! $current_post || is_wp_error( $current_post ) ) { | ||
return false; | ||
} | ||
|
||
$content = $current_post->post_content; | ||
} | ||
|
||
if ( empty( $content ) ) { | ||
return false; | ||
} | ||
|
||
$parsed_blocks = parse_blocks( $content ); | ||
foreach ( $parsed_blocks as $block ) { | ||
if ( empty( $block['blockName'] ) && strlen( trim( $block['innerHTML'] ) ) > 0 ) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b819f63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in b819f63.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5443493909
📝 Reported issues:
/test/e2e/specs/editor/various/a11y-region-navigation.spec.js
specs/editor/various/autosave.test.js