WP-Sweep - Version 1.1.2

Version Description

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-Sweep
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1.1 to 1.1.2

Files changed (5) hide show
  1. composer.json +2 -2
  2. composer.lock +34 -23
  3. inc/class-wpsweep-api.php +64 -50
  4. readme.txt +12 -4
  5. wp-sweep.php +15 -15
composer.json CHANGED
@@ -14,11 +14,11 @@
14
  "repositories": [
15
  {
16
  "type": "vcs",
17
- "url": "git@github.com:techinasia/WordPress-Coding-Standards.git"
18
  }
19
  ],
20
  "require": {
21
- "php": ">=5.4.0"
22
  },
23
  "require-dev": {
24
  "wp-coding-standards/wpcs": "dev-develop"
14
  "repositories": [
15
  {
16
  "type": "vcs",
17
+ "url": "git@github.com:lesterchan/WordPress-Coding-Standards.git"
18
  }
19
  ],
20
  "require": {
21
+ "php": ">=5.6"
22
  },
23
  "require-dev": {
24
  "wp-coding-standards/wpcs": "dev-develop"
composer.lock CHANGED
@@ -4,21 +4,21 @@
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
- "content-hash": "b4fb02c188443d529694b8f83ca80300",
8
  "packages": [],
9
  "packages-dev": [
10
  {
11
  "name": "squizlabs/php_codesniffer",
12
- "version": "3.3.2",
13
  "source": {
14
  "type": "git",
15
  "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
16
- "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e"
17
  },
18
  "dist": {
19
  "type": "zip",
20
- "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e",
21
- "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e",
22
  "shasum": ""
23
  },
24
  "require": {
@@ -51,41 +51,52 @@
51
  }
52
  ],
53
  "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
54
- "homepage": "http://www.squizlabs.com/php-codesniffer",
55
  "keywords": [
56
  "phpcs",
57
  "standards"
58
  ],
59
- "time": "2018-09-23T23:08:17+00:00"
60
  },
61
  {
62
  "name": "wp-coding-standards/wpcs",
63
  "version": "dev-develop",
64
  "source": {
65
  "type": "git",
66
- "url": "https://github.com/techinasia/WordPress-Coding-Standards.git",
67
- "reference": "bb4cb53e0e1e6510bb2be0afb2bd2079fd47220b"
68
  },
69
  "dist": {
70
  "type": "zip",
71
- "url": "https://api.github.com/repos/techinasia/WordPress-Coding-Standards/zipball/bb4cb53e0e1e6510bb2be0afb2bd2079fd47220b",
72
- "reference": "bb4cb53e0e1e6510bb2be0afb2bd2079fd47220b",
73
  "shasum": ""
74
  },
75
  "require": {
76
- "php": ">=5.3",
77
- "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2"
 
 
 
 
 
78
  },
79
  "suggest": {
80
- "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3"
81
  },
82
  "type": "phpcodesniffer-standard",
83
  "scripts": {
84
- "post-install-cmd": [
85
- "\"vendor/bin/phpcs\" --config-set installed_paths ../../.."
 
 
 
 
 
 
86
  ],
87
- "post-update-cmd": [
88
- "\"vendor/bin/phpcs\" --config-set installed_paths ../../.."
89
  ]
90
  },
91
  "license": [
@@ -94,7 +105,7 @@
94
  "authors": [
95
  {
96
  "name": "Contributors",
97
- "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors"
98
  }
99
  ],
100
  "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
@@ -104,11 +115,11 @@
104
  "standards"
105
  ],
106
  "support": {
107
- "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues",
108
- "wiki": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki",
109
- "source": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards"
110
  },
111
- "time": "2018-03-14T07:49:12+00:00"
112
  }
113
  ],
114
  "aliases": [],
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
+ "content-hash": "9000cd3a445ab002c25944897a08aff5",
8
  "packages": [],
9
  "packages-dev": [
10
  {
11
  "name": "squizlabs/php_codesniffer",
12
+ "version": "3.5.4",
13
  "source": {
14
  "type": "git",
15
  "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
16
+ "reference": "dceec07328401de6211037abbb18bda423677e26"
17
  },
18
  "dist": {
19
  "type": "zip",
20
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dceec07328401de6211037abbb18bda423677e26",
21
+ "reference": "dceec07328401de6211037abbb18bda423677e26",
22
  "shasum": ""
23
  },
24
  "require": {
51
  }
52
  ],
53
  "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
54
+ "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
55
  "keywords": [
56
  "phpcs",
57
  "standards"
58
  ],
59
+ "time": "2020-01-30T22:20:29+00:00"
60
  },
61
  {
62
  "name": "wp-coding-standards/wpcs",
63
  "version": "dev-develop",
64
  "source": {
65
  "type": "git",
66
+ "url": "https://github.com/lesterchan/WordPress-Coding-Standards.git",
67
+ "reference": "3c1967b0b56e4ea0f25beee6d0650b977edd3f5a"
68
  },
69
  "dist": {
70
  "type": "zip",
71
+ "url": "https://api.github.com/repos/lesterchan/WordPress-Coding-Standards/zipball/3c1967b0b56e4ea0f25beee6d0650b977edd3f5a",
72
+ "reference": "3c1967b0b56e4ea0f25beee6d0650b977edd3f5a",
73
  "shasum": ""
74
  },
75
  "require": {
76
+ "php": ">=5.4",
77
+ "squizlabs/php_codesniffer": "^3.3.1"
78
+ },
79
+ "require-dev": {
80
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
81
+ "phpcompatibility/php-compatibility": "^9.0",
82
+ "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
83
  },
84
  "suggest": {
85
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically."
86
  },
87
  "type": "phpcodesniffer-standard",
88
  "scripts": {
89
+ "check-cs": [
90
+ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
91
+ ],
92
+ "fix-cs": [
93
+ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
94
+ ],
95
+ "install-codestandards": [
96
+ "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
97
  ],
98
+ "run-tests": [
99
+ "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress --bootstrap=\"./vendor/squizlabs/php_codesniffer/tests/bootstrap.php\" ./vendor/squizlabs/php_codesniffer/tests/AllTests.php"
100
  ]
101
  },
102
  "license": [
105
  "authors": [
106
  {
107
  "name": "Contributors",
108
+ "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors"
109
  }
110
  ],
111
  "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
115
  "standards"
116
  ],
117
  "support": {
118
+ "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues",
119
+ "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki",
120
+ "source": "https://github.com/WordPress/WordPress-Coding-Standards"
121
  },
122
+ "time": "2020-01-16T07:14:21+00:00"
123
  }
124
  ],
