seo-by-rank-math
Last commit date
assets
6 days ago
includes
6 days ago
languages
6 days ago
vendor
6 days ago
composer.json
6 days ago
rank-math.php
6 days ago
readme.txt
6 days ago
uninstall.php
1 year ago
wpml-config.xml
5 years ago
uninstall.php
128 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Fired when the plugin is uninstalled. |
| 4 | * |
| 5 | * When populating this file, consider the following flow |
| 6 | * of control: |
| 7 | * |
| 8 | * - This method should be static |
| 9 | * - Check if the $_REQUEST content actually is the plugin name |
| 10 | * - Run an admin referrer check to make sure it goes through authentication |
| 11 | * - Verify the output of $_GET makes sense |
| 12 | * - Repeat with other user roles. Best directly by using the links/query string parameters. |
| 13 | * - Repeat things for multisite. Once for a single site in the network, once sitewide. |
| 14 | * |
| 15 | * This file may be updated more in future version of the Boilerplate; however, this is the |
| 16 | * general skeleton and outline for how the file should work. |
| 17 | * |
| 18 | * @link https://rankmath.com |
| 19 | * @since 0.9.0 |
| 20 | * @package RANK_MATH |
| 21 | */ |
| 22 | |
| 23 | // If uninstall not called from WordPress, then exit. |
| 24 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 25 | exit; |
| 26 | } |
| 27 | |
| 28 | // Clear scheduled tasks. |
| 29 | if ( class_exists( 'ActionScheduler_QueueRunner' ) ) { |
| 30 | ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); |
| 31 | } |
| 32 | if ( class_exists( 'ActionScheduler_DBStore' ) ) { |
| 33 | ActionScheduler_DBStore::instance()->cancel_actions_by_group( 'rank-math' ); |
| 34 | } |
| 35 | |
| 36 | // Set rank_math_clear_data_on_uninstall to TRUE to delete all data on uninstall. |
| 37 | if ( true === apply_filters( 'rank_math_clear_data_on_uninstall', false ) ) { |
| 38 | |
| 39 | if ( ! is_multisite() ) { |
| 40 | rank_math_remove_data(); |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | global $wpdb; |
| 45 | |
| 46 | $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'" ); |
| 47 | if ( ! empty( $blog_ids ) ) { |
| 48 | foreach ( $blog_ids as $site_id ) { |
| 49 | switch_to_blog( $site_id ); |
| 50 | rank_math_remove_data(); |
| 51 | restore_current_blog(); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Removes ALL plugin data |
| 58 | * |
| 59 | * @since 1.0.35 |
| 60 | */ |
| 61 | function rank_math_remove_data() { |
| 62 | // Delete all options. |
| 63 | rank_math_delete_options(); |
| 64 | |
| 65 | // Delete meta for post, user and term. |
| 66 | rank_math_delete_meta( 'post' ); |
| 67 | rank_math_delete_meta( 'user' ); |
| 68 | rank_math_delete_meta( 'term' ); |
| 69 | |
| 70 | // Drop Tables. |
| 71 | rank_math_drop_table( '404_logs' ); |
| 72 | rank_math_drop_table( 'redirections' ); |
| 73 | rank_math_drop_table( 'redirections_cache' ); |
| 74 | rank_math_drop_table( 'internal_links' ); |
| 75 | rank_math_drop_table( 'internal_meta' ); |
| 76 | rank_math_drop_table( 'analytics_gsc' ); |
| 77 | rank_math_drop_table( 'analytics_objects' ); |
| 78 | rank_math_drop_table( 'analytics_inspections' ); |
| 79 | |
| 80 | // Remove Capabilities. |
| 81 | /** |
| 82 | * PSR-4 Autoload. |
| 83 | */ |
| 84 | include __DIR__ . '/vendor/autoload.php'; |
| 85 | |
| 86 | \RankMath\Role_Manager\Capability_Manager::get()->remove_capabilities(); |
| 87 | |
| 88 | // Clear any cached data that has been removed. |
| 89 | wp_cache_flush(); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Delete options. |
| 94 | * |
| 95 | * @return void |
| 96 | */ |
| 97 | function rank_math_delete_options() { |
| 98 | global $wpdb; |
| 99 | |
| 100 | $where = $wpdb->prepare( 'WHERE option_name LIKE %s OR option_name LIKE %s', '%' . $wpdb->esc_like( 'rank-math' ) . '%', '%' . $wpdb->esc_like( 'rank_math' ) . '%' ); |
| 101 | $wpdb->query( "DELETE FROM {$wpdb->prefix}options {$where}" ); // phpcs:ignore |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Delete post meta. |
| 106 | * |
| 107 | * @param string $table Table name. |
| 108 | * @return void |
| 109 | */ |
| 110 | function rank_math_delete_meta( $table = 'post' ) { |
| 111 | global $wpdb; |
| 112 | |
| 113 | $where = $wpdb->prepare( 'WHERE meta_key LIKE %s OR meta_key LIKE %s', '%' . $wpdb->esc_like( 'rank-math' ) . '%', '%' . $wpdb->esc_like( 'rank_math' ) . '%' ); |
| 114 | $wpdb->query( "DELETE FROM {$wpdb->prefix}{$table}meta {$where}" ); // phpcs:ignore |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Drop table from database |
| 119 | * |
| 120 | * @param string $name Name of table. |
| 121 | * @return void |
| 122 | */ |
| 123 | function rank_math_drop_table( $name ) { |
| 124 | global $wpdb; |
| 125 | |
| 126 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}rank_math_{$name}" ); // phpcs:ignore |
| 127 | } |
| 128 |