Skip to content

Commit

Permalink
WP Playground notice
Browse files Browse the repository at this point in the history
  • Loading branch information
seb86 committed Nov 5, 2023
1 parent fb472fc commit 912ebb2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
22 changes: 22 additions & 0 deletions includes/admin/class-cocart-admin-notices.php
Expand Up @@ -81,6 +81,8 @@ public function __construct() {
if ( CoCart_Helpers::user_has_capabilities() ) {
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
}

add_action( 'admin_notices', array( $this, 'wordpress_playground_notice' ) );
} // END __construct()

/**
Expand Down Expand Up @@ -230,6 +232,11 @@ public function add_notices() {
return;
}

// Don't show notices if on WordPress Playground.
if ( CoCart_Helpers::is_on_wordpress_playground() ) {
return;
}

$notices = self::get_notices();

if ( empty( $notices ) ) {
Expand Down Expand Up @@ -476,6 +483,21 @@ public function setup_wizard_notice() {
include_once COCART_ABSPATH . 'includes/admin/views/html-notice-setup-wizard.php';
} // END setup_wizard_notice()

/**
* Displays a notice if the user installed CoCart on WordPress Playground.
*
* @access public
*
* @since 3.10.0 Introduced.
*
* @return void
*/
public function wordpress_playground_notice() {
if ( CoCart_Helpers::is_on_wordpress_playground() ) {
include_once COCART_ABSPATH . 'includes/admin/views/html-notice-playground.php';
}
} // END wordpress_playground_notice()

} // END class.

} // END if class exists.
Expand Down
39 changes: 39 additions & 0 deletions includes/admin/views/html-notice-playground.php
@@ -0,0 +1,39 @@
<?php
/**
* Admin View: Required WooCommerce Notice.
*
* @author Sébastien Dumont
* @package CoCart\Admin\Views
* @since 3.10.0
* @license GPL-2.0+
*/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div class="notice notice-error cocart-notice is-dismissible">
<div class="cocart-notice-inner">
<div class="cocart-notice-icon">
<img src="<?php echo esc_url( COCART_URL_PATH . '/assets/images/brand/logo.jpg' ); ?>" alt="CoCart Logo" />
</div>

<div class="cocart-notice-content">
<p>
<?php
echo sprintf(
/* translators: 1: CoCart, 2: InstaWP */
esc_html__( 'WordPress Playground is not compatible with the %1$s plugin. Recommend creating a sandbox site with %2$s instead.', 'cart-rest-api-for-woocommerce' ),
'CoCart',
'InstaWP'
);
?>
</p>
</div>

<div class="cocart-action">
<a href="<?php echo esc_url( 'https://app.instawp.io/onboard?launch_slug=true&plugins=cart-rest-api-for-woocommerce' ); ?>" class="button button-primary cocart-button" aria-label="<?php echo esc_html__( 'Setup Sandbox', 'cart-rest-api-for-woocommerce' ); ?>"><?php echo esc_html__( 'Setup Sandbox', 'cart-rest-api-for-woocommerce' ); ?></a>
</div>
</div>
</div>
23 changes: 23 additions & 0 deletions includes/class-cocart-helpers.php
Expand Up @@ -778,6 +778,29 @@ public static function is_wc_admin_enabled() {
return self::$is_wc_admin_enabled;
} // END is_wc_admin_enabled()

/**
* Returns true if plugin is accessed from WordPress Playground.
*
* @access public
*
* @static
*
* @since 3.10.0 Introduced.
*
* @ignore Function ignored when parsed into Code Reference.
*
* @return bool
*/
public static function is_on_wordpress_playground() {
$site_url = get_site_url();

if ( strpos( $site_url, 'playground.wordpress.net' ) !== false ) {
return true;
}

return false;
} // END is_on_wordpress_playground()

} // END class

return new CoCart_Helpers();

0 comments on commit 912ebb2

Please sign in to comment.