125
  "aliases": [],
inc/class-wpsweep-api.php CHANGED
@@ -52,41 +52,49 @@ class WPSweep_Api {
52
  * @return void
53
  */
54
  public function __construct() {
55
- add_action( 'rest_api_init', function() {
56
- register_rest_route( $this->namespace, 'count/(?P<name>\w+)', array(
57
- 'methods' => WP_REST_Server::READABLE,
58
- 'callback' => array( $this, 'count' ),
59
- 'permission_callback' => array( $this, 'permission_check' ),
60
- 'args' => array(
61
- 'name' => array(
62
- 'required' => true,
63
- 'validate_callback' => array( $this, 'is_sweep_name_valid' ),
64
- ),
65
- ),
66
- ));
67
- register_rest_route( $this->namespace, 'details/(?P<name>\w+)', array(
68
- 'methods' => WP_REST_Server::READABLE,
69
- 'callback' => array( $this, 'details' ),
70
- 'permission_callback' => array( $this, 'permission_check' ),
71
- 'args' => array(
72
- 'name' => array(
73
- 'required' => true,
74
- 'validate_callback' => array( $this, 'is_sweep_name_valid' ),
75
- ),
76
- ),
77
- ));
78
- register_rest_route( $this->namespace, 'sweep/(?P<name>\w+)', array(
79
- 'methods' => WP_REST_Server::DELETABLE,
80
- 'callback' => array( $this, 'sweep' ),
81
- 'permission_callback' => array( $this, 'permission_check' ),
82
- 'args' => array(
83
- 'name' => array(
84
- 'required' => true,
85
- 'validate_callback' => array( $this, 'is_sweep_name_valid' ),
86
- ),
87
- ),
88
- ));
89
- });
 
 
 
 
 
 
 
 
90
  }
91
  /**
92
  * Sweep item count
@@ -103,10 +111,12 @@ class WPSweep_Api {
103
  $sweep = new WPSweep();
104
  $count = (int) $sweep->count( $params['name'] );
105
 
106
- return new WP_REST_Response( array(
107
- 'name' => $params['name'],
108
- 'count' => $count,
109
- ) );
 
 
110
  }
111
 
112
  /**
@@ -124,11 +134,13 @@ class WPSweep_Api {
124
  $sweep = new WPSweep();
125
  $details = $sweep->details( $params['name'] );
126
 
127
- return new WP_REST_Response( array(
128
- 'name' => $params['name'],
129
- 'count' => count( $details ),
130
- 'data' => $details,
131
- ) );
 
 
132
  }
133
 
134
  /**
@@ -146,11 +158,13 @@ class WPSweep_Api {
146
  $sweep = new WPSweep();
147
  $results = $sweep->sweep( $params['name'] );
148
 
149
- return new WP_REST_Response( array(
150
- 'success' => ! empty( $results ),
151
- 'name' => $params['name'],
152
- 'message' => empty( $results ) ? __( 'No items left to sweep.', 'wp-sweep' ) : $results,
153
- ) );
 
 
154
  }
155
 
156
  /**
@@ -175,6 +189,6 @@ class WPSweep_Api {
175
  * @return bool Does the user has access to sweep?
176
  */
177
  public function permission_check() {
178
- return current_user_can( 'manage_options' );
179
  }
180
  }
