@@ -16,165 +16,165 @@ |
||
16 | 16 | */ |
17 | 17 | class GetPaid_MaxMind_Geolocation { |
18 | 18 | |
19 | - /** |
|
20 | - * The service responsible for interacting with the MaxMind database. |
|
21 | - * |
|
22 | - * @var GetPaid_MaxMind_Database_Service |
|
23 | - */ |
|
24 | - private $database_service; |
|
25 | - |
|
26 | - /** |
|
27 | - * Initialize the integration. |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - /** |
|
32 | - * Supports overriding the database service to be used. |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @return mixed|null The geolocation database service. |
|
36 | - */ |
|
37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | - if ( null === $this->database_service ) { |
|
39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | - } |
|
41 | - |
|
42 | - // Bind to the scheduled updater action. |
|
43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | - |
|
45 | - // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | - |
|
48 | - // Handle maxmind key updates. |
|
49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get database service. |
|
55 | - * |
|
56 | - * @return GetPaid_MaxMind_Database_Service|null |
|
57 | - */ |
|
58 | - public function get_database_service() { |
|
59 | - return $this->database_service; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Checks to make sure that the license key is valid. |
|
64 | - * |
|
65 | - * @param string $license_key The new license key. |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function handle_key_updates( $license_key ) { |
|
69 | - |
|
70 | - // Trim whitespaces and strip slashes. |
|
71 | - $license_key = trim( $license_key ); |
|
72 | - |
|
73 | - // Abort if the license key is empty or unchanged. |
|
74 | - if ( empty( $license_key ) ) { |
|
75 | - return $license_key; |
|
76 | - } |
|
77 | - |
|
78 | - // Abort if a database exists and the license key is unchaged. |
|
79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | - return $license_key; |
|
81 | - } |
|
82 | - |
|
83 | - // Check the license key by attempting to download the Geolocation database. |
|
84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | - return $license_key; |
|
88 | - } |
|
89 | - |
|
90 | - $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | - |
|
92 | - return $license_key; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Updates the database used for geolocation queries. |
|
97 | - * |
|
98 | - * @param string $tmp_database_path Temporary database path. |
|
99 | - */ |
|
100 | - public function update_database( $tmp_database_path = null ) { |
|
101 | - |
|
102 | - // Allow us to easily interact with the filesystem. |
|
103 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
104 | - WP_Filesystem(); |
|
105 | - global $wp_filesystem; |
|
106 | - |
|
107 | - // Remove any existing archives to comply with the MaxMind TOS. |
|
108 | - $target_database_path = $this->database_service->get_database_path(); |
|
109 | - |
|
110 | - // If there's no database path, we can't store the database. |
|
111 | - if ( empty( $target_database_path ) ) { |
|
112 | - return; |
|
113 | - } |
|
114 | - |
|
115 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
116 | - $wp_filesystem->delete( $target_database_path ); |
|
117 | - } |
|
118 | - |
|
119 | - // We can't download a database if there's no license key configured. |
|
120 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
121 | - if ( empty( $license_key ) ) { |
|
122 | - return; |
|
123 | - } |
|
124 | - |
|
125 | - if ( empty( $tmp_database_path ) ) { |
|
126 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
127 | - } |
|
128 | - |
|
129 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
130 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - // Move the new database into position. |
|
135 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
136 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
141 | - * |
|
142 | - * @param array $data Geolocation data. |
|
143 | - * @param string $ip_address The IP address to geolocate. |
|
144 | - * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
145 | - */ |
|
146 | - public function get_geolocation( $data, $ip_address ) { |
|
147 | - |
|
148 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
149 | - return $data; |
|
150 | - } |
|
151 | - |
|
152 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
153 | - |
|
154 | - return array( |
|
155 | - 'country' => $country_code, |
|
156 | - 'state' => '', |
|
157 | - 'city' => '', |
|
158 | - 'postcode' => '', |
|
159 | - ); |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Fetches the prefix for the MaxMind database file. |
|
165 | - * |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - private function get_database_prefix() { |
|
169 | - |
|
170 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
171 | - |
|
172 | - if ( empty( $prefix ) ) { |
|
173 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
174 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
175 | - } |
|
176 | - |
|
177 | - return $prefix; |
|
178 | - } |
|
19 | + /** |
|
20 | + * The service responsible for interacting with the MaxMind database. |
|
21 | + * |
|
22 | + * @var GetPaid_MaxMind_Database_Service |
|
23 | + */ |
|
24 | + private $database_service; |
|
25 | + |
|
26 | + /** |
|
27 | + * Initialize the integration. |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + /** |
|
32 | + * Supports overriding the database service to be used. |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @return mixed|null The geolocation database service. |
|
36 | + */ |
|
37 | + $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | + if ( null === $this->database_service ) { |
|
39 | + $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | + } |
|
41 | + |
|
42 | + // Bind to the scheduled updater action. |
|
43 | + add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | + |
|
45 | + // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | + add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | + |
|
48 | + // Handle maxmind key updates. |
|
49 | + add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get database service. |
|
55 | + * |
|
56 | + * @return GetPaid_MaxMind_Database_Service|null |
|
57 | + */ |
|
58 | + public function get_database_service() { |
|
59 | + return $this->database_service; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Checks to make sure that the license key is valid. |
|
64 | + * |
|
65 | + * @param string $license_key The new license key. |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function handle_key_updates( $license_key ) { |
|
69 | + |
|
70 | + // Trim whitespaces and strip slashes. |
|
71 | + $license_key = trim( $license_key ); |
|
72 | + |
|
73 | + // Abort if the license key is empty or unchanged. |
|
74 | + if ( empty( $license_key ) ) { |
|
75 | + return $license_key; |
|
76 | + } |
|
77 | + |
|
78 | + // Abort if a database exists and the license key is unchaged. |
|
79 | + if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | + return $license_key; |
|
81 | + } |
|
82 | + |
|
83 | + // Check the license key by attempting to download the Geolocation database. |
|
84 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | + getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | + return $license_key; |
|
88 | + } |
|
89 | + |
|
90 | + $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | + |
|
92 | + return $license_key; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Updates the database used for geolocation queries. |
|
97 | + * |
|
98 | + * @param string $tmp_database_path Temporary database path. |
|
99 | + */ |
|
100 | + public function update_database( $tmp_database_path = null ) { |
|
101 | + |
|
102 | + // Allow us to easily interact with the filesystem. |
|
103 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
104 | + WP_Filesystem(); |
|
105 | + global $wp_filesystem; |
|
106 | + |
|
107 | + // Remove any existing archives to comply with the MaxMind TOS. |
|
108 | + $target_database_path = $this->database_service->get_database_path(); |
|
109 | + |
|
110 | + // If there's no database path, we can't store the database. |
|
111 | + if ( empty( $target_database_path ) ) { |
|
112 | + return; |
|
113 | + } |
|
114 | + |
|
115 | + if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
116 | + $wp_filesystem->delete( $target_database_path ); |
|
117 | + } |
|
118 | + |
|
119 | + // We can't download a database if there's no license key configured. |
|
120 | + $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
121 | + if ( empty( $license_key ) ) { |
|
122 | + return; |
|
123 | + } |
|
124 | + |
|
125 | + if ( empty( $tmp_database_path ) ) { |
|
126 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
127 | + } |
|
128 | + |
|
129 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
130 | + wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + // Move the new database into position. |
|
135 | + $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
136 | + $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
141 | + * |
|
142 | + * @param array $data Geolocation data. |
|
143 | + * @param string $ip_address The IP address to geolocate. |
|
144 | + * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
145 | + */ |
|
146 | + public function get_geolocation( $data, $ip_address ) { |
|
147 | + |
|
148 | + if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
149 | + return $data; |
|
150 | + } |
|
151 | + |
|
152 | + $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
153 | + |
|
154 | + return array( |
|
155 | + 'country' => $country_code, |
|
156 | + 'state' => '', |
|
157 | + 'city' => '', |
|
158 | + 'postcode' => '', |
|
159 | + ); |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Fetches the prefix for the MaxMind database file. |
|
165 | + * |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + private function get_database_prefix() { |
|
169 | + |
|
170 | + $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
171 | + |
|
172 | + if ( empty( $prefix ) ) { |
|
173 | + $prefix = md5( uniqid( 'wpinv' ) ); |
|
174 | + update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
175 | + } |
|
176 | + |
|
177 | + return $prefix; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'manual'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 11; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 11; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Process Payment. |
|
50 | - * |
|
51 | - * |
|
52 | - * @param WPInv_Invoice $invoice Invoice. |
|
53 | - * @param array $submission_data Posted checkout fields. |
|
54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
49 | + * Process Payment. |
|
50 | + * |
|
51 | + * |
|
52 | + * @param WPInv_Invoice $invoice Invoice. |
|
53 | + * @param array $submission_data Posted checkout fields. |
|
54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * (Maybe) renews a manual subscription profile. |
|
89 | - * |
|
90 | - * |
|
88 | + * (Maybe) renews a manual subscription profile. |
|
89 | + * |
|
90 | + * |
|
91 | 91 | * @param WPInv_Subscription $subscription |
92 | - */ |
|
93 | - public function maybe_renew_subscription( $subscription ) { |
|
92 | + */ |
|
93 | + public function maybe_renew_subscription( $subscription ) { |
|
94 | 94 | |
95 | 95 | // Ensure its our subscription && it's active. |
96 | 96 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Processes invoice addons. |
|
114 | - * |
|
115 | - * @param WPInv_Invoice $invoice |
|
116 | - * @param GetPaid_Form_Item[] $items |
|
117 | - * @return WPInv_Invoice |
|
118 | - */ |
|
119 | - public function process_addons( $invoice, $items ) { |
|
113 | + * Processes invoice addons. |
|
114 | + * |
|
115 | + * @param WPInv_Invoice $invoice |
|
116 | + * @param GetPaid_Form_Item[] $items |
|
117 | + * @return WPInv_Invoice |
|
118 | + */ |
|
119 | + public function process_addons( $invoice, $items ) { |
|
120 | 120 | |
121 | 121 | foreach ( $items as $item ) { |
122 | 122 | $invoice->add_item( $item ); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
12 | - exit; |
|
12 | + exit; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,356 +21,356 @@ discard block |
||
21 | 21 | */ |
22 | 22 | abstract class GetPaid_Data { |
23 | 23 | |
24 | - /** |
|
25 | - * ID for this object. |
|
26 | - * |
|
27 | - * @since 1.0.19 |
|
28 | - * @var int |
|
29 | - */ |
|
30 | - protected $id = 0; |
|
31 | - |
|
32 | - /** |
|
33 | - * Core data for this object. Name value pairs (name + default value). |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Core data changes for this object. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $changes = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * This is false until the object is read from the DB. |
|
50 | - * |
|
51 | - * @since 1.0.19 |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - protected $object_read = false; |
|
55 | - |
|
56 | - /** |
|
57 | - * This is the name of this object type. |
|
58 | - * |
|
59 | - * @since 1.0.19 |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $object_type = 'data'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Extra data for this object. Name value pairs (name + default value). |
|
66 | - * Used as a standard way for sub classes (like item types) to add |
|
67 | - * additional information to an inherited class. |
|
68 | - * |
|
69 | - * @since 1.0.19 |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $extra_data = array(); |
|
73 | - |
|
74 | - /** |
|
75 | - * Set to _data on construct so we can track and reset data if needed. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - protected $default_data = array(); |
|
81 | - |
|
82 | - /** |
|
83 | - * Contains a reference to the data store for this class. |
|
84 | - * |
|
85 | - * @since 1.0.19 |
|
86 | - * @var GetPaid_Data_Store |
|
87 | - */ |
|
88 | - protected $data_store; |
|
89 | - |
|
90 | - /** |
|
91 | - * Stores meta in cache for future reads. |
|
92 | - * A group must be set to to enable caching. |
|
93 | - * |
|
94 | - * @since 1.0.19 |
|
95 | - * @var string |
|
96 | - */ |
|
97 | - protected $cache_group = ''; |
|
98 | - |
|
99 | - /** |
|
100 | - * Stores the last error. |
|
101 | - * |
|
102 | - * @since 1.0.19 |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $last_error = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Stores additional meta data. |
|
109 | - * |
|
110 | - * @since 1.0.19 |
|
111 | - * @var array |
|
112 | - */ |
|
113 | - protected $meta_data = null; |
|
114 | - |
|
115 | - /** |
|
116 | - * Default constructor. |
|
117 | - * |
|
118 | - * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
119 | - */ |
|
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | - $this->default_data = $this->data; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Only store the object ID to avoid serializing the data object instance. |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function __sleep() { |
|
131 | - return array( 'id' ); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Re-run the constructor with the object ID. |
|
136 | - * |
|
137 | - * If the object no longer exists, remove the ID. |
|
138 | - */ |
|
139 | - public function __wakeup() { |
|
140 | - $this->__construct( absint( $this->id ) ); |
|
141 | - |
|
142 | - if ( ! empty( $this->last_error ) ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - } |
|
145 | - |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | - * |
|
151 | - * @since 1.0.19 |
|
152 | - */ |
|
153 | - public function __clone() { |
|
154 | - $this->maybe_read_meta_data(); |
|
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get the data store. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @return object |
|
170 | - */ |
|
171 | - public function get_data_store() { |
|
172 | - return $this->data_store; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get the object type. |
|
177 | - * |
|
178 | - * @since 1.0.19 |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function get_object_type() { |
|
182 | - return $this->object_type; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns the unique ID for this object. |
|
187 | - * |
|
188 | - * @since 1.0.19 |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function get_id() { |
|
192 | - return $this->id; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Get form status. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Delete an object, set the ID to 0, and return result. |
|
208 | - * |
|
209 | - * @since 1.0.19 |
|
210 | - * @param bool $force_delete Should the data be deleted permanently. |
|
211 | - * @return bool result |
|
212 | - */ |
|
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store && $this->exists() ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
217 | - return true; |
|
218 | - } |
|
219 | - return false; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Save should create or update based on object existence. |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @return int |
|
227 | - */ |
|
228 | - public function save() { |
|
229 | - if ( ! $this->data_store ) { |
|
230 | - return $this->get_id(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | - * |
|
236 | - * @param GetPaid_Data $this The object being saved. |
|
237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | - */ |
|
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | - |
|
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
243 | - } else { |
|
244 | - $this->data_store->create( $this ); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Trigger action after saving to the DB. |
|
249 | - * |
|
250 | - * @param GetPaid_Data $this The object being saved. |
|
251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | - */ |
|
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | - |
|
255 | - return $this->get_id(); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Change data to JSON format. |
|
260 | - * |
|
261 | - * @since 1.0.19 |
|
262 | - * @return string Data in JSON format. |
|
263 | - */ |
|
264 | - public function __toString() { |
|
265 | - return wp_json_encode( $this->get_data() ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Returns all data for this object. |
|
270 | - * |
|
271 | - * @since 1.0.19 |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - public function get_data() { |
|
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns array of expected data keys for this object. |
|
280 | - * |
|
281 | - * @since 1.0.19 |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function get_data_keys() { |
|
285 | - return array_keys( $this->data ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @return array |
|
293 | - */ |
|
294 | - public function get_extra_data_keys() { |
|
295 | - return array_keys( $this->extra_data ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Filter null meta values from array. |
|
300 | - * |
|
301 | - * @since 1.0.19 |
|
302 | - * @param mixed $meta Meta value to check. |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Get All Meta Data. |
|
311 | - * |
|
312 | - * @since 1.0.19 |
|
313 | - * @return array of objects. |
|
314 | - */ |
|
315 | - public function get_meta_data() { |
|
316 | - $this->maybe_read_meta_data(); |
|
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Check if the key is an internal one. |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * @param string $key Key to check. |
|
325 | - * @return bool true if it's an internal key, false otherwise |
|
326 | - */ |
|
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | - |
|
330 | - if ( ! $internal_meta_key ) { |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | - |
|
336 | - if ( ! $has_setter_or_getter ) { |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - /* translators: %s: $key Key to check */ |
|
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
342 | - |
|
343 | - return true; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Magic method for setting data fields. |
|
348 | - * |
|
349 | - * This method does not update custom fields in the database. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @access public |
|
353 | - * |
|
354 | - */ |
|
355 | - public function __set( $key, $value ) { |
|
356 | - |
|
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
359 | - } |
|
360 | - |
|
361 | - if ( method_exists( $this, "set_$key") ) { |
|
362 | - |
|
363 | - /* translators: %s: $key Key to set */ |
|
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
365 | - |
|
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | - } else { |
|
368 | - $this->set_prop( $key, $value ); |
|
369 | - } |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
24 | + /** |
|
25 | + * ID for this object. |
|
26 | + * |
|
27 | + * @since 1.0.19 |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + protected $id = 0; |
|
31 | + |
|
32 | + /** |
|
33 | + * Core data for this object. Name value pairs (name + default value). |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Core data changes for this object. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $changes = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * This is false until the object is read from the DB. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $object_read = false; |
|
55 | + |
|
56 | + /** |
|
57 | + * This is the name of this object type. |
|
58 | + * |
|
59 | + * @since 1.0.19 |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $object_type = 'data'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Extra data for this object. Name value pairs (name + default value). |
|
66 | + * Used as a standard way for sub classes (like item types) to add |
|
67 | + * additional information to an inherited class. |
|
68 | + * |
|
69 | + * @since 1.0.19 |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $extra_data = array(); |
|
73 | + |
|
74 | + /** |
|
75 | + * Set to _data on construct so we can track and reset data if needed. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $default_data = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * Contains a reference to the data store for this class. |
|
84 | + * |
|
85 | + * @since 1.0.19 |
|
86 | + * @var GetPaid_Data_Store |
|
87 | + */ |
|
88 | + protected $data_store; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores meta in cache for future reads. |
|
92 | + * A group must be set to to enable caching. |
|
93 | + * |
|
94 | + * @since 1.0.19 |
|
95 | + * @var string |
|
96 | + */ |
|
97 | + protected $cache_group = ''; |
|
98 | + |
|
99 | + /** |
|
100 | + * Stores the last error. |
|
101 | + * |
|
102 | + * @since 1.0.19 |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $last_error = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Stores additional meta data. |
|
109 | + * |
|
110 | + * @since 1.0.19 |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + protected $meta_data = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * Default constructor. |
|
117 | + * |
|
118 | + * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
119 | + */ |
|
120 | + public function __construct( $read = 0 ) { |
|
121 | + $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | + $this->default_data = $this->data; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Only store the object ID to avoid serializing the data object instance. |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function __sleep() { |
|
131 | + return array( 'id' ); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Re-run the constructor with the object ID. |
|
136 | + * |
|
137 | + * If the object no longer exists, remove the ID. |
|
138 | + */ |
|
139 | + public function __wakeup() { |
|
140 | + $this->__construct( absint( $this->id ) ); |
|
141 | + |
|
142 | + if ( ! empty( $this->last_error ) ) { |
|
143 | + $this->set_id( 0 ); |
|
144 | + } |
|
145 | + |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | + * |
|
151 | + * @since 1.0.19 |
|
152 | + */ |
|
153 | + public function __clone() { |
|
154 | + $this->maybe_read_meta_data(); |
|
155 | + if ( ! empty( $this->meta_data ) ) { |
|
156 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | + $this->meta_data[ $array_key ] = clone $meta; |
|
158 | + if ( ! empty( $meta->id ) ) { |
|
159 | + $this->meta_data[ $array_key ]->id = null; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get the data store. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @return object |
|
170 | + */ |
|
171 | + public function get_data_store() { |
|
172 | + return $this->data_store; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get the object type. |
|
177 | + * |
|
178 | + * @since 1.0.19 |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function get_object_type() { |
|
182 | + return $this->object_type; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns the unique ID for this object. |
|
187 | + * |
|
188 | + * @since 1.0.19 |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function get_id() { |
|
192 | + return $this->id; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Get form status. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_status( $context = 'view' ) { |
|
203 | + return $this->get_prop( 'status', $context ); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Delete an object, set the ID to 0, and return result. |
|
208 | + * |
|
209 | + * @since 1.0.19 |
|
210 | + * @param bool $force_delete Should the data be deleted permanently. |
|
211 | + * @return bool result |
|
212 | + */ |
|
213 | + public function delete( $force_delete = false ) { |
|
214 | + if ( $this->data_store && $this->exists() ) { |
|
215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | + $this->set_id( 0 ); |
|
217 | + return true; |
|
218 | + } |
|
219 | + return false; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Save should create or update based on object existence. |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @return int |
|
227 | + */ |
|
228 | + public function save() { |
|
229 | + if ( ! $this->data_store ) { |
|
230 | + return $this->get_id(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | + * |
|
236 | + * @param GetPaid_Data $this The object being saved. |
|
237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | + */ |
|
239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | + |
|
241 | + if ( $this->get_id() ) { |
|
242 | + $this->data_store->update( $this ); |
|
243 | + } else { |
|
244 | + $this->data_store->create( $this ); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Trigger action after saving to the DB. |
|
249 | + * |
|
250 | + * @param GetPaid_Data $this The object being saved. |
|
251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | + */ |
|
253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | + |
|
255 | + return $this->get_id(); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Change data to JSON format. |
|
260 | + * |
|
261 | + * @since 1.0.19 |
|
262 | + * @return string Data in JSON format. |
|
263 | + */ |
|
264 | + public function __toString() { |
|
265 | + return wp_json_encode( $this->get_data() ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Returns all data for this object. |
|
270 | + * |
|
271 | + * @since 1.0.19 |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + public function get_data() { |
|
275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns array of expected data keys for this object. |
|
280 | + * |
|
281 | + * @since 1.0.19 |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function get_data_keys() { |
|
285 | + return array_keys( $this->data ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @return array |
|
293 | + */ |
|
294 | + public function get_extra_data_keys() { |
|
295 | + return array_keys( $this->extra_data ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Filter null meta values from array. |
|
300 | + * |
|
301 | + * @since 1.0.19 |
|
302 | + * @param mixed $meta Meta value to check. |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + protected function filter_null_meta( $meta ) { |
|
306 | + return ! is_null( $meta->value ); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Get All Meta Data. |
|
311 | + * |
|
312 | + * @since 1.0.19 |
|
313 | + * @return array of objects. |
|
314 | + */ |
|
315 | + public function get_meta_data() { |
|
316 | + $this->maybe_read_meta_data(); |
|
317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Check if the key is an internal one. |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * @param string $key Key to check. |
|
325 | + * @return bool true if it's an internal key, false otherwise |
|
326 | + */ |
|
327 | + protected function is_internal_meta_key( $key ) { |
|
328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | + |
|
330 | + if ( ! $internal_meta_key ) { |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | + |
|
336 | + if ( ! $has_setter_or_getter ) { |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + /* translators: %s: $key Key to check */ |
|
341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
342 | + |
|
343 | + return true; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Magic method for setting data fields. |
|
348 | + * |
|
349 | + * This method does not update custom fields in the database. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @access public |
|
353 | + * |
|
354 | + */ |
|
355 | + public function __set( $key, $value ) { |
|
356 | + |
|
357 | + if ( 'id' == strtolower( $key ) ) { |
|
358 | + return $this->set_id( $value ); |
|
359 | + } |
|
360 | + |
|
361 | + if ( method_exists( $this, "set_$key") ) { |
|
362 | + |
|
363 | + /* translators: %s: $key Key to set */ |
|
364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
365 | + |
|
366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | + } else { |
|
368 | + $this->set_prop( $key, $value ); |
|
369 | + } |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | // Check if we have a helper method for that. |
379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
382 | - /* translators: %s: $key Key to set */ |
|
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
384 | - } |
|
381 | + if ( 'post_type' != $key ) { |
|
382 | + /* translators: %s: $key Key to set */ |
|
383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
384 | + } |
|
385 | 385 | |
386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
387 | 387 | } |
@@ -391,515 +391,515 @@ discard block |
||
391 | 391 | return $this->post->$key; |
392 | 392 | } |
393 | 393 | |
394 | - return $this->get_prop( $key ); |
|
395 | - |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Get Meta Data by Key. |
|
400 | - * |
|
401 | - * @since 1.0.19 |
|
402 | - * @param string $key Meta Key. |
|
403 | - * @param bool $single return first found meta with key, or all with $key. |
|
404 | - * @param string $context What the value is for. Valid values are view and edit. |
|
405 | - * @return mixed |
|
406 | - */ |
|
407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
408 | - |
|
409 | - // Check if this is an internal meta key. |
|
410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
413 | - $function = 'get_' . $_key; |
|
414 | - |
|
415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
416 | - return $this->{$function}(); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - // Read the meta data if not yet read. |
|
421 | - $this->maybe_read_meta_data(); |
|
422 | - $meta_data = $this->get_meta_data(); |
|
423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
424 | - $value = $single ? '' : array(); |
|
425 | - |
|
426 | - if ( ! empty( $array_keys ) ) { |
|
427 | - // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
428 | - if ( $single ) { |
|
429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
430 | - } else { |
|
431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - if ( 'view' === $context ) { |
|
436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
437 | - } |
|
438 | - |
|
439 | - return $value; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
444 | - * |
|
445 | - * @since 1.0.19 |
|
446 | - * @param string $key Meta Key. |
|
447 | - * @return boolean |
|
448 | - */ |
|
449 | - public function meta_exists( $key = '' ) { |
|
450 | - $this->maybe_read_meta_data(); |
|
451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | - return in_array( $key, $array_keys, true ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Set all meta data from array. |
|
457 | - * |
|
458 | - * @since 1.0.19 |
|
459 | - * @param array $data Key/Value pairs. |
|
460 | - */ |
|
461 | - public function set_meta_data( $data ) { |
|
462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
463 | - $this->maybe_read_meta_data(); |
|
464 | - foreach ( $data as $meta ) { |
|
465 | - $meta = (array) $meta; |
|
466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
467 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
468 | - array( |
|
469 | - 'id' => $meta['id'], |
|
470 | - 'key' => $meta['key'], |
|
471 | - 'value' => $meta['value'], |
|
472 | - ) |
|
473 | - ); |
|
474 | - } |
|
475 | - } |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Add meta data. |
|
481 | - * |
|
482 | - * @since 1.0.19 |
|
483 | - * |
|
484 | - * @param string $key Meta key. |
|
485 | - * @param string|array $value Meta value. |
|
486 | - * @param bool $unique Should this be a unique key?. |
|
487 | - */ |
|
488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
490 | - $function = 'set_' . $key; |
|
491 | - |
|
492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
493 | - return $this->{$function}( $value ); |
|
494 | - } |
|
495 | - } |
|
496 | - |
|
497 | - $this->maybe_read_meta_data(); |
|
498 | - if ( $unique ) { |
|
499 | - $this->delete_meta_data( $key ); |
|
500 | - } |
|
501 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
502 | - array( |
|
503 | - 'key' => $key, |
|
504 | - 'value' => $value, |
|
505 | - ) |
|
506 | - ); |
|
507 | - |
|
508 | - $this->save(); |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Update meta data by key or ID, if provided. |
|
513 | - * |
|
514 | - * @since 1.0.19 |
|
515 | - * |
|
516 | - * @param string $key Meta key. |
|
517 | - * @param string|array $value Meta value. |
|
518 | - * @param int $meta_id Meta ID. |
|
519 | - */ |
|
520 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
521 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
522 | - $function = 'set_' . $key; |
|
523 | - |
|
524 | - if ( is_callable( array( $this, $function ) ) ) { |
|
525 | - return $this->{$function}( $value ); |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - $this->maybe_read_meta_data(); |
|
530 | - |
|
531 | - $array_key = false; |
|
532 | - |
|
533 | - if ( $meta_id ) { |
|
534 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
535 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
536 | - } else { |
|
537 | - // Find matches by key. |
|
538 | - $matches = array(); |
|
539 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
540 | - if ( $meta->key === $key ) { |
|
541 | - $matches[] = $meta_data_array_key; |
|
542 | - } |
|
543 | - } |
|
544 | - |
|
545 | - if ( ! empty( $matches ) ) { |
|
546 | - // Set matches to null so only one key gets the new value. |
|
547 | - foreach ( $matches as $meta_data_array_key ) { |
|
548 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
549 | - } |
|
550 | - $array_key = current( $matches ); |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - if ( false !== $array_key ) { |
|
555 | - $meta = $this->meta_data[ $array_key ]; |
|
556 | - $meta->key = $key; |
|
557 | - $meta->value = $value; |
|
558 | - } else { |
|
559 | - $this->add_meta_data( $key, $value, true ); |
|
560 | - } |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Delete meta data. |
|
565 | - * |
|
566 | - * @since 1.0.19 |
|
567 | - * @param string $key Meta key. |
|
568 | - */ |
|
569 | - public function delete_meta_data( $key ) { |
|
570 | - $this->maybe_read_meta_data(); |
|
571 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
572 | - |
|
573 | - if ( $array_keys ) { |
|
574 | - foreach ( $array_keys as $array_key ) { |
|
575 | - $this->meta_data[ $array_key ]->value = null; |
|
576 | - } |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Delete meta data. |
|
582 | - * |
|
583 | - * @since 1.0.19 |
|
584 | - * @param int $mid Meta ID. |
|
585 | - */ |
|
586 | - public function delete_meta_data_by_mid( $mid ) { |
|
587 | - $this->maybe_read_meta_data(); |
|
588 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
589 | - |
|
590 | - if ( $array_keys ) { |
|
591 | - foreach ( $array_keys as $array_key ) { |
|
592 | - $this->meta_data[ $array_key ]->value = null; |
|
593 | - } |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Read meta data if null. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - */ |
|
602 | - protected function maybe_read_meta_data() { |
|
603 | - if ( is_null( $this->meta_data ) ) { |
|
604 | - $this->read_meta_data(); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Read Meta Data from the database. Ignore any internal properties. |
|
610 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
611 | - * |
|
612 | - * @since 1.0.19 |
|
613 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
614 | - */ |
|
615 | - public function read_meta_data( $force_read = false ) { |
|
616 | - |
|
617 | - // Reset meta data. |
|
618 | - $this->meta_data = array(); |
|
619 | - |
|
620 | - // Maybe abort early. |
|
621 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
622 | - return; |
|
623 | - } |
|
624 | - |
|
625 | - // Only read from cache if the cache key is set. |
|
626 | - $cache_key = null; |
|
627 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
628 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
629 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | - } |
|
631 | - |
|
632 | - // Should we force read? |
|
633 | - if ( empty( $raw_meta_data ) ) { |
|
634 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
635 | - |
|
636 | - if ( ! empty( $cache_key ) ) { |
|
637 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
638 | - } |
|
639 | - |
|
640 | - } |
|
641 | - |
|
642 | - // Set meta data. |
|
643 | - if ( is_array( $raw_meta_data ) ) { |
|
644 | - |
|
645 | - foreach ( $raw_meta_data as $meta ) { |
|
646 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
647 | - array( |
|
648 | - 'id' => (int) $meta->meta_id, |
|
649 | - 'key' => $meta->meta_key, |
|
650 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
651 | - ) |
|
652 | - ); |
|
653 | - } |
|
654 | - |
|
655 | - } |
|
656 | - |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Update Meta Data in the database. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - */ |
|
664 | - public function save_meta_data() { |
|
665 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
666 | - return; |
|
667 | - } |
|
668 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
669 | - if ( is_null( $meta->value ) ) { |
|
670 | - if ( ! empty( $meta->id ) ) { |
|
671 | - $this->data_store->delete_meta( $this, $meta ); |
|
672 | - unset( $this->meta_data[ $array_key ] ); |
|
673 | - } |
|
674 | - } elseif ( empty( $meta->id ) ) { |
|
675 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
676 | - $meta->apply_changes(); |
|
677 | - } else { |
|
678 | - if ( $meta->get_changes() ) { |
|
679 | - $this->data_store->update_meta( $this, $meta ); |
|
680 | - $meta->apply_changes(); |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - if ( ! empty( $this->cache_group ) ) { |
|
685 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
686 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Set ID. |
|
692 | - * |
|
693 | - * @since 1.0.19 |
|
694 | - * @param int $id ID. |
|
695 | - */ |
|
696 | - public function set_id( $id ) { |
|
697 | - $this->id = absint( $id ); |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Sets item status. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @param string $status New status. |
|
705 | - * @return array details of change. |
|
706 | - */ |
|
707 | - public function set_status( $status ) { |
|
394 | + return $this->get_prop( $key ); |
|
395 | + |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Get Meta Data by Key. |
|
400 | + * |
|
401 | + * @since 1.0.19 |
|
402 | + * @param string $key Meta Key. |
|
403 | + * @param bool $single return first found meta with key, or all with $key. |
|
404 | + * @param string $context What the value is for. Valid values are view and edit. |
|
405 | + * @return mixed |
|
406 | + */ |
|
407 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
408 | + |
|
409 | + // Check if this is an internal meta key. |
|
410 | + $_key = str_replace( '_wpinv', '', $key ); |
|
411 | + $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
413 | + $function = 'get_' . $_key; |
|
414 | + |
|
415 | + if ( is_callable( array( $this, $function ) ) ) { |
|
416 | + return $this->{$function}(); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + // Read the meta data if not yet read. |
|
421 | + $this->maybe_read_meta_data(); |
|
422 | + $meta_data = $this->get_meta_data(); |
|
423 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
424 | + $value = $single ? '' : array(); |
|
425 | + |
|
426 | + if ( ! empty( $array_keys ) ) { |
|
427 | + // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
428 | + if ( $single ) { |
|
429 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
430 | + } else { |
|
431 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + if ( 'view' === $context ) { |
|
436 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
437 | + } |
|
438 | + |
|
439 | + return $value; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
444 | + * |
|
445 | + * @since 1.0.19 |
|
446 | + * @param string $key Meta Key. |
|
447 | + * @return boolean |
|
448 | + */ |
|
449 | + public function meta_exists( $key = '' ) { |
|
450 | + $this->maybe_read_meta_data(); |
|
451 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | + return in_array( $key, $array_keys, true ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Set all meta data from array. |
|
457 | + * |
|
458 | + * @since 1.0.19 |
|
459 | + * @param array $data Key/Value pairs. |
|
460 | + */ |
|
461 | + public function set_meta_data( $data ) { |
|
462 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
463 | + $this->maybe_read_meta_data(); |
|
464 | + foreach ( $data as $meta ) { |
|
465 | + $meta = (array) $meta; |
|
466 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
467 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
468 | + array( |
|
469 | + 'id' => $meta['id'], |
|
470 | + 'key' => $meta['key'], |
|
471 | + 'value' => $meta['value'], |
|
472 | + ) |
|
473 | + ); |
|
474 | + } |
|
475 | + } |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Add meta data. |
|
481 | + * |
|
482 | + * @since 1.0.19 |
|
483 | + * |
|
484 | + * @param string $key Meta key. |
|
485 | + * @param string|array $value Meta value. |
|
486 | + * @param bool $unique Should this be a unique key?. |
|
487 | + */ |
|
488 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
490 | + $function = 'set_' . $key; |
|
491 | + |
|
492 | + if ( is_callable( array( $this, $function ) ) ) { |
|
493 | + return $this->{$function}( $value ); |
|
494 | + } |
|
495 | + } |
|
496 | + |
|
497 | + $this->maybe_read_meta_data(); |
|
498 | + if ( $unique ) { |
|
499 | + $this->delete_meta_data( $key ); |
|
500 | + } |
|
501 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
502 | + array( |
|
503 | + 'key' => $key, |
|
504 | + 'value' => $value, |
|
505 | + ) |
|
506 | + ); |
|
507 | + |
|
508 | + $this->save(); |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Update meta data by key or ID, if provided. |
|
513 | + * |
|
514 | + * @since 1.0.19 |
|
515 | + * |
|
516 | + * @param string $key Meta key. |
|
517 | + * @param string|array $value Meta value. |
|
518 | + * @param int $meta_id Meta ID. |
|
519 | + */ |
|
520 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
521 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
522 | + $function = 'set_' . $key; |
|
523 | + |
|
524 | + if ( is_callable( array( $this, $function ) ) ) { |
|
525 | + return $this->{$function}( $value ); |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + $this->maybe_read_meta_data(); |
|
530 | + |
|
531 | + $array_key = false; |
|
532 | + |
|
533 | + if ( $meta_id ) { |
|
534 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
535 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
536 | + } else { |
|
537 | + // Find matches by key. |
|
538 | + $matches = array(); |
|
539 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
540 | + if ( $meta->key === $key ) { |
|
541 | + $matches[] = $meta_data_array_key; |
|
542 | + } |
|
543 | + } |
|
544 | + |
|
545 | + if ( ! empty( $matches ) ) { |
|
546 | + // Set matches to null so only one key gets the new value. |
|
547 | + foreach ( $matches as $meta_data_array_key ) { |
|
548 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
549 | + } |
|
550 | + $array_key = current( $matches ); |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + if ( false !== $array_key ) { |
|
555 | + $meta = $this->meta_data[ $array_key ]; |
|
556 | + $meta->key = $key; |
|
557 | + $meta->value = $value; |
|
558 | + } else { |
|
559 | + $this->add_meta_data( $key, $value, true ); |
|
560 | + } |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Delete meta data. |
|
565 | + * |
|
566 | + * @since 1.0.19 |
|
567 | + * @param string $key Meta key. |
|
568 | + */ |
|
569 | + public function delete_meta_data( $key ) { |
|
570 | + $this->maybe_read_meta_data(); |
|
571 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
572 | + |
|
573 | + if ( $array_keys ) { |
|
574 | + foreach ( $array_keys as $array_key ) { |
|
575 | + $this->meta_data[ $array_key ]->value = null; |
|
576 | + } |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Delete meta data. |
|
582 | + * |
|
583 | + * @since 1.0.19 |
|
584 | + * @param int $mid Meta ID. |
|
585 | + */ |
|
586 | + public function delete_meta_data_by_mid( $mid ) { |
|
587 | + $this->maybe_read_meta_data(); |
|
588 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
589 | + |
|
590 | + if ( $array_keys ) { |
|
591 | + foreach ( $array_keys as $array_key ) { |
|
592 | + $this->meta_data[ $array_key ]->value = null; |
|
593 | + } |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Read meta data if null. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + */ |
|
602 | + protected function maybe_read_meta_data() { |
|
603 | + if ( is_null( $this->meta_data ) ) { |
|
604 | + $this->read_meta_data(); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Read Meta Data from the database. Ignore any internal properties. |
|
610 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
611 | + * |
|
612 | + * @since 1.0.19 |
|
613 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
614 | + */ |
|
615 | + public function read_meta_data( $force_read = false ) { |
|
616 | + |
|
617 | + // Reset meta data. |
|
618 | + $this->meta_data = array(); |
|
619 | + |
|
620 | + // Maybe abort early. |
|
621 | + if ( ! $this->get_id() || ! $this->data_store ) { |
|
622 | + return; |
|
623 | + } |
|
624 | + |
|
625 | + // Only read from cache if the cache key is set. |
|
626 | + $cache_key = null; |
|
627 | + if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
628 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
629 | + $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | + } |
|
631 | + |
|
632 | + // Should we force read? |
|
633 | + if ( empty( $raw_meta_data ) ) { |
|
634 | + $raw_meta_data = $this->data_store->read_meta( $this ); |
|
635 | + |
|
636 | + if ( ! empty( $cache_key ) ) { |
|
637 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
638 | + } |
|
639 | + |
|
640 | + } |
|
641 | + |
|
642 | + // Set meta data. |
|
643 | + if ( is_array( $raw_meta_data ) ) { |
|
644 | + |
|
645 | + foreach ( $raw_meta_data as $meta ) { |
|
646 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
647 | + array( |
|
648 | + 'id' => (int) $meta->meta_id, |
|
649 | + 'key' => $meta->meta_key, |
|
650 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
651 | + ) |
|
652 | + ); |
|
653 | + } |
|
654 | + |
|
655 | + } |
|
656 | + |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Update Meta Data in the database. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + */ |
|
664 | + public function save_meta_data() { |
|
665 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
666 | + return; |
|
667 | + } |
|
668 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
669 | + if ( is_null( $meta->value ) ) { |
|
670 | + if ( ! empty( $meta->id ) ) { |
|
671 | + $this->data_store->delete_meta( $this, $meta ); |
|
672 | + unset( $this->meta_data[ $array_key ] ); |
|
673 | + } |
|
674 | + } elseif ( empty( $meta->id ) ) { |
|
675 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
676 | + $meta->apply_changes(); |
|
677 | + } else { |
|
678 | + if ( $meta->get_changes() ) { |
|
679 | + $this->data_store->update_meta( $this, $meta ); |
|
680 | + $meta->apply_changes(); |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + if ( ! empty( $this->cache_group ) ) { |
|
685 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
686 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Set ID. |
|
692 | + * |
|
693 | + * @since 1.0.19 |
|
694 | + * @param int $id ID. |
|
695 | + */ |
|
696 | + public function set_id( $id ) { |
|
697 | + $this->id = absint( $id ); |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Sets item status. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @param string $status New status. |
|
705 | + * @return array details of change. |
|
706 | + */ |
|
707 | + public function set_status( $status ) { |
|
708 | 708 | $old_status = $this->get_status(); |
709 | 709 | |
710 | - $this->set_prop( 'status', $status ); |
|
711 | - |
|
712 | - return array( |
|
713 | - 'from' => $old_status, |
|
714 | - 'to' => $status, |
|
715 | - ); |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * Set all props to default values. |
|
720 | - * |
|
721 | - * @since 1.0.19 |
|
722 | - */ |
|
723 | - public function set_defaults() { |
|
724 | - $this->data = $this->default_data; |
|
725 | - $this->changes = array(); |
|
726 | - $this->set_object_read( false ); |
|
727 | - } |
|
728 | - |
|
729 | - /** |
|
730 | - * Set object read property. |
|
731 | - * |
|
732 | - * @since 1.0.19 |
|
733 | - * @param boolean $read Should read?. |
|
734 | - */ |
|
735 | - public function set_object_read( $read = true ) { |
|
736 | - $this->object_read = (bool) $read; |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Get object read property. |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - * @return boolean |
|
744 | - */ |
|
745 | - public function get_object_read() { |
|
746 | - return (bool) $this->object_read; |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
751 | - * Only sets using public methods. |
|
752 | - * |
|
753 | - * @since 1.0.19 |
|
754 | - * |
|
755 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
756 | - * @param string $context In what context to run this. |
|
757 | - * |
|
758 | - * @return bool|WP_Error |
|
759 | - */ |
|
760 | - public function set_props( $props, $context = 'set' ) { |
|
761 | - $errors = false; |
|
762 | - |
|
763 | - $props = wp_unslash( $props ); |
|
764 | - foreach ( $props as $prop => $value ) { |
|
765 | - try { |
|
766 | - /** |
|
767 | - * Checks if the prop being set is allowed, and the value is not null. |
|
768 | - */ |
|
769 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
770 | - continue; |
|
771 | - } |
|
772 | - $setter = "set_$prop"; |
|
773 | - |
|
774 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
775 | - $this->{$setter}( $value ); |
|
776 | - } |
|
777 | - } catch ( Exception $e ) { |
|
778 | - if ( ! $errors ) { |
|
779 | - $errors = new WP_Error(); |
|
780 | - } |
|
781 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
782 | - $this->last_error = $e->getMessage(); |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Sets a prop for a setter method. |
|
791 | - * |
|
792 | - * This stores changes in a special array so we can track what needs saving |
|
793 | - * the the DB later. |
|
794 | - * |
|
795 | - * @since 1.0.19 |
|
796 | - * @param string $prop Name of prop to set. |
|
797 | - * @param mixed $value Value of the prop. |
|
798 | - */ |
|
799 | - protected function set_prop( $prop, $value ) { |
|
800 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
801 | - if ( true === $this->object_read ) { |
|
802 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
803 | - $this->changes[ $prop ] = $value; |
|
804 | - } |
|
805 | - } else { |
|
806 | - $this->data[ $prop ] = $value; |
|
807 | - } |
|
808 | - } |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * Return data changes only. |
|
813 | - * |
|
814 | - * @since 1.0.19 |
|
815 | - * @return array |
|
816 | - */ |
|
817 | - public function get_changes() { |
|
818 | - return $this->changes; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Merge changes with data and clear. |
|
823 | - * |
|
824 | - * @since 1.0.19 |
|
825 | - */ |
|
826 | - public function apply_changes() { |
|
827 | - $this->data = array_replace( $this->data, $this->changes ); |
|
828 | - $this->changes = array(); |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * Prefix for action and filter hooks on data. |
|
833 | - * |
|
834 | - * @since 1.0.19 |
|
835 | - * @return string |
|
836 | - */ |
|
837 | - protected function get_hook_prefix() { |
|
838 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
839 | - } |
|
840 | - |
|
841 | - /** |
|
842 | - * Gets a prop for a getter method. |
|
843 | - * |
|
844 | - * Gets the value from either current pending changes, or the data itself. |
|
845 | - * Context controls what happens to the value before it's returned. |
|
846 | - * |
|
847 | - * @since 1.0.19 |
|
848 | - * @param string $prop Name of prop to get. |
|
849 | - * @param string $context What the value is for. Valid values are view and edit. |
|
850 | - * @return mixed |
|
851 | - */ |
|
852 | - protected function get_prop( $prop, $context = 'view' ) { |
|
853 | - $value = null; |
|
854 | - |
|
855 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
856 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
857 | - |
|
858 | - if ( 'view' === $context ) { |
|
859 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
860 | - } |
|
861 | - } |
|
862 | - |
|
863 | - return $value; |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
868 | - * |
|
869 | - * @since 1.0.19 |
|
870 | - * @param string $prop Name of prop to set. |
|
871 | - * @param string|integer $value Value of the prop. |
|
872 | - */ |
|
873 | - protected function set_date_prop( $prop, $value ) { |
|
874 | - |
|
875 | - if ( empty( $value ) ) { |
|
876 | - $this->set_prop( $prop, null ); |
|
877 | - return; |
|
878 | - } |
|
879 | - $this->set_prop( $prop, $value ); |
|
880 | - |
|
881 | - } |
|
882 | - |
|
883 | - /** |
|
884 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
885 | - * |
|
886 | - * @since 1.0.19 |
|
887 | - * @param string $code Error code. |
|
888 | - * @param string $message Error message. |
|
889 | - */ |
|
890 | - protected function error( $code, $message ) { |
|
891 | - $this->last_error = $message; |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Checks if the object is saved in the database |
|
896 | - * |
|
897 | - * @since 1.0.19 |
|
898 | - * @return bool |
|
899 | - */ |
|
900 | - public function exists() { |
|
901 | - $id = $this->get_id(); |
|
902 | - return ! empty( $id ); |
|
903 | - } |
|
710 | + $this->set_prop( 'status', $status ); |
|
711 | + |
|
712 | + return array( |
|
713 | + 'from' => $old_status, |
|
714 | + 'to' => $status, |
|
715 | + ); |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Set all props to default values. |
|
720 | + * |
|
721 | + * @since 1.0.19 |
|
722 | + */ |
|
723 | + public function set_defaults() { |
|
724 | + $this->data = $this->default_data; |
|
725 | + $this->changes = array(); |
|
726 | + $this->set_object_read( false ); |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * Set object read property. |
|
731 | + * |
|
732 | + * @since 1.0.19 |
|
733 | + * @param boolean $read Should read?. |
|
734 | + */ |
|
735 | + public function set_object_read( $read = true ) { |
|
736 | + $this->object_read = (bool) $read; |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Get object read property. |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + * @return boolean |
|
744 | + */ |
|
745 | + public function get_object_read() { |
|
746 | + return (bool) $this->object_read; |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
751 | + * Only sets using public methods. |
|
752 | + * |
|
753 | + * @since 1.0.19 |
|
754 | + * |
|
755 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
756 | + * @param string $context In what context to run this. |
|
757 | + * |
|
758 | + * @return bool|WP_Error |
|
759 | + */ |
|
760 | + public function set_props( $props, $context = 'set' ) { |
|
761 | + $errors = false; |
|
762 | + |
|
763 | + $props = wp_unslash( $props ); |
|
764 | + foreach ( $props as $prop => $value ) { |
|
765 | + try { |
|
766 | + /** |
|
767 | + * Checks if the prop being set is allowed, and the value is not null. |
|
768 | + */ |
|
769 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
770 | + continue; |
|
771 | + } |
|
772 | + $setter = "set_$prop"; |
|
773 | + |
|
774 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
775 | + $this->{$setter}( $value ); |
|
776 | + } |
|
777 | + } catch ( Exception $e ) { |
|
778 | + if ( ! $errors ) { |
|
779 | + $errors = new WP_Error(); |
|
780 | + } |
|
781 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
782 | + $this->last_error = $e->getMessage(); |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Sets a prop for a setter method. |
|
791 | + * |
|
792 | + * This stores changes in a special array so we can track what needs saving |
|
793 | + * the the DB later. |
|
794 | + * |
|
795 | + * @since 1.0.19 |
|
796 | + * @param string $prop Name of prop to set. |
|
797 | + * @param mixed $value Value of the prop. |
|
798 | + */ |
|
799 | + protected function set_prop( $prop, $value ) { |
|
800 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
801 | + if ( true === $this->object_read ) { |
|
802 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
803 | + $this->changes[ $prop ] = $value; |
|
804 | + } |
|
805 | + } else { |
|
806 | + $this->data[ $prop ] = $value; |
|
807 | + } |
|
808 | + } |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * Return data changes only. |
|
813 | + * |
|
814 | + * @since 1.0.19 |
|
815 | + * @return array |
|
816 | + */ |
|
817 | + public function get_changes() { |
|
818 | + return $this->changes; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Merge changes with data and clear. |
|
823 | + * |
|
824 | + * @since 1.0.19 |
|
825 | + */ |
|
826 | + public function apply_changes() { |
|
827 | + $this->data = array_replace( $this->data, $this->changes ); |
|
828 | + $this->changes = array(); |
|
829 | + } |
|
830 | + |
|
831 | + /** |
|
832 | + * Prefix for action and filter hooks on data. |
|
833 | + * |
|
834 | + * @since 1.0.19 |
|
835 | + * @return string |
|
836 | + */ |
|
837 | + protected function get_hook_prefix() { |
|
838 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
839 | + } |
|
840 | + |
|
841 | + /** |
|
842 | + * Gets a prop for a getter method. |
|
843 | + * |
|
844 | + * Gets the value from either current pending changes, or the data itself. |
|
845 | + * Context controls what happens to the value before it's returned. |
|
846 | + * |
|
847 | + * @since 1.0.19 |
|
848 | + * @param string $prop Name of prop to get. |
|
849 | + * @param string $context What the value is for. Valid values are view and edit. |
|
850 | + * @return mixed |
|
851 | + */ |
|
852 | + protected function get_prop( $prop, $context = 'view' ) { |
|
853 | + $value = null; |
|
854 | + |
|
855 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
856 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
857 | + |
|
858 | + if ( 'view' === $context ) { |
|
859 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
860 | + } |
|
861 | + } |
|
862 | + |
|
863 | + return $value; |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
868 | + * |
|
869 | + * @since 1.0.19 |
|
870 | + * @param string $prop Name of prop to set. |
|
871 | + * @param string|integer $value Value of the prop. |
|
872 | + */ |
|
873 | + protected function set_date_prop( $prop, $value ) { |
|
874 | + |
|
875 | + if ( empty( $value ) ) { |
|
876 | + $this->set_prop( $prop, null ); |
|
877 | + return; |
|
878 | + } |
|
879 | + $this->set_prop( $prop, $value ); |
|
880 | + |
|
881 | + } |
|
882 | + |
|
883 | + /** |
|
884 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
885 | + * |
|
886 | + * @since 1.0.19 |
|
887 | + * @param string $code Error code. |
|
888 | + * @param string $message Error message. |
|
889 | + */ |
|
890 | + protected function error( $code, $message ) { |
|
891 | + $this->last_error = $message; |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Checks if the object is saved in the database |
|
896 | + * |
|
897 | + * @since 1.0.19 |
|
898 | + * @return bool |
|
899 | + */ |
|
900 | + public function exists() { |
|
901 | + $id = $this->get_id(); |
|
902 | + return ! empty( $id ); |
|
903 | + } |
|
904 | 904 | |
905 | 905 | } |
@@ -13,300 +13,300 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | - ) |
|
37 | - ); |
|
38 | - |
|
39 | - $this->init_hooks(); |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | + ) |
|
37 | + ); |
|
38 | + |
|
39 | + $this->init_hooks(); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - // Abort in case the parent invoice does not exist. |
|
156 | - $invoice = $subscription->get_parent_invoice(); |
|
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
162 | - return; |
|
163 | - } |
|
164 | - |
|
165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
166 | - |
|
167 | - $recipients = $this->get_recipients( $invoice ); |
|
168 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
169 | - $merge_tags = $email->get_merge_tags(); |
|
170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
172 | - $attachments = $email->get_attachments(); |
|
173 | - |
|
174 | - $result = $mailer->send( |
|
175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
176 | - $subject, |
|
177 | - $content, |
|
178 | - $attachments |
|
179 | - ); |
|
180 | - |
|
181 | - // Maybe send a copy to the admin. |
|
182 | - if ( $email->include_admin_bcc() ) { |
|
183 | - $mailer->send( |
|
184 | - wpinv_get_admin_email(), |
|
185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
186 | - $content, |
|
187 | - $attachments |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - if ( $result ) { |
|
192 | - $invoice->add_system_note( |
|
193 | - sprintf( |
|
194 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
195 | - sanitize_key( $type ), |
|
196 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
197 | - ) |
|
198 | - ); |
|
199 | - } else { |
|
200 | - $invoice->add_system_note( |
|
201 | - sprintf( |
|
202 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
203 | - sanitize_key( $type ), |
|
204 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
210 | - |
|
211 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
212 | 67 | |
213 | 68 | /** |
214 | - * Sends a new trial notification. |
|
215 | - * |
|
216 | - * @param WPInv_Subscription $subscription |
|
217 | - */ |
|
218 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
219 | 75 | |
220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
222 | 82 | |
223 | - } |
|
83 | + return $merge_tags; |
|
224 | 84 | |
225 | - /** |
|
226 | - * Sends a cancelled subscription notification. |
|
227 | - * |
|
228 | - * @param WPInv_Subscription $subscription |
|
229 | - */ |
|
230 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
231 | 86 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
234 | 113 | |
235 | - } |
|
114 | + } |
|
236 | 115 | |
237 | - /** |
|
238 | - * Sends a subscription expired notification. |
|
239 | - * |
|
240 | - * @param WPInv_Subscription $subscription |
|
241 | - */ |
|
242 | - public function subscription_expired( $subscription ) { |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
243 | 125 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
246 | 134 | |
247 | - } |
|
135 | + $cc = $invoice->get_email_cc(); |
|
248 | 136 | |
249 | - /** |
|
250 | - * Sends a completed subscription notification. |
|
251 | - * |
|
252 | - * @param WPInv_Subscription $subscription |
|
253 | - */ |
|
254 | - public function subscription_complete( $subscription ) { |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
255 | 141 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
142 | + return $recipients; |
|
143 | + } |
|
258 | 144 | |
259 | - } |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + // Abort in case the parent invoice does not exist. |
|
156 | + $invoice = $subscription->get_parent_invoice(); |
|
157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
162 | + return; |
|
163 | + } |
|
164 | + |
|
165 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
166 | + |
|
167 | + $recipients = $this->get_recipients( $invoice ); |
|
168 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
169 | + $merge_tags = $email->get_merge_tags(); |
|
170 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
172 | + $attachments = $email->get_attachments(); |
|
173 | + |
|
174 | + $result = $mailer->send( |
|
175 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
176 | + $subject, |
|
177 | + $content, |
|
178 | + $attachments |
|
179 | + ); |
|
180 | + |
|
181 | + // Maybe send a copy to the admin. |
|
182 | + if ( $email->include_admin_bcc() ) { |
|
183 | + $mailer->send( |
|
184 | + wpinv_get_admin_email(), |
|
185 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
186 | + $content, |
|
187 | + $attachments |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + if ( $result ) { |
|
192 | + $invoice->add_system_note( |
|
193 | + sprintf( |
|
194 | + __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
195 | + sanitize_key( $type ), |
|
196 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
197 | + ) |
|
198 | + ); |
|
199 | + } else { |
|
200 | + $invoice->add_system_note( |
|
201 | + sprintf( |
|
202 | + __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
203 | + sanitize_key( $type ), |
|
204 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
260 | 210 | |
261 | - /** |
|
262 | - * Sends a subscription renewal reminder notification. |
|
263 | - * |
|
264 | - */ |
|
265 | - public function renewal_reminder() { |
|
211 | + } |
|
266 | 212 | |
267 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
213 | + /** |
|
214 | + * Sends a new trial notification. |
|
215 | + * |
|
216 | + * @param WPInv_Subscription $subscription |
|
217 | + */ |
|
218 | + public function subscription_trial( $subscription ) { |
|
268 | 219 | |
269 | - // Fetch reminder days. |
|
270 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
220 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
271 | 222 | |
272 | - // Abort if non is set. |
|
273 | - if ( empty( $reminder_days ) ) { |
|
274 | - return; |
|
275 | - } |
|
223 | + } |
|
276 | 224 | |
277 | - // Fetch matching subscriptions. |
|
225 | + /** |
|
226 | + * Sends a cancelled subscription notification. |
|
227 | + * |
|
228 | + * @param WPInv_Subscription $subscription |
|
229 | + */ |
|
230 | + public function subscription_cancelled( $subscription ) { |
|
231 | + |
|
232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Sends a subscription expired notification. |
|
239 | + * |
|
240 | + * @param WPInv_Subscription $subscription |
|
241 | + */ |
|
242 | + public function subscription_expired( $subscription ) { |
|
243 | + |
|
244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
246 | + |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Sends a completed subscription notification. |
|
251 | + * |
|
252 | + * @param WPInv_Subscription $subscription |
|
253 | + */ |
|
254 | + public function subscription_complete( $subscription ) { |
|
255 | + |
|
256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
258 | + |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Sends a subscription renewal reminder notification. |
|
263 | + * |
|
264 | + */ |
|
265 | + public function renewal_reminder() { |
|
266 | + |
|
267 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
268 | + |
|
269 | + // Fetch reminder days. |
|
270 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
271 | + |
|
272 | + // Abort if non is set. |
|
273 | + if ( empty( $reminder_days ) ) { |
|
274 | + return; |
|
275 | + } |
|
276 | + |
|
277 | + // Fetch matching subscriptions. |
|
278 | 278 | $args = array( |
279 | 279 | 'number' => -1, |
280 | - 'count_total' => false, |
|
281 | - 'status' => 'trialling active', |
|
280 | + 'count_total' => false, |
|
281 | + 'status' => 'trialling active', |
|
282 | 282 | 'date_expires_query' => array( |
283 | - 'relation' => 'OR' |
|
283 | + 'relation' => 'OR' |
|
284 | 284 | ), |
285 | - ); |
|
285 | + ); |
|
286 | 286 | |
287 | - foreach ( $reminder_days as $days ) { |
|
288 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
287 | + foreach ( $reminder_days as $days ) { |
|
288 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
289 | 289 | |
290 | - $args['date_expires_query'][] = array( |
|
291 | - 'year' => $date['year'], |
|
292 | - 'month' => $date['month'], |
|
293 | - 'day' => $date['day'], |
|
294 | - ); |
|
290 | + $args['date_expires_query'][] = array( |
|
291 | + 'year' => $date['year'], |
|
292 | + 'month' => $date['month'], |
|
293 | + 'day' => $date['day'], |
|
294 | + ); |
|
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
298 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
299 | 299 | |
300 | 300 | foreach ( $subscriptions as $subscription ) { |
301 | 301 | |
302 | - // Skip packages. |
|
303 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
304 | - $email->object = $subscription; |
|
305 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
306 | - } |
|
302 | + // Skip packages. |
|
303 | + if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
304 | + $email->object = $subscription; |
|
305 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
306 | + } |
|
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - } |
|
310 | + } |
|
311 | 311 | |
312 | 312 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | <?php if ( $tabs ){ ?> |
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | - } |
|
20 | - do_action( 'wpi_addons_tabs' ); |
|
21 | - ?> |
|
17 | + foreach ( $tabs as $name => $label ) { |
|
18 | + echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | + } |
|
20 | + do_action( 'wpi_addons_tabs' ); |
|
21 | + ?> |
|
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if($current_tab == 'membership'){ |
|
26 | + if($current_tab == 'membership'){ |
|
27 | 27 | |
28 | - ?> |
|
28 | + ?> |
|
29 | 29 | |
30 | 30 | <div class="wpi-membership-tab-conatiner"> |
31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | <h2><?php _e("Have a membership key?","invoicing");?></h2> |
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | - ?> |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | + ?> |
|
42 | 42 | </p> |
43 | 43 | <?php }?> |
44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
52 | - if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | - } |
|
56 | - } |
|
57 | - ?> |
|
51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
52 | + if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | + foreach ( $addons as $addon ) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | + } |
|
56 | + } |
|
57 | + ?> |
|
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | <h3><?php _e("Included Gateways:","invoicing");?></h3> |
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | - } |
|
72 | - } |
|
73 | - ?> |
|
68 | + if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | + foreach ( $addons as $addon ) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | + } |
|
72 | + } |
|
73 | + ?> |
|
74 | 74 | </ul> |
75 | 75 | </div> |
76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | - ?> |
|
84 | + echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | + ?> |
|
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | - ?> |
|
104 | + echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | + ?> |
|
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
108 | 108 | <p> |
@@ -126,21 +126,21 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | </div> |
128 | 128 | <?php |
129 | - }else{ |
|
130 | - $installed_plugins = get_plugins(); |
|
129 | + }else{ |
|
130 | + $installed_plugins = get_plugins(); |
|
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | - //print_r($addons); |
|
134 | - ?> |
|
132 | + if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | + //print_r($addons); |
|
134 | + ?> |
|
135 | 135 | <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
136 | 136 | if(965==$addon->info->id){continue;}// don't show quote add on |
137 | - ?><li class="wpi-product"> |
|
137 | + ?><li class="wpi-product"> |
|
138 | 138 | <div class="wpi-product-title"> |
139 | 139 | <h3><?php |
140 | - if ( ! empty( $addon->info->excerpt) ){ |
|
141 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
142 | - } |
|
143 | - echo esc_html( $addon->info->title ); ?></h3> |
|
140 | + if ( ! empty( $addon->info->excerpt) ){ |
|
141 | + echo wpi_help_tip( $addon->info->excerpt ); |
|
142 | + } |
|
143 | + echo esc_html( $addon->info->title ); ?></h3> |
|
144 | 144 | </div> |
145 | 145 | |
146 | 146 | <span class="wpi-product-image"> |
@@ -148,32 +148,32 @@ discard block |
||
148 | 148 | <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
149 | 149 | <?php endif; |
150 | 150 | |
151 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
152 | - $addon->info->slug = 'getpaid-stripe-payments'; |
|
153 | - $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
154 | - } |
|
155 | - |
|
156 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
157 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
158 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
159 | - echo '</a>'; |
|
160 | - }elseif(isset($addon->info->link) && ( substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com" || substr( $addon->info->link, 0, 21 ) === "https://wpgetpaid.com" ) ){ |
|
161 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
162 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpgetpaid.com&TB_iframe=true'); |
|
163 | - }else{ |
|
164 | - // if installed show activation link |
|
165 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
166 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
167 | - }else{ |
|
168 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
169 | - } |
|
170 | - } |
|
171 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
172 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
173 | - echo '</a>'; |
|
174 | - } |
|
175 | - |
|
176 | - ?> |
|
151 | + if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
152 | + $addon->info->slug = 'getpaid-stripe-payments'; |
|
153 | + $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
154 | + } |
|
155 | + |
|
156 | + if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
157 | + echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
158 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
159 | + echo '</a>'; |
|
160 | + }elseif(isset($addon->info->link) && ( substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com" || substr( $addon->info->link, 0, 21 ) === "https://wpgetpaid.com" ) ){ |
|
161 | + if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
162 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpgetpaid.com&TB_iframe=true'); |
|
163 | + }else{ |
|
164 | + // if installed show activation link |
|
165 | + if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
166 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
167 | + }else{ |
|
168 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
169 | + } |
|
170 | + } |
|
171 | + echo '<a href="'.$url.'" class="thickbox">'; |
|
172 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
173 | + echo '</a>'; |
|
174 | + } |
|
175 | + |
|
176 | + ?> |
|
177 | 177 | |
178 | 178 | </span> |
179 | 179 | |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | <span class="wpi-product-button"> |
182 | 182 | <?php |
183 | 183 | $addon_obj->output_button( $addon ); |
184 | - ?> |
|
184 | + ?> |
|
185 | 185 | </span> |
186 | 186 | |
187 | 187 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
188 | 188 | <?php endif; |
189 | - } |
|
189 | + } |
|
190 | 190 | |
191 | - } |
|
192 | - ?> |
|
191 | + } |
|
192 | + ?> |
|
193 | 193 | |
194 | 194 | |
195 | 195 | <div class="clearfix" ></div> |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
209 | 209 | <br> |
210 | 210 | <?php |
211 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
212 | - ?> |
|
211 | + echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
212 | + ?> |
|
213 | 213 | </span> |
214 | 214 | </div> |
215 | 215 |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option( 'default_country', 'UK' ); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters( 'wpinv_default_country', $country ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function wpinv_sanitize_country( $country ) { |
38 | 38 | |
39 | - // Enure the country is specified |
|
39 | + // Enure the country is specified |
|
40 | 40 | if ( empty( $country ) ) { |
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option( 'default_state', '' ); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters( 'wpinv_default_state', $state ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | function wpinv_state_name( $state_code = '', $country_code = '' ) { |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | |
306 | 306 | $country = wpinv_sanitize_country( $country ); |
307 | 307 | |
308 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
309 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
310 | - return $continent_code; |
|
311 | - } |
|
312 | - } |
|
308 | + foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
309 | + if ( false !== array_search( $country, $countries, true ) ) { |
|
310 | + return $continent_code; |
|
311 | + } |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return ''; |
315 | 315 | |
@@ -601,33 +601,33 @@ discard block |
||
601 | 601 | } |
602 | 602 | |
603 | 603 | function wpinv_get_states_field() { |
604 | - if( empty( $_POST['country'] ) ) { |
|
605 | - $_POST['country'] = wpinv_get_default_country(); |
|
606 | - } |
|
607 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
604 | + if( empty( $_POST['country'] ) ) { |
|
605 | + $_POST['country'] = wpinv_get_default_country(); |
|
606 | + } |
|
607 | + $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
608 | 608 | |
609 | - if( !empty( $states ) ) { |
|
610 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
609 | + if( !empty( $states ) ) { |
|
610 | + $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
611 | 611 | |
612 | 612 | $class = isset( $_POST['class'] ) ? esc_attr( $_POST['class'] ) : ''; |
613 | 613 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
614 | 614 | |
615 | 615 | $args = array( |
616 | - 'name' => $sanitized_field_name, |
|
617 | - 'id' => $sanitized_field_name, |
|
618 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
619 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
620 | - 'show_option_all' => false, |
|
621 | - 'show_option_none' => false |
|
622 | - ); |
|
623 | - |
|
624 | - $response = wpinv_html_select( $args ); |
|
625 | - |
|
626 | - } else { |
|
627 | - $response = 'nostates'; |
|
628 | - } |
|
616 | + 'name' => $sanitized_field_name, |
|
617 | + 'id' => $sanitized_field_name, |
|
618 | + 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
619 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
620 | + 'show_option_all' => false, |
|
621 | + 'show_option_none' => false |
|
622 | + ); |
|
623 | + |
|
624 | + $response = wpinv_html_select( $args ); |
|
625 | + |
|
626 | + } else { |
|
627 | + $response = 'nostates'; |
|
628 | + } |
|
629 | 629 | |
630 | - return $response; |
|
630 | + return $response; |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
@@ -645,46 +645,46 @@ discard block |
||
645 | 645 | */ |
646 | 646 | function wpinv_get_address_formats() { |
647 | 647 | |
648 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
649 | - array( |
|
650 | - 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
651 | - 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
652 | - 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | - 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | - 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
655 | - 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | - 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | - 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
658 | - 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
659 | - 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
660 | - 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
661 | - 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | - 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
663 | - 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
664 | - 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
665 | - 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
666 | - 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
667 | - 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
668 | - 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
669 | - 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
670 | - 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
671 | - 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | - 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | - 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
674 | - 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
675 | - 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | - 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
677 | - 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
678 | - 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
679 | - 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
680 | - 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
681 | - 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
682 | - 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
683 | - 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
684 | - 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
685 | - 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
686 | - ) |
|
687 | - ); |
|
648 | + return apply_filters( 'wpinv_localisation_address_formats', |
|
649 | + array( |
|
650 | + 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
651 | + 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
652 | + 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | + 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | + 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
655 | + 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | + 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | + 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
658 | + 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
659 | + 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
660 | + 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
661 | + 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | + 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
663 | + 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
664 | + 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
665 | + 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
666 | + 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
667 | + 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
668 | + 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
669 | + 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
670 | + 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
671 | + 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | + 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | + 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
674 | + 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
675 | + 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | + 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
677 | + 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
678 | + 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
679 | + 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
680 | + 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
681 | + 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
682 | + 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
683 | + 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
684 | + 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
685 | + 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
686 | + ) |
|
687 | + ); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | /** |
@@ -701,21 +701,21 @@ discard block |
||
701 | 701 | } |
702 | 702 | |
703 | 703 | // Get all formats. |
704 | - $formats = wpinv_get_address_formats(); |
|
704 | + $formats = wpinv_get_address_formats(); |
|
705 | 705 | |
706 | - // Get format for the specified country. |
|
707 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
706 | + // Get format for the specified country. |
|
707 | + $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
708 | 708 | |
709 | 709 | /** |
710 | - * Filters the address format to use on Invoices. |
|
710 | + * Filters the address format to use on Invoices. |
|
711 | 711 | * |
712 | 712 | * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
713 | - * |
|
714 | - * @since 1.0.13 |
|
715 | - * |
|
716 | - * @param string $format The address format to use. |
|
713 | + * |
|
714 | + * @since 1.0.13 |
|
715 | + * |
|
716 | + * @param string $format The address format to use. |
|
717 | 717 | * @param string $country The country who's address format is being retrieved. |
718 | - */ |
|
718 | + */ |
|
719 | 719 | return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
720 | 720 | } |
721 | 721 | |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | 'country' => '', |
737 | 737 | 'zip' => '', |
738 | 738 | 'first_name' => '', |
739 | - 'last_name' => '', |
|
740 | - 'company' => '', |
|
739 | + 'last_name' => '', |
|
740 | + 'company' => '', |
|
741 | 741 | ); |
742 | 742 | |
743 | 743 | $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
@@ -758,14 +758,14 @@ discard block |
||
758 | 758 | $args['country_code']= $country; |
759 | 759 | |
760 | 760 | /** |
761 | - * Filters the address format replacements to use on Invoices. |
|
761 | + * Filters the address format replacements to use on Invoices. |
|
762 | 762 | * |
763 | - * |
|
764 | - * @since 1.0.13 |
|
765 | - * |
|
766 | - * @param array $replacements The address replacements to use. |
|
763 | + * |
|
764 | + * @since 1.0.13 |
|
765 | + * |
|
766 | + * @param array $replacements The address replacements to use. |
|
767 | 767 | * @param array $billing_details The billing details to use. |
768 | - */ |
|
768 | + */ |
|
769 | 769 | $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
770 | 770 | |
771 | 771 | $return = array(); |
@@ -788,5 +788,5 @@ discard block |
||
788 | 788 | * @return string |
789 | 789 | */ |
790 | 790 | function wpinv_trim_formatted_address_line( $line ) { |
791 | - return trim( $line, ', ' ); |
|
791 | + return trim( $line, ', ' ); |
|
792 | 792 | } |
793 | 793 | \ No newline at end of file |
@@ -20,13 +20,13 @@ |
||
20 | 20 | <title><?php esc_html_e( 'GetPaid › Setup Wizard', 'invoicing' ); ?></title> |
21 | 21 | <?php |
22 | 22 | getpaid_admin()->enqeue_scripts(); |
23 | - wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' ); |
|
24 | - wp_print_styles( 'select2' ); |
|
23 | + wp_enqueue_style( 'font-awesome', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), 'v5.13.0' ); |
|
24 | + wp_print_styles( 'select2' ); |
|
25 | 25 | wp_print_scripts( 'select2' ); |
26 | - wp_print_scripts( 'wpinv-admin-script' ); |
|
26 | + wp_print_scripts( 'wpinv-admin-script' ); |
|
27 | 27 | do_action( 'admin_print_styles' ); |
28 | 28 | do_action( 'admin_head' ); |
29 | - ?> |
|
29 | + ?> |
|
30 | 30 | <style> |
31 | 31 | body, p{ |
32 | 32 | font-size: 16px; |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | 64 | } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | 'getpaid-nonce' |
92 | 92 | ) |
93 | 93 | ); |
94 | - $anchor = __( 'Delete', 'invoicing' ); |
|
95 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
94 | + $anchor = __( 'Delete', 'invoicing' ); |
|
95 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
96 | 96 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
97 | 97 | |
98 | 98 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -319,10 +319,10 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
322 | - * Output the metabox. |
|
323 | - * |
|
324 | - * @param WP_Post $post |
|
325 | - */ |
|
322 | + * Output the metabox. |
|
323 | + * |
|
324 | + * @param WP_Post $post |
|
325 | + */ |
|
326 | 326 | public static function output2( $post ) { |
327 | 327 | |
328 | 328 | // Prepare the invoice. |