Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: newfold-labs/wp-module-coming-soon
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.2.4
Choose a base ref
...
head repository: newfold-labs/wp-module-coming-soon
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ Coming Soon functionality for WordPress.

### 1. Bump Version

Update the module versions in the `bootstrap.php` file (the NFD_COMING_SOON_MODULE_VERSION const) and in the `package.json` file (the package version).
Update the module versions in the `bootstrap.php` file (the NFD_COMING_SOON_MODULE_VERSION const) and in the `package.json` file (the package version). Alternatively, run the set-version-bump script to update the versions for you: `npm run set-version-bump`.

### 2. Build

2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
return;
}

define( 'NFD_COMING_SOON_MODULE_VERSION', '1.2.3' );
define( 'NFD_COMING_SOON_MODULE_VERSION', '1.3.5' );

require __DIR__ . '/includes/functions.php';

1 change: 0 additions & 1 deletion build/1.2.3/coming-soon.asset.php

This file was deleted.

1 change: 0 additions & 1 deletion build/1.2.3/coming-soon.css

This file was deleted.

1 change: 0 additions & 1 deletion build/1.2.3/coming-soon.js

This file was deleted.

1 change: 1 addition & 0 deletions build/1.3.5/coming-soon.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '2881219076ba99d271c3');
1 change: 1 addition & 0 deletions build/1.3.5/coming-soon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
]
},
"require-dev": {
"newfold-labs/wp-php-standards": "^1.2"
"newfold-labs/wp-php-standards": "^1.2.4"
},
"scripts": {
"fix": [
@@ -46,7 +46,7 @@
}
},
"require": {
"newfold-labs/wp-module-data": ">=2.4.18",
"newfold-labs/wp-module-data": "^2.6.8",
"wp-forge/wp-upgrade-handler": "^1.0"
}
}
150 changes: 150 additions & 0 deletions includes/AdminBarSiteStatusBadge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

namespace NewfoldLabs\WP\Module\ComingSoon;

use NewfoldLabs\WP\ModuleLoader\Container;
use WP_Admin_Bar;

/**
* Add site status badge (Coming Soon or Live) to WP admin bar.
* If WooCommerce is active, this badge will not be added.
* Instead, WooCommerce's site visibility badge will be displayed.
*/
class AdminBarSiteStatusBadge {
/**
* Container.
*
* @var Container
*/
private $container;

/**
* Default values.
*
* @var array
*/
private $defaults = array();

/**
* Constructor.
*
* @param Container $container Container.
*/
public function __construct( Container $container ) {
// Bail if WooCommerce is active.
if ( isWoocommerceActive() ) {
return;
}

$this->container = $container;

$this->defaults = array(
'admin_bar_cs_active' => __( 'Coming soon', 'newfold-module-coming-soon' ),
'admin_bar_cs_inactive' => __( 'Live', 'newfold-module-coming-soon' ),
);

add_action( 'admin_bar_menu', array( $this, 'site_status_badge' ), 31 );
add_action( 'wp_head', array( $this, 'site_status_badge_styles' ) );
add_action( 'admin_head', array( $this, 'site_status_badge_styles' ) );
add_action( 'update_option_nfd_coming_soon', array( __CLASS__, 'site_status_badge_timer' ), 10, 2 );
}

/**
* Add site status badge to WP admin bar.
*
* @param WP_Admin_Bar $admin_bar An instance of the WP_Admin_Bar class.
*/
public function site_status_badge( WP_Admin_Bar $admin_bar ): void {
if ( current_user_can( 'manage_options' ) ) {

$is_coming_soon = isComingSoonActive();
$title = $is_coming_soon ? $this->defaults['admin_bar_cs_active'] : $this->defaults['admin_bar_cs_inactive'];
$class = $this->site_status_badge_class( $is_coming_soon );

$site_status_menu = array(
'id' => 'nfd-site-visibility-badge',
'parent' => 'root-default',
'href' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=coming-soon-section#/settings' ),
'title' => $title,
'meta' => array(
'class' => 'nfd-site-status-badge-' . $class,
),
);
$admin_bar->add_menu( $site_status_menu );
}
}

/**
* Determine the class for the site status badge.
*
* @param bool $is_coming_soon Whether the site is in Coming Soon mode.
*/
private function site_status_badge_class( $is_coming_soon ): string {
$class = $is_coming_soon ? 'coming-soon' : 'live';

// Hide badge if the site has been live for more than 10 minutes.
if ( ! $is_coming_soon && ! get_transient( 'nfd_coming_soon_site_status_badge_timer' ) ) {
$class = 'hidden';
}

return $class;
}

/**
* Output CSS for site status badge.
*/
public function site_status_badge_styles(): void {
if ( is_admin_bar_showing() ) {
?>
<style>
#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge a.ab-item {
background-color: #F6F7F7;
color: black;
margin-top:7px;
padding: 0 6px;
height: 18px;
line-height: 17px;
border-radius: 2px;
}

#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge a.ab-item:hover,
#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge a.ab-item:focus {
background-color: #DCDCDE;
}

#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge a.ab-item:focus {
outline: var(--wp-admin-border-width-focus) solid var(--wp-admin-theme-color-darker-20);
}

