-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v6.1-a1: * 🌱**Database** Clear Orphaned Post Meta.
- Loading branch information
Hai Zheng
committed
Nov 20, 2023
1 parent
cf7c759
commit a9c9e9e
Showing
4 changed files
with
120 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* The admin optimize tool | ||
* | ||
|
@@ -8,6 +9,7 @@ | |
* @subpackage LiteSpeed/src | ||
* @author LiteSpeed Technologies <[email protected]> | ||
*/ | ||
|
||
namespace LiteSpeed; | ||
|
||
defined('WPINC') || exit(); | ||
|
@@ -18,6 +20,7 @@ class DB_Optm extends Root | |
|
||
private static $TYPES = array( | ||
'revision', | ||
'orphaned_post_meta', | ||
'auto_draft', | ||
'trash_post', | ||
'spam_comment', | ||
|
@@ -97,6 +100,9 @@ public function db_count($type, $ignore_multisite = false) | |
Utility::compatibility(); | ||
return array_sum(array_column($res, 0)); | ||
|
||
case 'orphaned_post_meta': | ||
return $wpdb->get_var("SELECT COUNT(a.*) FROM `$wpdb->postmeta` a LEFT JOIN `$wpdb->posts` b ON b.ID=a.post_id WHERE b.ID IS NULL"); | ||
|
||
case 'auto_draft': | ||
return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'auto-draft'"); | ||
|
||
|
@@ -193,6 +199,10 @@ private function _db_clean($type) | |
|
||
return __('Clean post revisions successfully.', 'litespeed-cache'); | ||
|
||
case 'orphaned_post_meta': | ||
$wpdb->query("DELETE a FROM `$wpdb->postmeta` a LEFT JOIN `$wpdb->posts` b ON b.ID=a.post_id WHERE b.ID IS NULL"); | ||
return __('Clean orphaned post meta successfully.', 'litespeed-cache'); | ||
|
||
case 'auto_draft': | ||
$wpdb->query("DELETE FROM `$wpdb->posts` WHERE post_status = 'auto-draft'"); | ||
return __('Clean auto drafts successfully.', 'litespeed-cache'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters