diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
commit | 10ef81bf85ad0a4bad0d204838e14c99ca2526f7 (patch) | |
tree | b4bb36a326d41de12d1a6181d2a2baf34696ac24 /plugins/jetpack/modules/memberships/class-jetpack-memberships.php | |
parent | Updating script for Update (diff) | |
download | blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.gz blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.bz2 blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.zip |
Update jetpack 8.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/modules/memberships/class-jetpack-memberships.php')
-rw-r--r-- | plugins/jetpack/modules/memberships/class-jetpack-memberships.php | 107 |
1 files changed, 93 insertions, 14 deletions
diff --git a/plugins/jetpack/modules/memberships/class-jetpack-memberships.php b/plugins/jetpack/modules/memberships/class-jetpack-memberships.php index 989d4e96..5a3ed64f 100644 --- a/plugins/jetpack/modules/memberships/class-jetpack-memberships.php +++ b/plugins/jetpack/modules/memberships/class-jetpack-memberships.php @@ -34,7 +34,29 @@ class Jetpack_Memberships { * * @var string */ - private static $button_block_name = 'membership-button'; + private static $button_block_name = 'recurring-payments'; + + /** + * These are defaults for wp_kses ran on the membership button. + * + * @var array + */ + private static $tags_allowed_in_the_button = array( 'br' => array() ); + + /** + * The minimum required plan for this Gutenberg block. + * + * @var string Plan slug + */ + private static $required_plan; + + /** + * Track recurring payments block registration. + * + * @var boolean True if block registration has been executed. + */ + private static $has_registered_block = false; + /** * Classic singleton pattern * @@ -56,6 +78,8 @@ class Jetpack_Memberships { if ( ! self::$instance ) { self::$instance = new self(); self::$instance->register_init_hook(); + // Yes, `personal-bundle` with a dash, `jetpack_personal` with an underscore. Check the v1.5 endpoint to verify. + self::$required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'personal-bundle' : 'jetpack_personal'; } return self::$instance; @@ -84,6 +108,7 @@ class Jetpack_Memberships { */ private function register_init_hook() { add_action( 'init', array( $this, 'init_hook_action' ) ); + add_action( 'jetpack_register_gutenberg_extensions', array( $this, 'register_gutenberg_block' ) ); } /** @@ -113,7 +138,7 @@ class Jetpack_Memberships { ); $order_args = array( 'label' => esc_html__( 'Plan', 'jetpack' ), - 'description' => esc_html__( 'Memberships plans', 'jetpack' ), + 'description' => esc_html__( 'Recurring Payments plans', 'jetpack' ), 'supports' => array( 'title', 'custom-fields', 'content' ), 'hierarchical' => false, 'public' => false, @@ -201,16 +226,18 @@ class Jetpack_Memberships { 'powered_text' => __( 'Powered by WordPress.com', 'jetpack' ), ); - $classes = array( - 'components-button', - 'is-primary', - 'is-button', - 'wp-block-jetpack-' . self::$button_block_name, - self::$css_classname_prefix . '-' . $data['id'], + $classes = Jetpack_Gutenberg::block_classes( + self::$button_block_name, + $attrs, + array( + 'wp-block-button__link', + 'components-button', + 'is-primary', + 'is-button', + self::$css_classname_prefix . '-' . $data['id'], + ) ); - if ( isset( $attrs['className'] ) ) { - array_push( $classes, $attrs['className'] ); - } + if ( isset( $attrs['submitButtonText'] ) ) { $data['button_label'] = $attrs['submitButtonText']; } @@ -233,7 +260,7 @@ class Jetpack_Memberships { ) ); } - $button_styles = implode( $button_styles, ';' ); + $button_styles = implode( ';', $button_styles ); add_thickbox(); return sprintf( '<button data-blog-id="%d" data-powered-text="%s" data-plan-id="%d" data-lang="%s" class="%s" style="%s">%s</button>', @@ -241,9 +268,9 @@ class Jetpack_Memberships { esc_attr( $data['powered_text'] ), esc_attr( $data['id'] ), esc_attr( get_locale() ), - esc_attr( implode( $classes, ' ' ) ), + esc_attr( $classes ), esc_attr( $button_styles ), - esc_html( $data['button_label'] ) + wp_kses( $data['button_label'], self::$tags_allowed_in_the_button ) ); } @@ -268,5 +295,57 @@ class Jetpack_Memberships { public static function get_connected_account_id() { return get_option( self::$connected_account_id_option_name ); } + + /** + * Whether Recurring Payments are enabled. + * + * @return bool + */ + public static function is_enabled_jetpack_recurring_payments() { + // For WPCOM sites. + if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'has_any_blog_stickers' ) ) { + $site_id = get_current_blog_id(); + return has_any_blog_stickers( array( 'personal-plan', 'premium-plan', 'business-plan', 'ecommerce-plan' ), $site_id ); + } + + // For Jetpack sites. + return Jetpack::is_active() && ( + /** This filter is documented in class.jetpack-gutenberg.php */ + ! apply_filters( 'jetpack_block_editor_enable_upgrade_nudge', false ) || // Remove when the default becomes `true`. + Jetpack_Plan::supports( 'recurring-payments' ) + ); + } + + /** + * Register the Recurring Payments Gutenberg block + */ + public function register_gutenberg_block() { + // This gate was introduced to prevent duplicate registration. A race condition exists where + // the registration that happens via extensions/blocks/recurring-payments/recurring-payments.php + // was adding the registration action after the action had been run in some contexts. + if ( self::$has_registered_block ) { + return; + } + + if ( self::is_enabled_jetpack_recurring_payments() ) { + jetpack_register_block( + 'jetpack/recurring-payments', + array( + 'render_callback' => array( $this, 'render_button' ), + ) + ); + } else { + Jetpack_Gutenberg::set_extension_unavailable( + 'jetpack/recurring-payments', + 'missing_plan', + array( + 'required_feature' => 'memberships', + 'required_plan' => self::$required_plan, + ) + ); + } + + self::$has_registered_block = true; + } } Jetpack_Memberships::get_instance(); |