$form_id_prefix, ); /** * Fire to render donation form. * * @since 1.7 */ do_action( 'give_donation_form', $post_data['give_form_id'], $args ); exit(); } } add_action( 'wp_ajax_give_load_gateway', 'give_load_ajax_gateway' ); add_action( 'wp_ajax_nopriv_give_load_gateway', 'give_load_ajax_gateway' ); /** * Create wp nonce using Ajax call. * * Use give_donation_form_nonce() js fn to create nonce. * * @since 4.16.6 Bail early when the form ID is not a give_forms post or is a Visual Form Builder (v3) form. * @since 2.0 * * @return void */ function give_donation_form_nonce() { if ( isset( $_POST['give_form_id'] ) ) { // Get donation form id. $form_id = is_numeric( $_POST['give_form_id'] ) ? absint( $_POST['give_form_id'] ) : 0; if ( ! ShortcodeUtils::isValidForm( $form_id ) ) { wp_send_json_error( [ 'error' => 'give_invalid_donation_form' ], 400 ); } // Visual Form Builder (v3) forms use route signatures instead of the legacy nonce endpoint. if ( FormUtils::isV3Form( $form_id ) ) { wp_send_json_error( [ 'error' => 'give_unsupported_form_version' ], 400 ); } // Send nonce json data. wp_send_json_success( wp_create_nonce( "give_donation_form_nonce_{$form_id}" ) ); } } add_action( 'wp_ajax_give_donation_form_nonce', 'give_donation_form_nonce' ); add_action( 'wp_ajax_nopriv_give_donation_form_nonce', 'give_donation_form_nonce' ); /** * Create all nonce of donation form using Ajax call. * Note: only for internal use * * @since 4.16.6 Bail early when the form ID is not a give_forms post. * @since 4.9.0 rename function - PHP 8 compatibility * @since 2.2.0 * * @return void */ function give_donation_form_reset_all_nonce() { if ( isset( $_POST['give_form_id'] ) ) { // Get donation form id. $form_id = is_numeric( $_POST['give_form_id'] ) ? absint( $_POST['give_form_id'] ) : 0; if ( ! ShortcodeUtils::isValidForm( $form_id ) ) { wp_send_json_error( [ 'error' => 'give_invalid_donation_form' ], 400 ); } $data = array( 'give_form_hash' => wp_create_nonce( "give_donation_form_nonce_{$form_id}" ), 'give_form_user_register_hash' => wp_create_nonce( "give_form_create_user_nonce_{$form_id}" ), ); /** * Filter the ajax request data * * @since 2.2.0 */ $data = apply_filters( 'give_donation_form_reset_all_nonce_data', $data ); // Send nonce json data. wp_send_json_success( $data ); } wp_send_json_error(); } add_action( 'wp_ajax_give_donation_form_reset_all_nonce', 'give_donation_form_reset_all_nonce'); add_action( 'wp_ajax_nopriv_give_donation_form_reset_all_nonce', 'give_donation_form_reset_all_nonce'); /** * Sets an error within the donation form if no gateways are enabled. * * @todo: we can deprecate this function in future because gateways will not empty if get via Give API. * * @since 1.0 * * @return void */ function give_no_gateway_error() { $gateways = give_get_enabled_payment_gateways(); if ( empty( $gateways ) ) { give_set_error( 'no_gateways', esc_html__( 'You must enable a payment gateway to use Give.', 'give' ) ); } else { give_unset_error( 'no_gateways' ); } } add_action( 'init', 'give_no_gateway_error' );