$atts Shortcode attributes. * @return string Form HTML. * @since 0.0.1 */ public function render_shortcode( $atts ) { $atts = shortcode_atts( [ 'id' => 0, ], $atts, 'suredonation_form' ); $form_id = absint( $atts['id'] ); if ( ! $form_id ) { if ( current_user_can( 'edit_posts' ) ) { return '

' . esc_html__( 'Please specify a form ID: [suredonation_form id="123"]', 'suredonation' ) . '

'; } return ''; } // Get the form post. $form = get_post( $form_id ); if ( ! $form || Donation_Form_CPT::POST_TYPE !== $form->post_type ) { if ( current_user_can( 'edit_posts' ) ) { return '

' . esc_html__( 'Invalid donation form ID.', 'suredonation' ) . '

'; } return ''; } if ( 'publish' !== $form->post_status && ! current_user_can( 'edit_posts' ) ) { return ''; } // Enqueue frontend assets. $this->enqueue_assets(); // Render the form. return $this->render_form( $form ); } /** * Render the form HTML. * * @param \WP_Post $form Form post object. * @return string Form HTML. * @since 0.0.1 */ private function render_form( $form ) { $form_id = $form->ID; $campaign_id = Donation_Form_CPT::get_form_campaign_id( $form_id ); // Parse the form content (blocks). $blocks = parse_blocks( $form->post_content ); // Render blocks. $blocks_html = ''; foreach ( $blocks as $block ) { if ( ! empty( $block['blockName'] ) ) { // Add form ID to block attributes. $block['attrs']['formId'] = $form_id; $blocks_html .= render_block( $block ); } } // Generate unique form ID for the container. $unique_form_id = 'suredonation-form-' . $form_id . '-' . wp_rand(); // Nonce action based on campaign. $nonce_action = $campaign_id ? 'suredonation_donation_' . $campaign_id : 'suredonation_donation_standalone'; ob_start(); ?>
admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'suredonation_payment_nonce' ), 'confirmationType' => 'message', // Default to showing message. Could be 'redirect' in future. 'redirectUrl' => '', 'successTitle' => __( 'Thank You!', 'suredonation' ), 'successMessage' => __( 'Your donation has been processed successfully. A confirmation email will be sent to you shortly.', 'suredonation' ), ] ); // Enqueue Stripe.js if Stripe is configured. $this->maybe_enqueue_stripe(); } /** * Enqueue Stripe.js if Stripe is configured. * * @return void * @since 0.0.1 */ private function maybe_enqueue_stripe() { if ( ! class_exists( 'SureDonation\Inc\Payments\Stripe\Stripe_Helper' ) ) { return; } $publishable_key = \SureDonation\Inc\Payments\Stripe\Stripe_Helper::get_stripe_publishable_key(); if ( ! empty( $publishable_key ) ) { wp_enqueue_script( 'stripe-js', 'https://js.stripe.com/v3/', [], null, // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- External script. true ); } } }