Conditions | 29 |
Paths | > 20000 |
Total Lines | 175 |
Code Lines | 83 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
25 | public function __construct() |
||
26 | { |
||
27 | // throw new EE_Error('error'); |
||
28 | |||
29 | do_action('AHEE_log', __CLASS__, __FUNCTION__); |
||
30 | |||
31 | //wp have no MONTH_IN_SECONDS constant. So we approximate our own assuming all months are 4 weeks long. |
||
32 | if (! defined('MONTH_IN_SECONDS')) { |
||
33 | define('MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4); |
||
34 | } |
||
35 | |||
36 | if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
||
37 | $this->_uxip_hooks(); |
||
38 | } |
||
39 | |||
40 | |||
41 | $ueip_optin = EE_Registry::instance()->CFG->core->ee_ueip_optin; |
||
42 | $ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified; |
||
43 | |||
44 | //has optin been selected for data collection? |
||
45 | $espresso_data_optin = ! empty($ueip_optin) ? $ueip_optin : null; |
||
46 | |||
47 | if (empty($ueip_has_notified) |
||
48 | && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance |
||
49 | ) { |
||
50 | add_action('admin_notices', array($this, 'espresso_data_collection_optin_notice'), 10); |
||
51 | add_action('admin_enqueue_scripts', array($this, 'espresso_data_collection_enqueue_scripts'), 10); |
||
52 | add_action('wp_ajax_espresso_data_optin', array($this, 'espresso_data_optin_ajax_handler'), 10); |
||
53 | update_option('ee_ueip_optin', 'yes'); |
||
54 | $espresso_data_optin = 'yes'; |
||
55 | } |
||
56 | |||
57 | //let's prepare extra stats |
||
58 | $extra_stats = array(); |
||
59 | |||
60 | //only collect extra stats if the plugin user has opted in and transient is expired. |
||
61 | if (! empty($espresso_data_optin) && $espresso_data_optin == 'yes') { |
||
62 | if (false === ($transient = get_transient('ee_extra_data')) |
||
63 | && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance |
||
64 | ) { |
||
65 | |||
66 | $current_site = is_multisite() ? get_current_site() : null; |
||
67 | $site_pre = ! is_main_site() && ! empty($current_site) |
||
68 | ? trim( |
||
69 | preg_replace('/\b\w\S\w\b/', '', $current_site->domain), |
||
70 | '.' |
||
71 | ) . '_' |
||
72 | : ''; |
||
73 | |||
74 | |||
75 | //active gateways |
||
76 | $active_gateways = get_option('event_espresso_active_gateways'); |
||
77 | if (! empty($active_gateways)) { |
||
78 | foreach ((array)$active_gateways as $gateway => $ignore) { |
||
79 | $extra_stats[$site_pre . $gateway . '_gateway_active'] = 1; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | if (is_multisite() && is_main_site()) { |
||
84 | $extra_stats['is_multisite'] = true; |
||
85 | } |
||
86 | |||
87 | //what is the current active theme? |
||
88 | $active_theme = get_option('uxip_ee_active_theme'); |
||
89 | if (! empty($active_theme)) { |
||
90 | $extra_stats[$site_pre . 'active_theme'] = $active_theme; |
||
91 | } |
||
92 | |||
93 | //event info regarding an all event count and all "active" event count |
||
94 | $all_events_count = get_option('uxip_ee4_all_events_count'); |
||
95 | if (! empty($all_events_count)) { |
||
96 | $extra_stats[$site_pre . 'ee4_all_events_count'] = $all_events_count; |
||
97 | } |
||
98 | $active_events_count = get_option('uxip_ee4_active_events_count'); |
||
99 | if (! empty($active_events_count)) { |
||
100 | $extra_stats[$site_pre . 'ee4_active_events_count'] = $active_events_count; |
||
101 | } |
||
102 | |||
103 | //datetime stuff |
||
104 | $dtt_count = get_option('uxip_ee_all_dtts_count'); |
||
105 | if (! empty($dtt_count)) { |
||
106 | $extra_stats[$site_pre . 'all_dtts_count'] = $dtt_count; |
||
107 | } |
||
108 | |||
109 | $dtt_sold = get_option('uxip_ee_dtt_sold'); |
||
110 | if (! empty($dtt_sold)) { |
||
111 | $extra_stats[$site_pre . 'dtt_sold'] = $dtt_sold; |
||
112 | } |
||
113 | |||
114 | //ticket stuff |
||
115 | $all_tkt_count = get_option('uxip_ee_all_tkt_count'); |
||
116 | if (! empty($all_tkt_count)) { |
||
117 | $extra_stats[$site_pre . 'all_tkt_count'] = $all_tkt_count; |
||
118 | } |
||
119 | |||
120 | $free_tkt_count = get_option('uxip_ee_free_tkt_count'); |
||
121 | if (! empty($free_tkt_count)) { |
||
122 | $extra_stats[$site_pre . 'free_tkt_count'] = $free_tkt_count; |
||
123 | } |
||
124 | |||
125 | $paid_tkt_count = get_option('uxip_ee_paid_tkt_count'); |
||
126 | if (! empty($paid_tkt_count)) { |
||
127 | $extra_stats[$site_pre . 'paid_tkt_count'] = $paid_tkt_count; |
||
128 | } |
||
129 | |||
130 | $tkt_sold = get_option('uxip_ee_tkt_sold'); |
||
131 | if (! empty($tkt_sold)) { |
||
132 | $extra_stats[$site_pre . 'tkt_sold'] = $tkt_sold; |
||
133 | } |
||
134 | |||
135 | //phpversion checking |
||
136 | $extra_stats['phpversion'] = function_exists('phpversion') ? phpversion() : 'unknown'; |
||
137 | |||
138 | //set transient |
||
139 | set_transient('ee_extra_data', $extra_stats, WEEK_IN_SECONDS); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | |||
144 | // PUE Auto Upgrades stuff |
||
145 | if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file |
||
146 | require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
||
147 | |||
148 | $api_key = isset(EE_Registry::instance()->NET_CFG->core->site_license_key) |
||
149 | ? EE_Registry::instance()->NET_CFG->core->site_license_key |
||
150 | : ''; |
||
151 | //this needs to be the host server where plugin update engine is installed. Note, if you leave this blank |
||
152 | // then it is assumed the WordPress repo will be used and we'll just check there. |
||
153 | $host_server_url = 'https://eventespresso.com'; |
||
154 | |||
155 | //Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. |
||
156 | // So it's important that you use a key for the version type that is unique and not found in another key. |
||
157 | //For example: |
||
158 | //$plugin_slug['premium']['p'] = 'some-premium-slug'; |
||
159 | //$plugin_slug['prerelease']['pr'] = 'some-pre-release-slug'; |
||
160 | //The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr ) |
||
161 | // so doing something like: |
||
162 | //$plugin_slug['premium']['p'] = 'some-premium-slug'; |
||
163 | //$plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
||
164 | //..WOULD work! |
||
165 | $plugin_slug = array( |
||
166 | 'free' => array('decaf' => 'event-espresso-core-decaf'), |
||
167 | 'premium' => array('p' => 'event-espresso-core-reg'), |
||
168 | 'prerelease' => array('beta' => 'event-espresso-core-pr'), |
||
169 | ); |
||
170 | |||
171 | |||
172 | //$options needs to be an array with the included keys as listed. |
||
173 | $options = array( |
||
174 | // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
||
175 | // clients options table. Will be automatically set if left blank. |
||
176 | 'apikey' => $api_key, |
||
177 | //(required), you will need to obtain the apikey that the client gets from your site and |
||
178 | // then saves in their sites options table (see 'getting an api-key' below) |
||
179 | 'lang_domain' => 'event_espresso', |
||
180 | //(optional) - put here whatever reference you are using for the localization of your plugin (if it's |
||
181 | // localized). That way strings in this file will be included in the translation for your plugin. |
||
182 | 'checkPeriod' => '24', |
||
183 | //(optional) - use this parameter to indicate how often you want the client's install to ping your |
||
184 | // server for update checks. The integer indicates hours. If you don't include this parameter it will |
||
185 | // default to 12 hours. |
||
186 | 'option_key' => 'site_license_key', |
||
187 | //this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
||
188 | // updating your information message whenever this option_key is modified. |
||
189 | 'options_page_slug' => 'espresso_general_settings', |
||
190 | 'plugin_basename' => EE_PLUGIN_BASENAME, |
||
191 | 'use_wp_update' => true, |
||
192 | //if TRUE then you want FREE versions of the plugin to be updated from WP |
||
193 | 'extra_stats' => $extra_stats, |
||
194 | 'turn_on_notices_saved' => true, |
||
195 | ); |
||
196 | //initiate the class and start the plugin update engine! |
||
197 | new PluginUpdateEngineChecker($host_server_url, $plugin_slug, $options); |
||
198 | } |
||
199 | } |
||
200 | |||
456 |