sudar /
bulk-delete
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Class that encapsulates the deletion of posts based on days. |
||
| 4 | * |
||
| 5 | * @author Sudar |
||
| 6 | * |
||
| 7 | * @package BulkDelete |
||
| 8 | */ |
||
| 9 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
||
| 10 | |||
| 11 | class Bulk_Delete_By_Days { |
||
| 12 | public $days; |
||
| 13 | public $op; |
||
|
0 ignored issues
–
show
|
|||
| 14 | |||
| 15 | /** |
||
| 16 | * Default constructor. |
||
| 17 | */ |
||
| 18 | public function __construct() { |
||
| 19 | add_action( 'parse_query', array( $this, 'parse_query' ) ); |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Parse the query. |
||
| 24 | * |
||
| 25 | * @param array $query |
||
| 26 | */ |
||
| 27 | public function parse_query( $query ) { |
||
| 28 | if ( isset( $query->query_vars['days'] ) ) { |
||
| 29 | $this->days = $query->query_vars['days']; |
||
| 30 | $this->op = $query->query_vars['op']; |
||
| 31 | |||
| 32 | add_filter( 'posts_where', array( $this, 'filter_where' ) ); |
||
| 33 | add_filter( 'posts_selection', array( $this, 'remove_where' ) ); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Modify the where clause. |
||
| 39 | * |
||
| 40 | * @param string $where (optional) |
||
| 41 | * |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | public function filter_where( $where = '' ) { |
||
| 45 | $where .= ' AND post_date ' . $this->op . " '" . date( 'y-m-d', strtotime( '-' . $this->days . ' days' ) ) . "'"; |
||
| 46 | |||
| 47 | return $where; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Remove the `posts_where` filter. |
||
| 52 | */ |
||
| 53 | public function remove_where() { |
||
| 54 | remove_filter( 'posts_where', array( $this, 'filter_where' ) ); |
||
| 55 | } |
||
| 56 | } |
||
| 57 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.