summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2020-01-06 14:32:30 -0500
committerAnthony G. Basile <blueness@gentoo.org>2020-01-06 14:32:30 -0500
commit10ef81bf85ad0a4bad0d204838e14c99ca2526f7 (patch)
treeb4bb36a326d41de12d1a6181d2a2baf34696ac24 /plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php
parentUpdating script for Update (diff)
downloadblogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.gz
blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.bz2
blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.zip
Update jetpack 8.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php')
-rw-r--r--plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php91
1 files changed, 76 insertions, 15 deletions
diff --git a/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php b/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php
index 7fe46fc4..b40dd837 100644
--- a/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php
+++ b/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php
@@ -41,7 +41,8 @@ class Jetpack_WPCOM_Block_Editor {
}
add_action( 'login_init', array( $this, 'allow_block_editor_login' ), 1 );
- add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts' ) );
+ add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts' ), 9 );
+ add_action( 'enqueue_block_assets', array( $this, 'enqueue_styles' ) );
add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugins' ) );
}
@@ -137,7 +138,7 @@ class Jetpack_WPCOM_Block_Editor {
*/
public function add_login_html() {
?>
- <input type="hidden" name="redirect_to" value="<?php echo esc_url( $_REQUEST['redirect_to'] ); ?>" />
+ <input type="hidden" name="redirect_to" value="<?php echo esc_url( $_REQUEST['redirect_to'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>" />
<script type="application/javascript">
document.getElementById( 'loginform' ).addEventListener( 'submit' , function() {
document.getElementById( 'wp-submit' ).setAttribute( 'disabled', 'disabled' );
@@ -151,7 +152,7 @@ class Jetpack_WPCOM_Block_Editor {
* Does the redirect to the block editor.
*/
public function do_redirect() {
- wp_redirect( $GLOBALS['redirect_to'] );
+ wp_safe_redirect( $GLOBALS['redirect_to'] );
exit;
}
@@ -265,7 +266,19 @@ class Jetpack_WPCOM_Block_Editor {
wp_enqueue_script(
'wpcom-block-editor-common',
$src_common,
- array( 'lodash', 'wp-compose', 'wp-data', 'wp-editor', 'wp-rich-text' ),
+ array(
+ 'jquery',
+ 'lodash',
+ 'wp-blocks',
+ 'wp-compose',
+ 'wp-data',
+ 'wp-dom-ready',
+ 'wp-editor',
+ 'wp-nux',
+ 'wp-plugins',
+ 'wp-polyfill',
+ 'wp-rich-text',
+ ),
$version,
true
);
@@ -285,16 +298,6 @@ class Jetpack_WPCOM_Block_Editor {
)
);
- $src_styles = $debug
- ? '//widgets.wp.com/wpcom-block-editor/common.css?minify=false'
- : '//widgets.wp.com/wpcom-block-editor/common.min.css';
- wp_enqueue_style(
- 'wpcom-block-editor-styles',
- $src_styles,
- array(),
- $version
- );
-
if ( $this->is_iframed_block_editor() ) {
$src_calypso_iframe_bridge = $debug
? '//widgets.wp.com/wpcom-block-editor/calypso-iframe-bridge-server.js?minify=false'
@@ -303,7 +306,18 @@ class Jetpack_WPCOM_Block_Editor {
wp_enqueue_script(
'wpcom-block-editor-calypso-iframe-bridge',
$src_calypso_iframe_bridge,
- array( 'calypsoify_wpadminmods_js', 'jquery', 'lodash', 'react', 'wp-blocks', 'wp-data', 'wp-hooks', 'wp-tinymce', 'wp-url' ),
+ array(
+ 'calypsoify_wpadminmods_js',
+ 'jquery',
+ 'lodash',
+ 'react',
+ 'wp-blocks',
+ 'wp-data',
+ 'wp-hooks',
+ 'wp-polyfill',
+ 'wp-tinymce',
+ 'wp-url',
+ ),
$version,
true
);
@@ -311,6 +325,53 @@ class Jetpack_WPCOM_Block_Editor {
}
/**
+ * Enqueue WP.com block editor common styles.
+ */
+ public function enqueue_styles() {
+ // Enqueue only for the block editor in WP Admin.
+ global $pagenow;
+ if ( is_admin() && ! in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
+ return;
+ }
+
+ // Enqueue on the front-end only if justified blocks are present.
+ if ( ! is_admin() && ! $this->has_justified_block() ) {
+ return;
+ }
+
+ $debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
+ $version = gmdate( 'Ymd' );
+
+ $src_styles = $debug
+ ? '//widgets.wp.com/wpcom-block-editor/common.css?minify=false'
+ : '//widgets.wp.com/wpcom-block-editor/common.min.css';
+ wp_enqueue_style(
+ 'wpcom-block-editor-styles',
+ $src_styles,
+ array(),
+ $version
+ );
+ }
+
+ /**
+ * Determines if the current $post contains a justified paragraph block.
+ *
+ * @return boolean true if justified paragraph is found, false otherwise.
+ */
+ public function has_justified_block() {
+ global $post;
+ if ( ! $post instanceof WP_Post ) {
+ return false;
+ };
+
+ if ( ! has_blocks( $post ) ) {
+ return false;
+ }
+
+ return false !== strpos( $post->post_content, '<!-- wp:paragraph {"align":"justify"' );
+ }
+
+ /**
* Register the Tiny MCE plugins for the WordPress.com block editor integration.
*
* @param array $plugin_array An array of external Tiny MCE plugins.