summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/simple-payments/simple-payments.php')
-rw-r--r--plugins/jetpack/modules/simple-payments/simple-payments.php51
1 files changed, 45 insertions, 6 deletions
diff --git a/plugins/jetpack/modules/simple-payments/simple-payments.php b/plugins/jetpack/modules/simple-payments/simple-payments.php
index a7e5371a..6ac3d8c7 100644
--- a/plugins/jetpack/modules/simple-payments/simple-payments.php
+++ b/plugins/jetpack/modules/simple-payments/simple-payments.php
@@ -27,7 +27,7 @@ class Jetpack_Simple_Payments {
return self::$instance;
}
- private function register_scripts() {
+ private function register_scripts_and_styles() {
/**
* Paypal heavily discourages putting that script in your own server:
* @see https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/add-paypal-button/
@@ -35,18 +35,26 @@ class Jetpack_Simple_Payments {
wp_register_script( 'paypal-checkout-js', 'https://www.paypalobjects.com/api/checkout.js', array(), null, true );
wp_register_script( 'paypal-express-checkout', plugins_url( '/paypal-express-checkout.js', __FILE__ ),
array( 'jquery', 'paypal-checkout-js' ), self::$version );
+ wp_register_style( 'jetpack-simple-payments', plugins_url( '/simple-payments.css', __FILE__ ), array( 'dashicons' ) );
}
+
private function register_init_hook() {
add_action( 'init', array( $this, 'init_hook_action' ) );
}
+
private function register_shortcode() {
add_shortcode( self::$shortcode, array( $this, 'parse_shortcode' ) );
}
public function init_hook_action() {
+ if ( ! $this->is_enabled_jetpack_simple_payments() ) {
+ add_shortcode( self::$shortcode, array( $this, 'ignore_shortcode' ) );
+ return;
+ }
+
add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_rest_api_types' ) );
add_filter( 'jetpack_sync_post_meta_whitelist', array( $this, 'allow_sync_post_meta' ) );
- $this->register_scripts();
+ $this->register_scripts_and_styles();
$this->register_shortcode();
$this->setup_cpts();
@@ -69,6 +77,33 @@ class Jetpack_Simple_Payments {
return Jetpack_Options::get_option( 'id' );
}
+ /**
+ * Used to check whether Simple Payments are enabled for given site.
+ *
+ * @return bool True if Simple Payments are enabled, false otherwise.
+ */
+ function is_enabled_jetpack_simple_payments() {
+ /**
+ * Can be used by plugin authors to disable the conflicting output of Simple Payments.
+ *
+ * @since 6.3.0
+ *
+ * @param bool True if Simple Payments should be disabled, false otherwise.
+ */
+ if ( apply_filters( 'jetpack_disable_simple_payments', false ) ) {
+ return false;
+ }
+
+ // For WPCOM sites
+ if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'has_blog_sticker' ) ) {
+ $site_id = $this->get_blog_id();
+ return has_blog_sticker( 'premium-plan', $site_id ) || has_blog_sticker( 'business-plan', $site_id );
+ }
+
+ // For all Jetpack sites
+ return Jetpack::is_active() && Jetpack::active_plan_supports( 'simple-payments');
+ }
+
function parse_shortcode( $attrs, $content = false ) {
if ( empty( $attrs['id'] ) ) {
return;
@@ -100,12 +135,14 @@ class Jetpack_Simple_Payments {
);
$data['id'] = $attrs['id'];
+
+ if( ! wp_style_is( 'jetpack-simple-payments', 'enqueue' ) ) {
+ wp_enqueue_style( 'jetpack-simple-payments' );
+ }
+
if ( ! wp_script_is( 'paypal-express-checkout', 'enqueued' ) ) {
wp_enqueue_script( 'paypal-express-checkout' );
}
- if ( ! wp_style_is( 'simple-payments', 'enqueued' ) ) {
- wp_enqueue_style( 'simple-payments', plugins_url( 'simple-payments.css', __FILE__ ), array( 'dashicons' ) );
- }
wp_add_inline_script( 'paypal-express-checkout', sprintf(
"try{PaypalExpressCheckout.renderButton( '%d', '%d', '%s', '%d' );}catch(e){}",
@@ -118,6 +155,8 @@ class Jetpack_Simple_Payments {
return $this->output_shortcode( $data );
}
+ function ignore_shortcode() { return; }
+
function output_shortcode( $data ) {
$items = '';
$css_prefix = self::$css_classname_prefix;
@@ -213,7 +252,7 @@ class Jetpack_Simple_Payments {
'read_private_posts' => 'read_private_posts',
);
$order_args = array(
- 'label' => esc_html__( 'Order', 'jetpack' ),
+ 'label' => esc_html_x( 'Order', 'noun: a quantity of goods or items purchased or sold', 'jetpack' ),
'description' => esc_html__( 'Simple Payments orders', 'jetpack' ),
'supports' => array( 'custom-fields', 'excerpt' ),
'hierarchical' => false,