Example #1
0
/**
 * Define the metabox and field configurations.
 *
 * @param  array $meta_boxes
 *
 * @return array
 */
function give_single_forms_cmb2_metaboxes(array $meta_boxes)
{
    $post_id = give_get_admin_post_id();
    $price = give_get_form_price($post_id);
    $custom_amount_minimum = give_get_form_minimum_price($post_id);
    $goal = give_get_form_goal($post_id);
    $variable_pricing = give_has_variable_prices($post_id);
    $prices = give_get_variable_prices($post_id);
    //No empty prices - min. 1.00 for new forms
    if (empty($price) && is_null($post_id)) {
        $price = esc_attr(give_format_amount('1.00'));
    }
    //Min. $1.00 for new forms
    if (empty($custom_amount_minimum)) {
        $custom_amount_minimum = esc_attr(give_format_amount('1.00'));
    }
    // Start with an underscore to hide fields from custom fields list
    $prefix = '_give_';
    /**
     * Repeatable Field Groups
     */
    $meta_boxes['form_field_options'] = apply_filters('give_forms_field_options', array('id' => 'form_field_options', 'title' => esc_html__('Donation Options', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'fields' => apply_filters('give_forms_donation_form_metabox_fields', array(array('name' => esc_html__('Donation Option', 'give'), 'description' => esc_html__('Would you like this form to have one set donation price or multiple levels (for example, $10, $20, $50)?', 'give'), 'id' => $prefix . 'price_option', 'type' => 'radio_inline', 'default' => 'set', 'options' => apply_filters('give_forms_price_options', array('set' => esc_html__('Set Donation', 'give'), 'multi' => esc_html__('Multi-level Donation', 'give')))), array('name' => esc_html__('Set Donation', 'give'), 'description' => esc_html__('This is the set donation amount for this form. If you have a "Custom Amount Minimum" set, make sure it is less than this amount.', 'give'), 'id' => $prefix . 'set_price', 'type' => 'text_small', 'row_classes' => 'give-subfield', 'render_row_cb' => 'give_cmb_amount_field_render_row_cb', 'sanitization_cb' => 'give_sanitize_price_field_value', 'attributes' => array('placeholder' => give_format_decimal('1.00'), 'value' => give_format_decimal($price), 'class' => 'cmb-type-text-small give-money-field')), array('id' => $prefix . 'levels_header', 'type' => 'levels_repeater_header'), array('id' => $prefix . 'donation_levels', 'type' => 'group', 'row_classes' => 'give-subfield', 'options' => array('add_button' => esc_html__('Add Level', 'give'), 'remove_button' => '<span class="dashicons dashicons-no"></span>', 'sortable' => true), 'fields' => apply_filters('give_donation_levels_table_row', array(array('name' => esc_html__('ID', 'give'), 'id' => $prefix . 'id', 'type' => 'levels_id'), array('name' => esc_html__('Amount', 'give'), 'id' => $prefix . 'amount', 'type' => 'text_small', 'before_field' => give_get_option('currency_position') == 'before' ? '<span class="give-money-symbol  give-money-symbol-before">' . give_currency_symbol() . '</span>' : '', 'after_field' => give_get_option('currency_position') == 'after' ? '<span class="give-money-symbol  give-money-symbol-after">' . give_currency_symbol() . '</span>' : '', 'sanitization_cb' => 'give_sanitize_price_field_value', 'attributes' => array('placeholder' => give_format_decimal('1.00'), 'class' => 'cmb-type-text-small give-money-field'), 'before' => 'give_format_admin_multilevel_amount'), array('name' => esc_html__('Text', 'give'), 'id' => $prefix . 'text', 'type' => 'text', 'attributes' => array('placeholder' => esc_html__('Donation Level', 'give'), 'class' => 'give-multilevel-text-field')), array('name' => esc_html__('Default', 'give'), 'id' => $prefix . 'default', 'type' => 'give_default_radio_inline')))), array('name' => esc_html__('Display Style', 'give'), 'description' => esc_html__('Set how the donations levels will display on the form.', 'give'), 'id' => $prefix . 'display_style', 'type' => 'radio_inline', 'default' => 'buttons', 'options' => array('buttons' => esc_html__('Buttons', 'give'), 'radios' => esc_html__('Radios', 'give'), 'dropdown' => esc_html__('Dropdown', 'give'))), array('name' => esc_html__('Custom Amount', 'give'), 'description' => esc_html__('Do you want the user to be able to input their own donation amount?', 'give'), 'id' => $prefix . 'custom_amount', 'type' => 'radio_inline', 'default' => 'no', 'options' => array('yes' => esc_html__('Yes', 'give'), 'no' => esc_html__('No', 'give'))), array('name' => esc_html__('Custom Amount Minimum', 'give'), 'description' => esc_html__('If you would like to set a minimum custom donation amount please enter it here.', 'give'), 'id' => $prefix . 'custom_amount_minimum', 'type' => 'text_small', 'row_classes' => 'give-subfield', 'render_row_cb' => 'give_cmb_amount_field_render_row_cb', 'sanitization_cb' => 'give_sanitize_price_field_value', 'attributes' => array('placeholder' => give_format_decimal('1.00'), 'value' => give_format_decimal($custom_amount_minimum), 'class' => 'cmb-type-text-small give-money-field')), array('name' => esc_html__('Custom Amount Text', 'give'), 'description' => esc_html__('This text appears as a label below the custom amount field for set donation forms. For multi-level forms the text will appear as it\'s own level (ie button, radio, or select option).', 'give'), 'id' => $prefix . 'custom_amount_text', 'type' => 'text', 'row_classes' => 'give-subfield', 'attributes' => array('rows' => 3, 'placeholder' => esc_attr__('Give a Custom Amount', 'give'))), array('name' => esc_html__('Goal', 'give'), 'description' => esc_html__('Do you want to set a donation goal for this form?', 'give'), 'id' => $prefix . 'goal_option', 'type' => 'radio_inline', 'default' => 'no', 'options' => array('yes' => esc_html__('Yes', 'give'), 'no' => esc_html__('No', 'give'))), array('name' => esc_html__('Goal Amount', 'give'), 'description' => esc_html__('This is the monetary goal amount you want to reach for this donation form.', 'give'), 'id' => $prefix . 'set_goal', 'type' => 'text_small', 'row_classes' => 'give-subfield', 'render_row_cb' => 'give_cmb_amount_field_render_row_cb', 'sanitization_cb' => 'give_sanitize_price_field_value', 'attributes' => array('placeholder' => give_format_decimal('0.00'), 'value' => give_format_decimal($goal), 'class' => 'cmb-type-text-small give-money-field')), array('name' => esc_html__('Goal Format', 'give'), 'description' => esc_html__('Would you like to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded".', 'give'), 'id' => $prefix . 'goal_format', 'type' => 'radio_inline', 'default' => 'amount', 'row_classes' => 'give-subfield', 'options' => array('amount' => esc_html__('Amount ', 'give'), 'percentage' => esc_html__('Percentage', 'give'))), array('name' => esc_html__('Goal Progress Bar Color', 'give'), 'id' => $prefix . 'goal_color', 'type' => 'colorpicker', 'row_classes' => 'give-subfield', 'default' => '#2bc253'), array('name' => esc_html__('Close Form when Goal Achieved', 'give'), 'desc' => esc_html__('Would you like to close the donation forms and stop accepting donations once this goal has been met?', 'give'), 'id' => $prefix . 'close_form_when_goal_achieved', 'type' => 'radio_inline', 'row_classes' => 'give-subfield', 'options' => array('yes' => esc_html__('Yes', 'give'), 'no' => esc_html__('No', 'give')), 'default' => 'no'), array('name' => esc_html__('Goal Achieved Message', 'give'), 'desc' => esc_html__('Would you like to display a custom message when the goal is closed? If none is provided the default message will be displayed', 'give'), 'id' => $prefix . 'form_goal_achieved_message', 'type' => 'textarea', 'row_classes' => 'give-subfield', 'attributes' => array('placeholder' => esc_attr__('Thank you to all our donors, we have met our fundraising goal.', 'give')))))));
    /**
     * Content Field
     */
    $meta_boxes['form_content_options'] = apply_filters('give_forms_content_options', array('id' => 'form_content_options', 'title' => esc_html__('Form Content', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'fields' => apply_filters('give_forms_content_options_metabox_fields', array(array('name' => esc_html__('Display Content', 'give'), 'description' => esc_html__('Do you want to display content? If you select "Yes" a WYSIWYG editor will appear which you will be able to enter content to display above or below the form.', 'give'), 'id' => $prefix . 'content_option', 'type' => 'select', 'options' => apply_filters('give_forms_content_options_select', array('none' => esc_html__('No content', 'give'), 'give_pre_form' => esc_html__('Yes, display content ABOVE the form fields', 'give'), 'give_post_form' => esc_html__('Yes, display content BELOW the form fields', 'give'))), 'default' => 'none'), array('name' => esc_html__('Content', 'give'), 'description' => esc_html__('This content will display on the single give form page.', 'give'), 'id' => $prefix . 'form_content', 'row_classes' => 'give-subfield', 'type' => 'wysiwyg')))));
    /**
     * Display Options
     */
    $meta_boxes['form_display_options'] = apply_filters('give_form_display_options', array('id' => 'form_display_options', 'title' => esc_html__('Form Display Options', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, 'fields' => apply_filters('give_forms_display_options_metabox_fields', array(array('name' => esc_html__('Payment Fields', 'give'), 'desc' => esc_html__('How would you like to display payment information for this form? The "Show on Page" option will display the entire form when the page loads. "Reveal Upon Click" places a button below the donation fields and upon click slides into view the rest of the fields. "Modal Window Upon Click" is a similar option, rather than sliding into view the fields they will open in a shadow box or "modal" window.', 'give'), 'id' => $prefix . 'payment_display', 'type' => 'select', 'options' => array('onpage' => esc_html__('Show on Page', 'give'), 'reveal' => esc_html__('Reveal Upon Click', 'give'), 'modal' => esc_html__('Modal Window Upon Click', 'give')), 'default' => 'onpage'), array('id' => $prefix . 'reveal_label', 'name' => esc_html__('Reveal / Modal Open Text', 'give'), 'desc' => esc_html__('The button label for completing the donation.', 'give'), 'type' => 'text_small', 'row_classes' => 'give-subfield', 'attributes' => array('placeholder' => esc_attr__('Donate Now', 'give'))), array('id' => $prefix . 'checkout_label', 'name' => esc_html__('Complete Donation Text', 'give'), 'desc' => esc_html__('The button label for completing a donation.', 'give'), 'type' => 'text_small', 'attributes' => array('placeholder' => esc_html__('Donate Now', 'give'))), array('name' => esc_html__('Default Gateway', 'give'), 'desc' => esc_html__('By default, the gateway for this form will inherit the global default gateway (set under Give > Settings > Payment Gateways). This option allows you to customize the default gateway for this form only.', 'give'), 'id' => $prefix . 'default_gateway', 'type' => 'default_gateway'), array('name' => esc_html__('Disable Guest Donations', 'give'), 'desc' => esc_html__('Do you want to require users be logged-in to make donations?', 'give'), 'id' => $prefix . 'logged_in_only', 'type' => 'checkbox'), array('name' => esc_html__('Register / Login Form', 'give'), 'desc' => esc_html__('Display the registration and login forms in the payment section for non-logged-in users.', 'give'), 'id' => $prefix . 'show_register_form', 'type' => 'select', 'options' => array('both' => esc_html__('Registration and Login Forms', 'give'), 'registration' => esc_html__('Registration Form Only', 'give'), 'login' => esc_html__('Login Form Only', 'give'), 'none' => esc_html__('None', 'give')), 'default' => 'none'), array('name' => esc_html__('Floating Labels', 'give'), 'desc' => sprintf(__('Select the <a href="%s" target="_blank">floating labels</a> setting for this Give form.<br>Be aware that if you have the "Disable CSS" option enabled, you will need to style the floating labels yourself.', 'give'), esc_url('https://givewp.com/documentation/core/give-forms/creating-give-forms/#floating-labels')), 'id' => $prefix . 'form_floating_labels', 'type' => 'select', 'options' => array('' => esc_html__('Use the global setting', 'give'), 'enabled' => esc_html__('Enabled', 'give'), 'disabled' => esc_html__('Disabled', 'give')), 'default' => 'none')))));
    /**
     * Terms & Conditions
     */
    $meta_boxes['form_terms_options'] = apply_filters('give_forms_terms_options', array('id' => 'form_terms_options', 'title' => esc_html__('Terms and Conditions', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'fields' => apply_filters('give_forms_terms_options_metabox_fields', array(array('name' => esc_html__('Terms and Conditions', 'give'), 'description' => esc_html__('Do you want to require the user to agree to terms and conditions prior to being able to complete their donation?', 'give'), 'id' => $prefix . 'terms_option', 'type' => 'select', 'options' => apply_filters('give_forms_content_options_select', array('none' => esc_html__('No', 'give'), 'yes' => esc_html__('Yes', 'give'))), 'default' => 'none'), array('id' => $prefix . 'agree_label', 'name' => esc_html__('Agree to Terms Label', 'give'), 'desc' => esc_html__('The label shown next to the agree to terms check box. Add your own to customize or leave blank to use the default text placeholder.', 'give'), 'type' => 'text', 'row_classes' => 'give-subfield', 'size' => 'regular', 'attributes' => array('placeholder' => esc_attr__('Agree to Terms?', 'give'))), array('id' => $prefix . 'agree_text', 'row_classes' => 'give-subfield', 'name' => esc_html__('Agreement Text', 'give'), 'desc' => esc_html__('This is the actual text which the user will have to agree to in order to make a donation.', 'give'), 'type' => 'wysiwyg')))));
    return $meta_boxes;
}
Example #2
0
/**
 * Donation Form Validate Minimum Donation Amount
 *
 * @access      private
 * @since       1.3.6
 * @return      bool
 */
function give_verify_minimum_price()
{
    $amount = give_sanitize_amount($_REQUEST['give-amount']);
    $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
    $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0;
    $variable_prices = give_has_variable_prices($form_id);
    if ($variable_prices && !empty($price_id)) {
        $price_level_amount = give_get_price_option_amount($form_id, $price_id);
        if ($price_level_amount == $amount) {
            return true;
        }
    }
    $minimum = give_get_form_minimum_price($form_id);
    if ($minimum > $amount) {
        return false;
    }
    return true;
}
Example #3
0
/**
 * Get Donation Form
 *
 * @since 1.0
 *
 * @param array $args Arguments for display
 *
 * @return string $purchase_form
 */
function give_get_donation_form($args = array())
{
    global $post;
    $form_id = is_object($post) ? $post->ID : 0;
    if (isset($args['id'])) {
        $form_id = $args['id'];
    }
    $defaults = apply_filters('give_form_args_defaults', array('form_id' => $form_id));
    $args = wp_parse_args($args, $defaults);
    $form = new Give_Donate_Form($args['form_id']);
    //bail if no form ID
    if (empty($form->ID)) {
        return false;
    }
    $payment_mode = give_get_chosen_gateway($form->ID);
    $form_action = add_query_arg(apply_filters('give_form_action_args', array('payment-mode' => $payment_mode)), give_get_current_page_url());
    //Sanity Check: Donation form not published or user doesn't have permission to view drafts
    if ('publish' !== $form->post_status && !current_user_can('edit_give_forms', $form->ID)) {
        return false;
    }
    //Get the form wrap CSS classes.
    $form_wrap_classes = $form->get_form_wrap_classes($args);
    //Get the <form> tag wrap CSS classes.
    $form_classes = $form->get_form_classes($args);
    ob_start();
    /**
     * Fires before the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_pre_form_output', $form->ID, $args);
    ?>

	<div id="give-form-<?php 
    echo $form->ID;
    ?>
-wrap" class="<?php 
    echo $form_wrap_classes;
    ?>
">

		<?php 
    if ($form->is_close_donation_form()) {
        //Get Goal thank you message.
        $display_thankyou_message = get_post_meta($form->ID, '_give_form_goal_achieved_message', true);
        $display_thankyou_message = !empty($display_thankyou_message) ? $display_thankyou_message : esc_html__('Thank you to all our donors, we have met our fundraising goal.', 'give');
        //Print thank you message.
        apply_filters('give_goal_closed_output', give_output_error($display_thankyou_message, true, 'success'));
    } else {
        if (isset($args['show_title']) && $args['show_title'] == true) {
            echo apply_filters('give_form_title', '<h2 class="give-form-title">' . get_the_title($form_id) . '</h2>');
        }
        do_action('give_pre_form', $form->ID, $args);
        ?>

			<form id="give-form-<?php 
        echo $form_id;
        ?>
" class="<?php 
        echo $form_classes;
        ?>
" action="<?php 
        echo esc_url_raw($form_action);
        ?>
" method="post">
				<input type="hidden" name="give-form-id" value="<?php 
        echo $form->ID;
        ?>
"/>
				<input type="hidden" name="give-form-title" value="<?php 
        echo htmlentities($form->post_title);
        ?>
"/>
				<input type="hidden" name="give-current-url" value="<?php 
        echo htmlspecialchars(give_get_current_page_url());
        ?>
"/>
				<input type="hidden" name="give-form-url" value="<?php 
        echo htmlspecialchars(give_get_current_page_url());
        ?>
"/>
				<input type="hidden" name="give-form-minimum" value="<?php 
        echo give_format_amount(give_get_form_minimum_price($form->ID));
        ?>
"/>

				<!-- The following field is for robots only, invisible to humans: -->
				<span class="give-hidden" style="display: none !important;">
					<label for="give-form-honeypot-<?php 
        echo $form_id;
        ?>
"></label>
					<input id="give-form-honeypot-<?php 
        echo $form_id;
        ?>
" type="text" name="give-honeypot" class="give-honeypot give-hidden"/>
				</span>

				<?php 
        //Price ID hidden field for variable (mult-level) donation forms
        if (give_has_variable_prices($form_id)) {
            //get default selected price ID
            $prices = apply_filters('give_form_variable_prices', give_get_variable_prices($form_id), $form_id);
            $price_id = 0;
            //loop through prices
            foreach ($prices as $price) {
                if (isset($price['_give_default']) && $price['_give_default'] === 'default') {
                    $price_id = $price['_give_id']['level_id'];
                }
            }
            ?>
					<input type="hidden" name="give-price-id" value="<?php 
            echo $price_id;
            ?>
"/>
				<?php 
        }
        do_action('give_checkout_form_top', $form->ID, $args);
        do_action('give_payment_mode_select', $form->ID, $args);
        do_action('give_checkout_form_bottom', $form->ID, $args);
        ?>
			</form>

			<?php 
        do_action('give_post_form', $form->ID, $args);
        ?>

		<?php 
    }
    ?>

		<!--end #give-form-<?php 
    echo absint($form->ID);
    ?>
--></div>
	<?php 
    /**
     * Fires after the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_post_form_output', $form->ID, $args);
    $final_output = ob_get_clean();
    echo apply_filters('give_donate_form', $final_output, $args);
}
Example #4
0
/**
 * Get Donation Form
 *
 * @since 1.0
 *
 * @param array $args Arguments for display
 *
 * @return string $purchase_form
 */
function give_get_donation_form($args = array())
{
    global $post;
    $post_id = is_object($post) ? $post->ID : 0;
    if (isset($args['id'])) {
        $post_id = $args['id'];
    }
    $defaults = apply_filters('give_form_args_defaults', array('form_id' => $post_id));
    $args = wp_parse_args($args, $defaults);
    $form = new Give_Donate_Form($args['form_id']);
    //bail if no form ID
    if (empty($form->ID)) {
        return false;
    }
    $payment_mode = give_get_chosen_gateway($form->ID);
    $form_action = esc_url(add_query_arg(apply_filters('give_form_action_args', array('payment-mode' => $payment_mode)), give_get_current_page_url()));
    if ('publish' !== $form->post_status && !current_user_can('edit_product', $form->ID)) {
        return false;
        // Product not published or user doesn't have permission to view drafts
    }
    $display_option = isset($args['display_style']) && !empty($args['display_style']) ? $args['display_style'] : get_post_meta($form->ID, '_give_payment_display', true);
    $float_labels_option = give_is_float_labels_enabled($args) ? ' float-labels-enabled' : '';
    $form_classes_array = apply_filters('give_form_classes', array('give-form-wrap', 'give-display-' . $display_option), $form->ID, $args);
    $form_classes = implode(' ', $form_classes_array);
    ob_start();
    /**
     * Fires before the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_pre_form_output', $form->ID, $args);
    ?>

	<div id="give-form-<?php 
    echo $form->ID;
    ?>
-wrap" class="<?php 
    echo $form_classes;
    ?>
">

		<?php 
    if (isset($args['show_title']) && $args['show_title'] == true) {
        echo apply_filters('give_form_title', '<h2  class="give-form-title">' . get_the_title($post_id) . '</h2>');
    }
    ?>

		<?php 
    do_action('give_pre_form', $form->ID, $args);
    ?>

		<form id="give-form-<?php 
    echo $post_id;
    ?>
" class="give-form give-form-<?php 
    echo absint($form->ID);
    echo $float_labels_option;
    ?>
" action="<?php 
    echo $form_action;
    ?>
" method="post">
			<input type="hidden" name="give-form-id" value="<?php 
    echo $form->ID;
    ?>
"/>
			<input type="hidden" name="give-form-title" value="<?php 
    echo htmlentities($form->post_title);
    ?>
"/>
			<input type="hidden" name="give-current-url" value="<?php 
    echo htmlspecialchars(give_get_current_page_url());
    ?>
"/>
			<input type="hidden" name="give-form-url" value="<?php 
    echo htmlspecialchars(give_get_current_page_url());
    ?>
"/>
			<input type="hidden" name="give-form-minimum" value="<?php 
    echo give_get_form_minimum_price($form->ID);
    ?>
"/>
			<?php 
    //Price ID hidden field for variable (mult-level) donation forms
    if (give_has_variable_prices($post_id)) {
        //get default selected price ID
        $prices = apply_filters('give_form_variable_prices', give_get_variable_prices($post_id), $post_id);
        $price_id = 0;
        //loop through prices
        foreach ($prices as $price) {
            if (isset($price['_give_default']) && $price['_give_default'] === 'default') {
                $price_id = $price['_give_id']['level_id'];
            }
        }
        ?>
				<input type="hidden" name="give-price-id" value="<?php 
        echo $price_id;
        ?>
"/>
			<?php 
    }
    do_action('give_checkout_form_top', $form->ID, $args);
    do_action('give_payment_mode_select', $form->ID, $args);
    do_action('give_checkout_form_bottom', $form->ID, $args);
    ?>

		</form>

		<?php 
    do_action('give_post_form', $form->ID, $args);
    ?>

		<!--end #give-form-<?php 
    echo absint($form->ID);
    ?>
--></div>
	<?php 
    /**
     * Fires after the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_post_form_output', $form->ID, $args);
    $final_output = ob_get_clean();
    echo apply_filters('give_donate_form', $final_output, $args);
}