52
  * @return void
53
  */
54
  public function __construct() {
55
+ add_action(
56
+ 'rest_api_init', function() {
57
+ register_rest_route(
58
+ $this->namespace, 'count/(?P<name>\w+)', array(
59
+ 'methods' => WP_REST_Server::READABLE,
60
+ 'callback' => array( $this, 'count' ),
61
+ 'permission_callback' => array( $this, 'permission_check' ),
62
+ 'args' => array(
63
+ 'name' => array(
64
+ 'required' => true,
65
+ 'validate_callback' => array( $this, 'is_sweep_name_valid' ),
66
+ ),
67
+ ),
68
+ )
69
+ );
70
+ register_rest_route(
71
+ $this->namespace, 'details/(?P<name>\w+)', array(
72
+ 'methods' => WP_REST_Server::READABLE,
73
+ 'callback' => array( $this, 'details' ),
74
+ 'permission_callback' => array( $this, 'permission_check' ),
75
+ 'args' => array(
76
+ 'name' => array(
77
+ 'required' => true,
78
+ 'validate_callback' => array( $this, 'is_sweep_name_valid' ),
79
+ ),
80
+ ),
81
+ )
82
+ );
83
+ register_rest_route(
84
+ $this->namespace, 'sweep/(?P<name>\w+)', array(
85
+ 'methods' => WP_REST_Server::DELETABLE,
86
+ 'callback' => array( $this, 'sweep' ),
87
+ 'permission_callback' => array( $this, 'permission_check' ),
88
+ 'args' => array(
89
+ 'name' => array(
90
+ 'required' => true,
91
+ 'validate_callback' => array( $this, 'is_sweep_name_valid' ),
92
+ ),
93
+ ),
94
+ )
95
+ );
96
+ }
97
+ );
98
  }
99
  /**
100
  * Sweep item count
111
  $sweep = new WPSweep();
112
  $count = (int) $sweep->count( $params['name'] );
113
 
114
+ return new WP_REST_Response(
115
+ array(
116
+ 'name' => $params['name'],
117
+ 'count' => $count,
118
+ )
119
+ );
120
  }
121
 
122
  /**
134
  $sweep = new WPSweep();
135
  $details = $sweep->details( $params['name'] );
136
 
137
+ return new WP_REST_Response(
138
+ array(
139
+ 'name' => $params['name'],
140
+ 'count' => count( $details ),
141
+ 'data' => $details,
142
+ )
143
+ );
144
  }
145
 
146
  /**
158
  $sweep = new WPSweep();
159
  $results = $sweep->sweep( $params['name'] );
160
 
161
+ return new WP_REST_Response(
162
+ array(
163
+ 'success' => ! empty( $results ),
164
+ 'name' => $params['name'],
165
+ 'message' => empty( $results ) ? __( 'No items left to sweep.', 'wp-sweep' ) : $results,
166
+ )
167
+ );
168
  }
169
 
170
  /**
189
  * @return bool Does the user has access to sweep?
190
  */
