Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Deactivation
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 on_deactivate
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 disable_coming_soon
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
20
 load_text_domain
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Deactivation class file.
4 *
5 * @package NewfoldLabs\WP\Module\Deactivation
6 */
7
8namespace NewfoldLabs\WP\Module\Deactivation;
9
10use NewfoldLabs\WP\ModuleLoader\Container;
11use NewfoldLabs\WP\Module\Deactivation\DeactivationSurvey;
12
13/**
14 * Deactivation class.
15 */
16class Deactivation {
17
18    /**
19     * Dependency injection container.
20     *
21     * @var Container
22     */
23    protected $container;
24
25    /**
26     * Constructor.
27     *
28     * @param Container $container The plugin container.
29     */
30    public function __construct( Container $container ) {
31        $this->container = $container;
32
33        // deactivation hook
34        register_deactivation_hook(
35            $container->plugin()->file,
36            array( $this, 'on_deactivate' )
37        );
38
39        // Plugin deactivation survey.
40        \add_action( 'init', array( __CLASS__, 'load_text_domain' ), 100 );
41        add_action(
42            'admin_head-plugins.php',
43            function () {
44                new DeactivationSurvey();
45            }
46        );
47    }
48
49    /**
50     * Handle deactivation.
51     *
52     * @return void
53     */
54    public function on_deactivate() {
55        // disable coming soon mode
56        $this->disable_coming_soon();
57
58        // clear relevant transients
59        \delete_transient( 'newfold_marketplace' );
60        \delete_transient( 'newfold_notifications' );
61        \delete_transient( 'newfold_solutions' );
62
63        // flush rewrite rules
64        \flush_rewrite_rules();
65    }
66
67    /**
68     * Disable the coming soon page.
69     *
70     * @return void
71     */
72    public function disable_coming_soon() {
73        $coming_soon_service = $this->container->has( 'comingSoon' ) ? $this->container->get( 'comingSoon' ) : null;
74        if ( $coming_soon_service && $coming_soon_service->is_enabled() ) {
75            $coming_soon_service->disable();
76        }
77    }
78
79    /**
80     * Load text domain for Module
81     *
82     * @return void
83     */
84    public static function load_text_domain() {
85
86        \load_plugin_textdomain(
87            'wp-module-deactivation',
88            false,
89            NFD_DEACTIVATION_DIR . '/languages'
90        );
91    }
92}