Completed
Pull Request — master (#791)
by Devin
17:46
created

functions.php ➔ give_get_form_dropdown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 2
eloc 5
c 3
b 0
f 2
nc 2
nop 2
dl 0
loc 9
rs 9.6666
ccs 0
cts 0
cp 0
crap 6
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 35 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Payment Functions
4
 *
5
 * @package     Give
6
 * @subpackage  Payments
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-1.0.php GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Get Payments
19
 *
20
 * Retrieve payments from the database.
21
 *
22
 * Since 1.0, this function takes an array of arguments, instead of individual
23
 * parameters. All of the original parameters remain, but can be passed in any
24
 * order via the array.
25
 *
26
 * $offset = 0, $number = 20, $mode = 'live', $orderby = 'ID', $order = 'DESC',
27
 * $user = null, $status = 'any', $meta_key = null
28
 *
29
 * @since 1.0
30
 *
31
 * @param array $args Arguments passed to get payments
32
 *
33
 * @return object $payments Payments retrieved from the database
34
 */
35
function give_get_payments( $args = array() ) {
36
37
	// Fallback to post objects to ensure backwards compatibility
38 42
	if ( ! isset( $args['output'] ) ) {
39 42
		$args['output'] = 'posts';
40 42
	}
41
42 42
	$args     = apply_filters( 'give_get_payments_args', $args );
43 42
	$payments = new Give_Payments_Query( $args );
44
45 42
	return $payments->get_payments();
46
}
47
48
/**
49
 * Retrieve payment by a given field
50
 *
51
 * @since       1.0
52
 *
53
 * @param       string $field The field to retrieve the payment with
54
 * @param       mixed $value The value for $field
55
 *
56
 * @return      mixed
57
 */
58
function give_get_payment_by( $field = '', $value = '' ) {
59
60 42
	if ( empty( $field ) || empty( $value ) ) {
61
		return false;
62
	}
63
64 42
	switch ( strtolower( $field ) ) {
65
66 42
		case 'id':
67 42
			$payment = new Give_Payment( $value );
68 42
			$id      = $payment->ID;
69
70 42
			if ( empty( $id ) ) {
71
				return false;
72
			}
73
74 42
			break;
75
76
		case 'key':
77
			$payment = give_get_payments( array(
78
				'meta_key'       => '_give_payment_purchase_key',
79
				'meta_value'     => $value,
80
				'posts_per_page' => 1,
81
				'fields'         => 'ids',
82
			) );
83
84
			if ( $payment ) {
85
				$payment = new Give_Payment( $payment[0] );
86
			}
87
88
			break;
89
90
		case 'payment_number':
91
			$payment = give_get_payments( array(
92
				'meta_key'       => '_give_payment_number',
93
				'meta_value'     => $value,
94
				'posts_per_page' => 1,
95
				'fields'         => 'ids',
96
			) );
97
98
			if ( $payment ) {
99
				$payment = new Give_Payment( $payment[0] );
100
			}
101
102
			break;
103
104
		default:
105
			return false;
106 42
	}
107
108 42
	if ( $payment ) {
109 42
		return $payment;
110
	}
111
112
	return false;
113
}
114
115
/**
116
 * Insert Payment
117
 *
118
 * @since 1.0
119
 *
120
 * @param array $payment_data
121
 *
122
 * @return int|bool Payment ID if payment is inserted, false otherwise
123
 */
124
function give_insert_payment( $payment_data = array() ) {
125
126 52
	if ( empty( $payment_data ) ) {
127
		return false;
128
	}
129
130 52
	$payment    = new Give_Payment();
131 52
	$gateway    = ! empty( $payment_data['gateway'] ) ? $payment_data['gateway'] : '';
132 52
	$gateway    = empty( $gateway ) && isset( $_POST['give-gateway'] ) ? $_POST['give-gateway'] : $gateway;
133 52
	$form_id    = isset( $payment_data['give_form_id'] ) ? $payment_data['give_form_id'] : 0;
134 52
	$price_id   = isset( $payment_data['give_price_id'] ) ? $payment_data['give_price_id'] : give_get_price_id( $payment_data['give_form_id'], $payment_data['price'] );
135 52
	$form_title = isset( $payment_data['give_form_title'] ) ? $payment_data['give_form_title'] : get_the_title( $form_id );
136
137
	//Set properties
138 52
	$payment->total          = $payment_data['price'];
0 ignored issues
show
Documentation introduced by
The property $total is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
139 52
	$payment->status         = ! empty( $payment_data['status'] ) ? $payment_data['status'] : 'pending';
0 ignored issues
show
Documentation introduced by
The property $status is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
140 52
	$payment->currency       = ! empty( $payment_data['currency'] ) ? $payment_data['currency'] : give_get_currency();
0 ignored issues
show
Documentation introduced by
The property $currency is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
141 52
	$payment->user_info      = $payment_data['user_info'];
0 ignored issues
show
Documentation introduced by
The property $user_info is declared private in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
142 52
	$payment->gateway        = $gateway;
0 ignored issues
show
Documentation introduced by
The property $gateway is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
143 52
	$payment->form_title     = $form_title;
0 ignored issues
show
Documentation introduced by
The property $form_title is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
144 52
	$payment->form_id        = $form_id;
0 ignored issues
show
Documentation introduced by
The property $form_id is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
145 52
	$payment->price_id       = $price_id;
0 ignored issues
show
Documentation introduced by
The property $price_id is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
146 52
	$payment->user_id        = $payment_data['user_info']['id'];
0 ignored issues
show
Documentation introduced by
The property $user_id is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
147 52
	$payment->email          = $payment_data['user_email'];
0 ignored issues
show
Documentation introduced by
The property $email is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
148 52
	$payment->first_name     = $payment_data['user_info']['first_name'];
0 ignored issues
show
Documentation introduced by
The property $first_name is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
149 52
	$payment->last_name      = $payment_data['user_info']['last_name'];
0 ignored issues
show
Documentation introduced by
The property $last_name is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
150 52
	$payment->email          = $payment_data['user_info']['email'];
0 ignored issues
show
Documentation introduced by
The property $email is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
151 52
	$payment->ip             = give_get_ip();
0 ignored issues
show
Documentation introduced by
The property $ip is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
152 52
	$payment->key            = $payment_data['purchase_key'];
0 ignored issues
show
Documentation introduced by
The property $key is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
153 52
	$payment->mode           = give_is_test_mode() ? 'test' : 'live';
0 ignored issues
show
Documentation introduced by
The property $mode is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
154 52
	$payment->parent_payment = ! empty( $payment_data['parent'] ) ? absint( $payment_data['parent'] ) : '';
0 ignored issues
show
Documentation introduced by
The property $parent_payment is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
155
156
	//Add the donation
157
	$args = array(
158 52
		'price'    => $payment->total,
0 ignored issues
show
Documentation introduced by
The property $total is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
159 52
		'price_id' => $payment->price_id,
0 ignored issues
show
Documentation introduced by
The property $price_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
160 52
		'fees'     => isset( $payment_data['fees'] ) ? $payment_data['fees'] : array()
161 52
	);
162
163 52
	$payment->add_donation( $payment->form_id, $args );
0 ignored issues
show
Documentation introduced by
The property $form_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
164
165
	//Set date if present
166 52
	if ( isset( $payment_data['post_date'] ) ) {
167
		$payment->date = $payment_data['post_date'];
0 ignored issues
show
Documentation introduced by
The property $date is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
168
	}
169
170
	//Handle sequential payments
171 52
	if ( give_get_option( 'enable_sequential' ) ) {
172 20
		$number          = give_get_next_payment_number();
173 20
		$payment->number = give_format_payment_number( $number );
0 ignored issues
show
Documentation introduced by
The property $number is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
174 20
		update_option( 'give_last_payment_number', $number );
175 20
	}
176
177
	// Clear the user's purchased cache
178 52
	delete_transient( 'give_user_' . $payment_data['user_info']['id'] . '_purchases' );
179
180
	//Save payment
181 52
	$payment->save();
182
183
	//Hook it
184 52
	do_action( 'give_insert_payment', $payment->ID, $payment_data );
185
186
	//Return payment ID upon success
187 52
	if ( ! empty( $payment->ID ) ) {
188 52
		return $payment->ID;
189
	}
190
191
	// Return false if no payment was inserted
192
	return false;
193
194
}
195
196
/**
197
 * Updates a payment status.
198
 *
199
 * @since 1.0
200
 *
201
 * @param int $payment_id Payment ID
202
 * @param string $new_status New Payment Status (default: publish)
203
 *
204
 * @return bool
205
 */
206
function give_update_payment_status( $payment_id, $new_status = 'publish' ) {
207
208 35
	$payment         = new Give_Payment( $payment_id );
209 35
	$payment->status = $new_status;
0 ignored issues
show
Documentation introduced by
The property $status is declared protected in Give_Payment. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
210 35
	$updated         = $payment->save();
211
212 35
	return $updated;
213
}
214
215
216
/**
217
 * Deletes a Donation
218
 *
219
 * @since 1.0
220
 * @global    $give_logs
221
 * @uses  Give_Logging::delete_logs()
222
 *
223
 * @param int $payment_id Payment ID (default: 0)
224
 * @param bool $update_customer If we should update the customer stats (default:true)
225
 *
226
 * @return void
227
 */
228
function give_delete_purchase( $payment_id = 0, $update_customer = true ) {
229 31
	global $give_logs;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
230
231 31
	$payment     = new Give_Payment( $payment_id );
232 31
	$amount      = give_get_payment_amount( $payment_id );
233 31
	$status      = $payment->post_status;
0 ignored issues
show
Documentation introduced by
The property $post_status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
234 31
	$customer_id = give_get_payment_customer_id( $payment_id );
235 31
	$customer    = new Give_Customer( $customer_id );
236
237
	//Only undo purchases that aren't these statuses
238 31
	$dont_undo_statuses = apply_filters( 'give_undo_purchase_statuses', array(
239 31
		'pending',
240
		'cancelled'
241 31
	) );
242
243 31
	if ( ! in_array( $status, $dont_undo_statuses ) ) {
244 16
		give_undo_purchase( false, $payment_id );
245 16
	}
246
247 31
	if ( $status == 'publish' ) {
248
249
		// Only decrease earnings if they haven't already been decreased (or were never increased for this payment)
250 14
		give_decrease_total_earnings( $amount );
251
		// Clear the This Month earnings (this_monththis_month is NOT a typo)
252 14
		delete_transient( md5( 'give_earnings_this_monththis_month' ) );
253
254 14
		if ( $customer->id && $update_customer ) {
255
256
			// Decrement the stats for the customer
257
			$customer->decrease_purchase_count();
258
			$customer->decrease_value( $amount );
259
260
		}
261 14
	}
262
263 31
	do_action( 'give_payment_delete', $payment_id );
264
265 31
	if ( $customer->id && $update_customer ) {
266
267
		// Remove the payment ID from the customer
268 1
		$customer->remove_payment( $payment_id );
269
270 1
	}
271
272
	// Remove the payment
273 31
	wp_delete_post( $payment_id, true );
274
275
	// Remove related sale log entries
276 31
	$give_logs->delete_logs(
277 31
		null,
278 31
		'sale',
279
		array(
280
			array(
281 31
				'key'   => '_give_log_payment_id',
282
				'value' => $payment_id
283 31
			)
284 31
		)
285 31
	);
286
287 31
	do_action( 'give_payment_deleted', $payment_id );
288 31
}
289
290
/**
291
 * Undoes a donation, including the decrease of donations and earning stats. Used for when refunding or deleting a donation
292
 *
293
 * @since 1.0
294
 *
295
 * @param int $form_id Form (Post) ID
296
 * @param int $payment_id Payment ID
297
 *
298
 * @return void
299
 */
300
function give_undo_purchase( $form_id = false, $payment_id ) {
301
302 20
	if ( ! empty( $form_id ) ) {
303
		$form_id = false;
304
		_give_deprected_argument( 'form_id', 'give_undo_purchase', '1.5' );
305
	}
306
307 20
	$payment = new Give_Payment( $payment_id );
308
309 20
	$maybe_decrease_earnings = apply_filters( 'give_decrease_earnings_on_undo', true, $payment, $payment->form_id );
0 ignored issues
show
Documentation introduced by
The property $form_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
310 20
	if ( true === $maybe_decrease_earnings ) {
311
		// decrease earnings
312 18
		give_decrease_earnings( $payment->form_id, $payment->total );
0 ignored issues
show
Documentation introduced by
The property $form_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property $total is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
313 18
	}
314
315 20
	$maybe_decrease_sales = apply_filters( 'give_decrease_sales_on_undo', true, $payment, $payment->form_id );
0 ignored issues
show
Documentation introduced by
The property $form_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
316 20
	if ( true === $maybe_decrease_sales ) {
317
		// decrease purchase count
318 18
		give_decrease_purchase_count( $payment->form_id );
0 ignored issues
show
Documentation introduced by
The property $form_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
319 18
	}
320
321 20
}
322
323
324
/**
325
 * Count Payments
326
 *
327
 * Returns the total number of payments recorded.
328
 *
329
 * @since 1.0
330
 *
331
 * @param array $args
332
 *
333
 * @return array $count Number of payments sorted by payment status
334
 */
335
function give_count_payments( $args = array() ) {
336
337 6
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
338
339
	$defaults = array(
340 6
		'user'       => null,
341 6
		's'          => null,
342 6
		'start-date' => null,
343 6
		'end-date'   => null,
344 6
		'form_id'    => null,
345 6
	);
346
347 6
	$args = wp_parse_args( $args, $defaults );
348
349 6
	$select = "SELECT p.post_status,count( * ) AS num_posts";
350 6
	$join   = '';
351 6
	$where  = "WHERE p.post_type = 'give_payment'";
352
353
	// Count payments for a specific user
354 6
	if ( ! empty( $args['user'] ) ) {
355
356
		if ( is_email( $args['user'] ) ) {
357
			$field = 'email';
358
		} elseif ( is_numeric( $args['user'] ) ) {
359
			$field = 'id';
360
		} else {
361
			$field = '';
362
		}
363
364
		$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
365
366
		if ( ! empty( $field ) ) {
367
			$where .= "
368
				AND m.meta_key = '_give_payment_user_{$field}'
369
				AND m.meta_value = '{$args['user']}'";
370
		}
371
372
		// Count payments for a search
373 6
	} elseif ( ! empty( $args['s'] ) ) {
374
375
		if ( is_email( $args['s'] ) || strlen( $args['s'] ) == 32 ) {
376
377
			if ( is_email( $args['s'] ) ) {
378
				$field = '_give_payment_user_email';
379
			} else {
380
				$field = '_give_payment_purchase_key';
381
			}
382
383
			$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
384
			$where .= $wpdb->prepare( "
385
				AND m.meta_key = %s
386
				AND m.meta_value = %s",
387
				$field,
388
				$args['s']
389
			);
390
391
		} elseif ( '#' == substr( $args['s'], 0, 1 ) ) {
392
393
			$search = str_replace( '#:', '', $args['s'] );
394
			$search = str_replace( '#', '', $search );
395
396
			$select = "SELECT p2.post_status,count( * ) AS num_posts ";
397
			$join   = "LEFT JOIN $wpdb->postmeta m ON m.meta_key = '_give_log_payment_id' AND m.post_id = p.ID ";
398
			$join .= "INNER JOIN $wpdb->posts p2 ON m.meta_value = p2.ID ";
399
			$where = "WHERE p.post_type = 'give_log' ";
400
			$where .= $wpdb->prepare( "AND p.post_parent = %d} ", $search );
401
402
		} elseif ( is_numeric( $args['s'] ) ) {
403
404
			$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
405
			$where .= $wpdb->prepare( "
406
				AND m.meta_key = '_give_payment_user_id'
407
				AND m.meta_value = %d",
408
				$args['s']
409
			);
410
411
		} else {
412
			$search = $wpdb->esc_like( $args['s'] );
413
			$search = '%' . $search . '%';
414
415
			$where .= $wpdb->prepare( "AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))", $search, $search );
416
		}
417
418
	}
419
420 6
	if ( ! empty( $args['form_id'] ) && is_numeric( $args['form_id'] ) ) {
421
422
		$where .= $wpdb->prepare( " AND p.post_parent = %d", $args['form_id'] );
423
424
	}
425
	// Limit payments count by date
426 6
	if ( ! empty( $args['start-date'] ) && false !== strpos( $args['start-date'], '/' ) ) {
427
428
		$date_parts = explode( '/', $args['start-date'] );
429
		$month      = ! empty( $date_parts[0] ) && is_numeric( $date_parts[0] ) ? $date_parts[0] : 0;
430
		$day        = ! empty( $date_parts[1] ) && is_numeric( $date_parts[1] ) ? $date_parts[1] : 0;
431
		$year       = ! empty( $date_parts[2] ) && is_numeric( $date_parts[2] ) ? $date_parts[2] : 0;
432
433
		$is_date = checkdate( $month, $day, $year );
434
		if ( false !== $is_date ) {
435
436
			$date = new DateTime( $args['start-date'] );
437
			$where .= $wpdb->prepare( " AND p.post_date >= '%s'", $date->format( 'Y-m-d' ) );
438
439
		}
440
441
		// Fixes an issue with the payments list table counts when no end date is specified (partiy with stats class)
442
		if ( empty( $args['end-date'] ) ) {
443
			$args['end-date'] = $args['start-date'];
444
		}
445
446
	}
447
448 6
	if ( ! empty ( $args['end-date'] ) && false !== strpos( $args['end-date'], '/' ) ) {
449
450
		$date_parts = explode( '/', $args['end-date'] );
451
452
		$month = ! empty( $date_parts[0] ) ? $date_parts[0] : 0;
453
		$day   = ! empty( $date_parts[1] ) ? $date_parts[1] : 0;
454
		$year  = ! empty( $date_parts[2] ) ? $date_parts[2] : 0;
455
456
		$is_date = checkdate( $month, $day, $year );
457
		if ( false !== $is_date ) {
458
459
			$date = new DateTime( $args['end-date'] );
460
			$where .= $wpdb->prepare( " AND p.post_date <= '%s'", $date->format( 'Y-m-d' ) );
461
462
		}
463
464
	}
465
466 6
	$where = apply_filters( 'give_count_payments_where', $where );
467 6
	$join  = apply_filters( 'give_count_payments_join', $join );
468
469
	$query = "$select
470 6
		FROM $wpdb->posts p
471 6
		$join
472 6
		$where
473
		GROUP BY p.post_status
474 6
	";
475
476 6
	$cache_key = md5( $query );
477
478 6
	$count = wp_cache_get( $cache_key, 'counts' );
479 6
	if ( false !== $count ) {
480
		return $count;
481
	}
482
483 6
	$count = $wpdb->get_results( $query, ARRAY_A );
484
485 6
	$stats    = array();
486 6
	$statuses = get_post_stati();
487 6
	if ( isset( $statuses['private'] ) && empty( $args['s'] ) ) {
488 6
		unset( $statuses['private'] );
489 6
	}
490
491 6
	foreach ( $statuses as $state ) {
492 6
		$stats[ $state ] = 0;
493 6
	}
494
495 6
	foreach ( (array) $count as $row ) {
496
497 6
		if ( 'private' == $row['post_status'] && empty( $args['s'] ) ) {
498
			continue;
499
		}
500
501 6
		$stats[ $row['post_status'] ] = $row['num_posts'];
502 6
	}
503
504 6
	$stats = (object) $stats;
505 6
	wp_cache_set( $cache_key, $stats, 'counts' );
506
507 6
	return $stats;
508
}
509
510
511
/**
512
 * Check For Existing Payment
513
 *
514
 * @since 1.0
515
 *
516
 * @param int $payment_id Payment ID
517
 *
518
 * @return bool true if payment exists, false otherwise
519
 */
520
function give_check_for_existing_payment( $payment_id ) {
521
	$exists  = false;
522
	$payment = new Give_Payment( $payment_id );
523
524
525
	if ( $payment_id === $payment->ID && 'publish' === $payment->status ) {
0 ignored issues
show
Documentation introduced by
The property $status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
526
		$exists = true;
527
	}
528
529
	return $exists;
530
}
531
532
/**
533
 * Get Payment Status
534
 *
535
 * @since 1.0
536
 *
537
 * @param WP_Post $payment
538
 * @param bool $return_label Whether to return the donation status or not
539
 *
540
 * @return bool|mixed if payment status exists, false otherwise
541
 */
542
function give_get_payment_status( $payment, $return_label = false ) {
543
544
	if ( ! is_object( $payment ) || ! isset( $payment->post_status ) ) {
545
		return false;
546
	}
547
548
	$statuses = give_get_payment_statuses();
549
550
	if ( ! is_array( $statuses ) || empty( $statuses ) ) {
551
		return false;
552
	}
553
554
	$payment = new Give_Payment( $payment->ID );
555
556
	if ( array_key_exists( $payment->status, $statuses ) ) {
0 ignored issues
show
Documentation introduced by
The property $status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
557
		if ( true === $return_label ) {
558
			return $statuses[ $payment->status ];
0 ignored issues
show
Documentation introduced by
The property $status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
559
		} else {
560
			// Account that our 'publish' status is labeled 'Complete'
561
			$post_status = 'publish' == $payment->status ? 'Complete' : $payment->post_status;
0 ignored issues
show
Documentation introduced by
The property $status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property $post_status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
562
563
			// Make sure we're matching cases, since they matter
564
			return array_search( strtolower( $post_status ), array_map( 'strtolower', $statuses ) );
565
		}
566
	}
567
568
	return false;
569
}
570
571
/**
572
 * Retrieves all available statuses for payments.
573
 *
574
 * @since 1.0
575
 * @return array $payment_status All the available payment statuses
576
 */
577
function give_get_payment_statuses() {
578
	$payment_statuses = array(
579 52
		'pending'     => __( 'Pending', 'give' ),
580 52
		'publish'     => __( 'Complete', 'give' ),
581 52
		'refunded'    => __( 'Refunded', 'give' ),
582 52
		'failed'      => __( 'Failed', 'give' ),
583 52
		'cancelled'   => __( 'Cancelled', 'give' ),
584 52
		'abandoned'   => __( 'Abandoned', 'give' ),
585 52
		'preapproval' => __( 'Pre-Approved', 'give' ),
586 52
		'revoked'     => __( 'Revoked', 'give' )
587 52
	);
588
589 52
	return apply_filters( 'give_payment_statuses', $payment_statuses );
590
}
591
592
/**
593
 * Get Payment Status Keys
594
 *
595
 * Retrieves keys for all available statuses for payments
596
 *
597
 * @since       1.0
598
 * @return array $payment_status All the available payment statuses
599
 */
600
function give_get_payment_status_keys() {
601 52
	$statuses = array_keys( give_get_payment_statuses() );
602 52
	asort( $statuses );
603
604 52
	return array_values( $statuses );
605
}
606
607
/**
608
 * Get Earnings By Date
609
 *
610
 * @since 1.0
611
 *
612
 * @param int $day Day number
613
 * @param int $month_num Month number
614
 * @param int $year Year
615
 * @param int $hour Hour
616
 *
617
 * @return int $earnings Earnings
618
 */
619
function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) {
620
621
	// This is getting deprecated soon. Use Give_Payment_Stats with the get_earnings() method instead
622
623
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
624
625
	$args = array(
626
		'post_type'              => 'give_payment',
627
		'nopaging'               => true,
628
		'year'                   => $year,
629
		'monthnum'               => $month_num,
630
		'post_status'            => array( 'publish', 'revoked' ),
631
		'fields'                 => 'ids',
632
		'update_post_term_cache' => false
633
	);
634
	if ( ! empty( $day ) ) {
635
		$args['day'] = $day;
636
	}
637
638
	if ( ! empty( $hour ) ) {
639
		$args['hour'] = $hour;
640
	}
641
642
	$args = apply_filters( 'give_get_earnings_by_date_args', $args );
643
	$key  = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 );
