@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @category Class |
12 | 12 | * @author WordImpress |
13 | 13 | */ |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | * and data exists in the queue. |
55 | 55 | */ |
56 | 56 | public function handle_cron_healthcheck() { |
57 | - if ( $this->is_process_running() ) { |
|
57 | + if ($this->is_process_running()) { |
|
58 | 58 | // Background process already running. |
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | - if ( $this->is_queue_empty() ) { |
|
62 | + if ($this->is_queue_empty()) { |
|
63 | 63 | // No data to process. |
64 | 64 | $this->clear_scheduled_event(); |
65 | 65 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * Schedule fallback event. |
74 | 74 | */ |
75 | 75 | protected function schedule_event() { |
76 | - if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { |
|
77 | - wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier ); |
|
76 | + if ( ! wp_next_scheduled($this->cron_hook_identifier)) { |
|
77 | + wp_schedule_event(time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return mixed |
92 | 92 | */ |
93 | - protected function task( $update ) { |
|
94 | - if ( empty( $update ) ) { |
|
93 | + protected function task($update) { |
|
94 | + if (empty($update)) { |
|
95 | 95 | return false; |
96 | 96 | } |
97 | 97 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | 'update_info' => $update, |
106 | 106 | 'step' => 1, |
107 | 107 | 'update' => 1, |
108 | - 'heading' => sprintf( 'Update %s of {update_count}', 1 ), |
|
108 | + 'heading' => sprintf('Update %s of {update_count}', 1), |
|
109 | 109 | 'percentage' => $give_updates->percentage, |
110 | 110 | ) |
111 | 111 | ); |
@@ -113,30 +113,30 @@ discard block |
||
113 | 113 | // Continuously skip update if previous update does not complete yet. |
114 | 114 | if ( |
115 | 115 | $resume_update['update_info']['id'] !== $update['id'] && |
116 | - ! give_has_upgrade_completed( $resume_update['update_info']['id'] ) |
|
116 | + ! give_has_upgrade_completed($resume_update['update_info']['id']) |
|
117 | 117 | ) { |
118 | 118 | $batch = Give_Updates::$background_updater->get_all_batch(); |
119 | - $batch_data_count = count( $batch->data ); |
|
119 | + $batch_data_count = count($batch->data); |
|
120 | 120 | |
121 | - if ( ! empty( $batch ) && 1 === $batch_data_count ) { |
|
122 | - if ( ! empty( $update['depend'] ) ) { |
|
121 | + if ( ! empty($batch) && 1 === $batch_data_count) { |
|
122 | + if ( ! empty($update['depend'])) { |
|
123 | 123 | |
124 | 124 | $give_updates = Give_Updates::get_instance(); |
125 | - $all_updates = $give_updates->get_updates( 'database', 'all' ); |
|
126 | - $all_update_ids = wp_list_pluck( $all_updates, 'id' ); |
|
125 | + $all_updates = $give_updates->get_updates('database', 'all'); |
|
126 | + $all_update_ids = wp_list_pluck($all_updates, 'id'); |
|
127 | 127 | |
128 | - foreach ( $update['depend'] as $depend ) { |
|
129 | - if ( give_has_upgrade_completed( $depend ) ) { |
|
128 | + foreach ($update['depend'] as $depend) { |
|
129 | + if (give_has_upgrade_completed($depend)) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | |
133 | - if ( in_array( $depend, $all_update_ids ) ) { |
|
134 | - array_unshift( $batch->data, $all_updates[ array_search( $depend, $all_update_ids ) ] ); |
|
133 | + if (in_array($depend, $all_update_ids)) { |
|
134 | + array_unshift($batch->data, $all_updates[array_search($depend, $all_update_ids)]); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - if( $batch_data_count !== count( $batch->data ) ) { |
|
139 | - update_option( $batch->key, $batch->data ); |
|
138 | + if ($batch_data_count !== count($batch->data)) { |
|
139 | + update_option($batch->key, $batch->data); |
|
140 | 140 | $this->dispatch(); |
141 | 141 | |
142 | 142 | wp_die(); |
@@ -150,15 +150,15 @@ discard block |
||
150 | 150 | |
151 | 151 | // Set params. |
152 | 152 | $resume_update['update_info'] = $update; |
153 | - $give_updates->step = absint( $resume_update['step'] ); |
|
154 | - $give_updates->update = absint( $resume_update['update'] ); |
|
155 | - $is_parent_update_completed = $give_updates->is_parent_updates_completed( $update ); |
|
153 | + $give_updates->step = absint($resume_update['step']); |
|
154 | + $give_updates->update = absint($resume_update['update']); |
|
155 | + $is_parent_update_completed = $give_updates->is_parent_updates_completed($update); |
|
156 | 156 | |
157 | 157 | |
158 | 158 | // Skip update if dependency update does not complete yet. |
159 | - if ( empty( $is_parent_update_completed ) ) { |
|
159 | + if (empty($is_parent_update_completed)) { |
|
160 | 160 | // @todo: set error when you have only one update with invalid dependency |
161 | - if ( ! is_null( $is_parent_update_completed ) ) { |
|
161 | + if ( ! is_null($is_parent_update_completed)) { |
|
162 | 162 | return $update; |
163 | 163 | } |
164 | 164 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | Give_Cache::disable(); |
170 | 170 | |
171 | 171 | // Run update. |
172 | - if ( is_array( $update['callback'] ) ) { |
|
172 | + if (is_array($update['callback'])) { |
|
173 | 173 | $update['callback'][0]->$update['callback'][1](); |
174 | 174 | } else { |
175 | 175 | $update['callback'](); |
@@ -178,21 +178,21 @@ discard block |
||
178 | 178 | // Set update info. |
179 | 179 | $doing_upgrade_args = array( |
180 | 180 | 'update_info' => $update, |
181 | - 'step' => ++ $give_updates->step, |
|
181 | + 'step' => ++$give_updates->step, |
|
182 | 182 | 'update' => $give_updates->update, |
183 | - 'heading' => sprintf( 'Update %s of %s', $give_updates->update, get_option( 'give_db_update_count' ) ), |
|
183 | + 'heading' => sprintf('Update %s of %s', $give_updates->update, get_option('give_db_update_count')), |
|
184 | 184 | 'percentage' => $give_updates->percentage, |
185 | 185 | 'total_percentage' => $give_updates->get_db_update_processing_percentage(), |
186 | 186 | ); |
187 | 187 | |
188 | 188 | // Cache upgrade. |
189 | - update_option( 'give_doing_upgrade', $doing_upgrade_args ); |
|
189 | + update_option('give_doing_upgrade', $doing_upgrade_args); |
|
190 | 190 | |
191 | 191 | // Enable cache. |
192 | 192 | Give_Cache::enable(); |
193 | 193 | |
194 | 194 | // Check if current update completed or not. |
195 | - if ( give_has_upgrade_completed( $update['id'] ) ) { |
|
195 | + if (give_has_upgrade_completed($update['id'])) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | protected function complete() { |
209 | 209 | parent::complete(); |
210 | 210 | |
211 | - delete_option( 'give_db_update_count' ); |
|
212 | - delete_option( 'give_doing_upgrade' ); |
|
213 | - add_option( 'give_show_db_upgrade_complete_notice', 1, '', 'no' ); |
|
211 | + delete_option('give_db_update_count'); |
|
212 | + delete_option('give_doing_upgrade'); |
|
213 | + add_option('give_show_db_upgrade_complete_notice', 1, '', 'no'); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | * @return int |
220 | 220 | */ |
221 | 221 | protected function get_memory_limit() { |
222 | - if ( function_exists( 'ini_get' ) ) { |
|
223 | - $memory_limit = ini_get( 'memory_limit' ); |
|
222 | + if (function_exists('ini_get')) { |
|
223 | + $memory_limit = ini_get('memory_limit'); |
|
224 | 224 | } else { |
225 | 225 | // Sensible default. |
226 | 226 | $memory_limit = '128M'; |
227 | 227 | } |
228 | 228 | |
229 | - if ( ! $memory_limit || '-1' === $memory_limit ) { |
|
229 | + if ( ! $memory_limit || '-1' === $memory_limit) { |
|
230 | 230 | // Unlimited, set to 32GB. |
231 | 231 | $memory_limit = '32000M'; |
232 | 232 | } |
233 | 233 | |
234 | - return intval( $memory_limit ) * 1024 * 1024; |
|
234 | + return intval($memory_limit) * 1024 * 1024; |
|
235 | 235 | } |
236 | 236 | } |
@@ -80,34 +80,34 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param array $args |
82 | 82 | */ |
83 | - public function register( $args ) { |
|
83 | + public function register($args) { |
|
84 | 84 | $args_default = array( |
85 | 85 | 'id' => '', |
86 | 86 | 'version' => '', |
87 | 87 | 'callback' => '', |
88 | 88 | ); |
89 | 89 | |
90 | - $args = wp_parse_args( $args, $args_default ); |
|
90 | + $args = wp_parse_args($args, $args_default); |
|
91 | 91 | |
92 | 92 | // You can only register database upgrade. |
93 | 93 | $args['type'] = 'database'; |
94 | 94 | |
95 | 95 | // Bailout. |
96 | 96 | if ( |
97 | - empty( $args['id'] ) || |
|
98 | - empty( $args['version'] ) || |
|
99 | - empty( $args['callback'] ) || |
|
100 | - ! is_callable( $args['callback'] ) |
|
97 | + empty($args['id']) || |
|
98 | + empty($args['version']) || |
|
99 | + empty($args['callback']) || |
|
100 | + ! is_callable($args['callback']) |
|
101 | 101 | ) { |
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // Change depend param to array. |
106 | - if ( isset( $args['depend'] ) && is_string( $args['depend'] ) ) { |
|
107 | - $args['depend'] = array( $args['depend'] ); |
|
106 | + if (isset($args['depend']) && is_string($args['depend'])) { |
|
107 | + $args['depend'] = array($args['depend']); |
|
108 | 108 | } |
109 | 109 | |
110 | - $this->updates[ $args['type'] ][] = $args; |
|
110 | + $this->updates[$args['type']][] = $args; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @return static |
119 | 119 | */ |
120 | 120 | static function get_instance() { |
121 | - if ( is_null( self::$instance ) ) { |
|
121 | + if (is_null(self::$instance)) { |
|
122 | 122 | self::$instance = new self(); |
123 | 123 | } |
124 | 124 | |
@@ -136,24 +136,24 @@ discard block |
||
136 | 136 | /** |
137 | 137 | * Load file |
138 | 138 | */ |
139 | - require_once GIVE_PLUGIN_DIR . 'includes/class-give-background-updater.php'; |
|
140 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; |
|
139 | + require_once GIVE_PLUGIN_DIR.'includes/class-give-background-updater.php'; |
|
140 | + require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php'; |
|
141 | 141 | |
142 | 142 | self::$background_updater = new Give_Background_Updater(); |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Setup hooks. |
146 | 146 | */ |
147 | - add_action( 'init', array( $this, '__register_upgrade' ), 9999 ); |
|
148 | - add_action( 'give_set_upgrade_completed', array( $this, '__flush_resume_updates' ), 9999 ); |
|
149 | - add_action( 'wp_ajax_give_db_updates_info', array( $this, '__give_db_updates_info' ) ); |
|
150 | - add_action( 'wp_ajax_give_run_db_updates', array( $this, '__give_start_updating' ) ); |
|
151 | - add_action( 'admin_init', array( $this, '__redirect_admin' ) ); |
|
152 | - add_action( 'admin_notices', array( $this, '__show_notice' ) ); |
|
153 | - |
|
154 | - if ( is_admin() ) { |
|
155 | - add_action( 'admin_init', array( $this, '__change_donations_label' ), 9999 ); |
|
156 | - add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 ); |
|
147 | + add_action('init', array($this, '__register_upgrade'), 9999); |
|
148 | + add_action('give_set_upgrade_completed', array($this, '__flush_resume_updates'), 9999); |
|
149 | + add_action('wp_ajax_give_db_updates_info', array($this, '__give_db_updates_info')); |
|
150 | + add_action('wp_ajax_give_run_db_updates', array($this, '__give_start_updating')); |
|
151 | + add_action('admin_init', array($this, '__redirect_admin')); |
|
152 | + add_action('admin_notices', array($this, '__show_notice')); |
|
153 | + |
|
154 | + if (is_admin()) { |
|
155 | + add_action('admin_init', array($this, '__change_donations_label'), 9999); |
|
156 | + add_action('admin_menu', array($this, '__register_menu'), 9999); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | $addons = give_get_plugins(); |
168 | 168 | $plugin_updates = get_plugin_updates(); |
169 | 169 | |
170 | - foreach ( $addons as $key => $info ) { |
|
171 | - if ( 'active' != $info['Status'] || 'add-on' != $info['Type'] || empty( $plugin_updates[ $key ] ) ) { |
|
170 | + foreach ($addons as $key => $info) { |
|
171 | + if ('active' != $info['Status'] || 'add-on' != $info['Type'] || empty($plugin_updates[$key])) { |
|
172 | 172 | continue; |
173 | 173 | } |
174 | 174 | |
175 | - $this->updates['plugin'][] = array_merge( $info, (array) $plugin_updates[ $key ] ); |
|
175 | + $this->updates['plugin'][] = array_merge($info, (array) $plugin_updates[$key]); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @access public |
185 | 185 | */ |
186 | 186 | public function __register_upgrade() { |
187 | - if ( ! is_admin() ) { |
|
187 | + if ( ! is_admin()) { |
|
188 | 188 | return; |
189 | 189 | } |
190 | 190 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @since 1.8.12 |
195 | 195 | */ |
196 | - do_action( 'give_register_updates', $this ); |
|
196 | + do_action('give_register_updates', $this); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -206,21 +206,20 @@ discard block |
||
206 | 206 | global $menu; |
207 | 207 | |
208 | 208 | // Bailout. |
209 | - if ( empty( $menu ) || ! $this->get_total_update_count() ) { |
|
209 | + if (empty($menu) || ! $this->get_total_update_count()) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | |
213 | - foreach ( $menu as $index => $menu_item ) { |
|
214 | - if ( 'edit.php?post_type=give_forms' !== $menu_item[2] ) { |
|
213 | + foreach ($menu as $index => $menu_item) { |
|
214 | + if ('edit.php?post_type=give_forms' !== $menu_item[2]) { |
|
215 | 215 | continue; |
216 | 216 | } |
217 | 217 | |
218 | - $menu[ $index ][0] = sprintf( |
|
218 | + $menu[$index][0] = sprintf( |
|
219 | 219 | '%1$s <span class="update-plugins"><span class="plugin-count give-update-progress-count">%2$s%3$s</span></span>', |
220 | - __( 'Donations', 'give' ), |
|
220 | + __('Donations', 'give'), |
|
221 | 221 | $this->is_doing_updates() ? |
222 | - $this->get_db_update_processing_percentage() : |
|
223 | - $this->get_total_update_count(), |
|
222 | + $this->get_db_update_processing_percentage() : $this->get_total_update_count(), |
|
224 | 223 | $this->is_doing_updates() ? '%' : '' |
225 | 224 | ); |
226 | 225 | |
@@ -236,7 +235,7 @@ discard block |
||
236 | 235 | */ |
237 | 236 | public function __register_menu() { |
238 | 237 | // Bailout. |
239 | - if( ! give_test_ajax_works() ) { |
|
238 | + if ( ! give_test_ajax_works()) { |
|
240 | 239 | return; |
241 | 240 | } |
242 | 241 | |
@@ -244,17 +243,17 @@ discard block |
||
244 | 243 | $this->__register_plugin_addon_updates(); |
245 | 244 | |
246 | 245 | // Bailout. |
247 | - if ( ! $this->get_total_update_count() ) { |
|
246 | + if ( ! $this->get_total_update_count()) { |
|
248 | 247 | // Show complete update message if still on update setting page. |
249 | - if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) { |
|
248 | + if (isset($_GET['page']) && 'give-updates' === $_GET['page']) { |
|
250 | 249 | // Upgrades |
251 | 250 | add_submenu_page( |
252 | 251 | 'edit.php?post_type=give_forms', |
253 | - esc_html__( 'Give Updates Complete', 'give' ), |
|
254 | - __( 'Updates', 'give' ), |
|
252 | + esc_html__('Give Updates Complete', 'give'), |
|
253 | + __('Updates', 'give'), |
|
255 | 254 | 'manage_give_settings', |
256 | 255 | 'give-updates', |
257 | - array( $this, 'render_complete_page' ) |
|
256 | + array($this, 'render_complete_page') |
|
258 | 257 | ); |
259 | 258 | } |
260 | 259 | |
@@ -264,18 +263,17 @@ discard block |
||
264 | 263 | // Upgrades |
265 | 264 | add_submenu_page( |
266 | 265 | 'edit.php?post_type=give_forms', |
267 | - esc_html__( 'Give Updates', 'give' ), |
|
266 | + esc_html__('Give Updates', 'give'), |
|
268 | 267 | sprintf( |
269 | 268 | '%1$s <span class="update-plugins"><span class="plugin-count give-update-progress-count">%2$s%3$s</span></span>', |
270 | - __( 'Updates', 'give' ), |
|
269 | + __('Updates', 'give'), |
|
271 | 270 | $this->is_doing_updates() ? |
272 | - $this->get_db_update_processing_percentage() : |
|
273 | - $this->get_total_update_count(), |
|
271 | + $this->get_db_update_processing_percentage() : $this->get_total_update_count(), |
|
274 | 272 | $this->is_doing_updates() ? '%' : '' |
275 | 273 | ), |
276 | 274 | 'manage_give_settings', |
277 | 275 | 'give-updates', |
278 | - array( $this, 'render_page' ) |
|
276 | + array($this, 'render_page') |
|
279 | 277 | ); |
280 | 278 | } |
281 | 279 | |
@@ -290,13 +288,13 @@ discard block |
||
290 | 288 | // Show db upgrade completed notice. |
291 | 289 | if ( |
292 | 290 | ! wp_doing_ajax() && |
293 | - current_user_can( 'manage_give_settings' ) && |
|
294 | - get_option( 'give_show_db_upgrade_complete_notice' ) && |
|
295 | - ! isset( $_GET['give-db-update-completed'] ) |
|
291 | + current_user_can('manage_give_settings') && |
|
292 | + get_option('give_show_db_upgrade_complete_notice') && |
|
293 | + ! isset($_GET['give-db-update-completed']) |
|
296 | 294 | ) { |
297 | - delete_option( 'give_show_db_upgrade_complete_notice' ); |
|
295 | + delete_option('give_show_db_upgrade_complete_notice'); |
|
298 | 296 | |
299 | - wp_redirect( add_query_arg( array( 'give-db-update-completed' => 'give_db_upgrade_completed' ) ) ); |
|
297 | + wp_redirect(add_query_arg(array('give-db-update-completed' => 'give_db_upgrade_completed'))); |
|
300 | 298 | exit(); |
301 | 299 | } |
302 | 300 | } |
@@ -310,28 +308,28 @@ discard block |
||
310 | 308 | */ |
311 | 309 | public function __show_notice() { |
312 | 310 | // Bailout. |
313 | - if ( ! current_user_can( 'manage_give_settings' ) || $this->is_doing_updates() ) { |
|
311 | + if ( ! current_user_can('manage_give_settings') || $this->is_doing_updates()) { |
|
314 | 312 | return; |
315 | 313 | } |
316 | 314 | |
317 | 315 | // Run DB updates. |
318 | - if ( ! empty( $_GET['give-run-db-update'] ) ) { |
|
316 | + if ( ! empty($_GET['give-run-db-update'])) { |
|
319 | 317 | $this->run_db_update(); |
320 | 318 | } |
321 | 319 | |
322 | 320 | |
323 | 321 | // Bailout. |
324 | - if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) { |
|
322 | + if (isset($_GET['page']) && 'give-updates' === $_GET['page']) { |
|
325 | 323 | return; |
326 | 324 | } |
327 | 325 | |
328 | 326 | // Show notice if ajax is not working. |
329 | - if ( ! give_test_ajax_works() ) { |
|
327 | + if ( ! give_test_ajax_works()) { |
|
330 | 328 | Give()->notices->register_notice( |
331 | 329 | array( |
332 | 330 | 'id' => 'give_db_upgrade_ajax_inaccessible', |
333 | 331 | 'type' => 'error', |
334 | - 'description' => __( 'Give needs to upgrade the database but cannot because AJAX is not functioning properly. Please contact your host and ask them to ensure admin-ajax.php is accessible.', 'give' ), |
|
332 | + 'description' => __('Give needs to upgrade the database but cannot because AJAX is not functioning properly. Please contact your host and ask them to ensure admin-ajax.php is accessible.', 'give'), |
|
335 | 333 | 'show' => true, |
336 | 334 | ) |
337 | 335 | ); |
@@ -340,46 +338,46 @@ discard block |
||
340 | 338 | } |
341 | 339 | |
342 | 340 | // Show db upgrade completed notice. |
343 | - if ( ! empty( $_GET['give-db-update-completed'] ) ) { |
|
344 | - Give()->notices->register_notice( array( |
|
341 | + if ( ! empty($_GET['give-db-update-completed'])) { |
|
342 | + Give()->notices->register_notice(array( |
|
345 | 343 | 'id' => 'give_db_upgrade_completed', |
346 | 344 | 'type' => 'updated', |
347 | - 'description' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), |
|
345 | + 'description' => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'), |
|
348 | 346 | 'show' => true, |
349 | - ) ); |
|
347 | + )); |
|
350 | 348 | |
351 | 349 | // Start update. |
352 | - } elseif ( ! empty( $_GET['give-run-db-update'] ) ) { |
|
350 | + } elseif ( ! empty($_GET['give-run-db-update'])) { |
|
353 | 351 | $this->run_db_update(); |
354 | 352 | |
355 | 353 | // Show run the update notice. |
356 | - } elseif ( $this->get_total_new_db_update_count() ) { |
|
354 | + } elseif ($this->get_total_new_db_update_count()) { |
|
357 | 355 | ob_start(); |
358 | 356 | ?> |
359 | 357 | <p> |
360 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
361 | - – <?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give' ); ?> |
|
358 | + <strong><?php _e('Database Update', 'give'); ?></strong> |
|
359 | + – <?php _e('GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give'); ?> |
|
362 | 360 | </p> |
363 | 361 | <p class="submit"> |
364 | - <a href="<?php echo esc_url( add_query_arg( array( 'give-run-db-update' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-run-update-now"> |
|
365 | - <?php _e( 'Run the updater', 'woocommerce' ); ?> |
|
362 | + <a href="<?php echo esc_url(add_query_arg(array('give-run-db-update' => 1), admin_url('edit.php?post_type=give_forms&page=give-updates'))); ?>" class="button button-primary give-run-update-now"> |
|
363 | + <?php _e('Run the updater', 'woocommerce'); ?> |
|
366 | 364 | </a> |
367 | 365 | </p> |
368 | 366 | <script type="text/javascript"> |
369 | 367 | jQuery('.give-run-update-now').click('click', function () { |
370 | - return window.confirm('<?php echo esc_js( __( 'It is strongly recommended that you backup your database before proceeding. Do you want to run the update now?', 'give' ) ); ?>'); // jshint ignore:line |
|
368 | + return window.confirm('<?php echo esc_js(__('It is strongly recommended that you backup your database before proceeding. Do you want to run the update now?', 'give')); ?>'); // jshint ignore:line |
|
371 | 369 | }); |
372 | 370 | </script> |
373 | 371 | <?php |
374 | 372 | $desc_html = ob_get_clean(); |
375 | 373 | |
376 | 374 | |
377 | - Give()->notices->register_notice( array( |
|
375 | + Give()->notices->register_notice(array( |
|
378 | 376 | 'id' => 'give_upgrade_db', |
379 | 377 | 'type' => 'updated', |
380 | 378 | 'dismissible' => false, |
381 | 379 | 'description' => $desc_html, |
382 | - ) ); |
|
380 | + )); |
|
383 | 381 | } |
384 | 382 | } |
385 | 383 | |
@@ -390,7 +388,7 @@ discard block |
||
390 | 388 | * @access public |
391 | 389 | */ |
392 | 390 | public function render_complete_page() { |
393 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades-complete.php'; |
|
391 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades-complete.php'; |
|
394 | 392 | } |
395 | 393 | |
396 | 394 | /** |
@@ -400,7 +398,7 @@ discard block |
||
400 | 398 | * @access public |
401 | 399 | */ |
402 | 400 | public function render_page() { |
403 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades.php'; |
|
401 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades.php'; |
|
404 | 402 | } |
405 | 403 | |
406 | 404 | /** |
@@ -411,26 +409,26 @@ discard block |
||
411 | 409 | */ |
412 | 410 | private function run_db_update() { |
413 | 411 | // Bailout. |
414 | - if ( $this->is_doing_updates() || ! $this->get_total_new_db_update_count() ) { |
|
412 | + if ($this->is_doing_updates() || ! $this->get_total_new_db_update_count()) { |
|
415 | 413 | return; |
416 | 414 | } |
417 | 415 | |
418 | - $updates = $this->get_updates( 'database', 'new' ); |
|
416 | + $updates = $this->get_updates('database', 'new'); |
|
419 | 417 | |
420 | - foreach ( $updates as $update ) { |
|
421 | - self::$background_updater->push_to_queue( $update ); |
|
418 | + foreach ($updates as $update) { |
|
419 | + self::$background_updater->push_to_queue($update); |
|
422 | 420 | } |
423 | 421 | |
424 | - add_option( 'give_db_update_count', count( $updates ), '', 'no' ); |
|
422 | + add_option('give_db_update_count', count($updates), '', 'no'); |
|
425 | 423 | |
426 | - add_option( 'give_doing_upgrade', array( |
|
424 | + add_option('give_doing_upgrade', array( |
|
427 | 425 | 'update_info' => $updates[0], |
428 | 426 | 'step' => 1, |
429 | 427 | 'update' => 1, |
430 | - 'heading' => sprintf( 'Update %s of %s', 1, count( $updates ) ), |
|
428 | + 'heading' => sprintf('Update %s of %s', 1, count($updates)), |
|
431 | 429 | 'percentage' => 0, |
432 | 430 | 'total_percentage' => 0, |
433 | - ), '', 'no' ); |
|
431 | + ), '', 'no'); |
|
434 | 432 | |
435 | 433 | self::$background_updater->save()->dispatch(); |
436 | 434 | } |
@@ -444,11 +442,11 @@ discard block |
||
444 | 442 | */ |
445 | 443 | public function __flush_resume_updates() { |
446 | 444 | //delete_option( 'give_doing_upgrade' ); |
447 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
445 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
448 | 446 | |
449 | 447 | // Reset counter. |
450 | 448 | $this->step = $this->percentage = 0; |
451 | - ++ $this->update; |
|
449 | + ++$this->update; |
|
452 | 450 | } |
453 | 451 | |
454 | 452 | |
@@ -463,7 +461,7 @@ discard block |
||
463 | 461 | public function __give_start_updating() { |
464 | 462 | // Check permission. |
465 | 463 | if ( |
466 | - ! current_user_can( 'manage_give_settings' ) || |
|
464 | + ! current_user_can('manage_give_settings') || |
|
467 | 465 | $this->is_doing_updates() |
468 | 466 | ) { |
469 | 467 | wp_send_json_error(); |
@@ -471,7 +469,7 @@ discard block |
||
471 | 469 | |
472 | 470 | // @todo: validate nonce |
473 | 471 | // @todo: set http method to post |
474 | - if ( empty( $_POST['run_db_update'] ) ) { |
|
472 | + if (empty($_POST['run_db_update'])) { |
|
475 | 473 | wp_send_json_error(); |
476 | 474 | } |
477 | 475 | |
@@ -490,21 +488,21 @@ discard block |
||
490 | 488 | * @return string |
491 | 489 | */ |
492 | 490 | public function __give_db_updates_info() { |
493 | - $update_info = get_option( 'give_doing_upgrade' ); |
|
491 | + $update_info = get_option('give_doing_upgrade'); |
|
494 | 492 | $response_type = ''; |
495 | 493 | |
496 | - if ( empty( $update_info ) && ! $this->get_pending_db_update_count() ) { |
|
497 | - $update_info = array( |
|
498 | - 'message' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), |
|
499 | - 'heading' => __( 'Updates Completed.', 'give' ), |
|
494 | + if (empty($update_info) && ! $this->get_pending_db_update_count()) { |
|
495 | + $update_info = array( |
|
496 | + 'message' => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'), |
|
497 | + 'heading' => __('Updates Completed.', 'give'), |
|
500 | 498 | 'percentage' => 0, |
501 | 499 | ); |
502 | 500 | $response_type = 'success'; |
503 | 501 | |
504 | - delete_option( 'give_show_db_upgrade_complete_notice' ); |
|
502 | + delete_option('give_show_db_upgrade_complete_notice'); |
|
505 | 503 | } |
506 | 504 | |
507 | - $this->send_ajax_response( $update_info, $response_type ); |
|
505 | + $this->send_ajax_response($update_info, $response_type); |
|
508 | 506 | } |
509 | 507 | |
510 | 508 | /** |
@@ -516,7 +514,7 @@ discard block |
||
516 | 514 | * @param $data |
517 | 515 | * @param string $type |
518 | 516 | */ |
519 | - public function send_ajax_response( $data, $type = '' ) { |
|
517 | + public function send_ajax_response($data, $type = '') { |
|
520 | 518 | $default = array( |
521 | 519 | 'message' => '', |
522 | 520 | 'heading' => '', |
@@ -526,24 +524,24 @@ discard block |
||
526 | 524 | ); |
527 | 525 | |
528 | 526 | // Set data. |
529 | - $data = wp_parse_args( $data, $default ); |
|
527 | + $data = wp_parse_args($data, $default); |
|
530 | 528 | |
531 | 529 | // Enable cache. |
532 | 530 | Give_Cache::enable(); |
533 | 531 | |
534 | - switch ( $type ) { |
|
532 | + switch ($type) { |
|
535 | 533 | case 'success': |
536 | - wp_send_json_success( $data ); |
|
534 | + wp_send_json_success($data); |
|
537 | 535 | break; |
538 | 536 | |
539 | 537 | case 'error': |
540 | - wp_send_json_error( $data ); |
|
538 | + wp_send_json_error($data); |
|
541 | 539 | break; |
542 | 540 | |
543 | 541 | default: |
544 | - wp_send_json( array( |
|
542 | + wp_send_json(array( |
|
545 | 543 | 'data' => $data, |
546 | - ) ); |
|
544 | + )); |
|
547 | 545 | break; |
548 | 546 | } |
549 | 547 | } |
@@ -557,12 +555,12 @@ discard block |
||
557 | 555 | * @param $total |
558 | 556 | * @param $current_total |
559 | 557 | */ |
560 | - public function set_percentage( $total, $current_total ) { |
|
558 | + public function set_percentage($total, $current_total) { |
|
561 | 559 | // Set percentage. |
562 | - $this->percentage = $total ? ( ( $current_total ) / $total ) * 100 : 0; |
|
560 | + $this->percentage = $total ? (($current_total) / $total) * 100 : 0; |
|
563 | 561 | |
564 | 562 | // Verify percentage. |
565 | - $this->percentage = ( 100 < $this->percentage ) ? 100 : $this->percentage; |
|
563 | + $this->percentage = (100 < $this->percentage) ? 100 : $this->percentage; |
|
566 | 564 | } |
567 | 565 | |
568 | 566 | /** |
@@ -575,23 +573,23 @@ discard block |
||
575 | 573 | * |
576 | 574 | * @return bool|null |
577 | 575 | */ |
578 | - public function is_parent_updates_completed( $update ) { |
|
576 | + public function is_parent_updates_completed($update) { |
|
579 | 577 | // Bailout. |
580 | - if ( empty( $update['depend'] ) ) { |
|
578 | + if (empty($update['depend'])) { |
|
581 | 579 | return true; |
582 | 580 | } |
583 | 581 | |
584 | 582 | // Check if dependency is valid or not. |
585 | - if ( ! $this->has_valid_dependency( $update ) ) { |
|
586 | - error_log( print_r( 'exit 2', true ) . "\n", 3, WP_CONTENT_DIR . '/debug_new.log' ); |
|
583 | + if ( ! $this->has_valid_dependency($update)) { |
|
584 | + error_log(print_r('exit 2', true)."\n", 3, WP_CONTENT_DIR.'/debug_new.log'); |
|
587 | 585 | return null; |
588 | 586 | } |
589 | 587 | |
590 | 588 | $is_dependency_completed = true; |
591 | 589 | |
592 | - foreach ( $update['depend'] as $depend ) { |
|
590 | + foreach ($update['depend'] as $depend) { |
|
593 | 591 | |
594 | - if ( ! give_has_upgrade_completed( $depend ) ) { |
|
592 | + if ( ! give_has_upgrade_completed($depend)) { |
|
595 | 593 | $is_dependency_completed = false; |
596 | 594 | break; |
597 | 595 | } |
@@ -608,7 +606,7 @@ discard block |
||
608 | 606 | * @return bool |
609 | 607 | */ |
610 | 608 | public function is_doing_updates() { |
611 | - return (bool) get_option( 'give_doing_upgrade' ); |
|
609 | + return (bool) get_option('give_doing_upgrade'); |
|
612 | 610 | } |
613 | 611 | |
614 | 612 | |
@@ -622,7 +620,7 @@ discard block |
||
622 | 620 | * |
623 | 621 | * @return bool |
624 | 622 | */ |
625 | - public function has_valid_dependency( $update ) { |
|
623 | + public function has_valid_dependency($update) { |
|
626 | 624 | $is_valid_dependency = true; |
627 | 625 | // $update_ids = wp_list_pluck( $this->get_updates( 'database', 'all' ), 'id' ); |
628 | 626 | // |
@@ -648,32 +646,32 @@ discard block |
||
648 | 646 | * |
649 | 647 | * @return array |
650 | 648 | */ |
651 | - public function get_updates( $update_type = '', $status = 'all' ) { |
|
649 | + public function get_updates($update_type = '', $status = 'all') { |
|
652 | 650 | // return all updates. |
653 | - if ( empty( $update_type ) ) { |
|
651 | + if (empty($update_type)) { |
|
654 | 652 | return $this->updates; |
655 | 653 | } |
656 | 654 | |
657 | 655 | // Get specific update. |
658 | - $updates = ! empty( $this->updates[ $update_type ] ) ? $this->updates[ $update_type ] : array(); |
|
656 | + $updates = ! empty($this->updates[$update_type]) ? $this->updates[$update_type] : array(); |
|
659 | 657 | |
660 | 658 | // Bailout. |
661 | - if ( empty( $updates ) ) { |
|
659 | + if (empty($updates)) { |
|
662 | 660 | return $updates; |
663 | 661 | } |
664 | 662 | |
665 | - switch ( $status ) { |
|
663 | + switch ($status) { |
|
666 | 664 | case 'new': |
667 | 665 | // Remove already completed updates. |
668 | 666 | $completed_updates = give_get_completed_upgrades(); |
669 | 667 | |
670 | - if ( ! empty( $completed_updates ) ) { |
|
671 | - foreach ( $updates as $index => $update ) { |
|
672 | - if ( in_array( $update['id'], $completed_updates ) ) { |
|
673 | - unset( $updates[ $index ] ); |
|
668 | + if ( ! empty($completed_updates)) { |
|
669 | + foreach ($updates as $index => $update) { |
|
670 | + if (in_array($update['id'], $completed_updates)) { |
|
671 | + unset($updates[$index]); |
|
674 | 672 | } |
675 | 673 | } |
676 | - $updates = array_values( $updates ); |
|
674 | + $updates = array_values($updates); |
|
677 | 675 | } |
678 | 676 | |
679 | 677 | break; |
@@ -690,7 +688,7 @@ discard block |
||
690 | 688 | * @return int |
691 | 689 | */ |
692 | 690 | public function get_total_plugin_update_count() { |
693 | - return count( $this->get_updates( 'plugin' ) ); |
|
691 | + return count($this->get_updates('plugin')); |
|
694 | 692 | } |
695 | 693 | |
696 | 694 | /** |
@@ -705,7 +703,7 @@ discard block |
||
705 | 703 | $db_update_count = $this->get_pending_db_update_count(); |
706 | 704 | $plugin_update_count = $this->get_total_plugin_update_count(); |
707 | 705 | |
708 | - return ( $db_update_count + $plugin_update_count ); |
|
706 | + return ($db_update_count + $plugin_update_count); |
|
709 | 707 | } |
710 | 708 | |
711 | 709 | /** |
@@ -717,7 +715,7 @@ discard block |
||
717 | 715 | * @return int |
718 | 716 | */ |
719 | 717 | public function get_pending_db_update_count() { |
720 | - return count( $this->get_updates( 'database', 'new' ) ); |
|
718 | + return count($this->get_updates('database', 'new')); |
|
721 | 719 | } |
722 | 720 | |
723 | 721 | /** |
@@ -729,7 +727,7 @@ discard block |
||
729 | 727 | * @return int |
730 | 728 | */ |
731 | 729 | public function get_total_db_update_count() { |
732 | - return count( $this->get_updates( 'database', 'all' ) ); |
|
730 | + return count($this->get_updates('database', 'all')); |
|
733 | 731 | } |
734 | 732 | |
735 | 733 | /** |
@@ -742,8 +740,7 @@ discard block |
||
742 | 740 | */ |
743 | 741 | public function get_total_new_db_update_count() { |
744 | 742 | return $this->is_doing_updates() ? |
745 | - get_option( 'give_db_update_count' ) : |
|
746 | - $this->get_pending_db_update_count(); |
|
743 | + get_option('give_db_update_count') : $this->get_pending_db_update_count(); |
|
747 | 744 | } |
748 | 745 | |
749 | 746 | /** |
@@ -755,11 +752,10 @@ discard block |
||
755 | 752 | * @return int |
756 | 753 | */ |
757 | 754 | public function get_running_db_update() { |
758 | - $current_update = get_option( 'give_doing_upgrade' ); |
|
755 | + $current_update = get_option('give_doing_upgrade'); |
|
759 | 756 | |
760 | 757 | return $this->is_doing_updates() ? |
761 | - $current_update['update'] : |
|
762 | - 1; |
|
758 | + $current_update['update'] : 1; |
|
763 | 759 | } |
764 | 760 | |
765 | 761 | /** |
@@ -771,23 +767,21 @@ discard block |
||
771 | 767 | */ |
772 | 768 | public function get_db_update_processing_percentage() { |
773 | 769 | // Bailout. |
774 | - if ( ! $this->get_total_new_db_update_count() ) { |
|
770 | + if ( ! $this->get_total_new_db_update_count()) { |
|
775 | 771 | return 0; |
776 | 772 | } |
777 | 773 | |
778 | - $resume_update = get_option( 'give_doing_upgrade' ); |
|
779 | - $update_count_percentages = ( ( $this->get_running_db_update() - 1 ) / $this->get_total_new_db_update_count() ) * 100; |
|
780 | - $update_percentage_share = ( 1 / $this->get_total_new_db_update_count() ) * 100; |
|
781 | - $upgrade_percentage = ( ( $resume_update['percentage'] * $update_percentage_share ) / 100 ); |
|
774 | + $resume_update = get_option('give_doing_upgrade'); |
|
775 | + $update_count_percentages = (($this->get_running_db_update() - 1) / $this->get_total_new_db_update_count()) * 100; |
|
776 | + $update_percentage_share = (1 / $this->get_total_new_db_update_count()) * 100; |
|
777 | + $upgrade_percentage = (($resume_update['percentage'] * $update_percentage_share) / 100); |
|
782 | 778 | |
783 | 779 | $final_percentage = $update_count_percentages + $upgrade_percentage; |
784 | 780 | |
785 | 781 | return $this->is_doing_updates() ? |
786 | - ( absint( $final_percentage ) ? |
|
787 | - absint( $final_percentage ) : |
|
788 | - round( $final_percentage, 2 ) |
|
789 | - ) : |
|
790 | - 0; |
|
782 | + (absint($final_percentage) ? |
|
783 | + absint($final_percentage) : round($final_percentage, 2) |
|
784 | + ) : 0; |
|
791 | 785 | } |
792 | 786 | } |
793 | 787 |
@@ -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 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /* @var WPDB $wpdb */ |
36 | 36 | global $wpdb; |
37 | 37 | |
38 | - $this->table_name = $wpdb->prefix . 'give_logs'; |
|
38 | + $this->table_name = $wpdb->prefix.'give_logs'; |
|
39 | 39 | $this->primary_key = 'ID'; |
40 | 40 | $this->version = '1.0'; |
41 | 41 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @return array Default column values. |
74 | 74 | */ |
75 | 75 | public function get_column_defaults() { |
76 | - $log_create_date = current_time( 'mysql', 0 ); |
|
77 | - $log_create_date_gmt = get_gmt_from_date( $log_create_date ); |
|
76 | + $log_create_date = current_time('mysql', 0); |
|
77 | + $log_create_date_gmt = get_gmt_from_date($log_create_date); |
|
78 | 78 | |
79 | 79 | return array( |
80 | 80 | 'ID' => 0, |
@@ -97,39 +97,39 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return bool|int |
99 | 99 | */ |
100 | - public function add( $data = array() ) { |
|
100 | + public function add($data = array()) { |
|
101 | 101 | // Valid table columns. |
102 | - $table_columns = array_keys( $this->get_columns() ); |
|
102 | + $table_columns = array_keys($this->get_columns()); |
|
103 | 103 | |
104 | 104 | // Filter data. |
105 | - foreach ( $data as $table_column => $column_data ) { |
|
106 | - if ( ! in_array( $table_column, $table_columns ) ) { |
|
107 | - unset( $data[ $table_column ] ); |
|
105 | + foreach ($data as $table_column => $column_data) { |
|
106 | + if ( ! in_array($table_column, $table_columns)) { |
|
107 | + unset($data[$table_column]); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | 111 | // Set default values. |
112 | - $current_log_data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
112 | + $current_log_data = wp_parse_args($data, $this->get_column_defaults()); |
|
113 | 113 | |
114 | 114 | // Log parent should be an int. |
115 | - $current_log_data['log_parent'] = absint( $current_log_data['log_parent'] ); |
|
115 | + $current_log_data['log_parent'] = absint($current_log_data['log_parent']); |
|
116 | 116 | |
117 | 117 | // Get log. |
118 | - $existing_log = $this->get_log_by( $current_log_data['ID'] ); |
|
118 | + $existing_log = $this->get_log_by($current_log_data['ID']); |
|
119 | 119 | |
120 | 120 | // Update an existing log. |
121 | - if ( $existing_log ) { |
|
121 | + if ($existing_log) { |
|
122 | 122 | |
123 | 123 | // Create new log data from existing and new log data. |
124 | - $current_log_data = array_merge( $current_log_data, $existing_log ); |
|
124 | + $current_log_data = array_merge($current_log_data, $existing_log); |
|
125 | 125 | |
126 | 126 | // Update log data. |
127 | - $this->update( $current_log_data['ID'], $current_log_data ); |
|
127 | + $this->update($current_log_data['ID'], $current_log_data); |
|
128 | 128 | |
129 | 129 | $log_id = $current_log_data['ID']; |
130 | 130 | |
131 | 131 | } else { |
132 | - $log_id = $this->insert( $current_log_data, 'log' ); |
|
132 | + $log_id = $this->insert($current_log_data, 'log'); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | return $log_id; |
@@ -147,20 +147,20 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return bool|null|array |
149 | 149 | */ |
150 | - public function get_log_by( $log_id = 0, $by = 'id' ) { |
|
150 | + public function get_log_by($log_id = 0, $by = 'id') { |
|
151 | 151 | /* @var WPDB $wpdb */ |
152 | 152 | global $wpdb; |
153 | 153 | $log = null; |
154 | 154 | |
155 | 155 | // Make sure $log_id is int. |
156 | - $log_id = absint( $log_id ); |
|
156 | + $log_id = absint($log_id); |
|
157 | 157 | |
158 | 158 | // Bailout. |
159 | - if ( empty( $log_id ) ) { |
|
159 | + if (empty($log_id)) { |
|
160 | 160 | return null; |
161 | 161 | } |
162 | 162 | |
163 | - switch ( $by ) { |
|
163 | + switch ($by) { |
|
164 | 164 | case 'id': |
165 | 165 | $log = $wpdb->get_row( |
166 | 166 | $wpdb->prepare( |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | break; |
173 | 173 | |
174 | 174 | default: |
175 | - $log = apply_filters( "give_get_log_by_{$by}", $log, $log_id ); |
|
175 | + $log = apply_filters("give_get_log_by_{$by}", $log, $log_id); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | return $log; |
@@ -188,14 +188,14 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return mixed |
190 | 190 | */ |
191 | - public function get_logs( $args = array() ) { |
|
191 | + public function get_logs($args = array()) { |
|
192 | 192 | global $wpdb; |
193 | - $sql_query = $this->get_sql( $args ); |
|
193 | + $sql_query = $this->get_sql($args); |
|
194 | 194 | |
195 | 195 | // Get log. |
196 | - if ( ! ( $logs = Give_Cache::get( 'give_logs', true, $sql_query ) ) ) { |
|
197 | - $logs = $wpdb->get_results( $sql_query ); |
|
198 | - Give_Cache::set( 'give_logs', $logs, 3600, true, $sql_query ); |
|
196 | + if ( ! ($logs = Give_Cache::get('give_logs', true, $sql_query))) { |
|
197 | + $logs = $wpdb->get_results($sql_query); |
|
198 | + Give_Cache::set('give_logs', $logs, 3600, true, $sql_query); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | return $logs; |
@@ -212,21 +212,21 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @return int |
214 | 214 | */ |
215 | - public function count( $args = array() ) { |
|
215 | + public function count($args = array()) { |
|
216 | 216 | /* @var WPDB $wpdb */ |
217 | 217 | global $wpdb; |
218 | 218 | $args['number'] = - 1; |
219 | 219 | $args['fields'] = 'ID'; |
220 | 220 | $args['count'] = true; |
221 | 221 | |
222 | - $sql_query = $this->get_sql( $args ); |
|
222 | + $sql_query = $this->get_sql($args); |
|
223 | 223 | |
224 | - if ( ! ( $count = Give_Cache::get( 'give_logs_count', true, $sql_query ) ) ) { |
|
225 | - $count = $wpdb->get_var( $sql_query ); |
|
226 | - Give_Cache::set( 'give_logs_count', $count, 3600, true, $args ); |
|
224 | + if ( ! ($count = Give_Cache::get('give_logs_count', true, $sql_query))) { |
|
225 | + $count = $wpdb->get_var($sql_query); |
|
226 | + Give_Cache::set('give_logs_count', $count, 3600, true, $args); |
|
227 | 227 | } |
228 | 228 | |
229 | - return absint( $count ); |
|
229 | + return absint($count); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | PRIMARY KEY (ID) |
253 | 253 | ) {$charset_collate};"; |
254 | 254 | |
255 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
256 | - dbDelta( $sql ); |
|
255 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
256 | + dbDelta($sql); |
|
257 | 257 | |
258 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
258 | + update_option($this->table_name.'_db_version', $this->version); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return string |
271 | 271 | */ |
272 | - public function get_sql( $args = array() ) { |
|
272 | + public function get_sql($args = array()) { |
|
273 | 273 | /* @var WPDB $wpdb */ |
274 | 274 | global $wpdb; |
275 | 275 | |
@@ -283,12 +283,12 @@ discard block |
||
283 | 283 | 'count' => false, |
284 | 284 | ); |
285 | 285 | |
286 | - $args = wp_parse_args( $args, $defaults ); |
|
286 | + $args = wp_parse_args($args, $defaults); |
|
287 | 287 | |
288 | 288 | // validate params. |
289 | - $this->validate_params( $args ); |
|
289 | + $this->validate_params($args); |
|
290 | 290 | |
291 | - if ( $args['number'] < 1 ) { |
|
291 | + if ($args['number'] < 1) { |
|
292 | 292 | $args['number'] = 99999999999; |
293 | 293 | } |
294 | 294 | |
@@ -296,78 +296,78 @@ discard block |
||
296 | 296 | $where = ''; |
297 | 297 | |
298 | 298 | // Get sql query for meta. |
299 | - if ( ! empty( $args['meta_query'] ) ) { |
|
300 | - $meta_query_object = new WP_Meta_Query( $args['meta_query'] ); |
|
301 | - $meta_query = $meta_query_object->get_sql( 'log', $this->table_name, 'id' ); |
|
302 | - $where = implode( '', $meta_query ); |
|
299 | + if ( ! empty($args['meta_query'])) { |
|
300 | + $meta_query_object = new WP_Meta_Query($args['meta_query']); |
|
301 | + $meta_query = $meta_query_object->get_sql('log', $this->table_name, 'id'); |
|
302 | + $where = implode('', $meta_query); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $where .= ' WHERE 1=1 '; |
306 | 306 | |
307 | 307 | // Set offset. |
308 | - if ( empty( $args['offset'] ) && ( 0 < $args['paged'] ) ) { |
|
309 | - $args['offset'] = $args['number'] * ( $args['paged'] - 1 ); |
|
308 | + if (empty($args['offset']) && (0 < $args['paged'])) { |
|
309 | + $args['offset'] = $args['number'] * ($args['paged'] - 1); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | // Set fields. |
313 | 313 | $fields = "{$this->table_name}.*"; |
314 | - if ( is_string( $args['fields'] ) && ( 'all' !== $args['fields'] ) ) { |
|
314 | + if (is_string($args['fields']) && ('all' !== $args['fields'])) { |
|
315 | 315 | $fields = "{$this->table_name}.{$args['fields']}"; |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Set count. |
319 | - if ( $args['count'] ) { |
|
319 | + if ($args['count']) { |
|
320 | 320 | $fields = "COUNT({$fields})"; |
321 | 321 | } |
322 | 322 | |
323 | 323 | // Specific logs. |
324 | - if ( ! empty( $args['ID'] ) ) { |
|
324 | + if ( ! empty($args['ID'])) { |
|
325 | 325 | |
326 | - if ( ! is_array( $args['ID'] ) ) { |
|
327 | - $args['ID'] = explode( ',', $args['ID'] ); |
|
326 | + if ( ! is_array($args['ID'])) { |
|
327 | + $args['ID'] = explode(',', $args['ID']); |
|
328 | 328 | } |
329 | - $log_ids = implode( ',', array_map( 'intval', $args['ID'] ) ); |
|
329 | + $log_ids = implode(',', array_map('intval', $args['ID'])); |
|
330 | 330 | |
331 | 331 | $where .= " AND {$this->table_name}.ID IN( {$log_ids} ) "; |
332 | 332 | } |
333 | 333 | |
334 | 334 | // Logs created for a specific date or in a date range |
335 | - if ( ! empty( $args['date_query'] ) ) { |
|
336 | - $date_query_object = new WP_Date_Query( $args['date_query'], "{$this->table_name}.log_date" ); |
|
337 | - $where .= $date_query_object->get_sql(); |
|
335 | + if ( ! empty($args['date_query'])) { |
|
336 | + $date_query_object = new WP_Date_Query($args['date_query'], "{$this->table_name}.log_date"); |
|
337 | + $where .= $date_query_object->get_sql(); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // Logs create for specific parent. |
341 | - if ( ! empty( $args['log_parent'] ) ) { |
|
342 | - if ( ! is_array( $args['log_parent'] ) ) { |
|
343 | - $args['log_parent'] = explode( ',', $args['log_parent'] ); |
|
341 | + if ( ! empty($args['log_parent'])) { |
|
342 | + if ( ! is_array($args['log_parent'])) { |
|
343 | + $args['log_parent'] = explode(',', $args['log_parent']); |
|
344 | 344 | } |
345 | - $parent_ids = implode( ',', array_map( 'intval', $args['log_parent'] ) ); |
|
345 | + $parent_ids = implode(',', array_map('intval', $args['log_parent'])); |
|
346 | 346 | |
347 | 347 | $where .= " AND {$this->table_name}.log_parent IN( {$parent_ids} ) "; |
348 | 348 | } |
349 | 349 | |
350 | 350 | // Logs create for specific type. |
351 | 351 | // is_array check is for backward compatibility. |
352 | - if ( ! empty( $args['log_type'] ) && ! is_array( $args['log_type'] ) ) { |
|
353 | - if ( ! is_array( $args['log_type'] ) ) { |
|
354 | - $args['log_type'] = explode( ',', $args['log_type'] ); |
|
352 | + if ( ! empty($args['log_type']) && ! is_array($args['log_type'])) { |
|
353 | + if ( ! is_array($args['log_type'])) { |
|
354 | + $args['log_type'] = explode(',', $args['log_type']); |
|
355 | 355 | } |
356 | 356 | |
357 | - $log_types = implode( '\',\'', array_map( 'trim', $args['log_type'] ) ); |
|
357 | + $log_types = implode('\',\'', array_map('trim', $args['log_type'])); |
|
358 | 358 | |
359 | 359 | $where .= " AND {$this->table_name}.log_type IN( '{$log_types}' ) "; |
360 | 360 | } |
361 | 361 | |
362 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'log_date' : $args['orderby']; |
|
362 | + $args['orderby'] = ! array_key_exists($args['orderby'], $this->get_columns()) ? 'log_date' : $args['orderby']; |
|
363 | 363 | |
364 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
365 | - $args['order'] = esc_sql( $args['order'] ); |
|
364 | + $args['orderby'] = esc_sql($args['orderby']); |
|
365 | + $args['order'] = esc_sql($args['order']); |
|
366 | 366 | |
367 | 367 | return $wpdb->prepare( |
368 | 368 | "SELECT {$fields} FROM {$this->table_name} {$where} ORDER BY {$this->table_name}.{$args['orderby']} {$args['order']} LIMIT %d,%d;", |
369 | - absint( $args['offset'] ), |
|
370 | - absint( $args['number'] ) |
|
369 | + absint($args['offset']), |
|
370 | + absint($args['number']) |
|
371 | 371 | ); |
372 | 372 | } |
373 | 373 | |
@@ -382,13 +382,11 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @return mixed |
384 | 384 | */ |
385 | - private function validate_params( &$args ) { |
|
385 | + private function validate_params(&$args) { |
|
386 | 386 | // fields params |
387 | 387 | $args['fields'] = 'ids' === $args['fields'] ? |
388 | - 'ID' : |
|
389 | - $args['fields']; |
|
390 | - $args['fields'] = array_key_exists( $args['fields'], $this->get_columns() ) ? |
|
391 | - $args['fields'] : |
|
392 | - 'all'; |
|
388 | + 'ID' : $args['fields']; |
|
389 | + $args['fields'] = array_key_exists($args['fields'], $this->get_columns()) ? |
|
390 | + $args['fields'] : 'all'; |
|
393 | 391 | } |
394 | 392 | } |
@@ -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 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param $args array The array of arguments that can be passed in and used for setting up this payment query. |
88 | 88 | */ |
89 | - public function __construct( $args = array() ) { |
|
89 | + public function __construct($args = array()) { |
|
90 | 90 | $defaults = array( |
91 | 91 | 'number' => 20, |
92 | 92 | 'offset' => 0, |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | // 'form' => array(), |
105 | 105 | ); |
106 | 106 | |
107 | - $this->args = wp_parse_args( $args, $defaults ); |
|
107 | + $this->args = wp_parse_args($args, $defaults); |
|
108 | 108 | $this->table_name = Give()->donors->table_name; |
109 | 109 | $this->meta_table_name = Give()->donor_meta->table_name; |
110 | 110 | $this->meta_type = Give()->donor_meta->meta_type; |
@@ -146,21 +146,21 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @param Give_Donors_Query $this Donors query object. |
148 | 148 | */ |
149 | - do_action( 'give_pre_get_donors', $this ); |
|
149 | + do_action('give_pre_get_donors', $this); |
|
150 | 150 | |
151 | - $cache_key = Give_Cache::get_key( 'give_donor', $this->get_sql(), false ); |
|
151 | + $cache_key = Give_Cache::get_key('give_donor', $this->get_sql(), false); |
|
152 | 152 | |
153 | 153 | // Get donors from cache. |
154 | - $this->donors = Give_Cache::get_db_query( $cache_key ); |
|
154 | + $this->donors = Give_Cache::get_db_query($cache_key); |
|
155 | 155 | |
156 | - if ( is_null( $this->donors ) ) { |
|
157 | - if ( empty( $this->args['count'] ) ) { |
|
158 | - $this->donors = $wpdb->get_results( $this->get_sql() ); |
|
156 | + if (is_null($this->donors)) { |
|
157 | + if (empty($this->args['count'])) { |
|
158 | + $this->donors = $wpdb->get_results($this->get_sql()); |
|
159 | 159 | } else { |
160 | - $this->donors = $wpdb->get_var( $this->get_sql() ); |
|
160 | + $this->donors = $wpdb->get_var($this->get_sql()); |
|
161 | 161 | } |
162 | 162 | |
163 | - Give_Cache::set_db_query( $cache_key, $this->donors ); |
|
163 | + Give_Cache::set_db_query($cache_key, $this->donors); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @param Give_Donors_Query $this Donors query object. |
173 | 173 | */ |
174 | - do_action( 'give_post_get_donors', $this ); |
|
174 | + do_action('give_post_get_donors', $this); |
|
175 | 175 | |
176 | 176 | return $this->donors; |
177 | 177 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | public function get_sql() { |
189 | 189 | global $wpdb; |
190 | 190 | |
191 | - if ( $this->args['number'] < 1 ) { |
|
191 | + if ($this->args['number'] < 1) { |
|
192 | 192 | $this->args['number'] = 99999999999; |
193 | 193 | } |
194 | 194 | |
@@ -196,22 +196,22 @@ discard block |
||
196 | 196 | |
197 | 197 | |
198 | 198 | // Set offset. |
199 | - if ( empty( $this->args['offset'] ) && ( 0 < $this->args['paged'] ) ) { |
|
200 | - $this->args['offset'] = $this->args['number'] * ( $this->args['paged'] - 1 ); |
|
199 | + if (empty($this->args['offset']) && (0 < $this->args['paged'])) { |
|
200 | + $this->args['offset'] = $this->args['number'] * ($this->args['paged'] - 1); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | // Set fields. |
204 | 204 | $fields = "{$this->table_name}.*"; |
205 | - if ( ! empty( $this->args['fields'] ) && 'all' !== $this->args['fields'] ) { |
|
206 | - if ( is_string( $this->args['fields'] ) ) { |
|
205 | + if ( ! empty($this->args['fields']) && 'all' !== $this->args['fields']) { |
|
206 | + if (is_string($this->args['fields'])) { |
|
207 | 207 | $fields = "{$this->table_name}.{$this->args['fields']}"; |
208 | - } elseif ( is_array( $this->args['fields'] ) ) { |
|
209 | - $fields = "{$this->table_name}." . implode( " , {$this->table_name}.", $this->args['fields'] ); |
|
208 | + } elseif (is_array($this->args['fields'])) { |
|
209 | + $fields = "{$this->table_name}.".implode(" , {$this->table_name}.", $this->args['fields']); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | 213 | // Set count. |
214 | - if ( ! empty( $this->args['count'] ) ) { |
|
214 | + if ( ! empty($this->args['count'])) { |
|
215 | 215 | $fields = "COUNT({$this->table_name}.id)"; |
216 | 216 | } |
217 | 217 | |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | |
220 | 220 | $sql = $wpdb->prepare( |
221 | 221 | "SELECT {$fields} FROM {$this->table_name} LIMIT %d,%d;", |
222 | - absint( $this->args['offset'] ), |
|
223 | - absint( $this->args['number'] ) |
|
222 | + absint($this->args['offset']), |
|
223 | + absint($this->args['number']) |
|
224 | 224 | ); |
225 | 225 | |
226 | 226 | // $where, $orderby and order already prepared query they can generate notice if you re prepare them in above. |
227 | 227 | // WordPress consider LIKE condition as placeholder if start with s,f, or d. |
228 | - $sql = str_replace( 'LIMIT', "{$where} {$orderby} {$this->args['order']} LIMIT", $sql ); |
|
228 | + $sql = str_replace('LIMIT', "{$where} {$orderby} {$this->args['order']} LIMIT", $sql); |
|
229 | 229 | |
230 | 230 | return $sql; |
231 | 231 | } |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | $where = ''; |
244 | 244 | |
245 | 245 | // Get sql query for meta. |
246 | - if ( ! empty( $this->args['meta_query'] ) ) { |
|
247 | - $meta_query_object = new WP_Meta_Query( $this->args['meta_query'] ); |
|
246 | + if ( ! empty($this->args['meta_query'])) { |
|
247 | + $meta_query_object = new WP_Meta_Query($this->args['meta_query']); |
|
248 | 248 | $meta_query = $meta_query_object->get_sql( |
249 | 249 | $this->meta_type, |
250 | 250 | $this->table_name, |
251 | 251 | 'id' |
252 | 252 | ); |
253 | 253 | |
254 | - $where = implode( '', $meta_query ); |
|
254 | + $where = implode('', $meta_query); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | $where .= 'WHERE 1=1 '; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | $where .= $this->get_where_user(); |
262 | 262 | $where .= $this->get_where_date(); |
263 | 263 | |
264 | - return trim( $where ); |
|
264 | + return trim($where); |
|
265 | 265 | |
266 | 266 | } |
267 | 267 | |
@@ -279,17 +279,17 @@ discard block |
||
279 | 279 | |
280 | 280 | $where = ''; |
281 | 281 | |
282 | - if ( ! empty( $this->args['email'] ) ) { |
|
282 | + if ( ! empty($this->args['email'])) { |
|
283 | 283 | |
284 | - if ( is_array( $this->args['email'] ) ) { |
|
284 | + if (is_array($this->args['email'])) { |
|
285 | 285 | |
286 | - $emails_count = count( $this->args['email'] ); |
|
287 | - $emails_placeholder = array_fill( 0, $emails_count, '%s' ); |
|
288 | - $emails = implode( ', ', $emails_placeholder ); |
|
286 | + $emails_count = count($this->args['email']); |
|
287 | + $emails_placeholder = array_fill(0, $emails_count, '%s'); |
|
288 | + $emails = implode(', ', $emails_placeholder); |
|
289 | 289 | |
290 | - $where .= $wpdb->prepare( "AND {$this->table_name}.email IN( $emails )", $this->args['email'] ); |
|
290 | + $where .= $wpdb->prepare("AND {$this->table_name}.email IN( $emails )", $this->args['email']); |
|
291 | 291 | } else { |
292 | - $where .= $wpdb->prepare( "AND {$this->table_name}.email = %s", $this->args['email'] ); |
|
292 | + $where .= $wpdb->prepare("AND {$this->table_name}.email = %s", $this->args['email']); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | $where = ''; |
310 | 310 | |
311 | 311 | // Specific donors. |
312 | - if ( ! empty( $this->args['donor'] ) ) { |
|
313 | - if ( ! is_array( $this->args['donor'] ) ) { |
|
314 | - $this->args['donor'] = explode( ',', $this->args['donor'] ); |
|
312 | + if ( ! empty($this->args['donor'])) { |
|
313 | + if ( ! is_array($this->args['donor'])) { |
|
314 | + $this->args['donor'] = explode(',', $this->args['donor']); |
|
315 | 315 | } |
316 | - $donor_ids = implode( ',', array_map( 'intval', $this->args['donor'] ) ); |
|
316 | + $donor_ids = implode(',', array_map('intval', $this->args['donor'])); |
|
317 | 317 | |
318 | 318 | $where .= "AND {$this->table_name}.id IN( {$donor_ids} )"; |
319 | 319 | } |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | $where = ''; |
335 | 335 | |
336 | 336 | // Donors created for a specific date or in a date range |
337 | - if ( ! empty( $this->args['date_query'] ) ) { |
|
337 | + if ( ! empty($this->args['date_query'])) { |
|
338 | 338 | $date_query_object = new WP_Date_Query( |
339 | - is_array( $this->args['date_query'] ) ? $this->args['date_query'] : wp_parse_args( $this->args['date_query'] ), |
|
339 | + is_array($this->args['date_query']) ? $this->args['date_query'] : wp_parse_args($this->args['date_query']), |
|
340 | 340 | "{$this->table_name}.date_created" |
341 | 341 | ); |
342 | 342 | |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | $where = ''; |
372 | 372 | |
373 | 373 | // Donors created for a specific date or in a date range |
374 | - if ( ! empty( $this->args['s'] ) && false !== strpos( $this->args['s'], ':' ) ) { |
|
375 | - $search_parts = explode( ':', $this->args['s'] ); |
|
374 | + if ( ! empty($this->args['s']) && false !== strpos($this->args['s'], ':')) { |
|
375 | + $search_parts = explode(':', $this->args['s']); |
|
376 | 376 | |
377 | - if ( ! empty( $search_parts[0] ) ) { |
|
378 | - switch ( $search_parts[0] ) { |
|
377 | + if ( ! empty($search_parts[0])) { |
|
378 | + switch ($search_parts[0]) { |
|
379 | 379 | case 'name': |
380 | 380 | $where = "AND {$this->table_name}.name LIKE '%{$search_parts[1]}%'"; |
381 | 381 | break; |
@@ -403,11 +403,11 @@ discard block |
||
403 | 403 | $where = ''; |
404 | 404 | |
405 | 405 | // Donors create for specific wp user. |
406 | - if ( ! empty( $this->args['user'] ) ) { |
|
407 | - if ( ! is_array( $this->args['user'] ) ) { |
|
408 | - $this->args['user'] = explode( ',', $this->args['user'] ); |
|
406 | + if ( ! empty($this->args['user'])) { |
|
407 | + if ( ! is_array($this->args['user'])) { |
|
408 | + $this->args['user'] = explode(',', $this->args['user']); |
|
409 | 409 | } |
410 | - $user_ids = implode( ',', array_map( 'intval', $this->args['user'] ) ); |
|
410 | + $user_ids = implode(',', array_map('intval', $this->args['user'])); |
|
411 | 411 | |
412 | 412 | $where .= "AND {$this->table_name}.user_id IN( {$user_ids} )"; |
413 | 413 | } |
@@ -426,14 +426,13 @@ discard block |
||
426 | 426 | private function get_order_query() { |
427 | 427 | $table_columns = Give()->donors->get_columns(); |
428 | 428 | |
429 | - $this->args['orderby'] = ! array_key_exists( $this->args['orderby'], $table_columns ) ? |
|
430 | - 'id' : |
|
431 | - $this->args['orderby']; |
|
429 | + $this->args['orderby'] = ! array_key_exists($this->args['orderby'], $table_columns) ? |
|
430 | + 'id' : $this->args['orderby']; |
|
432 | 431 | |
433 | - $this->args['orderby'] = esc_sql( $this->args['orderby'] ); |
|
434 | - $this->args['order'] = esc_sql( $this->args['order'] ); |
|
432 | + $this->args['orderby'] = esc_sql($this->args['orderby']); |
|
433 | + $this->args['order'] = esc_sql($this->args['order']); |
|
435 | 434 | |
436 | - switch ( $table_columns[ $this->args['orderby'] ] ) { |
|
435 | + switch ($table_columns[$this->args['orderby']]) { |
|
437 | 436 | case '%d': |
438 | 437 | case '%f': |
439 | 438 | $query = "ORDER BY {$this->table_name}.{$this->args['orderby']}+0"; |
@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | * @since 1.8 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; // Exit if accessed directly. |
14 | 14 | } |
15 | 15 | |
16 | -if ( ! class_exists( 'Give_Settings_General' ) ) : |
|
16 | +if ( ! class_exists('Give_Settings_General')) : |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Give_Settings_General. |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function __construct() { |
29 | 29 | $this->id = 'general'; |
30 | - $this->label = __( 'General', 'give' ); |
|
30 | + $this->label = __('General', 'give'); |
|
31 | 31 | |
32 | 32 | $this->default_tab = 'general-settings'; |
33 | 33 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $settings = array(); |
45 | 45 | $current_section = give_get_current_setting_section(); |
46 | 46 | |
47 | - switch ( $current_section ) { |
|
47 | + switch ($current_section) { |
|
48 | 48 | case 'access-control': |
49 | 49 | $settings = array( |
50 | 50 | // Section 3: Access control. |
@@ -54,20 +54,20 @@ discard block |
||
54 | 54 | ), |
55 | 55 | array( |
56 | 56 | 'id' => 'session_lifetime', |
57 | - 'name' => __( 'Session Lifetime', 'give' ), |
|
58 | - 'desc' => __( 'The length of time a user\'s session is kept alive. Give starts a new session per user upon donation. Sessions allow donors to view their donation receipts without being logged in.', 'give' ), |
|
57 | + 'name' => __('Session Lifetime', 'give'), |
|
58 | + 'desc' => __('The length of time a user\'s session is kept alive. Give starts a new session per user upon donation. Sessions allow donors to view their donation receipts without being logged in.', 'give'), |
|
59 | 59 | 'type' => 'select', |
60 | 60 | 'options' => array( |
61 | - '86400' => __( '24 Hours', 'give' ), |
|
62 | - '172800' => __( '48 Hours', 'give' ), |
|
63 | - '259200' => __( '72 Hours', 'give' ), |
|
64 | - '604800' => __( '1 Week', 'give' ), |
|
61 | + '86400' => __('24 Hours', 'give'), |
|
62 | + '172800' => __('48 Hours', 'give'), |
|
63 | + '259200' => __('72 Hours', 'give'), |
|
64 | + '604800' => __('1 Week', 'give'), |
|
65 | 65 | ), |
66 | 66 | ), |
67 | 67 | array( |
68 | 68 | 'id' => 'limit_display_donations', |
69 | - 'name' => __( 'Limit Donations Displayed', 'give' ), |
|
70 | - 'desc' => __( 'Adjusts the number of donations displayed to a non logged-in user when they attempt to access the Donation History page without an active session. For security reasons, it\'s best to leave this at 1-3 donations.', 'give' ), |
|
69 | + 'name' => __('Limit Donations Displayed', 'give'), |
|
70 | + 'desc' => __('Adjusts the number of donations displayed to a non logged-in user when they attempt to access the Donation History page without an active session. For security reasons, it\'s best to leave this at 1-3 donations.', 'give'), |
|
71 | 71 | 'default' => '1', |
72 | 72 | 'type' => 'number', |
73 | 73 | 'css' => 'width:50px;', |
@@ -77,36 +77,36 @@ discard block |
||
77 | 77 | ), |
78 | 78 | ), |
79 | 79 | array( |
80 | - 'name' => __( 'Email Access', 'give' ), |
|
81 | - 'desc' => __( 'Would you like your donors to be able to access their donation history using only email? Donors whose sessions have expired and do not have an account may still access their donation history via a temporary email access link.', 'give' ), |
|
80 | + 'name' => __('Email Access', 'give'), |
|
81 | + 'desc' => __('Would you like your donors to be able to access their donation history using only email? Donors whose sessions have expired and do not have an account may still access their donation history via a temporary email access link.', 'give'), |
|
82 | 82 | 'id' => 'email_access', |
83 | 83 | 'type' => 'radio_inline', |
84 | 84 | 'default' => 'disabled', |
85 | 85 | 'options' => array( |
86 | - 'enabled' => __( 'Enabled', 'give' ), |
|
87 | - 'disabled' => __( 'Disabled', 'give' ), |
|
86 | + 'enabled' => __('Enabled', 'give'), |
|
87 | + 'disabled' => __('Disabled', 'give'), |
|
88 | 88 | ), |
89 | 89 | ), |
90 | 90 | array( |
91 | 91 | 'id' => 'recaptcha_key', |
92 | - 'name' => __( 'reCAPTCHA Site Key', 'give' ), |
|
92 | + 'name' => __('reCAPTCHA Site Key', 'give'), |
|
93 | 93 | /* translators: %s: https://www.google.com/recaptcha/ */ |
94 | - 'desc' => sprintf( __( 'If you would like to prevent spam on the email access form navigate to <a href="%s" target="_blank">the reCAPTCHA website</a> and sign up for an API key and paste your reCAPTCHA site key here. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give' ), esc_url( 'http://docs.givewp.com/recaptcha' ) ), |
|
94 | + 'desc' => sprintf(__('If you would like to prevent spam on the email access form navigate to <a href="%s" target="_blank">the reCAPTCHA website</a> and sign up for an API key and paste your reCAPTCHA site key here. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give'), esc_url('http://docs.givewp.com/recaptcha')), |
|
95 | 95 | 'default' => '', |
96 | 96 | 'type' => 'text', |
97 | 97 | ), |
98 | 98 | array( |
99 | 99 | 'id' => 'recaptcha_secret', |
100 | - 'name' => __( 'reCAPTCHA Secret Key', 'give' ), |
|
101 | - 'desc' => __( 'Please paste the reCAPTCHA secret key here from your reCAPTCHA API Keys panel.', 'give' ), |
|
100 | + 'name' => __('reCAPTCHA Secret Key', 'give'), |
|
101 | + 'desc' => __('Please paste the reCAPTCHA secret key here from your reCAPTCHA API Keys panel.', 'give'), |
|
102 | 102 | 'default' => '', |
103 | 103 | 'type' => 'text', |
104 | 104 | ), |
105 | 105 | array( |
106 | - 'name' => __( 'Access Control Docs Link', 'give' ), |
|
106 | + 'name' => __('Access Control Docs Link', 'give'), |
|
107 | 107 | 'id' => 'access_control_docs_link', |
108 | - 'url' => esc_url( 'http://docs.givewp.com/settings-access-control' ), |
|
109 | - 'title' => __( 'Access Control', 'give' ), |
|
108 | + 'url' => esc_url('http://docs.givewp.com/settings-access-control'), |
|
109 | + 'title' => __('Access Control', 'give'), |
|
110 | 110 | 'type' => 'give_docs_link', |
111 | 111 | ), |
112 | 112 | array( |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | break; |
118 | 118 | |
119 | 119 | case 'currency-settings' : |
120 | - $currency_position_before = __( 'Before - %s‎10', 'give' ); |
|
121 | - $currency_position_after = __( 'After - 10%s‏', 'give' ); |
|
120 | + $currency_position_before = __('Before - %s‎10', 'give'); |
|
121 | + $currency_position_after = __('After - 10%s‏', 'give'); |
|
122 | 122 | |
123 | 123 | $settings = array( |
124 | 124 | // Section 2: Currency |
@@ -127,14 +127,14 @@ discard block |
||
127 | 127 | 'id' => 'give_title_general_settings_2', |
128 | 128 | ), |
129 | 129 | array( |
130 | - 'name' => __( 'Currency Settings', 'give' ), |
|
130 | + 'name' => __('Currency Settings', 'give'), |
|
131 | 131 | 'desc' => '', |
132 | 132 | 'type' => 'give_title', |
133 | 133 | 'id' => 'give_title_general_settings_2', |
134 | 134 | ), |
135 | 135 | array( |
136 | - 'name' => __( 'Currency', 'give' ), |
|
137 | - 'desc' => __( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ), |
|
136 | + 'name' => __('Currency', 'give'), |
|
137 | + 'desc' => __('The donation currency. Note that some payment gateways have currency restrictions.', 'give'), |
|
138 | 138 | 'id' => 'currency', |
139 | 139 | 'class' => 'give-select-chosen', |
140 | 140 | 'type' => 'select', |
@@ -142,51 +142,51 @@ discard block |
||
142 | 142 | 'default' => 'USD', |
143 | 143 | ), |
144 | 144 | array( |
145 | - 'name' => __( 'Currency Position', 'give' ), |
|
146 | - 'desc' => __( 'The position of the currency symbol.', 'give' ), |
|
145 | + 'name' => __('Currency Position', 'give'), |
|
146 | + 'desc' => __('The position of the currency symbol.', 'give'), |
|
147 | 147 | 'id' => 'currency_position', |
148 | 148 | 'type' => 'select', |
149 | 149 | 'options' => array( |
150 | 150 | /* translators: %s: currency symbol */ |
151 | - 'before' => sprintf( $currency_position_before, give_currency_symbol( give_get_currency() ) ), |
|
151 | + 'before' => sprintf($currency_position_before, give_currency_symbol(give_get_currency())), |
|
152 | 152 | /* translators: %s: currency symbol */ |
153 | - 'after' => sprintf( $currency_position_after, give_currency_symbol( give_get_currency() ) ), |
|
153 | + 'after' => sprintf($currency_position_after, give_currency_symbol(give_get_currency())), |
|
154 | 154 | ), |
155 | 155 | 'default' => 'before', |
156 | 156 | 'attributes' => array( |
157 | - 'data-before-template' => sprintf( $currency_position_before, '{currency_pos}' ), |
|
158 | - 'data-after-template' => sprintf( $currency_position_after, '{currency_pos}' ), |
|
157 | + 'data-before-template' => sprintf($currency_position_before, '{currency_pos}'), |
|
158 | + 'data-after-template' => sprintf($currency_position_after, '{currency_pos}'), |
|
159 | 159 | ), |
160 | 160 | ), |
161 | 161 | array( |
162 | - 'name' => __( 'Thousands Separator', 'give' ), |
|
163 | - 'desc' => __( 'The symbol (typically , or .) to separate thousands.', 'give' ), |
|
162 | + 'name' => __('Thousands Separator', 'give'), |
|
163 | + 'desc' => __('The symbol (typically , or .) to separate thousands.', 'give'), |
|
164 | 164 | 'id' => 'thousands_separator', |
165 | 165 | 'type' => 'text', |
166 | 166 | 'default' => ',', |
167 | 167 | 'css' => 'width:12em;', |
168 | 168 | ), |
169 | 169 | array( |
170 | - 'name' => __( 'Decimal Separator', 'give' ), |
|
171 | - 'desc' => __( 'The symbol (usually , or .) to separate decimal points.', 'give' ), |
|
170 | + 'name' => __('Decimal Separator', 'give'), |
|
171 | + 'desc' => __('The symbol (usually , or .) to separate decimal points.', 'give'), |
|
172 | 172 | 'id' => 'decimal_separator', |
173 | 173 | 'type' => 'text', |
174 | 174 | 'default' => '.', |
175 | 175 | 'css' => 'width:12em;', |
176 | 176 | ), |
177 | 177 | array( |
178 | - 'name' => __( 'Number of Decimals', 'give' ), |
|
179 | - 'desc' => __( 'The number of decimal points displayed in amounts.', 'give' ), |
|
178 | + 'name' => __('Number of Decimals', 'give'), |
|
179 | + 'desc' => __('The number of decimal points displayed in amounts.', 'give'), |
|
180 | 180 | 'id' => 'number_decimals', |
181 | 181 | 'type' => 'text', |
182 | 182 | 'default' => 2, |
183 | 183 | 'css' => 'width:12em;', |
184 | 184 | ), |
185 | 185 | array( |
186 | - 'name' => __( 'Currency Options Docs Link', 'give' ), |
|
186 | + 'name' => __('Currency Options Docs Link', 'give'), |
|
187 | 187 | 'id' => 'currency_settings_docs_link', |
188 | - 'url' => esc_url( 'http://docs.givewp.com/settings-currency' ), |
|
189 | - 'title' => __( 'Currency Settings', 'give' ), |
|
188 | + 'url' => esc_url('http://docs.givewp.com/settings-currency'), |
|
189 | + 'title' => __('Currency Settings', 'give'), |
|
190 | 190 | 'type' => 'give_docs_link', |
191 | 191 | ), |
192 | 192 | array( |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $country = give_get_country(); |
203 | 203 | |
204 | 204 | // get the list of the states of which default country is selected. |
205 | - $states = give_get_states( $country ); |
|
205 | + $states = give_get_states($country); |
|
206 | 206 | |
207 | 207 | // Get the country list that does not have any states init. |
208 | 208 | $no_states_country = give_no_states_country_list(); |
@@ -214,46 +214,46 @@ discard block |
||
214 | 214 | 'id' => 'give_title_general_settings_1', |
215 | 215 | ), |
216 | 216 | array( |
217 | - 'name' => __( 'General Settings', 'give' ), |
|
217 | + 'name' => __('General Settings', 'give'), |
|
218 | 218 | 'desc' => '', |
219 | 219 | 'type' => 'give_title', |
220 | 220 | 'id' => 'give_title_general_settings_1', |
221 | 221 | ), |
222 | 222 | array( |
223 | - 'name' => __( 'Success Page', 'give' ), |
|
223 | + 'name' => __('Success Page', 'give'), |
|
224 | 224 | /* translators: %s: [give_receipt] */ |
225 | - 'desc' => sprintf( __( 'The page donors are sent to after completing their donations. The %s shortcode should be on this page.', 'give' ), '<code>[give_receipt]</code>' ), |
|
225 | + 'desc' => sprintf(__('The page donors are sent to after completing their donations. The %s shortcode should be on this page.', 'give'), '<code>[give_receipt]</code>'), |
|
226 | 226 | 'id' => 'success_page', |
227 | 227 | 'type' => 'select', |
228 | - 'options' => give_cmb2_get_post_options( array( |
|
228 | + 'options' => give_cmb2_get_post_options(array( |
|
229 | 229 | 'post_type' => 'page', |
230 | 230 | 'numberposts' => 999, |
231 | - ) ), |
|
231 | + )), |
|
232 | 232 | ), |
233 | 233 | array( |
234 | - 'name' => __( 'Failed Donation Page', 'give' ), |
|
235 | - 'desc' => __( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ), |
|
234 | + 'name' => __('Failed Donation Page', 'give'), |
|
235 | + 'desc' => __('The page donors are sent to if their donation is cancelled or fails.', 'give'), |
|
236 | 236 | 'id' => 'failure_page', |
237 | 237 | 'type' => 'select', |
238 | - 'options' => give_cmb2_get_post_options( array( |
|
238 | + 'options' => give_cmb2_get_post_options(array( |
|
239 | 239 | 'post_type' => 'page', |
240 | 240 | 'numberposts' => 999, |
241 | - ) ), |
|
241 | + )), |
|
242 | 242 | ), |
243 | 243 | array( |
244 | - 'name' => __( 'Donation History Page', 'give' ), |
|
244 | + 'name' => __('Donation History Page', 'give'), |
|
245 | 245 | /* translators: %s: [donation_history] */ |
246 | - 'desc' => sprintf( __( 'The page showing a complete donation history for the current user. The %s shortcode should be on this page.', 'give' ), '<code>[donation_history]</code>' ), |
|
246 | + 'desc' => sprintf(__('The page showing a complete donation history for the current user. The %s shortcode should be on this page.', 'give'), '<code>[donation_history]</code>'), |
|
247 | 247 | 'id' => 'history_page', |
248 | 248 | 'type' => 'select', |
249 | - 'options' => give_cmb2_get_post_options( array( |
|
249 | + 'options' => give_cmb2_get_post_options(array( |
|
250 | 250 | 'post_type' => 'page', |
251 | 251 | 'numberposts' => 999, |
252 | - ) ), |
|
252 | + )), |
|
253 | 253 | ), |
254 | 254 | array( |
255 | - 'name' => __( 'Base Country', 'give' ), |
|
256 | - 'desc' => __( 'The country your site operates from.', 'give' ), |
|
255 | + 'name' => __('Base Country', 'give'), |
|
256 | + 'desc' => __('The country your site operates from.', 'give'), |
|
257 | 257 | 'id' => 'base_country', |
258 | 258 | 'type' => 'select', |
259 | 259 | 'options' => give_get_country_list(), |
@@ -264,18 +264,18 @@ discard block |
||
264 | 264 | * @since 1.8.14 |
265 | 265 | */ |
266 | 266 | array( |
267 | - 'wrapper_class' => ( array_key_exists( $country, $no_states_country ) ? 'give-hidden' : '' ), |
|
268 | - 'name' => __( 'Base State/Province', 'give' ), |
|
269 | - 'desc' => __( 'The state/province your site operates from.', 'give' ), |
|
267 | + 'wrapper_class' => (array_key_exists($country, $no_states_country) ? 'give-hidden' : ''), |
|
268 | + 'name' => __('Base State/Province', 'give'), |
|
269 | + 'desc' => __('The state/province your site operates from.', 'give'), |
|
270 | 270 | 'id' => 'base_state', |
271 | - 'type' => ( empty( $states ) ? 'text' : 'select' ), |
|
271 | + 'type' => (empty($states) ? 'text' : 'select'), |
|
272 | 272 | 'options' => $states, |
273 | 273 | ), |
274 | 274 | array( |
275 | - 'name' => __( 'General Options Docs Link', 'give' ), |
|
275 | + 'name' => __('General Options Docs Link', 'give'), |
|
276 | 276 | 'id' => 'general_options_docs_link', |
277 | - 'url' => esc_url( 'http://docs.givewp.com/settings-general' ), |
|
278 | - 'title' => __( 'General Options', 'give' ), |
|
277 | + 'url' => esc_url('http://docs.givewp.com/settings-general'), |
|
278 | + 'title' => __('General Options', 'give'), |
|
279 | 279 | 'type' => 'give_docs_link', |
280 | 280 | ), |
281 | 281 | array( |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * Filter the general settings. |
291 | 291 | * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
292 | 292 | */ |
293 | - $settings = apply_filters( 'give_settings_general', $settings ); |
|
293 | + $settings = apply_filters('give_settings_general', $settings); |
|
294 | 294 | |
295 | 295 | /** |
296 | 296 | * Filter the settings. |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param array $settings |
301 | 301 | */ |
302 | - $settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
|
302 | + $settings = apply_filters('give_get_settings_'.$this->id, $settings); |
|
303 | 303 | |
304 | 304 | // Output. |
305 | 305 | return $settings; |
@@ -313,12 +313,12 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function get_sections() { |
315 | 315 | $sections = array( |
316 | - 'general-settings' => __( 'General', 'give' ), |
|
317 | - 'currency-settings' => __( 'Currency', 'give' ), |
|
318 | - 'access-control' => __( 'Access Control', 'give' ), |
|
316 | + 'general-settings' => __('General', 'give'), |
|
317 | + 'currency-settings' => __('Currency', 'give'), |
|
318 | + 'access-control' => __('Access Control', 'give'), |
|
319 | 319 | ); |
320 | 320 | |
321 | - return apply_filters( 'give_get_sections_' . $this->id, $sections ); |
|
321 | + return apply_filters('give_get_sections_'.$this->id, $sections); |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 |
@@ -277,7 +277,7 @@ |
||
277 | 277 | /** |
278 | 278 | * Rename query clauses for new meta table |
279 | 279 | * |
280 | - * @param $clause |
|
280 | + * @param string $clause |
|
281 | 281 | * @param $filter |
282 | 282 | * |
283 | 283 | * @return mixed |
@@ -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 | |
@@ -75,40 +75,40 @@ discard block |
||
75 | 75 | */ |
76 | 76 | function __construct() { |
77 | 77 | // Bailout. |
78 | - if ( empty( $this->supports ) || ! $this->is_custom_meta_table_active() ) { |
|
78 | + if (empty($this->supports) || ! $this->is_custom_meta_table_active()) { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | - if ( in_array( 'add_post_metadata', $this->supports ) ) { |
|
83 | - add_filter( 'add_post_metadata', array( $this, '__add_meta' ), 0, 5 ); |
|
82 | + if (in_array('add_post_metadata', $this->supports)) { |
|
83 | + add_filter('add_post_metadata', array($this, '__add_meta'), 0, 5); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( in_array( 'get_post_metadata', $this->supports ) ) { |
|
87 | - add_filter( 'get_post_metadata', array( $this, '__get_meta' ), 0, 4 ); |
|
86 | + if (in_array('get_post_metadata', $this->supports)) { |
|
87 | + add_filter('get_post_metadata', array($this, '__get_meta'), 0, 4); |
|
88 | 88 | } |
89 | 89 | |
90 | - if ( in_array( 'update_post_metadata', $this->supports ) ) { |
|
91 | - add_filter( 'update_post_metadata', array( $this, '__update_meta' ), 0, 5 ); |
|
90 | + if (in_array('update_post_metadata', $this->supports)) { |
|
91 | + add_filter('update_post_metadata', array($this, '__update_meta'), 0, 5); |
|
92 | 92 | } |
93 | 93 | |
94 | - if ( in_array( 'delete_post_metadata', $this->supports ) ) { |
|
95 | - add_filter( 'delete_post_metadata', array( $this, '__delete_meta' ), 0, 5 ); |
|
94 | + if (in_array('delete_post_metadata', $this->supports)) { |
|
95 | + add_filter('delete_post_metadata', array($this, '__delete_meta'), 0, 5); |
|
96 | 96 | } |
97 | 97 | |
98 | - if ( in_array( 'posts_where', $this->supports ) ) { |
|
99 | - add_filter( 'posts_where', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
98 | + if (in_array('posts_where', $this->supports)) { |
|
99 | + add_filter('posts_where', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
100 | 100 | } |
101 | 101 | |
102 | - if ( in_array( 'posts_join', $this->supports ) ) { |
|
103 | - add_filter( 'posts_join', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
102 | + if (in_array('posts_join', $this->supports)) { |
|
103 | + add_filter('posts_join', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( in_array( 'posts_groupby', $this->supports ) ) { |
|
107 | - add_filter( 'posts_groupby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
106 | + if (in_array('posts_groupby', $this->supports)) { |
|
107 | + add_filter('posts_groupby', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
108 | 108 | } |
109 | 109 | |
110 | - if ( in_array( 'posts_orderby', $this->supports ) ) { |
|
111 | - add_filter( 'posts_orderby', array( $this, '__rename_meta_table_name_in_query' ), 99999, 2 ); |
|
110 | + if (in_array('posts_orderby', $this->supports)) { |
|
111 | + add_filter('posts_orderby', array($this, '__rename_meta_table_name_in_query'), 99999, 2); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -126,16 +126,16 @@ discard block |
||
126 | 126 | * @return mixed Will be an array if $single is false. Will be value of meta data field if $single |
127 | 127 | * is true. |
128 | 128 | */ |
129 | - public function get_meta( $id = 0, $meta_key = '', $single = false ) { |
|
130 | - $id = $this->sanitize_id( $id ); |
|
129 | + public function get_meta($id = 0, $meta_key = '', $single = false) { |
|
130 | + $id = $this->sanitize_id($id); |
|
131 | 131 | |
132 | 132 | // Bailout. |
133 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
133 | + if ( ! $this->is_valid_post_type($id)) { |
|
134 | 134 | return $this->check; |
135 | 135 | } |
136 | 136 | |
137 | - if ( $this->raw_result ) { |
|
138 | - if ( ! ( $value = get_metadata( $this->meta_type, $id, $meta_key, false ) ) ) { |
|
137 | + if ($this->raw_result) { |
|
138 | + if ( ! ($value = get_metadata($this->meta_type, $id, $meta_key, false))) { |
|
139 | 139 | $value = ''; |
140 | 140 | } |
141 | 141 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $this->raw_result = false; |
144 | 144 | |
145 | 145 | } else { |
146 | - $value = get_metadata( $this->meta_type, $id, $meta_key, $single ); |
|
146 | + $value = get_metadata($this->meta_type, $id, $meta_key, $single); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $value; |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @return int|bool False for failure. True for success. |
167 | 167 | */ |
168 | - public function add_meta( $id = 0, $meta_key = '', $meta_value, $unique = false ) { |
|
169 | - $id = $this->sanitize_id( $id ); |
|
168 | + public function add_meta($id = 0, $meta_key = '', $meta_value, $unique = false) { |
|
169 | + $id = $this->sanitize_id($id); |
|
170 | 170 | |
171 | 171 | // Bailout. |
172 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
172 | + if ( ! $this->is_valid_post_type($id)) { |
|
173 | 173 | return $this->check; |
174 | 174 | } |
175 | 175 | |
176 | - $meta_id = add_metadata( $this->meta_type, $id, $meta_key, $meta_value, $unique ); |
|
176 | + $meta_id = add_metadata($this->meta_type, $id, $meta_key, $meta_value, $unique); |
|
177 | 177 | |
178 | - if ( $meta_id ) { |
|
179 | - $this->delete_cache( $id ); |
|
178 | + if ($meta_id) { |
|
179 | + $this->delete_cache($id); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | return $meta_id; |
@@ -202,18 +202,18 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return int|bool False on failure, true if success. |
204 | 204 | */ |
205 | - public function update_meta( $id = 0, $meta_key = '', $meta_value, $prev_value = '' ) { |
|
206 | - $id = $this->sanitize_id( $id ); |
|
205 | + public function update_meta($id = 0, $meta_key = '', $meta_value, $prev_value = '') { |
|
206 | + $id = $this->sanitize_id($id); |
|
207 | 207 | |
208 | 208 | // Bailout. |
209 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
209 | + if ( ! $this->is_valid_post_type($id)) { |
|
210 | 210 | return $this->check; |
211 | 211 | } |
212 | 212 | |
213 | - $meta_id = update_metadata( $this->meta_type, $id, $meta_key, $meta_value, $prev_value ); |
|
213 | + $meta_id = update_metadata($this->meta_type, $id, $meta_key, $meta_value, $prev_value); |
|
214 | 214 | |
215 | - if ( $meta_id ) { |
|
216 | - $this->delete_cache( $id ); |
|
215 | + if ($meta_id) { |
|
216 | + $this->delete_cache($id); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | return $meta_id; |
@@ -236,18 +236,18 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return bool False for failure. True for success. |
238 | 238 | */ |
239 | - public function delete_meta( $id = 0, $meta_key = '', $meta_value = '', $delete_all = '' ) { |
|
240 | - $id = $this->sanitize_id( $id ); |
|
239 | + public function delete_meta($id = 0, $meta_key = '', $meta_value = '', $delete_all = '') { |
|
240 | + $id = $this->sanitize_id($id); |
|
241 | 241 | |
242 | 242 | // Bailout. |
243 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
243 | + if ( ! $this->is_valid_post_type($id)) { |
|
244 | 244 | return $this->check; |
245 | 245 | } |
246 | 246 | |
247 | - $is_meta_deleted = delete_metadata( $this->meta_type, $id, $meta_key, $meta_value, $delete_all ); |
|
247 | + $is_meta_deleted = delete_metadata($this->meta_type, $id, $meta_key, $meta_value, $delete_all); |
|
248 | 248 | |
249 | - if ( $is_meta_deleted ) { |
|
250 | - $this->delete_cache( $id ); |
|
249 | + if ($is_meta_deleted) { |
|
250 | + $this->delete_cache($id); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | return $is_meta_deleted; |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @return string |
266 | 266 | */ |
267 | - public function __rename_meta_table_name_in_query( $clause, $wp_query ) { |
|
267 | + public function __rename_meta_table_name_in_query($clause, $wp_query) { |
|
268 | 268 | // Add new table to sql query. |
269 | - if ( $this->is_post_type_query( $wp_query ) && ! empty( $wp_query->meta_query->queries ) ) { |
|
270 | - $clause = $this->__rename_meta_table_name( $clause, current_filter() ); |
|
269 | + if ($this->is_post_type_query($wp_query) && ! empty($wp_query->meta_query->queries)) { |
|
270 | + $clause = $this->__rename_meta_table_name($clause, current_filter()); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | return $clause; |
@@ -282,39 +282,39 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return mixed |
284 | 284 | */ |
285 | - public function __rename_meta_table_name( $clause, $filter ){ |
|
285 | + public function __rename_meta_table_name($clause, $filter) { |
|
286 | 286 | global $wpdb; |
287 | 287 | |
288 | - $clause = str_replace( "{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause ); |
|
289 | - $clause = str_replace( $wpdb->postmeta, $this->table_name, $clause ); |
|
288 | + $clause = str_replace("{$wpdb->postmeta}.post_id", "{$this->table_name}.{$this->meta_type}_id", $clause); |
|
289 | + $clause = str_replace($wpdb->postmeta, $this->table_name, $clause); |
|
290 | 290 | |
291 | - switch( $filter ) { |
|
291 | + switch ($filter) { |
|
292 | 292 | case 'posts_join': |
293 | - $joins = array( 'INNER JOIN', 'LEFT JOIN' ); |
|
293 | + $joins = array('INNER JOIN', 'LEFT JOIN'); |
|
294 | 294 | |
295 | - foreach ( $joins as $join ) { |
|
296 | - if( false !== strpos( $clause, $join ) ) { |
|
297 | - $clause = explode( $join, $clause ); |
|
295 | + foreach ($joins as $join) { |
|
296 | + if (false !== strpos($clause, $join)) { |
|
297 | + $clause = explode($join, $clause); |
|
298 | 298 | |
299 | - foreach ( $clause as $key => $clause_part ) { |
|
300 | - if( empty( $clause_part ) ) { |
|
299 | + foreach ($clause as $key => $clause_part) { |
|
300 | + if (empty($clause_part)) { |
|
301 | 301 | continue; |
302 | 302 | } |
303 | 303 | |
304 | - preg_match( '/' . $wpdb->prefix . 'give_' . $this->meta_type . 'meta AS (.*) ON/', $clause_part, $alias_table_name ); |
|
304 | + preg_match('/'.$wpdb->prefix.'give_'.$this->meta_type.'meta AS (.*) ON/', $clause_part, $alias_table_name); |
|
305 | 305 | |
306 | - if( isset( $alias_table_name[1] ) ) { |
|
307 | - $clause[$key] = str_replace( "{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part ); |
|
306 | + if (isset($alias_table_name[1])) { |
|
307 | + $clause[$key] = str_replace("{$alias_table_name[1]}.post_id", "{$alias_table_name[1]}.{$this->meta_type}_id", $clause_part); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
311 | - $clause = implode( "{$join} ", $clause ); |
|
311 | + $clause = implode("{$join} ", $clause); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | break; |
315 | 315 | |
316 | 316 | case 'posts_where': |
317 | - $clause = str_replace( array( 'mt2.post_id', 'mt1.post_id' ), array( "mt2.{$this->meta_type}_id", "mt1.{$this->meta_type}_id" ), $clause ); |
|
317 | + $clause = str_replace(array('mt2.post_id', 'mt1.post_id'), array("mt2.{$this->meta_type}_id", "mt1.{$this->meta_type}_id"), $clause); |
|
318 | 318 | break; |
319 | 319 | } |
320 | 320 | |
@@ -332,19 +332,19 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @return bool |
334 | 334 | */ |
335 | - protected function is_post_type_query( $wp_query ) { |
|
335 | + protected function is_post_type_query($wp_query) { |
|
336 | 336 | $status = false; |
337 | 337 | |
338 | 338 | // Check if it is payment query. |
339 | - if ( ! empty( $wp_query->query['post_type'] ) ) { |
|
339 | + if ( ! empty($wp_query->query['post_type'])) { |
|
340 | 340 | if ( |
341 | - is_string( $wp_query->query['post_type'] ) && |
|
341 | + is_string($wp_query->query['post_type']) && |
|
342 | 342 | $this->post_type === $wp_query->query['post_type'] |
343 | 343 | ) { |
344 | 344 | $status = true; |
345 | 345 | } elseif ( |
346 | - is_array( $wp_query->query['post_type'] ) && |
|
347 | - in_array( $this->post_type, $wp_query->query['post_type'] ) |
|
346 | + is_array($wp_query->query['post_type']) && |
|
347 | + in_array($this->post_type, $wp_query->query['post_type']) |
|
348 | 348 | ) { |
349 | 349 | $status = true; |
350 | 350 | } |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return bool |
365 | 365 | */ |
366 | - protected function is_valid_post_type( $ID ) { |
|
367 | - return $ID && ( $this->post_type === get_post_type( $ID ) ); |
|
366 | + protected function is_valid_post_type($ID) { |
|
367 | + return $ID && ($this->post_type === get_post_type($ID)); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @return void |
392 | 392 | */ |
393 | - private function delete_cache( $id, $meta_type = '' ) { |
|
394 | - $meta_type = empty( $meta_type ) ? $this->meta_type : $meta_type; |
|
393 | + private function delete_cache($id, $meta_type = '') { |
|
394 | + $meta_type = empty($meta_type) ? $this->meta_type : $meta_type; |
|
395 | 395 | |
396 | 396 | $group = array( |
397 | 397 | // 'form' => 'give-forms', |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | // 'log' => 'give-logs', |
402 | 402 | ); |
403 | 403 | |
404 | - if ( array_key_exists( $meta_type, $group ) ) { |
|
405 | - Give_Cache::delete_group( $id, $group[ $meta_type ] ); |
|
404 | + if (array_key_exists($meta_type, $group)) { |
|
405 | + Give_Cache::delete_group($id, $group[$meta_type]); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
@@ -417,8 +417,8 @@ discard block |
||
417 | 417 | * |
418 | 418 | * @return mixed |
419 | 419 | */ |
420 | - public function __call( $name, $arguments ) { |
|
421 | - switch ( $name ) { |
|
420 | + public function __call($name, $arguments) { |
|
421 | + switch ($name) { |
|
422 | 422 | case '__add_meta': |
423 | 423 | $this->check = $arguments[0]; |
424 | 424 | $id = $arguments[1]; |
@@ -427,11 +427,11 @@ discard block |
||
427 | 427 | $unique = $arguments[4]; |
428 | 428 | |
429 | 429 | // Bailout. |
430 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
430 | + if ( ! $this->is_valid_post_type($id)) { |
|
431 | 431 | return $this->check; |
432 | 432 | } |
433 | 433 | |
434 | - return $this->add_meta( $id, $meta_key, $meta_value, $unique ); |
|
434 | + return $this->add_meta($id, $meta_key, $meta_value, $unique); |
|
435 | 435 | |
436 | 436 | case '__get_meta': |
437 | 437 | $this->check = $arguments[0]; |
@@ -440,13 +440,13 @@ discard block |
||
440 | 440 | $single = $arguments[3]; |
441 | 441 | |
442 | 442 | // Bailout. |
443 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
443 | + if ( ! $this->is_valid_post_type($id)) { |
|
444 | 444 | return $this->check; |
445 | 445 | } |
446 | 446 | |
447 | 447 | $this->raw_result = true; |
448 | 448 | |
449 | - return $this->get_meta( $id, $meta_key, $single ); |
|
449 | + return $this->get_meta($id, $meta_key, $single); |
|
450 | 450 | |
451 | 451 | case '__update_meta': |
452 | 452 | $this->check = $arguments[0]; |
@@ -455,11 +455,11 @@ discard block |
||
455 | 455 | $meta_value = $arguments[3]; |
456 | 456 | |
457 | 457 | // Bailout. |
458 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
458 | + if ( ! $this->is_valid_post_type($id)) { |
|
459 | 459 | return $this->check; |
460 | 460 | } |
461 | 461 | |
462 | - return $this->update_meta( $id, $meta_key, $meta_value ); |
|
462 | + return $this->update_meta($id, $meta_key, $meta_value); |
|
463 | 463 | |
464 | 464 | case '__delete_meta': |
465 | 465 | $this->check = $arguments[0]; |
@@ -469,11 +469,11 @@ discard block |
||
469 | 469 | $delete_all = $arguments[3]; |
470 | 470 | |
471 | 471 | // Bailout. |
472 | - if ( ! $this->is_valid_post_type( $id ) ) { |
|
472 | + if ( ! $this->is_valid_post_type($id)) { |
|
473 | 473 | return $this->check; |
474 | 474 | } |
475 | 475 | |
476 | - return $this->delete_meta( $id, $meta_key, $meta_value, $delete_all ); |
|
476 | + return $this->delete_meta($id, $meta_key, $meta_value, $delete_all); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | } |
480 | 480 | \ No newline at end of file |