Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calypsoify: Add support for switching to Classic when iframing the block editor. #12163

Merged
merged 4 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions modules/calypsoify/class.jetpack-calypsoify.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
<?php
/*
/**
* This is Calypso skin of the wp-admin interface that is conditionally triggered via the ?calypsoify=1 param.
* Ported from an internal Automattic plugin.
*/

*/
class Jetpack_Calypsoify {
static $instance = false;

/**
* Singleton instance of `Jetpack_Calypsoify`.
*
* @var object
*/
public static $instance = false;

/**
* Is Calypsoify enabled, based on any value of `calypsoify` user meta.
*
* @var bool
*/
public $is_calypsoify_enabled = false;

private function __construct() {
add_action( 'wp_loaded', array( $this, 'setup' ) );
Expand All @@ -20,9 +32,10 @@ public static function getInstance() {
}

public function setup() {
$this->is_calypsoify_enabled = 1 == (int) get_user_meta( get_current_user_id(), 'calypsoify', true );
add_action( 'admin_init', array( $this, 'check_param' ), 4 );

if ( 1 == (int) get_user_meta( get_current_user_id(), 'calypsoify', true ) ) {
if ( $this->is_calypsoify_enabled ) {
add_action( 'admin_init', array( $this, 'setup_admin' ), 6 );
}

Expand Down Expand Up @@ -369,6 +382,19 @@ public function get_close_gutenberg_url() {
return $this->get_calypso_url();
}

/**
* Returns the URL for switching the user's editor to the Calypso (WordPress.com Classic) editor.
*
* @return string
*/
public function get_switch_to_classic_editor_url() {
return add_query_arg(
'set-editor',
'classic',
$this->is_calypsoify_enabled ? $this->get_calypso_url( get_the_ID() ) : false
kwight marked this conversation as resolved.
Show resolved Hide resolved
);
}

public function check_param() {
if ( isset( $_GET['calypsoify'] ) ) {
if ( 1 == (int) $_GET['calypsoify'] ) {
Expand Down
10 changes: 5 additions & 5 deletions modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ public function filter_salt( $salt, $scheme ) {
* Enqueue the scripts for the WordPress.com block editor integration.
*/
public function enqueue_scripts() {
$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$version = gmdate( 'YW' );
$is_calypsoify = 1 === (int) get_user_meta( get_current_user_id(), 'calypsoify', true );
$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$version = gmdate( 'YW' );

$src_common = $debug
? '//widgets.wp.com/wpcom-block-editor/common.js?minify=false'
Expand All @@ -215,9 +214,10 @@ public function enqueue_scripts() {
'wpcomGutenberg',
array(
'switchToClassic' => array(
'isVisible' => false,
'isVisible' => $this->is_iframed_block_editor(),
'label' => __( 'Switch to Classic Editor', 'jetpack' ),
kwight marked this conversation as resolved.
Show resolved Hide resolved
'url' => Jetpack_Calypsoify::getInstance()->get_switch_to_classic_editor_url(),
kwight marked this conversation as resolved.
Show resolved Hide resolved
),
'isCalypsoify' => $is_calypsoify,
'richTextToolbar' => array(
'justify' => __( 'Justify', 'jetpack' ),
'underline' => __( 'Underline', 'jetpack' ),
Expand Down