644
645
	if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) {
646
		$earnings = false;
647
	} else {
648
		$earnings = get_transient( $key );
649
	}
650
651
	if ( false === $earnings ) {
652
		$sales    = get_posts( $args );
653
		$earnings = 0;
654
		if ( $sales ) {
655
			$sales = implode( ',', $sales );
656
657
			$earnings = $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$sales})" );
658
659
		}
660
		// Cache the results for one hour
661
		set_transient( $key, $earnings, HOUR_IN_SECONDS );
662
	}
663
664
	return round( $earnings, 2 );
665
}
666
667
/**
668
 * Get Donations (sales) By Date
669
 *
670
 * @since  1.0
671
 *
672
 * @param int $day Day number
673
 * @param int $month_num Month number
674
 * @param int $year Year
675
 * @param int $hour Hour
676
 *
677
 * @return int $count Sales
678
 */
679
function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null ) {
680
681
	// This is getting deprecated soon. Use Give_Payment_Stats with the get_sales() method instead
682
	$args = array(
683
		'post_type'              => 'give_payment',
684
		'nopaging'               => true,
685
		'year'                   => $year,
686
		'fields'                 => 'ids',
687
		'post_status'            => array( 'publish', 'revoked' ),
688
		'update_post_meta_cache' => false,
689
		'update_post_term_cache' => false
690
	);
691
692
	$show_free = apply_filters( 'give_sales_by_date_show_free', true, $args );
693
694
	if ( false === $show_free ) {
695
		$args['meta_query'] = array(
696
			array(
697
				'key'     => '_give_payment_total',
698
				'value'   => 0,
699
				'compare' => '>',
700
				'type'    => 'NUMERIC',
701
			),
702
		);
703
	}
704
705
	if ( ! empty( $month_num ) ) {
706
		$args['monthnum'] = $month_num;
707
	}
708
709
	if ( ! empty( $day ) ) {
710
		$args['day'] = $day;
711
	}
712
713
	if ( ! empty( $hour ) ) {
714
		$args['hour'] = $hour;
715
	}
716
717
	$args = apply_filters( 'give_get_sales_by_date_args', $args );
718
719
	$key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 );