191
  public function permission_check() {
192
+ return current_user_can( 'update_plugins' );
193
  }
194
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: GamerZ
3
  Donate link: https://lesterchan.net/site/donation/
4
  Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
5
  Requires at least: 4.6
6
- Tested up to: 5.3
7
- Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -81,11 +81,15 @@ WP-Sweep Available Items:
81
  * oembed_postmeta
82
 
83
  WP-Sweep is not compatible with the following plugins:
 
 
 
84
  * [Meta Slider](https://wordpress.org/support/plugin/ml-slider/)
 
85
  * [Slider Revolution](https://revolution.themepunch.com/)
86
  * [Viba Portfolio](https://codecanyon.net/item/viba-portfolio-wordpress-plugin/9561599)
87
- * [MailPress](https://www.mailpress.org/)
88
- * [Asgaros Forum](https://www.asgaros.de/)
89
 
90
  ### Build Status
91
  [![Build Status](https://travis-ci.org/lesterchan/wp-sweep.svg?branch=master)](https://travis-ci.org/lesterchan/wp-sweep) [![Code Climate](https://codeclimate.com/github/lesterchan/wp-sweep/badges/gpa.svg)](https://codeclimate.com/github/lesterchan/wp-sweep) [![Issue Count](https://codeclimate.com/github/lesterchan/wp-sweep/badges/issue_count.svg)](https://codeclimate.com/github/lesterchan/wp-sweep)
@@ -100,6 +104,10 @@ WP-Sweep is not compatible with the following plugins:
100
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
101
 
102
  ## Changelog
 
 
 
 
103
  ### 1.1.1
104
  * NEW: `wp_sweep_excluded_termids` filter.
105
 
3
  Donate link: https://lesterchan.net/site/donation/
4
  Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
5
  Requires at least: 4.6
6
+ Tested up to: 5.4
7
+ Stable tag: 1.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
81
  * oembed_postmeta
82
 
83
  WP-Sweep is not compatible with the following plugins:
84
+ * [Asgaros Forum](https://wordpress.org/plugins/asgaros-forum/)
85
+ * [Elementor Popup Builder](https://elementor.com/features/popup-builder/)
86
+ * [MailPress](https://wordpress.org/plugins/mailpress/)
87
  * [Meta Slider](https://wordpress.org/support/plugin/ml-slider/)
88
+ * [Polylang](https://wordpress.org/plugins/polylang/)
89
  * [Slider Revolution](https://revolution.themepunch.com/)
90
  * [Viba Portfolio](https://codecanyon.net/item/viba-portfolio-wordpress-plugin/9561599)
91
+
92
+
93
 
94
  ### Build Status
95
  [![Build Status](https://travis-ci.org/lesterchan/wp-sweep.svg?branch=master)](https://travis-ci.org/lesterchan/wp-sweep) [![Code Climate](https://codeclimate.com/github/lesterchan/wp-sweep/badges/gpa.svg)](https://codeclimate.com/github/lesterchan/wp-sweep) [![Issue Count](https://codeclimate.com/github/lesterchan/wp-sweep/badges/issue_count.svg)](https://codeclimate.com/github/lesterchan/wp-sweep)
104
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
105
 
106
  ## Changelog
107
+ ### 1.1.2
108
+ * NEW: Changed permission check to `manage_plugins` for better MultiSite compatibility.
109
+ * NEW: Bump min PHP version to 5.6.
110
+
111
  ### 1.1.1
112
  * NEW: `wp_sweep_excluded_termids` filter.
113
 
wp-sweep.php CHANGED
@@ -9,7 +9,7 @@
9
  Plugin Name: WP-Sweep
10
  Plugin URI: https://lesterchan.net/portfolio/programming/php/
11
  Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
12
- Version: 1.1.1
13
  Author: Lester 'GaMerZ' Chan
14
  Author URI: https://lesterchan.net
15
  Text Domain: wp-sweep
@@ -17,7 +17,7 @@ License: GPL2
17
  */
18
 
19
  /*
20
- Copyright 2019 Lester Chan (email : lesterchan@gmail.com)
21
 
22
  This program is free software; you can redistribute it and/or modify
23
  it under the terms of the GNU General Public License, version 2, as
@@ -38,7 +38,7 @@ License: GPL2
38
  *
39
  * @since 1.0.0
40
  */
41
- define( 'WP_SWEEP_VERSION', '1.1.1' );
42
 
43
  /**
44
  * WP Rest API
@@ -179,7 +179,7 @@ class WPSweep {
179
  * @return void
180
  */
181
  public function admin_menu() {
182
- add_management_page( _x( 'Sweep', 'Page title', 'wp-sweep' ), _x( 'Sweep', 'Menu title', 'wp-sweep' ), 'manage_options', 'wp-sweep/admin.php' );
183
  }
184
 
185
 
@@ -394,10 +394,10 @@ class WPSweep {
394
  break;
395
  case 'orphan_term_relationships':
396
  $orphan_term_relationships_sql = implode( "','", array_map( 'esc_sql', $this->get_excluded_taxonomies() ) );
397
- $count = $wpdb->get_var( "SELECT COUNT(object_id) FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('$orphan_term_relationships_sql') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" ); // WPCS: unprepared SQL ok.
398
  break;
399
  case 'unused_terms':
400
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) ); // WPCS: unprepared SQL ok.
401
  break;
402
  case 'duplicated_postmeta':
403
  $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1 ) );
@@ -484,10 +484,10 @@ class WPSweep {
484
  break;
485
  case 'orphan_term_relationships':
486
  $orphan_term_relationships_sql = implode( "','", array_map( 'esc_sql', $this->get_excluded_taxonomies() ) );
487
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('$orphan_term_relationships_sql') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) ); // WPCS: unprepared SQL ok.
488
  break;
489
  case 'unused_terms':
490
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ') LIMIT %d', 0, $this->limit_details ) ); // WPCS: unprepared SQL ok.
491
  break;
492
  case 'duplicated_postmeta':
493
  $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
@@ -697,7 +697,7 @@ class WPSweep {
697
  }
698
  break;
699
  case 'orphan_term_relationships':
700
- $query = $wpdb->get_results( "SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode( '\',\'', $this->get_excluded_taxonomies() ) . "') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" ); // WPCS: unprepared SQL ok.
701
  if ( $query ) {
702
  foreach ( $query as $tax ) {
703
  $wp_remove_object_terms = wp_remove_object_terms( (int) $tax->object_id, (int) $tax->term_id, $tax->taxonomy );
@@ -711,7 +711,7 @@ class WPSweep {
711
  }
712
  break;
713
  case 'unused_terms':
714
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT tt.term_taxonomy_id, t.term_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) ); // WPCS: unprepared SQL ok.
715
  if ( $query ) {
716
  $check_wp_terms = false;
717
  foreach ( $query as $tax ) {
@@ -737,7 +737,7 @@ class WPSweep {
737
  foreach ( $query as $meta ) {
738
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
739
  array_pop( $ids );
740
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND post_id = %d', (int) $meta->post_id ) ); // WPCS: unprepared SQL ok.
741
  }
742
 
743
  // translators: %s is the Duplicated Post Meta count.
@@ -750,7 +750,7 @@ class WPSweep {
750
  foreach ( $query as $meta ) {
751
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
752
  array_pop( $ids );
753
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND comment_id = %d', (int) $meta->comment_id ) ); // WPCS: unprepared SQL ok.
754
  }
755
 
756
  // translators: %s is the Duplicated Comment Meta count.
@@ -763,7 +763,7 @@ class WPSweep {
763
  foreach ( $query as $meta ) {
764
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
765
  array_pop( $ids );
766
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ') AND user_id = %d', (int) $meta->user_id ) ); // WPCS: unprepared SQL ok.
767
  }
768
 
769
  // translators: %s is the Duplicated User Meta count.
@@ -776,7 +776,7 @@ class WPSweep {
776
  foreach ( $query as $meta ) {
777
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
778
  array_pop( $ids );
779
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND term_id = %d', (int) $meta->term_id ) ); // WPCS: unprepared SQL ok.
780
  }
781
 
782
  // translators: %s is the Duplicated Term Meta count.
@@ -787,7 +787,7 @@ class WPSweep {
787
  $query = $wpdb->get_col( 'SHOW TABLES' );
788
  if ( $query ) {
789
  $tables = implode( ',', $query );
790
- $wpdb->query( "OPTIMIZE TABLE $tables" ); // WPCS: unprepared SQL ok.
791
 
792
  // translators: %s is the Tables count.
793
  $message = sprintf( __( '%s Tables Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
9
  Plugin Name: WP-Sweep
10
  Plugin URI: https://lesterchan.net/portfolio/programming/php/
11
  Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
12
+ Version: 1.1.2
13
  Author: Lester 'GaMerZ' Chan
14
  Author URI: https://lesterchan.net
15
  Text Domain: wp-sweep
17
  */
18
 
19
  /*
20
+ Copyright 2020 Lester Chan (email : lesterchan@gmail.com)
21
 
22
  This program is free software; you can redistribute it and/or modify
23
  it under the terms of the GNU General Public License, version 2, as
38
  *
39
  * @since 1.0.0
40
  */
41
+ define( 'WP_SWEEP_VERSION', '1.1.2' );
42
 
43
  /**
44
  * WP Rest API
179
  * @return void
180
  */
181
  public function admin_menu() {
182
+ add_management_page( _x( 'Sweep', 'Page title', 'wp-sweep' ), _x( 'Sweep', 'Menu title', 'wp-sweep' ), 'update_plugins', 'wp-sweep/admin.php' );
183
  }
184
 
185
 
394
  break;
395
  case 'orphan_term_relationships':
396
  $orphan_term_relationships_sql = implode( "','", array_map( 'esc_sql', $this->get_excluded_taxonomies() ) );
397
+ $count = $wpdb->get_var( "SELECT COUNT(object_id) FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('$orphan_term_relationships_sql') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" ); // phpcs:ignore
398
  break;
399
  case 'unused_terms':
400
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) ); // phpcs:ignore
401
  break;
402
  case 'duplicated_postmeta':
403
  $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1 ) );
484
  break;
485
  case 'orphan_term_relationships':
486
  $orphan_term_relationships_sql = implode( "','", array_map( 'esc_sql', $this->get_excluded_taxonomies() ) );
487
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('$orphan_term_relationships_sql') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) ); // phpcs:ignore
488
  break;
489
  case 'unused_terms':
490
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ') LIMIT %d', 0, $this->limit_details ) ); // phpcs:ignore
491
  break;
492
  case 'duplicated_postmeta':
493
  $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
697
  }
698
  break;
699
  case 'orphan_term_relationships':
700
+ $query = $wpdb->get_results( "SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode( '\',\'', $this->get_excluded_taxonomies() ) . "') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" ); // phpcs:ignore
701
  if ( $query ) {
702
  foreach ( $query as $tax ) {
703
  $wp_remove_object_terms = wp_remove_object_terms( (int) $tax->object_id, (int) $tax->term_id, $tax->taxonomy );
711
  }
712
  break;
713
  case 'unused_terms':
714
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT tt.term_taxonomy_id, t.term_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) ); // phpcs:ignore
715
  if ( $query ) {
716
  $check_wp_terms = false;
717
  foreach ( $query as $tax ) {
737
  foreach ( $query as $meta ) {
738
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
739
  array_pop( $ids );
740
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND post_id = %d', (int) $meta->post_id ) ); // phpcs:ignore
741
  }
742
 
743
  // translators: %s is the Duplicated Post Meta count.
750
  foreach ( $query as $meta ) {
751
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
752
  array_pop( $ids );
753
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND comment_id = %d', (int) $meta->comment_id ) ); // phpcs:ignore
754
  }
755
 
756
  // translators: %s is the Duplicated Comment Meta count.
763
  foreach ( $query as $meta ) {
764
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
765
  array_pop( $ids );
766
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ') AND user_id = %d', (int) $meta->user_id ) ); // phpcs:ignore
767
  }
768
 
769
  // translators: %s is the Duplicated User Meta count.
776
  foreach ( $query as $meta ) {
777
  $ids = array_map( 'intval', explode( ',', $meta->ids ) );
778
  array_pop( $ids );
779
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND term_id = %d', (int) $meta->term_id ) ); // phpcs:ignore
780
  }
781
 
782
  // translators: %s is the Duplicated Term Meta count.
787
  $query = $wpdb->get_col( 'SHOW TABLES' );
788
  if ( $query ) {
789
  $tables = implode( ',', $query );
790
+ $wpdb->query( "OPTIMIZE TABLE $tables" ); // phpcs:ignore
791
 
792
  // translators: %s is the Tables count.
793
  $message = sprintf( __( '%s Tables Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );