Skip to content

Commit

Permalink
Add asetting to allow the JP site to be iframed by WordPress.com.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwight committed Mar 19, 2019
1 parent 00ad2ad commit 3589642
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 2 deletions.
1 change: 1 addition & 0 deletions _inc/client/components/navigation-settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const NavigationSettings = createReactClass( {
'infinite-scroll',
'minileven',
'copy-post',
'wordpress-com-compose',
] ) && (
<NavItem
path="#writing"
Expand Down
30 changes: 28 additions & 2 deletions _inc/client/writing/composing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,17 @@ export class Composing extends React.Component {
render() {
const foundCopyPost = this.props.isModuleFound( 'copy-post' ),
foundAtD = this.props.isModuleFound( 'after-the-deadline' ),
foundMarkdown = this.props.isModuleFound( 'markdown' );
foundMarkdown = this.props.isModuleFound( 'markdown' ),
foundWordPressComCompose = this.props.isModuleFound( 'wordpress-com-compose' );

if ( ! foundCopyPost && ! foundMarkdown && ! foundAtD ) {
if ( ! foundCopyPost && ! foundMarkdown && ! foundAtD && ! foundWordPressComCompose ) {
return null;
}

const markdown = this.props.module( 'markdown' ),
atd = this.props.module( 'after-the-deadline' ),
copyPost = this.props.module( 'copy-post' ),
wordPressComCompose = this.props.module( 'wordpress-com-compose' ),
unavailableInDevMode = this.props.isUnavailableInDevMode( 'after-the-deadline' ),
copyPostSettings = (
<SettingsGroup
Expand All @@ -233,6 +235,29 @@ export class Composing extends React.Component {
</FormFieldset>
</SettingsGroup>
),
wordPressComComposeSettings = (
<SettingsGroup
module={ wordPressComCompose }
support={ {
text: __( 'Allow new block editor posts to be composed on WordPress.com.' ),
link: 'https://jetpack.com/support/copy-post-2/',
} }
>
<FormFieldset>
<ModuleToggle
slug="wordpress-com-compose"
activated={ !! this.props.getOptionValue( 'wordpress-com-compose' ) }
toggling={ this.props.isSavingAnyOption( 'wordpress-com-compose' ) }
disabled={ this.props.isSavingAnyOption( 'wordpress-com-compose' ) }
toggleModule={ this.props.toggleModuleNow }
>
<span className="jp-form-toggle-explanation">
{ wordPressComCompose.description }
</span>
</ModuleToggle>
</FormFieldset>
</SettingsGroup>
),
markdownSettings = (
<SettingsGroup
module={ markdown }
Expand Down Expand Up @@ -300,6 +325,7 @@ export class Composing extends React.Component {
saveDisabled={ this.props.isSavingAnyOption( 'ignored_phrases' ) }
>
{ foundCopyPost && copyPostSettings }
{ foundWordPressComCompose && wordPressComComposeSettings }
{ foundMarkdown && markdownSettings }
{ foundAtD && atdSettings }
</SettingsCard>
Expand Down
7 changes: 7 additions & 0 deletions modules/module-headings.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ function jetpack_get_module_i18n( $key ) {
'name' => _x( 'Ads', 'Module Name', 'jetpack' ),
'description' => _x( 'Earn income by allowing Jetpack to display high quality ads.', 'Module Description', 'jetpack' ),
),

'wordpress-com-compose' => array(
'name' => _x( 'WordPress.com Compose', 'Module Name', 'jetpack' ),
'description' => _x( 'Allow new block editor posts to be composed on WordPress.com.', 'Module Description', 'jetpack' ),
'recommended description' => _x( 'Allow new block editor posts to be composed on WordPress.com.', 'Jumpstart Description', 'jetpack' ),
),
);
}
return $modules[ $key ];
Expand Down Expand Up @@ -272,6 +278,7 @@ function jetpack_get_module_i18n_tag( $key ) {
// - modules/markdown.php
// - modules/post-by-email.php
// - modules/shortcodes.php
// - modules/wordpress-com-compose.php
'Writing' =>_x( 'Writing', 'Module Tag', 'jetpack' ),

// Modules with `Photos and Videos` tag:
Expand Down
10 changes: 10 additions & 0 deletions modules/module-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,13 @@ function jetpack_more_info_copy_post() {
esc_html_e( 'Create a new post based on an existing post.', 'jetpack' );
}
add_action( 'jetpack_module_more_info_copy-post', 'jetpack_more_info_copy_post' );

function jetpack_wordpress_com_compose_more_link() {
echo 'https://jetpack.com/support/copy-post-2/';
}
add_action( 'jetpack_learn_more_button_wordpress-com-compose', 'jetpack_wordpress_com_compose_more_link' );

function jetpack_more_info_wordpress_com_compose() {
esc_html_e( 'WordPress.com Compose', 'jetpack' );
}
add_action( 'jetpack_module_more_info_wordpress-com-compose', 'jetpack_more_info_wordpress_com_compose' );
57 changes: 57 additions & 0 deletions modules/wordpress-com-compose.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Module Name: WordPress.com Compose
* Module Description: Allow new block editor posts to be composed on WordPress.com.
* Jumpstart Description: Allow new block editor posts to be composed on WordPress.com.
* Sort Order: 15
* First Introduced: 7.2
* Requires Connection: Yes
* Auto Activate: No
* Module Tags: Writing
* Feature: Writing
* Additional Search Queries: iframes, allow, compose, WordPress.com, block
*/

function jetpack_disable_send_frame_options_header() {
if ( jetpack_framing_allowed() ) {
remove_action( 'admin_init', 'send_frame_options_header' );
}
}
add_action( 'admin_init', 'jetpack_disable_send_frame_options_header', 1 ); // High priority to get ahead of send_frame_options_header

function jetpack_get_frame_nonce() {
return wp_create_nonce( 'frame-' . Jetpack_Options::get_option( 'id' ) );
}

function jetpack_framing_allowed() {
if ( empty( $_GET['frame-nonce'] ) ) {
return false;
}

$verified = wp_verify_nonce( $_GET['frame-nonce'], 'frame-' . Jetpack_Options::get_option( 'id' ) );

if ( $verified ) {
define( 'IFRAME_REQUEST', true );
return true;
}
return false;
}

/**
* Automatically add frame-nonce to any admin_url() calls when the current page is framed.
*/
function jetpack_auto_frame_nonce( $url ) {
if ( jetpack_framing_allowed() ) {
$url = add_query_arg( array( 'frame-nonce' => jetpack_get_frame_nonce() ), $url );
}
return $url;
}
add_filter( 'admin_url', 'jetpack_auto_frame_nonce' );

function jetpack_add_iframed_body_class( $classes ) {
if ( jetpack_framing_allowed() ) {
$classes .= ' is-iframed ';
}
return $classes;
}
add_filter( 'admin_body_class', 'jetpack_add_iframed_body_class' );

0 comments on commit 3589642

Please sign in to comment.