Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/extensio.../blocks/button
File: button.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Button Block.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 8.5.0
[4] Fix | Delete
*
[5] Fix | Delete
* @package automattic/jetpack
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
namespace Automattic\Jetpack\Extensions\Button;
[9] Fix | Delete
[10] Fix | Delete
use Automattic\Jetpack\Blocks;
[11] Fix | Delete
use Jetpack_Gutenberg;
[12] Fix | Delete
[13] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[14] Fix | Delete
exit( 0 );
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
const FEATURE_NAME = 'button';
[18] Fix | Delete
const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Registers the block for use in Gutenberg
[22] Fix | Delete
* This is done via an action so that we can disable
[23] Fix | Delete
* registration if we need to.
[24] Fix | Delete
*/
[25] Fix | Delete
function register_block() {
[26] Fix | Delete
Blocks::jetpack_register_block(
[27] Fix | Delete
BLOCK_NAME,
[28] Fix | Delete
array(
[29] Fix | Delete
'render_callback' => __NAMESPACE__ . '\render_block',
[30] Fix | Delete
'render_email_callback' => __NAMESPACE__ . '\render_email',
[31] Fix | Delete
'uses_context' => array( 'jetpack/parentBlockWidth' ),
[32] Fix | Delete
'selectors' => array(
[33] Fix | Delete
'border' => '.wp-block-jetpack-button .wp-block-button__link',
[34] Fix | Delete
),
[35] Fix | Delete
)
[36] Fix | Delete
);
[37] Fix | Delete
}
[38] Fix | Delete
add_action( 'init', __NAMESPACE__ . '\register_block' );
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Button block render callback.
[42] Fix | Delete
*
[43] Fix | Delete
* @param array $attributes Array containing the Button block attributes.
[44] Fix | Delete
* @param string $content The Button block content.
[45] Fix | Delete
*
[46] Fix | Delete
* @return string
[47] Fix | Delete
*/
[48] Fix | Delete
function render_block( $attributes, $content ) {
[49] Fix | Delete
$save_in_post_content = get_attribute( $attributes, 'saveInPostContent' );
[50] Fix | Delete
[51] Fix | Delete
// The Jetpack Button block depends on the core button block styles.
[52] Fix | Delete
// The following ensures that those styles are enqueued when rendering this block.
[53] Fix | Delete
enqueue_existing_button_style_dependency( 'core/button' );
[54] Fix | Delete
enqueue_existing_button_style_dependency( 'core/buttons' );
[55] Fix | Delete
[56] Fix | Delete
Jetpack_Gutenberg::load_styles_as_required( FEATURE_NAME );
[57] Fix | Delete
[58] Fix | Delete
if ( $save_in_post_content || ! class_exists( 'DOMDocument' ) ) {
[59] Fix | Delete
return $content;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
$element = get_attribute( $attributes, 'element' );
[63] Fix | Delete
$text = wp_kses_post( get_attribute( $attributes, 'text' ) );
[64] Fix | Delete
$unique_id = get_attribute( $attributes, 'uniqueId' );
[65] Fix | Delete
$url = get_attribute( $attributes, 'url' );
[66] Fix | Delete
$classes = Blocks::classes( FEATURE_NAME, $attributes, array( 'wp-block-button' ) );
[67] Fix | Delete
[68] Fix | Delete
$button_classes = get_button_classes( $attributes );
[69] Fix | Delete
$button_styles = get_button_styles( $attributes );
[70] Fix | Delete
$wrapper_styles = get_button_wrapper_styles( $attributes );
[71] Fix | Delete
[72] Fix | Delete
$wrapper_attributes = sprintf( ' class="%s" style="%s"', esc_attr( $classes ), esc_attr( $wrapper_styles ) );
[73] Fix | Delete
$button_attributes = sprintf( ' class="%s" style="%s"', esc_attr( $button_classes ), esc_attr( $button_styles ) );
[74] Fix | Delete
[75] Fix | Delete
if ( empty( $unique_id ) ) {
[76] Fix | Delete
$button_attributes .= ' data-id-attr="placeholder"';
[77] Fix | Delete
} else {
[78] Fix | Delete
$button_attributes .= sprintf( ' data-id-attr="%1$s" id="%1$s"', esc_attr( $unique_id ) );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
if ( ! in_array( $element, array( 'a', 'button', 'input' ), true ) ) {
[82] Fix | Delete
$element = 'a';
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
if ( 'a' === $element ) {
[86] Fix | Delete
$button_attributes .= sprintf( ' href="%s" target="_blank" role="button" rel="noopener noreferrer"', esc_url( $url ) );
[87] Fix | Delete
} elseif ( 'button' === $element ) {
[88] Fix | Delete
$button_attributes .= ' type="submit"';
[89] Fix | Delete
} elseif ( 'input' === $element ) {
[90] Fix | Delete
$button_attributes .= sprintf( ' type="submit" value="%s"', esc_attr( wp_strip_all_tags( $text, true ) ) );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$button_attributes .= ' data-wp-class--is-submitting="state.isSubmitting" data-wp-bind--aria-disabled="state.isAriaDisabled"';
[94] Fix | Delete
[95] Fix | Delete
$svg = '<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z" opacity=".25"/><path d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"><animateTransform attributeName="transform" type="rotate" dur="0.75s" values="0 12 12;360 12 12" repeatCount="indefinite"/></path></svg>';
[96] Fix | Delete
$form_submitting_text = '<span class="is-visually-hidden">' . __( 'Submitting form', 'jetpack' ) . '</span>';
[97] Fix | Delete
$spinner = '<span class="spinner" aria-hidden="true">' . $svg . $form_submitting_text . '</span>';
[98] Fix | Delete
[99] Fix | Delete
$button = 'input' === $element
[100] Fix | Delete
? '<' . $element . $button_attributes . ' />'
[101] Fix | Delete
: '<' . $element . $button_attributes . '>' . $text . $spinner . '</' . $element . '>';
[102] Fix | Delete
[103] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[104] Fix | Delete
return '<div' . $wrapper_attributes . '>' . $button . '</div>';
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* WooCommerce Email Editor render callback for the button block.
[109] Fix | Delete
*
[110] Fix | Delete
* @param string $block_content The block content.
[111] Fix | Delete
* @param array $parsed_block The parsed block data.
[112] Fix | Delete
* @param object $rendering_context The email rendering context.
[113] Fix | Delete
*
[114] Fix | Delete
* @return string
[115] Fix | Delete
*/
[116] Fix | Delete
function render_email( $block_content, array $parsed_block, $rendering_context ) {
[117] Fix | Delete
// Validate input parameters and required dependencies
[118] Fix | Delete
if ( ! isset( $parsed_block['attrs'] ) || ! is_array( $parsed_block['attrs'] ) ||
[119] Fix | Delete
! class_exists( '\Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks\Button' ) ) {
[120] Fix | Delete
return '';
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
$attributes = $parsed_block['attrs'];
[124] Fix | Delete
[125] Fix | Delete
// Create a mock innerHTML that WooCommerce's button renderer can parse
[126] Fix | Delete
$button_text = ! empty( $attributes['text'] ) ? sanitize_text_field( $attributes['text'] ) : __( 'Click here', 'jetpack' );
[127] Fix | Delete
$button_url = ! empty( $attributes['url'] ) ? $attributes['url'] : '#';
[128] Fix | Delete
[129] Fix | Delete
// Create the innerHTML that WooCommerce's button renderer expects
[130] Fix | Delete
$inner_html = sprintf(
[131] Fix | Delete
'<div class="wp-block-button"><a class="wp-block-button__link" href="%s">%s</a></div>',
[132] Fix | Delete
esc_url( $button_url ),
[133] Fix | Delete
esc_html( $button_text )
[134] Fix | Delete
);
[135] Fix | Delete
[136] Fix | Delete
// Format attributes for WooCommerce's Styles_Helper
[137] Fix | Delete
$formatted_attributes = format_attributes_for_woocommerce( $attributes );
[138] Fix | Delete
[139] Fix | Delete
// Create a mock parsed block that WooCommerce's button renderer can handle
[140] Fix | Delete
$mock_parsed_block = array(
[141] Fix | Delete
'innerHTML' => $inner_html,
[142] Fix | Delete
'attrs' => $formatted_attributes,
[143] Fix | Delete
);
[144] Fix | Delete
[145] Fix | Delete
// Use WooCommerce's core button renderer
[146] Fix | Delete
$woo_button_renderer = new \Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks\Button();
[147] Fix | Delete
[148] Fix | Delete
return $woo_button_renderer->render( $block_content, $mock_parsed_block, $rendering_context );
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Format button attributes for WooCommerce's Styles_Helper.
[153] Fix | Delete
*
[154] Fix | Delete
* @param array $attributes The original attributes.
[155] Fix | Delete
* @return array The formatted attributes.
[156] Fix | Delete
*/
[157] Fix | Delete
function format_attributes_for_woocommerce( $attributes ) {
[158] Fix | Delete
$formatted = array();
[159] Fix | Delete
[160] Fix | Delete
// Handle background colors (prioritize subscription attributes)
[161] Fix | Delete
// Named colors go in backgroundColor, hex colors go in style.color.background
[162] Fix | Delete
if ( ! empty( $attributes['buttonBackgroundColor'] ) ) {
[163] Fix | Delete
$formatted['backgroundColor'] = $attributes['buttonBackgroundColor'];
[164] Fix | Delete
} elseif ( ! empty( $attributes['backgroundColor'] ) ) {
[165] Fix | Delete
$formatted['backgroundColor'] = $attributes['backgroundColor'];
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( ! empty( $attributes['customButtonBackgroundColor'] ) ) {
[169] Fix | Delete
$formatted['style']['color']['background'] = $attributes['customButtonBackgroundColor'];
[170] Fix | Delete
} elseif ( ! empty( $attributes['customBackgroundColor'] ) ) {
[171] Fix | Delete
$formatted['style']['color']['background'] = $attributes['customBackgroundColor'];
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
// Named colors go in textColor, hex colors go in style.color.text
[175] Fix | Delete
if ( ! empty( $attributes['textColor'] ) ) {
[176] Fix | Delete
$formatted['textColor'] = $attributes['textColor'];
[177] Fix | Delete
}
[178] Fix | Delete
if ( ! empty( $attributes['customTextColor'] ) ) {
[179] Fix | Delete
$formatted['style']['color']['text'] = $attributes['customTextColor'];
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
// Handle typography (font size)
[183] Fix | Delete
if ( ! empty( $attributes['fontSize'] ) ) {
[184] Fix | Delete
$formatted['style']['typography']['fontSize'] = $attributes['fontSize'];
[185] Fix | Delete
}
[186] Fix | Delete
if ( ! empty( $attributes['customFontSize'] ) ) {
[187] Fix | Delete
$formatted['style']['typography']['fontSize'] = $attributes['customFontSize'];
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
// Handle borders
[191] Fix | Delete
if ( ! empty( $attributes['borderRadius'] ) ) {
[192] Fix | Delete
$formatted['style']['border']['radius'] = $attributes['borderRadius'] . 'px';
[193] Fix | Delete
}
[194] Fix | Delete
// Named colors go in borderColor, hex colors go in style.color.border
[195] Fix | Delete
if ( ! empty( $attributes['borderColor'] ) ) {
[196] Fix | Delete
$formatted['borderColor'] = $attributes['borderColor'];
[197] Fix | Delete
}
[198] Fix | Delete
if ( ! empty( $attributes['customBorderColor'] ) ) {
[199] Fix | Delete
$formatted['style']['border']['color'] = $attributes['customBorderColor'];
[200] Fix | Delete
}
[201] Fix | Delete
// Handle border weight (subscription block uses borderWeight, button block expects style.border.width)
[202] Fix | Delete
if ( ! empty( $attributes['borderWeight'] ) ) {
[203] Fix | Delete
$formatted['style']['border']['width'] = $attributes['borderWeight'] . 'px';
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
// Handle padding
[207] Fix | Delete
if ( ! empty( $attributes['padding'] ) ) {
[208] Fix | Delete
$formatted['style']['spacing']['padding'] = $attributes['padding'] . 'px';
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
return $formatted;
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Get the Button block classes.
[216] Fix | Delete
*
[217] Fix | Delete
* @param array $attributes Array containing the block attributes.
[218] Fix | Delete
*
[219] Fix | Delete
* @return string
[220] Fix | Delete
*/
[221] Fix | Delete
function get_button_classes( $attributes ) {
[222] Fix | Delete
$classes = array( 'wp-block-button__link' );
[223] Fix | Delete
$has_class_name = array_key_exists( 'className', $attributes );
[224] Fix | Delete
$has_named_text_color = array_key_exists( 'textColor', $attributes );
[225] Fix | Delete
$has_custom_text_color = array_key_exists( 'customTextColor', $attributes );
[226] Fix | Delete
$has_named_background_color = array_key_exists( 'backgroundColor', $attributes );
[227] Fix | Delete
$has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes );
[228] Fix | Delete
$has_named_gradient = array_key_exists( 'gradient', $attributes );
[229] Fix | Delete
$has_custom_gradient = array_key_exists( 'customGradient', $attributes );
[230] Fix | Delete
$has_border_radius = array_key_exists( 'borderRadius', $attributes );
[231] Fix | Delete
$has_font_size = array_key_exists( 'fontSize', $attributes );
[232] Fix | Delete
$has_named_border_color = array_key_exists( 'borderColor', $attributes );
[233] Fix | Delete
[234] Fix | Delete
if ( $has_font_size ) {
[235] Fix | Delete
$classes[] = 'has-' . $attributes['fontSize'] . '-font-size';
[236] Fix | Delete
$classes[] = 'has-custom-font-size';
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
if ( $has_class_name ) {
[240] Fix | Delete
$classes[] = $attributes['className'];
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if ( $has_named_text_color || $has_custom_text_color ) {
[244] Fix | Delete
$classes[] = 'has-text-color';
[245] Fix | Delete
}
[246] Fix | Delete
if ( $has_named_text_color ) {
[247] Fix | Delete
$classes[] = sprintf( 'has-%s-color', $attributes['textColor'] );
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
if ( $has_named_border_color ) {
[251] Fix | Delete
$classes[] = sprintf( 'has-%s-border-color', $attributes['borderColor'] );
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
if (
[255] Fix | Delete
$has_named_background_color ||
[256] Fix | Delete
$has_custom_background_color ||
[257] Fix | Delete
$has_named_gradient ||
[258] Fix | Delete
$has_custom_gradient
[259] Fix | Delete
) {
[260] Fix | Delete
$classes[] = 'has-background';
[261] Fix | Delete
}
[262] Fix | Delete
if ( $has_named_background_color && ! $has_custom_gradient ) {
[263] Fix | Delete
$classes[] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] );
[264] Fix | Delete
}
[265] Fix | Delete
if ( $has_named_gradient ) {
[266] Fix | Delete
$classes[] = sprintf( 'has-%s-gradient-background', $attributes['gradient'] );
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
[270] Fix | Delete
if ( $has_border_radius && 0 == $attributes['borderRadius'] ) {
[271] Fix | Delete
$classes[] = 'no-border-radius';
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
return implode( ' ', $classes );
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
/**
[278] Fix | Delete
* Get the Button block styles.
[279] Fix | Delete
*
[280] Fix | Delete
* @param array $attributes Array containing the block attributes.
[281] Fix | Delete
*
[282] Fix | Delete
* @return string
[283] Fix | Delete
*/
[284] Fix | Delete
function get_button_styles( $attributes ) {
[285] Fix | Delete
$styles = array();
[286] Fix | Delete
$has_named_text_color = array_key_exists( 'textColor', $attributes );
[287] Fix | Delete
$has_custom_text_color = array_key_exists( 'customTextColor', $attributes );
[288] Fix | Delete
$has_named_background_color = array_key_exists( 'backgroundColor', $attributes );
[289] Fix | Delete
$has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes );
[290] Fix | Delete
$has_named_gradient = array_key_exists( 'gradient', $attributes );
[291] Fix | Delete
$has_custom_gradient = array_key_exists( 'customGradient', $attributes );
[292] Fix | Delete
$has_border_radius = array_key_exists( 'borderRadius', $attributes );
[293] Fix | Delete
$has_font_family = array_key_exists( 'fontFamily', $attributes );
[294] Fix | Delete
$has_typography_styles = array_key_exists( 'style', $attributes ) && array_key_exists( 'typography', $attributes['style'] );
[295] Fix | Delete
$has_custom_font_size = $has_typography_styles && array_key_exists( 'fontSize', $attributes['style']['typography'] );
[296] Fix | Delete
$has_custom_text_transform = $has_typography_styles && array_key_exists( 'textTransform', $attributes['style']['typography'] );
[297] Fix | Delete
$border_styles = array();
[298] Fix | Delete
$border_attribute = $attributes['style']['border'] ?? null;
[299] Fix | Delete
$is_border_style_array = is_array( $border_attribute );
[300] Fix | Delete
[301] Fix | Delete
$has_custom_border_color = $is_border_style_array && isset( $border_attribute['color'] );
[302] Fix | Delete
$has_border_style = $is_border_style_array && isset( $border_attribute['style'] );
[303] Fix | Delete
$has_border_width = $is_border_style_array && isset( $border_attribute['width'] );
[304] Fix | Delete
$has_individual_borders = $is_border_style_array && (
[305] Fix | Delete
isset( $border_attribute['top'] ) ||
[306] Fix | Delete
isset( $border_attribute['right'] ) ||
[307] Fix | Delete
isset( $border_attribute['bottom'] ) ||
[308] Fix | Delete
isset( $border_attribute['left'] )
[309] Fix | Delete
);
[310] Fix | Delete
[311] Fix | Delete
if ( $has_font_family ) {
[312] Fix | Delete
$styles[] = sprintf( 'font-family: %s;', $attributes['fontFamily'] );
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
if ( $has_custom_font_size ) {
[316] Fix | Delete
$styles[] = sprintf( 'font-size: %s;', $attributes['style']['typography']['fontSize'] );
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
if ( $has_custom_text_transform ) {
[320] Fix | Delete
$styles[] = sprintf( 'text-transform: %s;', $attributes['style']['typography']['textTransform'] );
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
if ( ! $has_named_text_color && $has_custom_text_color ) {
[324] Fix | Delete
$styles[] = sprintf( 'color: %s;', $attributes['customTextColor'] );
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
if ( ! $has_named_background_color && ! $has_named_gradient && $has_custom_gradient ) {
[328] Fix | Delete
$styles[] = sprintf( 'background: %s;', $attributes['customGradient'] );
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
if (
[332] Fix | Delete
$has_custom_background_color &&
[333] Fix | Delete
! $has_named_background_color &&
[334] Fix | Delete
! $has_named_gradient &&
[335] Fix | Delete
! $has_custom_gradient
[336] Fix | Delete
) {
[337] Fix | Delete
$styles[] = sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] );
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
// phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
[341] Fix | Delete
if ( $has_border_radius && 0 != $attributes['borderRadius'] ) {
[342] Fix | Delete
$styles[] = sprintf( 'border-radius: %spx;', $attributes['borderRadius'] );
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
if ( $has_custom_border_color ) {
[346] Fix | Delete
$border_styles['color'] = $attributes['style']['border']['color'];
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
if ( $has_border_style ) {
[350] Fix | Delete
$border_styles['style'] = $attributes['style']['border']['style'];
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
if ( $has_border_width ) {
[354] Fix | Delete
$border_styles['width'] = $attributes['style']['border']['width'];
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
if ( $has_individual_borders ) {
[358] Fix | Delete
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
[359] Fix | Delete
$border = $attributes['style']['border'][ $side ] ?? null;
[360] Fix | Delete
if ( is_array( $border ) ) {
[361] Fix | Delete
$border_side_values = array(
[362] Fix | Delete
'width' => $border['width'] ?? null,
[363] Fix | Delete
'color' => $border['color'] ?? null,
[364] Fix | Delete
'style' => $border['style'] ?? null,
[365] Fix | Delete
);
[366] Fix | Delete
$border_styles[ $side ] = $border_side_values;
[367] Fix | Delete
}
[368] Fix | Delete
}
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
$border_styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
[372] Fix | Delete
if ( isset( $border_styles['css'] ) ) {
[373] Fix | Delete
$styles[] = $border_styles['css'];
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
return implode( ' ', $styles );
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
/**
[380] Fix | Delete
* Get the Button wrapper block styles.
[381] Fix | Delete
*
[382] Fix | Delete
* @param array $attributes Array containing the block attributes.
[383] Fix | Delete
*
[384] Fix | Delete
* @return string
[385] Fix | Delete
*/
[386] Fix | Delete
function get_button_wrapper_styles( $attributes ) {
[387] Fix | Delete
$styles = array();
[388] Fix | Delete
$has_width = array_key_exists( 'width', $attributes );
[389] Fix | Delete
[390] Fix | Delete
if ( $has_width && ! empty( $attributes['width'] ) ) {
[391] Fix | Delete
$styles[] = sprintf( 'width: %s;', $attributes['width'] );
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
return implode( ' ', $styles );
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
/**
[398] Fix | Delete
* Get filtered attributes.
[399] Fix | Delete
*
[400] Fix | Delete
* @param array $attributes Array containing the Button block attributes.
[401] Fix | Delete
* @param string $attribute_name String containing the attribute name to get.
[402] Fix | Delete
*
[403] Fix | Delete
* @return string
[404] Fix | Delete
*/
[405] Fix | Delete
function get_attribute( $attributes, $attribute_name ) {
[406] Fix | Delete
if ( isset( $attributes[ $attribute_name ] ) ) {
[407] Fix | Delete
return $attributes[ $attribute_name ];
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
$default_attributes = array(
[411] Fix | Delete
'url' => '#',
[412] Fix | Delete
'element' => 'a',
[413] Fix | Delete
'saveInPostContent' => false,
[414] Fix | Delete
);
[415] Fix | Delete
[416] Fix | Delete
if ( isset( $default_attributes[ $attribute_name ] ) ) {
[417] Fix | Delete
return $default_attributes[ $attribute_name ];
[418] Fix | Delete
}
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
/**
[422] Fix | Delete
* Enqueue style for an existing block.
[423] Fix | Delete
*
[424] Fix | Delete
* The Jetpack Button block depends on styles from the core button block.
[425] Fix | Delete
* In case that block is not already within the post content, we can use
[426] Fix | Delete
* this function to ensure the block's style assets are enqueued.
[427] Fix | Delete
*
[428] Fix | Delete
* @param string $block_name Block type name including namespace.
[429] Fix | Delete
*/
[430] Fix | Delete
function enqueue_existing_button_style_dependency( $block_name ) {
[431] Fix | Delete
$existing_block = \WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
[432] Fix | Delete
if ( isset( $existing_block ) && ! empty( $existing_block->style ) ) {
[433] Fix | Delete
wp_enqueue_style( $existing_block->style );
[434] Fix | Delete
}
[435] Fix | Delete
}
[436] Fix | Delete
[437] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function