#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge.nfd-site-status-badge-live a.ab-item {
background-color: #E6F2E8;
color: #00450C;
}

#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge.nfd-site-status-badge-live a.ab-item:hover,
#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge.nfd-site-status-badge-live a.ab-item:focus {
background-color: #B8E6BF;
}

#wpadminbar .quicklinks #wp-admin-bar-nfd-site-visibility-badge.nfd-site-status-badge-hidden {
display: none;
}
</style>
<?php
}
}

/**
* Set 10 minutes transient timer for site status badge when coming soon is turned off.
*
* @param bool $old_value The old option value.
* @param bool $new_value The new option value.
*/
public static function site_status_badge_timer( $old_value, $new_value ): void {
$value = wp_validate_boolean( $new_value );

if ( false === $value ) {
set_transient( 'nfd_coming_soon_site_status_badge_timer', true, 10 * MINUTE_IN_SECONDS );
}
}
}
106 changes: 6 additions & 100 deletions includes/ComingSoon.php
Original file line number Diff line number Diff line change
@@ -24,10 +24,6 @@ public function __construct( Container $container ) {
'admin_screen_id' => container()->plugin()->id,
'admin_app_url' => \admin_url( 'admin.php?page=newfold' ),
'admin_notice_text' => __( 'Your site has Coming Soon mode active.', 'newfold-module-coming-soon' ),
'admin_bar_text' => '<div>' . __( 'Coming Soon Active', 'newfold-module-coming-soon' ) . '</div>',
'admin_bar_label' => __( 'Site Status: ', 'newfold-module-coming-soon' ),
'admin_bar_cs_active' => __( 'Not Live', 'newfold-module-coming-soon' ),
'admin_bar_cs_inactive' => __( 'Live', 'newfold-module-coming-soon' ),
'template_page_title' => __( 'Coming Soon!', 'newfold-module-coming-soon' ),
'template_styles' => false,
'template_content' => false,
@@ -49,6 +45,9 @@ public function __construct( Container $container ) {
// add plugin version to plugin styles file for cache busting
$this->args['template_styles'] = $this->args['template_styles'] . '?v=' . container()->plugin()->version;
}

new WooCommerceOptionsSync();

// set up all actions
\add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
\add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
@@ -58,15 +57,13 @@ public function __construct( Container $container ) {
\add_action( 'wp_ajax_newfold_coming_soon_subscribe', array( $this, 'coming_soon_subscribe' ) );
\add_action( 'wp_ajax_nopriv_newfold_coming_soon_subscribe', array( $this, 'coming_soon_subscribe' ) );
\add_action( 'plugins_loaded', array( $this, 'coming_soon_prevent_emails' ) );
\add_action( 'admin_bar_menu', array( $this, 'newfold_site_status' ), 100 );
\add_action( 'wp_body_open', array( $this, 'site_preview_warning' ) );
\add_action( 'admin_head', array( $this, 'admin_bar_coming_soon_admin_styles' ) );
\add_action( 'wp_head', array( $this, 'admin_bar_coming_soon_admin_styles' ) );
\add_filter( 'default_option_nfd_coming_soon', array( $this, 'filter_coming_soon_fallback' ) );
\add_action( 'update_option_nfd_coming_soon', array( $this, 'on_update_nfd_coming_soon' ), 10, 2 );
\add_action( 'update_option_mm_coming_soon', array( $this, 'on_update_mm_coming_soon' ), 10, 2 );
\add_filter( 'jetpack_is_under_construction_plugin', array( $this, 'filter_jetpack_is_under_construction' ) );

new AdminBarSiteStatusBadge( $container );
new SitePreviewWarning();
new PrePublishModal();
}

@@ -245,102 +242,11 @@ public function notice_display() {
}
}

