Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/extensio.../blocks/subscrip...
File: subscriptions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Subscriptions Block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\Jetpack\Extensions\Subscriptions;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\Jetpack\Blocks;
[9] Fix | Delete
use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Abstract_Token_Subscription_Service;
[10] Fix | Delete
use Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Jetpack_Token_Subscription_Service;
[11] Fix | Delete
use Automattic\Jetpack\Modules;
[12] Fix | Delete
use Automattic\Jetpack\Status\Host;
[13] Fix | Delete
use Automattic\Jetpack\Status\Request;
[14] Fix | Delete
use Jetpack_Gutenberg;
[15] Fix | Delete
use Jetpack_Memberships;
[16] Fix | Delete
use Jetpack_Subscriptions_Widget;
[17] Fix | Delete
[18] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[19] Fix | Delete
exit( 0 );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
require_once __DIR__ . '/class-jetpack-subscription-site.php';
[23] Fix | Delete
require_once __DIR__ . '/constants.php';
[24] Fix | Delete
require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/premium-content/_inc/subscription-service/include.php';
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* These block defaults should match ./constants.js
[28] Fix | Delete
*/
[29] Fix | Delete
const DEFAULT_BORDER_RADIUS_VALUE = 0;
[30] Fix | Delete
const DEFAULT_BORDER_WEIGHT_VALUE = 1;
[31] Fix | Delete
const DEFAULT_FONTSIZE_VALUE = '16px';
[32] Fix | Delete
const DEFAULT_PADDING_VALUE = 15;
[33] Fix | Delete
const DEFAULT_SPACING_VALUE = 10;
[34] Fix | Delete
const DEFAULT_BUTTON_WIDTH = 'auto';
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Registers the block for use in Gutenberg
[38] Fix | Delete
* This is done via an action so that we can disable
[39] Fix | Delete
* registration if we need to.
[40] Fix | Delete
*/
[41] Fix | Delete
function register_block() {
[42] Fix | Delete
/*
[43] Fix | Delete
* Disable the feature on P2 blogs
[44] Fix | Delete
*/
[45] Fix | Delete
if ( function_exists( '\WPForTeams\is_wpforteams_site' ) &&
[46] Fix | Delete
\WPForTeams\is_wpforteams_site( get_current_blog_id() ) ) {
[47] Fix | Delete
return;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/*
[51] Fix | Delete
* Do not proceed if the newsletter feature (Subscriptions module) is not enabled
[52] Fix | Delete
*/
[53] Fix | Delete
if ( ! ( new Modules() )->is_active( 'subscriptions' ) ) {
[54] Fix | Delete
return;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
[58] Fix | Delete
[59] Fix | Delete
if ( \Jetpack_Memberships::should_enable_monetize_blocks_in_editor() ) {
[60] Fix | Delete
Blocks::jetpack_register_block(
[61] Fix | Delete
__DIR__,
[62] Fix | Delete
array(
[63] Fix | Delete
'render_callback' => __NAMESPACE__ . '\render_block',
[64] Fix | Delete
'render_email_callback' => __NAMESPACE__ . '\render_email',
[65] Fix | Delete
'supports' => array(
[66] Fix | Delete
'spacing' => array(
[67] Fix | Delete
'margin' => true,
[68] Fix | Delete
'padding' => true,
[69] Fix | Delete
),
[70] Fix | Delete
'align' => array( 'wide', 'full' ),
[71] Fix | Delete
),
[72] Fix | Delete
)
[73] Fix | Delete
);
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
register_post_meta(
[77] Fix | Delete
'post',
[78] Fix | Delete
META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS,
[79] Fix | Delete
array(
[80] Fix | Delete
'show_in_rest' => true,
[81] Fix | Delete
'single' => true,
[82] Fix | Delete
'type' => 'string',
[83] Fix | Delete
'auth_callback' => function () {
[84] Fix | Delete
return wp_get_current_user()->has_cap( 'edit_posts' );
[85] Fix | Delete
},
[86] Fix | Delete
)
[87] Fix | Delete
);
[88] Fix | Delete
[89] Fix | Delete
register_post_meta(
[90] Fix | Delete
'post',
[91] Fix | Delete
META_NAME_FOR_POST_DONT_EMAIL_TO_SUBS,
[92] Fix | Delete
array(
[93] Fix | Delete
'default' => false,
[94] Fix | Delete
'show_in_rest' => true,
[95] Fix | Delete
'single' => true,
[96] Fix | Delete
'type' => 'boolean',
[97] Fix | Delete
'auth_callback' => function () {
[98] Fix | Delete
return wp_get_current_user()->has_cap( 'edit_posts' );
[99] Fix | Delete
},
[100] Fix | Delete
)
[101] Fix | Delete
);
[102] Fix | Delete
[103] Fix | Delete
register_post_meta(
[104] Fix | Delete
'post',
[105] Fix | Delete
META_NAME_FOR_POST_TIER_ID_SETTINGS,
[106] Fix | Delete
array(
[107] Fix | Delete
'show_in_rest' => true,
[108] Fix | Delete
'single' => true,
[109] Fix | Delete
'type' => 'integer',
[110] Fix | Delete
'auth_callback' => function () {
[111] Fix | Delete
return wp_get_current_user()->has_cap( 'edit_posts' );
[112] Fix | Delete
},
[113] Fix | Delete
)
[114] Fix | Delete
);
[115] Fix | Delete
[116] Fix | Delete
register_post_meta(
[117] Fix | Delete
'post',
[118] Fix | Delete
META_NAME_CONTAINS_PAYWALLED_CONTENT,
[119] Fix | Delete
array(
[120] Fix | Delete
'show_in_rest' => true,
[121] Fix | Delete
'single' => true,
[122] Fix | Delete
'type' => 'boolean',
[123] Fix | Delete
'auth_callback' => function () {
[124] Fix | Delete
return wp_get_current_user()->has_cap( 'edit_posts' );
[125] Fix | Delete
},
[126] Fix | Delete
)
[127] Fix | Delete
);
[128] Fix | Delete
[129] Fix | Delete
// This ensures Jetpack will sync this post meta to WPCOM.
[130] Fix | Delete
add_filter(
[131] Fix | Delete
'jetpack_sync_post_meta_whitelist',
[132] Fix | Delete
function ( $allowed_meta ) {
[133] Fix | Delete
return array_merge(
[134] Fix | Delete
$allowed_meta,
[135] Fix | Delete
array(
[136] Fix | Delete
META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS,
[137] Fix | Delete
META_NAME_FOR_POST_DONT_EMAIL_TO_SUBS,
[138] Fix | Delete
META_NAME_CONTAINS_PAYWALLED_CONTENT,
[139] Fix | Delete
)
[140] Fix | Delete
);
[141] Fix | Delete
}
[142] Fix | Delete
);
[143] Fix | Delete
[144] Fix | Delete
// Hide the content – Priority 8 makes it run before do_blocks gets called for the content
[145] Fix | Delete
add_filter( 'the_content', __NAMESPACE__ . '\add_paywall', 8 );
[146] Fix | Delete
[147] Fix | Delete
// Close comments on the front-end
[148] Fix | Delete
add_filter( 'comments_open', __NAMESPACE__ . '\maybe_close_comments', 10, 2 );
[149] Fix | Delete
add_filter( 'pings_open', __NAMESPACE__ . '\maybe_close_comments', 10, 2 );
[150] Fix | Delete
[151] Fix | Delete
// Hide existing comments
[152] Fix | Delete
add_filter( 'get_comment', __NAMESPACE__ . '\maybe_gate_existing_comments' );
[153] Fix | Delete
[154] Fix | Delete
// Add a 'Newsletter' column to the Edit posts page
[155] Fix | Delete
// We only display the "Newsletter" column if we have configured the paid newsletter plan
[156] Fix | Delete
if ( defined( 'WP_ADMIN' ) && WP_ADMIN && Jetpack_Memberships::has_configured_plans_jetpack_recurring_payments( 'newsletter' ) ) {
[157] Fix | Delete
add_action( 'manage_post_posts_columns', __NAMESPACE__ . '\register_newsletter_access_column' );
[158] Fix | Delete
add_action( 'manage_post_posts_custom_column', __NAMESPACE__ . '\render_newsletter_access_rows', 10, 2 );
[159] Fix | Delete
add_action( 'admin_head', __NAMESPACE__ . '\newsletter_access_column_styles' );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
add_action( 'init', __NAMESPACE__ . '\maybe_prevent_super_cache_caching' );
[163] Fix | Delete
[164] Fix | Delete
add_action( 'wp_after_insert_post', __NAMESPACE__ . '\add_paywalled_content_post_meta', 99, 2 );
[165] Fix | Delete
[166] Fix | Delete
add_filter(
[167] Fix | Delete
'jetpack_options_whitelist',
[168] Fix | Delete
function ( $options ) {
[169] Fix | Delete
$options[] = 'jetpack_subscriptions_subscribe_post_end_enabled';
[170] Fix | Delete
$options[] = 'jetpack_subscriptions_subscribe_navigation_enabled';
[171] Fix | Delete
[172] Fix | Delete
return $options;
[173] Fix | Delete
}
[174] Fix | Delete
);
[175] Fix | Delete
[176] Fix | Delete
// If called via REST API, we need to register later in the lifecycle
[177] Fix | Delete
if ( ( new Host() )->is_wpcom_platform() && ! Request::is_frontend() ) {
[178] Fix | Delete
add_action(
[179] Fix | Delete
'restapi_theme_init',
[180] Fix | Delete
function () {
[181] Fix | Delete
Jetpack_Subscription_Site::init()->handle_subscribe_block_placements();
[182] Fix | Delete
}
[183] Fix | Delete
);
[184] Fix | Delete
} else {
[185] Fix | Delete
Jetpack_Subscription_Site::init()->handle_subscribe_block_placements();
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
add_action( 'init', __NAMESPACE__ . '\register_block', 9 );
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Returns true when in a WP.com environment.
[192] Fix | Delete
*
[193] Fix | Delete
* @return boolean
[194] Fix | Delete
*/
[195] Fix | Delete
function is_wpcom() {
[196] Fix | Delete
return defined( 'IS_WPCOM' ) && IS_WPCOM;
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Adds a 'Newsletter' column after the 'Title' column in the post list
[201] Fix | Delete
*
[202] Fix | Delete
* @param array $columns An array of column names.
[203] Fix | Delete
* @return array An array of column names.
[204] Fix | Delete
*/
[205] Fix | Delete
function register_newsletter_access_column( $columns ) {
[206] Fix | Delete
$position = array_search( 'title', array_keys( $columns ), true );
[207] Fix | Delete
$new_column = array( NEWSLETTER_COLUMN_ID => __( 'Newsletter', 'jetpack' ) );
[208] Fix | Delete
return array_merge(
[209] Fix | Delete
array_slice( $columns, 0, $position + 1, true ),
[210] Fix | Delete
$new_column,
[211] Fix | Delete
array_slice( $columns, $position, null, true )
[212] Fix | Delete
);
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Add a meta to prevent publication on firehose, ES AI or Reader
[217] Fix | Delete
*
[218] Fix | Delete
* @param int $post_id Post id being saved.
[219] Fix | Delete
* @param \WP_Post $post Post being saved.
[220] Fix | Delete
* @return void
[221] Fix | Delete
*/
[222] Fix | Delete
function add_paywalled_content_post_meta( int $post_id, \WP_Post $post ) {
[223] Fix | Delete
if ( $post->post_type !== 'post' ) {
[224] Fix | Delete
return;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
$access_level = get_post_meta( $post_id, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
[228] Fix | Delete
[229] Fix | Delete
$is_paywalled = false;
[230] Fix | Delete
switch ( $access_level ) {
[231] Fix | Delete
case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS_ALL_TIERS:
[232] Fix | Delete
case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS:
[233] Fix | Delete
case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_SUBSCRIBERS:
[234] Fix | Delete
$is_paywalled = true;
[235] Fix | Delete
}
[236] Fix | Delete
if ( $is_paywalled ) {
[237] Fix | Delete
update_post_meta( $post_id, META_NAME_CONTAINS_PAYWALLED_CONTENT, $is_paywalled );
[238] Fix | Delete
}
[239] Fix | Delete
if ( ! $is_paywalled ) {
[240] Fix | Delete
delete_post_meta( $post_id, META_NAME_CONTAINS_PAYWALLED_CONTENT );
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Displays the newsletter access level.
[246] Fix | Delete
*
[247] Fix | Delete
* @param string $column_id The ID of the column to display.
[248] Fix | Delete
* @param int $post_id The current post ID.
[249] Fix | Delete
*/
[250] Fix | Delete
function render_newsletter_access_rows( $column_id, $post_id ) {
[251] Fix | Delete
if ( NEWSLETTER_COLUMN_ID !== $column_id ) {
[252] Fix | Delete
return;
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
$access_level = get_post_meta( $post_id, META_NAME_FOR_POST_LEVEL_ACCESS_SETTINGS, true );
[256] Fix | Delete
[257] Fix | Delete
switch ( $access_level ) {
[258] Fix | Delete
case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS_ALL_TIERS:
[259] Fix | Delete
echo esc_html__( 'Paid Subscribers (all plans)', 'jetpack' );
[260] Fix | Delete
break;
[261] Fix | Delete
case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_PAID_SUBSCRIBERS:
[262] Fix | Delete
echo esc_html__( 'Paid Subscribers', 'jetpack' );
[263] Fix | Delete
break;
[264] Fix | Delete
case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_SUBSCRIBERS:
[265] Fix | Delete
echo esc_html__( 'Subscribers', 'jetpack' );
[266] Fix | Delete
break;
[267] Fix | Delete
case Abstract_Token_Subscription_Service::POST_ACCESS_LEVEL_EVERYBODY:
[268] Fix | Delete
echo esc_html__( 'Everybody', 'jetpack' );
[269] Fix | Delete
break;
[270] Fix | Delete
default:
[271] Fix | Delete
echo '';
[272] Fix | Delete
}
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Adds the Newsletter column styles
[277] Fix | Delete
*/
[278] Fix | Delete
function newsletter_access_column_styles() {
[279] Fix | Delete
echo '<style id="jetpack-newsletter-newsletter-access-column"> table.fixed .column-newsletter_access { width: 10%; } </style>';
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Determine the amount of folks currently subscribed to the blog, splitted out in total_subscribers, email_subscribers, social_followers & paid_subscribers.
[284] Fix | Delete
*
[285] Fix | Delete
* @return array containing ['value' => ['total_subscribers' => 0, 'email_subscribers' => 0, 'paid_subscribers' => 0, 'social_followers' => 0]]
[286] Fix | Delete
*/
[287] Fix | Delete
function fetch_subscriber_counts() {
[288] Fix | Delete
$subs_count = 0;
[289] Fix | Delete
if ( is_wpcom() ) {
[290] Fix | Delete
$subs_count = array(
[291] Fix | Delete
'value' => \wpcom_fetch_subs_counts( true ),
[292] Fix | Delete
);
[293] Fix | Delete
} else {
[294] Fix | Delete
$cache_key = 'wpcom_subscribers_totals';
[295] Fix | Delete
$subs_count = get_transient( $cache_key );
[296] Fix | Delete
if ( false === $subs_count || 'failed' === $subs_count['status'] ) {
[297] Fix | Delete
$xml = new \Jetpack_IXR_Client();
[298] Fix | Delete
$xml->query( 'jetpack.fetchSubscriberCounts' );
[299] Fix | Delete
[300] Fix | Delete
if ( $xml->isError() ) { // If we get an error from .com, set the status to failed so that we will try again next time the data is requested.
[301] Fix | Delete
$subs_count = array(
[302] Fix | Delete
'status' => 'failed',
[303] Fix | Delete
'code' => $xml->getErrorCode(),
[304] Fix | Delete
'message' => $xml->getErrorMessage(),
[305] Fix | Delete
'value' => ( isset( $subs_count['value'] ) ) ? $subs_count['value'] : array(
[306] Fix | Delete
'total_subscribers' => 0,
[307] Fix | Delete
'email_subscribers' => 0,
[308] Fix | Delete
'social_followers' => 0,
[309] Fix | Delete
'paid_subscribers' => 0,
[310] Fix | Delete
),
[311] Fix | Delete
);
[312] Fix | Delete
} else {
[313] Fix | Delete
$subs_count = array(
[314] Fix | Delete
'status' => 'success',
[315] Fix | Delete
'value' => $xml->getResponse(),
[316] Fix | Delete
);
[317] Fix | Delete
}
[318] Fix | Delete
set_transient( $cache_key, $subs_count, 3600 ); // Try to cache the result for at least 1 hour.
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
return $subs_count;
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
/**
[325] Fix | Delete
* Returns subscriber count based on include_social_followers attribute
[326] Fix | Delete
*
[327] Fix | Delete
* @param bool $include_social_followers Whether to include social followers in the count.
[328] Fix | Delete
* @return int
[329] Fix | Delete
*/
[330] Fix | Delete
function get_subscriber_count( $include_social_followers ) {
[331] Fix | Delete
$counts = fetch_subscriber_counts();
[332] Fix | Delete
[333] Fix | Delete
if ( $include_social_followers ) {
[334] Fix | Delete
$subscriber_count = $counts['value']['total_subscribers'] + $counts['value']['social_followers'];
[335] Fix | Delete
} else {
[336] Fix | Delete
$subscriber_count = $counts['value']['total_subscribers'];
[337] Fix | Delete
}
[338] Fix | Delete
return $subscriber_count;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Returns true if the block attributes contain a value for the given key.
[343] Fix | Delete
*
[344] Fix | Delete
* @param array $attributes Array containing the block attributes.
[345] Fix | Delete
* @param string $key Block attribute key.
[346] Fix | Delete
*
[347] Fix | Delete
* @return boolean
[348] Fix | Delete
*/
[349] Fix | Delete
function has_attribute( $attributes, $key ) {
[350] Fix | Delete
return isset( $attributes[ $key ] ) && $attributes[ $key ] !== 'undefined';
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
/**
[354] Fix | Delete
* Returns the value for the given attribute key, with the option of providing a default fallback value.
[355] Fix | Delete
*
[356] Fix | Delete
* @param array $attributes Array containing the block attributes.
[357] Fix | Delete
* @param string $key Block attribute key.
[358] Fix | Delete
* @param mixed $default Optional fallback value in case the key doesn't exist.
[359] Fix | Delete
*
[360] Fix | Delete
* @return mixed
[361] Fix | Delete
*/
[362] Fix | Delete
function get_attribute( $attributes, $key, $default = null ) {
[363] Fix | Delete
return has_attribute( $attributes, $key ) ? $attributes[ $key ] : $default;
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
/**
[367] Fix | Delete
* Mimics getColorClassName, getFontSizeClass and getGradientClass from @wordpress/block-editor js package.
[368] Fix | Delete
*
[369] Fix | Delete
* @param string $setting Setting name.
[370] Fix | Delete
* @param string $value Setting value.
[371] Fix | Delete
*
[372] Fix | Delete
* @return string
[373] Fix | Delete
*/
[374] Fix | Delete
function get_setting_class_name( $setting, $value ) {
[375] Fix | Delete
if ( ! $setting || ! $value ) {
[376] Fix | Delete
return '';
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
return sprintf( 'has-%s-%s', $value, $setting );
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* Uses block attributes to generate an array containing the classes for various block elements.
[384] Fix | Delete
* Based on Jetpack_Subscriptions_Widget::do_subscription_form() which the block was originally using.
[385] Fix | Delete
*
[386] Fix | Delete
* @param array $attributes Array containing the block attributes.
[387] Fix | Delete
*
[388] Fix | Delete
* @return array
[389] Fix | Delete
*/
[390] Fix | Delete
function get_element_class_names_from_attributes( $attributes ) {
[391] Fix | Delete
$text_color_class = get_setting_class_name( 'color', get_attribute( $attributes, 'textColor' ) );
[392] Fix | Delete
$font_size_class = get_setting_class_name( 'font-size', get_attribute( $attributes, 'fontSize' ) );
[393] Fix | Delete
$border_class = get_setting_class_name( 'border-color', get_attribute( $attributes, 'borderColor' ) );
[394] Fix | Delete
[395] Fix | Delete
$button_background_class = get_setting_class_name( 'background-color', get_attribute( $attributes, 'buttonBackgroundColor' ) );
[396] Fix | Delete
$button_gradient_class = get_setting_class_name( 'gradient-background', get_attribute( $attributes, 'buttonGradient' ) );
[397] Fix | Delete
[398] Fix | Delete
$email_field_background_class = get_setting_class_name( 'background-color', get_attribute( $attributes, 'emailFieldBackgroundColor' ) );
[399] Fix | Delete
$email_field_gradient_class = get_setting_class_name( 'gradient-background', get_attribute( $attributes, 'emailFieldGradient' ) );
[400] Fix | Delete
[401] Fix | Delete
$submit_button_classes = array_filter(
[402] Fix | Delete
array(
[403] Fix | Delete
'wp-block-button__link' => true,
[404] Fix | Delete
'no-border-radius' => 0 === get_attribute( $attributes, 'borderRadius', 0 ),
[405] Fix | Delete
$font_size_class => true,
[406] Fix | Delete
$border_class => true,
[407] Fix | Delete
'has-text-color' => ! empty( $text_color_class ),
[408] Fix | Delete
$text_color_class => true,
[409] Fix | Delete
'has-background' => ! empty( $button_background_class ) || ! empty( $button_gradient_class ),
[410] Fix | Delete
$button_background_class => ! empty( $button_background_class ),
[411] Fix | Delete
$button_gradient_class => ! empty( $button_gradient_class ),
[412] Fix | Delete
)
[413] Fix | Delete
);
[414] Fix | Delete
[415] Fix | Delete
$email_field_classes = array_filter(
[416] Fix | Delete
array(
[417] Fix | Delete
'no-border-radius' => 0 === get_attribute( $attributes, 'borderRadius', 0 ),
[418] Fix | Delete
$font_size_class => true,
[419] Fix | Delete
$border_class => true,
[420] Fix | Delete
$email_field_background_class => true,
[421] Fix | Delete
$email_field_gradient_class => true,
[422] Fix | Delete
)
[423] Fix | Delete
);
[424] Fix | Delete
[425] Fix | Delete
$block_wrapper_classes = array_filter(
[426] Fix | Delete
array(
[427] Fix | Delete
'wp-block-jetpack-subscriptions__supports-newline' => true,
[428] Fix | Delete
'wp-block-jetpack-subscriptions__use-newline' => (bool) get_attribute( $attributes, 'buttonOnNewLine' ),
[429] Fix | Delete
'wp-block-jetpack-subscriptions__show-subs' => (bool) get_attribute( $attributes, 'showSubscribersTotal' ),
[430] Fix | Delete
)
[431] Fix | Delete
);
[432] Fix | Delete
[433] Fix | Delete
return array(
[434] Fix | Delete
'block_wrapper' => implode( ' ', array_keys( $block_wrapper_classes ) ),
[435] Fix | Delete
'email_field' => implode( ' ', array_keys( $email_field_classes ) ),
[436] Fix | Delete
'submit_button' => implode( ' ', array_keys( $submit_button_classes ) ),
[437] Fix | Delete
);
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
/**
[441] Fix | Delete
* Checks if block style is "button only"
[442] Fix | Delete
*
[443] Fix | Delete
* @param string $class_name Block attribute className; multiple names are spearated by space.
[444] Fix | Delete
*
[445] Fix | Delete
* @return bool
[446] Fix | Delete
*/
[447] Fix | Delete
function is_button_only_style( $class_name ) {
[448] Fix | Delete
if ( empty( $class_name ) ) {
[449] Fix | Delete
return false;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$class_names = explode( ' ', $class_name );
[453] Fix | Delete
return in_array( 'is-style-button', $class_names, true );
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
/**
[457] Fix | Delete
* Uses block attributes to generate an array containing the styles for various block elements.
[458] Fix | Delete
* Based on Jetpack_Subscriptions_Widget::do_subscription_form() which the block was originally using.
[459] Fix | Delete
*
[460] Fix | Delete
* @param array $attributes Array containing the block attributes.
[461] Fix | Delete
*
[462] Fix | Delete
* @return array
[463] Fix | Delete
*/
[464] Fix | Delete
function get_element_styles_from_attributes( $attributes ) {
[465] Fix | Delete
$is_button_only_style = is_button_only_style( get_attribute( $attributes, 'className', '' ) );
[466] Fix | Delete
[467] Fix | Delete
$button_background_style = ! has_attribute( $attributes, 'buttonBackgroundColor' ) && has_attribute( $attributes, 'customButtonGradient' )
[468] Fix | Delete
? get_attribute( $attributes, 'customButtonGradient' )
[469] Fix | Delete
: get_attribute( $attributes, 'customButtonBackgroundColor' );
[470] Fix | Delete
[471] Fix | Delete
$email_field_styles = '';
[472] Fix | Delete
$submit_button_wrapper_styles = '';
[473] Fix | Delete
$submit_button_styles = '';
[474] Fix | Delete
[475] Fix | Delete
if ( ! empty( $button_background_style ) ) {
[476] Fix | Delete
$submit_button_styles .= sprintf( 'background: %s;', $button_background_style );
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
if ( has_attribute( $attributes, 'customTextColor' ) ) {
[480] Fix | Delete
$submit_button_styles .= sprintf( 'color: %s;', get_attribute( $attributes, 'customTextColor' ) );
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
if ( has_attribute( $attributes, 'buttonWidth' ) ) {
[484] Fix | Delete
$submit_button_wrapper_styles .= sprintf( 'width: %s;', get_attribute( $attributes, 'buttonWidth', DEFAULT_BUTTON_WIDTH ) );
[485] Fix | Delete
$submit_button_wrapper_styles .= 'max-width: 100%;';
[486] Fix | Delete
[487] Fix | Delete
// Account for custom margins on inline forms.
[488] Fix | Delete
$submit_button_styles .= true === get_attribute( $attributes, 'buttonOnNewLine' )
[489] Fix | Delete
? 'width: 100%;'
[490] Fix | Delete
: sprintf( 'width: calc(100%% - %dpx);', get_attribute( $attributes, 'spacing', DEFAULT_SPACING_VALUE ) );
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
$font_size = get_attribute( $attributes, 'customFontSize', DEFAULT_FONTSIZE_VALUE );
[494] Fix | Delete
$style = sprintf( 'font-size: %s%s;', $font_size, is_numeric( $font_size ) ? 'px' : '' );
[495] Fix | Delete
[496] Fix | Delete
$submit_button_styles .= $style;
[497] Fix | Delete
$email_field_styles .= $style;
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function