Skip to content

Commit

Permalink
Remove unnecessary VIP html attribute replacement
Browse files Browse the repository at this point in the history
It turned out that all the VIP uses of the button just called render button directly passing attributes. As these won't pass inner block content they are treated as deprecated buttons for rendering. This means we won't be getting submitButtonAttributes while rendering the newest versions of the block added through the editor.
  • Loading branch information
aaronrobertshaw committed Jun 17, 2020
1 parent fd2921f commit 9882ba9
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions modules/memberships/class-jetpack-memberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function return_meta( $map ) {
*
* @return string|void
*/
public function render_button( $attrs, $content ) {
public function render_button( $attrs, $content = null ) {
Jetpack_Gutenberg::load_assets_as_required( self::$button_block_name, array( 'thickbox', 'wp-polyfill' ) );

if ( empty( $attrs['planId'] ) ) {
Expand All @@ -223,20 +223,10 @@ public function render_button( $attrs, $content ) {
add_thickbox();

if ( ! empty( $content ) ) {
$block_id = esc_attr( wp_unique_id( 'recurring-payments-block-' ) );
$content = str_replace( 'recurring-payments-id', $block_id, $content );

$block_id = esc_attr( wp_unique_id( 'recurring-payments-block-' ) );
$content = str_replace( 'recurring-payments-id', $block_id, $content );
$subscribe_url = $this->get_subscription_url( $plan_id );
$content = str_replace( 'href="#"', 'href="' . $subscribe_url . '"', $content );

// Allow for WPCOM VIP custom attributes or remove target="_blank" to match original behaviour.
$html_attributes = isset( $attrs['submitButtonAttributes'] )
? sanitize_text_field( $attrs['submitButtonAttributes'] )
: '';

$content = preg_replace( '/target="_blank"/', $html_attributes, $content );

return $content;
return str_replace( 'href="#"', 'href="' . $subscribe_url . '"', $content );
}

return $this->deprecated_render_button_v1( $attrs, $plan_id );
Expand Down

0 comments on commit 9882ba9

Please sign in to comment.