Skip to content

Commit

Permalink
Use a query argument instead of a cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jun 13, 2023
1 parent b7c8632 commit 896f8cf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function gutenberg_register_packages_scripts( $scripts ) {
case 'wp-block-library':
if (
! gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ||
isset( $_COOKIE['requiresTinymce'] ) ||
! empty( $_GET['requiresTinymce'] ) ||
gutenberg_current_content_contains_classic_block()
) {
array_push( $dependencies, 'editor' );
Expand Down
6 changes: 3 additions & 3 deletions lib/experimental/assets/tinymce-proxy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
async function markAsRequiringTinymce() {
const expiration = new Date( 'Dec 31, 2099 23:59:59' );
document.cookie = `requiresTinymce=1; expires=${ expiration }; path=/`;
window.location.reload();
const currentUrl = new URL( window.location.href );
currentUrl.searchParams.set( 'requiresTinymce', '1' );
window.location.href = currentUrl;
}

window.tinymce = new Proxy(
Expand Down
4 changes: 2 additions & 2 deletions lib/experimental/disable-tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function gutenberg_declare_classic_block_necessary() {
add_action( 'admin_footer', 'gutenberg_declare_classic_block_necessary' );

// If user has already requested TinyMCE, we're ending the experiment.
if ( isset( $_COOKIE['requiresTinymce'] ) || gutenberg_current_content_contains_classic_block() ) {
if ( ! empty( $_GET['requiresTinymce'] ) || gutenberg_current_content_contains_classic_block() ) {
return;
}

Expand All @@ -35,7 +35,7 @@ function gutenberg_disable_tinymce() {

/**
* Enqueue TinyMCE proxy script.
* Detects TinyMCE usage and sets the `requiresTinymce` cookie to stop disabling TinyMCE loading.
* 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__ ) );
Expand Down
9 changes: 4 additions & 5 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,14 @@ const getAllBlocks = () => {
// and when either of the following is true:
// - TinyMCE experiment is disabled;
// - there is a classic block in the current post's content;
// - the cookie to require TinyMCE is set.
// - the query argument to require TinyMCE is set.
if (
window?.wp?.oldEditor &&
( window?.wp?.needsClassicBlock ||
! window?.__experimentalDisableTinymce ||
( '; ' + document.cookie )
.split( '; requiresTinymce=' )
.pop()
.split( ';' )[ 0 ] )
!! new URLSearchParams( window?.location?.search ).get(
'requiresTinymce'
) )
) {
blocks.push( classic );
}
Expand Down

0 comments on commit 896f8cf

Please sign in to comment.