@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 3 | +if (!class_exists('WP_List_Table')) { |
|
| 4 | 4 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 5 | 5 | } |
| 6 | 6 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * |
| 142 | 142 | * @deprecated 3.0.0 Use `_x()` instead. |
| 143 | 143 | */ |
| 144 | - protected function translate( $text, $context = '' ) { |
|
| 144 | + protected function translate($text, $context = '') { |
|
| 145 | 145 | return $text; |
| 146 | 146 | } |
| 147 | 147 | |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | protected function get_bulk_actions() { |
| 158 | 158 | $actions = array(); |
| 159 | 159 | |
| 160 | - foreach ( $this->bulk_actions as $action => $label ) { |
|
| 161 | - if ( ! is_callable( array( $this, 'bulk_' . $action ) ) ) { |
|
| 162 | - throw new RuntimeException( "The bulk action $action does not have a callback method" ); |
|
| 160 | + foreach ($this->bulk_actions as $action => $label) { |
|
| 161 | + if (!is_callable(array($this, 'bulk_' . $action))) { |
|
| 162 | + throw new RuntimeException("The bulk action $action does not have a callback method"); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $actions[ $action ] = $label; |
|
| 165 | + $actions[$action] = $label; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | return $actions; |
@@ -177,24 +177,24 @@ discard block |
||
| 177 | 177 | global $wpdb; |
| 178 | 178 | // Detect when a bulk action is being triggered. |
| 179 | 179 | $action = $this->current_action(); |
| 180 | - if ( ! $action ) { |
|
| 180 | + if (!$action) { |
|
| 181 | 181 | return; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - check_admin_referer( 'bulk-' . $this->_args['plural'] ); |
|
| 184 | + check_admin_referer('bulk-' . $this->_args['plural']); |
|
| 185 | 185 | |
| 186 | 186 | $method = 'bulk_' . $action; |
| 187 | - if ( array_key_exists( $action, $this->bulk_actions ) && is_callable( array( $this, $method ) ) && ! empty( $_GET['ID'] ) && is_array( $_GET['ID'] ) ) { |
|
| 188 | - $ids_sql = '(' . implode( ',', array_fill( 0, count( $_GET['ID'] ), '%s' ) ) . ')'; |
|
| 189 | - $id = array_map( 'absint', $_GET['ID'] ); |
|
| 190 | - $this->$method( $id, $wpdb->prepare( $ids_sql, $id ) ); //phpcs:ignore WordPress.DB.PreparedSQL |
|
| 187 | + if (array_key_exists($action, $this->bulk_actions) && is_callable(array($this, $method)) && !empty($_GET['ID']) && is_array($_GET['ID'])) { |
|
| 188 | + $ids_sql = '(' . implode(',', array_fill(0, count($_GET['ID']), '%s')) . ')'; |
|
| 189 | + $id = array_map('absint', $_GET['ID']); |
|
| 190 | + $this->$method($id, $wpdb->prepare($ids_sql, $id)); //phpcs:ignore WordPress.DB.PreparedSQL |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if ( isset( $_SERVER['REQUEST_URI'] ) ) { |
|
| 193 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 194 | 194 | wp_safe_redirect( |
| 195 | 195 | remove_query_arg( |
| 196 | - array( '_wp_http_referer', '_wpnonce', 'ID', 'action', 'action2' ), |
|
| 197 | - esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
|
| 196 | + array('_wp_http_referer', '_wpnonce', 'ID', 'action', 'action2'), |
|
| 197 | + esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) |
|
| 198 | 198 | ) |
| 199 | 199 | ); |
| 200 | 200 | exit; |
@@ -209,10 +209,10 @@ discard block |
||
| 209 | 209 | * @param string $ids_sql the sql for the ids. |
| 210 | 210 | * @return void |
| 211 | 211 | */ |
| 212 | - protected function bulk_delete( array $ids, $ids_sql ) { |
|
| 212 | + protected function bulk_delete(array $ids, $ids_sql) { |
|
| 213 | 213 | $store = ActionScheduler::store(); |
| 214 | - foreach ( $ids as $action_id ) { |
|
| 215 | - $store->delete( $action_id ); |
|
| 214 | + foreach ($ids as $action_id) { |
|
| 215 | + $store->delete($action_id); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | protected function prepare_column_headers() { |
| 224 | 224 | $this->_column_headers = array( |
| 225 | 225 | $this->get_columns(), |
| 226 | - get_hidden_columns( $this->screen ), |
|
| 226 | + get_hidden_columns($this->screen), |
|
| 227 | 227 | $this->get_sortable_columns(), |
| 228 | 228 | ); |
| 229 | 229 | } |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | public function get_sortable_columns() { |
| 236 | 236 | $sort_by = array(); |
| 237 | - foreach ( $this->sort_by as $column ) { |
|
| 238 | - $sort_by[ $column ] = array( $column, true ); |
|
| 237 | + foreach ($this->sort_by as $column) { |
|
| 238 | + $sort_by[$column] = array($column, true); |
|
| 239 | 239 | } |
| 240 | 240 | return $sort_by; |
| 241 | 241 | } |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | public function get_columns() { |
| 248 | 248 | $columns = array_merge( |
| 249 | - array( 'cb' => '<input type="checkbox" />' ), |
|
| 249 | + array('cb' => '<input type="checkbox" />'), |
|
| 250 | 250 | $this->columns |
| 251 | 251 | ); |
| 252 | 252 | |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | protected function get_items_query_limit() { |
| 264 | 264 | global $wpdb; |
| 265 | 265 | |
| 266 | - $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); |
|
| 267 | - return $wpdb->prepare( 'LIMIT %d', $per_page ); |
|
| 266 | + $per_page = $this->get_items_per_page($this->get_per_page_option_name(), $this->items_per_page); |
|
| 267 | + return $wpdb->prepare('LIMIT %d', $per_page); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -273,10 +273,10 @@ discard block |
||
| 273 | 273 | * @return int |
| 274 | 274 | */ |
| 275 | 275 | protected function get_items_offset() { |
| 276 | - $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); |
|
| 276 | + $per_page = $this->get_items_per_page($this->get_per_page_option_name(), $this->items_per_page); |
|
| 277 | 277 | $current_page = $this->get_pagenum(); |
| 278 | - if ( 1 < $current_page ) { |
|
| 279 | - $offset = $per_page * ( $current_page - 1 ); |
|
| 278 | + if (1 < $current_page) { |
|
| 279 | + $offset = $per_page * ($current_page - 1); |
|
| 280 | 280 | } else { |
| 281 | 281 | $offset = 0; |
| 282 | 282 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | protected function get_items_query_offset() { |
| 295 | 295 | global $wpdb; |
| 296 | 296 | |
| 297 | - return $wpdb->prepare( 'OFFSET %d', $this->get_items_offset() ); |
|
| 297 | + return $wpdb->prepare('OFFSET %d', $this->get_items_offset()); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -303,12 +303,12 @@ discard block |
||
| 303 | 303 | * column and sortable. It will also use order (ASC|DESC) using DESC by default. |
| 304 | 304 | */ |
| 305 | 305 | protected function get_items_query_order() { |
| 306 | - if ( empty( $this->sort_by ) ) { |
|
| 306 | + if (empty($this->sort_by)) { |
|
| 307 | 307 | return ''; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $orderby = esc_sql( $this->get_request_orderby() ); |
|
| 311 | - $order = esc_sql( $this->get_request_order() ); |
|
| 310 | + $orderby = esc_sql($this->get_request_orderby()); |
|
| 311 | + $order = esc_sql($this->get_request_order()); |
|
| 312 | 312 | |
| 313 | 313 | return "ORDER BY {$orderby} {$order}"; |
| 314 | 314 | } |
@@ -320,10 +320,10 @@ discard block |
||
| 320 | 320 | */ |
| 321 | 321 | protected function get_request_orderby() { |
| 322 | 322 | |
| 323 | - $valid_sortable_columns = array_values( $this->sort_by ); |
|
| 323 | + $valid_sortable_columns = array_values($this->sort_by); |
|
| 324 | 324 | |
| 325 | - if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $valid_sortable_columns, true ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 326 | - $orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 325 | + if (!empty($_GET['orderby']) && in_array($_GET['orderby'], $valid_sortable_columns, true)) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 326 | + $orderby = sanitize_text_field(wp_unslash($_GET['orderby'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 327 | 327 | } else { |
| 328 | 328 | $orderby = $valid_sortable_columns[0]; |
| 329 | 329 | } |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | protected function get_request_order() { |
| 340 | 340 | |
| 341 | - if ( ! empty( $_GET['order'] ) && 'desc' === strtolower( sanitize_text_field( wp_unslash( $_GET['order'] ) ) ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 341 | + if (!empty($_GET['order']) && 'desc' === strtolower(sanitize_text_field(wp_unslash($_GET['order'])))) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 342 | 342 | $order = 'DESC'; |
| 343 | 343 | } else { |
| 344 | 344 | $order = 'ASC'; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | * @return string |
| 354 | 354 | */ |
| 355 | 355 | protected function get_request_status() { |
| 356 | - $status = ( ! empty( $_GET['status'] ) ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 356 | + $status = (!empty($_GET['status'])) ? sanitize_text_field(wp_unslash($_GET['status'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 357 | 357 | return $status; |
| 358 | 358 | } |
| 359 | 359 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * @return string |
| 364 | 364 | */ |
| 365 | 365 | protected function get_request_search_query() { |
| 366 | - $search_query = ( ! empty( $_GET['s'] ) ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 366 | + $search_query = (!empty($_GET['s'])) ? sanitize_text_field(wp_unslash($_GET['s'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 367 | 367 | return $search_query; |
| 368 | 368 | } |
| 369 | 369 | |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | * @return array |
| 375 | 375 | */ |
| 376 | 376 | protected function get_table_columns() { |
| 377 | - $columns = array_keys( $this->columns ); |
|
| 378 | - if ( ! in_array( $this->ID, $columns, true ) ) { |
|
| 377 | + $columns = array_keys($this->columns); |
|
| 378 | + if (!in_array($this->ID, $columns, true)) { |
|
| 379 | 379 | $columns[] = $this->ID; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -394,19 +394,19 @@ discard block |
||
| 394 | 394 | protected function get_items_query_search() { |
| 395 | 395 | global $wpdb; |
| 396 | 396 | |
| 397 | - if ( empty( $_GET['s'] ) || empty( $this->search_by ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 397 | + if (empty($_GET['s']) || empty($this->search_by)) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 398 | 398 | return ''; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - $search_string = sanitize_text_field( wp_unslash( $_GET['s'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 401 | + $search_string = sanitize_text_field(wp_unslash($_GET['s'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 402 | 402 | |
| 403 | 403 | $filter = array(); |
| 404 | - foreach ( $this->search_by as $column ) { |
|
| 404 | + foreach ($this->search_by as $column) { |
|
| 405 | 405 | $wild = '%'; |
| 406 | - $sql_like = $wild . $wpdb->esc_like( $search_string ) . $wild; |
|
| 407 | - $filter[] = $wpdb->prepare( '`' . $column . '` LIKE %s', $sql_like ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.DB.PreparedSQL.NotPrepared |
|
| 406 | + $sql_like = $wild . $wpdb->esc_like($search_string) . $wild; |
|
| 407 | + $filter[] = $wpdb->prepare('`' . $column . '` LIKE %s', $sql_like); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.DB.PreparedSQL.NotPrepared |
|
| 408 | 408 | } |
| 409 | - return implode( ' OR ', $filter ); |
|
| 409 | + return implode(' OR ', $filter); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -416,21 +416,21 @@ discard block |
||
| 416 | 416 | protected function get_items_query_filters() { |
| 417 | 417 | global $wpdb; |
| 418 | 418 | |
| 419 | - if ( ! $this->filter_by || empty( $_GET['filter_by'] ) || ! is_array( $_GET['filter_by'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 419 | + if (!$this->filter_by || empty($_GET['filter_by']) || !is_array($_GET['filter_by'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 420 | 420 | return ''; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $filter = array(); |
| 424 | 424 | |
| 425 | - foreach ( $this->filter_by as $column => $options ) { |
|
| 426 | - if ( empty( $_GET['filter_by'][ $column ] ) || empty( $options[ $_GET['filter_by'][ $column ] ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 425 | + foreach ($this->filter_by as $column => $options) { |
|
| 426 | + if (empty($_GET['filter_by'][$column]) || empty($options[$_GET['filter_by'][$column]])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 427 | 427 | continue; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - $filter[] = $wpdb->prepare( "`$column` = %s", sanitize_text_field( wp_unslash( $_GET['filter_by'][ $column ] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 430 | + $filter[] = $wpdb->prepare("`$column` = %s", sanitize_text_field(wp_unslash($_GET['filter_by'][$column]))); //phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - return implode( ' AND ', $filter ); |
|
| 433 | + return implode(' AND ', $filter); |
|
| 434 | 434 | |
| 435 | 435 | } |
| 436 | 436 | |
@@ -450,9 +450,9 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | $this->process_row_actions(); |
| 452 | 452 | |
| 453 | - if ( ! empty( $_REQUEST['_wp_http_referer'] && ! empty( $_SERVER['REQUEST_URI'] ) ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 453 | + if (!empty($_REQUEST['_wp_http_referer'] && !empty($_SERVER['REQUEST_URI']))) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 454 | 454 | // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter |
| 455 | - wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); |
|
| 455 | + wp_safe_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])))); |
|
| 456 | 456 | exit; |
| 457 | 457 | } |
| 458 | 458 | |
@@ -467,26 +467,26 @@ discard block |
||
| 467 | 467 | $this->get_items_query_filters(), |
| 468 | 468 | ) |
| 469 | 469 | ); |
| 470 | - $columns = '`' . implode( '`, `', $this->get_table_columns() ) . '`'; |
|
| 470 | + $columns = '`' . implode('`, `', $this->get_table_columns()) . '`'; |
|
| 471 | 471 | |
| 472 | - if ( ! empty( $where ) ) { |
|
| 473 | - $where = 'WHERE (' . implode( ') AND (', $where ) . ')'; |
|
| 472 | + if (!empty($where)) { |
|
| 473 | + $where = 'WHERE (' . implode(') AND (', $where) . ')'; |
|
| 474 | 474 | } else { |
| 475 | 475 | $where = ''; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | $sql = "SELECT $columns FROM {$this->table_name} {$where} {$order} {$limit} {$offset}"; |
| 479 | 479 | |
| 480 | - $this->set_items( $wpdb->get_results( $sql, ARRAY_A ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 480 | + $this->set_items($wpdb->get_results($sql, ARRAY_A)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 481 | 481 | |
| 482 | 482 | $query_count = "SELECT COUNT({$this->ID}) FROM {$this->table_name} {$where}"; |
| 483 | - $total_items = $wpdb->get_var( $query_count ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 484 | - $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); |
|
| 483 | + $total_items = $wpdb->get_var($query_count); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 484 | + $per_page = $this->get_items_per_page($this->get_per_page_option_name(), $this->items_per_page); |
|
| 485 | 485 | $this->set_pagination_args( |
| 486 | 486 | array( |
| 487 | 487 | 'total_items' => $total_items, |
| 488 | 488 | 'per_page' => $per_page, |
| 489 | - 'total_pages' => ceil( $total_items / $per_page ), |
|
| 489 | + 'total_pages' => ceil($total_items / $per_page), |
|
| 490 | 490 | ) |
| 491 | 491 | ); |
| 492 | 492 | } |
@@ -496,31 +496,31 @@ discard block |
||
| 496 | 496 | * |
| 497 | 497 | * @param string $which The name of the table. |
| 498 | 498 | */ |
| 499 | - public function extra_tablenav( $which ) { |
|
| 500 | - if ( ! $this->filter_by || 'top' !== $which ) { |
|
| 499 | + public function extra_tablenav($which) { |
|
| 500 | + if (!$this->filter_by || 'top' !== $which) { |
|
| 501 | 501 | return; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | echo '<div class="alignleft actions">'; |
| 505 | 505 | |
| 506 | - foreach ( $this->filter_by as $id => $options ) { |
|
| 507 | - $default = ! empty( $_GET['filter_by'][ $id ] ) ? sanitize_text_field( wp_unslash( $_GET['filter_by'][ $id ] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 508 | - if ( empty( $options[ $default ] ) ) { |
|
| 506 | + foreach ($this->filter_by as $id => $options) { |
|
| 507 | + $default = !empty($_GET['filter_by'][$id]) ? sanitize_text_field(wp_unslash($_GET['filter_by'][$id])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 508 | + if (empty($options[$default])) { |
|
| 509 | 509 | $default = ''; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - echo '<select name="filter_by[' . esc_attr( $id ) . ']" class="first" id="filter-by-' . esc_attr( $id ) . '">'; |
|
| 512 | + echo '<select name="filter_by[' . esc_attr($id) . ']" class="first" id="filter-by-' . esc_attr($id) . '">'; |
|
| 513 | 513 | |
| 514 | - foreach ( $options as $value => $label ) { |
|
| 515 | - echo '<option value="' . esc_attr( $value ) . '" ' . esc_html( $value === $default ? 'selected' : '' ) . '>' |
|
| 516 | - . esc_html( $label ) |
|
| 514 | + foreach ($options as $value => $label) { |
|
| 515 | + echo '<option value="' . esc_attr($value) . '" ' . esc_html($value === $default ? 'selected' : '') . '>' |
|
| 516 | + . esc_html($label) |
|
| 517 | 517 | . '</option>'; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | echo '</select>'; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - submit_button( esc_html__( 'Filter', 'woocommerce' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
|
| 523 | + submit_button(esc_html__('Filter', 'woocommerce'), '', 'filter_action', false, array('id' => 'post-query-submit')); |
|
| 524 | 524 | echo '</div>'; |
| 525 | 525 | } |
| 526 | 526 | |
@@ -530,10 +530,10 @@ discard block |
||
| 530 | 530 | * |
| 531 | 531 | * @param array $items Items array. |
| 532 | 532 | */ |
| 533 | - protected function set_items( array $items ) { |
|
| 533 | + protected function set_items(array $items) { |
|
| 534 | 534 | $this->items = array(); |
| 535 | - foreach ( $items as $item ) { |
|
| 536 | - $this->items[ $item[ $this->ID ] ] = array_map( 'maybe_unserialize', $item ); |
|
| 535 | + foreach ($items as $item) { |
|
| 536 | + $this->items[$item[$this->ID]] = array_map('maybe_unserialize', $item); |
|
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | 539 | |
@@ -544,8 +544,8 @@ discard block |
||
| 544 | 544 | * |
| 545 | 545 | * @param array $row The row to render. |
| 546 | 546 | */ |
| 547 | - public function column_cb( $row ) { |
|
| 548 | - return '<input name="ID[]" type="checkbox" value="' . esc_attr( $row[ $this->ID ] ) . '" />'; |
|
| 547 | + public function column_cb($row) { |
|
| 548 | + return '<input name="ID[]" type="checkbox" value="' . esc_attr($row[$this->ID]) . '" />'; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -558,36 +558,36 @@ discard block |
||
| 558 | 558 | * @param string $column_name Column name. |
| 559 | 559 | * @return string |
| 560 | 560 | */ |
| 561 | - protected function maybe_render_actions( $row, $column_name ) { |
|
| 562 | - if ( empty( $this->row_actions[ $column_name ] ) ) { |
|
| 561 | + protected function maybe_render_actions($row, $column_name) { |
|
| 562 | + if (empty($this->row_actions[$column_name])) { |
|
| 563 | 563 | return; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - $row_id = $row[ $this->ID ]; |
|
| 566 | + $row_id = $row[$this->ID]; |
|
| 567 | 567 | |
| 568 | 568 | $actions = '<div class="row-actions">'; |
| 569 | 569 | $action_count = 0; |
| 570 | - foreach ( $this->row_actions[ $column_name ] as $action_key => $action ) { |
|
| 570 | + foreach ($this->row_actions[$column_name] as $action_key => $action) { |
|
| 571 | 571 | |
| 572 | 572 | $action_count++; |
| 573 | 573 | |
| 574 | - if ( ! method_exists( $this, 'row_action_' . $action_key ) ) { |
|
| 574 | + if (!method_exists($this, 'row_action_' . $action_key)) { |
|
| 575 | 575 | continue; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - $action_link = ! empty( $action['link'] ) ? $action['link'] : add_query_arg( |
|
| 578 | + $action_link = !empty($action['link']) ? $action['link'] : add_query_arg( |
|
| 579 | 579 | array( |
| 580 | 580 | 'row_action' => $action_key, |
| 581 | 581 | 'row_id' => $row_id, |
| 582 | - 'nonce' => wp_create_nonce( $action_key . '::' . $row_id ), |
|
| 582 | + 'nonce' => wp_create_nonce($action_key . '::' . $row_id), |
|
| 583 | 583 | ) |
| 584 | 584 | ); |
| 585 | - $span_class = ! empty( $action['class'] ) ? $action['class'] : $action_key; |
|
| 586 | - $separator = ( $action_count < count( $this->row_actions[ $column_name ] ) ) ? ' | ' : ''; |
|
| 585 | + $span_class = !empty($action['class']) ? $action['class'] : $action_key; |
|
| 586 | + $separator = ($action_count < count($this->row_actions[$column_name])) ? ' | ' : ''; |
|
| 587 | 587 | |
| 588 | - $actions .= sprintf( '<span class="%s">', esc_attr( $span_class ) ); |
|
| 589 | - $actions .= sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', esc_url( $action_link ), esc_attr( $action['desc'] ), esc_html( $action['name'] ) ); |
|
| 590 | - $actions .= sprintf( '%s</span>', $separator ); |
|
| 588 | + $actions .= sprintf('<span class="%s">', esc_attr($span_class)); |
|
| 589 | + $actions .= sprintf('<a href="%1$s" title="%2$s">%3$s</a>', esc_url($action_link), esc_attr($action['desc']), esc_html($action['name'])); |
|
| 590 | + $actions .= sprintf('%s</span>', $separator); |
|
| 591 | 591 | } |
| 592 | 592 | $actions .= '</div>'; |
| 593 | 593 | return $actions; |
@@ -599,27 +599,27 @@ discard block |
||
| 599 | 599 | * @return void |
| 600 | 600 | */ |
| 601 | 601 | protected function process_row_actions() { |
| 602 | - $parameters = array( 'row_action', 'row_id', 'nonce' ); |
|
| 603 | - foreach ( $parameters as $parameter ) { |
|
| 604 | - if ( empty( $_REQUEST[ $parameter ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 602 | + $parameters = array('row_action', 'row_id', 'nonce'); |
|
| 603 | + foreach ($parameters as $parameter) { |
|
| 604 | + if (empty($_REQUEST[$parameter])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 605 | 605 | return; |
| 606 | 606 | } |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - $action = sanitize_text_field( wp_unslash( $_REQUEST['row_action'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
|
| 610 | - $row_id = sanitize_text_field( wp_unslash( $_REQUEST['row_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
|
| 611 | - $nonce = sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
|
| 609 | + $action = sanitize_text_field(wp_unslash($_REQUEST['row_action'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
|
| 610 | + $row_id = sanitize_text_field(wp_unslash($_REQUEST['row_id'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
|
| 611 | + $nonce = sanitize_text_field(wp_unslash($_REQUEST['nonce'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
|
| 612 | 612 | $method = 'row_action_' . $action; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 613 | 613 | |
| 614 | - if ( wp_verify_nonce( $nonce, $action . '::' . $row_id ) && method_exists( $this, $method ) ) { |
|
| 615 | - $this->$method( sanitize_text_field( wp_unslash( $row_id ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 614 | + if (wp_verify_nonce($nonce, $action . '::' . $row_id) && method_exists($this, $method)) { |
|
| 615 | + $this->$method(sanitize_text_field(wp_unslash($row_id))); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if ( isset( $_SERVER['REQUEST_URI'] ) ) { |
|
| 618 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 619 | 619 | wp_safe_redirect( |
| 620 | 620 | remove_query_arg( |
| 621 | - array( 'row_id', 'row_action', 'nonce' ), |
|
| 622 | - esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
|
| 621 | + array('row_id', 'row_action', 'nonce'), |
|
| 622 | + esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) |
|
| 623 | 623 | ) |
| 624 | 624 | ); |
| 625 | 625 | exit; |
@@ -634,9 +634,9 @@ discard block |
||
| 634 | 634 | * |
| 635 | 635 | * @return string |
| 636 | 636 | */ |
| 637 | - public function column_default( $item, $column_name ) { |
|
| 638 | - $column_html = esc_html( $item[ $column_name ] ); |
|
| 639 | - $column_html .= $this->maybe_render_actions( $item, $column_name ); |
|
| 637 | + public function column_default($item, $column_name) { |
|
| 638 | + $column_html = esc_html($item[$column_name]); |
|
| 639 | + $column_html .= $this->maybe_render_actions($item, $column_name); |
|
| 640 | 640 | return $column_html; |
| 641 | 641 | } |
| 642 | 642 | |
@@ -644,10 +644,10 @@ discard block |
||
| 644 | 644 | * Display the table heading and search query, if any |
| 645 | 645 | */ |
| 646 | 646 | protected function display_header() { |
| 647 | - echo '<h1 class="wp-heading-inline">' . esc_attr( $this->table_header ) . '</h1>'; |
|
| 648 | - if ( $this->get_request_search_query() ) { |
|
| 647 | + echo '<h1 class="wp-heading-inline">' . esc_attr($this->table_header) . '</h1>'; |
|
| 648 | + if ($this->get_request_search_query()) { |
|
| 649 | 649 | /* translators: %s: search query */ |
| 650 | - echo '<span class="subtitle">' . esc_attr( sprintf( __( 'Search results for "%s"', 'woocommerce' ), $this->get_request_search_query() ) ) . '</span>'; |
|
| 650 | + echo '<span class="subtitle">' . esc_attr(sprintf(__('Search results for "%s"', 'woocommerce'), $this->get_request_search_query())) . '</span>'; |
|
| 651 | 651 | } |
| 652 | 652 | echo '<hr class="wp-header-end">'; |
| 653 | 653 | } |
@@ -656,9 +656,9 @@ discard block |
||
| 656 | 656 | * Display the table heading and search query, if any |
| 657 | 657 | */ |
| 658 | 658 | protected function display_admin_notices() { |
| 659 | - foreach ( $this->admin_notices as $notice ) { |
|
| 660 | - echo '<div id="message" class="' . esc_attr( $notice['class'] ) . '">'; |
|
| 661 | - echo ' <p>' . wp_kses_post( $notice['message'] ) . '</p>'; |
|
| 659 | + foreach ($this->admin_notices as $notice) { |
|
| 660 | + echo '<div id="message" class="' . esc_attr($notice['class']) . '">'; |
|
| 661 | + echo ' <p>' . wp_kses_post($notice['message']) . '</p>'; |
|
| 662 | 662 | echo '</div>'; |
| 663 | 663 | } |
| 664 | 664 | } |
@@ -672,30 +672,30 @@ discard block |
||
| 672 | 672 | $request_status = $this->get_request_status(); |
| 673 | 673 | |
| 674 | 674 | // Helper to set 'all' filter when not set on status counts passed in. |
| 675 | - if ( ! isset( $this->status_counts['all'] ) ) { |
|
| 676 | - $this->status_counts = array( 'all' => array_sum( $this->status_counts ) ) + $this->status_counts; |
|
| 675 | + if (!isset($this->status_counts['all'])) { |
|
| 676 | + $this->status_counts = array('all' => array_sum($this->status_counts)) + $this->status_counts; |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - foreach ( $this->status_counts as $status_name => $count ) { |
|
| 679 | + foreach ($this->status_counts as $status_name => $count) { |
|
| 680 | 680 | |
| 681 | - if ( 0 === $count ) { |
|
| 681 | + if (0 === $count) { |
|
| 682 | 682 | continue; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if ( $status_name === $request_status || ( empty( $request_status ) && 'all' === $status_name ) ) { |
|
| 685 | + if ($status_name === $request_status || (empty($request_status) && 'all' === $status_name)) { |
|
| 686 | 686 | $status_list_item = '<li class="%1$s"><strong>%3$s</strong> (%4$d)</li>'; |
| 687 | 687 | } else { |
| 688 | 688 | $status_list_item = '<li class="%1$s"><a href="%2$s">%3$s</a> (%4$d)</li>'; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - $status_filter_url = ( 'all' === $status_name ) ? remove_query_arg( 'status' ) : add_query_arg( 'status', $status_name ); |
|
| 692 | - $status_filter_url = remove_query_arg( array( 'paged', 's' ), $status_filter_url ); |
|
| 693 | - $status_list_items[] = sprintf( $status_list_item, esc_attr( $status_name ), esc_url( $status_filter_url ), esc_html( ucfirst( $status_name ) ), absint( $count ) ); |
|
| 691 | + $status_filter_url = ('all' === $status_name) ? remove_query_arg('status') : add_query_arg('status', $status_name); |
|
| 692 | + $status_filter_url = remove_query_arg(array('paged', 's'), $status_filter_url); |
|
| 693 | + $status_list_items[] = sprintf($status_list_item, esc_attr($status_name), esc_url($status_filter_url), esc_html(ucfirst($status_name)), absint($count)); |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | - if ( $status_list_items ) { |
|
| 696 | + if ($status_list_items) { |
|
| 697 | 697 | echo '<ul class="subsubsub">'; |
| 698 | - echo implode( " | \n", $status_list_items ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 698 | + echo implode(" | \n", $status_list_items); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 699 | 699 | echo '</ul>'; |
| 700 | 700 | } |
| 701 | 701 | } |
@@ -706,15 +706,15 @@ discard block |
||
| 706 | 706 | * forget about any extra HTML. |
| 707 | 707 | */ |
| 708 | 708 | protected function display_table() { |
| 709 | - echo '<form id="' . esc_attr( $this->_args['plural'] ) . '-filter" method="get">'; |
|
| 710 | - foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 711 | - if ( '_' === $key[0] || 'paged' === $key || 'ID' === $key ) { |
|
| 709 | + echo '<form id="' . esc_attr($this->_args['plural']) . '-filter" method="get">'; |
|
| 710 | + foreach ($_GET as $key => $value) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 711 | + if ('_' === $key[0] || 'paged' === $key || 'ID' === $key) { |
|
| 712 | 712 | continue; |
| 713 | 713 | } |
| 714 | - echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" />'; |
|
| 714 | + echo '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />'; |
|
| 715 | 715 | } |
| 716 | - if ( ! empty( $this->search_by ) ) { |
|
| 717 | - echo $this->search_box( $this->get_search_box_button_text(), 'plugin' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 716 | + if (!empty($this->search_by)) { |
|
| 717 | + echo $this->search_box($this->get_search_box_button_text(), 'plugin'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 718 | 718 | } |
| 719 | 719 | parent::display(); |
| 720 | 720 | echo '</form>'; |
@@ -727,9 +727,9 @@ discard block |
||
| 727 | 727 | $this->process_bulk_action(); |
| 728 | 728 | $this->process_row_actions(); |
| 729 | 729 | |
| 730 | - if ( ! empty( $_REQUEST['_wp_http_referer'] ) && ! empty( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 730 | + if (!empty($_REQUEST['_wp_http_referer']) && !empty($_SERVER['REQUEST_URI'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 731 | 731 | // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter |
| 732 | - wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); |
|
| 732 | + wp_safe_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])))); |
|
| 733 | 733 | exit; |
| 734 | 734 | } |
| 735 | 735 | } |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | * Get the text to display in the search box on the list table. |
| 753 | 753 | */ |
| 754 | 754 | protected function get_search_box_placeholder() { |
| 755 | - return esc_html__( 'Search', 'woocommerce' ); |
|
| 755 | + return esc_html__('Search', 'woocommerce'); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | /** |
@@ -40,27 +40,27 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - public function register_tables( $force_update = false ) { |
|
| 43 | + public function register_tables($force_update = false) { |
|
| 44 | 44 | global $wpdb; |
| 45 | 45 | |
| 46 | 46 | // make WP aware of our tables |
| 47 | - foreach ( $this->tables as $table ) { |
|
| 47 | + foreach ($this->tables as $table) { |
|
| 48 | 48 | $wpdb->tables[] = $table; |
| 49 | - $name = $this->get_full_table_name( $table ); |
|
| 49 | + $name = $this->get_full_table_name($table); |
|
| 50 | 50 | $wpdb->$table = $name; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // create the tables |
| 54 | - if ( $this->schema_update_required() || $force_update ) { |
|
| 55 | - foreach ( $this->tables as $table ) { |
|
| 54 | + if ($this->schema_update_required() || $force_update) { |
|
| 55 | + foreach ($this->tables as $table) { |
|
| 56 | 56 | /** |
| 57 | 57 | * Allow custom processing before updating a table schema. |
| 58 | 58 | * |
| 59 | 59 | * @param string $table Name of table being updated. |
| 60 | 60 | * @param string $db_version Existing version of the table being updated. |
| 61 | 61 | */ |
| 62 | - do_action( 'action_scheduler_before_schema_update', $table, $this->db_version ); |
|
| 63 | - $this->update_table( $table ); |
|
| 62 | + do_action('action_scheduler_before_schema_update', $table, $this->db_version); |
|
| 63 | + $this->update_table($table); |
|
| 64 | 64 | } |
| 65 | 65 | $this->mark_schema_update_complete(); |
| 66 | 66 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return string The CREATE TABLE statement, suitable for passing to dbDelta |
| 73 | 73 | */ |
| 74 | - abstract protected function get_table_definition( $table ); |
|
| 74 | + abstract protected function get_table_definition($table); |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Determine if the database schema is out of date |
@@ -82,14 +82,14 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | private function schema_update_required() { |
| 84 | 84 | $option_name = 'schema-' . static::class; |
| 85 | - $this->db_version = get_option( $option_name, 0 ); |
|
| 85 | + $this->db_version = get_option($option_name, 0); |
|
| 86 | 86 | |
| 87 | 87 | // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema |
| 88 | - if ( 0 === $this->db_version ) { |
|
| 88 | + if (0 === $this->db_version) { |
|
| 89 | 89 | |
| 90 | 90 | $plugin_option_name = 'schema-'; |
| 91 | 91 | |
| 92 | - switch ( static::class ) { |
|
| 92 | + switch (static::class) { |
|
| 93 | 93 | case 'ActionScheduler_StoreSchema' : |
| 94 | 94 | $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker'; |
| 95 | 95 | break; |
@@ -98,12 +98,12 @@ discard block |
||
| 98 | 98 | break; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $this->db_version = get_option( $plugin_option_name, 0 ); |
|
| 101 | + $this->db_version = get_option($plugin_option_name, 0); |
|
| 102 | 102 | |
| 103 | - delete_option( $plugin_option_name ); |
|
| 103 | + delete_option($plugin_option_name); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - return version_compare( $this->db_version, $this->schema_version, '<' ); |
|
| 106 | + return version_compare($this->db_version, $this->schema_version, '<'); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | // work around race conditions and ensure that our option updates |
| 119 | 119 | $value_to_save = (string) $this->schema_version . '.0.' . time(); |
| 120 | 120 | |
| 121 | - update_option( $option_name, $value_to_save ); |
|
| 121 | + update_option($option_name, $value_to_save); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -128,14 +128,14 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @return void |
| 130 | 130 | */ |
| 131 | - private function update_table( $table ) { |
|
| 132 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 133 | - $definition = $this->get_table_definition( $table ); |
|
| 134 | - if ( $definition ) { |
|
| 135 | - $updated = dbDelta( $definition ); |
|
| 136 | - foreach ( $updated as $updated_table => $update_description ) { |
|
| 137 | - if ( strpos( $update_description, 'Created table' ) === 0 ) { |
|
| 138 | - do_action( 'action_scheduler/created_table', $updated_table, $table ); |
|
| 131 | + private function update_table($table) { |
|
| 132 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 133 | + $definition = $this->get_table_definition($table); |
|
| 134 | + if ($definition) { |
|
| 135 | + $updated = dbDelta($definition); |
|
| 136 | + foreach ($updated as $updated_table => $update_description) { |
|
| 137 | + if (strpos($update_description, 'Created table') === 0) { |
|
| 138 | + do_action('action_scheduler/created_table', $updated_table, $table); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * @return string The full name of the table, including the |
| 148 | 148 | * table prefix for the current blog |
| 149 | 149 | */ |
| 150 | - protected function get_full_table_name( $table ) { |
|
| 151 | - return $GLOBALS[ 'wpdb' ]->prefix . $table; |
|
| 150 | + protected function get_full_table_name($table) { |
|
| 151 | + return $GLOBALS['wpdb']->prefix . $table; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | public function tables_exist() { |
| 160 | 160 | global $wpdb; |
| 161 | 161 | |
| 162 | - $existing_tables = $wpdb->get_col( 'SHOW TABLES' ); |
|
| 162 | + $existing_tables = $wpdb->get_col('SHOW TABLES'); |
|
| 163 | 163 | $expected_tables = array_map( |
| 164 | - function ( $table_name ) use ( $wpdb ) { |
|
| 164 | + function($table_name) use ($wpdb) { |
|
| 165 | 165 | return $wpdb->prefix . $table_name; |
| 166 | 166 | }, |
| 167 | 167 | $this->tables |
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | - return count( array_intersect( $existing_tables, $expected_tables ) ) === count( $expected_tables ); |
|
| 170 | + return count(array_intersect($existing_tables, $expected_tables)) === count($expected_tables); |
|
| 171 | 171 | } |
| 172 | 172 | } |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | * @param mixed $recurrence The data used to determine the schedule's recurrance. |
| 40 | 40 | * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance. |
| 41 | 41 | */ |
| 42 | - public function __construct( DateTime $date, $recurrence, DateTime $first = null ) { |
|
| 43 | - parent::__construct( $date ); |
|
| 44 | - $this->first_date = empty( $first ) ? $date : $first; |
|
| 42 | + public function __construct(DateTime $date, $recurrence, DateTime $first = null) { |
|
| 43 | + parent::__construct($date); |
|
| 44 | + $this->first_date = empty($first) ? $date : $first; |
|
| 45 | 45 | $this->recurrence = $recurrence; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -75,10 +75,10 @@ discard block |
||
| 75 | 75 | public function __sleep() { |
| 76 | 76 | $sleep_params = parent::__sleep(); |
| 77 | 77 | $this->first_timestamp = $this->first_date->getTimestamp(); |
| 78 | - return array_merge( $sleep_params, array( |
|
| 78 | + return array_merge($sleep_params, array( |
|
| 79 | 79 | 'first_timestamp', |
| 80 | 80 | 'recurrence' |
| 81 | - ) ); |
|
| 81 | + )); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function __wakeup() { |
| 95 | 95 | parent::__wakeup(); |
| 96 | - if ( $this->first_timestamp > 0 ) { |
|
| 97 | - $this->first_date = as_get_datetime_object( $this->first_timestamp ); |
|
| 96 | + if ($this->first_timestamp > 0) { |
|
| 97 | + $this->first_date = as_get_datetime_object($this->first_timestamp); |
|
| 98 | 98 | } else { |
| 99 | 99 | $this->first_date = $this->get_date(); |
| 100 | 100 | } |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | * @param string $lock_type A string to identify different lock types. |
| 20 | 20 | * @return bool |
| 21 | 21 | */ |
| 22 | - public function is_locked( $lock_type ) { |
|
| 23 | - return ( $this->get_expiration( $lock_type ) >= time() ); |
|
| 22 | + public function is_locked($lock_type) { |
|
| 23 | + return ($this->get_expiration($lock_type) >= time()); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string $lock_type A string to identify different lock types. |
| 30 | 30 | * @return bool |
| 31 | 31 | */ |
| 32 | - abstract public function set( $lock_type ); |
|
| 32 | + abstract public function set($lock_type); |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * If a lock is set, return the timestamp it was set to expiry. |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param string $lock_type A string to identify different lock types. |
| 38 | 38 | * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
| 39 | 39 | */ |
| 40 | - abstract public function get_expiration( $lock_type ); |
|
| 40 | + abstract public function get_expiration($lock_type); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Get the amount of time to set for a given lock. 60 seconds by default. |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | * @param string $lock_type A string to identify different lock types. |
| 46 | 46 | * @return int |
| 47 | 47 | */ |
| 48 | - protected function get_duration( $lock_type ) { |
|
| 49 | - return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type ); |
|
| 48 | + protected function get_duration($lock_type) { |
|
| 49 | + return apply_filters('action_scheduler_lock_duration', self::$lock_duration, $lock_type); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @return ActionScheduler_Lock |
| 54 | 54 | */ |
| 55 | 55 | public static function instance() { |
| 56 | - if ( empty( self::$locker ) ) { |
|
| 57 | - $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' ); |
|
| 56 | + if (empty(self::$locker)) { |
|
| 57 | + $class = apply_filters('action_scheduler_lock_class', 'ActionScheduler_OptionLock'); |
|
| 58 | 58 | self::$locker = new $class(); |
| 59 | 59 | } |
| 60 | 60 | return self::$locker; |
@@ -15,17 +15,17 @@ discard block |
||
| 15 | 15 | * @param DateTime $date |
| 16 | 16 | * @return ActionScheduler_DateTime |
| 17 | 17 | */ |
| 18 | - public static function set_local_timezone( DateTime $date ) { |
|
| 18 | + public static function set_local_timezone(DateTime $date) { |
|
| 19 | 19 | |
| 20 | 20 | // Accept a DateTime for easier backward compatibility, even though we require methods on ActionScheduler_DateTime |
| 21 | - if ( ! is_a( $date, 'ActionScheduler_DateTime' ) ) { |
|
| 22 | - $date = as_get_datetime_object( $date->format( 'U' ) ); |
|
| 21 | + if (!is_a($date, 'ActionScheduler_DateTime')) { |
|
| 22 | + $date = as_get_datetime_object($date->format('U')); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - if ( get_option( 'timezone_string' ) ) { |
|
| 26 | - $date->setTimezone( new DateTimeZone( self::get_local_timezone_string() ) ); |
|
| 25 | + if (get_option('timezone_string')) { |
|
| 26 | + $date->setTimezone(new DateTimeZone(self::get_local_timezone_string())); |
|
| 27 | 27 | } else { |
| 28 | - $date->setUtcOffset( self::get_local_timezone_offset() ); |
|
| 28 | + $date->setUtcOffset(self::get_local_timezone_offset()); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | return $date; |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | * @since 2.1.0 |
| 45 | 45 | * @return string PHP timezone string for the site or empty if no timezone string is available. |
| 46 | 46 | */ |
| 47 | - protected static function get_local_timezone_string( $reset = false ) { |
|
| 47 | + protected static function get_local_timezone_string($reset = false) { |
|
| 48 | 48 | // If site timezone string exists, return it. |
| 49 | - $timezone = get_option( 'timezone_string' ); |
|
| 50 | - if ( $timezone ) { |
|
| 49 | + $timezone = get_option('timezone_string'); |
|
| 50 | + if ($timezone) { |
|
| 51 | 51 | return $timezone; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // Get UTC offset, if it isn't set then return UTC. |
| 55 | - $utc_offset = intval( get_option( 'gmt_offset', 0 ) ); |
|
| 56 | - if ( 0 === $utc_offset ) { |
|
| 55 | + $utc_offset = intval(get_option('gmt_offset', 0)); |
|
| 56 | + if (0 === $utc_offset) { |
|
| 57 | 57 | return 'UTC'; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -61,15 +61,15 @@ discard block |
||
| 61 | 61 | $utc_offset *= 3600; |
| 62 | 62 | |
| 63 | 63 | // Attempt to guess the timezone string from the UTC offset. |
| 64 | - $timezone = timezone_name_from_abbr( '', $utc_offset ); |
|
| 65 | - if ( $timezone ) { |
|
| 64 | + $timezone = timezone_name_from_abbr('', $utc_offset); |
|
| 65 | + if ($timezone) { |
|
| 66 | 66 | return $timezone; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // Last try, guess timezone string manually. |
| 70 | - foreach ( timezone_abbreviations_list() as $abbr ) { |
|
| 71 | - foreach ( $abbr as $city ) { |
|
| 72 | - if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) { |
|
| 70 | + foreach (timezone_abbreviations_list() as $abbr) { |
|
| 71 | + foreach ($abbr as $city) { |
|
| 72 | + if ((bool) date('I') === (bool) $city['dst'] && $city['timezone_id'] && intval($city['offset']) === $utc_offset) { |
|
| 73 | 73 | return $city['timezone_id']; |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -86,48 +86,48 @@ discard block |
||
| 86 | 86 | * @return float |
| 87 | 87 | */ |
| 88 | 88 | protected static function get_local_timezone_offset() { |
| 89 | - $timezone = get_option( 'timezone_string' ); |
|
| 89 | + $timezone = get_option('timezone_string'); |
|
| 90 | 90 | |
| 91 | - if ( $timezone ) { |
|
| 92 | - $timezone_object = new DateTimeZone( $timezone ); |
|
| 93 | - return $timezone_object->getOffset( new DateTime( 'now' ) ); |
|
| 91 | + if ($timezone) { |
|
| 92 | + $timezone_object = new DateTimeZone($timezone); |
|
| 93 | + return $timezone_object->getOffset(new DateTime('now')); |
|
| 94 | 94 | } else { |
| 95 | - return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS; |
|
| 95 | + return floatval(get_option('gmt_offset', 0)) * HOUR_IN_SECONDS; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @deprecated 2.1.0 |
| 101 | 101 | */ |
| 102 | - public static function get_local_timezone( $reset = FALSE ) { |
|
| 103 | - _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
| 104 | - if ( $reset ) { |
|
| 102 | + public static function get_local_timezone($reset = FALSE) { |
|
| 103 | + _deprecated_function(__FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()'); |
|
| 104 | + if ($reset) { |
|
| 105 | 105 | self::$local_timezone = NULL; |
| 106 | 106 | } |
| 107 | - if ( !isset(self::$local_timezone) ) { |
|
| 107 | + if (!isset(self::$local_timezone)) { |
|
| 108 | 108 | $tzstring = get_option('timezone_string'); |
| 109 | 109 | |
| 110 | - if ( empty($tzstring) ) { |
|
| 110 | + if (empty($tzstring)) { |
|
| 111 | 111 | $gmt_offset = get_option('gmt_offset'); |
| 112 | - if ( $gmt_offset == 0 ) { |
|
| 112 | + if ($gmt_offset == 0) { |
|
| 113 | 113 | $tzstring = 'UTC'; |
| 114 | 114 | } else { |
| 115 | 115 | $gmt_offset *= HOUR_IN_SECONDS; |
| 116 | - $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 ); |
|
| 116 | + $tzstring = timezone_name_from_abbr('', $gmt_offset, 1); |
|
| 117 | 117 | |
| 118 | 118 | // If there's no timezone string, try again with no DST. |
| 119 | - if ( false === $tzstring ) { |
|
| 120 | - $tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 ); |
|
| 119 | + if (false === $tzstring) { |
|
| 120 | + $tzstring = timezone_name_from_abbr('', $gmt_offset, 0); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // Try mapping to the first abbreviation we can find. |
| 124 | - if ( false === $tzstring ) { |
|
| 125 | - $is_dst = date( 'I' ); |
|
| 126 | - foreach ( timezone_abbreviations_list() as $abbr ) { |
|
| 127 | - foreach ( $abbr as $city ) { |
|
| 128 | - if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) { |
|
| 124 | + if (false === $tzstring) { |
|
| 125 | + $is_dst = date('I'); |
|
| 126 | + foreach (timezone_abbreviations_list() as $abbr) { |
|
| 127 | + foreach ($abbr as $city) { |
|
| 128 | + if ($city['dst'] == $is_dst && $city['offset'] == $gmt_offset) { |
|
| 129 | 129 | // If there's no valid timezone ID, keep looking. |
| 130 | - if ( null === $city['timezone_id'] ) { |
|
| 130 | + if (null === $city['timezone_id']) { |
|
| 131 | 131 | continue; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // If we still have no valid string, then fall back to UTC. |
| 142 | - if ( false === $tzstring ) { |
|
| 142 | + if (false === $tzstring) { |
|
| 143 | 143 | $tzstring = 'UTC'; |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | * @param ActionScheduler_FatalErrorMonitor $monitor |
| 32 | 32 | * @param ActionScheduler_QueueCleaner $cleaner |
| 33 | 33 | */ |
| 34 | - public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) { |
|
| 34 | + public function __construct(ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null) { |
|
| 35 | 35 | |
| 36 | - $this->created_time = microtime( true ); |
|
| 36 | + $this->created_time = microtime(true); |
|
| 37 | 37 | |
| 38 | 38 | $this->store = $store ? $store : ActionScheduler_Store::instance(); |
| 39 | - $this->monitor = $monitor ? $monitor : new ActionScheduler_FatalErrorMonitor( $this->store ); |
|
| 40 | - $this->cleaner = $cleaner ? $cleaner : new ActionScheduler_QueueCleaner( $this->store ); |
|
| 39 | + $this->monitor = $monitor ? $monitor : new ActionScheduler_FatalErrorMonitor($this->store); |
|
| 40 | + $this->cleaner = $cleaner ? $cleaner : new ActionScheduler_QueueCleaner($this->store); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -47,35 +47,35 @@ discard block |
||
| 47 | 47 | * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' |
| 48 | 48 | * Generally, this should be capitalised and not localised as it's a proper noun. |
| 49 | 49 | */ |
| 50 | - public function process_action( $action_id, $context = '' ) { |
|
| 50 | + public function process_action($action_id, $context = '') { |
|
| 51 | 51 | try { |
| 52 | 52 | $valid_action = false; |
| 53 | - do_action( 'action_scheduler_before_execute', $action_id, $context ); |
|
| 53 | + do_action('action_scheduler_before_execute', $action_id, $context); |
|
| 54 | 54 | |
| 55 | - if ( ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status( $action_id ) ) { |
|
| 56 | - do_action( 'action_scheduler_execution_ignored', $action_id, $context ); |
|
| 55 | + if (ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status($action_id)) { |
|
| 56 | + do_action('action_scheduler_execution_ignored', $action_id, $context); |
|
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $valid_action = true; |
| 61 | - do_action( 'action_scheduler_begin_execute', $action_id, $context ); |
|
| 61 | + do_action('action_scheduler_begin_execute', $action_id, $context); |
|
| 62 | 62 | |
| 63 | - $action = $this->store->fetch_action( $action_id ); |
|
| 64 | - $this->store->log_execution( $action_id ); |
|
| 63 | + $action = $this->store->fetch_action($action_id); |
|
| 64 | + $this->store->log_execution($action_id); |
|
| 65 | 65 | $action->execute(); |
| 66 | - do_action( 'action_scheduler_after_execute', $action_id, $action, $context ); |
|
| 67 | - $this->store->mark_complete( $action_id ); |
|
| 68 | - } catch ( Exception $e ) { |
|
| 69 | - if ( $valid_action ) { |
|
| 70 | - $this->store->mark_failure( $action_id ); |
|
| 71 | - do_action( 'action_scheduler_failed_execution', $action_id, $e, $context ); |
|
| 66 | + do_action('action_scheduler_after_execute', $action_id, $action, $context); |
|
| 67 | + $this->store->mark_complete($action_id); |
|
| 68 | + } catch (Exception $e) { |
|
| 69 | + if ($valid_action) { |
|
| 70 | + $this->store->mark_failure($action_id); |
|
| 71 | + do_action('action_scheduler_failed_execution', $action_id, $e, $context); |
|
| 72 | 72 | } else { |
| 73 | - do_action( 'action_scheduler_failed_validation', $action_id, $e, $context ); |
|
| 73 | + do_action('action_scheduler_failed_validation', $action_id, $e, $context); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) { |
|
| 78 | - $this->schedule_next_instance( $action, $action_id ); |
|
| 77 | + if (isset($action) && is_a($action, 'ActionScheduler_Action') && $action->get_schedule()->is_recurring()) { |
|
| 78 | + $this->schedule_next_instance($action, $action_id); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | * @param ActionScheduler_Action $action |
| 86 | 86 | * @param int $action_id |
| 87 | 87 | */ |
| 88 | - protected function schedule_next_instance( ActionScheduler_Action $action, $action_id ) { |
|
| 88 | + protected function schedule_next_instance(ActionScheduler_Action $action, $action_id) { |
|
| 89 | 89 | try { |
| 90 | - ActionScheduler::factory()->repeat( $action ); |
|
| 91 | - } catch ( Exception $e ) { |
|
| 92 | - do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, $action ); |
|
| 90 | + ActionScheduler::factory()->repeat($action); |
|
| 91 | + } catch (Exception $e) { |
|
| 92 | + do_action('action_scheduler_failed_to_schedule_next_instance', $action_id, $e, $action); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @author Jeremy Pry |
| 100 | 100 | */ |
| 101 | 101 | protected function run_cleanup() { |
| 102 | - $this->cleaner->clean( 10 * $this->get_time_limit() ); |
|
| 102 | + $this->cleaner->clean(10 * $this->get_time_limit()); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | 110 | public function get_allowed_concurrent_batches() { |
| 111 | - return apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 1 ); |
|
| 111 | + return apply_filters('action_scheduler_queue_runner_concurrent_batches', 1); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | $time_limit = 30; |
| 131 | 131 | |
| 132 | 132 | // Apply deprecated filter from deprecated get_maximum_execution_time() method |
| 133 | - if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) { |
|
| 134 | - _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' ); |
|
| 135 | - $time_limit = apply_filters( 'action_scheduler_maximum_execution_time', $time_limit ); |
|
| 133 | + if (has_filter('action_scheduler_maximum_execution_time')) { |
|
| 134 | + _deprecated_function('action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit'); |
|
| 135 | + $time_limit = apply_filters('action_scheduler_maximum_execution_time', $time_limit); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - return absint( apply_filters( 'action_scheduler_queue_runner_time_limit', $time_limit ) ); |
|
| 138 | + return absint(apply_filters('action_scheduler_queue_runner_time_limit', $time_limit)); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -144,14 +144,14 @@ discard block |
||
| 144 | 144 | * @return int The number of seconds. |
| 145 | 145 | */ |
| 146 | 146 | protected function get_execution_time() { |
| 147 | - $execution_time = microtime( true ) - $this->created_time; |
|
| 147 | + $execution_time = microtime(true) - $this->created_time; |
|
| 148 | 148 | |
| 149 | 149 | // Get the CPU time if the hosting environment uses it rather than wall-clock time to calculate a process's execution time. |
| 150 | - if ( function_exists( 'getrusage' ) && apply_filters( 'action_scheduler_use_cpu_execution_time', defined( 'PANTHEON_ENVIRONMENT' ) ) ) { |
|
| 150 | + if (function_exists('getrusage') && apply_filters('action_scheduler_use_cpu_execution_time', defined('PANTHEON_ENVIRONMENT'))) { |
|
| 151 | 151 | $resource_usages = getrusage(); |
| 152 | 152 | |
| 153 | - if ( isset( $resource_usages['ru_stime.tv_usec'], $resource_usages['ru_stime.tv_usec'] ) ) { |
|
| 154 | - $execution_time = $resource_usages['ru_stime.tv_sec'] + ( $resource_usages['ru_stime.tv_usec'] / 1000000 ); |
|
| 153 | + if (isset($resource_usages['ru_stime.tv_usec'], $resource_usages['ru_stime.tv_usec'])) { |
|
| 154 | + $execution_time = $resource_usages['ru_stime.tv_sec'] + ($resource_usages['ru_stime.tv_usec'] / 1000000); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
@@ -164,15 +164,15 @@ discard block |
||
| 164 | 164 | * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action |
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | - protected function time_likely_to_be_exceeded( $processed_actions ) { |
|
| 167 | + protected function time_likely_to_be_exceeded($processed_actions) { |
|
| 168 | 168 | |
| 169 | 169 | $execution_time = $this->get_execution_time(); |
| 170 | 170 | $max_execution_time = $this->get_time_limit(); |
| 171 | 171 | $time_per_action = $execution_time / $processed_actions; |
| 172 | - $estimated_time = $execution_time + ( $time_per_action * 3 ); |
|
| 172 | + $estimated_time = $execution_time + ($time_per_action * 3); |
|
| 173 | 173 | $likely_to_be_exceeded = $estimated_time > $max_execution_time; |
| 174 | 174 | |
| 175 | - return apply_filters( 'action_scheduler_maximum_execution_time_likely_to_be_exceeded', $likely_to_be_exceeded, $this, $processed_actions, $execution_time, $max_execution_time ); |
|
| 175 | + return apply_filters('action_scheduler_maximum_execution_time_likely_to_be_exceeded', $likely_to_be_exceeded, $this, $processed_actions, $execution_time, $max_execution_time); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -183,18 +183,18 @@ discard block |
||
| 183 | 183 | * @return int |
| 184 | 184 | */ |
| 185 | 185 | protected function get_memory_limit() { |
| 186 | - if ( function_exists( 'ini_get' ) ) { |
|
| 187 | - $memory_limit = ini_get( 'memory_limit' ); |
|
| 186 | + if (function_exists('ini_get')) { |
|
| 187 | + $memory_limit = ini_get('memory_limit'); |
|
| 188 | 188 | } else { |
| 189 | 189 | $memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if ( ! $memory_limit || -1 === $memory_limit || '-1' === $memory_limit ) { |
|
| 192 | + if (!$memory_limit || -1 === $memory_limit || '-1' === $memory_limit) { |
|
| 193 | 193 | // Unlimited, set to 32GB. |
| 194 | 194 | $memory_limit = '32G'; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - return ActionScheduler_Compatibility::convert_hr_to_bytes( $memory_limit ); |
|
| 197 | + return ActionScheduler_Compatibility::convert_hr_to_bytes($memory_limit); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -209,10 +209,10 @@ discard block |
||
| 209 | 209 | protected function memory_exceeded() { |
| 210 | 210 | |
| 211 | 211 | $memory_limit = $this->get_memory_limit() * 0.90; |
| 212 | - $current_memory = memory_get_usage( true ); |
|
| 212 | + $current_memory = memory_get_usage(true); |
|
| 213 | 213 | $memory_exceeded = $current_memory >= $memory_limit; |
| 214 | 214 | |
| 215 | - return apply_filters( 'action_scheduler_memory_exceeded', $memory_exceeded, $this ); |
|
| 215 | + return apply_filters('action_scheduler_memory_exceeded', $memory_exceeded, $this); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -224,8 +224,8 @@ discard block |
||
| 224 | 224 | * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action |
| 225 | 225 | * @return bool |
| 226 | 226 | */ |
| 227 | - protected function batch_limits_exceeded( $processed_actions ) { |
|
| 228 | - return $this->memory_exceeded() || $this->time_likely_to_be_exceeded( $processed_actions ); |
|
| 227 | + protected function batch_limits_exceeded($processed_actions) { |
|
| 228 | + return $this->memory_exceeded() || $this->time_likely_to_be_exceeded($processed_actions); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,5 +236,5 @@ discard block |
||
| 236 | 236 | * Generally, this should be capitalised and not localised as it's a proper noun. |
| 237 | 237 | * @return int The number of actions processed. |
| 238 | 238 | */ |
| 239 | - abstract public function run( $context = '' ); |
|
| 239 | + abstract public function run($context = ''); |
|
| 240 | 240 | } |
@@ -34,20 +34,20 @@ discard block |
||
| 34 | 34 | * Initialize the class and attach callbacks. |
| 35 | 35 | */ |
| 36 | 36 | public static function init() { |
| 37 | - if ( empty( self::$wp_comment_logger ) ) { |
|
| 37 | + if (empty(self::$wp_comment_logger)) { |
|
| 38 | 38 | self::$wp_comment_logger = new ActionScheduler_wpCommentLogger(); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - add_action( self::$cleanup_hook, array( __CLASS__, 'delete_all_action_comments' ) ); |
|
| 41 | + add_action(self::$cleanup_hook, array(__CLASS__, 'delete_all_action_comments')); |
|
| 42 | 42 | |
| 43 | 43 | // While there are orphaned logs left in the comments table, we need to attach the callbacks which filter comment counts. |
| 44 | - add_action( 'pre_get_comments', array( self::$wp_comment_logger, 'filter_comment_queries' ), 10, 1 ); |
|
| 45 | - add_action( 'wp_count_comments', array( self::$wp_comment_logger, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs |
|
| 46 | - add_action( 'comment_feed_where', array( self::$wp_comment_logger, 'filter_comment_feed' ), 10, 2 ); |
|
| 44 | + add_action('pre_get_comments', array(self::$wp_comment_logger, 'filter_comment_queries'), 10, 1); |
|
| 45 | + add_action('wp_count_comments', array(self::$wp_comment_logger, 'filter_comment_count'), 20, 2); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs |
|
| 46 | + add_action('comment_feed_where', array(self::$wp_comment_logger, 'filter_comment_feed'), 10, 2); |
|
| 47 | 47 | |
| 48 | 48 | // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen |
| 49 | - add_action( 'load-tools_page_action-scheduler', array( __CLASS__, 'register_admin_notice' ) ); |
|
| 50 | - add_action( 'load-woocommerce_page_wc-status', array( __CLASS__, 'register_admin_notice' ) ); |
|
| 49 | + add_action('load-tools_page_action-scheduler', array(__CLASS__, 'register_admin_notice')); |
|
| 50 | + add_action('load-woocommerce_page_wc-status', array(__CLASS__, 'register_admin_notice')); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return boolean Whether there are scheduled action comments in the comments table. |
| 59 | 59 | */ |
| 60 | 60 | public static function has_logs() { |
| 61 | - return 'yes' === get_option( self::$has_logs_option_key ); |
|
| 61 | + return 'yes' === get_option(self::$has_logs_option_key); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | * Attached to the migration complete hook 'action_scheduler/migration_complete'. |
| 67 | 67 | */ |
| 68 | 68 | public static function maybe_schedule_cleanup() { |
| 69 | - if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) { |
|
| 70 | - update_option( self::$has_logs_option_key, 'yes' ); |
|
| 69 | + if ((bool) get_comments(array('type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids'))) { |
|
| 70 | + update_option(self::$has_logs_option_key, 'yes'); |
|
| 71 | 71 | |
| 72 | - if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) { |
|
| 73 | - as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook ); |
|
| 72 | + if (!as_next_scheduled_action(self::$cleanup_hook)) { |
|
| 73 | + as_schedule_single_action(gmdate('U') + (6 * MONTH_IN_SECONDS), self::$cleanup_hook); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -80,15 +80,15 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public static function delete_all_action_comments() { |
| 82 | 82 | global $wpdb; |
| 83 | - $wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) ); |
|
| 84 | - delete_option( self::$has_logs_option_key ); |
|
| 83 | + $wpdb->delete($wpdb->comments, array('comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT)); |
|
| 84 | + delete_option(self::$has_logs_option_key); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Registers admin notices about the orphaned action logs. |
| 89 | 89 | */ |
| 90 | 90 | public static function register_admin_notice() { |
| 91 | - add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) ); |
|
| 91 | + add_action('admin_notices', array(__CLASS__, 'print_admin_notice')); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -96,20 +96,20 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public static function print_admin_notice() { |
| 98 | 98 | $next_cleanup_message = ''; |
| 99 | - $next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook ); |
|
| 99 | + $next_scheduled_cleanup_hook = as_next_scheduled_action(self::$cleanup_hook); |
|
| 100 | 100 | |
| 101 | - if ( $next_scheduled_cleanup_hook ) { |
|
| 101 | + if ($next_scheduled_cleanup_hook) { |
|
| 102 | 102 | /* translators: %s: date interval */ |
| 103 | - $next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'woocommerce' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) ); |
|
| 103 | + $next_cleanup_message = sprintf(__('This data will be deleted in %s.', 'woocommerce'), human_time_diff(gmdate('U'), $next_scheduled_cleanup_hook)); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $notice = sprintf( |
| 107 | 107 | /* translators: 1: next cleanup message 2: github issue URL */ |
| 108 | - __( 'Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s <a href="%2$s">Learn more »</a>', 'woocommerce' ), |
|
| 108 | + __('Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s <a href="%2$s">Learn more »</a>', 'woocommerce'), |
|
| 109 | 109 | $next_cleanup_message, |
| 110 | 110 | 'https://github.com/woocommerce/action-scheduler/issues/368' |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | - echo '<div class="notice notice-warning"><p>' . wp_kses_post( $notice ) . '</p></div>'; |
|
| 113 | + echo '<div class="notice notice-warning"><p>' . wp_kses_post($notice) . '</p></div>'; |
|
| 114 | 114 | } |
| 115 | 115 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * ActionScheduler_AsyncRequest_QueueRunner |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -defined( 'ABSPATH' ) || exit; |
|
| 6 | +defined('ABSPATH') || exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * ActionScheduler_AsyncRequest_QueueRunner class. |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * Initiate new async request |
| 39 | 39 | */ |
| 40 | - public function __construct( ActionScheduler_Store $store ) { |
|
| 40 | + public function __construct(ActionScheduler_Store $store) { |
|
| 41 | 41 | parent::__construct(); |
| 42 | 42 | $this->store = $store; |
| 43 | 43 | } |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | * if there are still pending actions after completing a queue in this request. |
| 50 | 50 | */ |
| 51 | 51 | protected function handle() { |
| 52 | - do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context |
|
| 52 | + do_action('action_scheduler_run_queue', 'Async Request'); // run a queue in the same way as WP Cron, but declare the Async Request context |
|
| 53 | 53 | |
| 54 | 54 | $sleep_seconds = $this->get_sleep_seconds(); |
| 55 | 55 | |
| 56 | - if ( $sleep_seconds ) { |
|
| 57 | - sleep( $sleep_seconds ); |
|
| 56 | + if ($sleep_seconds) { |
|
| 57 | + sleep($sleep_seconds); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $this->maybe_dispatch(); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * If the async request runner is needed and allowed to run, dispatch a request. |
| 65 | 65 | */ |
| 66 | 66 | public function maybe_dispatch() { |
| 67 | - if ( ! $this->allow() ) { |
|
| 67 | + if (!$this->allow()) { |
|
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | protected function allow() { |
| 81 | 81 | |
| 82 | - if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) { |
|
| 82 | + if (!has_action('action_scheduler_run_queue') || ActionScheduler::runner()->has_maximum_concurrent_batches() || !$this->store->has_pending_actions_due()) { |
|
| 83 | 83 | $allow = false; |
| 84 | 84 | } else { |
| 85 | 85 | $allow = true; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - return apply_filters( 'action_scheduler_allow_async_request_runner', $allow ); |
|
| 88 | + return apply_filters('action_scheduler_allow_async_request_runner', $allow); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Chaining async requests can crash MySQL. A brief sleep call in PHP prevents that. |
| 93 | 93 | */ |
| 94 | 94 | protected function get_sleep_seconds() { |
| 95 | - return apply_filters( 'action_scheduler_async_request_sleep_seconds', 5, $this ); |
|
| 95 | + return apply_filters('action_scheduler_async_request_sleep_seconds', 5, $this); |
|
| 96 | 96 | } |
| 97 | 97 | } |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | /** |
| 9 | 9 | * @var int $action_id |
| 10 | 10 | */ |
| 11 | - protected $action_id = ''; |
|
| 11 | + protected $action_id = ''; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * @var string $message |
| 15 | 15 | */ |
| 16 | - protected $message = ''; |
|
| 16 | + protected $message = ''; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @var Datetime $date |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param Datetime $date Datetime object with the time when this log entry was created. If this parameter is |
| 29 | 29 | * not provided a new Datetime object (with current time) will be created. |
| 30 | 30 | */ |
| 31 | - public function __construct( $action_id, $message, $date = null ) { |
|
| 31 | + public function __construct($action_id, $message, $date = null) { |
|
| 32 | 32 | |
| 33 | 33 | /* |
| 34 | 34 | * ActionScheduler_wpCommentLogger::get_entry() previously passed a 3rd param of $comment->comment_type |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * goodness knows why, so we need to guard against that here instead of using a DateTime type declaration |
| 38 | 38 | * for the constructor's 3rd param of $date and causing a fatal error with older versions of FUE. |
| 39 | 39 | */ |
| 40 | - if ( null !== $date && ! is_a( $date, 'DateTime' ) ) { |
|
| 41 | - _doing_it_wrong( __METHOD__, 'The third parameter must be a valid DateTime instance, or null.', '2.0.0' ); |
|
| 40 | + if (null !== $date && !is_a($date, 'DateTime')) { |
|
| 41 | + _doing_it_wrong(__METHOD__, 'The third parameter must be a valid DateTime instance, or null.', '2.0.0'); |
|
| 42 | 42 | $date = null; |
| 43 | 43 | } |
| 44 | 44 | |