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

Add notice about visibility in feeds to post edit screen when site is in Coming Soon mode #546

Open
wants to merge 7 commits into
base: production
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function __construct() {
add_filter( 'rest_request_before_callbacks', array( $this, 'disable_rest_endpoints' ), 99, 3 );
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu_item' ), 1000 );
add_action( 'admin_head', array( $this, 'admin_bar_styling' ) );
add_action( 'admin_footer', array( $this, 'maybe_show_block_editor_notice' ) );
add_action( 'wp_head', array( $this, 'admin_bar_styling' ) );
add_action( 'admin_notices', array( $this, 'block_new_post_admin_notice' ) );
add_filter( 'get_post_metadata', array( $this, 'jetpack_dont_email_post_to_subs' ), 10, 4 );
Expand Down Expand Up @@ -92,7 +93,7 @@ public function render_dynamic_styles() {
return;
}

// TODO: Figure out an alternative here.
// TODO: Figure out an alternative here.
//phpcs:ignore WordPress.PHP.DontExtract.extract_extract -- Not sure whats the alternative to this could be.
extract( $GLOBALS['WordCamp_Coming_Soon_Page']->get_template_variables() );

Expand Down Expand Up @@ -429,6 +430,17 @@ public function admin_bar_styling() {
<?php
}

/**
* Get the message maybe shown in editor views.
* NB! Block editor notices do not support HTML and all tags will be removed.
*/
public function get_notice_message() {
return sprintf(
__( '<a href="%s">Coming Soon mode</a> is enabled. <b>Published posts will be visible on RSS feed and WordPress.org profile feeds.</b> Site subscribers will not receive email notifications about published posts. Published posts will not be automatically cross-posted to social media accounts.', 'wordcamporg' ),
esc_url( $setting_url )
);
}

/**
* Show a notice if Coming Soon is enabled.
*
Expand All @@ -453,10 +465,7 @@ public function block_new_post_admin_notice() {

if ( 'post' === trim( $screen->id ) ) {
$class = 'notice notice-warning';
$message = sprintf(
__( '<a href="%s">Coming Soon mode</a> is enabled. Site subscribers will not receive email notifications about published posts. Published posts will not be automatically cross-posted to social media accounts.', 'wordcamporg' ),
esc_url( $setting_url )
);
$message = $this->get_notice_message();

if ( ! current_user_can( 'manage_options' ) ) {
$message = wp_strip_all_tags( $message );
Expand All @@ -466,6 +475,31 @@ public function block_new_post_admin_notice() {
}
}

/**
* Show a notice if Coming Soon is enabled also in Gutenberg block editor.
*/
public function maybe_show_block_editor_notice() {
timiwahalahti marked this conversation as resolved.
Show resolved Hide resolved
$settings = $GLOBALS['WCCSP_Settings']->get_settings();

if ( 'on' !== $settings['enabled'] ) {
return;
}

$message = $this->get_notice_message(); ?>

<script type="text/javascript">
( function( wp ) {
wp.data.dispatch( 'core/notices' ).createNotice(
timiwahalahti marked this conversation as resolved.
Show resolved Hide resolved
'warning',
'<?php echo esc_html( wp_strip_all_tags( $message ) ); ?>',
{
isDismissible: false,
}
);
} )( window.wp );
</script>
<?php }

/**
* Disable sending of Jetpack emails when Coming Soon mode is on.
*
Expand Down