Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/extensio.../blocks/subscrip...
File: subscriptions.php
$padding = get_attribute( $attributes, 'padding', DEFAULT_PADDING_VALUE );
[500] Fix | Delete
$style = sprintf( 'padding: %1$dpx %2$dpx %1$dpx %2$dpx;', $padding, round( $padding * 1.5 ) );
[501] Fix | Delete
[502] Fix | Delete
$submit_button_styles .= $style;
[503] Fix | Delete
$email_field_styles .= $style;
[504] Fix | Delete
[505] Fix | Delete
if ( ! $is_button_only_style ) {
[506] Fix | Delete
$button_spacing = get_attribute( $attributes, 'spacing', DEFAULT_SPACING_VALUE );
[507] Fix | Delete
if ( true === get_attribute( $attributes, 'buttonOnNewLine' ) ) {
[508] Fix | Delete
$submit_button_styles .= sprintf( 'margin-top: %dpx;', $button_spacing );
[509] Fix | Delete
} else {
[510] Fix | Delete
$submit_button_styles .= 'margin: 0; '; // Reset Safari's 2px default margin for buttons affecting input and button union
[511] Fix | Delete
$submit_button_styles .= sprintf( 'margin-left: %dpx;', $button_spacing );
[512] Fix | Delete
}
[513] Fix | Delete
}
[514] Fix | Delete
[515] Fix | Delete
if ( has_attribute( $attributes, 'borderColor' ) ) {
[516] Fix | Delete
$style = sprintf( 'border-color: %s;', get_attribute( $attributes, 'borderColor', '' ) );
[517] Fix | Delete
$submit_button_styles .= $style;
[518] Fix | Delete
$email_field_styles .= $style;
[519] Fix | Delete
}
[520] Fix | Delete
[521] Fix | Delete
$style = sprintf( 'border-radius: %dpx;', get_attribute( $attributes, 'borderRadius', DEFAULT_BORDER_RADIUS_VALUE ) );
[522] Fix | Delete
$submit_button_styles .= $style;
[523] Fix | Delete
$email_field_styles .= $style;
[524] Fix | Delete
[525] Fix | Delete
$style = sprintf( 'border-width: %dpx;', get_attribute( $attributes, 'borderWeight', DEFAULT_BORDER_WEIGHT_VALUE ) );
[526] Fix | Delete
$submit_button_styles .= $style;
[527] Fix | Delete
$email_field_styles .= $style;
[528] Fix | Delete
[529] Fix | Delete
if ( has_attribute( $attributes, 'customBorderColor' ) ) {
[530] Fix | Delete
$style = sprintf( 'border-color: %s; border-style: solid;', get_attribute( $attributes, 'customBorderColor' ) );
[531] Fix | Delete
[532] Fix | Delete
$submit_button_styles .= $style;
[533] Fix | Delete
$email_field_styles .= $style;
[534] Fix | Delete
}
[535] Fix | Delete
[536] Fix | Delete
if ( ! Request::is_frontend() ) {
[537] Fix | Delete
$background_color_style = get_attribute_color( 'buttonBackgroundColor', $attributes, '#113AF5' /* default lettre theme color */ );
[538] Fix | Delete
$text_color_style = get_attribute_color( 'textColor', $attributes, '#FFFFFF' );
[539] Fix | Delete
$submit_button_styles .= sprintf( ' background-color: %s; color: %s;', $background_color_style, $text_color_style );
[540] Fix | Delete
}
[541] Fix | Delete
[542] Fix | Delete
return array(
[543] Fix | Delete
'email_field' => $email_field_styles,
[544] Fix | Delete
'submit_button' => $submit_button_styles,
[545] Fix | Delete
'submit_button_wrapper' => $submit_button_wrapper_styles,
[546] Fix | Delete
);
[547] Fix | Delete
}
[548] Fix | Delete
[549] Fix | Delete
/**
[550] Fix | Delete
* Retrieve the resolved color for a given attribute.
[551] Fix | Delete
*
[552] Fix | Delete
* @param string $attribute_name The name of the attribute to resolve.
[553] Fix | Delete
* @param array $attributes An array of all attributes.
[554] Fix | Delete
* @param string $default_color A fallback color in case no color can be resolved.
[555] Fix | Delete
*
[556] Fix | Delete
* @return string Returns the resolved color or the default color if no color is found.
[557] Fix | Delete
*/
[558] Fix | Delete
function get_attribute_color( $attribute_name, $attributes, $default_color ) {
[559] Fix | Delete
if ( has_attribute( $attributes, $attribute_name ) ) {
[560] Fix | Delete
$color_slug = get_attribute( $attributes, $attribute_name );
[561] Fix | Delete
$resolved_color = get_color_from_slug( $color_slug );
[562] Fix | Delete
[563] Fix | Delete
if ( $resolved_color ) {
[564] Fix | Delete
return $resolved_color;
[565] Fix | Delete
}
[566] Fix | Delete
}
[567] Fix | Delete
[568] Fix | Delete
return get_global_style_color( $attribute_name, $default_color );
[569] Fix | Delete
}
[570] Fix | Delete
[571] Fix | Delete
/**
[572] Fix | Delete
* Retrieve the global style color based on a provided style key.
[573] Fix | Delete
*
[574] Fix | Delete
* @param string $style_key The key for the desired style.
[575] Fix | Delete
* @param string $default_color A fallback color in case the global style is not set.
[576] Fix | Delete
*
[577] Fix | Delete
* @return string Returns the color defined in global styles or the default color if not defined.
[578] Fix | Delete
*/
[579] Fix | Delete
function get_global_style_color( $style_key, $default_color ) {
[580] Fix | Delete
$global_styles = wp_get_global_styles(
[581] Fix | Delete
array( 'color' ),
[582] Fix | Delete
array(
[583] Fix | Delete
'block_name' => 'core/button',
[584] Fix | Delete
'transforms' => array( 'resolve-variables' ),
[585] Fix | Delete
)
[586] Fix | Delete
);
[587] Fix | Delete
[588] Fix | Delete
if ( isset( $global_styles[ $style_key ] ) ) {
[589] Fix | Delete
return $global_styles[ $style_key ];
[590] Fix | Delete
}
[591] Fix | Delete
[592] Fix | Delete
return $default_color;
[593] Fix | Delete
}
[594] Fix | Delete
[595] Fix | Delete
/**
[596] Fix | Delete
* Convert a color slug into its corresponding color value.
[597] Fix | Delete
*
[598] Fix | Delete
* @param string $slug The slug representation of the color.
[599] Fix | Delete
*
[600] Fix | Delete
* @return string|null Returns the color value if found, or null otherwise.
[601] Fix | Delete
*/
[602] Fix | Delete
function get_color_from_slug( $slug ) {
[603] Fix | Delete
$color_palettes = wp_get_global_settings( array( 'color', 'palette' ) );
[604] Fix | Delete
[605] Fix | Delete
if ( ! is_array( $color_palettes ) ) {
[606] Fix | Delete
return null;
[607] Fix | Delete
}
[608] Fix | Delete
[609] Fix | Delete
foreach ( $color_palettes as $palette ) {
[610] Fix | Delete
if ( is_array( $palette ) ) {
[611] Fix | Delete
foreach ( $palette as $color ) {
[612] Fix | Delete
if ( isset( $color['slug'] ) && $color['slug'] === $slug && isset( $color['color'] ) ) {
[613] Fix | Delete
return $color['color'];
[614] Fix | Delete
}
[615] Fix | Delete
}
[616] Fix | Delete
}
[617] Fix | Delete
}
[618] Fix | Delete
[619] Fix | Delete
return null;
[620] Fix | Delete
}
[621] Fix | Delete
[622] Fix | Delete
/**
[623] Fix | Delete
* Is the Jetpack_Memberships class loaded.
[624] Fix | Delete
*/
[625] Fix | Delete
function is_jetpack_memberships_loaded(): bool {
[626] Fix | Delete
return class_exists( '\Jetpack_Memberships' );
[627] Fix | Delete
}
[628] Fix | Delete
[629] Fix | Delete
/**
[630] Fix | Delete
* Subscriptions block render callback.
[631] Fix | Delete
*
[632] Fix | Delete
* @param array $attributes Array containing the block attributes.
[633] Fix | Delete
*
[634] Fix | Delete
* @return string
[635] Fix | Delete
*/
[636] Fix | Delete
function render_block( $attributes ) {
[637] Fix | Delete
// If the Subscriptions module is not active, don't render the block.
[638] Fix | Delete
if ( ! ( new Modules() )->is_active( 'subscriptions' ) ) {
[639] Fix | Delete
return '';
[640] Fix | Delete
}
[641] Fix | Delete
[642] Fix | Delete
if ( is_jetpack_memberships_loaded() ) {
[643] Fix | Delete
// We only want the sites that have newsletter feature enabled to be graced by this JavaScript.
[644] Fix | Delete
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
[645] Fix | Delete
} else {
[646] Fix | Delete
Jetpack_Gutenberg::load_styles_as_required( FEATURE_NAME );
[647] Fix | Delete
}
[648] Fix | Delete
[649] Fix | Delete
if ( ! class_exists( 'Jetpack_Subscriptions_Widget' ) ) {
[650] Fix | Delete
return '';
[651] Fix | Delete
}
[652] Fix | Delete
[653] Fix | Delete
// Prefill the email field with the current user's email if they are logged in via Memberships premium content token
[654] Fix | Delete
$subscribe_email = Jetpack_Memberships::get_current_user_email();
[655] Fix | Delete
[656] Fix | Delete
// If no email, then prefill the email field with the current user's email if they are logged in
[657] Fix | Delete
if ( empty( $subscribe_email ) ) {
[658] Fix | Delete
$current_user = wp_get_current_user();
[659] Fix | Delete
if ( ! empty( $current_user->user_email ) ) {
[660] Fix | Delete
$subscribe_email = $current_user->user_email;
[661] Fix | Delete
}
[662] Fix | Delete
}
[663] Fix | Delete
[664] Fix | Delete
// The block is using the Jetpack_Subscriptions_Widget backend, hence the need to increase the instance count.
[665] Fix | Delete
++Jetpack_Subscriptions_Widget::$instance_count;
[666] Fix | Delete
[667] Fix | Delete
$classes = get_element_class_names_from_attributes( $attributes );
[668] Fix | Delete
$styles = get_element_styles_from_attributes( $attributes );
[669] Fix | Delete
[670] Fix | Delete
// The default value was previously "true" in block.json. We don't want to rely setting "default" in block.json to falsy,
[671] Fix | Delete
// because it would change the setting for previously saved blocks. Block editor doesn't store default values in attributes at all.
[672] Fix | Delete
// Hence users without this set will still get social counts included in the subscriber counter.
[673] Fix | Delete
// Lowering the subscriber count on their behalf with code change would be controversial.
[674] Fix | Delete
// We want to disencourage including social count as it's misleading.
[675] Fix | Delete
$include_social_followers = isset( $attributes['includeSocialFollowers'] ) ? (bool) get_attribute( $attributes, 'includeSocialFollowers' ) : true;
[676] Fix | Delete
[677] Fix | Delete
$data = array(
[678] Fix | Delete
'widget_id' => Jetpack_Subscriptions_Widget::$instance_count,
[679] Fix | Delete
'subscribe_email' => $subscribe_email,
[680] Fix | Delete
'is_paid_subscriber' => get_attribute( $attributes, 'isPaidSubscriber', false ),
[681] Fix | Delete
'wrapper_attributes' => get_block_wrapper_attributes(
[682] Fix | Delete
array(
[683] Fix | Delete
'class' => $classes['block_wrapper'],
[684] Fix | Delete
)
[685] Fix | Delete
),
[686] Fix | Delete
'subscribe_placeholder' => get_attribute( $attributes, 'subscribePlaceholder', __( 'Type your email…', 'jetpack' ) ),
[687] Fix | Delete
'submit_button_text' => get_attribute( $attributes, 'submitButtonText', __( 'Subscribe', 'jetpack' ) ),
[688] Fix | Delete
'submit_button_text_subscribed' => get_attribute( $attributes, 'submitButtonTextSubscribed', __( 'Subscribed', 'jetpack' ) ),
[689] Fix | Delete
'submit_button_text_upgrade' => get_attribute( $attributes, 'submitButtonTextUpgrade', __( 'Upgrade subscription', 'jetpack' ) ),
[690] Fix | Delete
'success_message' => get_attribute(
[691] Fix | Delete
$attributes,
[692] Fix | Delete
'successMessage',
[693] Fix | Delete
esc_html__( "Success! An email was just sent to confirm your subscription. Please find the email now and click 'Confirm' to start subscribing.", 'jetpack' )
[694] Fix | Delete
),
[695] Fix | Delete
'show_subscribers_total' => (bool) get_attribute( $attributes, 'showSubscribersTotal' ),
[696] Fix | Delete
'subscribers_total' => get_attribute( $attributes, 'showSubscribersTotal' ) ? get_subscriber_count( $include_social_followers ) : 0,
[697] Fix | Delete
'referer' => esc_url_raw(
[698] Fix | Delete
( is_ssl() ? 'https' : 'http' ) . '://' . ( isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : '' ) .
[699] Fix | Delete
( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '' )
[700] Fix | Delete
),
[701] Fix | Delete
'source' => 'subscribe-block',
[702] Fix | Delete
'app_source' => get_attribute( $attributes, 'appSource', null ),
[703] Fix | Delete
'class_name' => get_attribute( $attributes, 'className' ),
[704] Fix | Delete
'selected_newsletter_categories' => get_attribute( $attributes, 'selectedNewsletterCategoryIds', array() ),
[705] Fix | Delete
'preselected_newsletter_categories' => get_attribute( $attributes, 'preselectNewsletterCategories', false ),
[706] Fix | Delete
);
[707] Fix | Delete
[708] Fix | Delete
// Only render the email version in non-frontend contexts.
[709] Fix | Delete
if ( is_feed() || wp_is_xml_request() ||
[710] Fix | Delete
( defined( 'REST_REQUEST' ) && REST_REQUEST && ! wp_is_json_request() ) ||
[711] Fix | Delete
( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
[712] Fix | Delete
( defined( 'WP_CLI' ) && WP_CLI ) ||
[713] Fix | Delete
wp_is_jsonp_request() ) {
[714] Fix | Delete
return render_for_email( $data, $styles );
[715] Fix | Delete
}
[716] Fix | Delete
[717] Fix | Delete
return render_for_website( $data, $classes, $styles );
[718] Fix | Delete
}
[719] Fix | Delete
[720] Fix | Delete
/**
[721] Fix | Delete
* Get the post access level for the current post. Defaults to 'everybody' if the query is not for a single post
[722] Fix | Delete
*
[723] Fix | Delete
* @return string the actual post access level (see projects/plugins/jetpack/extensions/blocks/subscriptions/constants.js for the values).
[724] Fix | Delete
*/
[725] Fix | Delete
function get_post_access_level_for_current_post() {
[726] Fix | Delete
if ( ! is_singular() ) {
[727] Fix | Delete
// There is no "actual" current post.
[728] Fix | Delete
return Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_EVERYBODY;
[729] Fix | Delete
}
[730] Fix | Delete
[731] Fix | Delete
return Jetpack_Memberships::get_post_access_level();
[732] Fix | Delete
}
[733] Fix | Delete
[734] Fix | Delete
/**
[735] Fix | Delete
* Renders the subscriptions block at the site.
[736] Fix | Delete
*
[737] Fix | Delete
* @param array $data Array containing block view data.
[738] Fix | Delete
* @param array $classes Array containing the classes for different block elements.
[739] Fix | Delete
* @param array $styles Array containing the styles for different block elements.
[740] Fix | Delete
*
[741] Fix | Delete
* @return string
[742] Fix | Delete
*/
[743] Fix | Delete
function render_for_website( $data, $classes, $styles ) {
[744] Fix | Delete
$lang = get_locale();
[745] Fix | Delete
$blog_id = \Jetpack_Options::get_option( 'id' );
[746] Fix | Delete
$widget_id_suffix = Jetpack_Subscriptions_Widget::$instance_count > 1 ? '-' . Jetpack_Subscriptions_Widget::$instance_count : '';
[747] Fix | Delete
$form_id = 'subscribe-blog' . $widget_id_suffix;
[748] Fix | Delete
$form_url = 'https://wordpress.com/email-subscriptions';
[749] Fix | Delete
$post_access_level = get_post_access_level_for_current_post();
[750] Fix | Delete
$is_button_only_style = ! empty( $data['class_name'] ) ? is_button_only_style( $data['class_name'] ) : false;
[751] Fix | Delete
[752] Fix | Delete
// Post ID is used for pulling post-specific paid status, and returning to the right post after confirming subscription
[753] Fix | Delete
$post_id = null;
[754] Fix | Delete
if ( in_the_loop() ) {
[755] Fix | Delete
$post_id = get_the_ID();
[756] Fix | Delete
} elseif ( is_singular( 'post' ) || is_page() ) {
[757] Fix | Delete
$post_id = get_queried_object_id();
[758] Fix | Delete
} else {
[759] Fix | Delete
$post_id = get_option( 'page_on_front' );
[760] Fix | Delete
}
[761] Fix | Delete
[762] Fix | Delete
$subscribe_field_id = apply_filters( 'subscribe_field_id', 'subscribe-field' . $widget_id_suffix, $data['widget_id'] );
[763] Fix | Delete
$tier_id = get_post_meta( $post_id, META_NAME_FOR_POST_TIER_ID_SETTINGS, true );
[764] Fix | Delete
$is_subscribed = Jetpack_Memberships::is_current_user_subscribed();
[765] Fix | Delete
$button_text = get_submit_button_text( $data );
[766] Fix | Delete
$show_subscriber_count = $data['show_subscribers_total'] && $data['subscribers_total'] && ! $is_subscribed;
[767] Fix | Delete
[768] Fix | Delete
ob_start();
[769] Fix | Delete
[770] Fix | Delete
Jetpack_Subscriptions_Widget::render_widget_status_messages(
[771] Fix | Delete
array(
[772] Fix | Delete
'success_message' => $data['success_message'],
[773] Fix | Delete
)
[774] Fix | Delete
);
[775] Fix | Delete
?>
[776] Fix | Delete
<div <?php echo wp_kses_data( $data['wrapper_attributes'] ); ?>>
[777] Fix | Delete
<div class="wp-block-jetpack-subscriptions__container<?php echo ! $is_subscribed ? ' is-not-subscriber' : ''; ?>">
[778] Fix | Delete
<?php if ( is_top_subscription() ) : ?>
[779] Fix | Delete
<p id="subscribe-submit" class="is-link"
[780] Fix | Delete
<?php if ( ! empty( $styles['submit_button_wrapper'] ) ) : ?>
[781] Fix | Delete
style="<?php echo esc_attr( $styles['submit_button_wrapper'] ); ?>"
[782] Fix | Delete
<?php endif; ?>
[783] Fix | Delete
>
[784] Fix | Delete
<a
[785] Fix | Delete
href="<?php echo esc_url( 'https://wordpress.com/reader/site/subscription/' . $blog_id ); ?>"
[786] Fix | Delete
<?php if ( ! empty( $classes['submit_button'] ) ) : ?>
[787] Fix | Delete
class="<?php echo esc_attr( $classes['submit_button'] ); ?>"
[788] Fix | Delete
<?php endif; ?>
[789] Fix | Delete
<?php if ( ! empty( $styles['submit_button'] ) ) : ?>
[790] Fix | Delete
style="<?php echo esc_attr( $styles['submit_button'] ); ?>"
[791] Fix | Delete
<?php endif; ?>
[792] Fix | Delete
>
[793] Fix | Delete
<?php echo sanitize_submit_text( $button_text ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
[794] Fix | Delete
</a>
[795] Fix | Delete
</p>
[796] Fix | Delete
<?php else : ?>
[797] Fix | Delete
<form
[798] Fix | Delete
action="<?php echo esc_url( $form_url ); ?>"
[799] Fix | Delete
method="post"
[800] Fix | Delete
accept-charset="utf-8"
[801] Fix | Delete
data-blog="<?php echo esc_attr( $blog_id ); ?>"
[802] Fix | Delete
data-post_access_level="<?php echo esc_attr( $post_access_level ); ?>"
[803] Fix | Delete
data-subscriber_email="<?php echo esc_attr( $data['subscribe_email'] ); ?>"
[804] Fix | Delete
id="<?php echo esc_attr( $form_id ); ?>"
[805] Fix | Delete
>
[806] Fix | Delete
<div class="wp-block-jetpack-subscriptions__form-elements">
[807] Fix | Delete
<?php if ( ! $is_subscribed && ! $is_button_only_style ) : ?>
[808] Fix | Delete
<p id="subscribe-email">
[809] Fix | Delete
<label
[810] Fix | Delete
id="<?php echo esc_attr( $subscribe_field_id . '-label' ); ?>"
[811] Fix | Delete
for="<?php echo esc_attr( $subscribe_field_id ); ?>"
[812] Fix | Delete
class="screen-reader-text"
[813] Fix | Delete
>
[814] Fix | Delete
<?php echo esc_html( $data['subscribe_placeholder'] ); ?>
[815] Fix | Delete
</label>
[816] Fix | Delete
<?php
[817] Fix | Delete
printf(
[818] Fix | Delete
'<input
[819] Fix | Delete
required="required"
[820] Fix | Delete
type="email"
[821] Fix | Delete
name="email"
[822] Fix | Delete
autocomplete="email"
[823] Fix | Delete
%1$s
[824] Fix | Delete
style="%2$s"
[825] Fix | Delete
placeholder="%3$s"
[826] Fix | Delete
value="%4$s"
[827] Fix | Delete
id="%5$s"
[828] Fix | Delete
%6$s
[829] Fix | Delete
/>',
[830] Fix | Delete
( ! empty( $classes['email_field'] )
[831] Fix | Delete
? 'class="' . esc_attr( $classes['email_field'] ) . '"'
[832] Fix | Delete
: ''
[833] Fix | Delete
),
[834] Fix | Delete
( ! empty( $styles['email_field'] )
[835] Fix | Delete
? esc_attr( $styles['email_field'] )
[836] Fix | Delete
: 'width: 95%; padding: 1px 10px'
[837] Fix | Delete
),
[838] Fix | Delete
esc_attr( $data['subscribe_placeholder'] ),
[839] Fix | Delete
esc_attr( $data['subscribe_email'] ),
[840] Fix | Delete
esc_attr( $subscribe_field_id ),
[841] Fix | Delete
( ! empty( $data['subscribe_email'] )
[842] Fix | Delete
? 'disabled title="' . esc_attr__( "You're logged in with this email", 'jetpack' ) . '"'
[843] Fix | Delete
: 'title="' . esc_attr__( 'Please fill in this field.', 'jetpack' ) . '"'
[844] Fix | Delete
)
[845] Fix | Delete
);
[846] Fix | Delete
?>
[847] Fix | Delete
</p>
[848] Fix | Delete
<?php endif; ?>
[849] Fix | Delete
<p id="subscribe-submit"
[850] Fix | Delete
<?php if ( ! empty( $styles['submit_button_wrapper'] ) ) : ?>
[851] Fix | Delete
style="<?php echo esc_attr( $styles['submit_button_wrapper'] ); ?>"
[852] Fix | Delete
<?php endif; ?>
[853] Fix | Delete
>
[854] Fix | Delete
<input type="hidden" name="action" value="subscribe"/>
[855] Fix | Delete
<input type="hidden" name="blog_id" value="<?php echo (int) $blog_id; ?>"/>
[856] Fix | Delete
<input type="hidden" name="source" value="<?php echo esc_url( $data['referer'] ); ?>"/>
[857] Fix | Delete
<input type="hidden" name="sub-type" value="<?php echo esc_attr( $data['source'] ); ?>"/>
[858] Fix | Delete
<input type="hidden" name="app_source" value="<?php echo esc_attr( $data['app_source'] ); ?>"/>
[859] Fix | Delete
<input type="hidden" name="redirect_fragment" value="<?php echo esc_attr( $form_id ); ?>"/>
[860] Fix | Delete
<input type="hidden" name="lang" value="<?php echo esc_attr( $lang ); ?>"/>
[861] Fix | Delete
<?php
[862] Fix | Delete
wp_nonce_field( 'blogsub_subscribe_' . $blog_id );
[863] Fix | Delete
[864] Fix | Delete
if ( ! empty( $post_id ) ) {
[865] Fix | Delete
echo '<input type="hidden" name="post_id" value="' . esc_attr( $post_id ) . '"/>';
[866] Fix | Delete
}
[867] Fix | Delete
[868] Fix | Delete
if ( ! empty( $tier_id ) ) {
[869] Fix | Delete
echo '<input type="hidden" name="tier_id" value="' . esc_attr( $tier_id ) . '"/>';
[870] Fix | Delete
}
[871] Fix | Delete
[872] Fix | Delete
if ( $data['preselected_newsletter_categories'] && ! empty( $data['selected_newsletter_categories'] ) ) {
[873] Fix | Delete
echo '<input type="hidden" name="selected_newsletter_categories" value="' . esc_attr( implode( ',', $data['selected_newsletter_categories'] ) ) . '"/>';
[874] Fix | Delete
}
[875] Fix | Delete
?>
[876] Fix | Delete
<button type="submit"
[877] Fix | Delete
<?php if ( ! empty( $classes['submit_button'] ) ) : ?>
[878] Fix | Delete
class="<?php echo esc_attr( $classes['submit_button'] ); ?>"
[879] Fix | Delete
<?php endif; ?>
[880] Fix | Delete
<?php if ( ! empty( $styles['submit_button'] ) ) : ?>
[881] Fix | Delete
style="<?php echo esc_attr( $styles['submit_button'] ); ?>"
[882] Fix | Delete
<?php endif; ?>
[883] Fix | Delete
name="jetpack_subscriptions_widget"
[884] Fix | Delete
>
[885] Fix | Delete
<?php echo sanitize_submit_text( $button_text ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
[886] Fix | Delete
</button>
[887] Fix | Delete
</p>
[888] Fix | Delete
</div>
[889] Fix | Delete
</form>
[890] Fix | Delete
<?php endif; ?>
[891] Fix | Delete
<?php if ( $show_subscriber_count ) : ?>
[892] Fix | Delete
<div class="wp-block-jetpack-subscriptions__subscount">
[893] Fix | Delete
<?php echo esc_html( Jetpack_Memberships::get_join_others_text( $data['subscribers_total'] ) ); ?>
[894] Fix | Delete
</div>
[895] Fix | Delete
<?php endif; ?>
[896] Fix | Delete
</div>
[897] Fix | Delete
</div>
[898] Fix | Delete
<?php
[899] Fix | Delete
return ob_get_clean();
[900] Fix | Delete
}
[901] Fix | Delete
[902] Fix | Delete
/**
[903] Fix | Delete
* Renders the email version of the subscriptions block.
[904] Fix | Delete
*
[905] Fix | Delete
* @param array $data Array containing block view data.
[906] Fix | Delete
* @param array $styles Array containing the styles for different block elements.
[907] Fix | Delete
*
[908] Fix | Delete
* @return string
[909] Fix | Delete
*/
[910] Fix | Delete
function render_for_email( $data, $styles ) {
[911] Fix | Delete
$submit_button_wrapper_style = ! empty( $styles['submit_button_wrapper'] ) ? 'style="' . esc_attr( $styles['submit_button_wrapper'] ) . '"' : '';
[912] Fix | Delete
$button_text = get_submit_button_text( $data );
[913] Fix | Delete
[914] Fix | Delete
$html = '<div ' . wp_kses_data( $data['wrapper_attributes'] ) . '>
[915] Fix | Delete
<div>
[916] Fix | Delete
<div>
[917] Fix | Delete
<div>
[918] Fix | Delete
<p ' . $submit_button_wrapper_style . '>
[919] Fix | Delete
<a href="' . esc_url( get_post_permalink() ) . '" style="' . esc_attr( $styles['submit_button'] ) . ' text-decoration: none; white-space: nowrap; margin-left: 0">' . sanitize_submit_text( $button_text ) . '</a>
[920] Fix | Delete
</p>
[921] Fix | Delete
</div>
[922] Fix | Delete
</div>
[923] Fix | Delete
</div>
[924] Fix | Delete
</div>';
[925] Fix | Delete
[926] Fix | Delete
return $html;
[927] Fix | Delete
}
[928] Fix | Delete
[929] Fix | Delete
/**
[930] Fix | Delete
* WooCommerce Email Editor render callback for the subscriptions block.
[931] Fix | Delete
*
[932] Fix | Delete
* @param string $block_content The block content.
[933] Fix | Delete
* @param array $parsed_block The parsed block data.
[934] Fix | Delete
* @param object $rendering_context The email rendering context.
[935] Fix | Delete
*
[936] Fix | Delete
* @return string
[937] Fix | Delete
*/
[938] Fix | Delete
function render_email( $block_content, array $parsed_block, $rendering_context ) {
[939] Fix | Delete
if ( ! isset( $parsed_block['attrs'] ) || ! is_array( $parsed_block['attrs'] ) || ! function_exists( '\Automattic\Jetpack\Extensions\Button\render_email' ) || ! class_exists( '\Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks\Button' ) ) {
[940] Fix | Delete
return '';
[941] Fix | Delete
}
[942] Fix | Delete
[943] Fix | Delete
// Map subscription block attributes to button block attributes
[944] Fix | Delete
$button_attributes = array(
[945] Fix | Delete
'text' => ! empty( $parsed_block['attrs']['submitButtonText'] ) ? sanitize_text_field( $parsed_block['attrs']['submitButtonText'] ) : __( 'Subscribe', 'jetpack' ),
[946] Fix | Delete
'url' => get_post_permalink(),
[947] Fix | Delete
'element' => 'a',
[948] Fix | Delete
// Map background colors
[949] Fix | Delete
'backgroundColor' => $parsed_block['attrs']['buttonBackgroundColor'] ?? null,
[950] Fix | Delete
'customBackgroundColor' => $parsed_block['attrs']['customButtonBackgroundColor'] ?? null,
[951] Fix | Delete
// Map text colors
[952] Fix | Delete
'textColor' => $parsed_block['attrs']['textColor'] ?? null,
[953] Fix | Delete
'customTextColor' => $parsed_block['attrs']['customTextColor'] ?? null,
[954] Fix | Delete
// Map borders
[955] Fix | Delete
'borderRadius' => $parsed_block['attrs']['borderRadius'] ?? 0,
[956] Fix | Delete
'borderWeight' => $parsed_block['attrs']['borderWeight'] ?? 1,
[957] Fix | Delete
'borderColor' => $parsed_block['attrs']['borderColor'] ?? null,
[958] Fix | Delete
'customBorderColor' => $parsed_block['attrs']['customBorderColor'] ?? null,
[959] Fix | Delete
// Map typography
[960] Fix | Delete
'fontSize' => $parsed_block['attrs']['fontSize'] ?? null,
[961] Fix | Delete
'customFontSize' => $parsed_block['attrs']['customFontSize'] ?? null,
[962] Fix | Delete
// Map spacing
[963] Fix | Delete
'padding' => $parsed_block['attrs']['padding'] ?? null,
[964] Fix | Delete
);
[965] Fix | Delete
[966] Fix | Delete
// Create a mock button block structure
[967] Fix | Delete
$button_parsed_block = array(
[968] Fix | Delete
'attrs' => $button_attributes,
[969] Fix | Delete
'email_attrs' => $parsed_block['email_attrs'] ?? array(),
[970] Fix | Delete
);
[971] Fix | Delete
[972] Fix | Delete
// Call the Jetpack button's email rendering
[973] Fix | Delete
return \Automattic\Jetpack\Extensions\Button\render_email(
[974] Fix | Delete
$block_content,
[975] Fix | Delete
$button_parsed_block,
[976] Fix | Delete
$rendering_context
[977] Fix | Delete
);
[978] Fix | Delete
}
[979] Fix | Delete
[980] Fix | Delete
/**
[981] Fix | Delete
* Gate access to posts
[982] Fix | Delete
*
[983] Fix | Delete
* @param string $the_content Post content.
[984] Fix | Delete
*
[985] Fix | Delete
* @return string
[986] Fix | Delete
*/
[987] Fix | Delete
function add_paywall( $the_content ) {
[988] Fix | Delete
require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php';
[989] Fix | Delete
[990] Fix | Delete
$post_access_level = Jetpack_Memberships::get_post_access_level();
[991] Fix | Delete
[992] Fix | Delete
if ( Jetpack_Memberships::user_can_view_post() ) {
[993] Fix | Delete
if ( $post_access_level !== Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_EVERYBODY ) {
[994] Fix | Delete
do_action(
[995] Fix | Delete
'earn_track_paywalled_post_view',
[996] Fix | Delete
array(
[997] Fix | Delete
'post_id' => get_the_ID(),
[998] Fix | Delete
)
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function