__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() ) { return $content; } require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php'; // If stripe isn't connected don't show anything to potential donors - they can't actually make a donation. if ( ! \Jetpack_Memberships::has_connected_account() ) { return ''; } Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); require_once JETPACK__PLUGIN_DIR . '/_inc/lib/class-jetpack-currencies.php'; $default_texts = get_default_texts(); $donations = array( 'one-time' => array_merge( array( '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( '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( '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
', esc_attr( $donation['class'] ), wp_kses_post( $donation['extraText'] ?? $default_texts['extraText'] ) ); $buttons .= sprintf( '%3$s', esc_attr( $donation['class'] ), esc_url( \Jetpack_Memberships::get_instance()->get_subscription_url( $plan_id ) ), wp_kses_post( $donation['buttonText'] ) ); } if ( $nav ) { $nav .= '%s
', wp_kses_post( $custom_amount_text ) ); $default_custom_amount = \Jetpack_Memberships::SUPPORTED_CURRENCIES[ $currency ] * 100; $custom_amount .= sprintf( '%4$s
%5$s %6$s