PluginProbe ʕ •ᴥ•ʔ
Admin Help Docs / trunk
Admin Help Docs vtrunk
2.0.1.1 trunk 1.4.3.2 2.0.0 2.0.0.1 2.0.0.2 2.0.1
admin-help-docs / inc / cleanup.php
admin-help-docs / inc Last commit date
css 1 month ago docs 3 months ago img 3 months ago js 3 months ago tabs 3 months ago api.php 3 months ago cleanup.php 3 months ago colors.php 1 month ago deprecated.php 3 months ago header.php 3 months ago helpers.php 1 month ago index.php 3 months ago menu.php 3 months ago plugins-page.php 3 months ago post-type-help-doc-imports.php 3 months ago post-type-help-docs.php 1 month ago shortcodes.php 1 month ago taxonomy-folders.php 3 months ago
cleanup.php
92 lines
1 <?php
2 /**
3 * Cleanup
4 */
5
6 namespace PluginRx\AdminHelpDocs;
7
8 if ( ! defined( 'ABSPATH' ) ) exit;
9
10 class Cleanup {
11
12 /**
13 * Run the cleanup process
14 */
15 public static function run() {
16 self::delete_all_transients();
17 self::delete_all_docs();
18 self::delete_all_imports();
19 self::delete_all_prefixed_options();
20
21 error_log( 'Admin Help Docs: ' . __( 'Cleanup complete. All plugin data has been removed after uninstallation.', 'admin-help-docs' ) );
22 } // End run()
23
24
25 /**
26 * Delete all transients related to the plugin
27 */
28 private static function delete_all_transients() {
29 global $wpdb;
30 $transients = $wpdb->get_col( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_helpdocs_%'" ); // phpcs:ignore
31 foreach ( $transients as $transient ) {
32 $transient_name = str_replace( '_transient_', '', $transient );
33 delete_transient( $transient_name );
34 }
35 } // End delete_all_transients()
36
37
38 /**
39 * Delete all help docs posts
40 */
41 private static function delete_all_docs() {
42 $args = [
43 'post_type' => 'help-docs',
44 'post_status' => 'any',
45 'numberposts' => -1,
46 'fields' => 'ids',
47 ];
48 $docs = get_posts( $args );
49 foreach ( $docs as $doc_id ) {
50 wp_delete_post( $doc_id, true );
51 }
52 } // End delete_all_docs()
53
54
55 /**
56 * Delete all imports
57 */
58 private static function delete_all_imports() {
59 $args = [
60 'post_type' => 'help-doc-imports',
61 'post_status' => 'any',
62 'numberposts' => -1,
63 'fields' => 'ids',
64 ];
65 $docs = get_posts( $args );
66 foreach ( $docs as $doc_id ) {
67 wp_delete_post( $doc_id, true );
68 }
69 } // End delete_all_imports()
70
71
72 /**
73 * Delete all options starting with helpdocs_
74 */
75 private static function delete_all_prefixed_options() {
76 global $wpdb;
77
78 $options = $wpdb->get_col( // phpcs:ignore
79 $wpdb->prepare( // phpcs:ignore
80 "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
81 'helpdocs_%'
82 )
83 );
84
85 if ( ! empty( $options ) ) {
86 foreach ( $options as $option ) {
87 delete_option( ( $option ) );
88 }
89 }
90 } // End delete_all_prefixed_options()
91
92 }