Give_Donate_Form::get_form_classes PHP Method

get_form_classes() public method

Provides the classes for the donation
html tag and filters for customization.
Since: 1.6
public get_form_classes ( $args ) : string
$args
return string
    public function get_form_classes($args)
    {
        $float_labels_option = give_is_float_labels_enabled($args) ? 'float-labels-enabled' : '';
        $form_classes_array = apply_filters('give_form_classes', array('give-form', 'give-form-' . $this->ID, 'give-form-type-' . $this->get_type(), $float_labels_option), $this->ID, $args);
        // Remove empty class names.
        $form_classes_array = array_filter($form_classes_array);
        return implode(' ', $form_classes_array);
    }

Usage Example

Exemplo n.º 1
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);
}