@@ -37,7 +37,7 @@ |
||
37 | 37 | * |
38 | 38 | * Display admin bar when active |
39 | 39 | * |
40 | - * @return bool |
|
40 | + * @return false|null |
|
41 | 41 | */ |
42 | 42 | public function give_admin_bar_menu() { |
43 | 43 | global $wp_admin_bar; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | * @since 1.0 |
28 | 28 | */ |
29 | 29 | public function __construct() { |
30 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
31 | - add_action( 'give_dismiss_notices', array( $this, 'dismiss_notices' ) ); |
|
32 | - add_action( 'admin_bar_menu', array( $this, 'give_admin_bar_menu' ), 1000, 1 ); |
|
30 | + add_action('admin_notices', array($this, 'show_notices')); |
|
31 | + add_action('give_dismiss_notices', array($this, 'dismiss_notices')); |
|
32 | + add_action('admin_bar_menu', array($this, 'give_admin_bar_menu'), 1000, 1); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -40,20 +40,20 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - public function give_admin_bar_menu( $wp_admin_bar ) { |
|
43 | + public function give_admin_bar_menu($wp_admin_bar) { |
|
44 | 44 | |
45 | - if ( ! give_is_test_mode() || ! current_user_can( 'view_give_reports' ) ) { |
|
45 | + if ( ! give_is_test_mode() || ! current_user_can('view_give_reports')) { |
|
46 | 46 | return false; |
47 | 47 | } |
48 | 48 | |
49 | 49 | // Add the main siteadmin menu item. |
50 | - $wp_admin_bar->add_menu( array( |
|
50 | + $wp_admin_bar->add_menu(array( |
|
51 | 51 | 'id' => 'give-test-notice', |
52 | - 'href' => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways' ), |
|
52 | + 'href' => admin_url('edit.php?post_type=give_forms&page=give-settings&tab=gateways'), |
|
53 | 53 | 'parent' => 'top-secondary', |
54 | - 'title' => esc_html__( 'Give Test Mode Active', 'give' ), |
|
55 | - 'meta' => array( 'class' => 'give-test-mode-active' ), |
|
56 | - ) ); |
|
54 | + 'title' => esc_html__('Give Test Mode Active', 'give'), |
|
55 | + 'meta' => array('class' => 'give-test-mode-active'), |
|
56 | + )); |
|
57 | 57 | |
58 | 58 | } |
59 | 59 | |
@@ -68,116 +68,116 @@ discard block |
||
68 | 68 | 'error' => array(), |
69 | 69 | ); |
70 | 70 | |
71 | - if ( ! give_test_ajax_works() && ! get_user_meta( get_current_user_id(), '_give_admin_ajax_inaccessible_dismissed', true ) && current_user_can( 'manage_give_settings' ) ) { |
|
71 | + if ( ! give_test_ajax_works() && ! get_user_meta(get_current_user_id(), '_give_admin_ajax_inaccessible_dismissed', true) && current_user_can('manage_give_settings')) { |
|
72 | 72 | echo '<div class="error">'; |
73 | - echo '<p>' . esc_html__( 'Your site appears to be blocking the WordPress ajax interface. This may cause issues with Give.', 'give' ) . '</p>'; |
|
73 | + echo '<p>'.esc_html__('Your site appears to be blocking the WordPress ajax interface. This may cause issues with Give.', 'give').'</p>'; |
|
74 | 74 | /* translators: %s: https://givewp.com/documentation/core/troubleshooting/admin-ajax-blocked/ */ |
75 | - echo '<p>' . sprintf( __( 'Please see <a href="%s" target="_blank">this reference</a> for possible solutions.', 'give' ), esc_url( 'https://givewp.com/documentation/core/troubleshooting/admin-ajax-blocked/' ) ) . '</p>'; |
|
76 | - echo '<p><a href="' . add_query_arg( array( |
|
75 | + echo '<p>'.sprintf(__('Please see <a href="%s" target="_blank">this reference</a> for possible solutions.', 'give'), esc_url('https://givewp.com/documentation/core/troubleshooting/admin-ajax-blocked/')).'</p>'; |
|
76 | + echo '<p><a href="'.add_query_arg(array( |
|
77 | 77 | 'give_action' => 'dismiss_notices', |
78 | 78 | 'give_notice' => 'admin_ajax_inaccessible', |
79 | - ) ) . '">' . esc_html__( 'Dismiss Notice', 'give' ) . '</a></p>'; |
|
79 | + )).'">'.esc_html__('Dismiss Notice', 'give').'</a></p>'; |
|
80 | 80 | echo '</div>'; |
81 | 81 | } |
82 | 82 | |
83 | - if ( isset( $_GET['give-message'] ) ) { |
|
83 | + if (isset($_GET['give-message'])) { |
|
84 | 84 | |
85 | 85 | // Donation reports errors. |
86 | - if ( current_user_can( 'view_give_reports' ) ) { |
|
87 | - switch ( $_GET['give-message'] ) { |
|
86 | + if (current_user_can('view_give_reports')) { |
|
87 | + switch ($_GET['give-message']) { |
|
88 | 88 | case 'donation_deleted' : |
89 | - $notices['updated']['give-donation-deleted'] = esc_attr__( 'The donation has been deleted.', 'give' ); |
|
89 | + $notices['updated']['give-donation-deleted'] = esc_attr__('The donation has been deleted.', 'give'); |
|
90 | 90 | break; |
91 | 91 | case 'email_sent' : |
92 | - $notices['updated']['give-payment-sent'] = esc_attr__( 'The donation receipt has been resent.', 'give' ); |
|
92 | + $notices['updated']['give-payment-sent'] = esc_attr__('The donation receipt has been resent.', 'give'); |
|
93 | 93 | break; |
94 | 94 | case 'refreshed-reports' : |
95 | - $notices['updated']['give-refreshed-reports'] = esc_attr__( 'The reports cache has been cleared.', 'give' ); |
|
95 | + $notices['updated']['give-refreshed-reports'] = esc_attr__('The reports cache has been cleared.', 'give'); |
|
96 | 96 | break; |
97 | 97 | case 'donation-note-deleted' : |
98 | - $notices['updated']['give-donation-note-deleted'] = esc_attr__( 'The donation note has been deleted.', 'give' ); |
|
98 | + $notices['updated']['give-donation-note-deleted'] = esc_attr__('The donation note has been deleted.', 'give'); |
|
99 | 99 | break; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | 103 | // Give settings notices and errors. |
104 | - if ( current_user_can( 'manage_give_settings' ) ) { |
|
105 | - switch ( $_GET['give-message'] ) { |
|
104 | + if (current_user_can('manage_give_settings')) { |
|
105 | + switch ($_GET['give-message']) { |
|
106 | 106 | case 'settings-imported' : |
107 | - $notices['updated']['give-settings-imported'] = esc_attr__( 'The settings have been imported.', 'give' ); |
|
107 | + $notices['updated']['give-settings-imported'] = esc_attr__('The settings have been imported.', 'give'); |
|
108 | 108 | break; |
109 | 109 | case 'api-key-generated' : |
110 | - $notices['updated']['give-api-key-generated'] = esc_attr__( 'API keys have been generated.', 'give' ); |
|
110 | + $notices['updated']['give-api-key-generated'] = esc_attr__('API keys have been generated.', 'give'); |
|
111 | 111 | break; |
112 | 112 | case 'api-key-exists' : |
113 | - $notices['error']['give-api-key-exists'] = esc_attr__( 'The specified user already has API keys.', 'give' ); |
|
113 | + $notices['error']['give-api-key-exists'] = esc_attr__('The specified user already has API keys.', 'give'); |
|
114 | 114 | break; |
115 | 115 | case 'api-key-regenerated' : |
116 | - $notices['updated']['give-api-key-regenerated'] = esc_attr__( 'API keys have been regenerated.', 'give' ); |
|
116 | + $notices['updated']['give-api-key-regenerated'] = esc_attr__('API keys have been regenerated.', 'give'); |
|
117 | 117 | break; |
118 | 118 | case 'api-key-revoked' : |
119 | - $notices['updated']['give-api-key-revoked'] = esc_attr__( 'API keys have been revoked.', 'give' ); |
|
119 | + $notices['updated']['give-api-key-revoked'] = esc_attr__('API keys have been revoked.', 'give'); |
|
120 | 120 | break; |
121 | 121 | case 'sent-test-email' : |
122 | - $notices['updated']['give-sent-test-email'] = esc_attr__( 'The test email has been sent.', 'give' ); |
|
122 | + $notices['updated']['give-sent-test-email'] = esc_attr__('The test email has been sent.', 'give'); |
|
123 | 123 | break; |
124 | 124 | } |
125 | 125 | } |
126 | 126 | // Payments errors. |
127 | - if ( current_user_can( 'edit_give_payments' ) ) { |
|
128 | - switch ( $_GET['give-message'] ) { |
|
127 | + if (current_user_can('edit_give_payments')) { |
|
128 | + switch ($_GET['give-message']) { |
|
129 | 129 | case 'note-added' : |
130 | - $notices['updated']['give-note-added'] = esc_attr__( 'The donation note has been added.', 'give' ); |
|
130 | + $notices['updated']['give-note-added'] = esc_attr__('The donation note has been added.', 'give'); |
|
131 | 131 | break; |
132 | 132 | case 'payment-updated' : |
133 | - $notices['updated']['give-payment-updated'] = esc_attr__( 'The donation has been updated.', 'give' ); |
|
133 | + $notices['updated']['give-payment-updated'] = esc_attr__('The donation has been updated.', 'give'); |
|
134 | 134 | break; |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | 138 | // Customer Notices. |
139 | - if ( current_user_can( 'edit_give_payments' ) ) { |
|
140 | - switch ( $_GET['give-message'] ) { |
|
139 | + if (current_user_can('edit_give_payments')) { |
|
140 | + switch ($_GET['give-message']) { |
|
141 | 141 | case 'customer-deleted' : |
142 | - $notices['updated']['give-customer-deleted'] = esc_attr__( 'The donor has been deleted.', 'give' ); |
|
142 | + $notices['updated']['give-customer-deleted'] = esc_attr__('The donor has been deleted.', 'give'); |
|
143 | 143 | break; |
144 | 144 | |
145 | 145 | case 'email-added' : |
146 | - $notices['updated']['give-customer-email-added'] = esc_attr__( 'Donor email added', 'give' ); |
|
146 | + $notices['updated']['give-customer-email-added'] = esc_attr__('Donor email added', 'give'); |
|
147 | 147 | break; |
148 | 148 | |
149 | 149 | case 'email-removed' : |
150 | - $notices['updated']['give-customer-email-removed'] = esc_attr__( 'Donor email removed', 'give' ); |
|
150 | + $notices['updated']['give-customer-email-removed'] = esc_attr__('Donor email removed', 'give'); |
|
151 | 151 | break; |
152 | 152 | |
153 | 153 | case 'email-remove-failed' : |
154 | - $notices['error']['give-customer-email-remove-failed'] = esc_attr__( 'Failed to remove donor email', 'give' ); |
|
154 | + $notices['error']['give-customer-email-remove-failed'] = esc_attr__('Failed to remove donor email', 'give'); |
|
155 | 155 | break; |
156 | 156 | |
157 | 157 | case 'primary-email-updated' : |
158 | - $notices['updated']['give-customer-primary-email-updated'] = esc_attr__( 'Primary email updated for donors', 'give' ); |
|
158 | + $notices['updated']['give-customer-primary-email-updated'] = esc_attr__('Primary email updated for donors', 'give'); |
|
159 | 159 | break; |
160 | 160 | |
161 | 161 | case 'primary-email-failed' : |
162 | - $notices['error']['give-customer-primary-email-failed'] = esc_attr__( 'Failed to set primary email', 'give' ); |
|
162 | + $notices['error']['give-customer-primary-email-failed'] = esc_attr__('Failed to set primary email', 'give'); |
|
163 | 163 | |
164 | 164 | } |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - if ( count( $notices['updated'] ) > 0 ) { |
|
169 | - foreach ( $notices['updated'] as $notice => $message ) { |
|
170 | - add_settings_error( 'give-notices', $notice, $message, 'updated' ); |
|
168 | + if (count($notices['updated']) > 0) { |
|
169 | + foreach ($notices['updated'] as $notice => $message) { |
|
170 | + add_settings_error('give-notices', $notice, $message, 'updated'); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | - if ( count( $notices['error'] ) > 0 ) { |
|
175 | - foreach ( $notices['error'] as $notice => $message ) { |
|
176 | - add_settings_error( 'give-notices', $notice, $message, 'error' ); |
|
174 | + if (count($notices['error']) > 0) { |
|
175 | + foreach ($notices['error'] as $notice => $message) { |
|
176 | + add_settings_error('give-notices', $notice, $message, 'error'); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - settings_errors( 'give-notices' ); |
|
180 | + settings_errors('give-notices'); |
|
181 | 181 | |
182 | 182 | } |
183 | 183 | |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | * @return void |
190 | 190 | */ |
191 | 191 | function give_admin_addons_notices() { |
192 | - add_settings_error( 'give-notices', 'give-addons-feed-error', esc_attr__( 'There seems to be an issue with the server. Please try again in a few minutes.', 'give' ), 'error' ); |
|
193 | - settings_errors( 'give-notices' ); |
|
192 | + add_settings_error('give-notices', 'give-addons-feed-error', esc_attr__('There seems to be an issue with the server. Please try again in a few minutes.', 'give'), 'error'); |
|
193 | + settings_errors('give-notices'); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * @return void |
202 | 202 | */ |
203 | 203 | function dismiss_notices() { |
204 | - if ( isset( $_GET['give_notice'] ) ) { |
|
205 | - update_user_meta( get_current_user_id(), '_give_' . $_GET['give_notice'] . '_dismissed', 1 ); |
|
206 | - wp_redirect( remove_query_arg( array( 'give_action', 'give_notice' ) ) ); |
|
204 | + if (isset($_GET['give_notice'])) { |
|
205 | + update_user_meta(get_current_user_id(), '_give_'.$_GET['give_notice'].'_dismissed', 1); |
|
206 | + wp_redirect(remove_query_arg(array('give_action', 'give_notice'))); |
|
207 | 207 | exit; |
208 | 208 | } |
209 | 209 | } |
@@ -81,7 +81,6 @@ discard block |
||
81 | 81 | * @since 1.1 |
82 | 82 | * |
83 | 83 | * @param array $item Contains all the data of the keys |
84 | - * @param string $column_name The name of the column |
|
85 | 84 | * |
86 | 85 | * @return string Column Name |
87 | 86 | */ |
@@ -96,7 +95,6 @@ discard block |
||
96 | 95 | * @since 1.1 |
97 | 96 | * |
98 | 97 | * @param array $item Contains all the data of the keys |
99 | - * @param string $column_name The name of the column |
|
100 | 98 | * |
101 | 99 | * @return string Column Name |
102 | 100 | */ |
@@ -111,7 +109,6 @@ discard block |
||
111 | 109 | * @since 1.1 |
112 | 110 | * |
113 | 111 | * @param array $item Contains all the data of the keys |
114 | - * @param string $column_name The name of the column |
|
115 | 112 | * |
116 | 113 | * @return string Column Name |
117 | 114 | */ |
@@ -124,7 +121,7 @@ discard block |
||
124 | 121 | * |
125 | 122 | * @access public |
126 | 123 | * @since 1.1 |
127 | - * @return void |
|
124 | + * @return string |
|
128 | 125 | */ |
129 | 126 | public function column_user( $item ) { |
130 | 127 |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
17 | 17 | // Load WP_List_Table if not loaded |
18 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
19 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
18 | +if ( ! class_exists('WP_List_Table')) { |
|
19 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | global $status, $page; |
51 | 51 | |
52 | 52 | // Set parent defaults |
53 | - parent::__construct( array( |
|
54 | - 'singular' => esc_html__( 'API Key', 'give' ), // Singular name of the listed records |
|
55 | - 'plural' => esc_html__( 'API Keys', 'give' ), // Plural name of the listed records |
|
53 | + parent::__construct(array( |
|
54 | + 'singular' => esc_html__('API Key', 'give'), // Singular name of the listed records |
|
55 | + 'plural' => esc_html__('API Keys', 'give'), // Plural name of the listed records |
|
56 | 56 | 'ajax' => false // Does this table support ajax? |
57 | - ) ); |
|
57 | + )); |
|
58 | 58 | |
59 | 59 | $this->query(); |
60 | 60 | } |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return string Column Name |
72 | 72 | */ |
73 | - public function column_default( $item, $column_name ) { |
|
74 | - return $item[ $column_name ]; |
|
73 | + public function column_default($item, $column_name) { |
|
74 | + return $item[$column_name]; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return string Column Name |
87 | 87 | */ |
88 | - public function column_key( $item ) { |
|
89 | - return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['key'] ) . '"/>'; |
|
88 | + public function column_key($item) { |
|
89 | + return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['key']).'"/>'; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return string Column Name |
102 | 102 | */ |
103 | - public function column_token( $item ) { |
|
104 | - return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['token'] ) . '"/>'; |
|
103 | + public function column_token($item) { |
|
104 | + return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['token']).'"/>'; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return string Column Name |
117 | 117 | */ |
118 | - public function column_secret( $item ) { |
|
119 | - return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['secret'] ) . '"/>'; |
|
118 | + public function column_secret($item) { |
|
119 | + return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="'.esc_attr($item['secret']).'"/>'; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,46 +126,46 @@ discard block |
||
126 | 126 | * @since 1.1 |
127 | 127 | * @return void |
128 | 128 | */ |
129 | - public function column_user( $item ) { |
|
129 | + public function column_user($item) { |
|
130 | 130 | |
131 | 131 | $actions = array(); |
132 | 132 | |
133 | - if ( apply_filters( 'give_api_log_requests', true ) ) { |
|
133 | + if (apply_filters('give_api_log_requests', true)) { |
|
134 | 134 | $actions['view'] = sprintf( |
135 | 135 | '<a href="%s">%s</a>', |
136 | - esc_url( add_query_arg( array( |
|
136 | + esc_url(add_query_arg(array( |
|
137 | 137 | 'view' => 'api_requests', |
138 | 138 | 'post_type' => 'give_forms', |
139 | 139 | 'page' => 'give-reports', |
140 | 140 | 'tab' => 'logs', |
141 | 141 | 's' => $item['email'] |
142 | - ), 'edit.php' ) ), |
|
143 | - esc_html__( 'View API Log', 'give' ) |
|
142 | + ), 'edit.php')), |
|
143 | + esc_html__('View API Log', 'give') |
|
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
147 | 147 | $actions['reissue'] = sprintf( |
148 | 148 | '<a href="%s" class="give-regenerate-api-key">%s</a>', |
149 | - esc_url( wp_nonce_url( add_query_arg( array( |
|
149 | + esc_url(wp_nonce_url(add_query_arg(array( |
|
150 | 150 | 'user_id' => $item['id'], |
151 | 151 | 'give_action' => 'process_api_key', |
152 | 152 | 'give_api_process' => 'regenerate' |
153 | - ) ), 'give-api-nonce' ) ), |
|
154 | - esc_html__( 'Reissue', 'give' ) |
|
153 | + )), 'give-api-nonce')), |
|
154 | + esc_html__('Reissue', 'give') |
|
155 | 155 | ); |
156 | - $actions['revoke'] = sprintf( |
|
156 | + $actions['revoke'] = sprintf( |
|
157 | 157 | '<a href="%s" class="give-revoke-api-key give-delete">%s</a>', |
158 | - esc_url( wp_nonce_url( add_query_arg( array( |
|
158 | + esc_url(wp_nonce_url(add_query_arg(array( |
|
159 | 159 | 'user_id' => $item['id'], |
160 | 160 | 'give_action' => 'process_api_key', |
161 | 161 | 'give_api_process' => 'revoke' |
162 | - ) ), 'give-api-nonce' ) ), |
|
163 | - esc_html__( 'Revoke', 'give' ) |
|
162 | + )), 'give-api-nonce')), |
|
163 | + esc_html__('Revoke', 'give') |
|
164 | 164 | ); |
165 | 165 | |
166 | - $actions = apply_filters( 'give_api_row_actions', array_filter( $actions ) ); |
|
166 | + $actions = apply_filters('give_api_row_actions', array_filter($actions)); |
|
167 | 167 | |
168 | - return sprintf( '%1$s %2$s', $item['user'], $this->row_actions( $actions ) ); |
|
168 | + return sprintf('%1$s %2$s', $item['user'], $this->row_actions($actions)); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function get_columns() { |
179 | 179 | $columns = array( |
180 | - 'user' => esc_html__( 'Username', 'give' ), |
|
181 | - 'key' => esc_html__( 'Public Key', 'give' ), |
|
182 | - 'token' => esc_html__( 'Token', 'give' ), |
|
183 | - 'secret' => esc_html__( 'Secret Key', 'give' ) |
|
180 | + 'user' => esc_html__('Username', 'give'), |
|
181 | + 'key' => esc_html__('Public Key', 'give'), |
|
182 | + 'token' => esc_html__('Token', 'give'), |
|
183 | + 'secret' => esc_html__('Secret Key', 'give') |
|
184 | 184 | ); |
185 | 185 | |
186 | 186 | return $columns; |
@@ -193,20 +193,20 @@ discard block |
||
193 | 193 | * @access protected |
194 | 194 | * @param string $which |
195 | 195 | */ |
196 | - protected function display_tablenav( $which ) { |
|
197 | - if ( 'top' === $which ) { |
|
198 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
196 | + protected function display_tablenav($which) { |
|
197 | + if ('top' === $which) { |
|
198 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
199 | 199 | } |
200 | 200 | ?> |
201 | - <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
|
201 | + <div class="tablenav <?php echo esc_attr($which); ?>"> |
|
202 | 202 | |
203 | 203 | <div class="alignleft actions bulkactions"> |
204 | - <?php $this->bulk_actions( $which ); ?> |
|
204 | + <?php $this->bulk_actions($which); ?> |
|
205 | 205 | </div> |
206 | 206 | |
207 | 207 | <?php |
208 | - $this->extra_tablenav( $which ); |
|
209 | - $this->pagination( $which ); |
|
208 | + $this->extra_tablenav($which); |
|
209 | + $this->pagination($which); |
|
210 | 210 | ?> |
211 | 211 | |
212 | 212 | <br class="clear" /> |
@@ -222,19 +222,19 @@ discard block |
||
222 | 222 | * @param string $which |
223 | 223 | * @return void |
224 | 224 | */ |
225 | - function bulk_actions( $which = '' ) { |
|
225 | + function bulk_actions($which = '') { |
|
226 | 226 | // These aren't really bulk actions but this outputs the markup in the right place |
227 | 227 | static $give_api_is_bottom; |
228 | 228 | |
229 | - if ( $give_api_is_bottom ) { |
|
229 | + if ($give_api_is_bottom) { |
|
230 | 230 | return; |
231 | 231 | } |
232 | 232 | ?> |
233 | 233 | <input type="hidden" name="give_action" value="process_api_key"/> |
234 | 234 | <input type="hidden" name="give_api_process" value="generate"/> |
235 | - <?php wp_nonce_field( 'give-api-nonce' ); ?> |
|
235 | + <?php wp_nonce_field('give-api-nonce'); ?> |
|
236 | 236 | <?php echo Give()->html->ajax_user_search(); ?> |
237 | - <?php submit_button( esc_html__( 'Generate New API Keys', 'give' ), 'secondary', 'submit', false ); ?> |
|
237 | + <?php submit_button(esc_html__('Generate New API Keys', 'give'), 'secondary', 'submit', false); ?> |
|
238 | 238 | <?php |
239 | 239 | $give_api_is_bottom = true; |
240 | 240 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @return int Current page number |
248 | 248 | */ |
249 | 249 | public function get_paged() { |
250 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
250 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -258,21 +258,21 @@ discard block |
||
258 | 258 | * @return array |
259 | 259 | */ |
260 | 260 | public function query() { |
261 | - $users = get_users( array( |
|
261 | + $users = get_users(array( |
|
262 | 262 | 'meta_value' => 'give_user_secret_key', |
263 | 263 | 'number' => $this->per_page, |
264 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ) |
|
265 | - ) ); |
|
266 | - $keys = array(); |
|
267 | - |
|
268 | - foreach ( $users as $user ) { |
|
269 | - $keys[ $user->ID ]['id'] = $user->ID; |
|
270 | - $keys[ $user->ID ]['email'] = $user->user_email; |
|
271 | - $keys[ $user->ID ]['user'] = '<a href="' . add_query_arg( 'user_id', $user->ID, 'user-edit.php' ) . '"><strong>' . $user->user_login . '</strong></a>'; |
|
272 | - |
|
273 | - $keys[ $user->ID ]['key'] = Give()->api->get_user_public_key( $user->ID ); |
|
274 | - $keys[ $user->ID ]['secret'] = Give()->api->get_user_secret_key( $user->ID ); |
|
275 | - $keys[ $user->ID ]['token'] = Give()->api->get_token( $user->ID ); |
|
264 | + 'offset' => $this->per_page * ($this->get_paged() - 1) |
|
265 | + )); |
|
266 | + $keys = array(); |
|
267 | + |
|
268 | + foreach ($users as $user) { |
|
269 | + $keys[$user->ID]['id'] = $user->ID; |
|
270 | + $keys[$user->ID]['email'] = $user->user_email; |
|
271 | + $keys[$user->ID]['user'] = '<a href="'.add_query_arg('user_id', $user->ID, 'user-edit.php').'"><strong>'.$user->user_login.'</strong></a>'; |
|
272 | + |
|
273 | + $keys[$user->ID]['key'] = Give()->api->get_user_public_key($user->ID); |
|
274 | + $keys[$user->ID]['secret'] = Give()->api->get_user_secret_key($user->ID); |
|
275 | + $keys[$user->ID]['token'] = Give()->api->get_token($user->ID); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | return $keys; |
@@ -289,13 +289,13 @@ discard block |
||
289 | 289 | public function total_items() { |
290 | 290 | global $wpdb; |
291 | 291 | |
292 | - if ( ! get_transient( 'give_total_api_keys' ) ) { |
|
293 | - $total_items = $wpdb->get_var( "SELECT count(user_id) FROM $wpdb->usermeta WHERE meta_value='give_user_secret_key'" ); |
|
292 | + if ( ! get_transient('give_total_api_keys')) { |
|
293 | + $total_items = $wpdb->get_var("SELECT count(user_id) FROM $wpdb->usermeta WHERE meta_value='give_user_secret_key'"); |
|
294 | 294 | |
295 | - set_transient( 'give_total_api_keys', $total_items, 60 * 60 ); |
|
295 | + set_transient('give_total_api_keys', $total_items, 60 * 60); |
|
296 | 296 | } |
297 | 297 | |
298 | - return get_transient( 'give_total_api_keys' ); |
|
298 | + return get_transient('give_total_api_keys'); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | $hidden = array(); // No hidden columns |
312 | 312 | $sortable = array(); // Not sortable... for now |
313 | 313 | |
314 | - $this->_column_headers = array( $columns, $hidden, $sortable, 'id' ); |
|
314 | + $this->_column_headers = array($columns, $hidden, $sortable, 'id'); |
|
315 | 315 | |
316 | 316 | $data = $this->query(); |
317 | 317 | |
@@ -319,10 +319,10 @@ discard block |
||
319 | 319 | |
320 | 320 | $this->items = $data; |
321 | 321 | |
322 | - $this->set_pagination_args( array( |
|
322 | + $this->set_pagination_args(array( |
|
323 | 323 | 'total_items' => $total_items, |
324 | 324 | 'per_page' => $this->per_page, |
325 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
325 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
326 | 326 | ) |
327 | 327 | ); |
328 | 328 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | * @uses api_request() |
68 | 68 | * |
69 | 69 | * @param array $_transient_data Update array build by WordPress. |
70 | - * @return array Modified update array with custom plugin data. |
|
70 | + * @return stdClass Modified update array with custom plugin data. |
|
71 | 71 | */ |
72 | 72 | function check_update( $_transient_data ) { |
73 | 73 |
@@ -15,324 +15,324 @@ |
||
15 | 15 | * @version 1.6 |
16 | 16 | */ |
17 | 17 | class EDD_SL_Plugin_Updater { |
18 | - private $api_url = ''; |
|
19 | - private $api_data = array(); |
|
20 | - private $name = ''; |
|
21 | - private $slug = ''; |
|
22 | - |
|
23 | - /** |
|
24 | - * Class constructor. |
|
25 | - * |
|
26 | - * @param string $_api_url The URL pointing to the custom API endpoint. |
|
27 | - * @param string $_plugin_file Path to the plugin file. |
|
28 | - * @param array $_api_data Optional data to send with API calls. |
|
29 | - */ |
|
30 | - function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
31 | - $this->api_url = trailingslashit( $_api_url ); |
|
32 | - $this->api_data = $_api_data; |
|
33 | - $this->name = plugin_basename( $_plugin_file ); |
|
34 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
35 | - $this->version = $_api_data['version']; |
|
36 | - |
|
37 | - // Set up hooks. |
|
38 | - $this->init(); |
|
39 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Set up WordPress filters to hook into WP's update process. |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function init() { |
|
48 | - |
|
49 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
50 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
51 | - |
|
52 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Check for Updates at the defined API endpoint and modify the update array. |
|
57 | - * |
|
58 | - * This function dives into the update API just when WordPress creates its update array, |
|
59 | - * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
60 | - * It is reassembled from parts of the native WordPress plugin update code. |
|
61 | - * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
62 | - * |
|
63 | - * @uses api_request() |
|
18 | + private $api_url = ''; |
|
19 | + private $api_data = array(); |
|
20 | + private $name = ''; |
|
21 | + private $slug = ''; |
|
22 | + |
|
23 | + /** |
|
24 | + * Class constructor. |
|
25 | + * |
|
26 | + * @param string $_api_url The URL pointing to the custom API endpoint. |
|
27 | + * @param string $_plugin_file Path to the plugin file. |
|
28 | + * @param array $_api_data Optional data to send with API calls. |
|
29 | + */ |
|
30 | + function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
31 | + $this->api_url = trailingslashit( $_api_url ); |
|
32 | + $this->api_data = $_api_data; |
|
33 | + $this->name = plugin_basename( $_plugin_file ); |
|
34 | + $this->slug = basename( $_plugin_file, '.php' ); |
|
35 | + $this->version = $_api_data['version']; |
|
36 | + |
|
37 | + // Set up hooks. |
|
38 | + $this->init(); |
|
39 | + add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Set up WordPress filters to hook into WP's update process. |
|
64 | 44 | * |
65 | - * @param array $_transient_data Update array build by WordPress. |
|
66 | - * @return array Modified update array with custom plugin data. |
|
67 | - */ |
|
68 | - function check_update( $_transient_data ) { |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function init() { |
|
69 | 48 | |
70 | - $screen = get_current_screen(); |
|
49 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
50 | + add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
71 | 51 | |
72 | - if( ! is_object( $_transient_data ) ) { |
|
73 | - $_transient_data = new stdClass; |
|
74 | - } |
|
52 | + add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
53 | + } |
|
75 | 54 | |
76 | - if( is_object($screen) && 'plugins.php' == $screen->parent_file && is_multisite() ) { |
|
77 | - return $_transient_data; |
|
78 | - } |
|
55 | + /** |
|
56 | + * Check for Updates at the defined API endpoint and modify the update array. |
|
57 | + * |
|
58 | + * This function dives into the update API just when WordPress creates its update array, |
|
59 | + * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
60 | + * It is reassembled from parts of the native WordPress plugin update code. |
|
61 | + * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
62 | + * |
|
63 | + * @uses api_request() |
|
64 | + * |
|
65 | + * @param array $_transient_data Update array build by WordPress. |
|
66 | + * @return array Modified update array with custom plugin data. |
|
67 | + */ |
|
68 | + function check_update( $_transient_data ) { |
|
79 | 69 | |
80 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
70 | + $screen = get_current_screen(); |
|
81 | 71 | |
82 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
72 | + if( ! is_object( $_transient_data ) ) { |
|
73 | + $_transient_data = new stdClass; |
|
74 | + } |
|
83 | 75 | |
84 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
76 | + if( is_object($screen) && 'plugins.php' == $screen->parent_file && is_multisite() ) { |
|
77 | + return $_transient_data; |
|
78 | + } |
|
85 | 79 | |
86 | - $this->did_check = true; |
|
80 | + if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
87 | 81 | |
88 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
82 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
89 | 83 | |
90 | - $_transient_data->response[ $this->name ] = $version_info; |
|
84 | + if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
91 | 85 | |
92 | - } |
|
86 | + $this->did_check = true; |
|
93 | 87 | |
94 | - $_transient_data->last_checked = time(); |
|
95 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
88 | + if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
96 | 89 | |
97 | - } |
|
90 | + $_transient_data->response[ $this->name ] = $version_info; |
|
98 | 91 | |
99 | - } |
|
92 | + } |
|
100 | 93 | |
101 | - return $_transient_data; |
|
102 | - } |
|
94 | + $_transient_data->last_checked = time(); |
|
95 | + $_transient_data->checked[ $this->name ] = $this->version; |
|
103 | 96 | |
104 | - /** |
|
105 | - * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
|
106 | - * |
|
107 | - * @param string $file |
|
108 | - * @param array $plugin |
|
109 | - */ |
|
110 | - public function show_update_notification( $file, $plugin ) { |
|
97 | + } |
|
111 | 98 | |
112 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
113 | - return; |
|
114 | - } |
|
99 | + } |
|
100 | + |
|
101 | + return $_transient_data; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
|
106 | + * |
|
107 | + * @param string $file |
|
108 | + * @param array $plugin |
|
109 | + */ |
|
110 | + public function show_update_notification( $file, $plugin ) { |
|
111 | + |
|
112 | + if( ! current_user_can( 'update_plugins' ) ) { |
|
113 | + return; |
|
114 | + } |
|
115 | 115 | |
116 | - if( ! is_multisite() ) { |
|
117 | - return; |
|
118 | - } |
|
116 | + if( ! is_multisite() ) { |
|
117 | + return; |
|
118 | + } |
|
119 | 119 | |
120 | - if ( $this->name != $file ) { |
|
121 | - return; |
|
122 | - } |
|
120 | + if ( $this->name != $file ) { |
|
121 | + return; |
|
122 | + } |
|
123 | 123 | |
124 | - // Remove our filter on the site transient |
|
125 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
124 | + // Remove our filter on the site transient |
|
125 | + remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
126 | 126 | |
127 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
127 | + $update_cache = get_site_transient( 'update_plugins' ); |
|
128 | 128 | |
129 | - if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
129 | + if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
130 | 130 | |
131 | - $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
132 | - $version_info = get_transient( $cache_key ); |
|
131 | + $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
132 | + $version_info = get_transient( $cache_key ); |
|
133 | 133 | |
134 | - if( false === $version_info ) { |
|
134 | + if( false === $version_info ) { |
|
135 | 135 | |
136 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
136 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
137 | 137 | |
138 | - set_transient( $cache_key, $version_info, 3600 ); |
|
139 | - } |
|
138 | + set_transient( $cache_key, $version_info, 3600 ); |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | - if( ! is_object( $version_info ) ) { |
|
143 | - return; |
|
144 | - } |
|
142 | + if( ! is_object( $version_info ) ) { |
|
143 | + return; |
|
144 | + } |
|
145 | 145 | |
146 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
146 | + if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
147 | 147 | |
148 | - $update_cache->response[ $this->name ] = $version_info; |
|
148 | + $update_cache->response[ $this->name ] = $version_info; |
|
149 | 149 | |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | - $update_cache->last_checked = time(); |
|
153 | - $update_cache->checked[ $this->name ] = $this->version; |
|
152 | + $update_cache->last_checked = time(); |
|
153 | + $update_cache->checked[ $this->name ] = $this->version; |
|
154 | 154 | |
155 | - set_site_transient( 'update_plugins', $update_cache ); |
|
155 | + set_site_transient( 'update_plugins', $update_cache ); |
|
156 | 156 | |
157 | - } else { |
|
157 | + } else { |
|
158 | 158 | |
159 | - $version_info = $update_cache->response[ $this->name ]; |
|
159 | + $version_info = $update_cache->response[ $this->name ]; |
|
160 | 160 | |
161 | - } |
|
161 | + } |
|
162 | 162 | |
163 | - // Restore our filter |
|
164 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
163 | + // Restore our filter |
|
164 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
165 | 165 | |
166 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
166 | + if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
167 | 167 | |
168 | - // build a plugin list row, with update notification |
|
169 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
170 | - echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
168 | + // build a plugin list row, with update notification |
|
169 | + $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
170 | + echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
171 | 171 | |
172 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
172 | + $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
173 | 173 | |
174 | - if ( empty( $version_info->download_link ) ) { |
|
175 | - printf( |
|
174 | + if ( empty( $version_info->download_link ) ) { |
|
175 | + printf( |
|
176 | 176 | /* translators: 1: name 2: changelog URL 3: version */ |
177 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ), |
|
178 | - esc_html( $version_info->name ), |
|
179 | - esc_url( $changelog_link ), |
|
180 | - esc_html( $version_info->new_version ) |
|
181 | - ); |
|
182 | - } else { |
|
183 | - printf( |
|
177 | + __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ), |
|
178 | + esc_html( $version_info->name ), |
|
179 | + esc_url( $changelog_link ), |
|
180 | + esc_html( $version_info->new_version ) |
|
181 | + ); |
|
182 | + } else { |
|
183 | + printf( |
|
184 | 184 | /* translators: 1: name 2: changelog URL 3: version 4: update URL */ |
185 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'give' ), |
|
186 | - esc_html( $version_info->name ), |
|
187 | - esc_url( $changelog_link ), |
|
188 | - esc_html( $version_info->new_version ), |
|
189 | - esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - echo '</div></td></tr>'; |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Updates information on the "View version x.x details" page with custom data. |
|
200 | - * |
|
201 | - * @uses api_request() |
|
202 | - * |
|
203 | - * @param mixed $_data |
|
204 | - * @param string $_action |
|
205 | - * @param object $_args |
|
206 | - * @return object $_data |
|
207 | - */ |
|
208 | - function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
209 | - |
|
210 | - |
|
211 | - if ( $_action != 'plugin_information' ) { |
|
212 | - |
|
213 | - return $_data; |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
218 | - |
|
219 | - return $_data; |
|
220 | - |
|
221 | - } |
|
222 | - |
|
223 | - $to_send = array( |
|
224 | - 'slug' => $this->slug, |
|
225 | - 'is_ssl' => is_ssl(), |
|
226 | - 'fields' => array( |
|
227 | - 'banners' => false, // These will be supported soon hopefully |
|
228 | - 'reviews' => false |
|
229 | - ) |
|
230 | - ); |
|
231 | - |
|
232 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
233 | - |
|
234 | - if ( false !== $api_response ) { |
|
235 | - $_data = $api_response; |
|
236 | - } |
|
237 | - |
|
238 | - return $_data; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Disable SSL verification in order to prevent download update failures |
|
244 | - * |
|
245 | - * @param array $args |
|
246 | - * @param string $url |
|
247 | - * @return object $array |
|
248 | - */ |
|
249 | - function http_request_args( $args, $url ) { |
|
250 | - // If it is an https request and we are performing a package download, disable ssl verification |
|
251 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
252 | - $args['sslverify'] = false; |
|
253 | - } |
|
254 | - return $args; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Calls the API and, if successfull, returns the object delivered by the API. |
|
259 | - * |
|
260 | - * @uses get_bloginfo() |
|
261 | - * @uses wp_remote_post() |
|
262 | - * @uses is_wp_error() |
|
263 | - * |
|
264 | - * @param string $_action The requested action. |
|
265 | - * @param array $_data Parameters for the API action. |
|
266 | - * @return false||object |
|
267 | - */ |
|
268 | - private function api_request( $_action, $_data ) { |
|
269 | - |
|
270 | - $data = array_merge( $this->api_data, $_data ); |
|
271 | - |
|
272 | - if ( $data['slug'] != $this->slug ) { |
|
273 | - return; |
|
185 | + __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'give' ), |
|
186 | + esc_html( $version_info->name ), |
|
187 | + esc_url( $changelog_link ), |
|
188 | + esc_html( $version_info->new_version ), |
|
189 | + esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + echo '</div></td></tr>'; |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Updates information on the "View version x.x details" page with custom data. |
|
200 | + * |
|
201 | + * @uses api_request() |
|
202 | + * |
|
203 | + * @param mixed $_data |
|
204 | + * @param string $_action |
|
205 | + * @param object $_args |
|
206 | + * @return object $_data |
|
207 | + */ |
|
208 | + function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
209 | + |
|
210 | + |
|
211 | + if ( $_action != 'plugin_information' ) { |
|
212 | + |
|
213 | + return $_data; |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
218 | + |
|
219 | + return $_data; |
|
220 | + |
|
221 | + } |
|
222 | + |
|
223 | + $to_send = array( |
|
224 | + 'slug' => $this->slug, |
|
225 | + 'is_ssl' => is_ssl(), |
|
226 | + 'fields' => array( |
|
227 | + 'banners' => false, // These will be supported soon hopefully |
|
228 | + 'reviews' => false |
|
229 | + ) |
|
230 | + ); |
|
231 | + |
|
232 | + $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
233 | + |
|
234 | + if ( false !== $api_response ) { |
|
235 | + $_data = $api_response; |
|
236 | + } |
|
237 | + |
|
238 | + return $_data; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Disable SSL verification in order to prevent download update failures |
|
244 | + * |
|
245 | + * @param array $args |
|
246 | + * @param string $url |
|
247 | + * @return object $array |
|
248 | + */ |
|
249 | + function http_request_args( $args, $url ) { |
|
250 | + // If it is an https request and we are performing a package download, disable ssl verification |
|
251 | + if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
252 | + $args['sslverify'] = false; |
|
253 | + } |
|
254 | + return $args; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Calls the API and, if successfull, returns the object delivered by the API. |
|
259 | + * |
|
260 | + * @uses get_bloginfo() |
|
261 | + * @uses wp_remote_post() |
|
262 | + * @uses is_wp_error() |
|
263 | + * |
|
264 | + * @param string $_action The requested action. |
|
265 | + * @param array $_data Parameters for the API action. |
|
266 | + * @return false||object |
|
267 | + */ |
|
268 | + private function api_request( $_action, $_data ) { |
|
269 | + |
|
270 | + $data = array_merge( $this->api_data, $_data ); |
|
271 | + |
|
272 | + if ( $data['slug'] != $this->slug ) { |
|
273 | + return; |
|
274 | 274 | } |
275 | 275 | |
276 | - if ( empty( $data['license'] ) ) { |
|
277 | - return; |
|
276 | + if ( empty( $data['license'] ) ) { |
|
277 | + return; |
|
278 | 278 | } |
279 | 279 | |
280 | - if( $this->api_url == home_url() ) { |
|
281 | - return false; // Don't allow a plugin to ping itself |
|
282 | - } |
|
280 | + if( $this->api_url == home_url() ) { |
|
281 | + return false; // Don't allow a plugin to ping itself |
|
282 | + } |
|
283 | 283 | |
284 | - $api_params = array( |
|
285 | - 'edd_action' => 'get_version', |
|
286 | - 'license' => $data['license'], |
|
287 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
288 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
289 | - 'slug' => $data['slug'], |
|
290 | - 'author' => $data['author'], |
|
291 | - 'url' => home_url() |
|
292 | - ); |
|
284 | + $api_params = array( |
|
285 | + 'edd_action' => 'get_version', |
|
286 | + 'license' => $data['license'], |
|
287 | + 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
288 | + 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
289 | + 'slug' => $data['slug'], |
|
290 | + 'author' => $data['author'], |
|
291 | + 'url' => home_url() |
|
292 | + ); |
|
293 | 293 | |
294 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
294 | + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
295 | 295 | |
296 | - if ( ! is_wp_error( $request ) ) { |
|
297 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
298 | - } |
|
296 | + if ( ! is_wp_error( $request ) ) { |
|
297 | + $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
298 | + } |
|
299 | 299 | |
300 | - if ( $request && isset( $request->sections ) ) { |
|
301 | - $request->sections = maybe_unserialize( $request->sections ); |
|
302 | - } else { |
|
303 | - $request = false; |
|
304 | - } |
|
300 | + if ( $request && isset( $request->sections ) ) { |
|
301 | + $request->sections = maybe_unserialize( $request->sections ); |
|
302 | + } else { |
|
303 | + $request = false; |
|
304 | + } |
|
305 | 305 | |
306 | - return $request; |
|
307 | - } |
|
306 | + return $request; |
|
307 | + } |
|
308 | 308 | |
309 | - public function show_changelog() { |
|
309 | + public function show_changelog() { |
|
310 | 310 | |
311 | 311 | |
312 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
313 | - return; |
|
314 | - } |
|
312 | + if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
313 | + return; |
|
314 | + } |
|
315 | 315 | |
316 | - if( empty( $_REQUEST['plugin'] ) ) { |
|
317 | - return; |
|
318 | - } |
|
316 | + if( empty( $_REQUEST['plugin'] ) ) { |
|
317 | + return; |
|
318 | + } |
|
319 | 319 | |
320 | - if( empty( $_REQUEST['slug'] ) ) { |
|
321 | - return; |
|
322 | - } |
|
320 | + if( empty( $_REQUEST['slug'] ) ) { |
|
321 | + return; |
|
322 | + } |
|
323 | 323 | |
324 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
325 | - wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
326 | - } |
|
324 | + if( ! current_user_can( 'update_plugins' ) ) { |
|
325 | + wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
326 | + } |
|
327 | 327 | |
328 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
328 | + $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
329 | 329 | |
330 | - if( $response && isset( $response->sections['changelog'] ) ) { |
|
331 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
332 | - } |
|
330 | + if( $response && isset( $response->sections['changelog'] ) ) { |
|
331 | + echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
332 | + } |
|
333 | 333 | |
334 | 334 | |
335 | - exit; |
|
336 | - } |
|
335 | + exit; |
|
336 | + } |
|
337 | 337 | |
338 | 338 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | //set_site_transient( 'update_plugins', null ); |
5 | 5 | |
6 | 6 | // Exit if accessed directly. |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if ( ! defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | * @param string $_plugin_file Path to the plugin file. |
28 | 28 | * @param array $_api_data Optional data to send with API calls. |
29 | 29 | */ |
30 | - function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
31 | - $this->api_url = trailingslashit( $_api_url ); |
|
30 | + function __construct($_api_url, $_plugin_file, $_api_data = null) { |
|
31 | + $this->api_url = trailingslashit($_api_url); |
|
32 | 32 | $this->api_data = $_api_data; |
33 | - $this->name = plugin_basename( $_plugin_file ); |
|
34 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
33 | + $this->name = plugin_basename($_plugin_file); |
|
34 | + $this->slug = basename($_plugin_file, '.php'); |
|
35 | 35 | $this->version = $_api_data['version']; |
36 | 36 | |
37 | 37 | // Set up hooks. |
38 | 38 | $this->init(); |
39 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
39 | + add_action('admin_init', array($this, 'show_changelog')); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function init() { |
48 | 48 | |
49 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
50 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
49 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
50 | + add_filter('plugins_api', array($this, 'plugins_api_filter'), 10, 3); |
|
51 | 51 | |
52 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
52 | + add_action('after_plugin_row_'.$this->name, array($this, 'show_update_notification'), 10, 2); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -65,34 +65,34 @@ discard block |
||
65 | 65 | * @param array $_transient_data Update array build by WordPress. |
66 | 66 | * @return array Modified update array with custom plugin data. |
67 | 67 | */ |
68 | - function check_update( $_transient_data ) { |
|
68 | + function check_update($_transient_data) { |
|
69 | 69 | |
70 | 70 | $screen = get_current_screen(); |
71 | 71 | |
72 | - if( ! is_object( $_transient_data ) ) { |
|
72 | + if ( ! is_object($_transient_data)) { |
|
73 | 73 | $_transient_data = new stdClass; |
74 | 74 | } |
75 | 75 | |
76 | - if( is_object($screen) && 'plugins.php' == $screen->parent_file && is_multisite() ) { |
|
76 | + if (is_object($screen) && 'plugins.php' == $screen->parent_file && is_multisite()) { |
|
77 | 77 | return $_transient_data; |
78 | 78 | } |
79 | 79 | |
80 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
80 | + if (empty($_transient_data->response) || empty($_transient_data->response[$this->name])) { |
|
81 | 81 | |
82 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
82 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
83 | 83 | |
84 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
84 | + if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) { |
|
85 | 85 | |
86 | 86 | $this->did_check = true; |
87 | 87 | |
88 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
88 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
89 | 89 | |
90 | - $_transient_data->response[ $this->name ] = $version_info; |
|
90 | + $_transient_data->response[$this->name] = $version_info; |
|
91 | 91 | |
92 | 92 | } |
93 | 93 | |
94 | 94 | $_transient_data->last_checked = time(); |
95 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
95 | + $_transient_data->checked[$this->name] = $this->version; |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -107,86 +107,86 @@ discard block |
||
107 | 107 | * @param string $file |
108 | 108 | * @param array $plugin |
109 | 109 | */ |
110 | - public function show_update_notification( $file, $plugin ) { |
|
110 | + public function show_update_notification($file, $plugin) { |
|
111 | 111 | |
112 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
112 | + if ( ! current_user_can('update_plugins')) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | - if( ! is_multisite() ) { |
|
116 | + if ( ! is_multisite()) { |
|
117 | 117 | return; |
118 | 118 | } |
119 | 119 | |
120 | - if ( $this->name != $file ) { |
|
120 | + if ($this->name != $file) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | 124 | // Remove our filter on the site transient |
125 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
125 | + remove_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'), 10); |
|
126 | 126 | |
127 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
127 | + $update_cache = get_site_transient('update_plugins'); |
|
128 | 128 | |
129 | - if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
129 | + if ( ! is_object($update_cache) || empty($update_cache->response) || empty($update_cache->response[$this->name])) { |
|
130 | 130 | |
131 | - $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
132 | - $version_info = get_transient( $cache_key ); |
|
131 | + $cache_key = md5('edd_plugin_'.sanitize_key($this->name).'_version_info'); |
|
132 | + $version_info = get_transient($cache_key); |
|
133 | 133 | |
134 | - if( false === $version_info ) { |
|
134 | + if (false === $version_info) { |
|
135 | 135 | |
136 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
136 | + $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug)); |
|
137 | 137 | |
138 | - set_transient( $cache_key, $version_info, 3600 ); |
|
138 | + set_transient($cache_key, $version_info, 3600); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
142 | - if( ! is_object( $version_info ) ) { |
|
142 | + if ( ! is_object($version_info)) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
146 | + if (version_compare($this->version, $version_info->new_version, '<')) { |
|
147 | 147 | |
148 | - $update_cache->response[ $this->name ] = $version_info; |
|
148 | + $update_cache->response[$this->name] = $version_info; |
|
149 | 149 | |
150 | 150 | } |
151 | 151 | |
152 | 152 | $update_cache->last_checked = time(); |
153 | - $update_cache->checked[ $this->name ] = $this->version; |
|
153 | + $update_cache->checked[$this->name] = $this->version; |
|
154 | 154 | |
155 | - set_site_transient( 'update_plugins', $update_cache ); |
|
155 | + set_site_transient('update_plugins', $update_cache); |
|
156 | 156 | |
157 | 157 | } else { |
158 | 158 | |
159 | - $version_info = $update_cache->response[ $this->name ]; |
|
159 | + $version_info = $update_cache->response[$this->name]; |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Restore our filter |
164 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
164 | + add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update')); |
|
165 | 165 | |
166 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
166 | + if ( ! empty($update_cache->response[$this->name]) && version_compare($this->version, $version_info->new_version, '<')) { |
|
167 | 167 | |
168 | 168 | // build a plugin list row, with update notification |
169 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
170 | - echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
169 | + $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
170 | + echo '<tr class="plugin-update-tr"><td colspan="'.$wp_list_table->get_column_count().'" class="plugin-update colspanchange"><div class="update-message">'; |
|
171 | 171 | |
172 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
172 | + $changelog_link = self_admin_url('index.php?edd_sl_action=view_plugin_changelog&plugin='.$this->name.'&slug='.$this->slug.'&TB_iframe=true&width=772&height=911'); |
|
173 | 173 | |
174 | - if ( empty( $version_info->download_link ) ) { |
|
174 | + if (empty($version_info->download_link)) { |
|
175 | 175 | printf( |
176 | 176 | /* translators: 1: name 2: changelog URL 3: version */ |
177 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give' ), |
|
178 | - esc_html( $version_info->name ), |
|
179 | - esc_url( $changelog_link ), |
|
180 | - esc_html( $version_info->new_version ) |
|
177 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'give'), |
|
178 | + esc_html($version_info->name), |
|
179 | + esc_url($changelog_link), |
|
180 | + esc_html($version_info->new_version) |
|
181 | 181 | ); |
182 | 182 | } else { |
183 | 183 | printf( |
184 | 184 | /* translators: 1: name 2: changelog URL 3: version 4: update URL */ |
185 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'give' ), |
|
186 | - esc_html( $version_info->name ), |
|
187 | - esc_url( $changelog_link ), |
|
188 | - esc_html( $version_info->new_version ), |
|
189 | - esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
185 | + __('There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'give'), |
|
186 | + esc_html($version_info->name), |
|
187 | + esc_url($changelog_link), |
|
188 | + esc_html($version_info->new_version), |
|
189 | + esc_url(wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=').$this->name, 'upgrade-plugin_'.$this->name)) |
|
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
@@ -205,16 +205,16 @@ discard block |
||
205 | 205 | * @param object $_args |
206 | 206 | * @return object $_data |
207 | 207 | */ |
208 | - function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
208 | + function plugins_api_filter($_data, $_action = '', $_args = null) { |
|
209 | 209 | |
210 | 210 | |
211 | - if ( $_action != 'plugin_information' ) { |
|
211 | + if ($_action != 'plugin_information') { |
|
212 | 212 | |
213 | 213 | return $_data; |
214 | 214 | |
215 | 215 | } |
216 | 216 | |
217 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
217 | + if ( ! isset($_args->slug) || ($_args->slug != $this->slug)) { |
|
218 | 218 | |
219 | 219 | return $_data; |
220 | 220 | |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | ) |
230 | 230 | ); |
231 | 231 | |
232 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
232 | + $api_response = $this->api_request('plugin_information', $to_send); |
|
233 | 233 | |
234 | - if ( false !== $api_response ) { |
|
234 | + if (false !== $api_response) { |
|
235 | 235 | $_data = $api_response; |
236 | 236 | } |
237 | 237 | |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | * @param string $url |
247 | 247 | * @return object $array |
248 | 248 | */ |
249 | - function http_request_args( $args, $url ) { |
|
249 | + function http_request_args($args, $url) { |
|
250 | 250 | // If it is an https request and we are performing a package download, disable ssl verification |
251 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
251 | + if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) { |
|
252 | 252 | $args['sslverify'] = false; |
253 | 253 | } |
254 | 254 | return $args; |
@@ -265,40 +265,40 @@ discard block |
||
265 | 265 | * @param array $_data Parameters for the API action. |
266 | 266 | * @return false||object |
267 | 267 | */ |
268 | - private function api_request( $_action, $_data ) { |
|
268 | + private function api_request($_action, $_data) { |
|
269 | 269 | |
270 | - $data = array_merge( $this->api_data, $_data ); |
|
270 | + $data = array_merge($this->api_data, $_data); |
|
271 | 271 | |
272 | - if ( $data['slug'] != $this->slug ) { |
|
272 | + if ($data['slug'] != $this->slug) { |
|
273 | 273 | return; |
274 | 274 | } |
275 | 275 | |
276 | - if ( empty( $data['license'] ) ) { |
|
276 | + if (empty($data['license'])) { |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | |
280 | - if( $this->api_url == home_url() ) { |
|
280 | + if ($this->api_url == home_url()) { |
|
281 | 281 | return false; // Don't allow a plugin to ping itself |
282 | 282 | } |
283 | 283 | |
284 | 284 | $api_params = array( |
285 | 285 | 'edd_action' => 'get_version', |
286 | 286 | 'license' => $data['license'], |
287 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
288 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
287 | + 'item_name' => isset($data['item_name']) ? $data['item_name'] : false, |
|
288 | + 'item_id' => isset($data['item_id']) ? $data['item_id'] : false, |
|
289 | 289 | 'slug' => $data['slug'], |
290 | 290 | 'author' => $data['author'], |
291 | 291 | 'url' => home_url() |
292 | 292 | ); |
293 | 293 | |
294 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
294 | + $request = wp_remote_post($this->api_url, array('timeout' => 15, 'sslverify' => false, 'body' => $api_params)); |
|
295 | 295 | |
296 | - if ( ! is_wp_error( $request ) ) { |
|
297 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
296 | + if ( ! is_wp_error($request)) { |
|
297 | + $request = json_decode(wp_remote_retrieve_body($request)); |
|
298 | 298 | } |
299 | 299 | |
300 | - if ( $request && isset( $request->sections ) ) { |
|
301 | - $request->sections = maybe_unserialize( $request->sections ); |
|
300 | + if ($request && isset($request->sections)) { |
|
301 | + $request->sections = maybe_unserialize($request->sections); |
|
302 | 302 | } else { |
303 | 303 | $request = false; |
304 | 304 | } |
@@ -309,26 +309,26 @@ discard block |
||
309 | 309 | public function show_changelog() { |
310 | 310 | |
311 | 311 | |
312 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
312 | + if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action']) { |
|
313 | 313 | return; |
314 | 314 | } |
315 | 315 | |
316 | - if( empty( $_REQUEST['plugin'] ) ) { |
|
316 | + if (empty($_REQUEST['plugin'])) { |
|
317 | 317 | return; |
318 | 318 | } |
319 | 319 | |
320 | - if( empty( $_REQUEST['slug'] ) ) { |
|
320 | + if (empty($_REQUEST['slug'])) { |
|
321 | 321 | return; |
322 | 322 | } |
323 | 323 | |
324 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
325 | - wp_die( esc_html__( 'You do not have permission to install plugin updates.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
324 | + if ( ! current_user_can('update_plugins')) { |
|
325 | + wp_die(esc_html__('You do not have permission to install plugin updates.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
326 | 326 | } |
327 | 327 | |
328 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
328 | + $response = $this->api_request('plugin_latest_version', array('slug' => $_REQUEST['slug'])); |
|
329 | 329 | |
330 | - if( $response && isset( $response->sections['changelog'] ) ) { |
|
331 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
330 | + if ($response && isset($response->sections['changelog'])) { |
|
331 | + echo '<div style="background:#fff;padding:10px;">'.$response->sections['changelog'].'</div>'; |
|
332 | 332 | } |
333 | 333 | |
334 | 334 |
@@ -321,7 +321,7 @@ |
||
321 | 321 | * |
322 | 322 | * @param int $post_id Download (Post) ID |
323 | 323 | * |
324 | - * @return void |
|
324 | + * @return null|integer |
|
325 | 325 | */ |
326 | 326 | function give_price_save_quick_edit( $post_id ) { |
327 | 327 | if ( ! isset( $_POST['post_type'] ) || 'give_forms' !== $_POST['post_type'] ) { |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -27,34 +27,34 @@ discard block |
||
27 | 27 | * @return array $form_columns Updated array of forms columns |
28 | 28 | * Post Type List Table |
29 | 29 | */ |
30 | -function give_form_columns( $give_form_columns ) { |
|
30 | +function give_form_columns($give_form_columns) { |
|
31 | 31 | |
32 | 32 | //Standard columns |
33 | 33 | $give_form_columns = array( |
34 | 34 | 'cb' => '<input type="checkbox"/>', |
35 | - 'title' => esc_html__( 'Name', 'give' ), |
|
36 | - 'form_category' => esc_html__( 'Categories', 'give' ), |
|
37 | - 'form_tag' => esc_html__( 'Tags', 'give' ), |
|
38 | - 'price' => esc_html__( 'Amount', 'give' ), |
|
39 | - 'goal' => esc_html__( 'Goal', 'give' ), |
|
40 | - 'donations' => esc_html__( 'Donations', 'give' ), |
|
41 | - 'earnings' => esc_html__( 'Income', 'give' ), |
|
42 | - 'shortcode' => esc_html__( 'Shortcode', 'give' ), |
|
43 | - 'date' => esc_html__( 'Date', 'give' ), |
|
35 | + 'title' => esc_html__('Name', 'give'), |
|
36 | + 'form_category' => esc_html__('Categories', 'give'), |
|
37 | + 'form_tag' => esc_html__('Tags', 'give'), |
|
38 | + 'price' => esc_html__('Amount', 'give'), |
|
39 | + 'goal' => esc_html__('Goal', 'give'), |
|
40 | + 'donations' => esc_html__('Donations', 'give'), |
|
41 | + 'earnings' => esc_html__('Income', 'give'), |
|
42 | + 'shortcode' => esc_html__('Shortcode', 'give'), |
|
43 | + 'date' => esc_html__('Date', 'give'), |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | //Does the user want categories / tags? |
47 | - if ( give_get_option( 'enable_categories' ) !== 'on' ) { |
|
48 | - unset( $give_form_columns['form_category'] ); |
|
47 | + if (give_get_option('enable_categories') !== 'on') { |
|
48 | + unset($give_form_columns['form_category']); |
|
49 | 49 | } |
50 | - if ( give_get_option( 'enable_tags' ) !== 'on' ) { |
|
51 | - unset( $give_form_columns['form_tag'] ); |
|
50 | + if (give_get_option('enable_tags') !== 'on') { |
|
51 | + unset($give_form_columns['form_tag']); |
|
52 | 52 | } |
53 | 53 | |
54 | - return apply_filters( 'give_forms_columns', $give_form_columns ); |
|
54 | + return apply_filters('give_forms_columns', $give_form_columns); |
|
55 | 55 | } |
56 | 56 | |
57 | -add_filter( 'manage_edit-give_forms_columns', 'give_form_columns' ); |
|
57 | +add_filter('manage_edit-give_forms_columns', 'give_form_columns'); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Render Give Form Columns |
@@ -66,60 +66,60 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return void |
68 | 68 | */ |
69 | -function give_render_form_columns( $column_name, $post_id ) { |
|
70 | - if ( get_post_type( $post_id ) == 'give_forms' ) { |
|
69 | +function give_render_form_columns($column_name, $post_id) { |
|
70 | + if (get_post_type($post_id) == 'give_forms') { |
|
71 | 71 | |
72 | - switch ( $column_name ) { |
|
72 | + switch ($column_name) { |
|
73 | 73 | case 'form_category': |
74 | - echo get_the_term_list( $post_id, 'give_forms_category', '', ', ', '' ); |
|
74 | + echo get_the_term_list($post_id, 'give_forms_category', '', ', ', ''); |
|
75 | 75 | break; |
76 | 76 | case 'form_tag': |
77 | - echo get_the_term_list( $post_id, 'give_forms_tag', '', ', ', '' ); |
|
77 | + echo get_the_term_list($post_id, 'give_forms_tag', '', ', ', ''); |
|
78 | 78 | break; |
79 | 79 | case 'price': |
80 | - if ( give_has_variable_prices( $post_id ) ) { |
|
81 | - echo give_price_range( $post_id ); |
|
80 | + if (give_has_variable_prices($post_id)) { |
|
81 | + echo give_price_range($post_id); |
|
82 | 82 | } else { |
83 | - echo give_price( $post_id, false ); |
|
84 | - echo '<input type="hidden" class="formprice-' . $post_id . '" value="' . give_get_form_price( $post_id ) . '" />'; |
|
83 | + echo give_price($post_id, false); |
|
84 | + echo '<input type="hidden" class="formprice-'.$post_id.'" value="'.give_get_form_price($post_id).'" />'; |
|
85 | 85 | } |
86 | 86 | break; |
87 | 87 | case 'goal': |
88 | - $goal_option = get_post_meta( $post_id, '_give_goal_option', true ); |
|
89 | - if ( ! empty( $goal_option ) && $goal_option === 'yes' ) { |
|
90 | - echo give_goal( $post_id, false ); |
|
88 | + $goal_option = get_post_meta($post_id, '_give_goal_option', true); |
|
89 | + if ( ! empty($goal_option) && $goal_option === 'yes') { |
|
90 | + echo give_goal($post_id, false); |
|
91 | 91 | } else { |
92 | - esc_html_e( 'No Goal Set', 'give' ); |
|
92 | + esc_html_e('No Goal Set', 'give'); |
|
93 | 93 | } |
94 | 94 | |
95 | - echo '<input type="hidden" class="formgoal-' . $post_id . '" value="' . give_get_form_goal( $post_id ) . '" />'; |
|
95 | + echo '<input type="hidden" class="formgoal-'.$post_id.'" value="'.give_get_form_goal($post_id).'" />'; |
|
96 | 96 | break; |
97 | 97 | case 'donations': |
98 | - if ( current_user_can( 'view_give_form_stats', $post_id ) ) { |
|
99 | - echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-reports&tab=logs&view=sales&form=' . $post_id ) ) . '">'; |
|
100 | - echo give_get_form_sales_stats( $post_id ); |
|
98 | + if (current_user_can('view_give_form_stats', $post_id)) { |
|
99 | + echo '<a href="'.esc_url(admin_url('edit.php?post_type=give_forms&page=give-reports&tab=logs&view=sales&form='.$post_id)).'">'; |
|
100 | + echo give_get_form_sales_stats($post_id); |
|
101 | 101 | echo '</a>'; |
102 | 102 | } else { |
103 | 103 | echo '-'; |
104 | 104 | } |
105 | 105 | break; |
106 | 106 | case 'earnings': |
107 | - if ( current_user_can( 'view_give_form_stats', $post_id ) ) { |
|
108 | - echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-reports&view=forms&form-id=' . $post_id ) ) . '">'; |
|
109 | - echo give_currency_filter( give_format_amount( give_get_form_earnings_stats( $post_id ) ) ); |
|
107 | + if (current_user_can('view_give_form_stats', $post_id)) { |
|
108 | + echo '<a href="'.esc_url(admin_url('edit.php?post_type=give_forms&page=give-reports&view=forms&form-id='.$post_id)).'">'; |
|
109 | + echo give_currency_filter(give_format_amount(give_get_form_earnings_stats($post_id))); |
|
110 | 110 | echo '</a>'; |
111 | 111 | } else { |
112 | 112 | echo '-'; |
113 | 113 | } |
114 | 114 | break; |
115 | 115 | case 'shortcode': |
116 | - echo '<input onclick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly="" value="[give_form id="' . absint( $post_id ) . '"]">'; |
|
116 | + echo '<input onclick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly="" value="[give_form id="'.absint($post_id).'"]">'; |
|
117 | 117 | break; |
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | -add_action( 'manage_posts_custom_column', 'give_render_form_columns', 10, 2 ); |
|
122 | +add_action('manage_posts_custom_column', 'give_render_form_columns', 10, 2); |
|
123 | 123 | |
124 | 124 | /** |
125 | 125 | * Registers the sortable columns in the list table |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return array $columns Array of sortable columns |
132 | 132 | */ |
133 | -function give_sortable_form_columns( $columns ) { |
|
133 | +function give_sortable_form_columns($columns) { |
|
134 | 134 | $columns['price'] = 'amount'; |
135 | 135 | $columns['sales'] = 'sales'; |
136 | 136 | $columns['earnings'] = 'earnings'; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | return $columns; |
141 | 141 | } |
142 | 142 | |
143 | -add_filter( 'manage_edit-give_forms_sortable_columns', 'give_sortable_form_columns' ); |
|
143 | +add_filter('manage_edit-give_forms_sortable_columns', 'give_sortable_form_columns'); |
|
144 | 144 | |
145 | 145 | /** |
146 | 146 | * Sorts Columns in the Forms List Table |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @return array $vars Array of all the sort variables |
153 | 153 | */ |
154 | -function give_sort_forms( $vars ) { |
|
154 | +function give_sort_forms($vars) { |
|
155 | 155 | // Check if we're viewing the "give_forms" post type |
156 | - if ( ! isset( $vars['post_type'] ) || ! isset( $vars['orderby'] ) || 'give_forms' !== $vars['post_type'] ) { |
|
156 | + if ( ! isset($vars['post_type']) || ! isset($vars['orderby']) || 'give_forms' !== $vars['post_type']) { |
|
157 | 157 | return $vars; |
158 | 158 | } |
159 | 159 | |
160 | - switch ( $vars['orderby'] ) { |
|
160 | + switch ($vars['orderby']) { |
|
161 | 161 | // Check if 'orderby' is set to "sales" |
162 | 162 | case 'sales': |
163 | 163 | $vars = array_merge( |
@@ -226,16 +226,16 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return array Array of all sort variables |
228 | 228 | */ |
229 | -function give_filter_forms( $vars ) { |
|
230 | - if ( isset( $vars['post_type'] ) && 'give_forms' == $vars['post_type'] ) { |
|
229 | +function give_filter_forms($vars) { |
|
230 | + if (isset($vars['post_type']) && 'give_forms' == $vars['post_type']) { |
|
231 | 231 | |
232 | 232 | // If an author ID was passed, use it |
233 | - if ( isset( $_REQUEST['author'] ) && ! current_user_can( 'view_give_reports' ) ) { |
|
233 | + if (isset($_REQUEST['author']) && ! current_user_can('view_give_reports')) { |
|
234 | 234 | |
235 | 235 | $author_id = $_REQUEST['author']; |
236 | - if ( (int) $author_id !== get_current_user_id() ) { |
|
236 | + if ((int) $author_id !== get_current_user_id()) { |
|
237 | 237 | // Tried to view the products of another person, sorry |
238 | - wp_die( esc_html__( 'You do not have permission to view this data.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
238 | + wp_die(esc_html__('You do not have permission to view this data.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
239 | 239 | } |
240 | 240 | $vars = array_merge( |
241 | 241 | $vars, |
@@ -260,11 +260,11 @@ discard block |
||
260 | 260 | * @return void |
261 | 261 | */ |
262 | 262 | function give_forms_load() { |
263 | - add_filter( 'request', 'give_sort_forms' ); |
|
264 | - add_filter( 'request', 'give_filter_forms' ); |
|
263 | + add_filter('request', 'give_sort_forms'); |
|
264 | + add_filter('request', 'give_filter_forms'); |
|
265 | 265 | } |
266 | 266 | |
267 | -add_action( 'load-edit.php', 'give_forms_load', 9999 ); |
|
267 | +add_action('load-edit.php', 'give_forms_load', 9999); |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * Remove Forms Month Filter |
@@ -278,17 +278,17 @@ discard block |
||
278 | 278 | * @global $typenow The post type we are viewing |
279 | 279 | * @return array Empty array disables the dropdown |
280 | 280 | */ |
281 | -function give_remove_month_filter( $dates ) { |
|
281 | +function give_remove_month_filter($dates) { |
|
282 | 282 | global $typenow; |
283 | 283 | |
284 | - if ( $typenow == 'give_forms' ) { |
|
284 | + if ($typenow == 'give_forms') { |
|
285 | 285 | $dates = array(); |
286 | 286 | } |
287 | 287 | |
288 | 288 | return $dates; |
289 | 289 | } |
290 | 290 | |
291 | -add_filter( 'months_dropdown_results', 'give_remove_month_filter', 99 ); |
|
291 | +add_filter('months_dropdown_results', 'give_remove_month_filter', 99); |
|
292 | 292 | |
293 | 293 | /** |
294 | 294 | * Updates price when saving post |
@@ -299,23 +299,23 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @return void |
301 | 301 | */ |
302 | -function give_price_save_quick_edit( $post_id ) { |
|
303 | - if ( ! isset( $_POST['post_type'] ) || 'give_forms' !== $_POST['post_type'] ) { |
|
302 | +function give_price_save_quick_edit($post_id) { |
|
303 | + if ( ! isset($_POST['post_type']) || 'give_forms' !== $_POST['post_type']) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
306 | + if ( ! current_user_can('edit_post', $post_id)) { |
|
307 | 307 | return $post_id; |
308 | 308 | } |
309 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
309 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
310 | 310 | return $post_id; |
311 | 311 | } |
312 | 312 | |
313 | - if ( isset( $_REQUEST['_give_regprice'] ) ) { |
|
314 | - update_post_meta( $post_id, '_give_set_price', strip_tags( stripslashes( $_REQUEST['_give_regprice'] ) ) ); |
|
313 | + if (isset($_REQUEST['_give_regprice'])) { |
|
314 | + update_post_meta($post_id, '_give_set_price', strip_tags(stripslashes($_REQUEST['_give_regprice']))); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | -add_action( 'save_post', 'give_price_save_quick_edit' ); |
|
318 | +add_action('save_post', 'give_price_save_quick_edit'); |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * Process bulk edit actions via AJAX |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | */ |
326 | 326 | function give_save_bulk_edit() { |
327 | 327 | |
328 | - $post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : array(); |
|
328 | + $post_ids = (isset($_POST['post_ids']) && ! empty($_POST['post_ids'])) ? $_POST['post_ids'] : array(); |
|
329 | 329 | |
330 | - if ( ! empty( $post_ids ) && is_array( $post_ids ) ) { |
|
331 | - $price = isset( $_POST['price'] ) ? strip_tags( stripslashes( $_POST['price'] ) ) : 0; |
|
332 | - foreach ( $post_ids as $post_id ) { |
|
330 | + if ( ! empty($post_ids) && is_array($post_ids)) { |
|
331 | + $price = isset($_POST['price']) ? strip_tags(stripslashes($_POST['price'])) : 0; |
|
332 | + foreach ($post_ids as $post_id) { |
|
333 | 333 | |
334 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
334 | + if ( ! current_user_can('edit_post', $post_id)) { |
|
335 | 335 | continue; |
336 | 336 | } |
337 | 337 | |
338 | - if ( ! empty( $price ) ) { |
|
339 | - update_post_meta( $post_id, '_give_set_price', give_sanitize_amount( $price ) ); |
|
338 | + if ( ! empty($price)) { |
|
339 | + update_post_meta($post_id, '_give_set_price', give_sanitize_amount($price)); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | } |
@@ -344,4 +344,4 @@ discard block |
||
344 | 344 | die(); |
345 | 345 | } |
346 | 346 | |
347 | -add_action( 'wp_ajax_give_save_bulk_edit', 'give_save_bulk_edit' ); |
|
347 | +add_action('wp_ajax_give_save_bulk_edit', 'give_save_bulk_edit'); |
@@ -157,7 +157,7 @@ |
||
157 | 157 | * |
158 | 158 | * @access public |
159 | 159 | * @since 1.0 |
160 | - * @return mixed String if search is present, false otherwise |
|
160 | + * @return string|false String if search is present, false otherwise |
|
161 | 161 | */ |
162 | 162 | public function get_search() { |
163 | 163 | return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
17 | 17 | // Load WP_List_Table if not loaded |
18 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
19 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
18 | +if ( ! class_exists('WP_List_Table')) { |
|
19 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | global $status, $page; |
46 | 46 | |
47 | 47 | // Set parent defaults |
48 | - parent::__construct( array( |
|
49 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
50 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
48 | + parent::__construct(array( |
|
49 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
50 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
51 | 51 | 'ajax' => false // Does this table support ajax? |
52 | - ) ); |
|
52 | + )); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -63,20 +63,20 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - public function search_box( $text, $input_id ) { |
|
67 | - $input_id = $input_id . '-search-input'; |
|
66 | + public function search_box($text, $input_id) { |
|
67 | + $input_id = $input_id.'-search-input'; |
|
68 | 68 | |
69 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
70 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
69 | + if ( ! empty($_REQUEST['orderby'])) { |
|
70 | + echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />'; |
|
71 | 71 | } |
72 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
73 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
72 | + if ( ! empty($_REQUEST['order'])) { |
|
73 | + echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />'; |
|
74 | 74 | } |
75 | 75 | ?> |
76 | 76 | <p class="search-box"> |
77 | 77 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
78 | 78 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
79 | - <?php submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?> |
|
79 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?> |
|
80 | 80 | </p> |
81 | 81 | <?php |
82 | 82 | } |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function get_columns() { |
92 | 92 | $columns = array( |
93 | - 'ID' => esc_html__( 'Log ID', 'give' ), |
|
94 | - 'details' => esc_html__( 'Request Details', 'give' ), |
|
95 | - 'ip' => esc_html__( 'Request IP', 'give' ), |
|
96 | - 'date' => esc_html__( 'Date', 'give' ) |
|
93 | + 'ID' => esc_html__('Log ID', 'give'), |
|
94 | + 'details' => esc_html__('Request Details', 'give'), |
|
95 | + 'ip' => esc_html__('Request IP', 'give'), |
|
96 | + 'date' => esc_html__('Date', 'give') |
|
97 | 97 | ); |
98 | 98 | |
99 | 99 | return $columns; |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return string Column Name |
112 | 112 | */ |
113 | - public function column_default( $item, $column_name ) { |
|
114 | - switch ( $column_name ) { |
|
113 | + public function column_default($item, $column_name) { |
|
114 | + switch ($column_name) { |
|
115 | 115 | default: |
116 | - return $item[ $column_name ]; |
|
116 | + return $item[$column_name]; |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -127,26 +127,26 @@ discard block |
||
127 | 127 | * |
128 | 128 | * @return void |
129 | 129 | */ |
130 | - public function column_details( $item ) { |
|
130 | + public function column_details($item) { |
|
131 | 131 | ?> |
132 | - <a href="#TB_inline?width=640&inlineId=log-details-<?php echo $item['ID']; ?>" class="thickbox"><?php esc_html_e( 'View Request', 'give' ); ?></a> |
|
132 | + <a href="#TB_inline?width=640&inlineId=log-details-<?php echo $item['ID']; ?>" class="thickbox"><?php esc_html_e('View Request', 'give'); ?></a> |
|
133 | 133 | <div id="log-details-<?php echo $item['ID']; ?>" style="display:none;"> |
134 | 134 | <?php |
135 | 135 | |
136 | - $request = get_post_field( 'post_excerpt', $item['ID'] ); |
|
137 | - $error = get_post_field( 'post_content', $item['ID'] ); |
|
138 | - echo '<p><strong>' . esc_html__( 'API Request:', 'give' ) . '</strong></p>'; |
|
139 | - echo '<div>' . $request . '</div>'; |
|
140 | - if ( ! empty( $error ) ) { |
|
141 | - echo '<p><strong>' . esc_html__( 'Error', 'give' ) . '</strong></p>'; |
|
142 | - echo '<div>' . esc_html( $error ) . '</div>'; |
|
136 | + $request = get_post_field('post_excerpt', $item['ID']); |
|
137 | + $error = get_post_field('post_content', $item['ID']); |
|
138 | + echo '<p><strong>'.esc_html__('API Request:', 'give').'</strong></p>'; |
|
139 | + echo '<div>'.$request.'</div>'; |
|
140 | + if ( ! empty($error)) { |
|
141 | + echo '<p><strong>'.esc_html__('Error', 'give').'</strong></p>'; |
|
142 | + echo '<div>'.esc_html($error).'</div>'; |
|
143 | 143 | } |
144 | - echo '<p><strong>' . esc_html__( 'API User:', 'give' ) . '</strong></p>'; |
|
145 | - echo '<div>' . get_post_meta( $item['ID'], '_give_log_user', true ) . '</div>'; |
|
146 | - echo '<p><strong>' . esc_html__( 'API Key:', 'give' ) . '</strong></p>'; |
|
147 | - echo '<div>' . get_post_meta( $item['ID'], '_give_log_key', true ) . '</div>'; |
|
148 | - echo '<p><strong>' . esc_html__( 'Request Date:', 'give' ) . '</strong></p>'; |
|
149 | - echo '<div>' . get_post_field( 'post_date', $item['ID'] ) . '</div>'; |
|
144 | + echo '<p><strong>'.esc_html__('API User:', 'give').'</strong></p>'; |
|
145 | + echo '<div>'.get_post_meta($item['ID'], '_give_log_user', true).'</div>'; |
|
146 | + echo '<p><strong>'.esc_html__('API Key:', 'give').'</strong></p>'; |
|
147 | + echo '<div>'.get_post_meta($item['ID'], '_give_log_key', true).'</div>'; |
|
148 | + echo '<p><strong>'.esc_html__('Request Date:', 'give').'</strong></p>'; |
|
149 | + echo '<div>'.get_post_field('post_date', $item['ID']).'</div>'; |
|
150 | 150 | ?> |
151 | 151 | </div> |
152 | 152 | <?php |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @return mixed String if search is present, false otherwise |
161 | 161 | */ |
162 | 162 | public function get_search() { |
163 | - return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
|
163 | + return ! empty($_GET['s']) ? urldecode(trim($_GET['s'])) : false; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | |
@@ -176,19 +176,19 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @param string $which |
178 | 178 | */ |
179 | - protected function display_tablenav( $which ) { |
|
180 | - if ( 'top' === $which ) { |
|
181 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
179 | + protected function display_tablenav($which) { |
|
180 | + if ('top' === $which) { |
|
181 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
182 | 182 | } |
183 | 183 | ?> |
184 | - <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
|
184 | + <div class="tablenav <?php echo esc_attr($which); ?>"> |
|
185 | 185 | |
186 | 186 | <div class="alignleft actions bulkactions"> |
187 | - <?php $this->bulk_actions( $which ); ?> |
|
187 | + <?php $this->bulk_actions($which); ?> |
|
188 | 188 | </div> |
189 | 189 | <?php |
190 | - $this->extra_tablenav( $which ); |
|
191 | - $this->pagination( $which ); |
|
190 | + $this->extra_tablenav($which); |
|
191 | + $this->pagination($which); |
|
192 | 192 | ?> |
193 | 193 | |
194 | 194 | <br class="clear"/> |
@@ -210,31 +210,31 @@ discard block |
||
210 | 210 | |
211 | 211 | $search = $this->get_search(); |
212 | 212 | |
213 | - if ( $search ) { |
|
214 | - if ( filter_var( $search, FILTER_VALIDATE_IP ) ) { |
|
213 | + if ($search) { |
|
214 | + if (filter_var($search, FILTER_VALIDATE_IP)) { |
|
215 | 215 | // This is an IP address search |
216 | 216 | $key = '_give_log_request_ip'; |
217 | - } else if ( is_email( $search ) ) { |
|
217 | + } else if (is_email($search)) { |
|
218 | 218 | // This is an email search |
219 | - $userdata = get_user_by( 'email', $search ); |
|
219 | + $userdata = get_user_by('email', $search); |
|
220 | 220 | |
221 | - if ( $userdata ) { |
|
221 | + if ($userdata) { |
|
222 | 222 | $search = $userdata->ID; |
223 | 223 | } |
224 | 224 | |
225 | 225 | $key = '_give_log_user'; |
226 | - } elseif ( strlen( $search ) == 32 ) { |
|
226 | + } elseif (strlen($search) == 32) { |
|
227 | 227 | // Look for an API key |
228 | 228 | $key = '_give_log_key'; |
229 | - } elseif ( stristr( $search, 'token:' ) ) { |
|
229 | + } elseif (stristr($search, 'token:')) { |
|
230 | 230 | // Look for an API token |
231 | - $search = str_ireplace( 'token:', '', $search ); |
|
231 | + $search = str_ireplace('token:', '', $search); |
|
232 | 232 | $key = '_give_log_token'; |
233 | 233 | } else { |
234 | 234 | // This is (probably) a user ID search |
235 | - $userdata = get_userdata( $search ); |
|
235 | + $userdata = get_userdata($search); |
|
236 | 236 | |
237 | - if ( $userdata ) { |
|
237 | + if ($userdata) { |
|
238 | 238 | $search = $userdata->ID; |
239 | 239 | } |
240 | 240 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @return int Current page number |
261 | 261 | */ |
262 | 262 | public function get_paged() { |
263 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
263 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @since 1.0 |
271 | 271 | * @return void |
272 | 272 | */ |
273 | - function bulk_actions( $which = '' ) { |
|
273 | + function bulk_actions($which = '') { |
|
274 | 274 | give_log_views(); |
275 | 275 | } |
276 | 276 | |
@@ -293,14 +293,14 @@ discard block |
||
293 | 293 | 'meta_query' => $this->get_meta_query() |
294 | 294 | ); |
295 | 295 | |
296 | - $logs = $give_logs->get_connected_logs( $log_query ); |
|
296 | + $logs = $give_logs->get_connected_logs($log_query); |
|
297 | 297 | |
298 | - if ( $logs ) { |
|
299 | - foreach ( $logs as $log ) { |
|
298 | + if ($logs) { |
|
299 | + foreach ($logs as $log) { |
|
300 | 300 | |
301 | 301 | $logs_data[] = array( |
302 | 302 | 'ID' => $log->ID, |
303 | - 'ip' => get_post_meta( $log->ID, '_give_log_request_ip', true ), |
|
303 | + 'ip' => get_post_meta($log->ID, '_give_log_request_ip', true), |
|
304 | 304 | 'date' => $log->post_date |
305 | 305 | ); |
306 | 306 | } |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | $columns = $this->get_columns(); |
329 | 329 | $hidden = array(); // No hidden columns |
330 | 330 | $sortable = $this->get_sortable_columns(); |
331 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
331 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
332 | 332 | $this->items = $this->get_logs(); |
333 | - $total_items = $give_logs->get_log_count( 0, 'api_requests' ); |
|
333 | + $total_items = $give_logs->get_log_count(0, 'api_requests'); |
|
334 | 334 | |
335 | - $this->set_pagination_args( array( |
|
335 | + $this->set_pagination_args(array( |
|
336 | 336 | 'total_items' => $total_items, |
337 | 337 | 'per_page' => $this->per_page, |
338 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
338 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
339 | 339 | ) |
340 | 340 | ); |
341 | 341 | } |
@@ -143,7 +143,7 @@ |
||
143 | 143 | * |
144 | 144 | * @access public |
145 | 145 | * @since 1.0 |
146 | - * @return mixed string If search is present, false otherwise |
|
146 | + * @return string|false string If search is present, false otherwise |
|
147 | 147 | */ |
148 | 148 | public function get_search() { |
149 | 149 | return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
@@ -71,8 +71,8 @@ |
||
71 | 71 | |
72 | 72 | case 'user_id' : |
73 | 73 | return '<a href="' . |
74 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
75 | - '">' . $item['user_name'] . '</a>'; |
|
74 | + admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
75 | + '">' . $item['user_name'] . '</a>'; |
|
76 | 76 | |
77 | 77 | case 'amount' : |
78 | 78 | return give_currency_filter( give_format_amount( $item['amount'] ) ); |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | // Exit if accessed directly. |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
16 | 16 | // Load WP_List_Table if not loaded |
17 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
18 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
17 | +if ( ! class_exists('WP_List_Table')) { |
|
18 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | global $status, $page; |
45 | 45 | |
46 | 46 | // Set parent defaults |
47 | - parent::__construct( array( |
|
48 | - 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
49 | - 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
47 | + parent::__construct(array( |
|
48 | + 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
|
49 | + 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
|
50 | 50 | 'ajax' => false // Does this table support ajax? |
51 | - ) ); |
|
51 | + )); |
|
52 | 52 | |
53 | - add_action( 'give_log_view_actions', array( $this, 'give_forms_filter' ) ); |
|
53 | + add_action('give_log_view_actions', array($this, 'give_forms_filter')); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -64,37 +64,37 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return string Column Name |
66 | 66 | */ |
67 | - public function column_default( $item, $column_name ) { |
|
67 | + public function column_default($item, $column_name) { |
|
68 | 68 | |
69 | - $payment = give_get_payment_by( 'id', $item['payment_id'] ); |
|
69 | + $payment = give_get_payment_by('id', $item['payment_id']); |
|
70 | 70 | |
71 | - switch ( $column_name ) { |
|
71 | + switch ($column_name) { |
|
72 | 72 | case 'form' : |
73 | - return '<a href="' . esc_url( add_query_arg( 'form', $item[ $column_name ] ) ) . '" >' . get_the_title( $item[ $column_name ] ) . '</a>'; |
|
73 | + return '<a href="'.esc_url(add_query_arg('form', $item[$column_name])).'" >'.get_the_title($item[$column_name]).'</a>'; |
|
74 | 74 | |
75 | 75 | case 'user_id' : |
76 | - return '<a href="' . |
|
77 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
78 | - '">' . $item['user_name'] . '</a>'; |
|
76 | + return '<a href="'. |
|
77 | + admin_url('edit.php?post_type=give_forms&page=give-payment-history&user='.( ! empty($item['user_id']) ? urlencode($item['user_id']) : give_get_payment_user_email($item['payment_id']))). |
|
78 | + '">'.$item['user_name'].'</a>'; |
|
79 | 79 | |
80 | 80 | case 'amount' : |
81 | - return give_currency_filter( give_format_amount( $item['amount'] ) ); |
|
81 | + return give_currency_filter(give_format_amount($item['amount'])); |
|
82 | 82 | |
83 | 83 | case 'status' : |
84 | 84 | |
85 | - $value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>'; |
|
85 | + $value = '<div class="give-donation-status status-'.sanitize_title(give_get_payment_status($payment, true)).'"><span class="give-donation-status-icon"></span> '.give_get_payment_status($payment, true).'</div>'; |
|
86 | 86 | |
87 | - if ( $payment->mode == 'test' ) { |
|
88 | - $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="' . esc_attr__( 'This donation was made in test mode.', 'give' ) . '">' . esc_html__( 'Test', 'give' ) . '</span>'; |
|
87 | + if ($payment->mode == 'test') { |
|
88 | + $value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="'.esc_attr__('This donation was made in test mode.', 'give').'">'.esc_html__('Test', 'give').'</span>'; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | return $value; |
92 | 92 | |
93 | 93 | case 'payment_id' : |
94 | - return '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $item['payment_id'] ) . '">' . give_get_payment_number( $item['payment_id'] ) . '</a>'; |
|
94 | + return '<a href="'.admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id='.$item['payment_id']).'">'.give_get_payment_number($item['payment_id']).'</a>'; |
|
95 | 95 | |
96 | 96 | default: |
97 | - return $item[ $column_name ]; |
|
97 | + return $item[$column_name]; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function get_columns() { |
109 | 109 | $columns = array( |
110 | - 'ID' => esc_html__( 'Log ID', 'give' ), |
|
111 | - 'user_id' => esc_html__( 'Donor', 'give' ), |
|
112 | - 'form' => esc_html__( 'Form', 'give' ), |
|
113 | - 'amount' => esc_html__( 'Donation Amount', 'give' ), |
|
114 | - 'status' => esc_html__( 'Status', 'give' ), |
|
115 | - 'payment_id' => esc_html__( 'Transaction ID', 'give' ), |
|
116 | - 'date' => esc_html__( 'Date', 'give' ) |
|
110 | + 'ID' => esc_html__('Log ID', 'give'), |
|
111 | + 'user_id' => esc_html__('Donor', 'give'), |
|
112 | + 'form' => esc_html__('Form', 'give'), |
|
113 | + 'amount' => esc_html__('Donation Amount', 'give'), |
|
114 | + 'status' => esc_html__('Status', 'give'), |
|
115 | + 'payment_id' => esc_html__('Transaction ID', 'give'), |
|
116 | + 'date' => esc_html__('Date', 'give') |
|
117 | 117 | ); |
118 | 118 | |
119 | 119 | return $columns; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @return int Current page number |
128 | 128 | */ |
129 | 129 | public function get_paged() { |
130 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
130 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @return mixed int If User ID, string If Email/Login |
139 | 139 | */ |
140 | 140 | public function get_filtered_user() { |
141 | - return isset( $_GET['user'] ) ? absint( $_GET['user'] ) : false; |
|
141 | + return isset($_GET['user']) ? absint($_GET['user']) : false; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return int Download ID |
150 | 150 | */ |
151 | 151 | public function get_filtered_give_form() { |
152 | - return ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : false; |
|
152 | + return ! empty($_GET['form']) ? absint($_GET['form']) : false; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @return mixed string If search is present, false otherwise |
161 | 161 | */ |
162 | 162 | public function get_search() { |
163 | - return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
|
163 | + return ! empty($_GET['s']) ? urldecode(trim($_GET['s'])) : false; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | |
@@ -176,20 +176,20 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @param string $which |
178 | 178 | */ |
179 | - protected function display_tablenav( $which ) { |
|
179 | + protected function display_tablenav($which) { |
|
180 | 180 | |
181 | - if ( 'top' === $which ) { |
|
182 | - wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
|
181 | + if ('top' === $which) { |
|
182 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
183 | 183 | } |
184 | 184 | ?> |
185 | - <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
|
185 | + <div class="tablenav <?php echo esc_attr($which); ?>"> |
|
186 | 186 | |
187 | 187 | <div class="alignleft actions bulkactions"> |
188 | - <?php $this->bulk_actions( $which ); ?> |
|
188 | + <?php $this->bulk_actions($which); ?> |
|
189 | 189 | </div> |
190 | 190 | <?php |
191 | - $this->extra_tablenav( $which ); |
|
192 | - $this->pagination( $which ); |
|
191 | + $this->extra_tablenav($which); |
|
192 | + $this->pagination($which); |
|
193 | 193 | ?> |
194 | 194 | |
195 | 195 | <br class="clear"/> |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | $meta_query = array(); |
214 | 214 | |
215 | - if ( $user ) { |
|
215 | + if ($user) { |
|
216 | 216 | // Show only logs from a specific user |
217 | 217 | $meta_query[] = array( |
218 | 218 | 'key' => '_give_log_user_id', |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | } |
222 | 222 | |
223 | 223 | $search = $this->get_search(); |
224 | - if ( $search ) { |
|
225 | - if ( is_email( $search ) ) { |
|
224 | + if ($search) { |
|
225 | + if (is_email($search)) { |
|
226 | 226 | // This is an email search. We use this to ensure it works for guest users and logged-in users |
227 | 227 | $key = '_give_log_user_info'; |
228 | 228 | $compare = 'LIKE'; |
@@ -231,32 +231,32 @@ discard block |
||
231 | 231 | $key = '_give_log_user_id'; |
232 | 232 | $compare = 'LIKE'; |
233 | 233 | |
234 | - if ( ! is_numeric( $search ) ) { |
|
234 | + if ( ! is_numeric($search)) { |
|
235 | 235 | // Searching for user by username |
236 | - $user = get_user_by( 'login', $search ); |
|
236 | + $user = get_user_by('login', $search); |
|
237 | 237 | |
238 | - if ( $user ) { |
|
238 | + if ($user) { |
|
239 | 239 | // Found one, set meta value to user's ID |
240 | 240 | $search = $user->ID; |
241 | 241 | } else { |
242 | 242 | // No user found so let's do a real search query |
243 | - $users = new WP_User_Query( array( |
|
243 | + $users = new WP_User_Query(array( |
|
244 | 244 | 'search' => $search, |
245 | - 'search_columns' => array( 'user_url', 'user_nicename' ), |
|
245 | + 'search_columns' => array('user_url', 'user_nicename'), |
|
246 | 246 | 'number' => 1, |
247 | 247 | 'fields' => 'ids' |
248 | - ) ); |
|
248 | + )); |
|
249 | 249 | |
250 | 250 | $found_user = $users->get_results(); |
251 | 251 | |
252 | - if ( $found_user ) { |
|
252 | + if ($found_user) { |
|
253 | 253 | $search = $found_user[0]; |
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | - if ( ! $this->file_search ) { |
|
259 | + if ( ! $this->file_search) { |
|
260 | 260 | // Meta query only works for non file name searche |
261 | 261 | $meta_query[] = array( |
262 | 262 | 'key' => $key, |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @since 1.0 |
278 | 278 | * @return void |
279 | 279 | */ |
280 | - function bulk_actions( $which = '' ) { |
|
280 | + function bulk_actions($which = '') { |
|
281 | 281 | give_log_views(); |
282 | 282 | } |
283 | 283 | |
@@ -289,22 +289,22 @@ discard block |
||
289 | 289 | * @return void |
290 | 290 | */ |
291 | 291 | public function give_forms_filter() { |
292 | - $give_forms = get_posts( array( |
|
292 | + $give_forms = get_posts(array( |
|
293 | 293 | 'post_type' => 'give_forms', |
294 | 294 | 'post_status' => 'any', |
295 | - 'posts_per_page' => - 1, |
|
295 | + 'posts_per_page' => -1, |
|
296 | 296 | 'orderby' => 'title', |
297 | 297 | 'order' => 'ASC', |
298 | 298 | 'fields' => 'ids', |
299 | 299 | 'update_post_meta_cache' => false, |
300 | 300 | 'update_post_term_cache' => false |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | |
303 | - if ( $give_forms ) { |
|
303 | + if ($give_forms) { |
|
304 | 304 | echo '<select name="form" id="give-log-form-filter">'; |
305 | - echo '<option value="0">' . esc_html__( 'All', 'give' ) . '</option>'; |
|
306 | - foreach ( $give_forms as $form ) { |
|
307 | - echo '<option value="' . $form . '"' . selected( $form, $this->get_filtered_give_form() ) . '>' . esc_html( get_the_title( $form ) ) . '</option>'; |
|
305 | + echo '<option value="0">'.esc_html__('All', 'give').'</option>'; |
|
306 | + foreach ($give_forms as $form) { |
|
307 | + echo '<option value="'.$form.'"'.selected($form, $this->get_filtered_give_form()).'>'.esc_html(get_the_title($form)).'</option>'; |
|
308 | 308 | } |
309 | 309 | echo '</select>'; |
310 | 310 | } |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | |
325 | 325 | $logs_data = array(); |
326 | 326 | $paged = $this->get_paged(); |
327 | - $give_form = empty( $_GET['s'] ) ? $this->get_filtered_give_form() : null; |
|
327 | + $give_form = empty($_GET['s']) ? $this->get_filtered_give_form() : null; |
|
328 | 328 | $user = $this->get_filtered_user(); |
329 | 329 | |
330 | 330 | $log_query = array( |
@@ -334,39 +334,39 @@ discard block |
||
334 | 334 | 'meta_query' => $this->get_meta_query() |
335 | 335 | ); |
336 | 336 | |
337 | - $cache_key = give_get_cache_key( 'get_logs', $log_query ); |
|
337 | + $cache_key = give_get_cache_key('get_logs', $log_query); |
|
338 | 338 | |
339 | 339 | // Return result from cache if exist. |
340 | - if ( ! ( $logs_data = get_option( $cache_key ) ) ) { |
|
340 | + if ( ! ($logs_data = get_option($cache_key))) { |
|
341 | 341 | |
342 | - $logs = $give_logs->get_connected_logs( $log_query ); |
|
342 | + $logs = $give_logs->get_connected_logs($log_query); |
|
343 | 343 | |
344 | - if ( $logs ) { |
|
345 | - foreach ( $logs as $log ) { |
|
346 | - $payment_id = get_post_meta( $log->ID, '_give_log_payment_id', true ); |
|
344 | + if ($logs) { |
|
345 | + foreach ($logs as $log) { |
|
346 | + $payment_id = get_post_meta($log->ID, '_give_log_payment_id', true); |
|
347 | 347 | |
348 | 348 | // Make sure this payment hasn't been deleted |
349 | - if ( get_post( $payment_id ) ) : |
|
350 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
351 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
352 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
349 | + if (get_post($payment_id)) : |
|
350 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
351 | + $payment_meta = give_get_payment_meta($payment_id); |
|
352 | + $payment_amount = give_get_payment_amount($payment_id); |
|
353 | 353 | |
354 | 354 | $logs_data[] = array( |
355 | - 'ID' => '<span class="give-item-label give-item-label-gray">' . $log->ID . '</span>', |
|
355 | + 'ID' => '<span class="give-item-label give-item-label-gray">'.$log->ID.'</span>', |
|
356 | 356 | 'payment_id' => $payment_id, |
357 | 357 | 'form' => $log->post_parent, |
358 | 358 | 'amount' => $payment_amount, |
359 | 359 | 'user_id' => $user_info['id'], |
360 | - 'user_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], |
|
361 | - 'date' => get_post_field( 'post_date', $payment_id ), |
|
360 | + 'user_name' => $user_info['first_name'].' '.$user_info['last_name'], |
|
361 | + 'date' => get_post_field('post_date', $payment_id), |
|
362 | 362 | ); |
363 | 363 | |
364 | 364 | endif; |
365 | 365 | } |
366 | 366 | |
367 | 367 | // Cache results. |
368 | - if ( ! empty( $logs_data ) ) { |
|
369 | - add_option( $cache_key, $logs_data, '', 'no' ); |
|
368 | + if ( ! empty($logs_data)) { |
|
369 | + add_option($cache_key, $logs_data, '', 'no'); |
|
370 | 370 | } |
371 | 371 | } |
372 | 372 | } |
@@ -394,15 +394,15 @@ discard block |
||
394 | 394 | $columns = $this->get_columns(); |
395 | 395 | $hidden = array(); |
396 | 396 | $sortable = $this->get_sortable_columns(); |
397 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
397 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
398 | 398 | $current_page = $this->get_pagenum(); |
399 | 399 | $this->items = $this->get_logs(); |
400 | - $total_items = $give_logs->get_log_count( $this->get_filtered_give_form(), 'sale', $this->get_meta_query() ); |
|
400 | + $total_items = $give_logs->get_log_count($this->get_filtered_give_form(), 'sale', $this->get_meta_query()); |
|
401 | 401 | |
402 | - $this->set_pagination_args( array( |
|
402 | + $this->set_pagination_args(array( |
|
403 | 403 | 'total_items' => $total_items, |
404 | 404 | 'per_page' => $this->per_page, |
405 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
405 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
406 | 406 | ) |
407 | 407 | ); |
408 | 408 | } |
@@ -576,7 +576,7 @@ |
||
576 | 576 | * selected date-range (if any) |
577 | 577 | * |
578 | 578 | * @since 1.0 |
579 | - * @return array |
|
579 | + * @return integer|null |
|
580 | 580 | */ |
581 | 581 | function give_get_report_dates() { |
582 | 582 | $dates = array(); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | $dates = give_get_report_dates(); |
26 | 26 | |
27 | 27 | // Determine graph options |
28 | - switch ( $dates['range'] ) : |
|
28 | + switch ($dates['range']) : |
|
29 | 29 | case 'today' : |
30 | 30 | case 'yesterday' : |
31 | 31 | $day_by_day = true; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $day_by_day = false; |
38 | 38 | break; |
39 | 39 | case 'other' : |
40 | - if ( $dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year'] && ( $dates['m_start'] != '12' && $dates['m_end'] != '1' ) ) { |
|
40 | + if ($dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year'] && ($dates['m_start'] != '12' && $dates['m_end'] != '1')) { |
|
41 | 41 | $day_by_day = false; |
42 | 42 | } else { |
43 | 43 | $day_by_day = true; |
@@ -49,61 +49,61 @@ discard block |
||
49 | 49 | endswitch; |
50 | 50 | |
51 | 51 | $earnings_totals = 0.00; // Total earnings for time period shown |
52 | - $sales_totals = 0; // Total sales for time period shown |
|
52 | + $sales_totals = 0; // Total sales for time period shown |
|
53 | 53 | |
54 | 54 | $earnings_data = array(); |
55 | 55 | $sales_data = array(); |
56 | 56 | |
57 | - if ( $dates['range'] == 'today' || $dates['range'] == 'yesterday' ) { |
|
57 | + if ($dates['range'] == 'today' || $dates['range'] == 'yesterday') { |
|
58 | 58 | // Hour by hour |
59 | 59 | $hour = 1; |
60 | - $month = date( 'n', current_time( 'timestamp' ) ); |
|
61 | - while ( $hour <= 23 ) : |
|
60 | + $month = date('n', current_time('timestamp')); |
|
61 | + while ($hour <= 23) : |
|
62 | 62 | |
63 | - $sales = give_get_sales_by_date( $dates['day'], $month, $dates['year'], $hour ); |
|
64 | - $earnings = give_get_earnings_by_date( $dates['day'], $month, $dates['year'], $hour ); |
|
63 | + $sales = give_get_sales_by_date($dates['day'], $month, $dates['year'], $hour); |
|
64 | + $earnings = give_get_earnings_by_date($dates['day'], $month, $dates['year'], $hour); |
|
65 | 65 | |
66 | 66 | $sales_totals += $sales; |
67 | 67 | $earnings_totals += $earnings; |
68 | 68 | |
69 | - $date = mktime( $hour, 0, 0, $month, $dates['day'], $dates['year'] ) * 1000; |
|
70 | - $sales_data[] = array( $date, $sales ); |
|
71 | - $earnings_data[] = array( $date, $earnings ); |
|
69 | + $date = mktime($hour, 0, 0, $month, $dates['day'], $dates['year']) * 1000; |
|
70 | + $sales_data[] = array($date, $sales); |
|
71 | + $earnings_data[] = array($date, $earnings); |
|
72 | 72 | |
73 | - $hour ++; |
|
73 | + $hour++; |
|
74 | 74 | endwhile; |
75 | 75 | |
76 | - } elseif ( $dates['range'] == 'this_week' || $dates['range'] == 'last_week' ) { |
|
76 | + } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') { |
|
77 | 77 | |
78 | 78 | // Day by day |
79 | 79 | $day = $dates['day']; |
80 | 80 | $day_end = $dates['day_end']; |
81 | 81 | $month = $dates['m_start']; |
82 | - while ( $day <= $day_end ) : |
|
83 | - $sales = give_get_sales_by_date( $day, $month, $dates['year'] ); |
|
82 | + while ($day <= $day_end) : |
|
83 | + $sales = give_get_sales_by_date($day, $month, $dates['year']); |
|
84 | 84 | $sales_totals += $sales; |
85 | 85 | |
86 | - $earnings = give_get_earnings_by_date( $day, $month, $dates['year'] ); |
|
86 | + $earnings = give_get_earnings_by_date($day, $month, $dates['year']); |
|
87 | 87 | $earnings_totals += $earnings; |
88 | 88 | |
89 | - $date = mktime( 0, 0, 0, $month, $day, $dates['year'] ) * 1000; |
|
90 | - $sales_data[] = array( $date, $sales ); |
|
91 | - $earnings_data[] = array( $date, $earnings ); |
|
92 | - $day ++; |
|
89 | + $date = mktime(0, 0, 0, $month, $day, $dates['year']) * 1000; |
|
90 | + $sales_data[] = array($date, $sales); |
|
91 | + $earnings_data[] = array($date, $earnings); |
|
92 | + $day++; |
|
93 | 93 | endwhile; |
94 | 94 | |
95 | 95 | } else { |
96 | 96 | |
97 | 97 | $y = $dates['year']; |
98 | - while ( $y <= $dates['year_end'] ) : |
|
98 | + while ($y <= $dates['year_end']) : |
|
99 | 99 | |
100 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
100 | + if ($dates['year'] == $dates['year_end']) { |
|
101 | 101 | $month_start = $dates['m_start']; |
102 | 102 | $month_end = $dates['m_end']; |
103 | - } elseif ( $y == $dates['year'] ) { |
|
103 | + } elseif ($y == $dates['year']) { |
|
104 | 104 | $month_start = $dates['m_start']; |
105 | 105 | $month_end = 12; |
106 | - } elseif ( $y == $dates['year_end'] ) { |
|
106 | + } elseif ($y == $dates['year_end']) { |
|
107 | 107 | $month_start = 1; |
108 | 108 | $month_end = $dates['m_end']; |
109 | 109 | } else { |
@@ -112,48 +112,48 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | $i = $month_start; |
115 | - while ( $i <= $month_end ) : |
|
115 | + while ($i <= $month_end) : |
|
116 | 116 | |
117 | - if ( $day_by_day ) { |
|
117 | + if ($day_by_day) { |
|
118 | 118 | |
119 | - if ( $i == $month_end ) { |
|
119 | + if ($i == $month_end) { |
|
120 | 120 | |
121 | 121 | $num_of_days = $dates['day_end']; |
122 | 122 | |
123 | 123 | } else { |
124 | 124 | |
125 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
125 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
126 | 126 | |
127 | 127 | } |
128 | 128 | |
129 | 129 | $d = $dates['day']; |
130 | 130 | |
131 | - while ( $d <= $num_of_days ) : |
|
131 | + while ($d <= $num_of_days) : |
|
132 | 132 | |
133 | - $sales = give_get_sales_by_date( $d, $i, $y ); |
|
133 | + $sales = give_get_sales_by_date($d, $i, $y); |
|
134 | 134 | $sales_totals += $sales; |
135 | 135 | |
136 | - $earnings = give_get_earnings_by_date( $d, $i, $y ); |
|
136 | + $earnings = give_get_earnings_by_date($d, $i, $y); |
|
137 | 137 | $earnings_totals += $earnings; |
138 | 138 | |
139 | - $date = mktime( 0, 0, 0, $i, $d, $y ) * 1000; |
|
140 | - $sales_data[] = array( $date, $sales ); |
|
141 | - $earnings_data[] = array( $date, $earnings ); |
|
142 | - $d ++; |
|
139 | + $date = mktime(0, 0, 0, $i, $d, $y) * 1000; |
|
140 | + $sales_data[] = array($date, $sales); |
|
141 | + $earnings_data[] = array($date, $earnings); |
|
142 | + $d++; |
|
143 | 143 | |
144 | 144 | endwhile; |
145 | 145 | |
146 | 146 | } else { |
147 | 147 | |
148 | - $sales = give_get_sales_by_date( null, $i, $y ); |
|
148 | + $sales = give_get_sales_by_date(null, $i, $y); |
|
149 | 149 | $sales_totals += $sales; |
150 | 150 | |
151 | - $earnings = give_get_earnings_by_date( null, $i, $y ); |
|
151 | + $earnings = give_get_earnings_by_date(null, $i, $y); |
|
152 | 152 | $earnings_totals += $earnings; |
153 | 153 | |
154 | - if ( $i == $month_end ) { |
|
154 | + if ($i == $month_end) { |
|
155 | 155 | |
156 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
156 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
157 | 157 | |
158 | 158 | } else { |
159 | 159 | |
@@ -161,24 +161,24 @@ discard block |
||
161 | 161 | |
162 | 162 | } |
163 | 163 | |
164 | - $date = mktime( 0, 0, 0, $i, $num_of_days, $y ) * 1000; |
|
165 | - $sales_data[] = array( $date, $sales ); |
|
166 | - $earnings_data[] = array( $date, $earnings ); |
|
164 | + $date = mktime(0, 0, 0, $i, $num_of_days, $y) * 1000; |
|
165 | + $sales_data[] = array($date, $sales); |
|
166 | + $earnings_data[] = array($date, $earnings); |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | |
170 | - $i ++; |
|
170 | + $i++; |
|
171 | 171 | |
172 | 172 | endwhile; |
173 | 173 | |
174 | - $y ++; |
|
174 | + $y++; |
|
175 | 175 | endwhile; |
176 | 176 | |
177 | 177 | } |
178 | 178 | |
179 | 179 | $data = array( |
180 | - esc_html__( 'Income', 'give' ) => $earnings_data, |
|
181 | - esc_html__( 'Donations', 'give' ) => $sales_data |
|
180 | + esc_html__('Income', 'give') => $earnings_data, |
|
181 | + esc_html__('Donations', 'give') => $sales_data |
|
182 | 182 | ); |
183 | 183 | |
184 | 184 | // start our own output buffer |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | <div class="postbox"> |
191 | 191 | <div class="inside"> |
192 | 192 | <?php |
193 | - $graph = new Give_Graph( $data ); |
|
194 | - $graph->set( 'x_mode', 'time' ); |
|
195 | - $graph->set( 'multiple_y_axes', true ); |
|
193 | + $graph = new Give_Graph($data); |
|
194 | + $graph->set('x_mode', 'time'); |
|
195 | + $graph->set('multiple_y_axes', true); |
|
196 | 196 | $graph->display(); |
197 | 197 | |
198 | - if ( 'this_month' == $dates['range'] ) { |
|
198 | + if ('this_month' == $dates['range']) { |
|
199 | 199 | $estimated = give_estimated_monthly_stats(); |
200 | 200 | } |
201 | 201 | ?> |
@@ -205,21 +205,21 @@ discard block |
||
205 | 205 | <table class="widefat reports-table alignleft" style="max-width:450px"> |
206 | 206 | <tbody> |
207 | 207 | <tr> |
208 | - <th scope="row"><strong><?php esc_html_e( 'Total income for period:', 'give' ); ?></strong></th> |
|
209 | - <td><?php echo give_currency_filter( give_format_amount( $earnings_totals ) ); ?></td> |
|
208 | + <th scope="row"><strong><?php esc_html_e('Total income for period:', 'give'); ?></strong></th> |
|
209 | + <td><?php echo give_currency_filter(give_format_amount($earnings_totals)); ?></td> |
|
210 | 210 | </tr> |
211 | 211 | <tr class="alternate"> |
212 | - <th scope="row"><strong><?php esc_html_e( 'Total donations for period:', 'give' ); ?><strong></th> |
|
212 | + <th scope="row"><strong><?php esc_html_e('Total donations for period:', 'give'); ?><strong></th> |
|
213 | 213 | <td><?php echo $sales_totals; ?></td> |
214 | 214 | </tr> |
215 | - <?php if ( 'this_month' == $dates['range'] ) : ?> |
|
215 | + <?php if ('this_month' == $dates['range']) : ?> |
|
216 | 216 | <tr> |
217 | - <th scope="row"><strong><?php esc_html_e( 'Estimated monthly income:', 'give' ); ?></strong></th> |
|
218 | - <td><?php echo give_currency_filter( give_format_amount( $estimated['earnings'] ) ); ?></td> |
|
217 | + <th scope="row"><strong><?php esc_html_e('Estimated monthly income:', 'give'); ?></strong></th> |
|
218 | + <td><?php echo give_currency_filter(give_format_amount($estimated['earnings'])); ?></td> |
|
219 | 219 | </tr> |
220 | 220 | <tr class="alternate"> |
221 | - <th scope="row"><strong><?php esc_html_e( 'Estimated monthly donations:', 'give' ); ?></strong></th> |
|
222 | - <td><?php echo floor( $estimated['sales'] ); ?></td> |
|
221 | + <th scope="row"><strong><?php esc_html_e('Estimated monthly donations:', 'give'); ?></strong></th> |
|
222 | + <td><?php echo floor($estimated['sales']); ?></td> |
|
223 | 223 | </tr> |
224 | 224 | <?php endif; ?> |
225 | 225 | </table> |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @since 1.0 |
234 | 234 | */ |
235 | - do_action( 'give_reports_graph_additional_stats' ); |
|
235 | + do_action('give_reports_graph_additional_stats'); |
|
236 | 236 | ?> |
237 | 237 | |
238 | 238 | </div> |
@@ -251,12 +251,12 @@ discard block |
||
251 | 251 | * @since 1.0 |
252 | 252 | * @return void |
253 | 253 | */ |
254 | -function give_reports_graph_of_form( $form_id = 0 ) { |
|
254 | +function give_reports_graph_of_form($form_id = 0) { |
|
255 | 255 | // Retrieve the queried dates |
256 | 256 | $dates = give_get_report_dates(); |
257 | 257 | |
258 | 258 | // Determine graph options |
259 | - switch ( $dates['range'] ) : |
|
259 | + switch ($dates['range']) : |
|
260 | 260 | case 'today' : |
261 | 261 | case 'yesterday' : |
262 | 262 | $day_by_day = true; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | $day_by_day = false; |
275 | 275 | break; |
276 | 276 | case 'other' : |
277 | - if ( $dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year'] ) { |
|
277 | + if ($dates['m_end'] - $dates['m_start'] >= 2 || $dates['year_end'] > $dates['year']) { |
|
278 | 278 | $day_by_day = false; |
279 | 279 | } else { |
280 | 280 | $day_by_day = true; |
@@ -286,75 +286,75 @@ discard block |
||
286 | 286 | endswitch; |
287 | 287 | |
288 | 288 | $earnings_totals = (float) 0.00; // Total earnings for time period shown |
289 | - $sales_totals = 0; // Total sales for time period shown |
|
289 | + $sales_totals = 0; // Total sales for time period shown |
|
290 | 290 | |
291 | 291 | $earnings_data = array(); |
292 | 292 | $sales_data = array(); |
293 | 293 | $stats = new Give_Payment_Stats; |
294 | 294 | |
295 | - if ( $dates['range'] == 'today' || $dates['range'] == 'yesterday' ) { |
|
295 | + if ($dates['range'] == 'today' || $dates['range'] == 'yesterday') { |
|
296 | 296 | |
297 | 297 | // Hour by hour |
298 | 298 | $month = $dates['m_start']; |
299 | 299 | $hour = 1; |
300 | 300 | $minute = 0; |
301 | 301 | $second = 0; |
302 | - while ( $hour <= 23 ) : |
|
302 | + while ($hour <= 23) : |
|
303 | 303 | |
304 | - if ( $hour == 23 ) { |
|
304 | + if ($hour == 23) { |
|
305 | 305 | $minute = $second = 59; |
306 | 306 | } |
307 | 307 | |
308 | - $date = mktime( $hour, $minute, $second, $month, $dates['day'], $dates['year'] ); |
|
309 | - $date_end = mktime( $hour + 1, $minute, $second, $month, $dates['day'], $dates['year'] ); |
|
308 | + $date = mktime($hour, $minute, $second, $month, $dates['day'], $dates['year']); |
|
309 | + $date_end = mktime($hour + 1, $minute, $second, $month, $dates['day'], $dates['year']); |
|
310 | 310 | |
311 | - $sales = $stats->get_sales( $form_id, $date, $date_end ); |
|
311 | + $sales = $stats->get_sales($form_id, $date, $date_end); |
|
312 | 312 | $sales_totals += $sales; |
313 | 313 | |
314 | - $earnings = $stats->get_earnings( $form_id, $date, $date_end ); |
|
314 | + $earnings = $stats->get_earnings($form_id, $date, $date_end); |
|
315 | 315 | $earnings_totals += $earnings; |
316 | 316 | |
317 | - $sales_data[] = array( $date * 1000, $sales ); |
|
318 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
317 | + $sales_data[] = array($date * 1000, $sales); |
|
318 | + $earnings_data[] = array($date * 1000, $earnings); |
|
319 | 319 | |
320 | - $hour ++; |
|
320 | + $hour++; |
|
321 | 321 | endwhile; |
322 | 322 | |
323 | - } elseif ( $dates['range'] == 'this_week' || $dates['range'] == 'last_week' ) { |
|
323 | + } elseif ($dates['range'] == 'this_week' || $dates['range'] == 'last_week') { |
|
324 | 324 | |
325 | 325 | //Day by day |
326 | 326 | $day = $dates['day']; |
327 | 327 | $day_end = $dates['day_end']; |
328 | 328 | $month = $dates['m_start']; |
329 | - while ( $day <= $day_end ) : |
|
329 | + while ($day <= $day_end) : |
|
330 | 330 | |
331 | - $date = mktime( 0, 0, 0, $month, $day, $dates['year'] ); |
|
332 | - $date_end = mktime( 0, 0, 0, $month, $day + 1, $dates['year'] ); |
|
333 | - $sales = $stats->get_sales( $form_id, $date, $date_end ); |
|
331 | + $date = mktime(0, 0, 0, $month, $day, $dates['year']); |
|
332 | + $date_end = mktime(0, 0, 0, $month, $day + 1, $dates['year']); |
|
333 | + $sales = $stats->get_sales($form_id, $date, $date_end); |
|
334 | 334 | $sales_totals += $sales; |
335 | 335 | |
336 | - $earnings = $stats->get_earnings( $form_id, $date, $date_end ); |
|
336 | + $earnings = $stats->get_earnings($form_id, $date, $date_end); |
|
337 | 337 | $earnings_totals += $earnings; |
338 | 338 | |
339 | - $sales_data[] = array( $date * 1000, $sales ); |
|
340 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
339 | + $sales_data[] = array($date * 1000, $sales); |
|
340 | + $earnings_data[] = array($date * 1000, $earnings); |
|
341 | 341 | |
342 | - $day ++; |
|
342 | + $day++; |
|
343 | 343 | endwhile; |
344 | 344 | |
345 | 345 | } else { |
346 | 346 | |
347 | 347 | $y = $dates['year']; |
348 | 348 | |
349 | - while ( $y <= $dates['year_end'] ) : |
|
349 | + while ($y <= $dates['year_end']) : |
|
350 | 350 | |
351 | 351 | $last_year = false; |
352 | 352 | |
353 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
353 | + if ($dates['year'] == $dates['year_end']) { |
|
354 | 354 | $month_start = $dates['m_start']; |
355 | 355 | $month_end = $dates['m_end']; |
356 | 356 | $last_year = true; |
357 | - } elseif ( $y == $dates['year'] ) { |
|
357 | + } elseif ($y == $dates['year']) { |
|
358 | 358 | $month_start = $dates['m_start']; |
359 | 359 | $month_end = 12; |
360 | 360 | } else { |
@@ -363,76 +363,76 @@ discard block |
||
363 | 363 | } |
364 | 364 | |
365 | 365 | $i = $month_start; |
366 | - while ( $i <= $month_end ) : |
|
366 | + while ($i <= $month_end) : |
|
367 | 367 | |
368 | - if ( $day_by_day ) { |
|
368 | + if ($day_by_day) { |
|
369 | 369 | |
370 | - if ( $i == $month_end && $last_year ) { |
|
370 | + if ($i == $month_end && $last_year) { |
|
371 | 371 | |
372 | 372 | $num_of_days = $dates['day_end']; |
373 | 373 | |
374 | 374 | } else { |
375 | 375 | |
376 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
376 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
380 | 380 | $d = $dates['day']; |
381 | - while ( $d <= $num_of_days ) : |
|
381 | + while ($d <= $num_of_days) : |
|
382 | 382 | |
383 | - $date = mktime( 0, 0, 0, $i, $d, $y ); |
|
384 | - $end_date = mktime( 23, 59, 59, $i, $d, $y ); |
|
383 | + $date = mktime(0, 0, 0, $i, $d, $y); |
|
384 | + $end_date = mktime(23, 59, 59, $i, $d, $y); |
|
385 | 385 | |
386 | - $sales = $stats->get_sales( $form_id, $date, $end_date ); |
|
386 | + $sales = $stats->get_sales($form_id, $date, $end_date); |
|
387 | 387 | $sales_totals += $sales; |
388 | 388 | |
389 | - $earnings = $stats->get_earnings( $form_id, $date, $end_date ); |
|
389 | + $earnings = $stats->get_earnings($form_id, $date, $end_date); |
|
390 | 390 | $earnings_totals += $earnings; |
391 | 391 | |
392 | - $sales_data[] = array( $date * 1000, $sales ); |
|
393 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
394 | - $d ++; |
|
392 | + $sales_data[] = array($date * 1000, $sales); |
|
393 | + $earnings_data[] = array($date * 1000, $earnings); |
|
394 | + $d++; |
|
395 | 395 | |
396 | 396 | endwhile; |
397 | 397 | |
398 | 398 | } else { |
399 | 399 | |
400 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
400 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
401 | 401 | |
402 | - $date = mktime( 0, 0, 0, $i, 1, $y ); |
|
403 | - $end_date = mktime( 23, 59, 59, $i, $num_of_days, $y ); |
|
402 | + $date = mktime(0, 0, 0, $i, 1, $y); |
|
403 | + $end_date = mktime(23, 59, 59, $i, $num_of_days, $y); |
|
404 | 404 | |
405 | - $sales = $stats->get_sales( $form_id, $date, $end_date ); |
|
405 | + $sales = $stats->get_sales($form_id, $date, $end_date); |
|
406 | 406 | $sales_totals += $sales; |
407 | 407 | |
408 | - $earnings = $stats->get_earnings( $form_id, $date, $end_date ); |
|
408 | + $earnings = $stats->get_earnings($form_id, $date, $end_date); |
|
409 | 409 | $earnings_totals += $earnings; |
410 | 410 | |
411 | - $sales_data[] = array( $date * 1000, $sales ); |
|
412 | - $earnings_data[] = array( $date * 1000, $earnings ); |
|
411 | + $sales_data[] = array($date * 1000, $sales); |
|
412 | + $earnings_data[] = array($date * 1000, $earnings); |
|
413 | 413 | |
414 | 414 | } |
415 | 415 | |
416 | - $i ++; |
|
416 | + $i++; |
|
417 | 417 | |
418 | 418 | endwhile; |
419 | 419 | |
420 | - $y ++; |
|
420 | + $y++; |
|
421 | 421 | endwhile; |
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | $data = array( |
426 | - esc_html__( 'Income', 'give' ) => $earnings_data, |
|
427 | - esc_html__( 'Donations', 'give' ) => $sales_data |
|
426 | + esc_html__('Income', 'give') => $earnings_data, |
|
427 | + esc_html__('Donations', 'give') => $sales_data |
|
428 | 428 | ); |
429 | 429 | |
430 | 430 | ?> |
431 | 431 | <h3><span><?php |
432 | 432 | printf( |
433 | 433 | /* translators: %s: form title */ |
434 | - esc_html__( 'Income Over Time for %s', 'give' ), |
|
435 | - get_the_title( $form_id ) |
|
434 | + esc_html__('Income Over Time for %s', 'give'), |
|
435 | + get_the_title($form_id) |
|
436 | 436 | ); |
437 | 437 | ?></span></h3> |
438 | 438 | |
@@ -440,9 +440,9 @@ discard block |
||
440 | 440 | <div class="postbox"> |
441 | 441 | <div class="inside"> |
442 | 442 | <?php |
443 | - $graph = new Give_Graph( $data ); |
|
444 | - $graph->set( 'x_mode', 'time' ); |
|
445 | - $graph->set( 'multiple_y_axes', true ); |
|
443 | + $graph = new Give_Graph($data); |
|
444 | + $graph->set('x_mode', 'time'); |
|
445 | + $graph->set('multiple_y_axes', true); |
|
446 | 446 | $graph->display(); |
447 | 447 | ?> |
448 | 448 | </div> |
@@ -451,20 +451,20 @@ discard block |
||
451 | 451 | <table class="widefat reports-table alignleft" style="max-width:450px"> |
452 | 452 | <tbody> |
453 | 453 | <tr> |
454 | - <th scope="row"><strong><?php esc_html_e( 'Total income for period:', 'give' ); ?></strong></th> |
|
455 | - <td><?php echo give_currency_filter( give_format_amount( $earnings_totals ) ); ?></td> |
|
454 | + <th scope="row"><strong><?php esc_html_e('Total income for period:', 'give'); ?></strong></th> |
|
455 | + <td><?php echo give_currency_filter(give_format_amount($earnings_totals)); ?></td> |
|
456 | 456 | </tr> |
457 | 457 | <tr class="alternate"> |
458 | - <th scope="row"><strong><?php esc_html_e( 'Total donations for period:', 'give' ); ?></strong></th> |
|
458 | + <th scope="row"><strong><?php esc_html_e('Total donations for period:', 'give'); ?></strong></th> |
|
459 | 459 | <td><?php echo $sales_totals; ?></td> |
460 | 460 | </tr> |
461 | 461 | <tr> |
462 | - <th scope="row"><strong><?php esc_html_e( 'Average monthly income:', 'give' ); ?></strong></th> |
|
463 | - <td><?php echo give_currency_filter( give_format_amount( give_get_average_monthly_form_earnings( $form_id ) ) ); ?></td> |
|
462 | + <th scope="row"><strong><?php esc_html_e('Average monthly income:', 'give'); ?></strong></th> |
|
463 | + <td><?php echo give_currency_filter(give_format_amount(give_get_average_monthly_form_earnings($form_id))); ?></td> |
|
464 | 464 | </tr> |
465 | 465 | <tr class="alternate"> |
466 | - <th scope="row"><strong><?php esc_html_e( 'Average monthly donations:', 'give' ); ?></strong></th> |
|
467 | - <td><?php echo number_format( give_get_average_monthly_form_sales( $form_id ), 0 ); ?></td> |
|
466 | + <th scope="row"><strong><?php esc_html_e('Average monthly donations:', 'give'); ?></strong></th> |
|
467 | + <td><?php echo number_format(give_get_average_monthly_form_sales($form_id), 0); ?></td> |
|
468 | 468 | </tr> |
469 | 469 | </tbody> |
470 | 470 | </table> |
@@ -481,26 +481,26 @@ discard block |
||
481 | 481 | * @return void |
482 | 482 | */ |
483 | 483 | function give_reports_graph_controls() { |
484 | - $date_options = apply_filters( 'give_report_date_options', array( |
|
485 | - 'today' => esc_html__( 'Today', 'give' ), |
|
486 | - 'yesterday' => esc_html__( 'Yesterday', 'give' ), |
|
487 | - 'this_week' => esc_html__( 'This Week', 'give' ), |
|
488 | - 'last_week' => esc_html__( 'Last Week', 'give' ), |
|
489 | - 'this_month' => esc_html__( 'This Month', 'give' ), |
|
490 | - 'last_month' => esc_html__( 'Last Month', 'give' ), |
|
491 | - 'this_quarter' => esc_html__( 'This Quarter', 'give' ), |
|
492 | - 'last_quarter' => esc_html__( 'Last Quarter', 'give' ), |
|
493 | - 'this_year' => esc_html__( 'This Year', 'give' ), |
|
494 | - 'last_year' => esc_html__( 'Last Year', 'give' ), |
|
495 | - 'other' => esc_html__( 'Custom', 'give' ) |
|
496 | - ) ); |
|
484 | + $date_options = apply_filters('give_report_date_options', array( |
|
485 | + 'today' => esc_html__('Today', 'give'), |
|
486 | + 'yesterday' => esc_html__('Yesterday', 'give'), |
|
487 | + 'this_week' => esc_html__('This Week', 'give'), |
|
488 | + 'last_week' => esc_html__('Last Week', 'give'), |
|
489 | + 'this_month' => esc_html__('This Month', 'give'), |
|
490 | + 'last_month' => esc_html__('Last Month', 'give'), |
|
491 | + 'this_quarter' => esc_html__('This Quarter', 'give'), |
|
492 | + 'last_quarter' => esc_html__('Last Quarter', 'give'), |
|
493 | + 'this_year' => esc_html__('This Year', 'give'), |
|
494 | + 'last_year' => esc_html__('Last Year', 'give'), |
|
495 | + 'other' => esc_html__('Custom', 'give') |
|
496 | + )); |
|
497 | 497 | |
498 | 498 | $dates = give_get_report_dates(); |
499 | 499 | $display = $dates['range'] == 'other' ? '' : 'style="display:none;"'; |
500 | 500 | $view = give_get_reporting_view(); |
501 | 501 | |
502 | - if ( empty( $dates['day_end'] ) ) { |
|
503 | - $dates['day_end'] = cal_days_in_month( CAL_GREGORIAN, date( 'n' ), date( 'Y' ) ); |
|
502 | + if (empty($dates['day_end'])) { |
|
503 | + $dates['day_end'] = cal_days_in_month(CAL_GREGORIAN, date('n'), date('Y')); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * |
509 | 509 | * @since 1.0 |
510 | 510 | */ |
511 | - do_action( 'give_report_graph_controls_before' ); |
|
511 | + do_action('give_report_graph_controls_before'); |
|
512 | 512 | ?> |
513 | 513 | <form id="give-graphs-filter" method="get" class="alignright"> |
514 | 514 | <div class="tablenav top alignright"> |
@@ -516,53 +516,53 @@ discard block |
||
516 | 516 | |
517 | 517 | <input type="hidden" name="post_type" value="give_forms" /> |
518 | 518 | <input type="hidden" name="page" value="give-reports" /> |
519 | - <input type="hidden" name="view" value="<?php echo esc_attr( $view ); ?>" /> |
|
519 | + <input type="hidden" name="view" value="<?php echo esc_attr($view); ?>" /> |
|
520 | 520 | |
521 | - <?php if ( isset( $_GET['form-id'] ) ) : ?> |
|
522 | - <input type="hidden" name="form-id" value="<?php echo absint( $_GET['form-id'] ); ?>" /> |
|
521 | + <?php if (isset($_GET['form-id'])) : ?> |
|
522 | + <input type="hidden" name="form-id" value="<?php echo absint($_GET['form-id']); ?>" /> |
|
523 | 523 | <?php endif; ?> |
524 | 524 | |
525 | 525 | <div id="give-graphs-date-options-wrap" class="alignright"> |
526 | 526 | <select id="give-graphs-date-options" name="range"> |
527 | - <?php foreach ( $date_options as $key => $option ) : ?> |
|
528 | - <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $dates['range'] ); ?>><?php echo esc_html( $option ); ?></option> |
|
527 | + <?php foreach ($date_options as $key => $option) : ?> |
|
528 | + <option value="<?php echo esc_attr($key); ?>"<?php selected($key, $dates['range']); ?>><?php echo esc_html($option); ?></option> |
|
529 | 529 | <?php endforeach; ?> |
530 | 530 | </select> |
531 | 531 | |
532 | - <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Filter', 'give' ); ?>" /> |
|
532 | + <input type="submit" class="button-secondary" value="<?php esc_attr_e('Filter', 'give'); ?>" /> |
|
533 | 533 | </div> |
534 | 534 | |
535 | 535 | <div id="give-date-range-options" <?php echo $display; ?>> |
536 | - <span><?php esc_html_e( 'From', 'give' ); ?> </span> |
|
536 | + <span><?php esc_html_e('From', 'give'); ?> </span> |
|
537 | 537 | <select id="give-graphs-month-start" name="m_start"> |
538 | - <?php for ( $i = 1; $i <= 12; $i ++ ) : ?> |
|
539 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['m_start'] ); ?>><?php echo give_month_num_to_name( $i ); ?></option> |
|
538 | + <?php for ($i = 1; $i <= 12; $i++) : ?> |
|
539 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['m_start']); ?>><?php echo give_month_num_to_name($i); ?></option> |
|
540 | 540 | <?php endfor; ?> |
541 | 541 | </select> |
542 | 542 | <select id="give-graphs-day-start" name="day"> |
543 | - <?php for ( $i = 1; $i <= 31; $i ++ ) : ?> |
|
544 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['day'] ); ?>><?php echo $i; ?></option> |
|
543 | + <?php for ($i = 1; $i <= 31; $i++) : ?> |
|
544 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['day']); ?>><?php echo $i; ?></option> |
|
545 | 545 | <?php endfor; ?> |
546 | 546 | </select> |
547 | 547 | <select id="give-graphs-year-start" name="year"> |
548 | - <?php for ( $i = 2007; $i <= date( 'Y' ); $i ++ ) : ?> |
|
549 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['year'] ); ?>><?php echo $i; ?></option> |
|
548 | + <?php for ($i = 2007; $i <= date('Y'); $i++) : ?> |
|
549 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['year']); ?>><?php echo $i; ?></option> |
|
550 | 550 | <?php endfor; ?> |
551 | 551 | </select> |
552 | - <span><?php esc_html_e( 'To', 'give' ); ?> </span> |
|
552 | + <span><?php esc_html_e('To', 'give'); ?> </span> |
|
553 | 553 | <select id="give-graphs-month-end" name="m_end"> |
554 | - <?php for ( $i = 1; $i <= 12; $i ++ ) : ?> |
|
555 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['m_end'] ); ?>><?php echo give_month_num_to_name( $i ); ?></option> |
|
554 | + <?php for ($i = 1; $i <= 12; $i++) : ?> |
|
555 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['m_end']); ?>><?php echo give_month_num_to_name($i); ?></option> |
|
556 | 556 | <?php endfor; ?> |
557 | 557 | </select> |
558 | 558 | <select id="give-graphs-day-end" name="day_end"> |
559 | - <?php for ( $i = 1; $i <= 31; $i ++ ) : ?> |
|
560 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['day_end'] ); ?>><?php echo $i; ?></option> |
|
559 | + <?php for ($i = 1; $i <= 31; $i++) : ?> |
|
560 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['day_end']); ?>><?php echo $i; ?></option> |
|
561 | 561 | <?php endfor; ?> |
562 | 562 | </select> |
563 | 563 | <select id="give-graphs-year-end" name="year_end"> |
564 | - <?php for ( $i = 2007; $i <= date( 'Y' ); $i ++ ) : ?> |
|
565 | - <option value="<?php echo absint( $i ); ?>" <?php selected( $i, $dates['year_end'] ); ?>><?php echo $i; ?></option> |
|
564 | + <?php for ($i = 2007; $i <= date('Y'); $i++) : ?> |
|
565 | + <option value="<?php echo absint($i); ?>" <?php selected($i, $dates['year_end']); ?>><?php echo $i; ?></option> |
|
566 | 566 | <?php endfor; ?> |
567 | 567 | </select> |
568 | 568 | </div> |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | * |
578 | 578 | * @since 1.0 |
579 | 579 | */ |
580 | - do_action( 'give_report_graph_controls_after' ); |
|
580 | + do_action('give_report_graph_controls_after'); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -592,65 +592,65 @@ discard block |
||
592 | 592 | function give_get_report_dates() { |
593 | 593 | $dates = array(); |
594 | 594 | |
595 | - $current_time = current_time( 'timestamp' ); |
|
595 | + $current_time = current_time('timestamp'); |
|
596 | 596 | |
597 | - $dates['range'] = isset( $_GET['range'] ) ? $_GET['range'] : 'this_month'; |
|
598 | - $dates['year'] = isset( $_GET['year'] ) ? $_GET['year'] : date( 'Y' ); |
|
599 | - $dates['year_end'] = isset( $_GET['year_end'] ) ? $_GET['year_end'] : date( 'Y' ); |
|
600 | - $dates['m_start'] = isset( $_GET['m_start'] ) ? $_GET['m_start'] : 1; |
|
601 | - $dates['m_end'] = isset( $_GET['m_end'] ) ? $_GET['m_end'] : 12; |
|
602 | - $dates['day'] = isset( $_GET['day'] ) ? $_GET['day'] : 1; |
|
603 | - $dates['day_end'] = isset( $_GET['day_end'] ) ? $_GET['day_end'] : cal_days_in_month( CAL_GREGORIAN, $dates['m_end'], $dates['year'] ); |
|
597 | + $dates['range'] = isset($_GET['range']) ? $_GET['range'] : 'this_month'; |
|
598 | + $dates['year'] = isset($_GET['year']) ? $_GET['year'] : date('Y'); |
|
599 | + $dates['year_end'] = isset($_GET['year_end']) ? $_GET['year_end'] : date('Y'); |
|
600 | + $dates['m_start'] = isset($_GET['m_start']) ? $_GET['m_start'] : 1; |
|
601 | + $dates['m_end'] = isset($_GET['m_end']) ? $_GET['m_end'] : 12; |
|
602 | + $dates['day'] = isset($_GET['day']) ? $_GET['day'] : 1; |
|
603 | + $dates['day_end'] = isset($_GET['day_end']) ? $_GET['day_end'] : cal_days_in_month(CAL_GREGORIAN, $dates['m_end'], $dates['year']); |
|
604 | 604 | |
605 | 605 | // Modify dates based on predefined ranges |
606 | - switch ( $dates['range'] ) : |
|
606 | + switch ($dates['range']) : |
|
607 | 607 | |
608 | 608 | case 'this_month' : |
609 | - $dates['m_start'] = date( 'n', $current_time ); |
|
610 | - $dates['m_end'] = date( 'n', $current_time ); |
|
609 | + $dates['m_start'] = date('n', $current_time); |
|
610 | + $dates['m_end'] = date('n', $current_time); |
|
611 | 611 | $dates['day'] = 1; |
612 | - $dates['day_end'] = cal_days_in_month( CAL_GREGORIAN, $dates['m_end'], $dates['year'] ); |
|
613 | - $dates['year'] = date( 'Y' ); |
|
614 | - $dates['year_end'] = date( 'Y' ); |
|
612 | + $dates['day_end'] = cal_days_in_month(CAL_GREGORIAN, $dates['m_end'], $dates['year']); |
|
613 | + $dates['year'] = date('Y'); |
|
614 | + $dates['year_end'] = date('Y'); |
|
615 | 615 | break; |
616 | 616 | |
617 | 617 | case 'last_month' : |
618 | - if ( date( 'n' ) == 1 ) { |
|
618 | + if (date('n') == 1) { |
|
619 | 619 | $dates['m_start'] = 12; |
620 | 620 | $dates['m_end'] = 12; |
621 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
622 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; |
|
621 | + $dates['year'] = date('Y', $current_time) - 1; |
|
622 | + $dates['year_end'] = date('Y', $current_time) - 1; |
|
623 | 623 | } else { |
624 | - $dates['m_start'] = date( 'n' ) - 1; |
|
625 | - $dates['m_end'] = date( 'n' ) - 1; |
|
624 | + $dates['m_start'] = date('n') - 1; |
|
625 | + $dates['m_end'] = date('n') - 1; |
|
626 | 626 | $dates['year_end'] = $dates['year']; |
627 | 627 | } |
628 | - $dates['day_end'] = cal_days_in_month( CAL_GREGORIAN, $dates['m_end'], $dates['year'] ); |
|
628 | + $dates['day_end'] = cal_days_in_month(CAL_GREGORIAN, $dates['m_end'], $dates['year']); |
|
629 | 629 | break; |
630 | 630 | |
631 | 631 | case 'today' : |
632 | - $dates['day'] = date( 'd', $current_time ); |
|
633 | - $dates['m_start'] = date( 'n', $current_time ); |
|
634 | - $dates['m_end'] = date( 'n', $current_time ); |
|
635 | - $dates['year'] = date( 'Y', $current_time ); |
|
632 | + $dates['day'] = date('d', $current_time); |
|
633 | + $dates['m_start'] = date('n', $current_time); |
|
634 | + $dates['m_end'] = date('n', $current_time); |
|
635 | + $dates['year'] = date('Y', $current_time); |
|
636 | 636 | break; |
637 | 637 | |
638 | 638 | case 'yesterday' : |
639 | 639 | |
640 | - $year = date( 'Y', $current_time ); |
|
641 | - $month = date( 'n', $current_time ); |
|
642 | - $day = date( 'd', $current_time ); |
|
640 | + $year = date('Y', $current_time); |
|
641 | + $month = date('n', $current_time); |
|
642 | + $day = date('d', $current_time); |
|
643 | 643 | |
644 | - if ( $month == 1 && $day == 1 ) { |
|
644 | + if ($month == 1 && $day == 1) { |
|
645 | 645 | |
646 | 646 | $year -= 1; |
647 | 647 | $month = 12; |
648 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
648 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
649 | 649 | |
650 | - } elseif ( $month > 1 && $day == 1 ) { |
|
650 | + } elseif ($month > 1 && $day == 1) { |
|
651 | 651 | |
652 | 652 | $month -= 1; |
653 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
653 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
654 | 654 | |
655 | 655 | } else { |
656 | 656 | |
@@ -666,91 +666,91 @@ discard block |
||
666 | 666 | break; |
667 | 667 | |
668 | 668 | case 'this_week' : |
669 | - $dates['day'] = date( 'd', $current_time - ( date( 'w', $current_time ) - 1 ) * 60 * 60 * 24 ) - 1; |
|
670 | - $dates['day'] += get_option( 'start_of_week' ); |
|
669 | + $dates['day'] = date('d', $current_time - (date('w', $current_time) - 1) * 60 * 60 * 24) - 1; |
|
670 | + $dates['day'] += get_option('start_of_week'); |
|
671 | 671 | $dates['day_end'] = $dates['day'] + 6; |
672 | - $dates['m_start'] = date( 'n', $current_time ); |
|
673 | - $dates['m_end'] = date( 'n', $current_time ); |
|
674 | - $dates['year'] = date( 'Y', $current_time ); |
|
672 | + $dates['m_start'] = date('n', $current_time); |
|
673 | + $dates['m_end'] = date('n', $current_time); |
|
674 | + $dates['year'] = date('Y', $current_time); |
|
675 | 675 | break; |
676 | 676 | |
677 | 677 | case 'last_week' : |
678 | - $dates['day'] = date( 'd', $current_time - ( date( 'w' ) - 1 ) * 60 * 60 * 24 ) - 8; |
|
679 | - $dates['day'] += get_option( 'start_of_week' ); |
|
678 | + $dates['day'] = date('d', $current_time - (date('w') - 1) * 60 * 60 * 24) - 8; |
|
679 | + $dates['day'] += get_option('start_of_week'); |
|
680 | 680 | $dates['day_end'] = $dates['day'] + 6; |
681 | - $dates['year'] = date( 'Y' ); |
|
682 | - |
|
683 | - if ( date( 'j', $current_time ) <= 7 ) { |
|
684 | - $dates['m_start'] = date( 'n', $current_time ) - 1; |
|
685 | - $dates['m_end'] = date( 'n', $current_time ) - 1; |
|
686 | - if ( $dates['m_start'] <= 1 ) { |
|
687 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
688 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; |
|
681 | + $dates['year'] = date('Y'); |
|
682 | + |
|
683 | + if (date('j', $current_time) <= 7) { |
|
684 | + $dates['m_start'] = date('n', $current_time) - 1; |
|
685 | + $dates['m_end'] = date('n', $current_time) - 1; |
|
686 | + if ($dates['m_start'] <= 1) { |
|
687 | + $dates['year'] = date('Y', $current_time) - 1; |
|
688 | + $dates['year_end'] = date('Y', $current_time) - 1; |
|
689 | 689 | } |
690 | 690 | } else { |
691 | - $dates['m_start'] = date( 'n', $current_time ); |
|
692 | - $dates['m_end'] = date( 'n', $current_time ); |
|
691 | + $dates['m_start'] = date('n', $current_time); |
|
692 | + $dates['m_end'] = date('n', $current_time); |
|
693 | 693 | } |
694 | 694 | break; |
695 | 695 | |
696 | 696 | case 'this_quarter' : |
697 | - $month_now = date( 'n', $current_time ); |
|
697 | + $month_now = date('n', $current_time); |
|
698 | 698 | |
699 | - if ( $month_now <= 3 ) { |
|
699 | + if ($month_now <= 3) { |
|
700 | 700 | |
701 | 701 | $dates['m_start'] = 1; |
702 | 702 | $dates['m_end'] = 4; |
703 | - $dates['year'] = date( 'Y', $current_time ); |
|
703 | + $dates['year'] = date('Y', $current_time); |
|
704 | 704 | |
705 | - } else if ( $month_now <= 6 ) { |
|
705 | + } else if ($month_now <= 6) { |
|
706 | 706 | |
707 | 707 | $dates['m_start'] = 4; |
708 | 708 | $dates['m_end'] = 7; |
709 | - $dates['year'] = date( 'Y', $current_time ); |
|
709 | + $dates['year'] = date('Y', $current_time); |
|
710 | 710 | |
711 | - } else if ( $month_now <= 9 ) { |
|
711 | + } else if ($month_now <= 9) { |
|
712 | 712 | |
713 | 713 | $dates['m_start'] = 7; |
714 | 714 | $dates['m_end'] = 10; |
715 | - $dates['year'] = date( 'Y', $current_time ); |
|
715 | + $dates['year'] = date('Y', $current_time); |
|
716 | 716 | |
717 | 717 | } else { |
718 | 718 | |
719 | 719 | $dates['m_start'] = 10; |
720 | 720 | $dates['m_end'] = 1; |
721 | - $dates['year'] = date( 'Y', $current_time ); |
|
722 | - $dates['year_end'] = date( 'Y', $current_time ) + 1; |
|
721 | + $dates['year'] = date('Y', $current_time); |
|
722 | + $dates['year_end'] = date('Y', $current_time) + 1; |
|
723 | 723 | |
724 | 724 | } |
725 | 725 | break; |
726 | 726 | |
727 | 727 | case 'last_quarter' : |
728 | - $month_now = date( 'n' ); |
|
728 | + $month_now = date('n'); |
|
729 | 729 | |
730 | - if ( $month_now <= 3 ) { |
|
730 | + if ($month_now <= 3) { |
|
731 | 731 | |
732 | 732 | $dates['m_start'] = 10; |
733 | 733 | $dates['m_end'] = 12; |
734 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
735 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; // Previous year |
|
734 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
735 | + $dates['year_end'] = date('Y', $current_time) - 1; // Previous year |
|
736 | 736 | |
737 | - } else if ( $month_now <= 6 ) { |
|
737 | + } else if ($month_now <= 6) { |
|
738 | 738 | |
739 | 739 | $dates['m_start'] = 1; |
740 | 740 | $dates['m_end'] = 3; |
741 | - $dates['year'] = date( 'Y', $current_time ); |
|
741 | + $dates['year'] = date('Y', $current_time); |
|
742 | 742 | |
743 | - } else if ( $month_now <= 9 ) { |
|
743 | + } else if ($month_now <= 9) { |
|
744 | 744 | |
745 | 745 | $dates['m_start'] = 4; |
746 | 746 | $dates['m_end'] = 6; |
747 | - $dates['year'] = date( 'Y', $current_time ); |
|
747 | + $dates['year'] = date('Y', $current_time); |
|
748 | 748 | |
749 | 749 | } else { |
750 | 750 | |
751 | 751 | $dates['m_start'] = 7; |
752 | 752 | $dates['m_end'] = 9; |
753 | - $dates['year'] = date( 'Y', $current_time ); |
|
753 | + $dates['year'] = date('Y', $current_time); |
|
754 | 754 | |
755 | 755 | } |
756 | 756 | break; |
@@ -758,19 +758,19 @@ discard block |
||
758 | 758 | case 'this_year' : |
759 | 759 | $dates['m_start'] = 1; |
760 | 760 | $dates['m_end'] = 12; |
761 | - $dates['year'] = date( 'Y', $current_time ); |
|
761 | + $dates['year'] = date('Y', $current_time); |
|
762 | 762 | break; |
763 | 763 | |
764 | 764 | case 'last_year' : |
765 | 765 | $dates['m_start'] = 1; |
766 | 766 | $dates['m_end'] = 12; |
767 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
768 | - $dates['year_end'] = date( 'Y', $current_time ) - 1; |
|
767 | + $dates['year'] = date('Y', $current_time) - 1; |
|
768 | + $dates['year_end'] = date('Y', $current_time) - 1; |
|
769 | 769 | break; |
770 | 770 | |
771 | 771 | endswitch; |
772 | 772 | |
773 | - return apply_filters( 'give_report_dates', $dates ); |
|
773 | + return apply_filters('give_report_dates', $dates); |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
@@ -780,17 +780,17 @@ discard block |
||
780 | 780 | * |
781 | 781 | * @param $data |
782 | 782 | */ |
783 | -function give_parse_report_dates( $data ) { |
|
783 | +function give_parse_report_dates($data) { |
|
784 | 784 | $dates = give_get_report_dates(); |
785 | 785 | |
786 | 786 | $view = give_get_reporting_view(); |
787 | - $id = isset( $_GET['form-id'] ) ? $_GET['form-id'] : null; |
|
787 | + $id = isset($_GET['form-id']) ? $_GET['form-id'] : null; |
|
788 | 788 | |
789 | - wp_redirect( add_query_arg( $dates, admin_url( 'edit.php?post_type=give_forms&page=give-reports&view=' . esc_attr( $view ) . '&form-id=' . absint( $id ) ) ) ); |
|
789 | + wp_redirect(add_query_arg($dates, admin_url('edit.php?post_type=give_forms&page=give-reports&view='.esc_attr($view).'&form-id='.absint($id)))); |
|
790 | 790 | give_die(); |
791 | 791 | } |
792 | 792 | |
793 | -add_action( 'give_filter_reports', 'give_parse_report_dates' ); |
|
793 | +add_action('give_filter_reports', 'give_parse_report_dates'); |
|
794 | 794 | |
795 | 795 | |
796 | 796 | /** |
@@ -802,16 +802,16 @@ discard block |
||
802 | 802 | */ |
803 | 803 | function give_reports_refresh_button() { |
804 | 804 | |
805 | - $url = wp_nonce_url( add_query_arg( array( |
|
805 | + $url = wp_nonce_url(add_query_arg(array( |
|
806 | 806 | 'give_action' => 'refresh_reports_transients', |
807 | 807 | 'give-message' => 'refreshed-reports' |
808 | - ) ), 'give-refresh-reports' ); |
|
808 | + )), 'give-refresh-reports'); |
|
809 | 809 | |
810 | - echo '<a href="' . $url . '" data-tooltip="' . esc_attr__( 'Clicking this will clear the reports cache.', 'give' ) . '" data-tooltip-my-position="right center" data-tooltip-target-position="left center" class="button alignright give-refresh-reports-button give-tooltip">' . esc_html__( 'Refresh Reports', 'give' ) . '</a>'; |
|
810 | + echo '<a href="'.$url.'" data-tooltip="'.esc_attr__('Clicking this will clear the reports cache.', 'give').'" data-tooltip-my-position="right center" data-tooltip-target-position="left center" class="button alignright give-refresh-reports-button give-tooltip">'.esc_html__('Refresh Reports', 'give').'</a>'; |
|
811 | 811 | |
812 | 812 | } |
813 | 813 | |
814 | -add_action( 'give_reports_graph_additional_stats', 'give_reports_refresh_button' ); |
|
814 | +add_action('give_reports_graph_additional_stats', 'give_reports_refresh_button'); |
|
815 | 815 | |
816 | 816 | /** |
817 | 817 | * Trigger the refresh of reports transients |
@@ -822,18 +822,18 @@ discard block |
||
822 | 822 | * |
823 | 823 | * @return void |
824 | 824 | */ |
825 | -function give_run_refresh_reports_transients( $data ) { |
|
825 | +function give_run_refresh_reports_transients($data) { |
|
826 | 826 | |
827 | - if ( ! wp_verify_nonce( $data['_wpnonce'], 'give-refresh-reports' ) ) { |
|
827 | + if ( ! wp_verify_nonce($data['_wpnonce'], 'give-refresh-reports')) { |
|
828 | 828 | return; |
829 | 829 | } |
830 | 830 | |
831 | 831 | //Delete transients |
832 | - delete_transient( 'give_estimated_monthly_stats' ); |
|
833 | - delete_transient( 'give_earnings_total' ); |
|
834 | - delete_transient( md5( 'give_earnings_this_monththis_month' ) ); |
|
835 | - delete_transient( md5( 'give_earnings_todaytoday' ) ); |
|
832 | + delete_transient('give_estimated_monthly_stats'); |
|
833 | + delete_transient('give_earnings_total'); |
|
834 | + delete_transient(md5('give_earnings_this_monththis_month')); |
|
835 | + delete_transient(md5('give_earnings_todaytoday')); |
|
836 | 836 | |
837 | 837 | } |
838 | 838 | |
839 | -add_action( 'give_refresh_reports_transients', 'give_run_refresh_reports_transients' ); |
|
840 | 839 | \ No newline at end of file |
840 | +add_action('give_refresh_reports_transients', 'give_run_refresh_reports_transients'); |
|
841 | 841 | \ No newline at end of file |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * |
212 | 212 | * @access public |
213 | 213 | * @since 1.1 |
214 | - * @return array |
|
214 | + * @return string |
|
215 | 215 | */ |
216 | 216 | public function get_versions() { |
217 | 217 | return $this->versions; |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * |
663 | 663 | * @param array $args Arguments to override defaults |
664 | 664 | * |
665 | - * @return array $dates |
|
665 | + * @return integer|null $dates |
|
666 | 666 | */ |
667 | 667 | public function get_dates( $args = array() ) { |
668 | 668 | $dates = array(); |
@@ -1712,7 +1712,7 @@ discard block |
||
1712 | 1712 | * |
1713 | 1713 | * @param int $user_id User ID of user to revoke key for |
1714 | 1714 | * |
1715 | - * @return string |
|
1715 | + * @return boolean |
|
1716 | 1716 | */ |
1717 | 1717 | public function revoke_api_key( $user_id = 0 ) { |
1718 | 1718 |
@@ -1437,7 +1437,7 @@ discard block |
||
1437 | 1437 | * Determines whether results should be displayed in XML or JSON |
1438 | 1438 | * |
1439 | 1439 | * @since 1.1 |
1440 | - * @access public |
|
1440 | + * @access public |
|
1441 | 1441 | * |
1442 | 1442 | * @return mixed|void |
1443 | 1443 | */ |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | * |
1456 | 1456 | * @access private |
1457 | 1457 | * @since 1.1 |
1458 | - * |
|
1458 | + * |
|
1459 | 1459 | * @global Give_Logging $give_logs |
1460 | 1460 | * @global WP_Query $wp_query |
1461 | 1461 | * |
@@ -1468,15 +1468,15 @@ discard block |
||
1468 | 1468 | return; |
1469 | 1469 | } |
1470 | 1470 | |
1471 | - /** |
|
1472 | - * @var Give_Logging $give_logs |
|
1473 | - */ |
|
1471 | + /** |
|
1472 | + * @var Give_Logging $give_logs |
|
1473 | + */ |
|
1474 | 1474 | global $give_logs; |
1475 | 1475 | |
1476 | - /** |
|
1477 | - * @var WP_Query $wp_query |
|
1478 | - */ |
|
1479 | - global $wp_query; |
|
1476 | + /** |
|
1477 | + * @var WP_Query $wp_query |
|
1478 | + */ |
|
1479 | + global $wp_query; |
|
1480 | 1480 | |
1481 | 1481 | $query = array( |
1482 | 1482 | 'give-api' => $wp_query->query_vars['give-api'], |
@@ -1534,9 +1534,9 @@ discard block |
||
1534 | 1534 | * @param int $status_code |
1535 | 1535 | */ |
1536 | 1536 | public function output( $status_code = 200 ) { |
1537 | - /** |
|
1538 | - * @var WP_Query $wp_query |
|
1539 | - */ |
|
1537 | + /** |
|
1538 | + * @var WP_Query $wp_query |
|
1539 | + */ |
|
1540 | 1540 | global $wp_query; |
1541 | 1541 | |
1542 | 1542 | $format = $this->get_output_format(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -140,27 +140,27 @@ discard block |
||
140 | 140 | 'v1' => 'GIVE_API_V1', |
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( $this->get_versions() as $version => $class ) { |
|
144 | - require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api-' . $version . '.php'; |
|
143 | + foreach ($this->get_versions() as $version => $class) { |
|
144 | + require_once GIVE_PLUGIN_DIR.'includes/api/class-give-api-'.$version.'.php'; |
|
145 | 145 | } |
146 | 146 | |
147 | - add_action( 'init', array( $this, 'add_endpoint' ) ); |
|
148 | - add_action( 'wp', array( $this, 'process_query' ), - 1 ); |
|
149 | - add_filter( 'query_vars', array( $this, 'query_vars' ) ); |
|
150 | - add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); |
|
151 | - add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); |
|
152 | - add_action( 'personal_options_update', array( $this, 'update_key' ) ); |
|
153 | - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); |
|
154 | - add_action( 'give_process_api_key', array( $this, 'process_api_key' ) ); |
|
147 | + add_action('init', array($this, 'add_endpoint')); |
|
148 | + add_action('wp', array($this, 'process_query'), - 1); |
|
149 | + add_filter('query_vars', array($this, 'query_vars')); |
|
150 | + add_action('show_user_profile', array($this, 'user_key_field')); |
|
151 | + add_action('edit_user_profile', array($this, 'user_key_field')); |
|
152 | + add_action('personal_options_update', array($this, 'update_key')); |
|
153 | + add_action('edit_user_profile_update', array($this, 'update_key')); |
|
154 | + add_action('give_process_api_key', array($this, 'process_api_key')); |
|
155 | 155 | |
156 | 156 | // Setup a backwards compatibility check for user API Keys |
157 | - add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); |
|
157 | + add_filter('get_user_metadata', array($this, 'api_key_backwards_compat'), 10, 4); |
|
158 | 158 | |
159 | 159 | // Determine if JSON_PRETTY_PRINT is available |
160 | - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
|
160 | + $this->pretty_print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : null; |
|
161 | 161 | |
162 | 162 | // Allow API request logging to be turned off |
163 | - $this->log_requests = apply_filters( 'give_api_log_requests', $this->log_requests ); |
|
163 | + $this->log_requests = apply_filters('give_api_log_requests', $this->log_requests); |
|
164 | 164 | |
165 | 165 | // Setup Give_Payment_Stats instance |
166 | 166 | $this->stats = new Give_Payment_Stats; |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @since 1.1 |
178 | 178 | */ |
179 | - public function add_endpoint( $rewrite_rules ) { |
|
180 | - add_rewrite_endpoint( 'give-api', EP_ALL ); |
|
179 | + public function add_endpoint($rewrite_rules) { |
|
180 | + add_rewrite_endpoint('give-api', EP_ALL); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string[] $vars New query vars |
192 | 192 | */ |
193 | - public function query_vars( $vars ) { |
|
193 | + public function query_vars($vars) { |
|
194 | 194 | |
195 | 195 | $vars[] = 'token'; |
196 | 196 | $vars[] = 'key'; |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function get_default_version() { |
243 | 243 | |
244 | - $version = get_option( 'give_default_api_version' ); |
|
244 | + $version = get_option('give_default_api_version'); |
|
245 | 245 | |
246 | - if ( defined( 'GIVE_API_VERSION' ) ) { |
|
246 | + if (defined('GIVE_API_VERSION')) { |
|
247 | 247 | $version = GIVE_API_VERSION; |
248 | - } elseif ( ! $version ) { |
|
248 | + } elseif ( ! $version) { |
|
249 | 249 | $version = 'v1'; |
250 | 250 | } |
251 | 251 | |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | |
267 | 267 | $version = $wp_query->query_vars['give-api']; |
268 | 268 | |
269 | - if ( strpos( $version, '/' ) ) { |
|
269 | + if (strpos($version, '/')) { |
|
270 | 270 | |
271 | - $version = explode( '/', $version ); |
|
272 | - $version = strtolower( $version[0] ); |
|
271 | + $version = explode('/', $version); |
|
272 | + $version = strtolower($version[0]); |
|
273 | 273 | |
274 | - $wp_query->query_vars['give-api'] = str_replace( $version . '/', '', $wp_query->query_vars['give-api'] ); |
|
274 | + $wp_query->query_vars['give-api'] = str_replace($version.'/', '', $wp_query->query_vars['give-api']); |
|
275 | 275 | |
276 | - if ( array_key_exists( $version, $this->versions ) ) { |
|
276 | + if (array_key_exists($version, $this->versions)) { |
|
277 | 277 | |
278 | 278 | $this->queried_version = $version; |
279 | 279 | |
@@ -310,32 +310,32 @@ discard block |
||
310 | 310 | $this->override = false; |
311 | 311 | |
312 | 312 | // Make sure we have both user and api key |
313 | - if ( ! empty( $wp_query->query_vars['give-api'] ) && ( $wp_query->query_vars['give-api'] != 'forms' || ! empty( $wp_query->query_vars['token'] ) ) ) { |
|
313 | + if ( ! empty($wp_query->query_vars['give-api']) && ($wp_query->query_vars['give-api'] != 'forms' || ! empty($wp_query->query_vars['token']))) { |
|
314 | 314 | |
315 | - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) { |
|
315 | + if (empty($wp_query->query_vars['token']) || empty($wp_query->query_vars['key'])) { |
|
316 | 316 | $this->missing_auth(); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Retrieve the user by public API key and ensure they exist |
320 | - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) { |
|
320 | + if ( ! ($user = $this->get_user($wp_query->query_vars['key']))) { |
|
321 | 321 | |
322 | 322 | $this->invalid_key(); |
323 | 323 | |
324 | 324 | } else { |
325 | 325 | |
326 | - $token = urldecode( $wp_query->query_vars['token'] ); |
|
327 | - $secret = $this->get_user_secret_key( $user ); |
|
328 | - $public = urldecode( $wp_query->query_vars['key'] ); |
|
326 | + $token = urldecode($wp_query->query_vars['token']); |
|
327 | + $secret = $this->get_user_secret_key($user); |
|
328 | + $public = urldecode($wp_query->query_vars['key']); |
|
329 | 329 | |
330 | - if ( hash_equals( md5( $secret . $public ), $token ) ) { |
|
330 | + if (hash_equals(md5($secret.$public), $token)) { |
|
331 | 331 | $this->is_valid_request = true; |
332 | 332 | } else { |
333 | 333 | $this->invalid_auth(); |
334 | 334 | } |
335 | 335 | } |
336 | - } elseif ( ! empty( $wp_query->query_vars['give-api'] ) && $wp_query->query_vars['give-api'] == 'forms' ) { |
|
336 | + } elseif ( ! empty($wp_query->query_vars['give-api']) && $wp_query->query_vars['give-api'] == 'forms') { |
|
337 | 337 | $this->is_valid_request = true; |
338 | - $wp_query->set( 'key', 'public' ); |
|
338 | + $wp_query->set('key', 'public'); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
@@ -351,25 +351,25 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @return bool if user ID is found, false otherwise |
353 | 353 | */ |
354 | - public function get_user( $key = '' ) { |
|
354 | + public function get_user($key = '') { |
|
355 | 355 | global $wpdb, $wp_query; |
356 | 356 | |
357 | - if ( empty( $key ) ) { |
|
358 | - $key = urldecode( $wp_query->query_vars['key'] ); |
|
357 | + if (empty($key)) { |
|
358 | + $key = urldecode($wp_query->query_vars['key']); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( empty( $key ) ) { |
|
361 | + if (empty($key)) { |
|
362 | 362 | return false; |
363 | 363 | } |
364 | 364 | |
365 | - $user = get_transient( md5( 'give_api_user_' . $key ) ); |
|
365 | + $user = get_transient(md5('give_api_user_'.$key)); |
|
366 | 366 | |
367 | - if ( false === $user ) { |
|
368 | - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); |
|
369 | - set_transient( md5( 'give_api_user_' . $key ), $user, DAY_IN_SECONDS ); |
|
367 | + if (false === $user) { |
|
368 | + $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key)); |
|
369 | + set_transient(md5('give_api_user_'.$key), $user, DAY_IN_SECONDS); |
|
370 | 370 | } |
371 | 371 | |
372 | - if ( $user != null ) { |
|
372 | + if ($user != null) { |
|
373 | 373 | $this->user_id = $user; |
374 | 374 | |
375 | 375 | return $user; |
@@ -378,37 +378,37 @@ discard block |
||
378 | 378 | return false; |
379 | 379 | } |
380 | 380 | |
381 | - public function get_user_public_key( $user_id = 0 ) { |
|
381 | + public function get_user_public_key($user_id = 0) { |
|
382 | 382 | global $wpdb; |
383 | 383 | |
384 | - if ( empty( $user_id ) ) { |
|
384 | + if (empty($user_id)) { |
|
385 | 385 | return ''; |
386 | 386 | } |
387 | 387 | |
388 | - $cache_key = md5( 'give_api_user_public_key' . $user_id ); |
|
389 | - $user_public_key = get_transient( $cache_key ); |
|
388 | + $cache_key = md5('give_api_user_public_key'.$user_id); |
|
389 | + $user_public_key = get_transient($cache_key); |
|
390 | 390 | |
391 | - if ( empty( $user_public_key ) ) { |
|
392 | - $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id ) ); |
|
393 | - set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); |
|
391 | + if (empty($user_public_key)) { |
|
392 | + $user_public_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_public_key' AND user_id = %d", $user_id)); |
|
393 | + set_transient($cache_key, $user_public_key, HOUR_IN_SECONDS); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return $user_public_key; |
397 | 397 | } |
398 | 398 | |
399 | - public function get_user_secret_key( $user_id = 0 ) { |
|
399 | + public function get_user_secret_key($user_id = 0) { |
|
400 | 400 | global $wpdb; |
401 | 401 | |
402 | - if ( empty( $user_id ) ) { |
|
402 | + if (empty($user_id)) { |
|
403 | 403 | return ''; |
404 | 404 | } |
405 | 405 | |
406 | - $cache_key = md5( 'give_api_user_secret_key' . $user_id ); |
|
407 | - $user_secret_key = get_transient( $cache_key ); |
|
406 | + $cache_key = md5('give_api_user_secret_key'.$user_id); |
|
407 | + $user_secret_key = get_transient($cache_key); |
|
408 | 408 | |
409 | - if ( empty( $user_secret_key ) ) { |
|
410 | - $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id ) ); |
|
411 | - set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); |
|
409 | + if (empty($user_secret_key)) { |
|
410 | + $user_secret_key = $wpdb->get_var($wpdb->prepare("SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'give_user_secret_key' AND user_id = %d", $user_id)); |
|
411 | + set_transient($cache_key, $user_secret_key, HOUR_IN_SECONDS); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | return $user_secret_key; |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | */ |
425 | 425 | private function missing_auth() { |
426 | 426 | $error = array(); |
427 | - $error['error'] = esc_html__( 'You must specify both a token and API key.', 'give' ); |
|
427 | + $error['error'] = esc_html__('You must specify both a token and API key.', 'give'); |
|
428 | 428 | |
429 | 429 | $this->data = $error; |
430 | - $this->output( 401 ); |
|
430 | + $this->output(401); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -441,10 +441,10 @@ discard block |
||
441 | 441 | */ |
442 | 442 | private function invalid_auth() { |
443 | 443 | $error = array(); |
444 | - $error['error'] = esc_html__( 'Your request could not be authenticated.', 'give' ); |
|
444 | + $error['error'] = esc_html__('Your request could not be authenticated.', 'give'); |
|
445 | 445 | |
446 | 446 | $this->data = $error; |
447 | - $this->output( 403 ); |
|
447 | + $this->output(403); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | */ |
459 | 459 | private function invalid_key() { |
460 | 460 | $error = array(); |
461 | - $error['error'] = esc_html__( 'Invalid API key.', 'give' ); |
|
461 | + $error['error'] = esc_html__('Invalid API key.', 'give'); |
|
462 | 462 | |
463 | 463 | $this->data = $error; |
464 | - $this->output( 403 ); |
|
464 | + $this->output(403); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -474,10 +474,10 @@ discard block |
||
474 | 474 | */ |
475 | 475 | private function invalid_version() { |
476 | 476 | $error = array(); |
477 | - $error['error'] = esc_html__( 'Invalid API version.', 'give' ); |
|
477 | + $error['error'] = esc_html__('Invalid API version.', 'give'); |
|
478 | 478 | |
479 | 479 | $this->data = $error; |
480 | - $this->output( 404 ); |
|
480 | + $this->output(404); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -493,10 +493,10 @@ discard block |
||
493 | 493 | global $wp_query; |
494 | 494 | |
495 | 495 | // Start logging how long the request takes for logging |
496 | - $before = microtime( true ); |
|
496 | + $before = microtime(true); |
|
497 | 497 | |
498 | 498 | // Check for give-api var. Get out if not present |
499 | - if ( empty( $wp_query->query_vars['give-api'] ) ) { |
|
499 | + if (empty($wp_query->query_vars['give-api'])) { |
|
500 | 500 | return; |
501 | 501 | } |
502 | 502 | |
@@ -510,45 +510,45 @@ discard block |
||
510 | 510 | $this->validate_request(); |
511 | 511 | |
512 | 512 | // Only proceed if no errors have been noted |
513 | - if ( ! $this->is_valid_request ) { |
|
513 | + if ( ! $this->is_valid_request) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - if ( ! defined( 'GIVE_DOING_API' ) ) { |
|
518 | - define( 'GIVE_DOING_API', true ); |
|
517 | + if ( ! defined('GIVE_DOING_API')) { |
|
518 | + define('GIVE_DOING_API', true); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | $data = array(); |
522 | 522 | $this->routes = new $this->versions[$this->get_queried_version()]; |
523 | 523 | $this->routes->validate_request(); |
524 | 524 | |
525 | - switch ( $this->endpoint ) : |
|
525 | + switch ($this->endpoint) : |
|
526 | 526 | |
527 | 527 | case 'stats' : |
528 | 528 | |
529 | - $data = $this->routes->get_stats( array( |
|
530 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
531 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
532 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
533 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
534 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null |
|
535 | - ) ); |
|
529 | + $data = $this->routes->get_stats(array( |
|
530 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
531 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
532 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
533 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
534 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null |
|
535 | + )); |
|
536 | 536 | |
537 | 537 | break; |
538 | 538 | |
539 | 539 | case 'forms' : |
540 | 540 | |
541 | - $form = isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null; |
|
541 | + $form = isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null; |
|
542 | 542 | |
543 | - $data = $this->routes->get_forms( $form ); |
|
543 | + $data = $this->routes->get_forms($form); |
|
544 | 544 | |
545 | 545 | break; |
546 | 546 | |
547 | 547 | case 'donors' : |
548 | 548 | |
549 | - $customer = isset( $wp_query->query_vars['donor'] ) ? $wp_query->query_vars['donor'] : null; |
|
549 | + $customer = isset($wp_query->query_vars['donor']) ? $wp_query->query_vars['donor'] : null; |
|
550 | 550 | |
551 | - $data = $this->routes->get_customers( $customer ); |
|
551 | + $data = $this->routes->get_customers($customer); |
|
552 | 552 | |
553 | 553 | break; |
554 | 554 | |
@@ -561,14 +561,14 @@ discard block |
||
561 | 561 | endswitch; |
562 | 562 | |
563 | 563 | // Allow extensions to setup their own return data |
564 | - $this->data = apply_filters( 'give_api_output_data', $data, $this->endpoint, $this ); |
|
564 | + $this->data = apply_filters('give_api_output_data', $data, $this->endpoint, $this); |
|
565 | 565 | |
566 | - $after = microtime( true ); |
|
567 | - $request_time = ( $after - $before ); |
|
566 | + $after = microtime(true); |
|
567 | + $request_time = ($after - $before); |
|
568 | 568 | $this->data['request_speed'] = $request_time; |
569 | 569 | |
570 | 570 | // Log this API request, if enabled. We log it here because we have access to errors. |
571 | - $this->log_request( $this->data ); |
|
571 | + $this->log_request($this->data); |
|
572 | 572 | |
573 | 573 | // Send out data to the output function |
574 | 574 | $this->output(); |
@@ -598,25 +598,25 @@ discard block |
||
598 | 598 | global $wp_query; |
599 | 599 | |
600 | 600 | // Whitelist our query options |
601 | - $accepted = apply_filters( 'give_api_valid_query_modes', array( |
|
601 | + $accepted = apply_filters('give_api_valid_query_modes', array( |
|
602 | 602 | 'stats', |
603 | 603 | 'forms', |
604 | 604 | 'donors', |
605 | 605 | 'donations' |
606 | - ) ); |
|
606 | + )); |
|
607 | 607 | |
608 | - $query = isset( $wp_query->query_vars['give-api'] ) ? $wp_query->query_vars['give-api'] : null; |
|
609 | - $query = str_replace( $this->queried_version . '/', '', $query ); |
|
608 | + $query = isset($wp_query->query_vars['give-api']) ? $wp_query->query_vars['give-api'] : null; |
|
609 | + $query = str_replace($this->queried_version.'/', '', $query); |
|
610 | 610 | |
611 | 611 | $error = array(); |
612 | 612 | |
613 | 613 | // Make sure our query is valid |
614 | - if ( ! in_array( $query, $accepted ) ) { |
|
615 | - $error['error'] = esc_html__( 'Invalid query.', 'give' ); |
|
614 | + if ( ! in_array($query, $accepted)) { |
|
615 | + $error['error'] = esc_html__('Invalid query.', 'give'); |
|
616 | 616 | |
617 | 617 | $this->data = $error; |
618 | 618 | // 400 is Bad Request |
619 | - $this->output( 400 ); |
|
619 | + $this->output(400); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | $this->endpoint = $query; |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | public function get_paged() { |
634 | 634 | global $wp_query; |
635 | 635 | |
636 | - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; |
|
636 | + return isset($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | |
@@ -648,13 +648,13 @@ discard block |
||
648 | 648 | public function per_page() { |
649 | 649 | global $wp_query; |
650 | 650 | |
651 | - $per_page = isset( $wp_query->query_vars['number'] ) ? $wp_query->query_vars['number'] : 10; |
|
651 | + $per_page = isset($wp_query->query_vars['number']) ? $wp_query->query_vars['number'] : 10; |
|
652 | 652 | |
653 | - if ( $per_page < 0 && $this->get_query_mode() == 'donors' ) { |
|
653 | + if ($per_page < 0 && $this->get_query_mode() == 'donors') { |
|
654 | 654 | $per_page = 99999999; |
655 | 655 | } // Customers query doesn't support -1 |
656 | 656 | |
657 | - return apply_filters( 'give_api_results_per_page', $per_page ); |
|
657 | + return apply_filters('give_api_results_per_page', $per_page); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | * |
668 | 668 | * @return array $dates |
669 | 669 | */ |
670 | - public function get_dates( $args = array() ) { |
|
670 | + public function get_dates($args = array()) { |
|
671 | 671 | $dates = array(); |
672 | 672 | |
673 | 673 | $defaults = array( |
@@ -678,60 +678,60 @@ discard block |
||
678 | 678 | 'enddate' => null |
679 | 679 | ); |
680 | 680 | |
681 | - $args = wp_parse_args( $args, $defaults ); |
|
681 | + $args = wp_parse_args($args, $defaults); |
|
682 | 682 | |
683 | - $current_time = current_time( 'timestamp' ); |
|
683 | + $current_time = current_time('timestamp'); |
|
684 | 684 | |
685 | - if ( 'range' === $args['date'] ) { |
|
686 | - $startdate = strtotime( $args['startdate'] ); |
|
687 | - $enddate = strtotime( $args['enddate'] ); |
|
688 | - $dates['day_start'] = date( 'd', $startdate ); |
|
689 | - $dates['day_end'] = date( 'd', $enddate ); |
|
690 | - $dates['m_start'] = date( 'n', $startdate ); |
|
691 | - $dates['m_end'] = date( 'n', $enddate ); |
|
692 | - $dates['year'] = date( 'Y', $startdate ); |
|
693 | - $dates['year_end'] = date( 'Y', $enddate ); |
|
685 | + if ('range' === $args['date']) { |
|
686 | + $startdate = strtotime($args['startdate']); |
|
687 | + $enddate = strtotime($args['enddate']); |
|
688 | + $dates['day_start'] = date('d', $startdate); |
|
689 | + $dates['day_end'] = date('d', $enddate); |
|
690 | + $dates['m_start'] = date('n', $startdate); |
|
691 | + $dates['m_end'] = date('n', $enddate); |
|
692 | + $dates['year'] = date('Y', $startdate); |
|
693 | + $dates['year_end'] = date('Y', $enddate); |
|
694 | 694 | } else { |
695 | 695 | // Modify dates based on predefined ranges |
696 | - switch ( $args['date'] ) : |
|
696 | + switch ($args['date']) : |
|
697 | 697 | |
698 | 698 | case 'this_month' : |
699 | 699 | $dates['day'] = null; |
700 | - $dates['m_start'] = date( 'n', $current_time ); |
|
701 | - $dates['m_end'] = date( 'n', $current_time ); |
|
702 | - $dates['year'] = date( 'Y', $current_time ); |
|
700 | + $dates['m_start'] = date('n', $current_time); |
|
701 | + $dates['m_end'] = date('n', $current_time); |
|
702 | + $dates['year'] = date('Y', $current_time); |
|
703 | 703 | break; |
704 | 704 | |
705 | 705 | case 'last_month' : |
706 | 706 | $dates['day'] = null; |
707 | - $dates['m_start'] = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1; |
|
707 | + $dates['m_start'] = date('n', $current_time) == 1 ? 12 : date('n', $current_time) - 1; |
|
708 | 708 | $dates['m_end'] = $dates['m_start']; |
709 | - $dates['year'] = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time ); |
|
709 | + $dates['year'] = date('n', $current_time) == 1 ? date('Y', $current_time) - 1 : date('Y', $current_time); |
|
710 | 710 | break; |
711 | 711 | |
712 | 712 | case 'today' : |
713 | - $dates['day'] = date( 'd', $current_time ); |
|
714 | - $dates['m_start'] = date( 'n', $current_time ); |
|
715 | - $dates['m_end'] = date( 'n', $current_time ); |
|
716 | - $dates['year'] = date( 'Y', $current_time ); |
|
713 | + $dates['day'] = date('d', $current_time); |
|
714 | + $dates['m_start'] = date('n', $current_time); |
|
715 | + $dates['m_end'] = date('n', $current_time); |
|
716 | + $dates['year'] = date('Y', $current_time); |
|
717 | 717 | break; |
718 | 718 | |
719 | 719 | case 'yesterday' : |
720 | 720 | |
721 | - $year = date( 'Y', $current_time ); |
|
722 | - $month = date( 'n', $current_time ); |
|
723 | - $day = date( 'd', $current_time ); |
|
721 | + $year = date('Y', $current_time); |
|
722 | + $month = date('n', $current_time); |
|
723 | + $day = date('d', $current_time); |
|
724 | 724 | |
725 | - if ( $month == 1 && $day == 1 ) { |
|
725 | + if ($month == 1 && $day == 1) { |
|
726 | 726 | |
727 | 727 | $year -= 1; |
728 | 728 | $month = 12; |
729 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
729 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
730 | 730 | |
731 | - } elseif ( $month > 1 && $day == 1 ) { |
|
731 | + } elseif ($month > 1 && $day == 1) { |
|
732 | 732 | |
733 | 733 | $month -= 1; |
734 | - $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); |
|
734 | + $day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
|
735 | 735 | |
736 | 736 | } else { |
737 | 737 | |
@@ -747,65 +747,65 @@ discard block |
||
747 | 747 | break; |
748 | 748 | |
749 | 749 | case 'this_quarter' : |
750 | - $month_now = date( 'n', $current_time ); |
|
750 | + $month_now = date('n', $current_time); |
|
751 | 751 | |
752 | 752 | $dates['day'] = null; |
753 | 753 | |
754 | - if ( $month_now <= 3 ) { |
|
754 | + if ($month_now <= 3) { |
|
755 | 755 | |
756 | 756 | $dates['m_start'] = 1; |
757 | 757 | $dates['m_end'] = 3; |
758 | - $dates['year'] = date( 'Y', $current_time ); |
|
758 | + $dates['year'] = date('Y', $current_time); |
|
759 | 759 | |
760 | - } else if ( $month_now <= 6 ) { |
|
760 | + } else if ($month_now <= 6) { |
|
761 | 761 | |
762 | 762 | $dates['m_start'] = 4; |
763 | 763 | $dates['m_end'] = 6; |
764 | - $dates['year'] = date( 'Y', $current_time ); |
|
764 | + $dates['year'] = date('Y', $current_time); |
|
765 | 765 | |
766 | - } else if ( $month_now <= 9 ) { |
|
766 | + } else if ($month_now <= 9) { |
|
767 | 767 | |
768 | 768 | $dates['m_start'] = 7; |
769 | 769 | $dates['m_end'] = 9; |
770 | - $dates['year'] = date( 'Y', $current_time ); |
|
770 | + $dates['year'] = date('Y', $current_time); |
|
771 | 771 | |
772 | 772 | } else { |
773 | 773 | |
774 | 774 | $dates['m_start'] = 10; |
775 | 775 | $dates['m_end'] = 12; |
776 | - $dates['year'] = date( 'Y', $current_time ); |
|
776 | + $dates['year'] = date('Y', $current_time); |
|
777 | 777 | |
778 | 778 | } |
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'last_quarter' : |
782 | - $month_now = date( 'n', $current_time ); |
|
782 | + $month_now = date('n', $current_time); |
|
783 | 783 | |
784 | 784 | $dates['day'] = null; |
785 | 785 | |
786 | - if ( $month_now <= 3 ) { |
|
786 | + if ($month_now <= 3) { |
|
787 | 787 | |
788 | 788 | $dates['m_start'] = 10; |
789 | 789 | $dates['m_end'] = 12; |
790 | - $dates['year'] = date( 'Y', $current_time ) - 1; // Previous year |
|
790 | + $dates['year'] = date('Y', $current_time) - 1; // Previous year |
|
791 | 791 | |
792 | - } else if ( $month_now <= 6 ) { |
|
792 | + } else if ($month_now <= 6) { |
|
793 | 793 | |
794 | 794 | $dates['m_start'] = 1; |
795 | 795 | $dates['m_end'] = 3; |
796 | - $dates['year'] = date( 'Y', $current_time ); |
|
796 | + $dates['year'] = date('Y', $current_time); |
|
797 | 797 | |
798 | - } else if ( $month_now <= 9 ) { |
|
798 | + } else if ($month_now <= 9) { |
|
799 | 799 | |
800 | 800 | $dates['m_start'] = 4; |
801 | 801 | $dates['m_end'] = 6; |
802 | - $dates['year'] = date( 'Y', $current_time ); |
|
802 | + $dates['year'] = date('Y', $current_time); |
|
803 | 803 | |
804 | 804 | } else { |
805 | 805 | |
806 | 806 | $dates['m_start'] = 7; |
807 | 807 | $dates['m_end'] = 9; |
808 | - $dates['year'] = date( 'Y', $current_time ); |
|
808 | + $dates['year'] = date('Y', $current_time); |
|
809 | 809 | |
810 | 810 | } |
811 | 811 | break; |
@@ -814,14 +814,14 @@ discard block |
||
814 | 814 | $dates['day'] = null; |
815 | 815 | $dates['m_start'] = null; |
816 | 816 | $dates['m_end'] = null; |
817 | - $dates['year'] = date( 'Y', $current_time ); |
|
817 | + $dates['year'] = date('Y', $current_time); |
|
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'last_year' : |
821 | 821 | $dates['day'] = null; |
822 | 822 | $dates['m_start'] = null; |
823 | 823 | $dates['m_end'] = null; |
824 | - $dates['year'] = date( 'Y', $current_time ) - 1; |
|
824 | + $dates['year'] = date('Y', $current_time) - 1; |
|
825 | 825 | break; |
826 | 826 | |
827 | 827 | endswitch; |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @param object $dates The dates used for retrieving earnings/donations |
836 | 836 | */ |
837 | 837 | |
838 | - return apply_filters( 'give_api_stat_dates', $dates ); |
|
838 | + return apply_filters('give_api_stat_dates', $dates); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -850,11 +850,11 @@ discard block |
||
850 | 850 | * |
851 | 851 | * @return array $customers Multidimensional array of the customers |
852 | 852 | */ |
853 | - public function get_customers( $customer = null ) { |
|
853 | + public function get_customers($customer = null) { |
|
854 | 854 | |
855 | 855 | $customers = array(); |
856 | 856 | $error = array(); |
857 | - if ( ! user_can( $this->user_id, 'view_give_sensitive_data' ) && ! $this->override ) { |
|
857 | + if ( ! user_can($this->user_id, 'view_give_sensitive_data') && ! $this->override) { |
|
858 | 858 | return $customers; |
859 | 859 | } |
860 | 860 | |
@@ -862,64 +862,64 @@ discard block |
||
862 | 862 | |
863 | 863 | $paged = $this->get_paged(); |
864 | 864 | $per_page = $this->per_page(); |
865 | - $offset = $per_page * ( $paged - 1 ); |
|
865 | + $offset = $per_page * ($paged - 1); |
|
866 | 866 | |
867 | - if ( is_numeric( $customer ) ) { |
|
867 | + if (is_numeric($customer)) { |
|
868 | 868 | $field = 'id'; |
869 | 869 | } else { |
870 | 870 | $field = 'email'; |
871 | 871 | } |
872 | 872 | |
873 | - $customer_query = Give()->customers->get_customers( array( |
|
873 | + $customer_query = Give()->customers->get_customers(array( |
|
874 | 874 | 'number' => $per_page, |
875 | 875 | 'offset' => $offset, |
876 | 876 | $field => $customer |
877 | - ) ); |
|
877 | + )); |
|
878 | 878 | $customer_count = 0; |
879 | 879 | |
880 | - if ( $customer_query ) { |
|
880 | + if ($customer_query) { |
|
881 | 881 | |
882 | - foreach ( $customer_query as $customer_obj ) { |
|
882 | + foreach ($customer_query as $customer_obj) { |
|
883 | 883 | |
884 | - $names = explode( ' ', $customer_obj->name ); |
|
885 | - $first_name = ! empty( $names[0] ) ? $names[0] : ''; |
|
884 | + $names = explode(' ', $customer_obj->name); |
|
885 | + $first_name = ! empty($names[0]) ? $names[0] : ''; |
|
886 | 886 | $last_name = ''; |
887 | - if ( ! empty( $names[1] ) ) { |
|
888 | - unset( $names[0] ); |
|
889 | - $last_name = implode( ' ', $names ); |
|
887 | + if ( ! empty($names[1])) { |
|
888 | + unset($names[0]); |
|
889 | + $last_name = implode(' ', $names); |
|
890 | 890 | } |
891 | 891 | |
892 | - $customers['donors'][ $customer_count ]['info']['user_id'] = ''; |
|
893 | - $customers['donors'][ $customer_count ]['info']['username'] = ''; |
|
894 | - $customers['donors'][ $customer_count ]['info']['display_name'] = ''; |
|
895 | - $customers['donors'][ $customer_count ]['info']['customer_id'] = $customer_obj->id; |
|
896 | - $customers['donors'][ $customer_count ]['info']['first_name'] = $first_name; |
|
897 | - $customers['donors'][ $customer_count ]['info']['last_name'] = $last_name; |
|
898 | - $customers['donors'][ $customer_count ]['info']['email'] = $customer_obj->email; |
|
892 | + $customers['donors'][$customer_count]['info']['user_id'] = ''; |
|
893 | + $customers['donors'][$customer_count]['info']['username'] = ''; |
|
894 | + $customers['donors'][$customer_count]['info']['display_name'] = ''; |
|
895 | + $customers['donors'][$customer_count]['info']['customer_id'] = $customer_obj->id; |
|
896 | + $customers['donors'][$customer_count]['info']['first_name'] = $first_name; |
|
897 | + $customers['donors'][$customer_count]['info']['last_name'] = $last_name; |
|
898 | + $customers['donors'][$customer_count]['info']['email'] = $customer_obj->email; |
|
899 | 899 | |
900 | - if ( ! empty( $customer_obj->user_id ) ) { |
|
900 | + if ( ! empty($customer_obj->user_id)) { |
|
901 | 901 | |
902 | - $user_data = get_userdata( $customer_obj->user_id ); |
|
902 | + $user_data = get_userdata($customer_obj->user_id); |
|
903 | 903 | |
904 | 904 | // Customer with registered account |
905 | - $customers['donors'][ $customer_count ]['info']['user_id'] = $customer_obj->user_id; |
|
906 | - $customers['donors'][ $customer_count ]['info']['username'] = $user_data->user_login; |
|
907 | - $customers['donors'][ $customer_count ]['info']['display_name'] = $user_data->display_name; |
|
905 | + $customers['donors'][$customer_count]['info']['user_id'] = $customer_obj->user_id; |
|
906 | + $customers['donors'][$customer_count]['info']['username'] = $user_data->user_login; |
|
907 | + $customers['donors'][$customer_count]['info']['display_name'] = $user_data->display_name; |
|
908 | 908 | |
909 | 909 | } |
910 | 910 | |
911 | - $customers['donors'][ $customer_count ]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
912 | - $customers['donors'][ $customer_count ]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
911 | + $customers['donors'][$customer_count]['stats']['total_donations'] = $customer_obj->purchase_count; |
|
912 | + $customers['donors'][$customer_count]['stats']['total_spent'] = $customer_obj->purchase_value; |
|
913 | 913 | |
914 | - $customer_count ++; |
|
914 | + $customer_count++; |
|
915 | 915 | |
916 | 916 | } |
917 | 917 | |
918 | - } elseif ( $customer ) { |
|
918 | + } elseif ($customer) { |
|
919 | 919 | |
920 | 920 | $error['error'] = sprintf( |
921 | 921 | /* translators: %s: customer */ |
922 | - esc_html__( 'Donor %s not found.', 'give' ), |
|
922 | + esc_html__('Donor %s not found.', 'give'), |
|
923 | 923 | $customer |
924 | 924 | ); |
925 | 925 | |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | |
928 | 928 | } else { |
929 | 929 | |
930 | - $error['error'] = esc_html__( 'No donors found.', 'give' ); |
|
930 | + $error['error'] = esc_html__('No donors found.', 'give'); |
|
931 | 931 | |
932 | 932 | return $error; |
933 | 933 | |
@@ -946,38 +946,38 @@ discard block |
||
946 | 946 | * |
947 | 947 | * @return array $customers Multidimensional array of the forms |
948 | 948 | */ |
949 | - public function get_forms( $form = null ) { |
|
949 | + public function get_forms($form = null) { |
|
950 | 950 | |
951 | 951 | $forms = array(); |
952 | 952 | $error = array(); |
953 | 953 | |
954 | - if ( $form == null ) { |
|
954 | + if ($form == null) { |
|
955 | 955 | $forms['forms'] = array(); |
956 | 956 | |
957 | - $form_list = get_posts( array( |
|
957 | + $form_list = get_posts(array( |
|
958 | 958 | 'post_type' => 'give_forms', |
959 | 959 | 'posts_per_page' => $this->per_page(), |
960 | 960 | 'suppress_filters' => true, |
961 | 961 | 'paged' => $this->get_paged() |
962 | - ) ); |
|
962 | + )); |
|
963 | 963 | |
964 | - if ( $form_list ) { |
|
964 | + if ($form_list) { |
|
965 | 965 | $i = 0; |
966 | - foreach ( $form_list as $form_info ) { |
|
967 | - $forms['forms'][ $i ] = $this->get_form_data( $form_info ); |
|
968 | - $i ++; |
|
966 | + foreach ($form_list as $form_info) { |
|
967 | + $forms['forms'][$i] = $this->get_form_data($form_info); |
|
968 | + $i++; |
|
969 | 969 | } |
970 | 970 | } |
971 | 971 | } else { |
972 | - if ( get_post_type( $form ) == 'give_forms' ) { |
|
973 | - $form_info = get_post( $form ); |
|
972 | + if (get_post_type($form) == 'give_forms') { |
|
973 | + $form_info = get_post($form); |
|
974 | 974 | |
975 | - $forms['forms'][0] = $this->get_form_data( $form_info ); |
|
975 | + $forms['forms'][0] = $this->get_form_data($form_info); |
|
976 | 976 | |
977 | 977 | } else { |
978 | 978 | $error['error'] = sprintf( |
979 | 979 | /* translators: %s: form */ |
980 | - esc_html__( 'Form %s not found.', 'give' ), |
|
980 | + esc_html__('Form %s not found.', 'give'), |
|
981 | 981 | $form |
982 | 982 | ); |
983 | 983 | |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | * |
998 | 998 | * @return array Array of post data to return back in the API |
999 | 999 | */ |
1000 | - private function get_form_data( $form_info ) { |
|
1000 | + private function get_form_data($form_info) { |
|
1001 | 1001 | |
1002 | 1002 | $form = array(); |
1003 | 1003 | |
@@ -1007,50 +1007,50 @@ discard block |
||
1007 | 1007 | $form['info']['create_date'] = $form_info->post_date; |
1008 | 1008 | $form['info']['modified_date'] = $form_info->post_modified; |
1009 | 1009 | $form['info']['status'] = $form_info->post_status; |
1010 | - $form['info']['link'] = html_entity_decode( $form_info->guid ); |
|
1011 | - $form['info']['content'] = get_post_meta( $form_info->ID, '_give_form_content', true ); |
|
1012 | - $form['info']['thumbnail'] = wp_get_attachment_url( get_post_thumbnail_id( $form_info->ID ) ); |
|
1010 | + $form['info']['link'] = html_entity_decode($form_info->guid); |
|
1011 | + $form['info']['content'] = get_post_meta($form_info->ID, '_give_form_content', true); |
|
1012 | + $form['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($form_info->ID)); |
|
1013 | 1013 | |
1014 | - if ( give_get_option( 'enable_categories' ) == 'on' ) { |
|
1015 | - $form['info']['category'] = get_the_terms( $form_info, 'give_forms_category' ); |
|
1016 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1014 | + if (give_get_option('enable_categories') == 'on') { |
|
1015 | + $form['info']['category'] = get_the_terms($form_info, 'give_forms_category'); |
|
1016 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1017 | 1017 | } |
1018 | - if ( give_get_option( 'enable_tags' ) == 'on' ) { |
|
1019 | - $form['info']['tags'] = get_the_terms( $form_info, 'give_forms_tag' ); |
|
1018 | + if (give_get_option('enable_tags') == 'on') { |
|
1019 | + $form['info']['tags'] = get_the_terms($form_info, 'give_forms_tag'); |
|
1020 | 1020 | } |
1021 | 1021 | |
1022 | - if ( user_can( $this->user_id, 'view_give_reports' ) || $this->override ) { |
|
1023 | - $form['stats']['total']['donations'] = give_get_form_sales_stats( $form_info->ID ); |
|
1024 | - $form['stats']['total']['earnings'] = give_get_form_earnings_stats( $form_info->ID ); |
|
1025 | - $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales( $form_info->ID ); |
|
1026 | - $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings( $form_info->ID ); |
|
1022 | + if (user_can($this->user_id, 'view_give_reports') || $this->override) { |
|
1023 | + $form['stats']['total']['donations'] = give_get_form_sales_stats($form_info->ID); |
|
1024 | + $form['stats']['total']['earnings'] = give_get_form_earnings_stats($form_info->ID); |
|
1025 | + $form['stats']['monthly_average']['donations'] = give_get_average_monthly_form_sales($form_info->ID); |
|
1026 | + $form['stats']['monthly_average']['earnings'] = give_get_average_monthly_form_earnings($form_info->ID); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | $counter = 0; |
1030 | - if ( give_has_variable_prices( $form_info->ID ) ) { |
|
1031 | - foreach ( give_get_variable_prices( $form_info->ID ) as $price ) { |
|
1032 | - $counter ++; |
|
1030 | + if (give_has_variable_prices($form_info->ID)) { |
|
1031 | + foreach (give_get_variable_prices($form_info->ID) as $price) { |
|
1032 | + $counter++; |
|
1033 | 1033 | //muli-level item |
1034 | - $level = isset( $price['_give_text'] ) ? $price['_give_text'] : 'level-' . $counter; |
|
1035 | - $form['pricing'][ sanitize_key( $level ) ] = $price['_give_amount']; |
|
1034 | + $level = isset($price['_give_text']) ? $price['_give_text'] : 'level-'.$counter; |
|
1035 | + $form['pricing'][sanitize_key($level)] = $price['_give_amount']; |
|
1036 | 1036 | |
1037 | 1037 | } |
1038 | 1038 | } else { |
1039 | - $form['pricing']['amount'] = give_get_form_price( $form_info->ID ); |
|
1039 | + $form['pricing']['amount'] = give_get_form_price($form_info->ID); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | - if ( user_can( $this->user_id, 'view_give_sensitive_data' ) || $this->override ) { |
|
1042 | + if (user_can($this->user_id, 'view_give_sensitive_data') || $this->override) { |
|
1043 | 1043 | |
1044 | 1044 | /** |
1045 | 1045 | * Fires when generating API sensitive data. |
1046 | 1046 | * |
1047 | 1047 | * @since 1.1 |
1048 | 1048 | */ |
1049 | - do_action( 'give_api_sensitive_data' ); |
|
1049 | + do_action('give_api_sensitive_data'); |
|
1050 | 1050 | |
1051 | 1051 | } |
1052 | 1052 | |
1053 | - return apply_filters( 'give_api_forms_form', $form ); |
|
1053 | + return apply_filters('give_api_forms_form', $form); |
|
1054 | 1054 | |
1055 | 1055 | } |
1056 | 1056 | |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | * |
1066 | 1066 | * @return array |
1067 | 1067 | */ |
1068 | - public function get_stats( $args = array() ) { |
|
1068 | + public function get_stats($args = array()) { |
|
1069 | 1069 | $defaults = array( |
1070 | 1070 | 'type' => null, |
1071 | 1071 | 'form' => null, |
@@ -1074,9 +1074,9 @@ discard block |
||
1074 | 1074 | 'enddate' => null |
1075 | 1075 | ); |
1076 | 1076 | |
1077 | - $args = wp_parse_args( $args, $defaults ); |
|
1077 | + $args = wp_parse_args($args, $defaults); |
|
1078 | 1078 | |
1079 | - $dates = $this->get_dates( $args ); |
|
1079 | + $dates = $this->get_dates($args); |
|
1080 | 1080 | |
1081 | 1081 | $stats = array(); |
1082 | 1082 | $earnings = array( |
@@ -1087,41 +1087,41 @@ discard block |
||
1087 | 1087 | ); |
1088 | 1088 | $error = array(); |
1089 | 1089 | |
1090 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1090 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1091 | 1091 | return $stats; |
1092 | 1092 | } |
1093 | 1093 | |
1094 | - if ( $args['type'] == 'donations' ) { |
|
1094 | + if ($args['type'] == 'donations') { |
|
1095 | 1095 | |
1096 | - if ( $args['form'] == null ) { |
|
1097 | - if ( $args['date'] == null ) { |
|
1096 | + if ($args['form'] == null) { |
|
1097 | + if ($args['date'] == null) { |
|
1098 | 1098 | $sales = $this->get_default_sales_stats(); |
1099 | - } elseif ( $args['date'] === 'range' ) { |
|
1099 | + } elseif ($args['date'] === 'range') { |
|
1100 | 1100 | // Return sales for a date range |
1101 | 1101 | |
1102 | 1102 | // Ensure the end date is later than the start date |
1103 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1104 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1103 | + if ($args['enddate'] < $args['startdate']) { |
|
1104 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | // Ensure both the start and end date are specified |
1108 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1109 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1108 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1109 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1110 | 1110 | } |
1111 | 1111 | |
1112 | 1112 | $total = 0; |
1113 | 1113 | |
1114 | 1114 | // Loop through the years |
1115 | 1115 | $y = $dates['year']; |
1116 | - while ( $y <= $dates['year_end'] ) : |
|
1116 | + while ($y <= $dates['year_end']) : |
|
1117 | 1117 | |
1118 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1118 | + if ($dates['year'] == $dates['year_end']) { |
|
1119 | 1119 | $month_start = $dates['m_start']; |
1120 | 1120 | $month_end = $dates['m_end']; |
1121 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1121 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1122 | 1122 | $month_start = $dates['m_start']; |
1123 | 1123 | $month_end = 12; |
1124 | - } elseif ( $y == $dates['year_end'] ) { |
|
1124 | + } elseif ($y == $dates['year_end']) { |
|
1125 | 1125 | $month_start = 1; |
1126 | 1126 | $month_end = $dates['m_end']; |
1127 | 1127 | } else { |
@@ -1130,113 +1130,113 @@ discard block |
||
1130 | 1130 | } |
1131 | 1131 | |
1132 | 1132 | $i = $month_start; |
1133 | - while ( $i <= $month_end ) : |
|
1133 | + while ($i <= $month_end) : |
|
1134 | 1134 | |
1135 | - if ( $i == $dates['m_start'] ) { |
|
1135 | + if ($i == $dates['m_start']) { |
|
1136 | 1136 | $d = $dates['day_start']; |
1137 | 1137 | } else { |
1138 | 1138 | $d = 1; |
1139 | 1139 | } |
1140 | 1140 | |
1141 | - if ( $i == $dates['m_end'] ) { |
|
1141 | + if ($i == $dates['m_end']) { |
|
1142 | 1142 | $num_of_days = $dates['day_end']; |
1143 | 1143 | } else { |
1144 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1144 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | - while ( $d <= $num_of_days ) : |
|
1148 | - $sale_count = give_get_sales_by_date( $d, $i, $y ); |
|
1149 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1150 | - if ( ! isset( $sales['sales'][ $date_key ] ) ) { |
|
1151 | - $sales['sales'][ $date_key ] = 0; |
|
1147 | + while ($d <= $num_of_days) : |
|
1148 | + $sale_count = give_get_sales_by_date($d, $i, $y); |
|
1149 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1150 | + if ( ! isset($sales['sales'][$date_key])) { |
|
1151 | + $sales['sales'][$date_key] = 0; |
|
1152 | 1152 | } |
1153 | - $sales['sales'][ $date_key ] += $sale_count; |
|
1153 | + $sales['sales'][$date_key] += $sale_count; |
|
1154 | 1154 | $total += $sale_count; |
1155 | - $d ++; |
|
1155 | + $d++; |
|
1156 | 1156 | endwhile; |
1157 | - $i ++; |
|
1157 | + $i++; |
|
1158 | 1158 | endwhile; |
1159 | 1159 | |
1160 | - $y ++; |
|
1160 | + $y++; |
|
1161 | 1161 | endwhile; |
1162 | 1162 | |
1163 | 1163 | $sales['totals'] = $total; |
1164 | 1164 | } else { |
1165 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1165 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1166 | 1166 | $sales_count = 0; |
1167 | 1167 | |
1168 | 1168 | // Loop through the months |
1169 | 1169 | $month = $dates['m_start']; |
1170 | 1170 | |
1171 | - while ( $month <= $dates['m_end'] ) : |
|
1172 | - $sales_count += give_get_sales_by_date( null, $month, $dates['year'] ); |
|
1173 | - $month ++; |
|
1171 | + while ($month <= $dates['m_end']) : |
|
1172 | + $sales_count += give_get_sales_by_date(null, $month, $dates['year']); |
|
1173 | + $month++; |
|
1174 | 1174 | endwhile; |
1175 | 1175 | |
1176 | - $sales['donations'][ $args['date'] ] = $sales_count; |
|
1176 | + $sales['donations'][$args['date']] = $sales_count; |
|
1177 | 1177 | } else { |
1178 | - $sales['donations'][ $args['date'] ] = give_get_sales_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1178 | + $sales['donations'][$args['date']] = give_get_sales_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1179 | 1179 | } |
1180 | 1180 | } |
1181 | - } elseif ( $args['form'] == 'all' ) { |
|
1182 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1181 | + } elseif ($args['form'] == 'all') { |
|
1182 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1183 | 1183 | $i = 0; |
1184 | - foreach ( $forms as $form_info ) { |
|
1185 | - $sales['donations'][ $i ] = array( $form_info->post_name => give_get_form_sales_stats( $form_info->ID ) ); |
|
1186 | - $i ++; |
|
1184 | + foreach ($forms as $form_info) { |
|
1185 | + $sales['donations'][$i] = array($form_info->post_name => give_get_form_sales_stats($form_info->ID)); |
|
1186 | + $i++; |
|
1187 | 1187 | } |
1188 | 1188 | } else { |
1189 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1190 | - $form_info = get_post( $args['form'] ); |
|
1191 | - $sales['donations'][0] = array( $form_info->post_name => give_get_form_sales_stats( $args['form'] ) ); |
|
1189 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1190 | + $form_info = get_post($args['form']); |
|
1191 | + $sales['donations'][0] = array($form_info->post_name => give_get_form_sales_stats($args['form'])); |
|
1192 | 1192 | } else { |
1193 | 1193 | $error['error'] = sprintf( |
1194 | 1194 | /* translators: %s: form */ |
1195 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1195 | + esc_html__('Form %s not found.', 'give'), |
|
1196 | 1196 | $args['form'] |
1197 | 1197 | ); |
1198 | 1198 | } |
1199 | 1199 | } |
1200 | 1200 | |
1201 | - if ( ! empty( $error ) ) { |
|
1201 | + if ( ! empty($error)) { |
|
1202 | 1202 | return $error; |
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | return $sales; |
1206 | 1206 | |
1207 | - } elseif ( $args['type'] == 'earnings' ) { |
|
1208 | - if ( $args['form'] == null ) { |
|
1209 | - if ( $args['date'] == null ) { |
|
1207 | + } elseif ($args['type'] == 'earnings') { |
|
1208 | + if ($args['form'] == null) { |
|
1209 | + if ($args['date'] == null) { |
|
1210 | 1210 | $earnings = $this->get_default_earnings_stats(); |
1211 | - } elseif ( $args['date'] === 'range' ) { |
|
1211 | + } elseif ($args['date'] === 'range') { |
|
1212 | 1212 | // Return sales for a date range |
1213 | 1213 | |
1214 | 1214 | // Ensure the end date is later than the start date |
1215 | - if ( $args['enddate'] < $args['startdate'] ) { |
|
1216 | - $error['error'] = esc_html__( 'The end date must be later than the start date.', 'give' ); |
|
1215 | + if ($args['enddate'] < $args['startdate']) { |
|
1216 | + $error['error'] = esc_html__('The end date must be later than the start date.', 'give'); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | // Ensure both the start and end date are specified |
1220 | - if ( empty( $args['startdate'] ) || empty( $args['enddate'] ) ) { |
|
1221 | - $error['error'] = esc_html__( 'Invalid or no date range specified.', 'give' ); |
|
1220 | + if (empty($args['startdate']) || empty($args['enddate'])) { |
|
1221 | + $error['error'] = esc_html__('Invalid or no date range specified.', 'give'); |
|
1222 | 1222 | } |
1223 | 1223 | |
1224 | 1224 | $total = (float) 0.00; |
1225 | 1225 | |
1226 | 1226 | // Loop through the years |
1227 | 1227 | $y = $dates['year']; |
1228 | - if ( ! isset( $earnings['earnings'] ) ) { |
|
1228 | + if ( ! isset($earnings['earnings'])) { |
|
1229 | 1229 | $earnings['earnings'] = array(); |
1230 | 1230 | } |
1231 | - while ( $y <= $dates['year_end'] ) : |
|
1231 | + while ($y <= $dates['year_end']) : |
|
1232 | 1232 | |
1233 | - if ( $dates['year'] == $dates['year_end'] ) { |
|
1233 | + if ($dates['year'] == $dates['year_end']) { |
|
1234 | 1234 | $month_start = $dates['m_start']; |
1235 | 1235 | $month_end = $dates['m_end']; |
1236 | - } elseif ( $y == $dates['year'] && $dates['year_end'] > $dates['year'] ) { |
|
1236 | + } elseif ($y == $dates['year'] && $dates['year_end'] > $dates['year']) { |
|
1237 | 1237 | $month_start = $dates['m_start']; |
1238 | 1238 | $month_end = 12; |
1239 | - } elseif ( $y == $dates['year_end'] ) { |
|
1239 | + } elseif ($y == $dates['year_end']) { |
|
1240 | 1240 | $month_start = 1; |
1241 | 1241 | $month_end = $dates['m_end']; |
1242 | 1242 | } else { |
@@ -1245,92 +1245,92 @@ discard block |
||
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | $i = $month_start; |
1248 | - while ( $i <= $month_end ) : |
|
1248 | + while ($i <= $month_end) : |
|
1249 | 1249 | |
1250 | - if ( $i == $dates['m_start'] ) { |
|
1250 | + if ($i == $dates['m_start']) { |
|
1251 | 1251 | $d = $dates['day_start']; |
1252 | 1252 | } else { |
1253 | 1253 | $d = 1; |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - if ( $i == $dates['m_end'] ) { |
|
1256 | + if ($i == $dates['m_end']) { |
|
1257 | 1257 | $num_of_days = $dates['day_end']; |
1258 | 1258 | } else { |
1259 | - $num_of_days = cal_days_in_month( CAL_GREGORIAN, $i, $y ); |
|
1259 | + $num_of_days = cal_days_in_month(CAL_GREGORIAN, $i, $y); |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | - while ( $d <= $num_of_days ) : |
|
1263 | - $earnings_stat = give_get_earnings_by_date( $d, $i, $y ); |
|
1264 | - $date_key = date( 'Ymd', strtotime( $y . '/' . $i . '/' . $d ) ); |
|
1265 | - if ( ! isset( $earnings['earnings'][ $date_key ] ) ) { |
|
1266 | - $earnings['earnings'][ $date_key ] = 0; |
|
1262 | + while ($d <= $num_of_days) : |
|
1263 | + $earnings_stat = give_get_earnings_by_date($d, $i, $y); |
|
1264 | + $date_key = date('Ymd', strtotime($y.'/'.$i.'/'.$d)); |
|
1265 | + if ( ! isset($earnings['earnings'][$date_key])) { |
|
1266 | + $earnings['earnings'][$date_key] = 0; |
|
1267 | 1267 | } |
1268 | - $earnings['earnings'][ $date_key ] += $earnings_stat; |
|
1268 | + $earnings['earnings'][$date_key] += $earnings_stat; |
|
1269 | 1269 | $total += $earnings_stat; |
1270 | - $d ++; |
|
1270 | + $d++; |
|
1271 | 1271 | endwhile; |
1272 | 1272 | |
1273 | - $i ++; |
|
1273 | + $i++; |
|
1274 | 1274 | endwhile; |
1275 | 1275 | |
1276 | - $y ++; |
|
1276 | + $y++; |
|
1277 | 1277 | endwhile; |
1278 | 1278 | |
1279 | 1279 | $earnings['totals'] = $total; |
1280 | 1280 | } else { |
1281 | - if ( $args['date'] == 'this_quarter' || $args['date'] == 'last_quarter' ) { |
|
1281 | + if ($args['date'] == 'this_quarter' || $args['date'] == 'last_quarter') { |
|
1282 | 1282 | $earnings_count = (float) 0.00; |
1283 | 1283 | |
1284 | 1284 | // Loop through the months |
1285 | 1285 | $month = $dates['m_start']; |
1286 | 1286 | |
1287 | - while ( $month <= $dates['m_end'] ) : |
|
1288 | - $earnings_count += give_get_earnings_by_date( null, $month, $dates['year'] ); |
|
1289 | - $month ++; |
|
1287 | + while ($month <= $dates['m_end']) : |
|
1288 | + $earnings_count += give_get_earnings_by_date(null, $month, $dates['year']); |
|
1289 | + $month++; |
|
1290 | 1290 | endwhile; |
1291 | 1291 | |
1292 | - $earnings['earnings'][ $args['date'] ] = $earnings_count; |
|
1292 | + $earnings['earnings'][$args['date']] = $earnings_count; |
|
1293 | 1293 | } else { |
1294 | - $earnings['earnings'][ $args['date'] ] = give_get_earnings_by_date( $dates['day'], $dates['m_start'], $dates['year'] ); |
|
1294 | + $earnings['earnings'][$args['date']] = give_get_earnings_by_date($dates['day'], $dates['m_start'], $dates['year']); |
|
1295 | 1295 | } |
1296 | 1296 | } |
1297 | - } elseif ( $args['form'] == 'all' ) { |
|
1298 | - $forms = get_posts( array( 'post_type' => 'give_forms', 'nopaging' => true ) ); |
|
1297 | + } elseif ($args['form'] == 'all') { |
|
1298 | + $forms = get_posts(array('post_type' => 'give_forms', 'nopaging' => true)); |
|
1299 | 1299 | |
1300 | 1300 | $i = 0; |
1301 | - foreach ( $forms as $form_info ) { |
|
1302 | - $earnings['earnings'][ $i ] = array( $form_info->post_name => give_get_form_earnings_stats( $form_info->ID ) ); |
|
1303 | - $i ++; |
|
1301 | + foreach ($forms as $form_info) { |
|
1302 | + $earnings['earnings'][$i] = array($form_info->post_name => give_get_form_earnings_stats($form_info->ID)); |
|
1303 | + $i++; |
|
1304 | 1304 | } |
1305 | 1305 | } else { |
1306 | - if ( get_post_type( $args['form'] ) == 'give_forms' ) { |
|
1307 | - $form_info = get_post( $args['form'] ); |
|
1308 | - $earnings['earnings'][0] = array( $form_info->post_name => give_get_form_earnings_stats( $args['form'] ) ); |
|
1306 | + if (get_post_type($args['form']) == 'give_forms') { |
|
1307 | + $form_info = get_post($args['form']); |
|
1308 | + $earnings['earnings'][0] = array($form_info->post_name => give_get_form_earnings_stats($args['form'])); |
|
1309 | 1309 | } else { |
1310 | 1310 | $error['error'] = sprintf( |
1311 | 1311 | /* translators: %s: form */ |
1312 | - esc_html__( 'Form %s not found.', 'give' ), |
|
1312 | + esc_html__('Form %s not found.', 'give'), |
|
1313 | 1313 | $args['form'] |
1314 | 1314 | ); |
1315 | 1315 | } |
1316 | 1316 | } |
1317 | 1317 | |
1318 | - if ( ! empty( $error ) ) { |
|
1318 | + if ( ! empty($error)) { |
|
1319 | 1319 | return $error; |
1320 | 1320 | } |
1321 | 1321 | |
1322 | 1322 | return $earnings; |
1323 | - } elseif ( $args['type'] == 'donors' ) { |
|
1323 | + } elseif ($args['type'] == 'donors') { |
|
1324 | 1324 | $customers = new Give_DB_Customers(); |
1325 | 1325 | $stats['donations']['total_donors'] = $customers->count(); |
1326 | 1326 | |
1327 | 1327 | return $stats; |
1328 | 1328 | |
1329 | - } elseif ( empty( $args['type'] ) ) { |
|
1330 | - $stats = array_merge( $stats, $this->get_default_sales_stats() ); |
|
1331 | - $stats = array_merge( $stats, $this->get_default_earnings_stats() ); |
|
1329 | + } elseif (empty($args['type'])) { |
|
1330 | + $stats = array_merge($stats, $this->get_default_sales_stats()); |
|
1331 | + $stats = array_merge($stats, $this->get_default_earnings_stats()); |
|
1332 | 1332 | |
1333 | - return array( 'stats' => $stats ); |
|
1333 | + return array('stats' => $stats); |
|
1334 | 1334 | } |
1335 | 1335 | } |
1336 | 1336 | |
@@ -1346,18 +1346,18 @@ discard block |
||
1346 | 1346 | |
1347 | 1347 | $sales = array(); |
1348 | 1348 | |
1349 | - if ( ! user_can( $this->user_id, 'view_give_reports' ) && ! $this->override ) { |
|
1349 | + if ( ! user_can($this->user_id, 'view_give_reports') && ! $this->override) { |
|
1350 | 1350 | return $sales; |
1351 | 1351 | } |
1352 | 1352 | |
1353 | - if ( isset( $wp_query->query_vars['id'] ) ) { |
|
1353 | + if (isset($wp_query->query_vars['id'])) { |
|
1354 | 1354 | $query = array(); |
1355 | - $query[] = new Give_Payment( $wp_query->query_vars['id'] ); |
|
1356 | - } elseif ( isset( $wp_query->query_vars['purchasekey'] ) ) { |
|
1355 | + $query[] = new Give_Payment($wp_query->query_vars['id']); |
|
1356 | + } elseif (isset($wp_query->query_vars['purchasekey'])) { |
|
1357 | 1357 | $query = array(); |
1358 | - $query[] = give_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); |
|
1359 | - } elseif ( isset( $wp_query->query_vars['email'] ) ) { |
|
1360 | - $args = array( |
|
1358 | + $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']); |
|
1359 | + } elseif (isset($wp_query->query_vars['email'])) { |
|
1360 | + $args = array( |
|
1361 | 1361 | 'fields' => 'ids', |
1362 | 1362 | 'meta_key' => '_give_payment_user_email', |
1363 | 1363 | 'meta_value' => $wp_query->query_vars['email'], |
@@ -1365,7 +1365,7 @@ discard block |
||
1365 | 1365 | 'page' => $this->get_paged(), |
1366 | 1366 | 'status' => 'publish' |
1367 | 1367 | ); |
1368 | - $query = give_get_payments( $args ); |
|
1368 | + $query = give_get_payments($args); |
|
1369 | 1369 | } else { |
1370 | 1370 | $args = array( |
1371 | 1371 | 'fields' => 'ids', |
@@ -1373,14 +1373,14 @@ discard block |
||
1373 | 1373 | 'page' => $this->get_paged(), |
1374 | 1374 | 'status' => 'publish' |
1375 | 1375 | ); |
1376 | - $query = give_get_payments( $args ); |
|
1376 | + $query = give_get_payments($args); |
|
1377 | 1377 | } |
1378 | - if ( $query ) { |
|
1378 | + if ($query) { |
|
1379 | 1379 | $i = 0; |
1380 | - foreach ( $query as $payment ) { |
|
1380 | + foreach ($query as $payment) { |
|
1381 | 1381 | |
1382 | - if ( is_numeric( $payment ) ) { |
|
1383 | - $payment = new Give_Payment( $payment ); |
|
1382 | + if (is_numeric($payment)) { |
|
1383 | + $payment = new Give_Payment($payment); |
|
1384 | 1384 | $payment_meta = $payment->get_meta(); |
1385 | 1385 | $user_info = $payment->user_info; |
1386 | 1386 | } else { |
@@ -1390,40 +1390,40 @@ discard block |
||
1390 | 1390 | $payment_meta = $payment->get_meta(); |
1391 | 1391 | $user_info = $payment->user_info; |
1392 | 1392 | |
1393 | - $first_name = isset( $user_info['first_name'] ) ? $user_info['first_name'] : ''; |
|
1394 | - $last_name = isset( $user_info['last_name'] ) ? $user_info['last_name'] : ''; |
|
1395 | - |
|
1396 | - $sales['donations'][ $i ]['ID'] = $payment->number; |
|
1397 | - $sales['donations'][ $i ]['transaction_id'] = $payment->transaction_id; |
|
1398 | - $sales['donations'][ $i ]['key'] = $payment->key; |
|
1399 | - $sales['donations'][ $i ]['total'] = $payment->total; |
|
1400 | - $sales['donations'][ $i ]['gateway'] = $payment->gateway; |
|
1401 | - $sales['donations'][ $i ]['name'] = $first_name . ' ' . $last_name; |
|
1402 | - $sales['donations'][ $i ]['fname'] = $first_name; |
|
1403 | - $sales['donations'][ $i ]['lname'] = $last_name; |
|
1404 | - $sales['donations'][ $i ]['email'] = $payment->email; |
|
1405 | - $sales['donations'][ $i ]['date'] = $payment->date; |
|
1406 | - |
|
1407 | - $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : $payment_meta; |
|
1408 | - $price = isset( $payment_meta['form_id'] ) ? give_get_form_price( $payment_meta['form_id'] ) : false; |
|
1409 | - $price_id = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null; |
|
1410 | - |
|
1411 | - $sales['donations'][ $i ]['form']['id'] = $form_id; |
|
1412 | - $sales['donations'][ $i ]['form']['name'] = get_the_title( $payment_meta['form_id'] ); |
|
1413 | - $sales['donations'][ $i ]['form']['price'] = $price; |
|
1414 | - |
|
1415 | - if ( give_has_variable_prices( $form_id ) ) { |
|
1416 | - if ( isset( $payment_meta['price_id'] ) ) { |
|
1417 | - $price_name = give_get_price_option_name( $form_id, $payment_meta['price_id'], $payment->ID ); |
|
1418 | - $sales['donations'][ $i ]['form']['price_name'] = $price_name; |
|
1419 | - $sales['donations'][ $i ]['form']['price_id'] = $price_id; |
|
1420 | - $sales['donations'][ $i ]['form']['price'] = give_get_price_option_amount( $form_id, $price_id ); |
|
1393 | + $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : ''; |
|
1394 | + $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : ''; |
|
1395 | + |
|
1396 | + $sales['donations'][$i]['ID'] = $payment->number; |
|
1397 | + $sales['donations'][$i]['transaction_id'] = $payment->transaction_id; |
|
1398 | + $sales['donations'][$i]['key'] = $payment->key; |
|
1399 | + $sales['donations'][$i]['total'] = $payment->total; |
|
1400 | + $sales['donations'][$i]['gateway'] = $payment->gateway; |
|
1401 | + $sales['donations'][$i]['name'] = $first_name.' '.$last_name; |
|
1402 | + $sales['donations'][$i]['fname'] = $first_name; |
|
1403 | + $sales['donations'][$i]['lname'] = $last_name; |
|
1404 | + $sales['donations'][$i]['email'] = $payment->email; |
|
1405 | + $sales['donations'][$i]['date'] = $payment->date; |
|
1406 | + |
|
1407 | + $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta; |
|
1408 | + $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false; |
|
1409 | + $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null; |
|
1410 | + |
|
1411 | + $sales['donations'][$i]['form']['id'] = $form_id; |
|
1412 | + $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']); |
|
1413 | + $sales['donations'][$i]['form']['price'] = $price; |
|
1414 | + |
|
1415 | + if (give_has_variable_prices($form_id)) { |
|
1416 | + if (isset($payment_meta['price_id'])) { |
|
1417 | + $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID); |
|
1418 | + $sales['donations'][$i]['form']['price_name'] = $price_name; |
|
1419 | + $sales['donations'][$i]['form']['price_id'] = $price_id; |
|
1420 | + $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id); |
|
1421 | 1421 | |
1422 | 1422 | } |
1423 | 1423 | } |
1424 | 1424 | |
1425 | 1425 | //Add custom meta to API |
1426 | - foreach ( $payment_meta as $meta_key => $meta_value ) { |
|
1426 | + foreach ($payment_meta as $meta_key => $meta_value) { |
|
1427 | 1427 | |
1428 | 1428 | $exceptions = array( |
1429 | 1429 | 'form_title', |
@@ -1436,19 +1436,19 @@ discard block |
||
1436 | 1436 | ); |
1437 | 1437 | |
1438 | 1438 | //Don't clutter up results with dupes |
1439 | - if ( in_array( $meta_key, $exceptions ) ) { |
|
1439 | + if (in_array($meta_key, $exceptions)) { |
|
1440 | 1440 | continue; |
1441 | 1441 | } |
1442 | 1442 | |
1443 | - $sales['donations'][ $i ]['payment_meta'][ $meta_key ] = $meta_value; |
|
1443 | + $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value; |
|
1444 | 1444 | |
1445 | 1445 | } |
1446 | 1446 | |
1447 | - $i ++; |
|
1447 | + $i++; |
|
1448 | 1448 | } |
1449 | 1449 | } |
1450 | 1450 | |
1451 | - return apply_filters( 'give_api_donations_endpoint', $sales ); |
|
1451 | + return apply_filters('give_api_donations_endpoint', $sales); |
|
1452 | 1452 | } |
1453 | 1453 | |
1454 | 1454 | /** |
@@ -1464,9 +1464,9 @@ discard block |
||
1464 | 1464 | public function get_output_format() { |
1465 | 1465 | global $wp_query; |
1466 | 1466 | |
1467 | - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; |
|
1467 | + $format = isset($wp_query->query_vars['format']) ? $wp_query->query_vars['format'] : 'json'; |
|
1468 | 1468 | |
1469 | - return apply_filters( 'give_api_output_format', $format ); |
|
1469 | + return apply_filters('give_api_output_format', $format); |
|
1470 | 1470 | } |
1471 | 1471 | |
1472 | 1472 | |
@@ -1483,8 +1483,8 @@ discard block |
||
1483 | 1483 | * |
1484 | 1484 | * @return void |
1485 | 1485 | */ |
1486 | - private function log_request( $data = array() ) { |
|
1487 | - if ( ! $this->log_requests ) { |
|
1486 | + private function log_request($data = array()) { |
|
1487 | + if ( ! $this->log_requests) { |
|
1488 | 1488 | return; |
1489 | 1489 | } |
1490 | 1490 | |
@@ -1500,36 +1500,36 @@ discard block |
||
1500 | 1500 | |
1501 | 1501 | $query = array( |
1502 | 1502 | 'give-api' => $wp_query->query_vars['give-api'], |
1503 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1504 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1505 | - 'query' => isset( $wp_query->query_vars['query'] ) ? $wp_query->query_vars['query'] : null, |
|
1506 | - 'type' => isset( $wp_query->query_vars['type'] ) ? $wp_query->query_vars['type'] : null, |
|
1507 | - 'form' => isset( $wp_query->query_vars['form'] ) ? $wp_query->query_vars['form'] : null, |
|
1508 | - 'customer' => isset( $wp_query->query_vars['customer'] ) ? $wp_query->query_vars['customer'] : null, |
|
1509 | - 'date' => isset( $wp_query->query_vars['date'] ) ? $wp_query->query_vars['date'] : null, |
|
1510 | - 'startdate' => isset( $wp_query->query_vars['startdate'] ) ? $wp_query->query_vars['startdate'] : null, |
|
1511 | - 'enddate' => isset( $wp_query->query_vars['enddate'] ) ? $wp_query->query_vars['enddate'] : null, |
|
1512 | - 'id' => isset( $wp_query->query_vars['id'] ) ? $wp_query->query_vars['id'] : null, |
|
1513 | - 'purchasekey' => isset( $wp_query->query_vars['purchasekey'] ) ? $wp_query->query_vars['purchasekey'] : null, |
|
1514 | - 'email' => isset( $wp_query->query_vars['email'] ) ? $wp_query->query_vars['email'] : null, |
|
1503 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1504 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1505 | + 'query' => isset($wp_query->query_vars['query']) ? $wp_query->query_vars['query'] : null, |
|
1506 | + 'type' => isset($wp_query->query_vars['type']) ? $wp_query->query_vars['type'] : null, |
|
1507 | + 'form' => isset($wp_query->query_vars['form']) ? $wp_query->query_vars['form'] : null, |
|
1508 | + 'customer' => isset($wp_query->query_vars['customer']) ? $wp_query->query_vars['customer'] : null, |
|
1509 | + 'date' => isset($wp_query->query_vars['date']) ? $wp_query->query_vars['date'] : null, |
|
1510 | + 'startdate' => isset($wp_query->query_vars['startdate']) ? $wp_query->query_vars['startdate'] : null, |
|
1511 | + 'enddate' => isset($wp_query->query_vars['enddate']) ? $wp_query->query_vars['enddate'] : null, |
|
1512 | + 'id' => isset($wp_query->query_vars['id']) ? $wp_query->query_vars['id'] : null, |
|
1513 | + 'purchasekey' => isset($wp_query->query_vars['purchasekey']) ? $wp_query->query_vars['purchasekey'] : null, |
|
1514 | + 'email' => isset($wp_query->query_vars['email']) ? $wp_query->query_vars['email'] : null, |
|
1515 | 1515 | ); |
1516 | 1516 | |
1517 | 1517 | $log_data = array( |
1518 | 1518 | 'log_type' => 'api_request', |
1519 | - 'post_excerpt' => http_build_query( $query ), |
|
1520 | - 'post_content' => ! empty( $data['error'] ) ? $data['error'] : '', |
|
1519 | + 'post_excerpt' => http_build_query($query), |
|
1520 | + 'post_content' => ! empty($data['error']) ? $data['error'] : '', |
|
1521 | 1521 | ); |
1522 | 1522 | |
1523 | 1523 | $log_meta = array( |
1524 | 1524 | 'request_ip' => give_get_ip(), |
1525 | 1525 | 'user' => $this->user_id, |
1526 | - 'key' => isset( $wp_query->query_vars['key'] ) ? $wp_query->query_vars['key'] : null, |
|
1527 | - 'token' => isset( $wp_query->query_vars['token'] ) ? $wp_query->query_vars['token'] : null, |
|
1526 | + 'key' => isset($wp_query->query_vars['key']) ? $wp_query->query_vars['key'] : null, |
|
1527 | + 'token' => isset($wp_query->query_vars['token']) ? $wp_query->query_vars['token'] : null, |
|
1528 | 1528 | 'time' => $data['request_speed'], |
1529 | 1529 | 'version' => $this->get_queried_version() |
1530 | 1530 | ); |
1531 | 1531 | |
1532 | - $give_logs->insert_log( $log_data, $log_meta ); |
|
1532 | + $give_logs->insert_log($log_data, $log_meta); |
|
1533 | 1533 | } |
1534 | 1534 | |
1535 | 1535 | |
@@ -1553,7 +1553,7 @@ discard block |
||
1553 | 1553 | * |
1554 | 1554 | * @param int $status_code |
1555 | 1555 | */ |
1556 | - public function output( $status_code = 200 ) { |
|
1556 | + public function output($status_code = 200) { |
|
1557 | 1557 | /** |
1558 | 1558 | * @var WP_Query $wp_query |
1559 | 1559 | */ |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | |
1562 | 1562 | $format = $this->get_output_format(); |
1563 | 1563 | |
1564 | - status_header( $status_code ); |
|
1564 | + status_header($status_code); |
|
1565 | 1565 | |
1566 | 1566 | /** |
1567 | 1567 | * Fires before outputing the API. |
@@ -1572,25 +1572,25 @@ discard block |
||
1572 | 1572 | * @param Give_API $this The Give_API object. |
1573 | 1573 | * @param string $format Output format, XML or JSON. Default is JSON. |
1574 | 1574 | */ |
1575 | - do_action( 'give_api_output_before', $this->data, $this, $format ); |
|
1575 | + do_action('give_api_output_before', $this->data, $this, $format); |
|
1576 | 1576 | |
1577 | - switch ( $format ) : |
|
1577 | + switch ($format) : |
|
1578 | 1578 | |
1579 | 1579 | case 'xml' : |
1580 | 1580 | |
1581 | - require_once GIVE_PLUGIN_DIR . 'includes/libraries/array2xml.php'; |
|
1582 | - $xml = Array2XML::createXML( 'give', $this->data ); |
|
1581 | + require_once GIVE_PLUGIN_DIR.'includes/libraries/array2xml.php'; |
|
1582 | + $xml = Array2XML::createXML('give', $this->data); |
|
1583 | 1583 | echo $xml->saveXML(); |
1584 | 1584 | |
1585 | 1585 | break; |
1586 | 1586 | |
1587 | 1587 | case 'json' : |
1588 | 1588 | |
1589 | - header( 'Content-Type: application/json' ); |
|
1590 | - if ( ! empty( $this->pretty_print ) ) { |
|
1591 | - echo json_encode( $this->data, $this->pretty_print ); |
|
1589 | + header('Content-Type: application/json'); |
|
1590 | + if ( ! empty($this->pretty_print)) { |
|
1591 | + echo json_encode($this->data, $this->pretty_print); |
|
1592 | 1592 | } else { |
1593 | - echo json_encode( $this->data ); |
|
1593 | + echo json_encode($this->data); |
|
1594 | 1594 | } |
1595 | 1595 | |
1596 | 1596 | break; |
@@ -1606,7 +1606,7 @@ discard block |
||
1606 | 1606 | * @param array $data Response data to return. |
1607 | 1607 | * @param Give_API $this The Give_API object. |
1608 | 1608 | */ |
1609 | - do_action( "give_api_output_{$format}", $this->data, $this ); |
|
1609 | + do_action("give_api_output_{$format}", $this->data, $this); |
|
1610 | 1610 | |
1611 | 1611 | break; |
1612 | 1612 | |
@@ -1621,7 +1621,7 @@ discard block |
||
1621 | 1621 | * @param Give_API $this The Give_API object. |
1622 | 1622 | * @param string $format Output format, XML or JSON. Default is JSON. |
1623 | 1623 | */ |
1624 | - do_action( 'give_api_output_after', $this->data, $this, $format ); |
|
1624 | + do_action('give_api_output_after', $this->data, $this, $format); |
|
1625 | 1625 | |
1626 | 1626 | give_die(); |
1627 | 1627 | } |
@@ -1638,37 +1638,37 @@ discard block |
||
1638 | 1638 | * |
1639 | 1639 | * @return void |
1640 | 1640 | */ |
1641 | - function user_key_field( $user ) { |
|
1641 | + function user_key_field($user) { |
|
1642 | 1642 | |
1643 | - if ( ( give_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_give_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { |
|
1644 | - $user = get_userdata( $user->ID ); |
|
1643 | + if ((give_get_option('api_allow_user_keys', false) || current_user_can('manage_give_settings')) && current_user_can('edit_user', $user->ID)) { |
|
1644 | + $user = get_userdata($user->ID); |
|
1645 | 1645 | ?> |
1646 | 1646 | <table class="form-table"> |
1647 | 1647 | <tbody> |
1648 | 1648 | <tr> |
1649 | 1649 | <th> |
1650 | - <?php esc_html_e( 'Give API Keys', 'give' ); ?> |
|
1650 | + <?php esc_html_e('Give API Keys', 'give'); ?> |
|
1651 | 1651 | </th> |
1652 | 1652 | <td> |
1653 | 1653 | <?php |
1654 | - $public_key = $this->get_user_public_key( $user->ID ); |
|
1655 | - $secret_key = $this->get_user_secret_key( $user->ID ); |
|
1654 | + $public_key = $this->get_user_public_key($user->ID); |
|
1655 | + $secret_key = $this->get_user_secret_key($user->ID); |
|
1656 | 1656 | ?> |
1657 | - <?php if ( empty( $user->give_user_public_key ) ) { ?> |
|
1657 | + <?php if (empty($user->give_user_public_key)) { ?> |
|
1658 | 1658 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1659 | - <span class="description"><?php esc_html_e( 'Generate API Key', 'give' ); ?></span> |
|
1659 | + <span class="description"><?php esc_html_e('Generate API Key', 'give'); ?></span> |
|
1660 | 1660 | <?php } else { ?> |
1661 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'give' ); ?> </strong> |
|
1662 | - <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> |
|
1661 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Public key:', 'give'); ?> </strong> |
|
1662 | + <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr($public_key); ?>"/> |
|
1663 | 1663 | <br/> |
1664 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'give' ); ?> </strong> |
|
1665 | - <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> |
|
1664 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Secret key:', 'give'); ?> </strong> |
|
1665 | + <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr($secret_key); ?>"/> |
|
1666 | 1666 | <br/> |
1667 | - <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'give' ); ?> </strong> |
|
1668 | - <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> |
|
1667 | + <strong style="display:inline-block; width: 125px;"><?php esc_html_e('Token:', 'give'); ?> </strong> |
|
1668 | + <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr($this->get_token($user->ID)); ?>"/> |
|
1669 | 1669 | <br/> |
1670 | 1670 | <input name="give_set_api_key" type="checkbox" id="give_set_api_key" value="0"/> |
1671 | - <span class="description"><label for="give_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'give' ); ?></label></span> |
|
1671 | + <span class="description"><label for="give_set_api_key"><?php esc_html_e('Revoke API Keys', 'give'); ?></label></span> |
|
1672 | 1672 | <?php } ?> |
1673 | 1673 | </td> |
1674 | 1674 | </tr> |
@@ -1687,69 +1687,69 @@ discard block |
||
1687 | 1687 | * |
1688 | 1688 | * @return void |
1689 | 1689 | */ |
1690 | - public function process_api_key( $args ) { |
|
1690 | + public function process_api_key($args) { |
|
1691 | 1691 | |
1692 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'give-api-nonce' ) ) { |
|
1692 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'give-api-nonce')) { |
|
1693 | 1693 | |
1694 | - wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
1694 | + wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
1695 | 1695 | |
1696 | 1696 | } |
1697 | 1697 | |
1698 | - if ( empty( $args['user_id'] ) ) { |
|
1699 | - wp_die( esc_html__( 'User ID Required.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 401 ) ); |
|
1698 | + if (empty($args['user_id'])) { |
|
1699 | + wp_die(esc_html__('User ID Required.', 'give'), esc_html__('Error', 'give'), array('response' => 401)); |
|
1700 | 1700 | } |
1701 | 1701 | |
1702 | - if ( is_numeric( $args['user_id'] ) ) { |
|
1703 | - $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); |
|
1702 | + if (is_numeric($args['user_id'])) { |
|
1703 | + $user_id = isset($args['user_id']) ? absint($args['user_id']) : get_current_user_id(); |
|
1704 | 1704 | } else { |
1705 | - $userdata = get_user_by( 'login', $args['user_id'] ); |
|
1705 | + $userdata = get_user_by('login', $args['user_id']); |
|
1706 | 1706 | $user_id = $userdata->ID; |
1707 | 1707 | } |
1708 | - $process = isset( $args['give_api_process'] ) ? strtolower( $args['give_api_process'] ) : false; |
|
1708 | + $process = isset($args['give_api_process']) ? strtolower($args['give_api_process']) : false; |
|
1709 | 1709 | |
1710 | - if ( $user_id == get_current_user_id() && ! give_get_option( 'allow_user_api_keys' ) && ! current_user_can( 'manage_give_settings' ) ) { |
|
1710 | + if ($user_id == get_current_user_id() && ! give_get_option('allow_user_api_keys') && ! current_user_can('manage_give_settings')) { |
|
1711 | 1711 | wp_die( |
1712 | 1712 | sprintf( |
1713 | 1713 | /* translators: %s: process */ |
1714 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1714 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1715 | 1715 | $process |
1716 | 1716 | ), |
1717 | - esc_html__( 'Error', 'give' ), |
|
1718 | - array( 'response' => 403 ) |
|
1717 | + esc_html__('Error', 'give'), |
|
1718 | + array('response' => 403) |
|
1719 | 1719 | ); |
1720 | - } elseif ( ! current_user_can( 'manage_give_settings' ) ) { |
|
1720 | + } elseif ( ! current_user_can('manage_give_settings')) { |
|
1721 | 1721 | wp_die( |
1722 | 1722 | sprintf( |
1723 | 1723 | /* translators: %s: process */ |
1724 | - esc_html__( 'You do not have permission to %s API keys for this user.', 'give' ), |
|
1724 | + esc_html__('You do not have permission to %s API keys for this user.', 'give'), |
|
1725 | 1725 | $process |
1726 | 1726 | ), |
1727 | - esc_html__( 'Error', 'give' ), |
|
1728 | - array( 'response' => 403 ) |
|
1727 | + esc_html__('Error', 'give'), |
|
1728 | + array('response' => 403) |
|
1729 | 1729 | ); |
1730 | 1730 | } |
1731 | 1731 | |
1732 | - switch ( $process ) { |
|
1732 | + switch ($process) { |
|
1733 | 1733 | case 'generate': |
1734 | - if ( $this->generate_api_key( $user_id ) ) { |
|
1735 | - delete_transient( 'give_total_api_keys' ); |
|
1736 | - wp_redirect( add_query_arg( 'give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1734 | + if ($this->generate_api_key($user_id)) { |
|
1735 | + delete_transient('give_total_api_keys'); |
|
1736 | + wp_redirect(add_query_arg('give-message', 'api-key-generated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1737 | 1737 | exit(); |
1738 | 1738 | } else { |
1739 | - wp_redirect( add_query_arg( 'give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1739 | + wp_redirect(add_query_arg('give-message', 'api-key-failed', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1740 | 1740 | exit(); |
1741 | 1741 | } |
1742 | 1742 | break; |
1743 | 1743 | case 'regenerate': |
1744 | - $this->generate_api_key( $user_id, true ); |
|
1745 | - delete_transient( 'give_total_api_keys' ); |
|
1746 | - wp_redirect( add_query_arg( 'give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1744 | + $this->generate_api_key($user_id, true); |
|
1745 | + delete_transient('give_total_api_keys'); |
|
1746 | + wp_redirect(add_query_arg('give-message', 'api-key-regenerated', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1747 | 1747 | exit(); |
1748 | 1748 | break; |
1749 | 1749 | case 'revoke': |
1750 | - $this->revoke_api_key( $user_id ); |
|
1751 | - delete_transient( 'give_total_api_keys' ); |
|
1752 | - wp_redirect( add_query_arg( 'give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api' ) ); |
|
1750 | + $this->revoke_api_key($user_id); |
|
1751 | + delete_transient('give_total_api_keys'); |
|
1752 | + wp_redirect(add_query_arg('give-message', 'api-key-revoked', 'edit.php?post_type=give_forms&page=give-settings&tab=api')); |
|
1753 | 1753 | exit(); |
1754 | 1754 | break; |
1755 | 1755 | default; |
@@ -1768,34 +1768,34 @@ discard block |
||
1768 | 1768 | * |
1769 | 1769 | * @return boolean True if (re)generated succesfully, false otherwise. |
1770 | 1770 | */ |
1771 | - public function generate_api_key( $user_id = 0, $regenerate = false ) { |
|
1771 | + public function generate_api_key($user_id = 0, $regenerate = false) { |
|
1772 | 1772 | |
1773 | - if ( empty( $user_id ) ) { |
|
1773 | + if (empty($user_id)) { |
|
1774 | 1774 | return false; |
1775 | 1775 | } |
1776 | 1776 | |
1777 | - $user = get_userdata( $user_id ); |
|
1777 | + $user = get_userdata($user_id); |
|
1778 | 1778 | |
1779 | - if ( ! $user ) { |
|
1779 | + if ( ! $user) { |
|
1780 | 1780 | return false; |
1781 | 1781 | } |
1782 | 1782 | |
1783 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1784 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1783 | + $public_key = $this->get_user_public_key($user_id); |
|
1784 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1785 | 1785 | |
1786 | - if ( empty( $public_key ) || $regenerate == true ) { |
|
1787 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1788 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1786 | + if (empty($public_key) || $regenerate == true) { |
|
1787 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1788 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1789 | 1789 | } else { |
1790 | 1790 | return false; |
1791 | 1791 | } |
1792 | 1792 | |
1793 | - if ( $regenerate == true ) { |
|
1794 | - $this->revoke_api_key( $user->ID ); |
|
1793 | + if ($regenerate == true) { |
|
1794 | + $this->revoke_api_key($user->ID); |
|
1795 | 1795 | } |
1796 | 1796 | |
1797 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1798 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1797 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1798 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1799 | 1799 | |
1800 | 1800 | return true; |
1801 | 1801 | } |
@@ -1810,26 +1810,26 @@ discard block |
||
1810 | 1810 | * |
1811 | 1811 | * @return string |
1812 | 1812 | */ |
1813 | - public function revoke_api_key( $user_id = 0 ) { |
|
1813 | + public function revoke_api_key($user_id = 0) { |
|
1814 | 1814 | |
1815 | - if ( empty( $user_id ) ) { |
|
1815 | + if (empty($user_id)) { |
|
1816 | 1816 | return false; |
1817 | 1817 | } |
1818 | 1818 | |
1819 | - $user = get_userdata( $user_id ); |
|
1819 | + $user = get_userdata($user_id); |
|
1820 | 1820 | |
1821 | - if ( ! $user ) { |
|
1821 | + if ( ! $user) { |
|
1822 | 1822 | return false; |
1823 | 1823 | } |
1824 | 1824 | |
1825 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1826 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1827 | - if ( ! empty( $public_key ) ) { |
|
1828 | - delete_transient( md5( 'give_api_user_' . $public_key ) ); |
|
1829 | - delete_transient( md5( 'give_api_user_public_key' . $user_id ) ); |
|
1830 | - delete_transient( md5( 'give_api_user_secret_key' . $user_id ) ); |
|
1831 | - delete_user_meta( $user_id, $public_key ); |
|
1832 | - delete_user_meta( $user_id, $secret_key ); |
|
1825 | + $public_key = $this->get_user_public_key($user_id); |
|
1826 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1827 | + if ( ! empty($public_key)) { |
|
1828 | + delete_transient(md5('give_api_user_'.$public_key)); |
|
1829 | + delete_transient(md5('give_api_user_public_key'.$user_id)); |
|
1830 | + delete_transient(md5('give_api_user_secret_key'.$user_id)); |
|
1831 | + delete_user_meta($user_id, $public_key); |
|
1832 | + delete_user_meta($user_id, $secret_key); |
|
1833 | 1833 | } else { |
1834 | 1834 | return false; |
1835 | 1835 | } |
@@ -1854,22 +1854,22 @@ discard block |
||
1854 | 1854 | * |
1855 | 1855 | * @return void |
1856 | 1856 | */ |
1857 | - public function update_key( $user_id ) { |
|
1858 | - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['give_set_api_key'] ) ) { |
|
1857 | + public function update_key($user_id) { |
|
1858 | + if (current_user_can('edit_user', $user_id) && isset($_POST['give_set_api_key'])) { |
|
1859 | 1859 | |
1860 | - $user = get_userdata( $user_id ); |
|
1860 | + $user = get_userdata($user_id); |
|
1861 | 1861 | |
1862 | - $public_key = $this->get_user_public_key( $user_id ); |
|
1863 | - $secret_key = $this->get_user_secret_key( $user_id ); |
|
1862 | + $public_key = $this->get_user_public_key($user_id); |
|
1863 | + $secret_key = $this->get_user_secret_key($user_id); |
|
1864 | 1864 | |
1865 | - if ( empty( $public_key ) ) { |
|
1866 | - $new_public_key = $this->generate_public_key( $user->user_email ); |
|
1867 | - $new_secret_key = $this->generate_private_key( $user->ID ); |
|
1865 | + if (empty($public_key)) { |
|
1866 | + $new_public_key = $this->generate_public_key($user->user_email); |
|
1867 | + $new_secret_key = $this->generate_private_key($user->ID); |
|
1868 | 1868 | |
1869 | - update_user_meta( $user_id, $new_public_key, 'give_user_public_key' ); |
|
1870 | - update_user_meta( $user_id, $new_secret_key, 'give_user_secret_key' ); |
|
1869 | + update_user_meta($user_id, $new_public_key, 'give_user_public_key'); |
|
1870 | + update_user_meta($user_id, $new_secret_key, 'give_user_secret_key'); |
|
1871 | 1871 | } else { |
1872 | - $this->revoke_api_key( $user_id ); |
|
1872 | + $this->revoke_api_key($user_id); |
|
1873 | 1873 | } |
1874 | 1874 | } |
1875 | 1875 | } |
@@ -1884,9 +1884,9 @@ discard block |
||
1884 | 1884 | * |
1885 | 1885 | * @return string |
1886 | 1886 | */ |
1887 | - private function generate_public_key( $user_email = '' ) { |
|
1888 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1889 | - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); |
|
1887 | + private function generate_public_key($user_email = '') { |
|
1888 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1889 | + $public = hash('md5', $user_email.$auth_key.date('U')); |
|
1890 | 1890 | |
1891 | 1891 | return $public; |
1892 | 1892 | } |
@@ -1901,9 +1901,9 @@ discard block |
||
1901 | 1901 | * |
1902 | 1902 | * @return string |
1903 | 1903 | */ |
1904 | - private function generate_private_key( $user_id = 0 ) { |
|
1905 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1906 | - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); |
|
1904 | + private function generate_private_key($user_id = 0) { |
|
1905 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1906 | + $secret = hash('md5', $user_id.$auth_key.date('U')); |
|
1907 | 1907 | |
1908 | 1908 | return $secret; |
1909 | 1909 | } |
@@ -1918,8 +1918,8 @@ discard block |
||
1918 | 1918 | * |
1919 | 1919 | * @return string |
1920 | 1920 | */ |
1921 | - public function get_token( $user_id = 0 ) { |
|
1922 | - return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); |
|
1921 | + public function get_token($user_id = 0) { |
|
1922 | + return hash('md5', $this->get_user_secret_key($user_id).$this->get_user_public_key($user_id)); |
|
1923 | 1923 | } |
1924 | 1924 | |
1925 | 1925 | /** |
@@ -1933,9 +1933,9 @@ discard block |
||
1933 | 1933 | |
1934 | 1934 | // Default sales return |
1935 | 1935 | $sales = array(); |
1936 | - $sales['donations']['today'] = $this->stats->get_sales( 0, 'today' ); |
|
1937 | - $sales['donations']['current_month'] = $this->stats->get_sales( 0, 'this_month' ); |
|
1938 | - $sales['donations']['last_month'] = $this->stats->get_sales( 0, 'last_month' ); |
|
1936 | + $sales['donations']['today'] = $this->stats->get_sales(0, 'today'); |
|
1937 | + $sales['donations']['current_month'] = $this->stats->get_sales(0, 'this_month'); |
|
1938 | + $sales['donations']['last_month'] = $this->stats->get_sales(0, 'last_month'); |
|
1939 | 1939 | $sales['donations']['totals'] = give_get_total_sales(); |
1940 | 1940 | |
1941 | 1941 | return $sales; |
@@ -1952,9 +1952,9 @@ discard block |
||
1952 | 1952 | |
1953 | 1953 | // Default earnings return |
1954 | 1954 | $earnings = array(); |
1955 | - $earnings['earnings']['today'] = $this->stats->get_earnings( 0, 'today' ); |
|
1956 | - $earnings['earnings']['current_month'] = $this->stats->get_earnings( 0, 'this_month' ); |
|
1957 | - $earnings['earnings']['last_month'] = $this->stats->get_earnings( 0, 'last_month' ); |
|
1955 | + $earnings['earnings']['today'] = $this->stats->get_earnings(0, 'today'); |
|
1956 | + $earnings['earnings']['current_month'] = $this->stats->get_earnings(0, 'this_month'); |
|
1957 | + $earnings['earnings']['last_month'] = $this->stats->get_earnings(0, 'last_month'); |
|
1958 | 1958 | $earnings['earnings']['totals'] = give_get_total_earnings(); |
1959 | 1959 | |
1960 | 1960 | return $earnings; |
@@ -1974,25 +1974,25 @@ discard block |
||
1974 | 1974 | * |
1975 | 1975 | * @return string The API key/secret for the user supplied |
1976 | 1976 | */ |
1977 | - public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { |
|
1977 | + public function api_key_backwards_compat($check, $object_id, $meta_key, $single) { |
|
1978 | 1978 | |
1979 | - if ( $meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key' ) { |
|
1979 | + if ($meta_key !== 'give_user_public_key' && $meta_key !== 'give_user_secret_key') { |
|
1980 | 1980 | return $check; |
1981 | 1981 | } |
1982 | 1982 | |
1983 | 1983 | $return = $check; |
1984 | 1984 | |
1985 | - switch ( $meta_key ) { |
|
1985 | + switch ($meta_key) { |
|
1986 | 1986 | case 'give_user_public_key': |
1987 | - $return = Give()->api->get_user_public_key( $object_id ); |
|
1987 | + $return = Give()->api->get_user_public_key($object_id); |
|
1988 | 1988 | break; |
1989 | 1989 | case 'give_user_secret_key': |
1990 | - $return = Give()->api->get_user_secret_key( $object_id ); |
|
1990 | + $return = Give()->api->get_user_secret_key($object_id); |
|
1991 | 1991 | break; |
1992 | 1992 | } |
1993 | 1993 | |
1994 | - if ( ! $single ) { |
|
1995 | - $return = array( $return ); |
|
1994 | + if ( ! $single) { |
|
1995 | + $return = array($return); |
|
1996 | 1996 | } |
1997 | 1997 | |
1998 | 1998 | return $return; |
@@ -477,7 +477,7 @@ |
||
477 | 477 | * |
478 | 478 | * @param int $payment_id |
479 | 479 | * |
480 | - * @return int payment_id |
|
480 | + * @return string payment_id |
|
481 | 481 | */ |
482 | 482 | function give_email_tag_payment_id( $payment_id ) { |
483 | 483 | return give_get_payment_number( $payment_id ); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | |
25 | 25 | // Exit if accessed directly. |
26 | -if ( ! defined( 'ABSPATH' ) ) { |
|
26 | +if ( ! defined('ABSPATH')) { |
|
27 | 27 | exit; |
28 | 28 | } |
29 | 29 | |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | * @param string $description Email tag description text |
56 | 56 | * @param callable $func Hook to run when email tag is found |
57 | 57 | */ |
58 | - public function add( $tag, $description, $func ) { |
|
59 | - if ( is_callable( $func ) ) { |
|
60 | - $this->tags[ $tag ] = array( |
|
58 | + public function add($tag, $description, $func) { |
|
59 | + if (is_callable($func)) { |
|
60 | + $this->tags[$tag] = array( |
|
61 | 61 | 'tag' => $tag, |
62 | 62 | 'description' => $description, |
63 | 63 | 'func' => $func |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param string $tag Email tag to remove hook from |
74 | 74 | */ |
75 | - public function remove( $tag ) { |
|
76 | - unset( $this->tags[ $tag ] ); |
|
75 | + public function remove($tag) { |
|
76 | + unset($this->tags[$tag]); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return bool |
87 | 87 | */ |
88 | - public function email_tag_exists( $tag ) { |
|
89 | - return array_key_exists( $tag, $this->tags ); |
|
88 | + public function email_tag_exists($tag) { |
|
89 | + return array_key_exists($tag, $this->tags); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return string Content with email tags filtered out. |
112 | 112 | */ |
113 | - public function do_tags( $content, $payment_id ) { |
|
113 | + public function do_tags($content, $payment_id) { |
|
114 | 114 | |
115 | 115 | // Check if there is at least one tag added. |
116 | - if ( empty( $this->tags ) || ! is_array( $this->tags ) ) { |
|
116 | + if (empty($this->tags) || ! is_array($this->tags)) { |
|
117 | 117 | return $content; |
118 | 118 | } |
119 | 119 | |
120 | 120 | $this->payment_id = $payment_id; |
121 | 121 | |
122 | - $new_content = preg_replace_callback( "/{([A-z0-9\-\_]+)}/s", array( $this, 'do_tag' ), $content ); |
|
122 | + $new_content = preg_replace_callback("/{([A-z0-9\-\_]+)}/s", array($this, 'do_tag'), $content); |
|
123 | 123 | |
124 | 124 | $this->payment_id = null; |
125 | 125 | |
@@ -135,17 +135,17 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return mixed |
137 | 137 | */ |
138 | - public function do_tag( $m ) { |
|
138 | + public function do_tag($m) { |
|
139 | 139 | |
140 | 140 | // Get tag |
141 | 141 | $tag = $m[1]; |
142 | 142 | |
143 | 143 | // Return tag if tag not set |
144 | - if ( ! $this->email_tag_exists( $tag ) ) { |
|
144 | + if ( ! $this->email_tag_exists($tag)) { |
|
145 | 145 | return $m[0]; |
146 | 146 | } |
147 | 147 | |
148 | - return call_user_func( $this->tags[ $tag ]['func'], $this->payment_id, $tag ); |
|
148 | + return call_user_func($this->tags[$tag]['func'], $this->payment_id, $tag); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | } |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | * @param string $description Description of the email tag added |
160 | 160 | * @param callable $func Hook to run when email tag is found |
161 | 161 | */ |
162 | -function give_add_email_tag( $tag, $description, $func ) { |
|
163 | - Give()->email_tags->add( $tag, $description, $func ); |
|
162 | +function give_add_email_tag($tag, $description, $func) { |
|
163 | + Give()->email_tags->add($tag, $description, $func); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @param string $tag Email tag to remove hook from |
172 | 172 | */ |
173 | -function give_remove_email_tag( $tag ) { |
|
174 | - Give()->email_tags->remove( $tag ); |
|
173 | +function give_remove_email_tag($tag) { |
|
174 | + Give()->email_tags->remove($tag); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return bool |
185 | 185 | */ |
186 | -function give_email_tag_exists( $tag ) { |
|
187 | - return Give()->email_tags->email_tag_exists( $tag ); |
|
186 | +function give_email_tag_exists($tag) { |
|
187 | + return Give()->email_tags->email_tag_exists($tag); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | $email_tags = give_get_email_tags(); |
212 | 212 | |
213 | 213 | ob_start(); |
214 | - if ( count( $email_tags ) > 0 ) : ?> |
|
214 | + if (count($email_tags) > 0) : ?> |
|
215 | 215 | <div class="give-email-tags-wrap"> |
216 | - <?php foreach ( $email_tags as $email_tag ) : ?> |
|
216 | + <?php foreach ($email_tags as $email_tag) : ?> |
|
217 | 217 | <span class="give_<?php echo $email_tag['tag']; ?>_tag"> |
218 | 218 | <code>{<?php echo $email_tag['tag']; ?>}</code> - <?php echo $email_tag['description']; ?> |
219 | 219 | </span> |
@@ -235,12 +235,12 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return string Content with email tags filtered out. |
237 | 237 | */ |
238 | -function give_do_email_tags( $content, $payment_id ) { |
|
238 | +function give_do_email_tags($content, $payment_id) { |
|
239 | 239 | |
240 | 240 | // Replace all tags |
241 | - $content = Give()->email_tags->do_tags( $content, $payment_id ); |
|
241 | + $content = Give()->email_tags->do_tags($content, $payment_id); |
|
242 | 242 | |
243 | - $content = apply_filters( 'give_email_template_tags', $content, give_get_payment_meta( $payment_id ), $payment_id ); |
|
243 | + $content = apply_filters('give_email_template_tags', $content, give_get_payment_meta($payment_id), $payment_id); |
|
244 | 244 | |
245 | 245 | // Return content |
246 | 246 | return $content; |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @since 1.0 |
261 | 261 | */ |
262 | - do_action( 'give_add_email_tags' ); |
|
262 | + do_action('give_add_email_tags'); |
|
263 | 263 | } |
264 | 264 | |
265 | -add_action( 'init', 'give_load_email_tags', - 999 ); |
|
265 | +add_action('init', 'give_load_email_tags', - 999); |
|
266 | 266 | |
267 | 267 | /** |
268 | 268 | * Add default Give email template tags. |
@@ -275,97 +275,97 @@ discard block |
||
275 | 275 | $email_tags = array( |
276 | 276 | array( |
277 | 277 | 'tag' => 'donation', |
278 | - 'description' => esc_html__( 'The donation form name, and the donation level (if applicable).', 'give' ), |
|
278 | + 'description' => esc_html__('The donation form name, and the donation level (if applicable).', 'give'), |
|
279 | 279 | 'function' => 'give_email_tag_donation' |
280 | 280 | ), |
281 | 281 | array( |
282 | 282 | 'tag' => 'form_title', |
283 | - 'description' => esc_html__( 'The donation form name.', 'give' ), |
|
283 | + 'description' => esc_html__('The donation form name.', 'give'), |
|
284 | 284 | 'function' => 'give_email_tag_form_title' |
285 | 285 | ), |
286 | 286 | array( |
287 | 287 | 'tag' => 'amount', |
288 | - 'description' => esc_html__( 'The total donation amount with currency sign.', 'give' ), |
|
288 | + 'description' => esc_html__('The total donation amount with currency sign.', 'give'), |
|
289 | 289 | 'function' => 'give_email_tag_amount' |
290 | 290 | ), |
291 | 291 | array( |
292 | 292 | 'tag' => 'price', |
293 | - 'description' => esc_html__( 'The total donation amount with currency sign.', 'give' ), |
|
293 | + 'description' => esc_html__('The total donation amount with currency sign.', 'give'), |
|
294 | 294 | 'function' => 'give_email_tag_price' |
295 | 295 | ), |
296 | 296 | array( |
297 | 297 | 'tag' => 'name', |
298 | - 'description' => esc_html__( 'The donor\'s first name.', 'give' ), |
|
298 | + 'description' => esc_html__('The donor\'s first name.', 'give'), |
|
299 | 299 | 'function' => 'give_email_tag_first_name' |
300 | 300 | ), |
301 | 301 | array( |
302 | 302 | 'tag' => 'fullname', |
303 | - 'description' => esc_html__( 'The donor\'s full name, first and last.', 'give' ), |
|
303 | + 'description' => esc_html__('The donor\'s full name, first and last.', 'give'), |
|
304 | 304 | 'function' => 'give_email_tag_fullname' |
305 | 305 | ), |
306 | 306 | array( |
307 | 307 | 'tag' => 'username', |
308 | - 'description' => esc_html__( 'The donor\'s user name on the site, if they registered an account.', 'give' ), |
|
308 | + 'description' => esc_html__('The donor\'s user name on the site, if they registered an account.', 'give'), |
|
309 | 309 | 'function' => 'give_email_tag_username' |
310 | 310 | ), |
311 | 311 | array( |
312 | 312 | 'tag' => 'user_email', |
313 | - 'description' => esc_html__( 'The donor\'s email address.', 'give' ), |
|
313 | + 'description' => esc_html__('The donor\'s email address.', 'give'), |
|
314 | 314 | 'function' => 'give_email_tag_user_email' |
315 | 315 | ), |
316 | 316 | array( |
317 | 317 | 'tag' => 'billing_address', |
318 | - 'description' => esc_html__( 'The donor\'s billing address.', 'give' ), |
|
318 | + 'description' => esc_html__('The donor\'s billing address.', 'give'), |
|
319 | 319 | 'function' => 'give_email_tag_billing_address' |
320 | 320 | ), |
321 | 321 | array( |
322 | 322 | 'tag' => 'date', |
323 | - 'description' => esc_html__( 'The date of the donation.', 'give' ), |
|
323 | + 'description' => esc_html__('The date of the donation.', 'give'), |
|
324 | 324 | 'function' => 'give_email_tag_date' |
325 | 325 | ), |
326 | 326 | array( |
327 | 327 | 'tag' => 'payment_id', |
328 | - 'description' => esc_html__( 'The unique ID number for this donation.', 'give' ), |
|
328 | + 'description' => esc_html__('The unique ID number for this donation.', 'give'), |
|
329 | 329 | 'function' => 'give_email_tag_payment_id' |
330 | 330 | ), |
331 | 331 | array( |
332 | 332 | 'tag' => 'receipt_id', |
333 | - 'description' => esc_html__( 'The unique ID number for this donation receipt.', 'give' ), |
|
333 | + 'description' => esc_html__('The unique ID number for this donation receipt.', 'give'), |
|
334 | 334 | 'function' => 'give_email_tag_receipt_id' |
335 | 335 | ), |
336 | 336 | array( |
337 | 337 | 'tag' => 'payment_method', |
338 | - 'description' => esc_html__( 'The method of payment used for this donation.', 'give' ), |
|
338 | + 'description' => esc_html__('The method of payment used for this donation.', 'give'), |
|
339 | 339 | 'function' => 'give_email_tag_payment_method' |
340 | 340 | ), |
341 | 341 | array( |
342 | 342 | 'tag' => 'sitename', |
343 | - 'description' => esc_html__( 'The name of your site.', 'give' ), |
|
343 | + 'description' => esc_html__('The name of your site.', 'give'), |
|
344 | 344 | 'function' => 'give_email_tag_sitename' |
345 | 345 | ), |
346 | 346 | array( |
347 | 347 | 'tag' => 'receipt_link', |
348 | - 'description' => esc_html__( 'The donation receipt direct link, to view the receipt on the website.', 'give' ), |
|
348 | + 'description' => esc_html__('The donation receipt direct link, to view the receipt on the website.', 'give'), |
|
349 | 349 | 'function' => 'give_email_tag_receipt_link' |
350 | 350 | ), |
351 | 351 | array( |
352 | 352 | 'tag' => 'receipt_link_url', |
353 | - 'description' => esc_html__( 'The donation receipt direct URL, to view the receipt on the website.', 'give' ), |
|
353 | + 'description' => esc_html__('The donation receipt direct URL, to view the receipt on the website.', 'give'), |
|
354 | 354 | 'function' => 'give_email_tag_receipt_link_url' |
355 | 355 | ), |
356 | 356 | ); |
357 | 357 | |
358 | 358 | // Apply give_email_tags filter |
359 | - $email_tags = apply_filters( 'give_email_tags', $email_tags ); |
|
359 | + $email_tags = apply_filters('give_email_tags', $email_tags); |
|
360 | 360 | |
361 | 361 | // Add email tags |
362 | - foreach ( $email_tags as $email_tag ) { |
|
363 | - give_add_email_tag( $email_tag['tag'], $email_tag['description'], $email_tag['function'] ); |
|
362 | + foreach ($email_tags as $email_tag) { |
|
363 | + give_add_email_tag($email_tag['tag'], $email_tag['description'], $email_tag['function']); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | } |
367 | 367 | |
368 | -add_action( 'give_add_email_tags', 'give_setup_email_tags' ); |
|
368 | +add_action('give_add_email_tags', 'give_setup_email_tags'); |
|
369 | 369 | |
370 | 370 | |
371 | 371 | /** |
@@ -377,15 +377,15 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @return string name |
379 | 379 | */ |
380 | -function give_email_tag_first_name( $payment_id ) { |
|
381 | - $payment = new Give_Payment( $payment_id ); |
|
380 | +function give_email_tag_first_name($payment_id) { |
|
381 | + $payment = new Give_Payment($payment_id); |
|
382 | 382 | $user_info = $payment->user_info; |
383 | 383 | |
384 | - if ( empty( $user_info ) ) { |
|
384 | + if (empty($user_info)) { |
|
385 | 385 | return ''; |
386 | 386 | } |
387 | 387 | |
388 | - $email_name = give_get_email_names( $user_info ); |
|
388 | + $email_name = give_get_email_names($user_info); |
|
389 | 389 | |
390 | 390 | return $email_name['name']; |
391 | 391 | } |
@@ -399,15 +399,15 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return string fullname |
401 | 401 | */ |
402 | -function give_email_tag_fullname( $payment_id ) { |
|
403 | - $payment = new Give_Payment( $payment_id ); |
|
402 | +function give_email_tag_fullname($payment_id) { |
|
403 | + $payment = new Give_Payment($payment_id); |
|
404 | 404 | $user_info = $payment->user_info; |
405 | 405 | |
406 | - if ( empty( $user_info ) ) { |
|
406 | + if (empty($user_info)) { |
|
407 | 407 | return ''; |
408 | 408 | } |
409 | 409 | |
410 | - $email_name = give_get_email_names( $user_info ); |
|
410 | + $email_name = give_get_email_names($user_info); |
|
411 | 411 | |
412 | 412 | return $email_name['fullname']; |
413 | 413 | } |
@@ -421,15 +421,15 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @return string username. |
423 | 423 | */ |
424 | -function give_email_tag_username( $payment_id ) { |
|
425 | - $payment = new Give_Payment( $payment_id ); |
|
424 | +function give_email_tag_username($payment_id) { |
|
425 | + $payment = new Give_Payment($payment_id); |
|
426 | 426 | $user_info = $payment->user_info; |
427 | 427 | |
428 | - if ( empty( $user_info ) ) { |
|
428 | + if (empty($user_info)) { |
|
429 | 429 | return ''; |
430 | 430 | } |
431 | 431 | |
432 | - $email_name = give_get_email_names( $user_info ); |
|
432 | + $email_name = give_get_email_names($user_info); |
|
433 | 433 | |
434 | 434 | return $email_name['username']; |
435 | 435 | } |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @return string user_email |
445 | 445 | */ |
446 | -function give_email_tag_user_email( $payment_id ) { |
|
447 | - $payment = new Give_Payment( $payment_id ); |
|
446 | +function give_email_tag_user_email($payment_id) { |
|
447 | + $payment = new Give_Payment($payment_id); |
|
448 | 448 | |
449 | 449 | return $payment->email; |
450 | 450 | } |
@@ -458,9 +458,9 @@ discard block |
||
458 | 458 | * |
459 | 459 | * @return string billing_address |
460 | 460 | */ |
461 | -function give_email_tag_billing_address( $payment_id ) { |
|
462 | - $user_info = give_get_payment_meta_user_info( $payment_id ); |
|
463 | - $user_address = ! empty( $user_info['address'] ) ? $user_info['address'] : array( |
|
461 | +function give_email_tag_billing_address($payment_id) { |
|
462 | + $user_info = give_get_payment_meta_user_info($payment_id); |
|
463 | + $user_address = ! empty($user_info['address']) ? $user_info['address'] : array( |
|
464 | 464 | 'line1' => '', |
465 | 465 | 'line2' => '', |
466 | 466 | 'city' => '', |
@@ -469,11 +469,11 @@ discard block |
||
469 | 469 | 'zip' => '' |
470 | 470 | ); |
471 | 471 | |
472 | - $return = $user_address['line1'] . "\n"; |
|
473 | - if ( ! empty( $user_address['line2'] ) ) { |
|
474 | - $return .= $user_address['line2'] . "\n"; |
|
472 | + $return = $user_address['line1']."\n"; |
|
473 | + if ( ! empty($user_address['line2'])) { |
|
474 | + $return .= $user_address['line2']."\n"; |
|
475 | 475 | } |
476 | - $return .= $user_address['city'] . ' ' . $user_address['zip'] . ' ' . $user_address['state'] . "\n"; |
|
476 | + $return .= $user_address['city'].' '.$user_address['zip'].' '.$user_address['state']."\n"; |
|
477 | 477 | $return .= $user_address['country']; |
478 | 478 | |
479 | 479 | return $return; |
@@ -488,10 +488,10 @@ discard block |
||
488 | 488 | * |
489 | 489 | * @return string date |
490 | 490 | */ |
491 | -function give_email_tag_date( $payment_id ) { |
|
492 | - $payment = new Give_Payment( $payment_id ); |
|
491 | +function give_email_tag_date($payment_id) { |
|
492 | + $payment = new Give_Payment($payment_id); |
|
493 | 493 | |
494 | - return date_i18n( give_date_format(), strtotime( $payment->date ) ); |
|
494 | + return date_i18n(give_date_format(), strtotime($payment->date)); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | * |
504 | 504 | * @return string amount |
505 | 505 | */ |
506 | -function give_email_tag_amount( $payment_id ) { |
|
507 | - $payment = new Give_Payment( $payment_id ); |
|
508 | - $give_amount = give_currency_filter( give_format_amount( $payment->total ), $payment->currency ); |
|
506 | +function give_email_tag_amount($payment_id) { |
|
507 | + $payment = new Give_Payment($payment_id); |
|
508 | + $give_amount = give_currency_filter(give_format_amount($payment->total), $payment->currency); |
|
509 | 509 | |
510 | - return html_entity_decode( $give_amount, ENT_COMPAT, 'UTF-8' ); |
|
510 | + return html_entity_decode($give_amount, ENT_COMPAT, 'UTF-8'); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -519,8 +519,8 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @return string price |
521 | 521 | */ |
522 | -function give_email_tag_price( $payment_id ) { |
|
523 | - return give_email_tag_amount( $payment_id ); |
|
522 | +function give_email_tag_price($payment_id) { |
|
523 | + return give_email_tag_amount($payment_id); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | * |
533 | 533 | * @return int payment_id |
534 | 534 | */ |
535 | -function give_email_tag_payment_id( $payment_id ) { |
|
536 | - $payment = new Give_Payment( $payment_id ); |
|
535 | +function give_email_tag_payment_id($payment_id) { |
|
536 | + $payment = new Give_Payment($payment_id); |
|
537 | 537 | |
538 | 538 | return $payment->number; |
539 | 539 | } |
@@ -547,8 +547,8 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @return string receipt_id |
549 | 549 | */ |
550 | -function give_email_tag_receipt_id( $payment_id ) { |
|
551 | - $payment = new Give_Payment( $payment_id ); |
|
550 | +function give_email_tag_receipt_id($payment_id) { |
|
551 | + $payment = new Give_Payment($payment_id); |
|
552 | 552 | |
553 | 553 | return $payment->key; |
554 | 554 | } |
@@ -562,14 +562,14 @@ discard block |
||
562 | 562 | * |
563 | 563 | * @return string $form_title |
564 | 564 | */ |
565 | -function give_email_tag_donation( $payment_id ) { |
|
566 | - $payment = new Give_Payment( $payment_id ); |
|
565 | +function give_email_tag_donation($payment_id) { |
|
566 | + $payment = new Give_Payment($payment_id); |
|
567 | 567 | $payment_meta = $payment->payment_meta; |
568 | - $level_title = give_has_variable_prices( $payment->form_id ); |
|
568 | + $level_title = give_has_variable_prices($payment->form_id); |
|
569 | 569 | $separator = $level_title ? '-' : ''; |
570 | - $form_title = strip_tags( give_get_payment_form_title( $payment_meta, false, $separator ) ); |
|
570 | + $form_title = strip_tags(give_get_payment_form_title($payment_meta, false, $separator)); |
|
571 | 571 | |
572 | - return ! empty( $form_title ) ? $form_title : ''; |
|
572 | + return ! empty($form_title) ? $form_title : ''; |
|
573 | 573 | |
574 | 574 | } |
575 | 575 | |
@@ -582,11 +582,11 @@ discard block |
||
582 | 582 | * |
583 | 583 | * @return string $form_title |
584 | 584 | */ |
585 | -function give_email_tag_form_title( $payment_id ) { |
|
586 | - $payment = new Give_Payment( $payment_id ); |
|
585 | +function give_email_tag_form_title($payment_id) { |
|
586 | + $payment = new Give_Payment($payment_id); |
|
587 | 587 | $payment_meta = $payment->payment_meta; |
588 | 588 | |
589 | - return isset( $payment_meta['form_title'] ) ? strip_tags( $payment_meta['form_title'] ) : ''; |
|
589 | + return isset($payment_meta['form_title']) ? strip_tags($payment_meta['form_title']) : ''; |
|
590 | 590 | |
591 | 591 | } |
592 | 592 | |
@@ -599,10 +599,10 @@ discard block |
||
599 | 599 | * |
600 | 600 | * @return string gateway |
601 | 601 | */ |
602 | -function give_email_tag_payment_method( $payment_id ) { |
|
603 | - $payment = new Give_Payment( $payment_id ); |
|
602 | +function give_email_tag_payment_method($payment_id) { |
|
603 | + $payment = new Give_Payment($payment_id); |
|
604 | 604 | |
605 | - return give_get_gateway_checkout_label( $payment->gateway ); |
|
605 | + return give_get_gateway_checkout_label($payment->gateway); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | /** |
@@ -614,8 +614,8 @@ discard block |
||
614 | 614 | * |
615 | 615 | * @return string sitename |
616 | 616 | */ |
617 | -function give_email_tag_sitename( $payment_id ) { |
|
618 | - return wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
617 | +function give_email_tag_sitename($payment_id) { |
|
618 | + return wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -627,19 +627,19 @@ discard block |
||
627 | 627 | * |
628 | 628 | * @return string receipt_link |
629 | 629 | */ |
630 | -function give_email_tag_receipt_link( $payment_id ) { |
|
630 | +function give_email_tag_receipt_link($payment_id) { |
|
631 | 631 | |
632 | - $receipt_url = esc_url( add_query_arg( array( |
|
633 | - 'payment_key' => give_get_payment_key( $payment_id ), |
|
632 | + $receipt_url = esc_url(add_query_arg(array( |
|
633 | + 'payment_key' => give_get_payment_key($payment_id), |
|
634 | 634 | 'give_action' => 'view_receipt' |
635 | - ), home_url() ) ); |
|
636 | - $formatted = sprintf( |
|
635 | + ), home_url())); |
|
636 | + $formatted = sprintf( |
|
637 | 637 | '<a href="%1$s">%2$s</a>', |
638 | 638 | $receipt_url, |
639 | - esc_html__( 'View it in your browser', 'give' ) |
|
639 | + esc_html__('View it in your browser', 'give') |
|
640 | 640 | ); |
641 | 641 | |
642 | - if ( give_get_option( 'email_template' ) !== 'none' ) { |
|
642 | + if (give_get_option('email_template') !== 'none') { |
|
643 | 643 | return $formatted; |
644 | 644 | } else { |
645 | 645 | return $receipt_url; |
@@ -658,12 +658,12 @@ discard block |
||
658 | 658 | * |
659 | 659 | * @return string receipt_url |
660 | 660 | */ |
661 | -function give_email_tag_receipt_link_url( $payment_id ) { |
|
661 | +function give_email_tag_receipt_link_url($payment_id) { |
|
662 | 662 | |
663 | - $receipt_url = esc_url( add_query_arg( array( |
|
664 | - 'payment_key' => give_get_payment_key( $payment_id ), |
|
663 | + $receipt_url = esc_url(add_query_arg(array( |
|
664 | + 'payment_key' => give_get_payment_key($payment_id), |
|
665 | 665 | 'give_action' => 'view_receipt' |
666 | - ), home_url() ) ); |
|
666 | + ), home_url())); |
|
667 | 667 | |
668 | 668 | return $receipt_url; |
669 | 669 |