$form_id, 'file' => '__templates/shortcode-goal.php__', 'line' => '10' ]); return false; } $form = new Give_Donate_Form( $form_id ); $goal_option = give_get_meta( $form->ID, '_give_goal_option', true ); // Sanity check - ensure form has pass all condition to show goal. if ( ( isset( $args['show_goal'] ) && ! filter_var( $args['show_goal'], FILTER_VALIDATE_BOOLEAN ) ) || empty( $form->ID ) || ( is_singular( 'give_forms' ) && ! give_is_setting_enabled( $goal_option ) ) || ! give_is_setting_enabled( $goal_option ) || 0 === $form->goal ) { return false; } $goal_progress_stats = give_goal_progress_stats( $form ); $goal_format = $goal_progress_stats['format']; $color = empty($args['color']) ? give_get_meta( $form_id, '_give_goal_color', true ) : sanitize_hex_color( $args['color'] ); $show_text = isset( $args['show_text'] ) ? filter_var( $args['show_text'], FILTER_VALIDATE_BOOLEAN ) : true; $show_bar = isset( $args['show_bar'] ) ? filter_var( $args['show_bar'], FILTER_VALIDATE_BOOLEAN ) : true; /** * @since 4.7.0 only use dates when they are set * @since 3.12.0 use DonationQuery to get donation amounts */ $form_income = 0; $donationQuery = (new DonationQuery())->form($form->ID); if (isset($args['start_date'], $args['end_date'])) { if ($args['start_date'] === $args['end_date']) { $form_income = $donationQuery->sumIntendedAmount(); } else { // If end date is not set, we have to use the current datetime. if (! $args['end_date']) { $args['end_date'] = date('Y-m-d H:i:s'); } $form_income = $donationQuery->between($args['start_date'], $args['end_date'])->sumIntendedAmount(); } } /** * Allow filtering the goal stats used for this shortcode context. * * @since 2.23.1 * * @param array $stats The income and goal values for this form goal. * @param int $form_id Donation Form ID. * @param array $goal_progress_stats The full goal progress stats. * @param array $args The full list of shortcode arguments passed. */ $shortcode_stats = apply_filters( 'give_goal_shortcode_stats', array( 'income' => $form_income, 'goal' => $goal_progress_stats['raw_goal'], ), $form_id, $goal_progress_stats, $args ); $income = $shortcode_stats['income']; $goal = $shortcode_stats['goal']; switch ( $goal_format ) { case 'donation': $progress = $goal ? round( ( $form->get_sales() / $goal ) * 100, 2 ) : 0; $progress_bar_value = $form->get_sales() >= $goal ? 100 : $progress; break; case 'donors': $progress = $goal ? round( ( give_get_form_donor_count( $form->ID ) / $goal ) * 100, 2 ) : 0; $progress_bar_value = give_get_form_donor_count( $form->ID ) >= $goal ? 100 : $progress; break; case 'percentage': $progress = $goal ? round( ( $income / $goal ) * 100, 2 ) : 0; $progress_bar_value = $income >= $goal ? 100 : $progress; break; default: $progress = $goal ? round( ( $income / $goal ) * 100, 2 ) : 0; $progress_bar_value = $income >= $goal ? 100 : $progress; break; } /** * Filter the goal progress output * * @since 1.8.8 */ $progress = apply_filters( 'give_goal_amount_funded_percentage_output', $progress, $form_id, $form ); ?>