720
721
	if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) {
722
		$count = false;
723
	} else {
724
		$count = get_transient( $key );
725
	}
726
727
	if ( false === $count ) {
728
		$sales = new WP_Query( $args );
729
		$count = (int) $sales->post_count;
730
		// Cache the results for one hour
731
		set_transient( $key, $count, HOUR_IN_SECONDS );
732
	}
733
734
	return $count;
735
}
736
737
/**
738
 * Checks whether a payment has been marked as complete.
739
 *
740
 * @since 1.0
741
 *
742
 * @param int $payment_id Payment ID to check against
743
 *
744
 * @return bool true if complete, false otherwise
745
 */
746
function give_is_payment_complete( $payment_id ) {
747
	$payment = new Give_Payment( $payment_id );
748
749
	$ret = false;
750
751
	if ( $payment->ID > 0 ) {
752
753
		if ( (int) $payment_id === (int) $payment->ID && 'publish' == $payment->status ) {
0 ignored issues
show
Documentation introduced by
The property $status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
754
			$ret = true;
755
		}
756
757
	}
758
759
	return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment->post_status );
0 ignored issues
show
Documentation introduced by
The property $post_status is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
760
}
761
762
/**
763
 * Get Total Sales (Donations)
764
 *
765
 * @since 1.0
766
 * @return int $count Total sales
767
 */
