-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathclass-purge-post-data.php
More file actions
executable file
·105 lines (92 loc) · 2.42 KB
/
Copy pathclass-purge-post-data.php
File metadata and controls
executable file
·105 lines (92 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Purge Post Data stored in the database that holds scan data about the posts.
*
* @package Accessibility_Checker
*/
namespace EDAC\Admin;
/**
* Uses sql queries to get and purge post data from the database for given post
* ids or for custom posts by post_type string.
*
* @since 1.10.0
*/
class Purge_Post_Data {
/**
* Purge deleted posts
*
* @since 1.10.0
*
* @param int $post_id ID of the post.
*
* @return void
*/
public static function delete_post( int $post_id ) {
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
$wpdb->query(
$wpdb->prepare(
'DELETE FROM %i WHERE postid = %d and siteid = %d',
edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' ),
$post_id,
get_current_blog_id()
)
);
self::delete_post_meta( $post_id );
}
/**
* Delete post meta
*
* @since 1.10.0
*
* @param int $post_id ID of the post.
*
* @return void
*/
public static function delete_post_meta( int $post_id ) {
if ( ! $post_id ) {
return;
}
$post_meta = get_post_meta( $post_id );
if ( $post_meta ) {
foreach ( $post_meta as $key => $value ) {
if ( substr( $key, 0, 5 ) === '_edac' || substr( $key, 0, 6 ) === '_edacp' ) {
delete_post_meta( $post_id, $key );
}
}
}
}
/**
* Purge issues by post type
*
* @since 1.10.0
*
* @param string $post_type Post Type.
*
* @return bool|int|\mysqli_result|void
*/
public static function delete_cpt_posts( string $post_type ) {
if ( ! $post_type || ! post_type_exists( $post_type ) ) {
return;
}
global $wpdb;
/**
* Fires before deleting posts of a specific post type.
*
* @since 1.31.0
*
* @param string $post_type Post Type.
*/
do_action( 'edac_before_delete_cpt_posts', $post_type );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
return $wpdb->query(
$wpdb->prepare(
"DELETE T1,T2 from $wpdb->postmeta as T1 JOIN %i as T2 ON T1.post_id = T2.postid WHERE T1.meta_key like %s and T2.siteid=%d and T2.type=%s",
edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' ),
'_edac%',
get_current_blog_id(),
$post_type
)
);
}
}