Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
jetpack_uninstall
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2/**
3 * Functionality that is executed when Jetpack is uninstalled via built-in WordPress commands.
4 *
5 * @package automattic/jetpack
6 */
7
8use Automattic\Jetpack\Backup\V0005\Helper_Script_Manager;
9use Automattic\Jetpack\Connection\Manager as Connection_Manager;
10use Automattic\Jetpack\Sync\Sender;
11
12if ( ! defined( 'ABSPATH' ) ) {
13    exit( 0 );
14}
15
16/**
17 * Uninstall script for Jetpack.
18 */
19function jetpack_uninstall() {
20    if (
21        ! defined( 'WP_UNINSTALL_PLUGIN' ) ||
22        ! WP_UNINSTALL_PLUGIN ||
23        // @phan-suppress-next-line PhanTypeMismatchArgumentInternal -- If it's defined, it's a string: https://developer.wordpress.org/plugins/plugin-basics/uninstall-methods/#method-2-uninstall-php
24        dirname( WP_UNINSTALL_PLUGIN ) !== dirname( plugin_basename( __FILE__ ) )
25    ) {
26        status_header( 404 );
27        exit( 0 );
28    }
29
30    if ( ! defined( 'JETPACK__PLUGIN_DIR' ) ) {
31        define( 'JETPACK__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
32    }
33
34    require JETPACK__PLUGIN_DIR . 'vendor/autoload_packages.php';
35
36    if ( method_exists( Connection_Manager::class, 'is_ready_for_cleanup' ) && ! Connection_Manager::is_ready_for_cleanup( dirname( plugin_basename( __FILE__ ) ) ) ) {
37        // There are other active Jetpack plugins, no need for cleanup.
38        return;
39    }
40
41    Jetpack_Options::delete_all_known_options();
42
43    // Delete all legacy options.
44    delete_option( 'jetpack_was_activated' );
45    delete_option( 'jetpack_auto_installed' );
46    delete_option( 'jetpack_register' );
47    delete_transient( 'jetpack_register' );
48
49    // Delete sync options
50    //
51    // Do not initialize any listeners.
52    // Since all the files will be deleted.
53    // No need to try to sync anything.
54    add_filter( 'jetpack_sync_modules', '__return_empty_array', 100 );
55
56    // Jetpack Sync.
57    Sender::get_instance()->uninstall();
58
59    // Jetpack Backup: Cleanup any leftover Helper Scripts.
60    Helper_Script_Manager::delete_all_helper_scripts();
61}
62
63jetpack_uninstall();