768
function give_get_total_sales() {
769
770 5
	$payments = give_count_payments();
771
772 5
	return $payments->revoked + $payments->publish;
773
}
774
775
/**
776
 * Get Total Earnings
777
 *
778
 * @since 1.0
779
 * @return float $total Total earnings
780
 */
781
function give_get_total_earnings() {
782
783 42
	$total = get_option( 'give_earnings_total', false );
784
785
	// If no total stored in DB, use old method of calculating total earnings
786 42
	if ( false === $total ) {
787
788 42
		global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
789
790 42
		$total = get_transient( 'give_earnings_total' );
791
792 42
		if ( false === $total ) {
793
794 42
			$total = (float) 0;
795
796 42
			$args = apply_filters( 'give_get_total_earnings_args', array(
797 42
				'offset' => 0,
798 42
				'number' => - 1,
799 42
				'status' => array( 'publish', 'revoked' ),
800
				'fields' => 'ids'
801 42
			) );
802
803
804 42
			$payments = give_get_payments( $args );
805 42
			if ( $payments ) {
806
807
				/*
808
				 * If performing a purchase, we need to skip the very last payment in the database, since it calls
809
				 * give_increase_total_earnings() on completion, which results in duplicated earnings for the very
810
				 * first purchase
811
				 */
812
813 42
				if ( did_action( 'give_update_payment_status' ) ) {
814 42
					array_pop( $payments );
815 42
				}
816
817 42
				if ( ! empty( $payments ) ) {
818
					$payments = implode( ',', $payments );
819
					$total += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})" );
820
				}
821
822 42
			}
823
824
			// Cache results for 1 day. This cache is cleared automatically when a payment is made
825 42
			set_transient( 'give_earnings_total', $total, 86400 );
826
827
			// Store the total for the first time
828 42
			update_option( 'give_earnings_total', $total );
829 42
		}
830 42
	}
831
832 42
	if ( $total < 0 ) {
833
		$total = 0; // Don't ever show negative earnings
834
	}
835
836 42
	return apply_filters( 'give_total_earnings', round( $total, give_currency_decimal_filter() ) );
837
}
838
839
/**
840
 * Increase the Total Earnings
841
 *
842
 * @since 1.0
843
 *
844
 * @param $amount int The amount you would like to increase the total earnings by.
845
 *
846
 * @return float $total Total earnings
847
 */
848
function give_increase_total_earnings( $amount = 0 ) {
849 42
	$total = give_get_total_earnings();
850 42
	$total += $amount;
851 42
	update_option( 'give_earnings_total', $total );
852
853 42
	return $total;
854
}
855
856
/**
857
 * Decrease the Total Earnings
858
 *
859
 * @since 1.0
860
 *
861
 * @param $amount int The amount you would like to decrease the total earnings by.
862
 *
863
 * @return float $total Total earnings
864
 */
865
function give_decrease_total_earnings( $amount = 0 ) {
866 19
	$total = give_get_total_earnings();
867 19
	$total -= $amount;
868 19
	if ( $total < 0 ) {
869
		$total = 0;
870
	}
871 19
	update_option( 'give_earnings_total', $total );
872
873 19
	return $total;
874
}
875
876
/**
877
 * Get Payment Meta for a specific Payment
878
 *
879
 * @since 1.0
880
 *
881
 * @param int $payment_id Payment ID
882
 * @param string $meta_key The meta key to pull
883
 * @param bool $single Pull single meta entry or as an object
884
 *
885
 * @return mixed $meta Payment Meta
886
 */
887
function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) {
888 42
	$payment = new Give_Payment( $payment_id );
889
890 42
	return $payment->get_meta( $meta_key, $single );
891
}
892
893
/**
894
 * Update the meta for a payment
895
 *
896
 * @param  integer $payment_id Payment ID
897
 * @param  string $meta_key Meta key to update
898
 * @param  string $meta_value Value to update to
899
 * @param  string $prev_value Previous value
900
 *
901
 * @return mixed               Meta ID if successful, false if unsuccessful
902
 */
903
function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
904 18
	$payment = new Give_Payment( $payment_id );
905
906 18
	return $payment->update_meta( $meta_key, $meta_value, $prev_value );
907
}
908
909
/**
910
 * Get the user_info Key from Payment Meta
911
 *
912
 * @since 1.0
913
 *
914
 * @param int $payment_id Payment ID
915
 *
916
 * @return array $user_info User Info Meta Values
917
 */
918
function give_get_payment_meta_user_info( $payment_id ) {
919
	$payment = new Give_Payment( $payment_id );
920
921
	return $payment->user_info;
0 ignored issues
show
Documentation introduced by
The property $user_info is declared private in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
922
}
923
924
/**
925
 * Get the donations Key from Payment Meta
926
 *
927
 * Retrieves the form_id from a (Previously titled give_get_payment_meta_donations)
928
 * @since       1.0
929
 *
930
 * @param int $payment_id Payment ID
931
 *
932
 * @return int $form_id
933
 */
934
function give_get_payment_form_id( $payment_id ) {
935
	$payment = new Give_Payment( $payment_id );
936
937
	return $payment->form_id;
0 ignored issues
show
Documentation introduced by
The property $form_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
938
}
939
940
/**
941
 * Get the user email associated with a payment
942
 *
943
 * @since 1.0
944
 *
945
 * @param int $payment_id Payment ID
946
 *
947
 * @return string $email User Email
948
 */
949
function give_get_payment_user_email( $payment_id ) {
950 42
	$payment = new Give_Payment( $payment_id );
951
952 42
	return $payment->email;
0 ignored issues
show
Documentation introduced by
The property $email is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
953
}
954
955
/**
956
 * Is the payment provided associated with a user account
957
 *
958
 * @since  1.3
959
 *
960
 * @param  int $payment_id The payment ID
961
 *
962
 * @return bool            If the payment is associated with a user (false) or not (true)
963
 */
964
function give_is_guest_payment( $payment_id ) {
965
	$payment_user_id  = give_get_payment_user_id( $payment_id );
966
	$is_guest_payment = ! empty( $payment_user_id ) && $payment_user_id > 0 ? false : true;
967
968
	return (bool) apply_filters( 'give_is_guest_payment', $is_guest_payment, $payment_id );
969
}
970
971
/**
972
 * Get the user ID associated with a payment
973
 *
974
 * @since 1.3
975
 *
976
 * @param int $payment_id Payment ID
977
 *
978
 * @return string $user_id User ID
979
 */
980
function give_get_payment_user_id( $payment_id ) {
981
	$payment = new Give_Payment( $payment_id );
982
983
	return $payment->user_id;
0 ignored issues
show
Documentation introduced by
The property $user_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
984
}
985
986
/**
987
 * Get the donor ID associated with a payment
988
 *
989
 * @since 1.0
990
 *
991
 * @param int $payment_id Payment ID
992
 *
993
 * @return string $customer_id Customer ID
994
 */
995
function give_get_payment_customer_id( $payment_id ) {
996 31
	$payment = new Give_Payment( $payment_id );
997
998 31
	return $payment->customer_id;
0 ignored issues
show
Documentation introduced by
The property $customer_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
999
}
1000
1001
/**
1002
 * Get the IP address used to make a purchase
1003
 *
1004
 * @since 1.0
1005
 *
1006
 * @param int $payment_id Payment ID
1007
 *
1008
 * @return string $ip User IP
1009
 */
1010
function give_get_payment_user_ip( $payment_id ) {
1011
	$payment = new Give_Payment( $payment_id );
1012
1013
	return $payment->ip;
0 ignored issues
show
Documentation introduced by
The property $ip is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1014
}
1015
1016
/**
1017
 * Get the date a payment was completed
1018
 *
1019
 * @since 1.0
1020
 *
1021
 * @param int $payment_id Payment ID
1022
 *
1023
 * @return string $date The date the payment was completed
1024
 */
1025
function give_get_payment_completed_date( $payment_id = 0 ) {
1026
	$payment = new Give_Payment( $payment_id );
1027
1028
	return $payment->completed_date;
0 ignored issues
show
Documentation introduced by
The property $completed_date is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1029
}
1030
1031
/**
1032
 * Get the gateway associated with a payment
1033
 *
1034
 * @since 1.0
1035
 *
1036
 * @param int $payment_id Payment ID
1037
 *
1038
 * @return string $gateway Gateway
1039
 */
1040
function give_get_payment_gateway( $payment_id ) {
1041
	$payment = new Give_Payment( $payment_id );
1042
1043
	return $payment->gateway;
0 ignored issues
show
Documentation introduced by
The property $gateway is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1044
}
1045
1046
/**
1047
 * Get the currency code a payment was made in
1048
 *
1049
 * @since 1.0
1050
 *
1051
 * @param int $payment_id Payment ID
1052
 *
1053
 * @return string $currency The currency code
1054
 */
1055
function give_get_payment_currency_code( $payment_id = 0 ) {
1056
	$payment = new Give_Payment( $payment_id );
1057
1058
	return $payment->currency;
0 ignored issues
show
Documentation introduced by
The property $currency is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1059
}
1060
1061
/**
1062
 * Get the currency name a payment was made in
1063
 *
1064
 * @since 1.0
1065
 *
1066
 * @param int $payment_id Payment ID
1067
 *
1068
 * @return string $currency The currency name
1069
 */
1070
function give_get_payment_currency( $payment_id = 0 ) {
1071
	$currency = give_get_payment_currency_code( $payment_id );
1072
1073
	return apply_filters( 'give_payment_currency', give_get_currency_name( $currency ), $payment_id );
1074
}
1075
1076
/**
1077
 * Get the purchase key for a purchase
1078
 *
1079
 * @since 1.0
1080
 *
1081
 * @param int $payment_id Payment ID
1082
 *
1083
 * @return string $key Purchase key
1084
 */
1085
function give_get_payment_key( $payment_id = 0 ) {
1086 52
	$payment = new Give_Payment( $payment_id );
1087
1088 52
	return $payment->key;
0 ignored issues
show
Documentation introduced by
The property $key is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1089
}
1090
1091
/**
1092
 * Get the payment order number
1093
 *
1094
 * This will return the payment ID if sequential order numbers are not enabled or the order number does not exist
1095
 *
1096
 * @since 1.0
1097
 *
1098
 * @param int $payment_id Payment ID
1099
 *
1100
 * @return string $number Payment order number
1101
 */
1102
function give_get_payment_number( $payment_id = 0 ) {
1103
	$payment = new Give_Payment( $payment_id );
1104
1105
	return $payment->number;
0 ignored issues
show
Documentation introduced by
The property $number is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1106
}
1107
1108
/**
1109
 * Formats the payment number with the prefix and postfix
1110
 *
1111
 * @since  1.3
1112
 *
1113
 * @param  int $number The payment number to format
1114
 *
1115
 * @return string      The formatted payment number
1116
 */
1117
function give_format_payment_number( $number ) {
1118
1119 20
	if ( ! give_get_option( 'enable_sequential' ) ) {
1120
		return $number;
1121
	}
1122
1123 20
	if ( ! is_numeric( $number ) ) {
1124
		return $number;
1125
	}
1126
1127 20
	$prefix  = give_get_option( 'sequential_prefix' );
1128 20
	$number  = absint( $number );
1129 20
	$postfix = give_get_option( 'sequential_postfix' );
1130
1131 20
	$formatted_number = $prefix . $number . $postfix;
1132
1133 20
	return apply_filters( 'give_format_payment_number', $formatted_number, $prefix, $number, $postfix );
1134
}
1135
1136
/**
1137
 * Gets the next available order number
1138
 *
1139
 * This is used when inserting a new payment
1140
 *
1141
 * @since 1.0
1142
 * @return string $number The next available payment number
1143
 */
1144
function give_get_next_payment_number() {
1145
1146 20
	if ( ! give_get_option( 'enable_sequential' ) ) {
1147
		return false;
1148
	}
1149
1150 20
	$number           = get_option( 'give_last_payment_number' );
1151 20
	$start            = give_get_option( 'sequential_start', 1 );
1152 20
	$increment_number = true;
1153
1154 20
	if ( false !== $number ) {
1155
1156 2
		if ( empty( $number ) ) {
1157
1158
			$number           = $start;
1159
			$increment_number = false;
1160
1161
		}
1162
1163 2
	} else {
1164
1165
		// This case handles the first addition of the new option, as well as if it get's deleted for any reason
1166 20
		$payments     = new Give_Payments_Query( array(
1167 20
			'number'  => 1,
1168 20
			'order'   => 'DESC',
1169 20
			'orderby' => 'ID',
1170 20
			'output'  => 'posts',
1171
			'fields'  => 'ids'
1172 20
		) );
1173 20
		$last_payment = $payments->get_payments();
1174
1175 20
		if ( ! empty( $last_payment ) ) {
1176
1177
			$number = give_get_payment_number( $last_payment[0] );
1178
1179
		}
1180
1181 20
		if ( ! empty( $number ) && $number !== (int) $last_payment[0] ) {
1182
1183
			$number = give_remove_payment_prefix_postfix( $number );
1184
1185
		} else {
1186
1187 20
			$number           = $start;
1188 20
			$increment_number = false;
1189
		}
1190
1191
	}
1192
1193 20
	$increment_number = apply_filters( 'give_increment_payment_number', $increment_number, $number );
1194
1195 20
	if ( $increment_number ) {
1196 2
		$number ++;
1197 2
	}
1198
1199 20
	return apply_filters( 'give_get_next_payment_number', $number );
1200
}
1201
1202
/**
1203
 * Given a given a number, remove the pre/postfix
1204
 *
1205
 * @since  1.3
1206
 *
1207
 * @param  string $number The formatted Current Number to increment
1208
 *
1209
 * @return string          The new Payment number without prefix and postfix
1210
 */
1211
function give_remove_payment_prefix_postfix( $number ) {
1212
1213
	$prefix  = give_get_option( 'sequential_prefix' );
1214
	$postfix = give_get_option( 'sequential_postfix' );
1215
1216
	// Remove prefix
1217
	$number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
1218
1219
	// Remove the postfix
1220
	$length      = strlen( $number );
1221
	$postfix_pos = strrpos( $number, $postfix );
1222
	if ( false !== $postfix_pos ) {
1223
		$number = substr_replace( $number, '', $postfix_pos, $length );
1224
	}
1225
1226
	// Ensure it's a whole number
1227
	$number = intval( $number );
1228
1229
	return apply_filters( 'give_remove_payment_prefix_postfix', $number, $prefix, $postfix );
1230
1231
}
1232
1233
1234
/**
1235
 * Get Payment Amount
1236
 *
1237
 * Get the fully formatted payment amount. The payment amount is retrieved using give_get_payment_amount() and is then sent through give_currency_filter() and  give_format_amount() to format the amount correctly.
1238
 *
1239
 * @since       1.0
1240
 *
1241
 * @param int $payment_id Payment ID
1242
 *
1243
 * @return string $amount Fully formatted payment amount
1244
 */
1245
function give_payment_amount( $payment_id = 0 ) {
1246
	$amount = give_get_payment_amount( $payment_id );
1247
1248
	return give_currency_filter( give_format_amount( $amount ), give_get_payment_currency_code( $payment_id ) );
1249
}
1250
1251
/**
1252
 * Get the amount associated with a payment
1253
 *
1254
 * @access public
1255
 * @since  1.0
1256
 *
1257
 * @param int $payment_id Payment ID
1258
 *
1259
 * @return mixed|void
1260
 */
1261
function give_get_payment_amount( $payment_id ) {
1262
1263 52
	$payment = new Give_Payment( $payment_id );
1264
1265 52
	return apply_filters( 'give_payment_amount', floatval( $payment->total ), $payment_id );
0 ignored issues
show
Documentation introduced by
The property $total is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1266
}
1267
1268
/**
1269
 * Payment Subtotal
1270
 *
1271
 * Retrieves subtotal for payment (this is the amount before fees) and then returns a full formatted amount. This function essentially calls give_get_payment_subtotal()
1272
 *
1273
 * @since 1.5
1274
 *
1275
 * @param int $payment_id Payment ID
1276
 *
1277
 * @see give_get_payment_subtotal()
1278
 *
1279
 * @return array Fully formatted payment subtotal
1280
 */
1281
function give_payment_subtotal( $payment_id = 0 ) {
1282
	$subtotal = give_get_payment_subtotal( $payment_id );
1283
1284
	return give_currency_filter( give_format_amount( $subtotal ), give_get_payment_currency_code( $payment_id ) );
1285
}
1286
1287
/**
1288
 * Get Payment Subtotal
1289
 *
1290
 * Retrieves subtotal for payment (this is the amount before fees) and then returns a non formatted amount.
1291
 *
1292
 * @since 1.5
1293
 *
1294
 * @param int $payment_id Payment ID
1295
 *
1296
 * @return float $subtotal Subtotal for payment (non formatted)
1297
 */
1298
function give_get_payment_subtotal( $payment_id = 0 ) {
1299
	$payment = new G_Payment( $payment_id );
1300
1301
	return $payment->subtotal;
1302
}
1303
1304
/**
1305
 * Retrieves arbitrary fees for the payment
1306
 *
1307
 * @since 1.5
1308
 *
1309
 * @param int $payment_id Payment ID
1310
 * @param string $type Fee type
1311
 *
1312
 * @return mixed array if payment fees found, false otherwise
1313
 */
1314
function give_get_payment_fees( $payment_id = 0, $type = 'all' ) {
1315
	$payment = new Give_Payment( $payment_id );
1316
1317
	return $payment->get_fees( $type );
1318
}
1319
1320
/**
1321
 * Retrieves the transaction ID for the given payment
1322
 *
1323
 * @since  1.0
1324
 *
1325
 * @param int $payment_id Payment ID
1326
 *
1327
 * @return string The Transaction ID
1328
 */
1329
function give_get_payment_transaction_id( $payment_id = 0 ) {
1330
	$payment = new Give_Payment( $payment_id );
1331
1332
	return $payment->transaction_id;
0 ignored issues
show
Documentation introduced by
The property $transaction_id is declared protected in Give_Payment. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1333
}
1334
1335
/**
1336
 * Sets a Transaction ID in post meta for the given Payment ID
1337
 *
1338
 * @since  1.0
1339
 *
1340
 * @param int $payment_id Payment ID
1341
 * @param string $transaction_id The transaction ID from the gateway
1342
 *
1343
 * @return bool|mixed
1344
 */
1345
function give_set_payment_transaction_id( $payment_id = 0, $transaction_id = '' ) {
1346
1347 18
	if ( empty( $payment_id ) || empty( $transaction_id ) ) {
1348
		return false;
1349
	}
1350
1351 18
	$transaction_id = apply_filters( 'give_set_payment_transaction_id', $transaction_id, $payment_id );
1352
1353 18
	return give_update_payment_meta( $payment_id, '_give_payment_transaction_id', $transaction_id );
1354
}
1355
1356
/**
1357
 * Retrieve the purchase ID based on the purchase key
1358
 *
1359
 * @since 1.0
1360
 * @global object $wpdb Used to query the database using the WordPress
1361
 *                      Database API
1362
 *
1363
 * @param string $key the purchase key to search for
1364
 *
1365
 * @return int $purchase Purchase ID
1366
 */
1367
function give_get_purchase_id_by_key( $key ) {
1368
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1369
1370
	$purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key ) );
1371
1372
	if ( $purchase != null ) {
1373
		return $purchase;
1374
	}
1375
1376
	return 0;
1377
}
1378
1379
1380
/**
1381
 * Retrieve the purchase ID based on the transaction ID
1382
 *
1383
 * @since 1.3
1384
 * @global object $wpdb Used to query the database using the WordPress
1385
 *                      Database API
1386
 *
1387
 * @param string $key the transaction ID to search for
1388
 *
1389
 * @return int $purchase Purchase ID
1390
 */
1391
function give_get_purchase_id_by_transaction_id( $key ) {
1392
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1393
1394
	$purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
1395
1396
	if ( $purchase != null ) {
1397
		return $purchase;
1398
	}
1399
1400
	return 0;
1401
}
1402
1403
/**
1404
 * Retrieve all notes attached to a purchase
1405
 *
1406
 * @since 1.0
1407
 *
1408
 * @param int $payment_id The payment ID to retrieve notes for
1409
 * @param string $search Search for notes that contain a search term
1410
 *
1411
 * @return array $notes Payment Notes
1412
 */
1413
function give_get_payment_notes( $payment_id = 0, $search = '' ) {
1414
1415
	if ( empty( $payment_id ) && empty( $search ) ) {
1416
		return false;
1417
	}
1418
1419
	remove_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1420
	remove_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1421
1422
	$notes = get_comments( array( 'post_id' => $payment_id, 'order' => 'ASC', 'search' => $search ) );
1423
1424
	add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1425
	add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1426
1427
	return $notes;
1428
}
1429
1430
1431
/**
1432
 * Add a note to a payment
1433
 *
1434
 * @since 1.0
1435
 *
1436
 * @param int $payment_id The payment ID to store a note for
1437
 * @param string $note The note to store
1438
 *
1439
 * @return int The new note ID
1440
 */
1441
function give_insert_payment_note( $payment_id = 0, $note = '' ) {
1442 52
	if ( empty( $payment_id ) ) {
1443
		return false;
1444
	}
1445
1446 52
	do_action( 'give_pre_insert_payment_note', $payment_id, $note );
1447
1448 52
	$note_id = wp_insert_comment( wp_filter_comment( array(
1449 52
		'comment_post_ID'      => $payment_id,
1450 52
		'comment_content'      => $note,
1451 52
		'user_id'              => is_admin() ? get_current_user_id() : 0,
1452 52
		'comment_date'         => current_time( 'mysql' ),
1453 52
		'comment_date_gmt'     => current_time( 'mysql', 1 ),
1454 52
		'comment_approved'     => 1,
1455 52
		'comment_parent'       => 0,
1456 52
		'comment_author'       => '',
1457 52
		'comment_author_IP'    => '',
1458 52
		'comment_author_url'   => '',
1459 52
		'comment_author_email' => '',
1460
		'comment_type'         => 'give_payment_note'
1461
1462 52
	) ) );
1463
1464 52
	do_action( 'give_insert_payment_note', $note_id, $payment_id, $note );
1465
1466 52
	return $note_id;
1467
}
1468
1469
/**
1470
 * Deletes a payment note
1471
 *
1472
 * @since 1.0
1473
 *
1474
 * @param int $comment_id The comment ID to delete
1475
 * @param int $payment_id The payment ID the note is connected to
1476
 *
1477
 * @return bool True on success, false otherwise
1478
 */
1479
function give_delete_payment_note( $comment_id = 0, $payment_id = 0 ) {
1480
	if ( empty( $comment_id ) ) {
1481
		return false;
1482
	}
1483
1484
	do_action( 'give_pre_delete_payment_note', $comment_id, $payment_id );
1485
	$ret = wp_delete_comment( $comment_id, true );
1486
	do_action( 'give_post_delete_payment_note', $comment_id, $payment_id );
1487
1488
	return $ret;
1489
}
1490
1491
/**
1492
 * Gets the payment note HTML
1493
 *
1494
 * @since 1.0
1495
 *
1496
 * @param     object /int $note The comment object or ID
1497
 * @param int $payment_id The payment ID the note is connected to
1498
 *
1499
 * @return string
1500
 */
1501
function give_get_payment_note_html( $note, $payment_id = 0 ) {
1502
1503
	if ( is_numeric( $note ) ) {
1504
		$note = get_comment( $note );
1505
	}
1506
1507
	if ( ! empty( $note->user_id ) ) {
1508
		$user = get_userdata( $note->user_id );
1509
		$user = $user->display_name;
1510
	} else {
1511
		$user = __( 'System', 'give' );
1512
	}
1513
1514
	$date_format = get_option( 'date_format' ) . ', ' . get_option( 'time_format' );
1515
1516
	$delete_note_url = wp_nonce_url( add_query_arg( array(
1517
		'give-action' => 'delete_payment_note',
1518
		'note_id'     => $note->comment_ID,
1519
		'payment_id'  => $payment_id
1520
	) ), 'give_delete_payment_note_' . $note->comment_ID );
1521
1522
	$note_html = '<div class="give-payment-note" id="give-payment-note-' . $note->comment_ID . '">';
1523
	$note_html .= '<p>';
1524
	$note_html .= '<strong>' . $user . '</strong>&nbsp;&ndash;&nbsp;<span style="color:#aaa;font-style:italic;">' . date_i18n( $date_format, strtotime( $note->comment_date ) ) . '</span><br/>';
1525
	$note_html .= $note->comment_content;
1526
	$note_html .= '&nbsp;&ndash;&nbsp;<a href="' . esc_url( $delete_note_url ) . '" class="give-delete-payment-note" data-note-id="' . absint( $note->comment_ID ) . '" data-payment-id="' . absint( $payment_id ) . '" title="' . __( 'Delete this payment note', 'give' ) . '">' . __( 'Delete', 'give' ) . '</a>';
1527
	$note_html .= '</p>';
1528
	$note_html .= '</div>';
1529
1530
	return $note_html;
1531
1532
}
1533
1534
/**
1535
 * Exclude notes (comments) on give_payment post type from showing in Recent
1536
 * Comments widgets
1537
 *
1538
 * @since 1.0
1539
 *
1540
 * @param object $query WordPress Comment Query Object
1541
 *
1542
 * @return void
1543
 */
1544
function give_hide_payment_notes( $query ) {
1545
	global $wp_version;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1546
1547
	if ( version_compare( floatval( $wp_version ), '4.1', '>=' ) ) {
1548
		$types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array();
1549
		if ( ! is_array( $types ) ) {
1550
			$types = array( $types );
1551
		}
1552
		$types[]                           = 'give_payment_note';
1553
		$query->query_vars['type__not_in'] = $types;
1554
	}
1555
}
1556
1557
add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1558
1559
/**
1560
 * Exclude notes (comments) on give_payment post type from showing in Recent Comments widgets
1561
 *
1562
 * @since 1.0
1563
 *
1564
 * @param array $clauses Comment clauses for comment query
1565
 * @param object $wp_comment_query WordPress Comment Query Object
1566
 *
1567
 * @return array $clauses Updated comment clauses
1568
 */
1569
function give_hide_payment_notes_pre_41( $clauses, $wp_comment_query ) {
0 ignored issues
show
Unused Code introduced by
The parameter $wp_comment_query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1570
	global $wpdb, $wp_version;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1571
1572
	if ( version_compare( floatval( $wp_version ), '4.1', '<' ) ) {
1573
		$clauses['where'] .= ' AND comment_type != "give_payment_note"';
1574
	}
1575
1576
	return $clauses;
1577
}
1578
1579
add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1580
1581
1582
/**
1583
 * Exclude notes (comments) on give_payment post type from showing in comment feeds
1584
 *
1585
 * @since 1.0
1586
 *
1587
 * @param array $where
1588
 * @param object $wp_comment_query WordPress Comment Query Object
1589
 *
1590
 * @return array $where
1591
 */
