__NAMESPACE__ . '\render_block', 'plan_check' => true, 'attributes' => array( 'currency' => array( 'type' => 'string', 'default' => 'USD', ), 'oneTimeDonation' => array( 'type' => 'object', 'default' => array( 'show' => true, 'planId' => null, 'amounts' => array( 5, 15, 100 ), 'heading' => __( 'Make a one-time donation', 'jetpack' ), 'extraText' => __( 'Your contribution is appreciated.', 'jetpack' ), 'buttonText' => __( 'Donate', 'jetpack' ), ), ), 'monthlyDonation' => array( 'type' => 'object', 'default' => array( 'show' => true, 'planId' => null, 'amounts' => array( 5, 15, 100 ), 'heading' => __( 'Make a monthly donation', 'jetpack' ), 'extraText' => __( 'Your contribution is appreciated.', 'jetpack' ), 'buttonText' => __( 'Donate monthly', 'jetpack' ), ), ), 'annualDonation' => array( 'type' => 'object', 'default' => array( 'show' => true, 'planId' => null, 'amounts' => array( 5, 15, 100 ), 'heading' => __( 'Make a yearly donation', 'jetpack' ), 'extraText' => __( 'Your contribution is appreciated.', 'jetpack' ), 'buttonText' => __( 'Donate yearly', 'jetpack' ), ), ), 'showCustomAmount' => array( 'type' => 'boolean', 'default' => true, ), 'chooseAmountText' => array( 'type' => 'string', 'default' => __( 'Choose an amount', 'jetpack' ), ), 'customAmountText' => array( 'type' => 'string', 'default' => __( 'Or enter a custom amount', 'jetpack' ), ), 'fallbackLinkUrl' => array( 'type' => 'string', ), ), ) ); } 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; } Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME, array( 'thickbox' ) ); add_thickbox(); require_once JETPACK__PLUGIN_DIR . 'modules/memberships/class-jetpack-memberships.php'; jetpack_require_lib( 'class-jetpack-currencies' ); $donations = array( 'one-time' => array_merge( array( 'title' => __( 'One-Time', 'jetpack' ), 'class' => 'donations__one-time-item', ), $attr['oneTimeDonation'] ), ); if ( $attr['monthlyDonation']['show'] ) { $donations['1 month'] = array_merge( array( 'title' => __( 'Monthly', 'jetpack' ), 'class' => 'donations__monthly-item', ), $attr['monthlyDonation'] ); } if ( $attr['annualDonation']['show'] ) { $donations['1 year'] = array_merge( array( 'title' => __( 'Yearly', 'jetpack' ), 'class' => 'donations__annual-item', ), $attr['annualDonation'] ); } $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'] ) ); $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( $attr['customAmountText'] ) ); $default_custom_amount = \Jetpack_Memberships::SUPPORTED_CURRENCIES[ $currency ] * 100; $custom_amount .= sprintf( '%4$s
%5$s %6$s