Give_Donate_Form::get_earnings PHP Method

get_earnings() public method

Retrieve the total earnings for the form
Since: 1.0
public get_earnings ( ) : float
return float Donation form total earnings.
    public function get_earnings()
    {
        if (!isset($this->earnings)) {
            if ('' == get_post_meta($this->ID, '_give_form_earnings', true)) {
                add_post_meta($this->ID, '_give_form_earnings', 0);
            }
            $this->earnings = get_post_meta($this->ID, '_give_form_earnings', true);
            if ($this->earnings < 0) {
                // Never let earnings be less than zero
                $this->earnings = 0;
            }
        }
        return $this->earnings;
    }

Usage Example

Exemplo n.º 1
0
/**
 * Show Give Goals
 * @since 1.0
 *
 * @param int $form_id
 *
 * @return bool
 */
function give_show_goal_progress($form_id)
{
    $goal_option = get_post_meta($form_id, '_give_goal_option', true);
    $form = new Give_Donate_Form($form_id);
    $goal = $form->goal;
    $income = $form->get_earnings();
    $color = get_post_meta($form_id, '_give_goal_color', true);
    if (empty($form->ID) || $goal_option !== 'yes' || $goal == 0) {
        return false;
    }
    $progress = round($income / $goal * 100, 2);
    if ($income > $goal) {
        $progress = 100;
    }
    $output = '<div class="goal-progress">';
    $output .= '<div class="raised">';
    $output .= sprintf(_x('%s of %s raised', 'give', 'This text displays the amount of income raised compared to the goal.'), '<span class="income">' . give_currency_filter(give_format_amount($income)) . '</span>', '<span class="goal-text">' . give_currency_filter(give_format_amount($goal))) . '</span>';
    $output .= '</div>';
    $output .= '<div class="progress-bar">';
    $output .= '<span style="width: ' . esc_attr($progress) . '%;';
    if (!empty($color)) {
        $output .= 'background-color:' . $color;
    }
    $output .= '"></span>';
    $output .= '</div></div><!-- /.goal-progress -->';
    echo apply_filters('give_goal_output', $output);
}
All Usage Examples Of Give_Donate_Form::get_earnings