wp-seopress
Last commit date
assets
1 day ago
inc
1 day ago
languages
1 day ago
public
1 day ago
src
1 day ago
templates
1 day ago
vendor
1 day ago
contributors.txt
6 months ago
readme.txt
1 day ago
seopress-autoload.php
7 months ago
seopress-functions.php
1 day ago
seopress.php
1 day ago
uninstall.php
7 months ago
wpml-config.xml
1 day ago
uninstall.php
140 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Uninstall SEOPress |
| 4 | * |
| 5 | * @package Uninstall |
| 6 | */ |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit( 'Please don’t call the plugin directly. Thanks :)' ); |
| 9 | |
| 10 | /** |
| 11 | * Uninstall SEOPress |
| 12 | * |
| 13 | * @since 6.2 |
| 14 | * |
| 15 | * @author Benjamin, inspired by Polylang |
| 16 | */ |
| 17 | |
| 18 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit. |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * SEOPRESS_Uninstall |
| 24 | */ |
| 25 | class SEOPRESS_Uninstall { |
| 26 | |
| 27 | /** |
| 28 | * Constructor: manages uninstall for multisite |
| 29 | * |
| 30 | * @since 6.2 |
| 31 | */ |
| 32 | public function __construct() { |
| 33 | global $wpdb; |
| 34 | |
| 35 | // Don't do anything except if the constant SEOPRESS_UNINSTALL is explicitely defined and true. |
| 36 | if ( ! defined( 'SEOPRESS_UNINSTALL' ) || ! SEOPRESS_UNINSTALL ) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | // Check if it is a multisite uninstall - if so, run the uninstall function for each blog id. |
| 41 | if ( is_multisite() ) { |
| 42 | foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) { |
| 43 | switch_to_blog( $blog_id ); |
| 44 | $this->uninstall(); |
| 45 | } |
| 46 | restore_current_blog(); |
| 47 | } else { |
| 48 | $this->uninstall(); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Delete all entries in the DB related to SEOPress Free AND PRO: |
| 54 | * Transients, post meta, options, custom tables |
| 55 | * |
| 56 | * @since 6.2 |
| 57 | * @updated 7.4 |
| 58 | */ |
| 59 | public function uninstall() { |
| 60 | global $wpdb; |
| 61 | |
| 62 | do_action( 'seopress_uninstall' ); |
| 63 | |
| 64 | // Delete post meta. |
| 65 | //phpcs:ignore |
| 66 | $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '_seopress_%'" ); |
| 67 | |
| 68 | // Delete redirections / 404 errors. |
| 69 | $sql = 'DELETE `posts`, `pm` |
| 70 | FROM `' . $wpdb->prefix . 'posts` AS `posts` |
| 71 | LEFT JOIN `' . $wpdb->prefix . 'postmeta` AS `pm` ON `pm`.`post_id` = `posts`.`ID` |
| 72 | WHERE `posts`.`post_type` = \'seopress_404\''; |
| 73 | |
| 74 | //phpcs:ignore |
| 75 | $sql = $wpdb->prepare( $sql ); |
| 76 | //phpcs:ignore |
| 77 | $wpdb->query( $sql ); |
| 78 | |
| 79 | // Delete schemas. |
| 80 | $sql = 'DELETE `posts`, `pm` |
| 81 | FROM `' . $wpdb->prefix . 'posts` AS `posts` |
| 82 | LEFT JOIN `' . $wpdb->prefix . 'postmeta` AS `pm` ON `pm`.`post_id` = `posts`.`ID` |
| 83 | WHERE `posts`.`post_type` = \'seopress_schemas\''; |
| 84 | |
| 85 | //phpcs:ignore |
| 86 | $sql = $wpdb->prepare( $sql ); |
| 87 | //phpcs:ignore |
| 88 | $wpdb->query( $sql ); |
| 89 | |
| 90 | // Delete broken links. |
| 91 | $sql = 'DELETE `posts`, `pm` |
| 92 | FROM `' . $wpdb->prefix . 'posts` AS `posts` |
| 93 | LEFT JOIN `' . $wpdb->prefix . 'postmeta` AS `pm` ON `pm`.`post_id` = `posts`.`ID` |
| 94 | WHERE `posts`.`post_type` = \'seopress_bot\''; |
| 95 | |
| 96 | //phpcs:ignore |
| 97 | $sql = $wpdb->prepare( $sql ); |
| 98 | //phpcs:ignore |
| 99 | $wpdb->query( $sql ); |
| 100 | |
| 101 | // Delete global settings. |
| 102 | //phpcs:ignore |
| 103 | $options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'seopress_%'" ); |
| 104 | array_map( 'delete_option', $options ); |
| 105 | |
| 106 | // Delete widget options. |
| 107 | //phpcs:ignore |
| 108 | $options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'widget_seopress_%'" ); |
| 109 | array_map( 'delete_option', $options ); |
| 110 | |
| 111 | // Delete transients. |
| 112 | delete_transient( '_seopress_sitemap_ids_video' ); |
| 113 | delete_transient( 'seopress_results_page_speed' ); |
| 114 | delete_transient( 'seopress_results_page_speed_desktop' ); |
| 115 | delete_transient( 'seopress_results_google_analytics' ); |
| 116 | delete_transient( 'seopress_results_matomo' ); |
| 117 | delete_transient( 'seopress_prevent_title_redirection_already_exist' ); |
| 118 | |
| 119 | // Delete custom tables. |
| 120 | //phpcs:ignore |
| 121 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}seopress_significant_keywords" ); |
| 122 | //phpcs:ignore |
| 123 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}seopress_content_analysis" ); |
| 124 | //phpcs:ignore |
| 125 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}seopress_seo_issues" ); |
| 126 | |
| 127 | // Clear CRON. |
| 128 | wp_clear_scheduled_hook( 'seopress_xml_sitemaps_ping_cron' ); |
| 129 | wp_clear_scheduled_hook( 'seopress_404_cron_cleaning' ); |
| 130 | wp_clear_scheduled_hook( 'seopress_google_analytics_cron' ); |
| 131 | wp_clear_scheduled_hook( 'seopress_page_speed_insights_cron' ); |
| 132 | wp_clear_scheduled_hook( 'seopress_404_email_alerts_cron' ); |
| 133 | wp_clear_scheduled_hook( 'seopress_insights_gsc_cron' ); |
| 134 | wp_clear_scheduled_hook( 'seopress_matomo_analytics_cron' ); |
| 135 | wp_clear_scheduled_hook( 'seopress_alerts_cron' ); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | new SEOPRESS_Uninstall(); |
| 140 |