__NAMESPACE__ . '\render_block',
)
);
}
}
add_action( 'init', __NAMESPACE__ . '\register_block' );
/**
* Donations block dynamic rendering.
*
* @param array $attr Array containing the Donations block attributes.
* @param string $content String containing the Donations block content.
*
* @return string
*/
function render_block( $attr, $content ) {
// Keep content as-is if rendered in other contexts than frontend (i.e. feed, emails, API, etc.).
if ( ! jetpack_is_frontend() ) {
$parsed = parse_blocks( $content );
if ( ! empty( $parsed[0] ) ) {
// Inject the link of the current post from the server side as the fallback link to make sure the donations block
// points to the correct post when it's inserted from the synced pattern (aka “My Pattern”).
$post_link = get_permalink();
$parsed[0]['attrs']['fallbackLinkUrl'] = $post_link;
$content = \render_block( $parsed[0] );
if ( preg_match( '/ array_merge(
array(
'planId' => null,
'title' => __( 'One-Time', 'jetpack' ),
'class' => 'donations__one-time-item',
'heading' => $default_texts['oneTimeDonation']['heading'],
'buttonText' => $default_texts['oneTimeDonation']['buttonText'],
),
$attr['oneTimeDonation']
),
);
if ( $attr['monthlyDonation']['show'] ) {
$donations['1 month'] = array_merge(
array(
'planId' => null,
'title' => __( 'Monthly', 'jetpack' ),
'class' => 'donations__monthly-item',
'heading' => $default_texts['monthlyDonation']['heading'],
'buttonText' => $default_texts['monthlyDonation']['buttonText'],
),
$attr['monthlyDonation']
);
}
if ( $attr['annualDonation']['show'] ) {
$donations['1 year'] = array_merge(
array(
'planId' => null,
'title' => __( 'Yearly', 'jetpack' ),
'class' => 'donations__annual-item',
'heading' => $default_texts['annualDonation']['heading'],
'buttonText' => $default_texts['annualDonation']['buttonText'],
),
$attr['annualDonation']
);
}
$choose_amount_text = isset( $attr['chooseAmountText'] ) && ! empty( $attr['chooseAmountText'] ) ? $attr['chooseAmountText'] : $default_texts['chooseAmountText'];
$custom_amount_text = isset( $attr['customAmountText'] ) && ! empty( $attr['customAmountText'] ) ? $attr['customAmountText'] : $default_texts['customAmountText'];
$currency = $attr['currency'];
$nav = '';
$headings = '';
$amounts = '';
$extra_text = '';
$buttons = '';
foreach ( $donations as $interval => $donation ) {
$plan_id = (int) $donation['planId'];
$plan = get_post( $plan_id );
if ( ! $plan || is_wp_error( $plan ) ) {
continue;
}
if ( count( $donations ) > 1 ) {
if ( ! $nav ) {
$nav .= ' %2$s %s %4$s%2$s
',
esc_attr( $donation['class'] ),
wp_kses_post( $donation['heading'] )
);
$amounts .= sprintf(
'
%7$s
%8$s