← All changes
|
extensions/blocks/premium-content/_inc/legacy-buttons.php
+62
-0
16.2-beta
→
16.3-beta
View file →
| @@ -1,0 +1,62 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Create legacy buttons markup. | |
| 4 | + * | |
| 5 | + * @package Automattic\Jetpack\Extensions\Premium_Content | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace Automattic\Jetpack\Extensions\Premium_Content; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Creates a subscribe/login buttons markup for legacy blocks. | |
| 12 | + * | |
| 13 | + * @param array $attributes Block attributes. | |
| 14 | + * @param string $content String containing the block content. | |
| 15 | + * @param object $block Legacy block. | |
| 16 | + * | |
| 17 | + * @return string Subscribe/login buttons markup. | |
| 18 | + */ | |
| 19 | +function create_legacy_buttons_markup( $attributes, $content, $block ) { | |
| 20 | + $button_styles = array(); | |
| 21 | + if ( ! empty( $attributes['customBackgroundButtonColor'] ) ) { | |
| 22 | + array_push( | |
| 23 | + $button_styles, | |
| 24 | + sprintf( | |
| 25 | + 'background-color: %s', | |
| 26 | + isset( $attributes['customBackgroundButtonColor'] ) ? sanitize_hex_color( $attributes['customBackgroundButtonColor'] ) : 'transparent' | |
| 27 | + ) | |
| 28 | + ); | |
| 29 | + } | |
| 30 | + if ( ! empty( $attributes['customTextButtonColor'] ) ) { | |
| 31 | + array_push( | |
| 32 | + $button_styles, | |
| 33 | + sprintf( | |
| 34 | + 'color: %s', | |
| 35 | + isset( $attributes['customTextButtonColor'] ) ? sanitize_hex_color( $attributes['customTextButtonColor'] ) : 'inherit' | |
| 36 | + ) | |
| 37 | + ); | |
| 38 | + } | |
| 39 | + $button_styles = implode( ';', $button_styles ); | |
| 40 | + | |
| 41 | + $login_button = sprintf( | |
| 42 | + '<div class="wp-block-button"><a role="button" href="%1$s" class="%2$s" style="%3$s">%4$s</a></div>', | |
| 43 | + esc_url( subscription_service()->access_url() ), | |
| 44 | + empty( $attributes['buttonClasses'] ) ? 'wp-block-button__link' : esc_attr( $attributes['buttonClasses'] ), | |
| 45 | + esc_attr( $button_styles ), | |
| 46 | + empty( $attributes['loginButtonText'] ) ? __( 'Log In', 'jetpack' ) : wp_kses_post( $attributes['loginButtonText'] ) | |
| 47 | + ); | |
| 48 | + | |
| 49 | + $subscribe_button = \Jetpack_Memberships::get_instance()->render_button( | |
| 50 | + array( | |
| 51 | + 'planId' => empty( $block->context['premium-content/planId'] ) ? 0 : $block->context['premium-content/planId'], | |
| 52 | + 'submitButtonClasses' => empty( $attributes['buttonClasses'] ) ? 'wp-block-button__link' : esc_attr( $attributes['buttonClasses'] ), | |
| 53 | + 'customTextButtonColor' => empty( $attributes['customTextButtonColor'] ) ? '' : esc_attr( $attributes['customTextButtonColor'] ), | |
| 54 | + 'customBackgroundButtonColor' => empty( $attributes['customBackgroundButtonColor'] ) ? '' : esc_attr( $attributes['customBackgroundButtonColor'] ), | |
| 55 | + 'submitButtonText' => empty( $attributes['subscribeButtonText'] ) ? __( 'Subscribe', 'jetpack' ) : esc_attr( $attributes['subscribeButtonText'] ), | |
| 56 | + ), | |
| 57 | + $content, | |
| 58 | + $block | |
| 59 | + ); | |
| 60 | + | |
| 61 | + return "<div class='wp-block-premium-content-logged-out-view__buttons'>{$subscribe_button}{$login_button}</div>"; | |
| 62 | +} | |