/**
* Some basic styles to control visibility of the coming soon state in the admin bar
*/
public function admin_bar_coming_soon_admin_styles() {
?>
<style>
#nfd-site-status {
align-items: center;
background-color: #F8F8F8;
border-radius: 2px;
border-style: solid;
border-width: 1px;
color: #333333;
display: flex;
font-weight: 500;
gap: 2px;
height: 22px;
margin-top: 4px;
padding: 0 14px;
}

#wpadminbar #wp-admin-bar-site-status .ab-item{
height:22px;
}

#nfd-site-status[data-coming-soon="true"] {
border-color: var(--Dark-Red, #C71919);
}

#nfd-site-status[data-coming-soon="false"] {
border-color: var(--A11y-GRN, #278224);
}

#nfd-site-status span {
display: none;
text-transform: uppercase;
font-weight: 500;
}

#nfd-site-status[data-coming-soon="true"] #nfd-site-status-coming-soon {
color: var(--Dark-Red, #C71919);
display: inline-block;
}

#nfd-site-status[data-coming-soon="false"] #nfd-site-status-live {
color: var(--A11y-GRN, #278224);
display: inline-block;
}
</style>
<?php
}

/**
* Customize the admin bar with site status.
*
* @param \WP_Admin_Bar $admin_bar An instance of the WP_Admin_Bar class.
*/
public function newfold_site_status( \WP_Admin_Bar $admin_bar ) {
if ( current_user_can( 'manage_options' ) ) {

$is_coming_soon = isComingSoonActive();
$current_state = $is_coming_soon ? 'true' : 'false';
$content = '<div id="nfd-site-status" data-coming-soon="' . $current_state . '">';
$content .= $this->args['admin_bar_label'];
$content .= '<span id="nfd-site-status-coming-soon" class="nfd-coming-soon-active">';
$content .= $this->args['admin_bar_cs_active'];
$content .= '</span>';
$content .= '<span id="nfd-site-status-live" class="nfd-coming-soon-inactive">';
$content .= $this->args['admin_bar_cs_inactive'];
$content .= '</span>';
$content .= '</div>';

$site_status_menu = array(
'id' => 'site-status',
'parent' => 'top-secondary',
'href' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=coming-soon-section#/settings' ),
'title' => $content,
);
$admin_bar->add_menu( $site_status_menu );
}
}

/**
* Load warning on site Preview
*/
public function site_preview_warning() {
if ( isComingSoonActive() ) {
echo "<div style='background-color: #e71616; padding: 0 16px;color:#ffffff;font-size:16px;text-align:center;font-weight: 590;'>" . esc_html__( 'Site Preview - This site is NOT LIVE, only admins can see this view.', 'newfold-module-coming-soon' ) . "</div>";
}
}

/**
* Load the coming soon page, if necessary.
*/
public function maybe_load_template() {
if ( ! is_user_logged_in() || 'preview=coming_soon' === $_SERVER['QUERY_STRING'] ) {
if ( ! is_user_logged_in() || ( isset( $_SERVER['QUERY_STRING'] ) && 'preview=coming_soon' === $_SERVER['QUERY_STRING'] ) ) {
if ( isComingSoonActive() ) {
self::coming_soon_content( $this->args );
die();
9 changes: 0 additions & 9 deletions includes/PrePublishModal.php
Original file line number Diff line number Diff line change
@@ -34,16 +34,7 @@ public static function register_assets() {
true
);

\wp_register_style(
'nfd-coming-soon',
NFD_COMING_SOON_BUILD_URL . '/coming-soon.css',
array(),
$asset['version']
);

\wp_enqueue_script( 'nfd-coming-soon' );
\wp_enqueue_style( 'nfd-coming-soon' );
}
}

}
Loading