Example #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;
    $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)), get_permalink()));
    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(get_permalink());
    ?>
" />
			<input type="hidden" name="give-form-url" value="<?php 
    echo htmlspecialchars(get_permalink($post_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);
}
 /**
  * Get form tag classes.
  *
  * Provides the classes for the donation <form> html tag and filters for customization.
  *
  * @since  1.6
  * @access public
  *
  * @param  $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);
 }