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