1592
function give_hide_payment_notes_from_feeds( $where, $wp_comment_query ) {
0 ignored issues
show
Unused Code introduced by
The parameter $wp_comment_query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1593
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1594
1595
	$where .= $wpdb->prepare( " AND comment_type != %s", 'give_payment_note' );
1596
1597
	return $where;
1598
}
1599
1600
add_filter( 'comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2 );
1601
1602
1603
/**
1604
 * Remove Give Comments from the wp_count_comments function
1605
 *
1606
 * @access public
1607
 * @since  1.0
1608
 *
1609
 * @param array $stats (empty from core filter)
1610
 * @param int $post_id Post ID
1611
 *
1612
 * @return array Array of comment counts
1613
 */
1614
function give_remove_payment_notes_in_comment_counts( $stats, $post_id ) {
1615
	global $wpdb, $pagenow;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1616
1617
	if ( 'index.php' != $pagenow ) {
1618
		return $stats;
1619
	}
1620
1621
	$post_id = (int) $post_id;
1622
1623
	if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) {
1624
		return $stats;
1625
	}
1626
1627
	$stats = wp_cache_get( "comments-{$post_id}", 'counts' );
1628
1629
	if ( false !== $stats ) {
1630
		return $stats;
1631
	}
1632
1633
	$where = 'WHERE comment_type != "give_payment_note"';
1634
1635
	if ( $post_id > 0 ) {
1636
		$where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1637
	}
1638
1639
	$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1640
1641
	$total    = 0;
1642
	$approved = array(
1643
		'0'            => 'moderated',
1644
		'1'            => 'approved',
1645
		'spam'         => 'spam',
1646
		'trash'        => 'trash',
1647
		'post-trashed' => 'post-trashed'
1648
	);
1649
	foreach ( (array) $count as $row ) {
1650
		// Don't count post-trashed toward totals
1651
		if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
1652
			$total += $row['num_comments'];
1653
		}
1654
		if ( isset( $approved[ $row['comment_approved'] ] ) ) {
1655
			$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
1656
		}
1657
	}
1658
1659
	$stats['total_comments'] = $total;
1660
	foreach ( $approved as $key ) {
1661
		if ( empty( $stats[ $key ] ) ) {
1662
			$stats[ $key ] = 0;
1663
		}
1664
	}
1665
1666
	$stats = (object) $stats;
1667
	wp_cache_set( "comments-{$post_id}", $stats, 'counts' );
1668
1669
	return $stats;
1670
}
1671
1672
add_filter( 'wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2 );
1673
1674
1675
/**
1676
 * Filter where older than one week
1677
 *
1678
 * @access public
1679
 * @since  1.0
1680
 *
1681
 * @param string $where Where clause
1682
 *
1683
 * @return string $where Modified where clause
1684
 */
1685
function give_filter_where_older_than_week( $where = '' ) {
1686
	// Payments older than one week
1687
	$start = date( 'Y-m-d', strtotime( '-7 days' ) );
1688
	$where .= " AND post_date <= '{$start}'";
1689
1690
	return $where;
1691
}
1692
1693
1694
/**
1695
 * Get Payment Form ID
1696
 *
1697
 * Retrieves the form title and appends the price ID title if applicable
1698
 *
1699
 * @since 1.5
1700
 *
1701
 * @param array $payment_meta
1702
 * @param bool $level_title Whether you want the entire title or just the level title
1703
 *
1704
 * @return string $form_title Returns the full title if $level_title false, otherwise returns the levels title
1705
 */
1706
function give_get_payment_form_title( $payment_meta, $level_title = false, $separator = '' ) {
1707
1708 42
	$form_id    = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0;
1709 42
	$form_title = isset( $payment_meta['form_title'] ) ? $payment_meta['form_title'] : '';
1710 42
	$price_id   = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null;
1711
1712 42
	if ( $level_title == true ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
1713
		$form_title = '';
1714
	}
1715
1716 42
	if ( give_has_variable_prices( $form_id ) ) {
1717
1718 34
		if ( ! empty( $separator ) ) {
1719 34
			$form_title .= ' ' . $separator;
1720 34
		}
1721 34
		$form_title .= ' <span class="donation-level-text-wrap">';
1722
1723 34
		if ( $price_id == 'custom' ) {
1724
1725
			$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
1726
			$form_title .= ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' );
1727
1728
		} else {
1729 34
			$form_title .= give_get_price_option_name( $form_id, $price_id );
1730
		}
1731
1732 34
		$form_title .= '</span>';
1733
1734 34
	}
1735
1736 42
	return apply_filters( 'give_get_payment_form_title', $form_title, $payment_meta );
1737
1738
}
1739
1740
/**
1741
 * Get Price ID
1742
 *
1743
 * Retrieves the Price ID when provided a proper form ID and price (donation) total
1744
 *
1745
 * @param $form_id
1746
 * @param $price
1747
 *
1748
 * @return string $price_id
1749
 */
1750
function give_get_price_id( $form_id, $price ) {
1751
1752 52
	$price_id = 0;
1753
1754 52
	if ( give_has_variable_prices( $form_id ) ) {
1755
1756 32
		$levels = maybe_unserialize( get_post_meta( $form_id, '_give_donation_levels', true ) );
1757
1758 32
		foreach ( $levels as $level ) {
1759
1760 32
			$level_amount = (float) give_sanitize_amount( $level['_give_amount'] );
1761
1762
			//check that this indeed the recurring price
1763 32
			if ( $level_amount == $price ) {
1764
1765 32
				$price_id = $level['_give_id']['level_id'];
1766
1767 32
			}
1768
1769 32
		}
1770
1771 32
	}
1772
1773 52
	return $price_id;
1774
1775
}
1776
1777
/**
1778
 * Get/Print give form dropdown html
1779
 * 
1780
 * This function is wrapper to public method forms_dropdown of Give_HTML_Elements class to get/print form dropdown html.
1781
 * Give_HTML_Elements is defind in includes/class-give-html-elements.php
1782
 *
1783
 * @since 1.6
1784
 * 
1785
 * @param array $args Arguments for form dropdown
1786
 * @param bool $echo  This parameter decide if print form dropdown html output or not
1787
 * 
1788
 * @return string/void
0 ignored issues
show
Documentation introduced by
The doc-type string/void could not be parsed: Unknown type name "string/void" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1789
 */
1790
function give_get_form_dropdown( $args = array(), $echo = false ){
1791
    $form_dropdown_html = Give()->html->forms_dropdown( $args );
1792
1793
    if( ! $echo ) {
1794
        return $form_dropdown_html;
1795
    }
1796
1797
    echo $form_dropdown_html;
1798
}
1799
1800
/**
1801
 * Get/Print give form variable price dropdown html
1802
 *
1803
 * @since 1.6
1804
 *
1805
 * @param array $args Arguments for form dropdown
1806
 * @param bool $echo  This parameter decide if print form dropdown html output or not
1807
 *
1808
 * @return string/void
0 ignored issues
show
Documentation introduced by
The doc-type string/void could not be parsed: Unknown type name "string/void" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1809
 */
1810
function give_get_form_variable_price_dropdown( $args = array(), $echo = false ){
1811
    
1812
    // Check for give form id.
1813
    if( empty( $args['id'] ) ) {
1814
        return false;
1815
    }
1816
1817
    // Check if form has variable prices or not.
1818
    if( ! ( $variable_prices = give_has_variable_prices( $args['id'] ) ) ) {
1819
        return false;
1820
    }
1821
    
1822
    $variable_prices = give_get_variable_prices( absint( $args['id'] ) );
1823
    $variable_price_options = array();
1824
1825
    // Check if multi donation form support custom donation or not.
1826
    if( give_is_custom_price_mode( absint( $args['id'] ) ) ) {
1827
        $variable_price_options['custom']  = _x( 'Custom', 'custom donation dropdown item', 'give' );
1828
    }
1829
1830
    // Get variable price and ID from variable price array.
1831
    foreach ( $variable_prices as $variable_price ) {
1832
        $variable_price_options[ $variable_price['_give_id']['level_id'] ] =  $variable_price['_give_text'];
1833
    }
1834
1835
1836
    // Update options.
1837
    $args = array_merge( $args, array( 'options' => $variable_price_options ) );
1838
1839
    // Generate select html.
1840
    $form_dropdown_html = Give()->html->select( $args );
1841
1842
    if( ! $echo ) {
1843
        return $form_dropdown_html;
1844
    }
1845
1846
    echo $form_dropdown_html;
1847
}