cursor" and never accepts a repeated id). * * @package Hermes_Conector */ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { exit; } // Another copy loaded in this request (the old plugin, or a Hermes from another folder). // "wp plugin uninstall --deactivate" loads this very copy first: that one does not count. if ( defined( 'BLOG_JURIDICO_VERSAO' ) || ( defined( 'HERMES_CONECTOR_VERSAO' ) && ( ! defined( 'HERMES_CONECTOR_ARQUIVO' ) || basename( dirname( HERMES_CONECTOR_ARQUIVO ) ) !== basename( __DIR__ ) ) ) ) { return; } if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } wp_cache_delete( 'plugins', 'plugins' ); // Bulk delete: the cached list may still show a folder already removed. $hermes_conector_eu = basename( __DIR__ ); // WP_UNINSTALL_PLUGIN keeps the FIRST plugin of a bulk delete. $hermes_conector_outras = array(); foreach ( get_plugins() as $hermes_conector_arquivo => $hermes_conector_dados ) { if ( dirname( $hermes_conector_arquivo ) === $hermes_conector_eu ) { continue; } $hermes_conector_base = basename( $hermes_conector_arquivo ); $hermes_conector_nome = isset( $hermes_conector_dados['Name'] ) ? (string) $hermes_conector_dados['Name'] : ''; $hermes_conector_uri = isset( $hermes_conector_dados['PluginURI'] ) ? (string) $hermes_conector_dados['PluginURI'] : ''; if ( ! in_array( $hermes_conector_base, array( 'hermes-conector.php', 'conector-blog-juridico.php' ), true ) || ( 'Conector Blog Jurídico' !== $hermes_conector_nome && false === strpos( $hermes_conector_uri, 'hermes.adv.br' ) ) ) { continue; } if ( is_plugin_active_for_network( $hermes_conector_arquivo ) ) { return; // Active on the whole network. } $hermes_conector_pasta = dirname( $hermes_conector_arquivo ); if ( '.' !== $hermes_conector_pasta && file_exists( WP_PLUGIN_DIR . '/' . $hermes_conector_pasta . '/uninstall.php' ) ) { return; // That copy cleans up when it is deleted. } $hermes_conector_outras[] = $hermes_conector_arquivo; } $hermes_conector_limpar = static function () { global $wpdb; // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange -- removing the plugin's own data. if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->prefix . 'blog_juridico_visitas' ) ) ) ) { $ultimo = (int) $wpdb->get_var( "SELECT MAX(id) FROM {$wpdb->prefix}blog_juridico_visitas" ); $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}blog_juridico_visitas" ); if ( $ultimo > 0 ) { // Only a number: a reinstall continues the ids (Hermes reads "id > cursor"). update_option( 'blog_juridico_visitas_ultimo_id', $ultimo, false ); } } // Rate-limit transients left by versions before 1.0.0. $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_bj_bat_' ) . '%', $wpdb->esc_like( '_transient_timeout_bj_bat_' ) . '%' ) ); // phpcs:enable delete_option( 'blog_juridico_db_versao' ); delete_option( 'blog_juridico_gsc_token' ); delete_option( 'blog_juridico_gsc_arquivo' ); delete_option( 'blog_juridico_contar_leituras' ); delete_option( 'blog_juridico_hermes_visto_em' ); wp_clear_scheduled_hook( 'hermes_conector_podar' ); delete_metadata( 'user', 0, 'hermes_conector_dispensado', '', true ); // Dismissed notices. }; if ( is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0, ) ) as $hermes_conector_site ) { switch_to_blog( $hermes_conector_site ); // A site where this folder, or another copy, is still active keeps its data. $hermes_conector_ativo = false; foreach ( (array) get_option( 'active_plugins', array() ) as $hermes_conector_p ) { $hermes_conector_p = (string) $hermes_conector_p; if ( dirname( $hermes_conector_p ) === $hermes_conector_eu || in_array( $hermes_conector_p, $hermes_conector_outras, true ) ) { $hermes_conector_ativo = true; } } if ( ! $hermes_conector_ativo ) { $hermes_conector_limpar(); } restore_current_blog(); } } else { foreach ( $hermes_conector_outras as $hermes_conector_p ) { if ( is_plugin_active( $hermes_conector_p ) ) { return; // An older copy is still active and uses the data. } } $hermes_conector_limpar(); }