Passed
Push — master ( 63ce67...b4800c )
by Brian
05:12
created

AyeCode_Deactivation_Survey   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 45
c 1
b 0
f 1
dl 0
loc 87
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 15 4
A scripts() 0 55 3
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7
if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) {
8
9
	class AyeCode_Deactivation_Survey {
10
11
		/**
12
		 * AyeCode_Deactivation_Survey instance.
13
		 *
14
		 * @access private
15
		 * @since  1.0.0
16
		 * @var    AyeCode_Deactivation_Survey There can be only one!
17
		 */
18
		private static $instance = null;
19
20
		public static $plugins;
21
22
		public $version = "1.0.3";
23
24
		public static function instance( $plugin = array() ) {
25
			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) {
26
				self::$instance = new AyeCode_Deactivation_Survey;
27
				self::$plugins = array();
28
29
				add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) );
30
31
				do_action( 'ayecode_deactivation_survey_loaded' );
32
			}
33
34
			if(!empty($plugin)){
35
				self::$plugins[] = (object)$plugin;
36
			}
37
38
			return self::$instance;
39
		}
40
41
		public function scripts() {
42
			global $pagenow;
43
44
			// Bail if we are not on the plugins page
45
			if ( $pagenow != "plugins.php" ) {
46
				return;
47
			}
48
49
			// Enqueue scripts
50
			add_thickbox();
51
			wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js');
52
53
			/*
54
			 * Localized strings. Strings can be localised by plugins using this class.
55
			 * We deliberately don't add textdomains here so that double textdomain warning is not given in theme review.
56
			 */
57
			wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array(
58
				'quick_feedback'			=> 'Quick Feedback',
59
				'foreword'					=> 'If you would be kind enough, please tell us why you\'re deactivating?',
60
				'better_plugins_name'		=> 'Please tell us which plugin?',
61
				'please_tell_us'			=> 'Please tell us the reason so we can improve the plugin',
62
				'do_not_attach_email'		=> 'Do not send my e-mail address with this feedback',
63
				'brief_description'			=> 'Please give us any feedback that could help us improve',
64
				'cancel'					=> 'Cancel',
65
				'skip_and_deactivate'		=> 'Skip &amp; Deactivate',
66
				'submit_and_deactivate'		=> 'Submit &amp; Deactivate',
67
				'please_wait'				=> 'Please wait',
68
				'get_support'				=> 'Get Support',
69
				'documentation'				=> 'Documentation',
70
				'thank_you'					=> 'Thank you!',
71
			));
72
73
			// Plugins
74
			$plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins);
75
76
			// Reasons
77
			$defaultReasons = array(
78
				'suddenly-stopped-working'	=> 'The plugin suddenly stopped working',
79
				'plugin-broke-site'			=> 'The plugin broke my site',
80
				'plugin-setup-difficult'	=> 'Too difficult to setup',
81
				'no-longer-needed'			=> 'I don\'t need this plugin any more',
82
				'found-better-plugin'		=> 'I found a better plugin',
83
				'temporary-deactivation'	=> 'It\'s a temporary deactivation, I\'m troubleshooting',
84
				'other'						=> 'Other',
85
			);
86
87
			foreach($plugins as $plugin)
88
			{
89
				$plugin->reasons = apply_filters('ayecode_deactivation_survey_reasons', $defaultReasons, $plugin);
90
				$plugin->url = home_url();
91
				$plugin->activated = 0;
92
			}
93
94
			// Send plugin data
95
			wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins);
96
97
		}
98
		
99
100
	}
101
102
}