@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
| 13 | 13 | $class_to_filepath = array(); |
| 14 | 14 | if (! empty($stages)) { |
| 15 | - foreach ($stages as $filepath) { |
|
| 16 | - $matches = array(); |
|
| 17 | - preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 19 | - } |
|
| 15 | + foreach ($stages as $filepath) { |
|
| 16 | + $matches = array(); |
|
| 17 | + preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | // give addons a chance to autoload their stages too |
| 22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_1_0__autoloaded_stages', $class_to_filepath); |
@@ -44,91 +44,91 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | - * |
|
| 50 | - * @param TableManager $table_manager |
|
| 51 | - * @param TableAnalysis $table_analysis |
|
| 52 | - */ |
|
| 53 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | - { |
|
| 55 | - $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
| 56 | - $this->_priority = 10; |
|
| 57 | - $this->_migration_stages = array( |
|
| 58 | - new EE_DMS_4_1_0_org_options(), |
|
| 59 | - new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | - new EE_DMS_4_1_0_gateways(), |
|
| 61 | - new EE_DMS_4_1_0_events(), |
|
| 62 | - new EE_DMS_4_1_0_prices(), |
|
| 63 | - new EE_DMS_4_1_0_category_details(), |
|
| 64 | - new EE_DMS_4_1_0_event_category(), |
|
| 65 | - new EE_DMS_4_1_0_venues(), |
|
| 66 | - new EE_DMS_4_1_0_event_venue(), |
|
| 67 | - new EE_DMS_4_1_0_question_groups(), |
|
| 68 | - new EE_DMS_4_1_0_questions(), |
|
| 69 | - new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | - new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | - new EE_DMS_4_1_0_attendees(), |
|
| 72 | - new EE_DMS_4_1_0_line_items(), |
|
| 73 | - new EE_DMS_4_1_0_answers(), |
|
| 74 | - new EE_DMS_4_1_0_checkins(), |
|
| 75 | - ); |
|
| 76 | - parent::__construct($table_manager, $table_analysis); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | - * |
|
| 84 | - * @global wpdb $wpdb |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - private function _checkin_table_exists() |
|
| 88 | - { |
|
| 89 | - global $wpdb; |
|
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | - if ($results) { |
|
| 92 | - return true; |
|
| 93 | - } else { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - public function can_migrate_from_version($version_array) |
|
| 101 | - { |
|
| 102 | - $version_string = $version_array['Core']; |
|
| 103 | - if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 47 | + /** |
|
| 48 | + * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | + * |
|
| 50 | + * @param TableManager $table_manager |
|
| 51 | + * @param TableAnalysis $table_analysis |
|
| 52 | + */ |
|
| 53 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | + { |
|
| 55 | + $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
| 56 | + $this->_priority = 10; |
|
| 57 | + $this->_migration_stages = array( |
|
| 58 | + new EE_DMS_4_1_0_org_options(), |
|
| 59 | + new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | + new EE_DMS_4_1_0_gateways(), |
|
| 61 | + new EE_DMS_4_1_0_events(), |
|
| 62 | + new EE_DMS_4_1_0_prices(), |
|
| 63 | + new EE_DMS_4_1_0_category_details(), |
|
| 64 | + new EE_DMS_4_1_0_event_category(), |
|
| 65 | + new EE_DMS_4_1_0_venues(), |
|
| 66 | + new EE_DMS_4_1_0_event_venue(), |
|
| 67 | + new EE_DMS_4_1_0_question_groups(), |
|
| 68 | + new EE_DMS_4_1_0_questions(), |
|
| 69 | + new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | + new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | + new EE_DMS_4_1_0_attendees(), |
|
| 72 | + new EE_DMS_4_1_0_line_items(), |
|
| 73 | + new EE_DMS_4_1_0_answers(), |
|
| 74 | + new EE_DMS_4_1_0_checkins(), |
|
| 75 | + ); |
|
| 76 | + parent::__construct($table_manager, $table_analysis); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | + * |
|
| 84 | + * @global wpdb $wpdb |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + private function _checkin_table_exists() |
|
| 88 | + { |
|
| 89 | + global $wpdb; |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | + if ($results) { |
|
| 92 | + return true; |
|
| 93 | + } else { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + public function can_migrate_from_version($version_array) |
|
| 101 | + { |
|
| 102 | + $version_string = $version_array['Core']; |
|
| 103 | + if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 104 | 104 | // echo "$version_string can be migrated fro"; |
| 105 | - return true; |
|
| 106 | - } elseif (! $version_string) { |
|
| 105 | + return true; |
|
| 106 | + } elseif (! $version_string) { |
|
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | - // no version string provided... this must be pre 4.1 |
|
| 109 | - // because since 4.1 we're |
|
| 110 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | - } else { |
|
| 108 | + // no version string provided... this must be pre 4.1 |
|
| 109 | + // because since 4.1 we're |
|
| 110 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | + } else { |
|
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - } |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
| 119 | - public function schema_changes_before_migration() |
|
| 120 | - { |
|
| 121 | - // relies on 4.1's EEH_Activation::create_table |
|
| 122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 123 | - $table_name = 'esp_answer'; |
|
| 124 | - $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 119 | + public function schema_changes_before_migration() |
|
| 120 | + { |
|
| 121 | + // relies on 4.1's EEH_Activation::create_table |
|
| 122 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 123 | + $table_name = 'esp_answer'; |
|
| 124 | + $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 125 | 125 | REG_ID int(10) unsigned NOT NULL, |
| 126 | 126 | QST_ID int(10) unsigned NOT NULL, |
| 127 | 127 | ANS_value text NOT NULL, |
| 128 | 128 | PRIMARY KEY (ANS_ID)"; |
| 129 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | - $table_name = 'esp_attendee_meta'; |
|
| 131 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 129 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 130 | + $table_name = 'esp_attendee_meta'; |
|
| 131 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 132 | 132 | ATT_ID bigint(20) unsigned NOT NULL, |
| 133 | 133 | ATT_fname varchar(45) NOT NULL, |
| 134 | 134 | ATT_lname varchar(45) NOT NULL, |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | KEY ATT_fname (ATT_fname), |
| 145 | 145 | KEY ATT_lname (ATT_lname), |
| 146 | 146 | KEY ATT_email (ATT_email(191))"; |
| 147 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 148 | - $table_name = 'esp_country'; |
|
| 149 | - $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL, |
|
| 147 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 148 | + $table_name = 'esp_country'; |
|
| 149 | + $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL, |
|
| 150 | 150 | CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL, |
| 151 | 151 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
| 152 | 152 | CNT_name varchar(45) COLLATE utf8_bin NOT NULL, |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | CNT_is_EU tinyint(1) DEFAULT '0', |
| 163 | 163 | CNT_active tinyint(1) DEFAULT '0', |
| 164 | 164 | PRIMARY KEY (CNT_ISO)"; |
| 165 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 166 | - $table_name = 'esp_datetime'; |
|
| 167 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 165 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 166 | + $table_name = 'esp_datetime'; |
|
| 167 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 168 | 168 | EVT_ID bigint(20) unsigned NOT NULL, |
| 169 | 169 | DTT_EVT_start datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 170 | 170 | DTT_EVT_end datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | PRIMARY KEY (DTT_ID), |
| 178 | 178 | KEY EVT_ID (EVT_ID), |
| 179 | 179 | KEY DTT_is_primary (DTT_is_primary)"; |
| 180 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 181 | - $table_name = 'esp_event_meta'; |
|
| 182 | - $sql = " |
|
| 180 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 181 | + $table_name = 'esp_event_meta'; |
|
| 182 | + $sql = " |
|
| 183 | 183 | EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
| 184 | 184 | EVT_ID bigint(20) unsigned NOT NULL, |
| 185 | 185 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -194,31 +194,31 @@ discard block |
||
| 194 | 194 | EVT_external_URL varchar(200) NULL, |
| 195 | 195 | EVT_donations tinyint(1) NULL, |
| 196 | 196 | PRIMARY KEY (EVTM_ID)"; |
| 197 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | - $table_name = 'esp_event_question_group'; |
|
| 199 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 197 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | + $table_name = 'esp_event_question_group'; |
|
| 199 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
| 201 | 201 | QSG_ID int(10) unsigned NOT NULL, |
| 202 | 202 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 203 | 203 | PRIMARY KEY (EQG_ID)"; |
| 204 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | - $table_name = 'esp_event_venue'; |
|
| 206 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 204 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | + $table_name = 'esp_event_venue'; |
|
| 206 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 207 | 207 | EVT_ID bigint(20) unsigned NOT NULL, |
| 208 | 208 | VNU_ID bigint(20) unsigned NOT NULL, |
| 209 | 209 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 210 | 210 | PRIMARY KEY (EVV_ID)"; |
| 211 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | - $table_name = 'esp_extra_meta'; |
|
| 213 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 211 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | + $table_name = 'esp_extra_meta'; |
|
| 213 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 214 | 214 | OBJ_ID int(11) DEFAULT NULL, |
| 215 | 215 | EXM_type varchar(45) DEFAULT NULL, |
| 216 | 216 | EXM_key varchar(45) DEFAULT NULL, |
| 217 | 217 | EXM_value text, |
| 218 | 218 | PRIMARY KEY (EXM_ID)"; |
| 219 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 220 | - $table_name = 'esp_line_item'; |
|
| 221 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 219 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 220 | + $table_name = 'esp_line_item'; |
|
| 221 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 222 | 222 | LIN_code varchar(245) NOT NULL DEFAULT '', |
| 223 | 223 | TXN_ID int(11) DEFAULT NULL, |
| 224 | 224 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -234,18 +234,18 @@ discard block |
||
| 234 | 234 | OBJ_ID int(11) DEFAULT NULL, |
| 235 | 235 | OBJ_type varchar(45)DEFAULT NULL, |
| 236 | 236 | PRIMARY KEY (LIN_ID)"; |
| 237 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 238 | - $table_name = 'esp_message_template'; |
|
| 239 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 237 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 238 | + $table_name = 'esp_message_template'; |
|
| 239 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 240 | 240 | GRP_ID int(10) unsigned NOT NULL, |
| 241 | 241 | MTP_context varchar(50) NOT NULL, |
| 242 | 242 | MTP_template_field varchar(30) NOT NULL, |
| 243 | 243 | MTP_content text NOT NULL, |
| 244 | 244 | PRIMARY KEY (MTP_ID), |
| 245 | 245 | KEY GRP_ID (GRP_ID)"; |
| 246 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 247 | - $table_name = 'esp_message_template_group'; |
|
| 248 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 246 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 247 | + $table_name = 'esp_message_template_group'; |
|
| 248 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 249 | 249 | EVT_ID bigint(20) unsigned DEFAULT NULL, |
| 250 | 250 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
| 251 | 251 | MTP_messenger varchar(30) NOT NULL, |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | PRIMARY KEY (GRP_ID), |
| 258 | 258 | KEY EVT_ID (EVT_ID), |
| 259 | 259 | KEY MTP_user_id (MTP_user_id)"; |
| 260 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 261 | - $table_name = 'esp_payment'; |
|
| 262 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 260 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 261 | + $table_name = 'esp_payment'; |
|
| 262 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 263 | 263 | TXN_ID int(10) unsigned DEFAULT NULL, |
| 264 | 264 | STS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL, |
| 265 | 265 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | PRIMARY KEY (PAY_ID), |
| 276 | 276 | KEY TXN_ID (TXN_ID), |
| 277 | 277 | KEY PAY_timestamp (PAY_timestamp)"; |
| 278 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 279 | - $table_name = "esp_ticket"; |
|
| 280 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 278 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 279 | + $table_name = "esp_ticket"; |
|
| 280 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 281 | 281 | TTM_ID int(10) unsigned NOT NULL, |
| 282 | 282 | TKT_name varchar(245) NOT NULL DEFAULT '', |
| 283 | 283 | TKT_description text NOT NULL, |
@@ -296,28 +296,28 @@ discard block |
||
| 296 | 296 | TKT_parent int(10) unsigned DEFAULT '0', |
| 297 | 297 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 298 | 298 | PRIMARY KEY (TKT_ID)"; |
| 299 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 300 | - $table_name = "esp_ticket_price"; |
|
| 301 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 299 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 300 | + $table_name = "esp_ticket_price"; |
|
| 301 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 302 | 302 | TKT_ID int(10) unsigned NOT NULL, |
| 303 | 303 | PRC_ID int(10) unsigned NOT NULL, |
| 304 | 304 | PRIMARY KEY (TKP_ID)"; |
| 305 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 306 | - $table_name = "esp_datetime_ticket"; |
|
| 307 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 305 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 306 | + $table_name = "esp_datetime_ticket"; |
|
| 307 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 308 | 308 | DTT_ID int(10) unsigned NOT NULL, |
| 309 | 309 | TKT_ID int(10) unsigned NOT NULL, |
| 310 | 310 | PRIMARY KEY (DTK_ID)"; |
| 311 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 312 | - $table_name = "esp_ticket_template"; |
|
| 313 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 311 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 312 | + $table_name = "esp_ticket_template"; |
|
| 313 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 314 | 314 | TTM_name varchar(45) NOT NULL, |
| 315 | 315 | TTM_description text, |
| 316 | 316 | TTM_file varchar(45), |
| 317 | 317 | PRIMARY KEY (TTM_ID)"; |
| 318 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | - $table_name = "esp_price"; |
|
| 320 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 318 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | + $table_name = "esp_price"; |
|
| 320 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 321 | 321 | PRT_ID tinyint(3) unsigned NOT NULL, |
| 322 | 322 | PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00', |
| 323 | 323 | PRC_name varchar(245) NOT NULL, |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | PRC_order tinyint(3) unsigned NOT NULL DEFAULT '0', |
| 329 | 329 | PRC_parent int(10) unsigned DEFAULT 0, |
| 330 | 330 | PRIMARY KEY (PRC_ID)"; |
| 331 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 332 | - $table_name = "esp_price_type"; |
|
| 333 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 331 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 332 | + $table_name = "esp_price_type"; |
|
| 333 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 334 | 334 | PRT_name varchar(45) NOT NULL, |
| 335 | 335 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
| 336 | 336 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 339 | 339 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
| 340 | 340 | PRIMARY KEY (PRT_ID)"; |
| 341 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | - $table_name = 'esp_question'; |
|
| 343 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 341 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | + $table_name = 'esp_question'; |
|
| 343 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 344 | 344 | QST_display_text text NOT NULL, |
| 345 | 345 | QST_admin_label varchar(255) NOT NULL, |
| 346 | 346 | QST_system varchar(25) DEFAULT NULL, |
@@ -352,10 +352,10 @@ discard block |
||
| 352 | 352 | QST_wp_user bigint(20) unsigned NULL, |
| 353 | 353 | QST_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 354 | 354 | PRIMARY KEY (QST_ID)'; |
| 355 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 356 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 357 | - $table_name = 'esp_question_group'; |
|
| 358 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 355 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 356 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 357 | + $table_name = 'esp_question_group'; |
|
| 358 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 359 | 359 | QSG_name varchar(255) NOT NULL, |
| 360 | 360 | QSG_identifier varchar(100) NOT NULL, |
| 361 | 361 | QSG_desc text NULL, |
@@ -366,23 +366,23 @@ discard block |
||
| 366 | 366 | QSG_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 367 | 367 | PRIMARY KEY (QSG_ID), |
| 368 | 368 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
| 369 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 370 | - $table_name = 'esp_question_group_question'; |
|
| 371 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 369 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 370 | + $table_name = 'esp_question_group_question'; |
|
| 371 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 372 | 372 | QSG_ID int(10) unsigned NOT NULL, |
| 373 | 373 | QST_ID int(10) unsigned NOT NULL, |
| 374 | 374 | PRIMARY KEY (QGQ_ID) "; |
| 375 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 376 | - $table_name = 'esp_question_option'; |
|
| 377 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 375 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 376 | + $table_name = 'esp_question_option'; |
|
| 377 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 378 | 378 | QSO_value varchar(255) NOT NULL, |
| 379 | 379 | QSO_desc text NOT NULL, |
| 380 | 380 | QST_ID int(10) unsigned NOT NULL, |
| 381 | 381 | QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 382 | 382 | PRIMARY KEY (QSO_ID)"; |
| 383 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | - $table_name = 'esp_registration'; |
|
| 385 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 383 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | + $table_name = 'esp_registration'; |
|
| 385 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 386 | 386 | EVT_ID bigint(20) unsigned NOT NULL, |
| 387 | 387 | ATT_ID bigint(20) unsigned NOT NULL, |
| 388 | 388 | TXN_ID int(10) unsigned NOT NULL, |
@@ -405,25 +405,25 @@ discard block |
||
| 405 | 405 | KEY STS_ID (STS_ID), |
| 406 | 406 | KEY REG_url_link (REG_url_link), |
| 407 | 407 | KEY REG_code (REG_code)"; |
| 408 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 409 | - $table_name = 'esp_checkin'; |
|
| 410 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 408 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 409 | + $table_name = 'esp_checkin'; |
|
| 410 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 411 | 411 | REG_ID int(10) unsigned NOT NULL, |
| 412 | 412 | DTT_ID int(10) unsigned NOT NULL, |
| 413 | 413 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
| 414 | 414 | CHK_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 415 | 415 | PRIMARY KEY (CHK_ID)"; |
| 416 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 417 | - $table_name = 'esp_state'; |
|
| 418 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 416 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 417 | + $table_name = 'esp_state'; |
|
| 418 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 419 | 419 | CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL, |
| 420 | 420 | STA_abbrev varchar(6) COLLATE utf8_bin NOT NULL, |
| 421 | 421 | STA_name varchar(100) COLLATE utf8_bin NOT NULL, |
| 422 | 422 | STA_active tinyint(1) DEFAULT '1', |
| 423 | 423 | PRIMARY KEY (STA_ID)"; |
| 424 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 425 | - $table_name = 'esp_status'; |
|
| 426 | - $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL, |
|
| 424 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 425 | + $table_name = 'esp_status'; |
|
| 426 | + $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL, |
|
| 427 | 427 | STS_code varchar(45) COLLATE utf8_bin NOT NULL, |
| 428 | 428 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
| 429 | 429 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -431,9 +431,9 @@ discard block |
||
| 431 | 431 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
| 432 | 432 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
| 433 | 433 | KEY STS_type (STS_type)"; |
| 434 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 435 | - $table_name = 'esp_transaction'; |
|
| 436 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 434 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 435 | + $table_name = 'esp_transaction'; |
|
| 436 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 437 | 437 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 438 | 438 | TXN_total decimal(10,3) DEFAULT '0.00', |
| 439 | 439 | TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00', |
@@ -443,9 +443,9 @@ discard block |
||
| 443 | 443 | PRIMARY KEY (TXN_ID), |
| 444 | 444 | KEY TXN_timestamp (TXN_timestamp), |
| 445 | 445 | KEY STS_ID (STS_ID)"; |
| 446 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 447 | - $table_name = 'esp_venue_meta'; |
|
| 448 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 446 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 447 | + $table_name = 'esp_venue_meta'; |
|
| 448 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 449 | 449 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 450 | 450 | VNU_address varchar(255) DEFAULT NULL, |
| 451 | 451 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -463,52 +463,52 @@ discard block |
||
| 463 | 463 | PRIMARY KEY (VNUM_ID), |
| 464 | 464 | KEY STA_ID (STA_ID), |
| 465 | 465 | KEY CNT_ISO (CNT_ISO)"; |
| 466 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 467 | - // setting up the default stats and countries is also essential for the data migrations to run |
|
| 468 | - // (because many need to convert old string states to foreign keys into the states table) |
|
| 469 | - $this->insert_default_states(); |
|
| 470 | - $this->insert_default_countries(); |
|
| 471 | - // setting up default prices, price types, and tickets is also essential for the price migrations |
|
| 472 | - $this->insert_default_price_types(); |
|
| 473 | - $this->insert_default_prices(); |
|
| 474 | - $this->insert_default_tickets(); |
|
| 475 | - // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 476 | - EE_Config::instance()->update_espresso_config(false, true); |
|
| 477 | - return true; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 484 | - * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 485 | - * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 486 | - * |
|
| 487 | - * @return boolean |
|
| 488 | - */ |
|
| 489 | - public function schema_changes_after_migration() |
|
| 490 | - { |
|
| 491 | - return true; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * insert_default_states |
|
| 498 | - * |
|
| 499 | - * @access public |
|
| 500 | - * @static |
|
| 501 | - * @return void |
|
| 502 | - */ |
|
| 503 | - public function insert_default_states() |
|
| 504 | - { |
|
| 505 | - global $wpdb; |
|
| 506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 507 | - if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 509 | - $states = $wpdb->get_var($SQL); |
|
| 510 | - if (! $states) { |
|
| 511 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 466 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 467 | + // setting up the default stats and countries is also essential for the data migrations to run |
|
| 468 | + // (because many need to convert old string states to foreign keys into the states table) |
|
| 469 | + $this->insert_default_states(); |
|
| 470 | + $this->insert_default_countries(); |
|
| 471 | + // setting up default prices, price types, and tickets is also essential for the price migrations |
|
| 472 | + $this->insert_default_price_types(); |
|
| 473 | + $this->insert_default_prices(); |
|
| 474 | + $this->insert_default_tickets(); |
|
| 475 | + // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 476 | + EE_Config::instance()->update_espresso_config(false, true); |
|
| 477 | + return true; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 484 | + * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 485 | + * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 486 | + * |
|
| 487 | + * @return boolean |
|
| 488 | + */ |
|
| 489 | + public function schema_changes_after_migration() |
|
| 490 | + { |
|
| 491 | + return true; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * insert_default_states |
|
| 498 | + * |
|
| 499 | + * @access public |
|
| 500 | + * @static |
|
| 501 | + * @return void |
|
| 502 | + */ |
|
| 503 | + public function insert_default_states() |
|
| 504 | + { |
|
| 505 | + global $wpdb; |
|
| 506 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 507 | + if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 508 | + $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 509 | + $states = $wpdb->get_var($SQL); |
|
| 510 | + if (! $states) { |
|
| 511 | + $SQL = "INSERT INTO " . $state_table . " |
|
| 512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
| 514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -579,29 +579,29 @@ discard block |
||
| 579 | 579 | (67, 'CA', 'PE', 'Prince Edward Island', 1), |
| 580 | 580 | (68, 'CA', 'QC', 'Quebec', 1), |
| 581 | 581 | (69, 'CA', 'SK', 'Saskatchewan', 1);"; |
| 582 | - $wpdb->query($SQL); |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * insert_default_countries |
|
| 591 | - * |
|
| 592 | - * @access public |
|
| 593 | - * @static |
|
| 594 | - * @return void |
|
| 595 | - */ |
|
| 596 | - public function insert_default_countries() |
|
| 597 | - { |
|
| 598 | - global $wpdb; |
|
| 599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 600 | - if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 602 | - $countries = $wpdb->get_var($SQL); |
|
| 603 | - if (! $countries) { |
|
| 604 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 582 | + $wpdb->query($SQL); |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * insert_default_countries |
|
| 591 | + * |
|
| 592 | + * @access public |
|
| 593 | + * @static |
|
| 594 | + * @return void |
|
| 595 | + */ |
|
| 596 | + public function insert_default_countries() |
|
| 597 | + { |
|
| 598 | + global $wpdb; |
|
| 599 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 600 | + if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 602 | + $countries = $wpdb->get_var($SQL); |
|
| 603 | + if (! $countries) { |
|
| 604 | + $SQL = "INSERT INTO " . $country_table . " |
|
| 605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -829,984 +829,984 @@ discard block |
||
| 829 | 829 | ('ZA', 'ZAF', 0, 'South Africa', 'ZAR', 'Rand', 'Rands', 'R', 1, 2, '+27', 0, 0), |
| 830 | 830 | ('ZM', 'ZMB', 0, 'Zambia', 'ZMK', 'Kwacha', 'Kwachas', '', 1, 2, '+260', 0, 0), |
| 831 | 831 | ('ZW', 'ZWE', 0, 'Zimbabwe', 'ZWD', 'Dollar', 'Dollars', 'Z$', 1, 2, '+263', 0, 0);"; |
| 832 | - $wpdb->query($SQL); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * insert_default_price_types |
|
| 841 | - * |
|
| 842 | - * @access public |
|
| 843 | - * @static |
|
| 844 | - * @return void |
|
| 845 | - */ |
|
| 846 | - public function insert_default_price_types() |
|
| 847 | - { |
|
| 848 | - global $wpdb; |
|
| 849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 850 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 852 | - $price_types_exist = $wpdb->get_var($SQL); |
|
| 853 | - if (! $price_types_exist) { |
|
| 854 | - $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 832 | + $wpdb->query($SQL); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * insert_default_price_types |
|
| 841 | + * |
|
| 842 | + * @access public |
|
| 843 | + * @static |
|
| 844 | + * @return void |
|
| 845 | + */ |
|
| 846 | + public function insert_default_price_types() |
|
| 847 | + { |
|
| 848 | + global $wpdb; |
|
| 849 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 850 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 852 | + $price_types_exist = $wpdb->get_var($SQL); |
|
| 853 | + if (! $price_types_exist) { |
|
| 854 | + $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 855 | 855 | (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
| 856 | 856 | (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
| 857 | 857 | (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
| 858 | 858 | (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
| 859 | 859 | (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
| 860 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 861 | - $wpdb->query($SQL); |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * insert_default_prices. We assume we're upgrading to regular here. |
|
| 870 | - * If we're INSTALLING 4.1 CAF, then we add a few extra default prices |
|
| 871 | - * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 872 | - * EE_BRewing_regular |
|
| 873 | - * |
|
| 874 | - * @access public |
|
| 875 | - * @static |
|
| 876 | - * @return void |
|
| 877 | - */ |
|
| 878 | - public function insert_default_prices() |
|
| 879 | - { |
|
| 880 | - global $wpdb; |
|
| 881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 882 | - if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 884 | - $prices_exist = $wpdb->get_var($SQL); |
|
| 885 | - if (! $prices_exist) { |
|
| 886 | - $SQL = "INSERT INTO $price_table |
|
| 860 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 861 | + $wpdb->query($SQL); |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * insert_default_prices. We assume we're upgrading to regular here. |
|
| 870 | + * If we're INSTALLING 4.1 CAF, then we add a few extra default prices |
|
| 871 | + * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 872 | + * EE_BRewing_regular |
|
| 873 | + * |
|
| 874 | + * @access public |
|
| 875 | + * @static |
|
| 876 | + * @return void |
|
| 877 | + */ |
|
| 878 | + public function insert_default_prices() |
|
| 879 | + { |
|
| 880 | + global $wpdb; |
|
| 881 | + $price_table = $wpdb->prefix . "esp_price"; |
|
| 882 | + if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 884 | + $prices_exist = $wpdb->get_var($SQL); |
|
| 885 | + if (! $prices_exist) { |
|
| 886 | + $SQL = "INSERT INTO $price_table |
|
| 887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
| 888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, null, 0, 0, 0);"; |
| 889 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 890 | - $wpdb->query($SQL); |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * insert default ticket |
|
| 899 | - * |
|
| 900 | - * @access public |
|
| 901 | - * @static |
|
| 902 | - * @return void |
|
| 903 | - */ |
|
| 904 | - public function insert_default_tickets() |
|
| 905 | - { |
|
| 906 | - global $wpdb; |
|
| 907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 908 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 910 | - $tickets_exist = $wpdb->get_var($SQL); |
|
| 911 | - if (! $tickets_exist) { |
|
| 912 | - $SQL = "INSERT INTO $ticket_table |
|
| 889 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 890 | + $wpdb->query($SQL); |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * insert default ticket |
|
| 899 | + * |
|
| 900 | + * @access public |
|
| 901 | + * @static |
|
| 902 | + * @return void |
|
| 903 | + */ |
|
| 904 | + public function insert_default_tickets() |
|
| 905 | + { |
|
| 906 | + global $wpdb; |
|
| 907 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 908 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 910 | + $tickets_exist = $wpdb->get_var($SQL); |
|
| 911 | + if (! $tickets_exist) { |
|
| 912 | + $SQL = "INSERT INTO $ticket_table |
|
| 913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
| 914 | 914 | ( 1, 0, '" |
| 915 | - . esc_html__("Free Ticket", "event_espresso") |
|
| 916 | - . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 917 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 918 | - $wpdb->query($SQL); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 922 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 924 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 925 | - if (! $ticket_prc_exist) { |
|
| 926 | - $SQL = "INSERT INTO $ticket_price_table |
|
| 915 | + . esc_html__("Free Ticket", "event_espresso") |
|
| 916 | + . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 917 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 918 | + $wpdb->query($SQL); |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 922 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 924 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 925 | + if (! $ticket_prc_exist) { |
|
| 926 | + $SQL = "INSERT INTO $ticket_price_table |
|
| 927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
| 928 | 928 | ( 1, 1, 1 ) |
| 929 | 929 | "; |
| 930 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 931 | - $wpdb->query($SQL); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 940 | - * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 941 | - * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 942 | - * |
|
| 943 | - * @global type $wpdb |
|
| 944 | - * @param string $country_name |
|
| 945 | - * @return array where keys are columns, values are column values |
|
| 946 | - */ |
|
| 947 | - public function get_or_create_country($country_name) |
|
| 948 | - { |
|
| 949 | - if (! $country_name) { |
|
| 950 | - throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
| 951 | - } |
|
| 952 | - global $wpdb; |
|
| 953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 954 | - if (is_int($country_name)) { |
|
| 955 | - $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 956 | - } |
|
| 957 | - $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 930 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 931 | + $wpdb->query($SQL); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 940 | + * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 941 | + * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 942 | + * |
|
| 943 | + * @global type $wpdb |
|
| 944 | + * @param string $country_name |
|
| 945 | + * @return array where keys are columns, values are column values |
|
| 946 | + */ |
|
| 947 | + public function get_or_create_country($country_name) |
|
| 948 | + { |
|
| 949 | + if (! $country_name) { |
|
| 950 | + throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
| 951 | + } |
|
| 952 | + global $wpdb; |
|
| 953 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 954 | + if (is_int($country_name)) { |
|
| 955 | + $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 956 | + } |
|
| 957 | + $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 958 | 958 | CNT_ISO LIKE %s OR |
| 959 | 959 | CNT_ISO3 LIKE %s OR |
| 960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
| 961 | - if (! $country) { |
|
| 962 | - // insert a new one then |
|
| 963 | - $cols_n_values = array( |
|
| 964 | - 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 965 | - 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 966 | - 'RGN_ID' => 0, |
|
| 967 | - 'CNT_name' => $country_name, |
|
| 968 | - 'CNT_cur_code' => 'USD', |
|
| 969 | - 'CNT_cur_single' => 'Dollar', |
|
| 970 | - 'CNT_cur_plural' => 'Dollars', |
|
| 971 | - 'CNT_cur_sign' => '$', |
|
| 972 | - 'CNT_cur_sign_b4' => true, |
|
| 973 | - 'CNT_cur_dec_plc' => 2, |
|
| 974 | - 'CNT_cur_dec_mrk' => '.', |
|
| 975 | - 'CNT_cur_thsnds' => ',', |
|
| 976 | - 'CNT_tel_code' => '+1', |
|
| 977 | - 'CNT_is_EU' => false, |
|
| 978 | - 'CNT_active' => true, |
|
| 979 | - ); |
|
| 980 | - $data_types = array( |
|
| 981 | - '%s',// CNT_ISO |
|
| 982 | - '%s',// CNT_ISO3 |
|
| 983 | - '%d',// RGN_ID |
|
| 984 | - '%s',// CNT_name |
|
| 985 | - '%s',// CNT_cur_code |
|
| 986 | - '%s',// CNT_cur_single |
|
| 987 | - '%s',// CNT_cur_plural |
|
| 988 | - '%s',// CNT_cur_sign |
|
| 989 | - '%d',// CNT_cur_sign_b4 |
|
| 990 | - '%d',// CNT_cur_dec_plc |
|
| 991 | - '%s',// CNT_cur_dec_mrk |
|
| 992 | - '%s',// CNT_cur_thsnds |
|
| 993 | - '%s',// CNT_tel_code |
|
| 994 | - '%d',// CNT_is_EU |
|
| 995 | - '%d',// CNT_active |
|
| 996 | - ); |
|
| 997 | - $success = $wpdb->insert( |
|
| 998 | - $country_table, |
|
| 999 | - $cols_n_values, |
|
| 1000 | - $data_types |
|
| 1001 | - ); |
|
| 1002 | - if (! $success) { |
|
| 1003 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1004 | - 'N/A', |
|
| 1005 | - array('country_id' => $country_name), |
|
| 1006 | - $country_table, |
|
| 1007 | - $cols_n_values, |
|
| 1008 | - $data_types |
|
| 1009 | - )); |
|
| 1010 | - } |
|
| 1011 | - $country = $cols_n_values; |
|
| 1012 | - } |
|
| 1013 | - return $country; |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * finds a country iso which hasnt been used yet |
|
| 1020 | - * |
|
| 1021 | - * @global type $wpdb |
|
| 1022 | - * @return string |
|
| 1023 | - */ |
|
| 1024 | - private function _find_available_country_iso($num_letters = 2) |
|
| 1025 | - { |
|
| 1026 | - global $wpdb; |
|
| 1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1028 | - $attempts = 0; |
|
| 1029 | - do { |
|
| 1030 | - $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1031 | - $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1032 | - . $country_table |
|
| 1033 | - . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1034 | - $attempts++; |
|
| 1035 | - // keep going until we find an available country code, or we arbitrarily |
|
| 1036 | - // decide we've tried this enough. Somehow they have way too many countries |
|
| 1037 | - // (probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | - return $current_iso; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1046 | - * is independent of outside code which can change in future versions of EE |
|
| 1047 | - * |
|
| 1048 | - * @global type $wpdb |
|
| 1049 | - * @param string $state_name |
|
| 1050 | - * @return array where keys are columns, values are column values |
|
| 1051 | - */ |
|
| 1052 | - public function get_or_create_state($state_name, $country_name = '') |
|
| 1053 | - { |
|
| 1054 | - if (! $state_name) { |
|
| 1055 | - throw new EE_Error(esc_html__( |
|
| 1056 | - "Could not get-or-create state because no state name was provided", |
|
| 1057 | - "event_espresso" |
|
| 1058 | - )); |
|
| 1059 | - } |
|
| 1060 | - try { |
|
| 1061 | - $country = $this->get_or_create_country($country_name); |
|
| 1062 | - $country_iso = $country['CNT_ISO']; |
|
| 1063 | - } catch (EE_Error $e) { |
|
| 1064 | - $country_iso = $this->get_default_country_iso(); |
|
| 1065 | - } |
|
| 1066 | - global $wpdb; |
|
| 1067 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1068 | - $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 961 | + if (! $country) { |
|
| 962 | + // insert a new one then |
|
| 963 | + $cols_n_values = array( |
|
| 964 | + 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 965 | + 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 966 | + 'RGN_ID' => 0, |
|
| 967 | + 'CNT_name' => $country_name, |
|
| 968 | + 'CNT_cur_code' => 'USD', |
|
| 969 | + 'CNT_cur_single' => 'Dollar', |
|
| 970 | + 'CNT_cur_plural' => 'Dollars', |
|
| 971 | + 'CNT_cur_sign' => '$', |
|
| 972 | + 'CNT_cur_sign_b4' => true, |
|
| 973 | + 'CNT_cur_dec_plc' => 2, |
|
| 974 | + 'CNT_cur_dec_mrk' => '.', |
|
| 975 | + 'CNT_cur_thsnds' => ',', |
|
| 976 | + 'CNT_tel_code' => '+1', |
|
| 977 | + 'CNT_is_EU' => false, |
|
| 978 | + 'CNT_active' => true, |
|
| 979 | + ); |
|
| 980 | + $data_types = array( |
|
| 981 | + '%s',// CNT_ISO |
|
| 982 | + '%s',// CNT_ISO3 |
|
| 983 | + '%d',// RGN_ID |
|
| 984 | + '%s',// CNT_name |
|
| 985 | + '%s',// CNT_cur_code |
|
| 986 | + '%s',// CNT_cur_single |
|
| 987 | + '%s',// CNT_cur_plural |
|
| 988 | + '%s',// CNT_cur_sign |
|
| 989 | + '%d',// CNT_cur_sign_b4 |
|
| 990 | + '%d',// CNT_cur_dec_plc |
|
| 991 | + '%s',// CNT_cur_dec_mrk |
|
| 992 | + '%s',// CNT_cur_thsnds |
|
| 993 | + '%s',// CNT_tel_code |
|
| 994 | + '%d',// CNT_is_EU |
|
| 995 | + '%d',// CNT_active |
|
| 996 | + ); |
|
| 997 | + $success = $wpdb->insert( |
|
| 998 | + $country_table, |
|
| 999 | + $cols_n_values, |
|
| 1000 | + $data_types |
|
| 1001 | + ); |
|
| 1002 | + if (! $success) { |
|
| 1003 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1004 | + 'N/A', |
|
| 1005 | + array('country_id' => $country_name), |
|
| 1006 | + $country_table, |
|
| 1007 | + $cols_n_values, |
|
| 1008 | + $data_types |
|
| 1009 | + )); |
|
| 1010 | + } |
|
| 1011 | + $country = $cols_n_values; |
|
| 1012 | + } |
|
| 1013 | + return $country; |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * finds a country iso which hasnt been used yet |
|
| 1020 | + * |
|
| 1021 | + * @global type $wpdb |
|
| 1022 | + * @return string |
|
| 1023 | + */ |
|
| 1024 | + private function _find_available_country_iso($num_letters = 2) |
|
| 1025 | + { |
|
| 1026 | + global $wpdb; |
|
| 1027 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 1028 | + $attempts = 0; |
|
| 1029 | + do { |
|
| 1030 | + $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1031 | + $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1032 | + . $country_table |
|
| 1033 | + . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1034 | + $attempts++; |
|
| 1035 | + // keep going until we find an available country code, or we arbitrarily |
|
| 1036 | + // decide we've tried this enough. Somehow they have way too many countries |
|
| 1037 | + // (probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1038 | + } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | + return $current_iso; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1046 | + * is independent of outside code which can change in future versions of EE |
|
| 1047 | + * |
|
| 1048 | + * @global type $wpdb |
|
| 1049 | + * @param string $state_name |
|
| 1050 | + * @return array where keys are columns, values are column values |
|
| 1051 | + */ |
|
| 1052 | + public function get_or_create_state($state_name, $country_name = '') |
|
| 1053 | + { |
|
| 1054 | + if (! $state_name) { |
|
| 1055 | + throw new EE_Error(esc_html__( |
|
| 1056 | + "Could not get-or-create state because no state name was provided", |
|
| 1057 | + "event_espresso" |
|
| 1058 | + )); |
|
| 1059 | + } |
|
| 1060 | + try { |
|
| 1061 | + $country = $this->get_or_create_country($country_name); |
|
| 1062 | + $country_iso = $country['CNT_ISO']; |
|
| 1063 | + } catch (EE_Error $e) { |
|
| 1064 | + $country_iso = $this->get_default_country_iso(); |
|
| 1065 | + } |
|
| 1066 | + global $wpdb; |
|
| 1067 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 1068 | + $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 1069 | 1069 | (STA_abbrev LIKE %s OR |
| 1070 | 1070 | STA_name LIKE %s) AND |
| 1071 | 1071 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
| 1072 | - if (! $state) { |
|
| 1073 | - // insert a new one then |
|
| 1074 | - $cols_n_values = array( |
|
| 1075 | - 'CNT_ISO' => $country_iso, |
|
| 1076 | - 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1077 | - 'STA_name' => $state_name, |
|
| 1078 | - 'STA_active' => true, |
|
| 1079 | - ); |
|
| 1080 | - $data_types = array( |
|
| 1081 | - '%s',// CNT_ISO |
|
| 1082 | - '%s',// STA_abbrev |
|
| 1083 | - '%s',// STA_name |
|
| 1084 | - '%d',// STA_active |
|
| 1085 | - ); |
|
| 1086 | - $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1087 | - if (! $success) { |
|
| 1088 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1089 | - 'N/A', |
|
| 1090 | - array('state' => $state_name, 'country_id' => $country_name), |
|
| 1091 | - $state_table, |
|
| 1092 | - $cols_n_values, |
|
| 1093 | - $data_types |
|
| 1094 | - )); |
|
| 1095 | - } |
|
| 1096 | - $state = $cols_n_values; |
|
| 1097 | - $state['STA_ID'] = $wpdb->insert_id; |
|
| 1098 | - } |
|
| 1099 | - return $state; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1106 | - * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1107 | - * |
|
| 1108 | - * @param type $timeString |
|
| 1109 | - * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1110 | - * with leading zeros) |
|
| 1111 | - */ |
|
| 1112 | - public function convertTimeFromAMPM($timeString) |
|
| 1113 | - { |
|
| 1114 | - $matches = array(); |
|
| 1115 | - preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1116 | - if (! $matches || count($matches) < 3) { |
|
| 1117 | - $hour = '00'; |
|
| 1118 | - $minutes = '00'; |
|
| 1119 | - } else { |
|
| 1120 | - $hour = intval($matches[1]); |
|
| 1121 | - $minutes = $matches[2]; |
|
| 1122 | - } |
|
| 1123 | - if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1124 | - $hour = intval($hour) + 12; |
|
| 1125 | - } |
|
| 1126 | - $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1127 | - $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1128 | - return "$hour:$minutes"; |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1135 | - * |
|
| 1136 | - * @param int $country_id |
|
| 1137 | - * @return string the country's ISO3 code |
|
| 1138 | - */ |
|
| 1139 | - public function get_iso_from_3_1_country_id($country_id) |
|
| 1140 | - { |
|
| 1141 | - $old_countries = array( |
|
| 1142 | - array(64, 'United States', 'US', 'USA', 1), |
|
| 1143 | - array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1144 | - array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1145 | - array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1146 | - array(70, 'France', 'FR', 'FRA', 2), |
|
| 1147 | - array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1148 | - array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1149 | - array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1150 | - array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1151 | - array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1152 | - array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1153 | - array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1154 | - array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1155 | - array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1156 | - array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1157 | - array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1158 | - array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1159 | - array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1160 | - array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1161 | - array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1162 | - array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1163 | - array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1164 | - array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1165 | - array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1166 | - array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1167 | - array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1168 | - array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1169 | - array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1170 | - array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1171 | - array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1172 | - array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1173 | - array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1174 | - array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1175 | - array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1176 | - array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1177 | - array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1178 | - array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1179 | - array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1180 | - array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1181 | - array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1182 | - array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1183 | - array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1184 | - array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1185 | - array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1186 | - array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1187 | - array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1188 | - array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1189 | - array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1190 | - array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1191 | - array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1192 | - array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1193 | - array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1194 | - array(42, 'China', 'CN', 'CHN', 1), |
|
| 1195 | - array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1196 | - array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1197 | - array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1198 | - array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1199 | - array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1200 | - array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1201 | - array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1202 | - array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1203 | - array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1204 | - array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1205 | - array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1206 | - array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1207 | - array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1208 | - array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1209 | - array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1210 | - array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1211 | - array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1212 | - array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1213 | - array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1214 | - array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1215 | - array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1216 | - array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1217 | - array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1218 | - array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1219 | - array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1220 | - array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1221 | - array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1222 | - array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1223 | - array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1224 | - array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1225 | - array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1226 | - array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1227 | - array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1228 | - array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1229 | - array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1230 | - array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1231 | - array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1232 | - array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1233 | - array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1234 | - array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1235 | - array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1236 | - array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1237 | - array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1238 | - array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1239 | - array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1240 | - array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1241 | - array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1242 | - array(91, 'India', 'IN', 'IND', 1), |
|
| 1243 | - array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1244 | - array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1245 | - array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1246 | - array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1247 | - array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1248 | - array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1249 | - array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1250 | - array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1251 | - array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1252 | - array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1253 | - array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1254 | - array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1255 | - array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1256 | - array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1257 | - array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1258 | - array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1259 | - array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1260 | - // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1261 | - array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1262 | - array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1263 | - array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1264 | - array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1265 | - array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1266 | - array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1267 | - array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1268 | - array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1269 | - array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1270 | - array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1271 | - array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1272 | - array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1273 | - array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1274 | - array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1275 | - array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1276 | - array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1277 | - array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1278 | - array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1279 | - array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1280 | - array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1281 | - array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1282 | - array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1283 | - array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1284 | - array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1285 | - array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1286 | - array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1287 | - array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1288 | - array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1289 | - array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1290 | - array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1291 | - array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1292 | - array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1293 | - array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1294 | - array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1295 | - array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1296 | - array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1297 | - array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1298 | - array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1299 | - array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1300 | - array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1301 | - array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1302 | - array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1303 | - array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1304 | - array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1305 | - array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1306 | - array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1307 | - array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1308 | - array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1309 | - array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1310 | - array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1311 | - array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1312 | - array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1313 | - array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1314 | - array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1315 | - array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1316 | - array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1317 | - array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1318 | - array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1319 | - array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1320 | - array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1321 | - array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1322 | - array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1323 | - array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1324 | - array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1325 | - array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1326 | - array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1327 | - array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1328 | - array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1329 | - array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1330 | - array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1331 | - array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1332 | - array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1333 | - array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1334 | - array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1335 | - array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1336 | - array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1337 | - array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1338 | - array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1339 | - array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1340 | - array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1341 | - array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1342 | - array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1343 | - array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1344 | - array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1345 | - array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1346 | - array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1347 | - array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1348 | - array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1349 | - array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1350 | - array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1351 | - array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1352 | - array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1353 | - array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1354 | - array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1355 | - array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1356 | - array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1357 | - array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1358 | - array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1359 | - array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1360 | - array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1361 | - array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1362 | - array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1363 | - array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1364 | - array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1365 | - ); |
|
| 1366 | - $country_iso = 'US'; |
|
| 1367 | - foreach ($old_countries as $country_array) { |
|
| 1368 | - // note: index 0 is the 3.1 country ID |
|
| 1369 | - if ($country_array[0] == $country_id) { |
|
| 1370 | - // note: index 2 is the ISO |
|
| 1371 | - $country_iso = $country_array[2]; |
|
| 1372 | - break; |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - return $country_iso; |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - |
|
| 1379 | - |
|
| 1380 | - /** |
|
| 1381 | - * Gets the ISO3 for the |
|
| 1382 | - * |
|
| 1383 | - * @return string |
|
| 1384 | - */ |
|
| 1385 | - public function get_default_country_iso() |
|
| 1386 | - { |
|
| 1387 | - $old_org_options = get_option('events_organization_settings'); |
|
| 1388 | - $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1389 | - return $iso; |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1396 | - * |
|
| 1397 | - * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1398 | - * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1399 | - * default payment status, the event's default payment status, or |
|
| 1400 | - * the attendee's payment status) required pre-approval. |
|
| 1401 | - * @return string STS_ID for use in 4.1 |
|
| 1402 | - */ |
|
| 1403 | - public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1404 | - { |
|
| 1405 | - // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1406 | - if ($this_thing_required_pre_approval) { |
|
| 1407 | - return 'RNA'; |
|
| 1408 | - } else { |
|
| 1409 | - $mapping = $default_reg_stati_conversions = array( |
|
| 1410 | - 'Completed' => 'RAP', |
|
| 1411 | - '' => 'RPP', |
|
| 1412 | - 'Incomplete' => 'RPP', |
|
| 1413 | - 'Pending' => 'RAP', |
|
| 1414 | - // stati that only occurred on 3.1 attendees: |
|
| 1415 | - 'Payment Declined' => 'RPP', |
|
| 1416 | - 'Not Completed' => 'RPP', |
|
| 1417 | - 'Cancelled' => 'RPP', |
|
| 1418 | - 'Declined' => 'RPP', |
|
| 1419 | - ); |
|
| 1420 | - } |
|
| 1421 | - return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1428 | - * and sets it as the featured image on the CPT event |
|
| 1429 | - * |
|
| 1430 | - * @param type $old_event |
|
| 1431 | - * @param type $new_cpt_id |
|
| 1432 | - * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1433 | - * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1434 | - */ |
|
| 1435 | - public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1436 | - $guid, |
|
| 1437 | - $new_cpt_id, |
|
| 1438 | - EE_Data_Migration_Script_Stage $migration_stage |
|
| 1439 | - ) { |
|
| 1440 | - $created_attachment_post = false; |
|
| 1441 | - $guid = $this->_get_original_guid($guid); |
|
| 1442 | - if ($guid) { |
|
| 1443 | - // check for an existing attachment post with this guid |
|
| 1444 | - $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1445 | - if (! $attachment_post_id) { |
|
| 1446 | - // post thumbnail with that GUID doesn't exist, we should create one |
|
| 1447 | - $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1448 | - $created_attachment_post = true; |
|
| 1449 | - } |
|
| 1450 | - // double-check we actually have an attachment post |
|
| 1451 | - if ($attachment_post_id) { |
|
| 1452 | - update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1453 | - } else { |
|
| 1454 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1455 | - "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1456 | - "event_espresso" |
|
| 1457 | - ), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1458 | - } |
|
| 1459 | - } |
|
| 1460 | - return $created_attachment_post; |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - |
|
| 1464 | - |
|
| 1465 | - /** |
|
| 1466 | - * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1467 | - * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1468 | - * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1469 | - * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1470 | - * exists |
|
| 1471 | - * |
|
| 1472 | - * @param string $guid_in_old_event |
|
| 1473 | - * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1474 | - */ |
|
| 1475 | - private function _get_original_guid($guid_in_old_event) |
|
| 1476 | - { |
|
| 1477 | - $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1478 | - // do a head request to verify the file exists |
|
| 1479 | - $head_response = wp_remote_head($original_guid); |
|
| 1480 | - if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1481 | - return $original_guid; |
|
| 1482 | - } else { |
|
| 1483 | - return $guid_in_old_event; |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - |
|
| 1488 | - |
|
| 1489 | - /** |
|
| 1490 | - * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1491 | - * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1492 | - * thumbnails) |
|
| 1493 | - * |
|
| 1494 | - * @param type $guid |
|
| 1495 | - * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1496 | - * @return int |
|
| 1497 | - */ |
|
| 1498 | - private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1499 | - { |
|
| 1500 | - if (! $guid) { |
|
| 1501 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1502 | - "Cannot create image attachment for a blank GUID!", |
|
| 1503 | - "event_espresso" |
|
| 1504 | - ))); |
|
| 1505 | - return 0; |
|
| 1506 | - } |
|
| 1507 | - $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1508 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1509 | - // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1510 | - if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1511 | - // image is located remotely. download it and place it in the uploads directory |
|
| 1512 | - if (! is_readable($guid)) { |
|
| 1513 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1514 | - "Could not create image attachment from non-existent file: %s", |
|
| 1515 | - "event_espresso" |
|
| 1516 | - ), $guid)); |
|
| 1517 | - return 0; |
|
| 1518 | - } |
|
| 1519 | - $contents = file_get_contents($guid); |
|
| 1520 | - if ($contents === false) { |
|
| 1521 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1522 | - "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1523 | - "event_espresso" |
|
| 1524 | - ), $guid)); |
|
| 1525 | - return false; |
|
| 1526 | - } |
|
| 1527 | - $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid); |
|
| 1528 | - $savefile = fopen($local_filepath, 'w'); |
|
| 1529 | - fwrite($savefile, $contents); |
|
| 1530 | - fclose($savefile); |
|
| 1531 | - $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1532 | - } else { |
|
| 1533 | - $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1534 | - } |
|
| 1535 | - $attachment = array( |
|
| 1536 | - 'guid' => $guid, |
|
| 1537 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1538 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1539 | - 'post_content' => '', |
|
| 1540 | - 'post_status' => 'inherit', |
|
| 1541 | - ); |
|
| 1542 | - $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1543 | - if (! $attach_id) { |
|
| 1544 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1545 | - "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1546 | - "event_espresso" |
|
| 1547 | - ), $guid, $this->_json_encode($attachment))); |
|
| 1548 | - return $attach_id; |
|
| 1549 | - } |
|
| 1550 | - // you must first include the image.php file |
|
| 1551 | - // for the function wp_generate_attachment_metadata() to work |
|
| 1552 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1553 | - $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1554 | - if (! $attach_data) { |
|
| 1555 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1556 | - "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1557 | - "event_espresso" |
|
| 1558 | - ), $attach_id, $local_filepath, $guid)); |
|
| 1559 | - return $attach_id; |
|
| 1560 | - } |
|
| 1561 | - $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1562 | - if (! $metadata_save_result) { |
|
| 1563 | - $migration_stage->add_error(sprintf(esc_html__( |
|
| 1564 | - "Could not update attachment metadata for attachment %d with data %s", |
|
| 1565 | - "event_espresso" |
|
| 1566 | - ), $attach_id, $this->_json_encode($attach_data))); |
|
| 1567 | - } |
|
| 1568 | - return $attach_id; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1575 | - * and returns its ID. |
|
| 1576 | - * |
|
| 1577 | - * @global type $wpdb |
|
| 1578 | - * @param string $guid |
|
| 1579 | - * @return int |
|
| 1580 | - */ |
|
| 1581 | - private function _get_image_attachment_id_by_GUID($guid) |
|
| 1582 | - { |
|
| 1583 | - global $wpdb; |
|
| 1584 | - $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1585 | - return $attachment_id; |
|
| 1586 | - } |
|
| 1587 | - |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - /** |
|
| 1591 | - * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1592 | - * (and optionally a timezone; if none is given, the wp default is used) |
|
| 1593 | - * |
|
| 1594 | - * @param EE_Data_Migration_Script_base $stage |
|
| 1595 | - * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1596 | - * UTC time for |
|
| 1597 | - * @param string $DATETIME_string |
|
| 1598 | - * @param string $timezone |
|
| 1599 | - * @return string |
|
| 1600 | - */ |
|
| 1601 | - public function convert_date_string_to_utc( |
|
| 1602 | - EE_Data_Migration_Script_Stage $stage, |
|
| 1603 | - $row_of_data, |
|
| 1604 | - $DATETIME_string, |
|
| 1605 | - $timezone = null |
|
| 1606 | - ) { |
|
| 1607 | - $original_tz = $timezone; |
|
| 1608 | - if (! $timezone) { |
|
| 1609 | - $timezone = $this->_get_wp_timezone(); |
|
| 1610 | - } |
|
| 1611 | - if (! $timezone) { |
|
| 1612 | - $stage->add_error(sprintf( |
|
| 1613 | - esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
| 1614 | - $original_tz, |
|
| 1615 | - $row_of_data |
|
| 1616 | - )); |
|
| 1617 | - $timezone = 'UTC'; |
|
| 1618 | - } |
|
| 1619 | - try { |
|
| 1620 | - $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1621 | - EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
| 1622 | - } catch (Exception $e) { |
|
| 1623 | - $stage->add_error(sprintf(esc_html__( |
|
| 1624 | - "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1625 | - "event_espresso" |
|
| 1626 | - ), $DATETIME_string, $timezone)); |
|
| 1627 | - $date_obj = new DateTime(); |
|
| 1628 | - } |
|
| 1629 | - return $date_obj->format('Y-m-d H:i:s'); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - /** |
|
| 1635 | - * Gets the default timezone string from wordpress (even if they set a gmt offset) |
|
| 1636 | - * |
|
| 1637 | - * @return string |
|
| 1638 | - */ |
|
| 1639 | - private function _get_wp_timezone() |
|
| 1640 | - { |
|
| 1641 | - $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1642 | - // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1643 | - if (empty($timezone)) { |
|
| 1644 | - // let's get a the WordPress UTC offset |
|
| 1645 | - $offset = get_option('gmt_offset'); |
|
| 1646 | - $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1647 | - } |
|
| 1648 | - return $timezone; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * Gets the wordpress timezone string from a UTC offset |
|
| 1655 | - * |
|
| 1656 | - * @param int $offset |
|
| 1657 | - * @return boolean |
|
| 1658 | - */ |
|
| 1659 | - private function timezone_convert_to_string_from_offset($offset) |
|
| 1660 | - { |
|
| 1661 | - // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did not work as expected - its not reliable |
|
| 1662 | - $offset *= 3600; // convert hour offset to seconds |
|
| 1663 | - $abbrarray = timezone_abbreviations_list(); |
|
| 1664 | - foreach ($abbrarray as $abbr) { |
|
| 1665 | - foreach ($abbr as $city) { |
|
| 1666 | - if ($city['offset'] == $offset) { |
|
| 1667 | - return $city['timezone_id']; |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - } |
|
| 1671 | - return false; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - public function migration_page_hooks() |
|
| 1677 | - { |
|
| 1678 | - add_filter( |
|
| 1679 | - 'FHEE__ee_migration_page__header', |
|
| 1680 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1681 | - 10, |
|
| 1682 | - 3 |
|
| 1683 | - ); |
|
| 1684 | - add_filter( |
|
| 1685 | - 'FHEE__ee_migration_page__p_after_header', |
|
| 1686 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1687 | - 10, |
|
| 1688 | - 2 |
|
| 1689 | - ); |
|
| 1690 | - add_filter( |
|
| 1691 | - 'FHEE__ee_migration_page__option_1_main', |
|
| 1692 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1693 | - 10, |
|
| 1694 | - 3 |
|
| 1695 | - ); |
|
| 1696 | - add_filter( |
|
| 1697 | - 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1698 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1699 | - 10, |
|
| 1700 | - 3 |
|
| 1701 | - ); |
|
| 1702 | - add_action( |
|
| 1703 | - 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1704 | - array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1705 | - 10, |
|
| 1706 | - 3 |
|
| 1707 | - ); |
|
| 1708 | - add_filter( |
|
| 1709 | - 'FHEE__ee_migration_page__option_2_main', |
|
| 1710 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1711 | - 10, |
|
| 1712 | - 4 |
|
| 1713 | - ); |
|
| 1714 | - add_filter( |
|
| 1715 | - 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1716 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1717 | - 10, |
|
| 1718 | - 2 |
|
| 1719 | - ); |
|
| 1720 | - add_filter( |
|
| 1721 | - 'FHEE__ee_migration_page__option_2_details', |
|
| 1722 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1723 | - 10, |
|
| 1724 | - 2 |
|
| 1725 | - ); |
|
| 1726 | - add_action( |
|
| 1727 | - 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1728 | - array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1729 | - ); |
|
| 1730 | - add_filter( |
|
| 1731 | - 'FHEE__ee_migration_page__done_migration_header', |
|
| 1732 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1733 | - 10, |
|
| 1734 | - 2 |
|
| 1735 | - ); |
|
| 1736 | - add_filter( |
|
| 1737 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1738 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1739 | - 10, |
|
| 1740 | - 2 |
|
| 1741 | - ); |
|
| 1742 | - add_filter( |
|
| 1743 | - 'FHEE__ee_migration_page__migration_options_template', |
|
| 1744 | - array($this,'use_migration_options_from_ee3_template') |
|
| 1745 | - ); |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - |
|
| 1749 | - |
|
| 1750 | - public function _migrate_page_hook_simplify_version_strings( |
|
| 1751 | - $old_content, |
|
| 1752 | - $current_db_state, |
|
| 1753 | - $next_db_state, |
|
| 1754 | - $ultimate_db_state = null |
|
| 1755 | - ) { |
|
| 1756 | - return str_replace( |
|
| 1757 | - array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1758 | - array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
| 1759 | - $old_content |
|
| 1760 | - ); |
|
| 1761 | - } |
|
| 1762 | - |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1766 | - { |
|
| 1767 | - return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
| 1768 | - } |
|
| 1769 | - |
|
| 1770 | - |
|
| 1771 | - |
|
| 1772 | - public function _migration_page_hook_option_1_extra_details() |
|
| 1773 | - { |
|
| 1774 | - ?> |
|
| 1072 | + if (! $state) { |
|
| 1073 | + // insert a new one then |
|
| 1074 | + $cols_n_values = array( |
|
| 1075 | + 'CNT_ISO' => $country_iso, |
|
| 1076 | + 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1077 | + 'STA_name' => $state_name, |
|
| 1078 | + 'STA_active' => true, |
|
| 1079 | + ); |
|
| 1080 | + $data_types = array( |
|
| 1081 | + '%s',// CNT_ISO |
|
| 1082 | + '%s',// STA_abbrev |
|
| 1083 | + '%s',// STA_name |
|
| 1084 | + '%d',// STA_active |
|
| 1085 | + ); |
|
| 1086 | + $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1087 | + if (! $success) { |
|
| 1088 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
| 1089 | + 'N/A', |
|
| 1090 | + array('state' => $state_name, 'country_id' => $country_name), |
|
| 1091 | + $state_table, |
|
| 1092 | + $cols_n_values, |
|
| 1093 | + $data_types |
|
| 1094 | + )); |
|
| 1095 | + } |
|
| 1096 | + $state = $cols_n_values; |
|
| 1097 | + $state['STA_ID'] = $wpdb->insert_id; |
|
| 1098 | + } |
|
| 1099 | + return $state; |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1106 | + * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1107 | + * |
|
| 1108 | + * @param type $timeString |
|
| 1109 | + * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1110 | + * with leading zeros) |
|
| 1111 | + */ |
|
| 1112 | + public function convertTimeFromAMPM($timeString) |
|
| 1113 | + { |
|
| 1114 | + $matches = array(); |
|
| 1115 | + preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1116 | + if (! $matches || count($matches) < 3) { |
|
| 1117 | + $hour = '00'; |
|
| 1118 | + $minutes = '00'; |
|
| 1119 | + } else { |
|
| 1120 | + $hour = intval($matches[1]); |
|
| 1121 | + $minutes = $matches[2]; |
|
| 1122 | + } |
|
| 1123 | + if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1124 | + $hour = intval($hour) + 12; |
|
| 1125 | + } |
|
| 1126 | + $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1127 | + $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1128 | + return "$hour:$minutes"; |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1135 | + * |
|
| 1136 | + * @param int $country_id |
|
| 1137 | + * @return string the country's ISO3 code |
|
| 1138 | + */ |
|
| 1139 | + public function get_iso_from_3_1_country_id($country_id) |
|
| 1140 | + { |
|
| 1141 | + $old_countries = array( |
|
| 1142 | + array(64, 'United States', 'US', 'USA', 1), |
|
| 1143 | + array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1144 | + array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1145 | + array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1146 | + array(70, 'France', 'FR', 'FRA', 2), |
|
| 1147 | + array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1148 | + array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1149 | + array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1150 | + array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1151 | + array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1152 | + array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1153 | + array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1154 | + array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1155 | + array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1156 | + array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1157 | + array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1158 | + array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1159 | + array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1160 | + array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1161 | + array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1162 | + array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1163 | + array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1164 | + array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1165 | + array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1166 | + array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1167 | + array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1168 | + array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1169 | + array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1170 | + array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1171 | + array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1172 | + array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1173 | + array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1174 | + array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1175 | + array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1176 | + array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1177 | + array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1178 | + array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1179 | + array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1180 | + array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1181 | + array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1182 | + array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1183 | + array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1184 | + array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1185 | + array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1186 | + array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1187 | + array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1188 | + array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1189 | + array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1190 | + array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1191 | + array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1192 | + array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1193 | + array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1194 | + array(42, 'China', 'CN', 'CHN', 1), |
|
| 1195 | + array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1196 | + array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1197 | + array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1198 | + array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1199 | + array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1200 | + array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1201 | + array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1202 | + array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1203 | + array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1204 | + array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1205 | + array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1206 | + array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1207 | + array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1208 | + array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1209 | + array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1210 | + array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1211 | + array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1212 | + array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1213 | + array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1214 | + array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1215 | + array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1216 | + array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1217 | + array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1218 | + array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1219 | + array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1220 | + array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1221 | + array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1222 | + array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1223 | + array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1224 | + array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1225 | + array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1226 | + array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1227 | + array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1228 | + array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1229 | + array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1230 | + array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1231 | + array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1232 | + array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1233 | + array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1234 | + array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1235 | + array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1236 | + array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1237 | + array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1238 | + array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1239 | + array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1240 | + array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1241 | + array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1242 | + array(91, 'India', 'IN', 'IND', 1), |
|
| 1243 | + array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1244 | + array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1245 | + array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1246 | + array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1247 | + array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1248 | + array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1249 | + array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1250 | + array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1251 | + array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1252 | + array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1253 | + array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1254 | + array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1255 | + array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1256 | + array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1257 | + array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1258 | + array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1259 | + array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1260 | + // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1261 | + array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1262 | + array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1263 | + array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1264 | + array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1265 | + array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1266 | + array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1267 | + array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1268 | + array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1269 | + array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1270 | + array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1271 | + array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1272 | + array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1273 | + array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1274 | + array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1275 | + array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1276 | + array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1277 | + array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1278 | + array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1279 | + array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1280 | + array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1281 | + array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1282 | + array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1283 | + array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1284 | + array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1285 | + array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1286 | + array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1287 | + array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1288 | + array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1289 | + array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1290 | + array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1291 | + array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1292 | + array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1293 | + array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1294 | + array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1295 | + array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1296 | + array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1297 | + array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1298 | + array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1299 | + array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1300 | + array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1301 | + array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1302 | + array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1303 | + array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1304 | + array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1305 | + array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1306 | + array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1307 | + array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1308 | + array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1309 | + array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1310 | + array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1311 | + array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1312 | + array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1313 | + array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1314 | + array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1315 | + array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1316 | + array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1317 | + array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1318 | + array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1319 | + array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1320 | + array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1321 | + array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1322 | + array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1323 | + array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1324 | + array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1325 | + array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1326 | + array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1327 | + array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1328 | + array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1329 | + array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1330 | + array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1331 | + array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1332 | + array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1333 | + array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1334 | + array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1335 | + array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1336 | + array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1337 | + array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1338 | + array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1339 | + array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1340 | + array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1341 | + array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1342 | + array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1343 | + array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1344 | + array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1345 | + array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1346 | + array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1347 | + array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1348 | + array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1349 | + array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1350 | + array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1351 | + array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1352 | + array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1353 | + array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1354 | + array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1355 | + array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1356 | + array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1357 | + array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1358 | + array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1359 | + array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1360 | + array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1361 | + array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1362 | + array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1363 | + array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1364 | + array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1365 | + ); |
|
| 1366 | + $country_iso = 'US'; |
|
| 1367 | + foreach ($old_countries as $country_array) { |
|
| 1368 | + // note: index 0 is the 3.1 country ID |
|
| 1369 | + if ($country_array[0] == $country_id) { |
|
| 1370 | + // note: index 2 is the ISO |
|
| 1371 | + $country_iso = $country_array[2]; |
|
| 1372 | + break; |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + return $country_iso; |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + |
|
| 1379 | + |
|
| 1380 | + /** |
|
| 1381 | + * Gets the ISO3 for the |
|
| 1382 | + * |
|
| 1383 | + * @return string |
|
| 1384 | + */ |
|
| 1385 | + public function get_default_country_iso() |
|
| 1386 | + { |
|
| 1387 | + $old_org_options = get_option('events_organization_settings'); |
|
| 1388 | + $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1389 | + return $iso; |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1396 | + * |
|
| 1397 | + * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1398 | + * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1399 | + * default payment status, the event's default payment status, or |
|
| 1400 | + * the attendee's payment status) required pre-approval. |
|
| 1401 | + * @return string STS_ID for use in 4.1 |
|
| 1402 | + */ |
|
| 1403 | + public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1404 | + { |
|
| 1405 | + // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1406 | + if ($this_thing_required_pre_approval) { |
|
| 1407 | + return 'RNA'; |
|
| 1408 | + } else { |
|
| 1409 | + $mapping = $default_reg_stati_conversions = array( |
|
| 1410 | + 'Completed' => 'RAP', |
|
| 1411 | + '' => 'RPP', |
|
| 1412 | + 'Incomplete' => 'RPP', |
|
| 1413 | + 'Pending' => 'RAP', |
|
| 1414 | + // stati that only occurred on 3.1 attendees: |
|
| 1415 | + 'Payment Declined' => 'RPP', |
|
| 1416 | + 'Not Completed' => 'RPP', |
|
| 1417 | + 'Cancelled' => 'RPP', |
|
| 1418 | + 'Declined' => 'RPP', |
|
| 1419 | + ); |
|
| 1420 | + } |
|
| 1421 | + return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1428 | + * and sets it as the featured image on the CPT event |
|
| 1429 | + * |
|
| 1430 | + * @param type $old_event |
|
| 1431 | + * @param type $new_cpt_id |
|
| 1432 | + * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1433 | + * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1434 | + */ |
|
| 1435 | + public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1436 | + $guid, |
|
| 1437 | + $new_cpt_id, |
|
| 1438 | + EE_Data_Migration_Script_Stage $migration_stage |
|
| 1439 | + ) { |
|
| 1440 | + $created_attachment_post = false; |
|
| 1441 | + $guid = $this->_get_original_guid($guid); |
|
| 1442 | + if ($guid) { |
|
| 1443 | + // check for an existing attachment post with this guid |
|
| 1444 | + $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1445 | + if (! $attachment_post_id) { |
|
| 1446 | + // post thumbnail with that GUID doesn't exist, we should create one |
|
| 1447 | + $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1448 | + $created_attachment_post = true; |
|
| 1449 | + } |
|
| 1450 | + // double-check we actually have an attachment post |
|
| 1451 | + if ($attachment_post_id) { |
|
| 1452 | + update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1453 | + } else { |
|
| 1454 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1455 | + "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1456 | + "event_espresso" |
|
| 1457 | + ), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1458 | + } |
|
| 1459 | + } |
|
| 1460 | + return $created_attachment_post; |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + |
|
| 1464 | + |
|
| 1465 | + /** |
|
| 1466 | + * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1467 | + * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1468 | + * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1469 | + * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1470 | + * exists |
|
| 1471 | + * |
|
| 1472 | + * @param string $guid_in_old_event |
|
| 1473 | + * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1474 | + */ |
|
| 1475 | + private function _get_original_guid($guid_in_old_event) |
|
| 1476 | + { |
|
| 1477 | + $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1478 | + // do a head request to verify the file exists |
|
| 1479 | + $head_response = wp_remote_head($original_guid); |
|
| 1480 | + if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1481 | + return $original_guid; |
|
| 1482 | + } else { |
|
| 1483 | + return $guid_in_old_event; |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + |
|
| 1488 | + |
|
| 1489 | + /** |
|
| 1490 | + * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1491 | + * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1492 | + * thumbnails) |
|
| 1493 | + * |
|
| 1494 | + * @param type $guid |
|
| 1495 | + * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1496 | + * @return int |
|
| 1497 | + */ |
|
| 1498 | + private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1499 | + { |
|
| 1500 | + if (! $guid) { |
|
| 1501 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1502 | + "Cannot create image attachment for a blank GUID!", |
|
| 1503 | + "event_espresso" |
|
| 1504 | + ))); |
|
| 1505 | + return 0; |
|
| 1506 | + } |
|
| 1507 | + $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1508 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1509 | + // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1510 | + if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1511 | + // image is located remotely. download it and place it in the uploads directory |
|
| 1512 | + if (! is_readable($guid)) { |
|
| 1513 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1514 | + "Could not create image attachment from non-existent file: %s", |
|
| 1515 | + "event_espresso" |
|
| 1516 | + ), $guid)); |
|
| 1517 | + return 0; |
|
| 1518 | + } |
|
| 1519 | + $contents = file_get_contents($guid); |
|
| 1520 | + if ($contents === false) { |
|
| 1521 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1522 | + "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1523 | + "event_espresso" |
|
| 1524 | + ), $guid)); |
|
| 1525 | + return false; |
|
| 1526 | + } |
|
| 1527 | + $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid); |
|
| 1528 | + $savefile = fopen($local_filepath, 'w'); |
|
| 1529 | + fwrite($savefile, $contents); |
|
| 1530 | + fclose($savefile); |
|
| 1531 | + $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1532 | + } else { |
|
| 1533 | + $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1534 | + } |
|
| 1535 | + $attachment = array( |
|
| 1536 | + 'guid' => $guid, |
|
| 1537 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1538 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1539 | + 'post_content' => '', |
|
| 1540 | + 'post_status' => 'inherit', |
|
| 1541 | + ); |
|
| 1542 | + $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1543 | + if (! $attach_id) { |
|
| 1544 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1545 | + "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1546 | + "event_espresso" |
|
| 1547 | + ), $guid, $this->_json_encode($attachment))); |
|
| 1548 | + return $attach_id; |
|
| 1549 | + } |
|
| 1550 | + // you must first include the image.php file |
|
| 1551 | + // for the function wp_generate_attachment_metadata() to work |
|
| 1552 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1553 | + $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1554 | + if (! $attach_data) { |
|
| 1555 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1556 | + "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1557 | + "event_espresso" |
|
| 1558 | + ), $attach_id, $local_filepath, $guid)); |
|
| 1559 | + return $attach_id; |
|
| 1560 | + } |
|
| 1561 | + $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1562 | + if (! $metadata_save_result) { |
|
| 1563 | + $migration_stage->add_error(sprintf(esc_html__( |
|
| 1564 | + "Could not update attachment metadata for attachment %d with data %s", |
|
| 1565 | + "event_espresso" |
|
| 1566 | + ), $attach_id, $this->_json_encode($attach_data))); |
|
| 1567 | + } |
|
| 1568 | + return $attach_id; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1575 | + * and returns its ID. |
|
| 1576 | + * |
|
| 1577 | + * @global type $wpdb |
|
| 1578 | + * @param string $guid |
|
| 1579 | + * @return int |
|
| 1580 | + */ |
|
| 1581 | + private function _get_image_attachment_id_by_GUID($guid) |
|
| 1582 | + { |
|
| 1583 | + global $wpdb; |
|
| 1584 | + $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1585 | + return $attachment_id; |
|
| 1586 | + } |
|
| 1587 | + |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + /** |
|
| 1591 | + * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1592 | + * (and optionally a timezone; if none is given, the wp default is used) |
|
| 1593 | + * |
|
| 1594 | + * @param EE_Data_Migration_Script_base $stage |
|
| 1595 | + * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1596 | + * UTC time for |
|
| 1597 | + * @param string $DATETIME_string |
|
| 1598 | + * @param string $timezone |
|
| 1599 | + * @return string |
|
| 1600 | + */ |
|
| 1601 | + public function convert_date_string_to_utc( |
|
| 1602 | + EE_Data_Migration_Script_Stage $stage, |
|
| 1603 | + $row_of_data, |
|
| 1604 | + $DATETIME_string, |
|
| 1605 | + $timezone = null |
|
| 1606 | + ) { |
|
| 1607 | + $original_tz = $timezone; |
|
| 1608 | + if (! $timezone) { |
|
| 1609 | + $timezone = $this->_get_wp_timezone(); |
|
| 1610 | + } |
|
| 1611 | + if (! $timezone) { |
|
| 1612 | + $stage->add_error(sprintf( |
|
| 1613 | + esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
| 1614 | + $original_tz, |
|
| 1615 | + $row_of_data |
|
| 1616 | + )); |
|
| 1617 | + $timezone = 'UTC'; |
|
| 1618 | + } |
|
| 1619 | + try { |
|
| 1620 | + $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1621 | + EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
| 1622 | + } catch (Exception $e) { |
|
| 1623 | + $stage->add_error(sprintf(esc_html__( |
|
| 1624 | + "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1625 | + "event_espresso" |
|
| 1626 | + ), $DATETIME_string, $timezone)); |
|
| 1627 | + $date_obj = new DateTime(); |
|
| 1628 | + } |
|
| 1629 | + return $date_obj->format('Y-m-d H:i:s'); |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + /** |
|
| 1635 | + * Gets the default timezone string from wordpress (even if they set a gmt offset) |
|
| 1636 | + * |
|
| 1637 | + * @return string |
|
| 1638 | + */ |
|
| 1639 | + private function _get_wp_timezone() |
|
| 1640 | + { |
|
| 1641 | + $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1642 | + // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1643 | + if (empty($timezone)) { |
|
| 1644 | + // let's get a the WordPress UTC offset |
|
| 1645 | + $offset = get_option('gmt_offset'); |
|
| 1646 | + $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1647 | + } |
|
| 1648 | + return $timezone; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * Gets the wordpress timezone string from a UTC offset |
|
| 1655 | + * |
|
| 1656 | + * @param int $offset |
|
| 1657 | + * @return boolean |
|
| 1658 | + */ |
|
| 1659 | + private function timezone_convert_to_string_from_offset($offset) |
|
| 1660 | + { |
|
| 1661 | + // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did not work as expected - its not reliable |
|
| 1662 | + $offset *= 3600; // convert hour offset to seconds |
|
| 1663 | + $abbrarray = timezone_abbreviations_list(); |
|
| 1664 | + foreach ($abbrarray as $abbr) { |
|
| 1665 | + foreach ($abbr as $city) { |
|
| 1666 | + if ($city['offset'] == $offset) { |
|
| 1667 | + return $city['timezone_id']; |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + } |
|
| 1671 | + return false; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + public function migration_page_hooks() |
|
| 1677 | + { |
|
| 1678 | + add_filter( |
|
| 1679 | + 'FHEE__ee_migration_page__header', |
|
| 1680 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1681 | + 10, |
|
| 1682 | + 3 |
|
| 1683 | + ); |
|
| 1684 | + add_filter( |
|
| 1685 | + 'FHEE__ee_migration_page__p_after_header', |
|
| 1686 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1687 | + 10, |
|
| 1688 | + 2 |
|
| 1689 | + ); |
|
| 1690 | + add_filter( |
|
| 1691 | + 'FHEE__ee_migration_page__option_1_main', |
|
| 1692 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1693 | + 10, |
|
| 1694 | + 3 |
|
| 1695 | + ); |
|
| 1696 | + add_filter( |
|
| 1697 | + 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1698 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1699 | + 10, |
|
| 1700 | + 3 |
|
| 1701 | + ); |
|
| 1702 | + add_action( |
|
| 1703 | + 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1704 | + array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1705 | + 10, |
|
| 1706 | + 3 |
|
| 1707 | + ); |
|
| 1708 | + add_filter( |
|
| 1709 | + 'FHEE__ee_migration_page__option_2_main', |
|
| 1710 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1711 | + 10, |
|
| 1712 | + 4 |
|
| 1713 | + ); |
|
| 1714 | + add_filter( |
|
| 1715 | + 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1716 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1717 | + 10, |
|
| 1718 | + 2 |
|
| 1719 | + ); |
|
| 1720 | + add_filter( |
|
| 1721 | + 'FHEE__ee_migration_page__option_2_details', |
|
| 1722 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1723 | + 10, |
|
| 1724 | + 2 |
|
| 1725 | + ); |
|
| 1726 | + add_action( |
|
| 1727 | + 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1728 | + array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1729 | + ); |
|
| 1730 | + add_filter( |
|
| 1731 | + 'FHEE__ee_migration_page__done_migration_header', |
|
| 1732 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1733 | + 10, |
|
| 1734 | + 2 |
|
| 1735 | + ); |
|
| 1736 | + add_filter( |
|
| 1737 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1738 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1739 | + 10, |
|
| 1740 | + 2 |
|
| 1741 | + ); |
|
| 1742 | + add_filter( |
|
| 1743 | + 'FHEE__ee_migration_page__migration_options_template', |
|
| 1744 | + array($this,'use_migration_options_from_ee3_template') |
|
| 1745 | + ); |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + |
|
| 1749 | + |
|
| 1750 | + public function _migrate_page_hook_simplify_version_strings( |
|
| 1751 | + $old_content, |
|
| 1752 | + $current_db_state, |
|
| 1753 | + $next_db_state, |
|
| 1754 | + $ultimate_db_state = null |
|
| 1755 | + ) { |
|
| 1756 | + return str_replace( |
|
| 1757 | + array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1758 | + array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
| 1759 | + $old_content |
|
| 1760 | + ); |
|
| 1761 | + } |
|
| 1762 | + |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1766 | + { |
|
| 1767 | + return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
| 1768 | + } |
|
| 1769 | + |
|
| 1770 | + |
|
| 1771 | + |
|
| 1772 | + public function _migration_page_hook_option_1_extra_details() |
|
| 1773 | + { |
|
| 1774 | + ?> |
|
| 1775 | 1775 | <p><?php printf(esc_html__( |
| 1776 | - "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
| 1777 | - "event_espresso" |
|
| 1778 | - )); ?></p><?php |
|
| 1779 | - } |
|
| 1776 | + "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
| 1777 | + "event_espresso" |
|
| 1778 | + )); ?></p><?php |
|
| 1779 | + } |
|
| 1780 | 1780 | |
| 1781 | 1781 | |
| 1782 | 1782 | |
| 1783 | - public function _migration_page_hook_after_migration_options_table() |
|
| 1784 | - { |
|
| 1785 | - ?><p class="ee-attention"> |
|
| 1783 | + public function _migration_page_hook_after_migration_options_table() |
|
| 1784 | + { |
|
| 1785 | + ?><p class="ee-attention"> |
|
| 1786 | 1786 | <strong><span class="reminder-spn"> |
| 1787 | 1787 | <?php _e( |
| 1788 | - "Important note to those using Event Espresso 3 addons: ", |
|
| 1789 | - "event_espresso" |
|
| 1790 | - ); ?></span></strong> |
|
| 1788 | + "Important note to those using Event Espresso 3 addons: ", |
|
| 1789 | + "event_espresso" |
|
| 1790 | + ); ?></span></strong> |
|
| 1791 | 1791 | <br/> |
| 1792 | 1792 | <?php _e( |
| 1793 | - "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
| 1794 | - "event_espresso" |
|
| 1795 | - ); ?> |
|
| 1793 | + "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
| 1794 | + "event_espresso" |
|
| 1795 | + ); ?> |
|
| 1796 | 1796 | </p><?php |
| 1797 | - } |
|
| 1797 | + } |
|
| 1798 | 1798 | |
| 1799 | 1799 | |
| 1800 | 1800 | |
| 1801 | - /** |
|
| 1802 | - * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
| 1803 | - * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
| 1804 | - * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
| 1805 | - * @param $template_filepath |
|
| 1806 | - * @return string |
|
| 1807 | - */ |
|
| 1808 | - public function use_migration_options_from_ee3_template($template_filepath) |
|
| 1809 | - { |
|
| 1810 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1811 | - } |
|
| 1801 | + /** |
|
| 1802 | + * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
| 1803 | + * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
| 1804 | + * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
| 1805 | + * @param $template_filepath |
|
| 1806 | + * @return string |
|
| 1807 | + */ |
|
| 1808 | + public function use_migration_options_from_ee3_template($template_filepath) |
|
| 1809 | + { |
|
| 1810 | + return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1811 | + } |
|
| 1812 | 1812 | } |
@@ -9,13 +9,13 @@ discard block |
||
| 9 | 9 | // unfortunately, this needs to be done upon INCLUSION of this file, |
| 10 | 10 | // instead of construction, because it only gets constructed on first page load |
| 11 | 11 | // (all other times it gets resurrected from a wordpress option) |
| 12 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
|
| 12 | +$stages = glob(EE_CORE.'data_migration_scripts/4_1_0_stages/*'); |
|
| 13 | 13 | $class_to_filepath = array(); |
| 14 | -if (! empty($stages)) { |
|
| 14 | +if ( ! empty($stages)) { |
|
| 15 | 15 | foreach ($stages as $filepath) { |
| 16 | 16 | $matches = array(); |
| 17 | 17 | preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
| 18 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 18 | + $class_to_filepath[$matches[1]] = $filepath; |
|
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | // give addons a chance to autoload their stages too |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | private function _checkin_table_exists() |
| 88 | 88 | { |
| 89 | 89 | global $wpdb; |
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '".$wpdb->prefix."events_attendee_checkin"."'"); |
|
| 91 | 91 | if ($results) { |
| 92 | 92 | return true; |
| 93 | 93 | } else { |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
| 104 | 104 | // echo "$version_string can be migrated fro"; |
| 105 | 105 | return true; |
| 106 | - } elseif (! $version_string) { |
|
| 106 | + } elseif ( ! $version_string) { |
|
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | 108 | // no version string provided... this must be pre 4.1 |
| 109 | 109 | // because since 4.1 we're |
| 110 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 110 | + return false; // changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | 111 | } else { |
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | 113 | return false; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function schema_changes_before_migration() |
| 120 | 120 | { |
| 121 | 121 | // relies on 4.1's EEH_Activation::create_table |
| 122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 122 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
| 123 | 123 | $table_name = 'esp_answer'; |
| 124 | 124 | $sql = "ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 125 | 125 | REG_ID int(10) unsigned NOT NULL, |
@@ -503,12 +503,12 @@ discard block |
||
| 503 | 503 | public function insert_default_states() |
| 504 | 504 | { |
| 505 | 505 | global $wpdb; |
| 506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 506 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 507 | 507 | if ($this->_get_table_analysis()->tableExists($state_table)) { |
| 508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 508 | + $SQL = "SELECT COUNT('STA_ID') FROM ".$state_table; |
|
| 509 | 509 | $states = $wpdb->get_var($SQL); |
| 510 | - if (! $states) { |
|
| 511 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 510 | + if ( ! $states) { |
|
| 511 | + $SQL = "INSERT INTO ".$state_table." |
|
| 512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
| 514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | public function insert_default_countries() |
| 597 | 597 | { |
| 598 | 598 | global $wpdb; |
| 599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 599 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 600 | 600 | if ($this->_get_table_analysis()->tableExists($country_table)) { |
| 601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM ".$country_table; |
|
| 602 | 602 | $countries = $wpdb->get_var($SQL); |
| 603 | - if (! $countries) { |
|
| 604 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 603 | + if ( ! $countries) { |
|
| 604 | + $SQL = "INSERT INTO ".$country_table." |
|
| 605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -846,17 +846,17 @@ discard block |
||
| 846 | 846 | public function insert_default_price_types() |
| 847 | 847 | { |
| 848 | 848 | global $wpdb; |
| 849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 849 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
| 850 | 850 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
| 851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table; |
|
| 852 | 852 | $price_types_exist = $wpdb->get_var($SQL); |
| 853 | - if (! $price_types_exist) { |
|
| 853 | + if ( ! $price_types_exist) { |
|
| 854 | 854 | $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
| 855 | - (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
|
| 856 | - (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
|
| 857 | - (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
|
| 858 | - (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
|
| 859 | - (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
|
| 855 | + (1, '".esc_html__('Base Price', 'event_espresso')."', 1, 0, 0, 0), |
|
| 856 | + (2, '" . esc_html__('Percent Discount', 'event_espresso')."', 2, 1, 20, 0), |
|
| 857 | + (3, '" . esc_html__('Fixed Discount', 'event_espresso')."', 2, 0, 30, 0), |
|
| 858 | + (4, '" . esc_html__('Percent Surcharge', 'event_espresso')."', 3, 1, 40, 0), |
|
| 859 | + (5, '" . esc_html__('Fixed Surcharge', 'event_espresso')."', 3, 0, 50, 0);"; |
|
| 860 | 860 | $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
| 861 | 861 | $wpdb->query($SQL); |
| 862 | 862 | } |
@@ -878,11 +878,11 @@ discard block |
||
| 878 | 878 | public function insert_default_prices() |
| 879 | 879 | { |
| 880 | 880 | global $wpdb; |
| 881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 881 | + $price_table = $wpdb->prefix."esp_price"; |
|
| 882 | 882 | if ($this->_get_table_analysis()->tableExists($price_table)) { |
| 883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table; |
|
| 884 | 884 | $prices_exist = $wpdb->get_var($SQL); |
| 885 | - if (! $prices_exist) { |
|
| 885 | + if ( ! $prices_exist) { |
|
| 886 | 886 | $SQL = "INSERT INTO $price_table |
| 887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
| 888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, null, 0, 0, 0);"; |
@@ -904,11 +904,11 @@ discard block |
||
| 904 | 904 | public function insert_default_tickets() |
| 905 | 905 | { |
| 906 | 906 | global $wpdb; |
| 907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 907 | + $ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 908 | 908 | if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
| 909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table; |
|
| 910 | 910 | $tickets_exist = $wpdb->get_var($SQL); |
| 911 | - if (! $tickets_exist) { |
|
| 911 | + if ( ! $tickets_exist) { |
|
| 912 | 912 | $SQL = "INSERT INTO $ticket_table |
| 913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
| 914 | 914 | ( 1, 0, '" |
@@ -918,11 +918,11 @@ discard block |
||
| 918 | 918 | $wpdb->query($SQL); |
| 919 | 919 | } |
| 920 | 920 | } |
| 921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 921 | + $ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 922 | 922 | if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
| 923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table; |
|
| 924 | 924 | $ticket_prc_exist = $wpdb->get_var($SQL); |
| 925 | - if (! $ticket_prc_exist) { |
|
| 925 | + if ( ! $ticket_prc_exist) { |
|
| 926 | 926 | $SQL = "INSERT INTO $ticket_price_table |
| 927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
| 928 | 928 | ( 1, 1, 1 ) |
@@ -946,11 +946,11 @@ discard block |
||
| 946 | 946 | */ |
| 947 | 947 | public function get_or_create_country($country_name) |
| 948 | 948 | { |
| 949 | - if (! $country_name) { |
|
| 949 | + if ( ! $country_name) { |
|
| 950 | 950 | throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
| 951 | 951 | } |
| 952 | 952 | global $wpdb; |
| 953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 953 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 954 | 954 | if (is_int($country_name)) { |
| 955 | 955 | $country_name = $this->get_iso_from_3_1_country_id($country_name); |
| 956 | 956 | } |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | CNT_ISO LIKE %s OR |
| 959 | 959 | CNT_ISO3 LIKE %s OR |
| 960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
| 961 | - if (! $country) { |
|
| 961 | + if ( ! $country) { |
|
| 962 | 962 | // insert a new one then |
| 963 | 963 | $cols_n_values = array( |
| 964 | 964 | 'CNT_ISO' => $this->_find_available_country_iso(2), |
@@ -978,28 +978,28 @@ discard block |
||
| 978 | 978 | 'CNT_active' => true, |
| 979 | 979 | ); |
| 980 | 980 | $data_types = array( |
| 981 | - '%s',// CNT_ISO |
|
| 982 | - '%s',// CNT_ISO3 |
|
| 983 | - '%d',// RGN_ID |
|
| 984 | - '%s',// CNT_name |
|
| 985 | - '%s',// CNT_cur_code |
|
| 986 | - '%s',// CNT_cur_single |
|
| 987 | - '%s',// CNT_cur_plural |
|
| 988 | - '%s',// CNT_cur_sign |
|
| 989 | - '%d',// CNT_cur_sign_b4 |
|
| 990 | - '%d',// CNT_cur_dec_plc |
|
| 991 | - '%s',// CNT_cur_dec_mrk |
|
| 992 | - '%s',// CNT_cur_thsnds |
|
| 993 | - '%s',// CNT_tel_code |
|
| 994 | - '%d',// CNT_is_EU |
|
| 995 | - '%d',// CNT_active |
|
| 981 | + '%s', // CNT_ISO |
|
| 982 | + '%s', // CNT_ISO3 |
|
| 983 | + '%d', // RGN_ID |
|
| 984 | + '%s', // CNT_name |
|
| 985 | + '%s', // CNT_cur_code |
|
| 986 | + '%s', // CNT_cur_single |
|
| 987 | + '%s', // CNT_cur_plural |
|
| 988 | + '%s', // CNT_cur_sign |
|
| 989 | + '%d', // CNT_cur_sign_b4 |
|
| 990 | + '%d', // CNT_cur_dec_plc |
|
| 991 | + '%s', // CNT_cur_dec_mrk |
|
| 992 | + '%s', // CNT_cur_thsnds |
|
| 993 | + '%s', // CNT_tel_code |
|
| 994 | + '%d', // CNT_is_EU |
|
| 995 | + '%d', // CNT_active |
|
| 996 | 996 | ); |
| 997 | 997 | $success = $wpdb->insert( |
| 998 | 998 | $country_table, |
| 999 | 999 | $cols_n_values, |
| 1000 | 1000 | $data_types |
| 1001 | 1001 | ); |
| 1002 | - if (! $success) { |
|
| 1002 | + if ( ! $success) { |
|
| 1003 | 1003 | throw new EE_Error($this->_create_error_message_for_db_insertion( |
| 1004 | 1004 | 'N/A', |
| 1005 | 1005 | array('country_id' => $country_name), |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | private function _find_available_country_iso($num_letters = 2) |
| 1025 | 1025 | { |
| 1026 | 1026 | global $wpdb; |
| 1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1027 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 1028 | 1028 | $attempts = 0; |
| 1029 | 1029 | do { |
| 1030 | 1030 | $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | // keep going until we find an available country code, or we arbitrarily |
| 1036 | 1036 | // decide we've tried this enough. Somehow they have way too many countries |
| 1037 | 1037 | // (probably because they're mis-using the EE3 country_id like a custom question) |
| 1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1038 | + }while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | 1039 | return $current_iso; |
| 1040 | 1040 | } |
| 1041 | 1041 | |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | */ |
| 1052 | 1052 | public function get_or_create_state($state_name, $country_name = '') |
| 1053 | 1053 | { |
| 1054 | - if (! $state_name) { |
|
| 1054 | + if ( ! $state_name) { |
|
| 1055 | 1055 | throw new EE_Error(esc_html__( |
| 1056 | 1056 | "Could not get-or-create state because no state name was provided", |
| 1057 | 1057 | "event_espresso" |
@@ -1064,12 +1064,12 @@ discard block |
||
| 1064 | 1064 | $country_iso = $this->get_default_country_iso(); |
| 1065 | 1065 | } |
| 1066 | 1066 | global $wpdb; |
| 1067 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1067 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 1068 | 1068 | $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
| 1069 | 1069 | (STA_abbrev LIKE %s OR |
| 1070 | 1070 | STA_name LIKE %s) AND |
| 1071 | 1071 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
| 1072 | - if (! $state) { |
|
| 1072 | + if ( ! $state) { |
|
| 1073 | 1073 | // insert a new one then |
| 1074 | 1074 | $cols_n_values = array( |
| 1075 | 1075 | 'CNT_ISO' => $country_iso, |
@@ -1078,13 +1078,13 @@ discard block |
||
| 1078 | 1078 | 'STA_active' => true, |
| 1079 | 1079 | ); |
| 1080 | 1080 | $data_types = array( |
| 1081 | - '%s',// CNT_ISO |
|
| 1082 | - '%s',// STA_abbrev |
|
| 1083 | - '%s',// STA_name |
|
| 1084 | - '%d',// STA_active |
|
| 1081 | + '%s', // CNT_ISO |
|
| 1082 | + '%s', // STA_abbrev |
|
| 1083 | + '%s', // STA_name |
|
| 1084 | + '%d', // STA_active |
|
| 1085 | 1085 | ); |
| 1086 | 1086 | $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
| 1087 | - if (! $success) { |
|
| 1087 | + if ( ! $success) { |
|
| 1088 | 1088 | throw new EE_Error($this->_create_error_message_for_db_insertion( |
| 1089 | 1089 | 'N/A', |
| 1090 | 1090 | array('state' => $state_name, 'country_id' => $country_name), |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | { |
| 1114 | 1114 | $matches = array(); |
| 1115 | 1115 | preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
| 1116 | - if (! $matches || count($matches) < 3) { |
|
| 1116 | + if ( ! $matches || count($matches) < 3) { |
|
| 1117 | 1117 | $hour = '00'; |
| 1118 | 1118 | $minutes = '00'; |
| 1119 | 1119 | } else { |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | 'Declined' => 'RPP', |
| 1419 | 1419 | ); |
| 1420 | 1420 | } |
| 1421 | - return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
| 1421 | + return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA'; |
|
| 1422 | 1422 | } |
| 1423 | 1423 | |
| 1424 | 1424 | |
@@ -1442,7 +1442,7 @@ discard block |
||
| 1442 | 1442 | if ($guid) { |
| 1443 | 1443 | // check for an existing attachment post with this guid |
| 1444 | 1444 | $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
| 1445 | - if (! $attachment_post_id) { |
|
| 1445 | + if ( ! $attachment_post_id) { |
|
| 1446 | 1446 | // post thumbnail with that GUID doesn't exist, we should create one |
| 1447 | 1447 | $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
| 1448 | 1448 | $created_attachment_post = true; |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
| 1478 | 1478 | // do a head request to verify the file exists |
| 1479 | 1479 | $head_response = wp_remote_head($original_guid); |
| 1480 | - if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1480 | + if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1481 | 1481 | return $original_guid; |
| 1482 | 1482 | } else { |
| 1483 | 1483 | return $guid_in_old_event; |
@@ -1497,7 +1497,7 @@ discard block |
||
| 1497 | 1497 | */ |
| 1498 | 1498 | private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
| 1499 | 1499 | { |
| 1500 | - if (! $guid) { |
|
| 1500 | + if ( ! $guid) { |
|
| 1501 | 1501 | $migration_stage->add_error(sprintf(esc_html__( |
| 1502 | 1502 | "Cannot create image attachment for a blank GUID!", |
| 1503 | 1503 | "event_espresso" |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
| 1510 | 1510 | if (strpos($guid, $wp_upload_dir['url']) === false) { |
| 1511 | 1511 | // image is located remotely. download it and place it in the uploads directory |
| 1512 | - if (! is_readable($guid)) { |
|
| 1512 | + if ( ! is_readable($guid)) { |
|
| 1513 | 1513 | $migration_stage->add_error(sprintf(esc_html__( |
| 1514 | 1514 | "Could not create image attachment from non-existent file: %s", |
| 1515 | 1515 | "event_espresso" |
@@ -1524,7 +1524,7 @@ discard block |
||
| 1524 | 1524 | ), $guid)); |
| 1525 | 1525 | return false; |
| 1526 | 1526 | } |
| 1527 | - $local_filepath = $wp_upload_dir['path'] . '/' . basename($guid); |
|
| 1527 | + $local_filepath = $wp_upload_dir['path'].'/'.basename($guid); |
|
| 1528 | 1528 | $savefile = fopen($local_filepath, 'w'); |
| 1529 | 1529 | fwrite($savefile, $contents); |
| 1530 | 1530 | fclose($savefile); |
@@ -1540,7 +1540,7 @@ discard block |
||
| 1540 | 1540 | 'post_status' => 'inherit', |
| 1541 | 1541 | ); |
| 1542 | 1542 | $attach_id = wp_insert_attachment($attachment, $guid); |
| 1543 | - if (! $attach_id) { |
|
| 1543 | + if ( ! $attach_id) { |
|
| 1544 | 1544 | $migration_stage->add_error(sprintf(esc_html__( |
| 1545 | 1545 | "Could not create image attachment post from image '%s'. Attachment data was %s.", |
| 1546 | 1546 | "event_espresso" |
@@ -1549,9 +1549,9 @@ discard block |
||
| 1549 | 1549 | } |
| 1550 | 1550 | // you must first include the image.php file |
| 1551 | 1551 | // for the function wp_generate_attachment_metadata() to work |
| 1552 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1552 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
| 1553 | 1553 | $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
| 1554 | - if (! $attach_data) { |
|
| 1554 | + if ( ! $attach_data) { |
|
| 1555 | 1555 | $migration_stage->add_error(sprintf(esc_html__( |
| 1556 | 1556 | "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
| 1557 | 1557 | "event_espresso" |
@@ -1559,7 +1559,7 @@ discard block |
||
| 1559 | 1559 | return $attach_id; |
| 1560 | 1560 | } |
| 1561 | 1561 | $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
| 1562 | - if (! $metadata_save_result) { |
|
| 1562 | + if ( ! $metadata_save_result) { |
|
| 1563 | 1563 | $migration_stage->add_error(sprintf(esc_html__( |
| 1564 | 1564 | "Could not update attachment metadata for attachment %d with data %s", |
| 1565 | 1565 | "event_espresso" |
@@ -1605,10 +1605,10 @@ discard block |
||
| 1605 | 1605 | $timezone = null |
| 1606 | 1606 | ) { |
| 1607 | 1607 | $original_tz = $timezone; |
| 1608 | - if (! $timezone) { |
|
| 1608 | + if ( ! $timezone) { |
|
| 1609 | 1609 | $timezone = $this->_get_wp_timezone(); |
| 1610 | 1610 | } |
| 1611 | - if (! $timezone) { |
|
| 1611 | + if ( ! $timezone) { |
|
| 1612 | 1612 | $stage->add_error(sprintf( |
| 1613 | 1613 | esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
| 1614 | 1614 | $original_tz, |
@@ -1741,7 +1741,7 @@ discard block |
||
| 1741 | 1741 | ); |
| 1742 | 1742 | add_filter( |
| 1743 | 1743 | 'FHEE__ee_migration_page__migration_options_template', |
| 1744 | - array($this,'use_migration_options_from_ee3_template') |
|
| 1744 | + array($this, 'use_migration_options_from_ee3_template') |
|
| 1745 | 1745 | ); |
| 1746 | 1746 | } |
| 1747 | 1747 | |
@@ -1807,6 +1807,6 @@ discard block |
||
| 1807 | 1807 | */ |
| 1808 | 1808 | public function use_migration_options_from_ee3_template($template_filepath) |
| 1809 | 1809 | { |
| 1810 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
| 1810 | + return EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee3.template.php'; |
|
| 1811 | 1811 | } |
| 1812 | 1812 | } |
@@ -14,2509 +14,2509 @@ discard block |
||
| 14 | 14 | final class EE_Config implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const OPTION_NAME = 'ee_config'; |
|
| 18 | - |
|
| 19 | - const LOG_NAME = 'ee_config_log'; |
|
| 20 | - |
|
| 21 | - const LOG_LENGTH = 100; |
|
| 22 | - |
|
| 23 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * instance of the EE_Config object |
|
| 27 | - * |
|
| 28 | - * @var EE_Config $_instance |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean $_logging_enabled |
|
| 35 | - */ |
|
| 36 | - private static $_logging_enabled = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | - */ |
|
| 41 | - private $legacy_shortcodes_manager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * An StdClass whose property names are addon slugs, |
|
| 45 | - * and values are their config classes |
|
| 46 | - * |
|
| 47 | - * @var StdClass |
|
| 48 | - */ |
|
| 49 | - public $addons; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Admin_Config |
|
| 53 | - */ |
|
| 54 | - public $admin; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Core_Config |
|
| 58 | - */ |
|
| 59 | - public $core; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Currency_Config |
|
| 63 | - */ |
|
| 64 | - public $currency; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Organization_Config |
|
| 68 | - */ |
|
| 69 | - public $organization; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_Registration_Config |
|
| 73 | - */ |
|
| 74 | - public $registration; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Template_Config |
|
| 78 | - */ |
|
| 79 | - public $template_settings; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Holds EE environment values. |
|
| 83 | - * |
|
| 84 | - * @var EE_Environment_Config |
|
| 85 | - */ |
|
| 86 | - public $environment; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * settings pertaining to Google maps |
|
| 90 | - * |
|
| 91 | - * @var EE_Map_Config |
|
| 92 | - */ |
|
| 93 | - public $map_settings; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * settings pertaining to Taxes |
|
| 97 | - * |
|
| 98 | - * @var EE_Tax_Config |
|
| 99 | - */ |
|
| 100 | - public $tax_settings; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Settings pertaining to global messages settings. |
|
| 104 | - * |
|
| 105 | - * @var EE_Messages_Config |
|
| 106 | - */ |
|
| 107 | - public $messages; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated |
|
| 111 | - * @var EE_Gateway_Config |
|
| 112 | - */ |
|
| 113 | - public $gateway; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var array $_addon_option_names |
|
| 117 | - * @access private |
|
| 118 | - */ |
|
| 119 | - private $_addon_option_names = array(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array $_module_route_map |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 125 | - private static $_module_route_map = array(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array $_module_forward_map |
|
| 129 | - * @access private |
|
| 130 | - */ |
|
| 131 | - private static $_module_forward_map = array(); |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @var array $_module_view_map |
|
| 135 | - * @access private |
|
| 136 | - */ |
|
| 137 | - private static $_module_view_map = array(); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @singleton method used to instantiate class object |
|
| 142 | - * @access public |
|
| 143 | - * @return EE_Config instance |
|
| 144 | - */ |
|
| 145 | - public static function instance() |
|
| 146 | - { |
|
| 147 | - // check if class object is instantiated, and instantiated properly |
|
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 149 | - self::$_instance = new self(); |
|
| 150 | - } |
|
| 151 | - return self::$_instance; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Resets the config |
|
| 157 | - * |
|
| 158 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | - * reflect its state in the database |
|
| 161 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | - * site was put into maintenance mode) |
|
| 165 | - * @return EE_Config |
|
| 166 | - */ |
|
| 167 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | - { |
|
| 169 | - if (self::$_instance instanceof EE_Config) { |
|
| 170 | - if ($hard_reset) { |
|
| 171 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | - self::$_instance->_addon_option_names = array(); |
|
| 173 | - self::$_instance->_initialize_config(); |
|
| 174 | - self::$_instance->update_espresso_config(); |
|
| 175 | - } |
|
| 176 | - self::$_instance->update_addon_option_names(); |
|
| 177 | - } |
|
| 178 | - self::$_instance = null; |
|
| 179 | - // we don't need to reset the static properties imo because those should |
|
| 180 | - // only change when a module is added or removed. Currently we don't |
|
| 181 | - // support removing a module during a request when it previously existed |
|
| 182 | - if ($reinstantiate) { |
|
| 183 | - return self::instance(); |
|
| 184 | - } else { |
|
| 185 | - return null; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * class constructor |
|
| 192 | - * |
|
| 193 | - * @access private |
|
| 194 | - */ |
|
| 195 | - private function __construct() |
|
| 196 | - { |
|
| 197 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | - // setup empty config classes |
|
| 200 | - $this->_initialize_config(); |
|
| 201 | - // load existing EE site settings |
|
| 202 | - $this->_load_core_config(); |
|
| 203 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | - $this->_verify_config(); |
|
| 205 | - // register shortcodes and modules |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | - array($this, 'register_shortcodes_and_modules'), |
|
| 209 | - 999 |
|
| 210 | - ); |
|
| 211 | - // initialize shortcodes and modules |
|
| 212 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | - // register widgets |
|
| 214 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | - // shutdown |
|
| 216 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | - // construct__end hook |
|
| 218 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | - // hardcoded hack |
|
| 220 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return boolean |
|
| 226 | - */ |
|
| 227 | - public static function logging_enabled() |
|
| 228 | - { |
|
| 229 | - return self::$_logging_enabled; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * use to get the current theme if needed from static context |
|
| 235 | - * |
|
| 236 | - * @return string current theme set. |
|
| 237 | - */ |
|
| 238 | - public static function get_current_theme() |
|
| 239 | - { |
|
| 240 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * _initialize_config |
|
| 247 | - * |
|
| 248 | - * @access private |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - private function _initialize_config() |
|
| 252 | - { |
|
| 253 | - EE_Config::trim_log(); |
|
| 254 | - // set defaults |
|
| 255 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | - $this->addons = new stdClass(); |
|
| 257 | - // set _module_route_map |
|
| 258 | - EE_Config::$_module_route_map = array(); |
|
| 259 | - // set _module_forward_map |
|
| 260 | - EE_Config::$_module_forward_map = array(); |
|
| 261 | - // set _module_view_map |
|
| 262 | - EE_Config::$_module_view_map = array(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * load core plugin configuration |
|
| 268 | - * |
|
| 269 | - * @access private |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - private function _load_core_config() |
|
| 273 | - { |
|
| 274 | - // load_core_config__start hook |
|
| 275 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | - $espresso_config = $this->get_espresso_config(); |
|
| 277 | - foreach ($espresso_config as $config => $settings) { |
|
| 278 | - // load_core_config__start hook |
|
| 279 | - $settings = apply_filters( |
|
| 280 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | - $settings, |
|
| 282 | - $config, |
|
| 283 | - $this |
|
| 284 | - ); |
|
| 285 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | - // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | - if (method_exists($settings, 'populate')) { |
|
| 289 | - $this->{$config}->populate(); |
|
| 290 | - } |
|
| 291 | - if (method_exists($settings, 'do_hooks')) { |
|
| 292 | - $this->{$config}->do_hooks(); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | - $this->update_espresso_config(); |
|
| 298 | - } |
|
| 299 | - // load_core_config__end hook |
|
| 300 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * _verify_config |
|
| 306 | - * |
|
| 307 | - * @access protected |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - protected function _verify_config() |
|
| 311 | - { |
|
| 312 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | - ? $this->core |
|
| 314 | - : new EE_Core_Config(); |
|
| 315 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | - ? $this->organization |
|
| 318 | - : new EE_Organization_Config(); |
|
| 319 | - $this->organization = apply_filters( |
|
| 320 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | - $this->organization |
|
| 322 | - ); |
|
| 323 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | - ? $this->currency |
|
| 325 | - : new EE_Currency_Config(); |
|
| 326 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | - ? $this->registration |
|
| 329 | - : new EE_Registration_Config(); |
|
| 330 | - $this->registration = apply_filters( |
|
| 331 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | - $this->registration |
|
| 333 | - ); |
|
| 334 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | - ? $this->admin |
|
| 336 | - : new EE_Admin_Config(); |
|
| 337 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | - ? $this->template_settings |
|
| 340 | - : new EE_Template_Config(); |
|
| 341 | - $this->template_settings = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | - $this->template_settings |
|
| 344 | - ); |
|
| 345 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | - ? $this->map_settings |
|
| 347 | - : new EE_Map_Config(); |
|
| 348 | - $this->map_settings = apply_filters( |
|
| 349 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | - $this->map_settings |
|
| 351 | - ); |
|
| 352 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | - ? $this->environment |
|
| 354 | - : new EE_Environment_Config(); |
|
| 355 | - $this->environment = apply_filters( |
|
| 356 | - 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | - $this->environment |
|
| 358 | - ); |
|
| 359 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | - ? $this->tax_settings |
|
| 361 | - : new EE_Tax_Config(); |
|
| 362 | - $this->tax_settings = apply_filters( |
|
| 363 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | - $this->tax_settings |
|
| 365 | - ); |
|
| 366 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | - ? $this->messages |
|
| 369 | - : new EE_Messages_Config(); |
|
| 370 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | - ? $this->gateway |
|
| 372 | - : new EE_Gateway_Config(); |
|
| 373 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | - $this->legacy_shortcodes_manager = null; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * get_espresso_config |
|
| 380 | - * |
|
| 381 | - * @access public |
|
| 382 | - * @return array of espresso config stuff |
|
| 383 | - */ |
|
| 384 | - public function get_espresso_config() |
|
| 385 | - { |
|
| 386 | - // grab espresso configuration |
|
| 387 | - return apply_filters( |
|
| 388 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * double_check_config_comparison |
|
| 396 | - * |
|
| 397 | - * @access public |
|
| 398 | - * @param string $option |
|
| 399 | - * @param $old_value |
|
| 400 | - * @param $value |
|
| 401 | - */ |
|
| 402 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | - { |
|
| 404 | - // make sure we're checking the ee config |
|
| 405 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | - if ($value != $old_value) { |
|
| 409 | - // if they are NOT the same, then remove the hook, |
|
| 410 | - // which means the subsequent update results will be based solely on the update query results |
|
| 411 | - // the reason we do this is because, as stated above, |
|
| 412 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | - // If values are found to match their previous old value, |
|
| 415 | - // then WP bails before performing any update. |
|
| 416 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | - // MySQL MAY ALSO NOT perform the update because |
|
| 420 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * update_espresso_config |
|
| 431 | - * |
|
| 432 | - * @access public |
|
| 433 | - */ |
|
| 434 | - protected function _reset_espresso_addon_config() |
|
| 435 | - { |
|
| 436 | - $this->_addon_option_names = array(); |
|
| 437 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | - } |
|
| 442 | - $this->addons->{$addon_name} = null; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * update_espresso_config |
|
| 449 | - * |
|
| 450 | - * @access public |
|
| 451 | - * @param bool $add_success |
|
| 452 | - * @param bool $add_error |
|
| 453 | - * @return bool |
|
| 454 | - */ |
|
| 455 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | - { |
|
| 457 | - // don't allow config updates during WP heartbeats |
|
| 458 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | - // $clone = clone( self::$_instance ); |
|
| 463 | - // self::$_instance = NULL; |
|
| 464 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | - $this->_reset_espresso_addon_config(); |
|
| 466 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | - // but BEFORE the actual update occurs |
|
| 468 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | - $this->legacy_shortcodes_manager = null; |
|
| 472 | - // now update "ee_config" |
|
| 473 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | - // if not saved... check if the hook we just added still exists; |
|
| 477 | - // if it does, it means one of two things: |
|
| 478 | - // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | - // or... |
|
| 480 | - // the db update query returned 0 rows affected |
|
| 481 | - // (probably because the data value was the same from it's perspective) |
|
| 482 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | - // but just means no update occurred, so don't display an error to the user. |
|
| 484 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | - // then it means that something truly went wrong |
|
| 486 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | - // remove our action since we don't want it in the system anymore |
|
| 488 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | - // self::$_instance = $clone; |
|
| 491 | - // unset( $clone ); |
|
| 492 | - // if config remains the same or was updated successfully |
|
| 493 | - if ($saved) { |
|
| 494 | - if ($add_success) { |
|
| 495 | - EE_Error::add_success( |
|
| 496 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | - __FILE__, |
|
| 498 | - __FUNCTION__, |
|
| 499 | - __LINE__ |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - return true; |
|
| 503 | - } else { |
|
| 504 | - if ($add_error) { |
|
| 505 | - EE_Error::add_error( |
|
| 506 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * _verify_config_params |
|
| 519 | - * |
|
| 520 | - * @access private |
|
| 521 | - * @param string $section |
|
| 522 | - * @param string $name |
|
| 523 | - * @param string $config_class |
|
| 524 | - * @param EE_Config_Base $config_obj |
|
| 525 | - * @param array $tests_to_run |
|
| 526 | - * @param bool $display_errors |
|
| 527 | - * @return bool TRUE on success, FALSE on fail |
|
| 528 | - */ |
|
| 529 | - private function _verify_config_params( |
|
| 530 | - $section = '', |
|
| 531 | - $name = '', |
|
| 532 | - $config_class = '', |
|
| 533 | - $config_obj = null, |
|
| 534 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | - $display_errors = true |
|
| 536 | - ) { |
|
| 537 | - try { |
|
| 538 | - foreach ($tests_to_run as $test) { |
|
| 539 | - switch ($test) { |
|
| 540 | - // TEST #1 : check that section was set |
|
| 541 | - case 1: |
|
| 542 | - if (empty($section)) { |
|
| 543 | - if ($display_errors) { |
|
| 544 | - throw new EE_Error( |
|
| 545 | - sprintf( |
|
| 546 | - __( |
|
| 547 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ), |
|
| 550 | - $config_class |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - break; |
|
| 557 | - // TEST #2 : check that settings section exists |
|
| 558 | - case 2: |
|
| 559 | - if (! isset($this->{$section})) { |
|
| 560 | - if ($display_errors) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - sprintf( |
|
| 563 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | - $section |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - break; |
|
| 571 | - // TEST #3 : check that section is the proper format |
|
| 572 | - case 3: |
|
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | - ) { |
|
| 575 | - if ($display_errors) { |
|
| 576 | - throw new EE_Error( |
|
| 577 | - sprintf( |
|
| 578 | - __( |
|
| 579 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ), |
|
| 582 | - $section |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - return false; |
|
| 587 | - } |
|
| 588 | - break; |
|
| 589 | - // TEST #4 : check that config section name has been set |
|
| 590 | - case 4: |
|
| 591 | - if (empty($name)) { |
|
| 592 | - if ($display_errors) { |
|
| 593 | - throw new EE_Error( |
|
| 594 | - __( |
|
| 595 | - 'No name has been provided for the specific configuration section.', |
|
| 596 | - 'event_espresso' |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - break; |
|
| 603 | - // TEST #5 : check that a config class name has been set |
|
| 604 | - case 5: |
|
| 605 | - if (empty($config_class)) { |
|
| 606 | - if ($display_errors) { |
|
| 607 | - throw new EE_Error( |
|
| 608 | - __( |
|
| 609 | - 'No class name has been provided for the specific configuration section.', |
|
| 610 | - 'event_espresso' |
|
| 611 | - ) |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - return false; |
|
| 615 | - } |
|
| 616 | - break; |
|
| 617 | - // TEST #6 : verify config class is accessible |
|
| 618 | - case 6: |
|
| 619 | - if (! class_exists($config_class)) { |
|
| 620 | - if ($display_errors) { |
|
| 621 | - throw new EE_Error( |
|
| 622 | - sprintf( |
|
| 623 | - __( |
|
| 624 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | - 'event_espresso' |
|
| 626 | - ), |
|
| 627 | - $config_class |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - break; |
|
| 634 | - // TEST #7 : check that config has even been set |
|
| 635 | - case 7: |
|
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 637 | - if ($display_errors) { |
|
| 638 | - throw new EE_Error( |
|
| 639 | - sprintf( |
|
| 640 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | - $section, |
|
| 642 | - $name |
|
| 643 | - ) |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } else { |
|
| 648 | - // and make sure it's not serialized |
|
| 649 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | - } |
|
| 651 | - break; |
|
| 652 | - // TEST #8 : check that config is the requested type |
|
| 653 | - case 8: |
|
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | - if ($display_errors) { |
|
| 656 | - throw new EE_Error( |
|
| 657 | - sprintf( |
|
| 658 | - __( |
|
| 659 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | - 'event_espresso' |
|
| 661 | - ), |
|
| 662 | - $section, |
|
| 663 | - $name, |
|
| 664 | - $config_class |
|
| 665 | - ) |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - return false; |
|
| 669 | - } |
|
| 670 | - break; |
|
| 671 | - // TEST #9 : verify config object |
|
| 672 | - case 9: |
|
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | - if ($display_errors) { |
|
| 675 | - throw new EE_Error( |
|
| 676 | - sprintf( |
|
| 677 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | - print_r($config_obj, true) |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - return false; |
|
| 683 | - } |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } catch (EE_Error $e) { |
|
| 688 | - $e->get_error(); |
|
| 689 | - } |
|
| 690 | - // you have successfully run the gauntlet |
|
| 691 | - return true; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * _generate_config_option_name |
|
| 697 | - * |
|
| 698 | - * @access protected |
|
| 699 | - * @param string $section |
|
| 700 | - * @param string $name |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | - { |
|
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * _set_config_class |
|
| 711 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | - * |
|
| 713 | - * @access private |
|
| 714 | - * @param string $config_class |
|
| 715 | - * @param string $name |
|
| 716 | - * @return string |
|
| 717 | - */ |
|
| 718 | - private function _set_config_class($config_class = '', $name = '') |
|
| 719 | - { |
|
| 720 | - return ! empty($config_class) |
|
| 721 | - ? $config_class |
|
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * set_config |
|
| 728 | - * |
|
| 729 | - * @access protected |
|
| 730 | - * @param string $section |
|
| 731 | - * @param string $name |
|
| 732 | - * @param string $config_class |
|
| 733 | - * @param EE_Config_Base $config_obj |
|
| 734 | - * @return EE_Config_Base |
|
| 735 | - */ |
|
| 736 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | - { |
|
| 738 | - // ensure config class is set to something |
|
| 739 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | - return null; |
|
| 743 | - } |
|
| 744 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | - $this->update_addon_option_names(); |
|
| 749 | - } |
|
| 750 | - // verify the incoming config object but suppress errors |
|
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | - $config_obj = new $config_class(); |
|
| 753 | - } |
|
| 754 | - if (get_option($config_option_name)) { |
|
| 755 | - EE_Config::log($config_option_name); |
|
| 756 | - update_option($config_option_name, $config_obj); |
|
| 757 | - $this->{$section}->{$name} = $config_obj; |
|
| 758 | - return $this->{$section}->{$name}; |
|
| 759 | - } else { |
|
| 760 | - // create a wp-option for this config |
|
| 761 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | - return $this->{$section}->{$name}; |
|
| 764 | - } else { |
|
| 765 | - EE_Error::add_error( |
|
| 766 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | - __FILE__, |
|
| 768 | - __FUNCTION__, |
|
| 769 | - __LINE__ |
|
| 770 | - ); |
|
| 771 | - return null; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * update_config |
|
| 779 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | - * |
|
| 781 | - * @access public |
|
| 782 | - * @param string $section |
|
| 783 | - * @param string $name |
|
| 784 | - * @param EE_Config_Base|string $config_obj |
|
| 785 | - * @param bool $throw_errors |
|
| 786 | - * @return bool |
|
| 787 | - */ |
|
| 788 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | - { |
|
| 790 | - // don't allow config updates during WP heartbeats |
|
| 791 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - $config_obj = maybe_unserialize($config_obj); |
|
| 795 | - // get class name of the incoming object |
|
| 796 | - $config_class = get_class($config_obj); |
|
| 797 | - // run tests 1-5 and 9 to verify config |
|
| 798 | - if (! $this->_verify_config_params( |
|
| 799 | - $section, |
|
| 800 | - $name, |
|
| 801 | - $config_class, |
|
| 802 | - $config_obj, |
|
| 803 | - array(1, 2, 3, 4, 7, 9) |
|
| 804 | - ) |
|
| 805 | - ) { |
|
| 806 | - return false; |
|
| 807 | - } |
|
| 808 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | - // save new config to db |
|
| 812 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | - return true; |
|
| 814 | - } |
|
| 815 | - } else { |
|
| 816 | - // first check if the record already exists |
|
| 817 | - $existing_config = get_option($config_option_name); |
|
| 818 | - $config_obj = serialize($config_obj); |
|
| 819 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | - if ($existing_config == $config_obj) { |
|
| 821 | - $this->{$section}->{$name} = $config_obj; |
|
| 822 | - return true; |
|
| 823 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | - EE_Config::log($config_option_name); |
|
| 825 | - // update wp-option for this config class |
|
| 826 | - $this->{$section}->{$name} = $config_obj; |
|
| 827 | - return true; |
|
| 828 | - } elseif ($throw_errors) { |
|
| 829 | - EE_Error::add_error( |
|
| 830 | - sprintf( |
|
| 831 | - __( |
|
| 832 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | - 'event_espresso' |
|
| 834 | - ), |
|
| 835 | - $config_class, |
|
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 837 | - ), |
|
| 838 | - __FILE__, |
|
| 839 | - __FUNCTION__, |
|
| 840 | - __LINE__ |
|
| 841 | - ); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * get_config |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @param string $section |
|
| 853 | - * @param string $name |
|
| 854 | - * @param string $config_class |
|
| 855 | - * @return mixed EE_Config_Base | NULL |
|
| 856 | - */ |
|
| 857 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | - { |
|
| 859 | - // ensure config class is set to something |
|
| 860 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | - return null; |
|
| 864 | - } |
|
| 865 | - // now test if the requested config object exists, but suppress errors |
|
| 866 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | - // config already exists, so pass it back |
|
| 868 | - return $this->{$section}->{$name}; |
|
| 869 | - } |
|
| 870 | - // load config option from db if it exists |
|
| 871 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | - // verify the newly retrieved config object, but suppress errors |
|
| 873 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | - // config is good, so set it and pass it back |
|
| 875 | - $this->{$section}->{$name} = $config_obj; |
|
| 876 | - return $this->{$section}->{$name}; |
|
| 877 | - } |
|
| 878 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | - // verify the newly created config object |
|
| 881 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | - return $this->{$section}->{$name}; |
|
| 883 | - } else { |
|
| 884 | - EE_Error::add_error( |
|
| 885 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | - __FILE__, |
|
| 887 | - __FUNCTION__, |
|
| 888 | - __LINE__ |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - return null; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * get_config_option |
|
| 897 | - * |
|
| 898 | - * @access public |
|
| 899 | - * @param string $config_option_name |
|
| 900 | - * @return mixed EE_Config_Base | FALSE |
|
| 901 | - */ |
|
| 902 | - public function get_config_option($config_option_name = '') |
|
| 903 | - { |
|
| 904 | - // retrieve the wp-option for this config class. |
|
| 905 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | - if (empty($config_option)) { |
|
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | - } |
|
| 909 | - return $config_option; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * log |
|
| 915 | - * |
|
| 916 | - * @param string $config_option_name |
|
| 917 | - */ |
|
| 918 | - public static function log($config_option_name = '') |
|
| 919 | - { |
|
| 920 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | - // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | - $_request = $_REQUEST; |
|
| 924 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 926 | - 'config_name' => $config_option_name, |
|
| 927 | - 'request' => $_request, |
|
| 928 | - ); |
|
| 929 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * trim_log |
|
| 936 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | - */ |
|
| 938 | - public static function trim_log() |
|
| 939 | - { |
|
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 941 | - return; |
|
| 942 | - } |
|
| 943 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | - $log_length = count($config_log); |
|
| 945 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | - ksort($config_log); |
|
| 947 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * get_page_for_posts |
|
| 955 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | - * |
|
| 958 | - * @access public |
|
| 959 | - * @return string |
|
| 960 | - */ |
|
| 961 | - public static function get_page_for_posts() |
|
| 962 | - { |
|
| 963 | - $page_for_posts = get_option('page_for_posts'); |
|
| 964 | - if (! $page_for_posts) { |
|
| 965 | - return 'posts'; |
|
| 966 | - } |
|
| 967 | - /** @type WPDB $wpdb */ |
|
| 968 | - global $wpdb; |
|
| 969 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * register_shortcodes_and_modules. |
|
| 976 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | - * so they can help trigger maintenance mode if it's needed |
|
| 979 | - * |
|
| 980 | - * @access public |
|
| 981 | - * @return void |
|
| 982 | - */ |
|
| 983 | - public function register_shortcodes_and_modules() |
|
| 984 | - { |
|
| 985 | - // allow modules to set hooks for the rest of the system |
|
| 986 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * initialize_shortcodes_and_modules |
|
| 992 | - * meaning they can start adding their hooks to get stuff done |
|
| 993 | - * |
|
| 994 | - * @access public |
|
| 995 | - * @return void |
|
| 996 | - */ |
|
| 997 | - public function initialize_shortcodes_and_modules() |
|
| 998 | - { |
|
| 999 | - // allow modules to set hooks for the rest of the system |
|
| 1000 | - $this->_initialize_modules(); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * widgets_init |
|
| 1006 | - * |
|
| 1007 | - * @access private |
|
| 1008 | - * @return void |
|
| 1009 | - */ |
|
| 1010 | - public function widgets_init() |
|
| 1011 | - { |
|
| 1012 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | - // on frontend when not in any maintenance mode |
|
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | - || ( |
|
| 1016 | - is_admin() |
|
| 1017 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | - ) |
|
| 1019 | - ) { |
|
| 1020 | - // grab list of installed widgets |
|
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | - // filter list of modules to register |
|
| 1023 | - $widgets_to_register = apply_filters( |
|
| 1024 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | - $widgets_to_register |
|
| 1026 | - ); |
|
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1028 | - // cycle thru widget folders |
|
| 1029 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | - // add to list of installed widget modules |
|
| 1031 | - EE_Config::register_ee_widget($widget_path); |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - // filter list of installed modules |
|
| 1035 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | - EE_Registry::instance()->widgets |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * register_ee_widget - makes core aware of this widget |
|
| 1045 | - * |
|
| 1046 | - * @access public |
|
| 1047 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function register_ee_widget($widget_path = null) |
|
| 1051 | - { |
|
| 1052 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | - $widget_ext = '.widget.php'; |
|
| 1054 | - // make all separators match |
|
| 1055 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | - $file_name = explode('.', basename($widget_path)); |
|
| 1060 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | - // sanitize shortcode directory name |
|
| 1063 | - $widget = sanitize_key($widget); |
|
| 1064 | - // now we need to rebuild the shortcode path |
|
| 1065 | - $widget_path = explode('/', $widget_path); |
|
| 1066 | - // remove last segment |
|
| 1067 | - array_pop($widget_path); |
|
| 1068 | - // glue it back together |
|
| 1069 | - $widget_path = implode(DS, $widget_path); |
|
| 1070 | - } else { |
|
| 1071 | - // grab and sanitize widget directory name |
|
| 1072 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | - } |
|
| 1074 | - // create classname from widget directory name |
|
| 1075 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | - // add class prefix |
|
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1078 | - // does the widget exist ? |
|
| 1079 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1080 | - $msg = sprintf( |
|
| 1081 | - __( |
|
| 1082 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | - 'event_espresso' |
|
| 1084 | - ), |
|
| 1085 | - $widget_class, |
|
| 1086 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1087 | - ); |
|
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - // load the widget class file |
|
| 1092 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1093 | - // verify that class exists |
|
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1095 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | - return; |
|
| 1098 | - } |
|
| 1099 | - register_widget($widget_class); |
|
| 1100 | - // add to array of registered widgets |
|
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * _register_modules |
|
| 1107 | - * |
|
| 1108 | - * @access private |
|
| 1109 | - * @return array |
|
| 1110 | - */ |
|
| 1111 | - private function _register_modules() |
|
| 1112 | - { |
|
| 1113 | - // grab list of installed modules |
|
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | - // filter list of modules to register |
|
| 1116 | - $modules_to_register = apply_filters( |
|
| 1117 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | - $modules_to_register |
|
| 1119 | - ); |
|
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1121 | - // loop through folders |
|
| 1122 | - foreach ($modules_to_register as $module_path) { |
|
| 1123 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | - ) { |
|
| 1127 | - // add to list of installed modules |
|
| 1128 | - EE_Config::register_module($module_path); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - // filter list of installed modules |
|
| 1133 | - return apply_filters( |
|
| 1134 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | - EE_Registry::instance()->modules |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * register_module - makes core aware of this module |
|
| 1142 | - * |
|
| 1143 | - * @access public |
|
| 1144 | - * @param string $module_path - full path up to and including module folder |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public static function register_module($module_path = null) |
|
| 1148 | - { |
|
| 1149 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | - $module_ext = '.module.php'; |
|
| 1151 | - // make all separators match |
|
| 1152 | - $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1153 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | - $module_file = explode('.', basename($module_path)); |
|
| 1157 | - // now we need to rebuild the shortcode path |
|
| 1158 | - $module_path = explode('/', $module_path); |
|
| 1159 | - // remove last segment |
|
| 1160 | - array_pop($module_path); |
|
| 1161 | - // glue it back together |
|
| 1162 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1163 | - // take first segment from file name pieces and sanitize it |
|
| 1164 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | - // ensure class prefix is added |
|
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | - } else { |
|
| 1168 | - // we need to generate the filename based off of the folder name |
|
| 1169 | - // grab and sanitize module name |
|
| 1170 | - $module = strtolower(basename($module_path)); |
|
| 1171 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | - // like trailingslashit() |
|
| 1173 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1174 | - // create classname from module directory name |
|
| 1175 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | - // add class prefix |
|
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1178 | - } |
|
| 1179 | - // does the module exist ? |
|
| 1180 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1181 | - $msg = sprintf( |
|
| 1182 | - __( |
|
| 1183 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | - 'event_espresso' |
|
| 1185 | - ), |
|
| 1186 | - $module |
|
| 1187 | - ); |
|
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | - return false; |
|
| 1190 | - } |
|
| 1191 | - // load the module class file |
|
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1193 | - // verify that class exists |
|
| 1194 | - if (! class_exists($module_class)) { |
|
| 1195 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | - return false; |
|
| 1198 | - } |
|
| 1199 | - // add to array of registered modules |
|
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | - do_action( |
|
| 1202 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | - $module_class, |
|
| 1204 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | - ); |
|
| 1206 | - return true; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * _initialize_modules |
|
| 1212 | - * allow modules to set hooks for the rest of the system |
|
| 1213 | - * |
|
| 1214 | - * @access private |
|
| 1215 | - * @return void |
|
| 1216 | - */ |
|
| 1217 | - private function _initialize_modules() |
|
| 1218 | - { |
|
| 1219 | - // cycle thru shortcode folders |
|
| 1220 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | - // which set hooks ? |
|
| 1223 | - if (is_admin()) { |
|
| 1224 | - // fire immediately |
|
| 1225 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | - } else { |
|
| 1227 | - // delay until other systems are online |
|
| 1228 | - add_action( |
|
| 1229 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | - array($module_class, 'set_hooks') |
|
| 1231 | - ); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * register_route - adds module method routes to route_map |
|
| 1239 | - * |
|
| 1240 | - * @access public |
|
| 1241 | - * @param string $route - "pretty" public alias for module method |
|
| 1242 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | - * @param string $method_name - the actual module method to be routed to |
|
| 1244 | - * @param string $key - url param key indicating a route is being called |
|
| 1245 | - * @return bool |
|
| 1246 | - */ |
|
| 1247 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | - { |
|
| 1249 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | - $module = str_replace('EED_', '', $module); |
|
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | - return false; |
|
| 1256 | - } |
|
| 1257 | - if (empty($route)) { |
|
| 1258 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | - return false; |
|
| 1261 | - } |
|
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | - $msg = sprintf( |
|
| 1264 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | - $route |
|
| 1266 | - ); |
|
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | - return true; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * get_route - get module method route |
|
| 1277 | - * |
|
| 1278 | - * @access public |
|
| 1279 | - * @param string $route - "pretty" public alias for module method |
|
| 1280 | - * @param string $key - url param key indicating a route is being called |
|
| 1281 | - * @return string |
|
| 1282 | - */ |
|
| 1283 | - public static function get_route($route = null, $key = 'ee') |
|
| 1284 | - { |
|
| 1285 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | - } |
|
| 1290 | - return null; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * get_routes - get ALL module method routes |
|
| 1296 | - * |
|
| 1297 | - * @access public |
|
| 1298 | - * @return array |
|
| 1299 | - */ |
|
| 1300 | - public static function get_routes() |
|
| 1301 | - { |
|
| 1302 | - return EE_Config::$_module_route_map; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | - * |
|
| 1309 | - * @access public |
|
| 1310 | - * @param string $route - "pretty" public alias for module method |
|
| 1311 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | - * class, allows different forwards to be served based on status |
|
| 1313 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | - * @param string $key - url param key indicating a route is being called |
|
| 1315 | - * @return bool |
|
| 1316 | - */ |
|
| 1317 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | - { |
|
| 1319 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | - $msg = sprintf( |
|
| 1322 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | - $route |
|
| 1324 | - ); |
|
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | - return false; |
|
| 1327 | - } |
|
| 1328 | - if (empty($forward)) { |
|
| 1329 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | - return false; |
|
| 1332 | - } |
|
| 1333 | - if (is_array($forward)) { |
|
| 1334 | - if (! isset($forward[1])) { |
|
| 1335 | - $msg = sprintf( |
|
| 1336 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | - $route |
|
| 1338 | - ); |
|
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | - return false; |
|
| 1341 | - } |
|
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | - $msg = sprintf( |
|
| 1344 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | - $forward[1], |
|
| 1346 | - $route |
|
| 1347 | - ); |
|
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | - return false; |
|
| 1350 | - } |
|
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1352 | - $msg = sprintf( |
|
| 1353 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | - $forward, |
|
| 1355 | - $route |
|
| 1356 | - ); |
|
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | - return false; |
|
| 1359 | - } |
|
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | - return true; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - /** |
|
| 1366 | - * get_forward - get forwarding route |
|
| 1367 | - * |
|
| 1368 | - * @access public |
|
| 1369 | - * @param string $route - "pretty" public alias for module method |
|
| 1370 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | - * allows different forwards to be served based on status |
|
| 1372 | - * @param string $key - url param key indicating a route is being called |
|
| 1373 | - * @return string |
|
| 1374 | - */ |
|
| 1375 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | - { |
|
| 1377 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | - return apply_filters( |
|
| 1380 | - 'FHEE__EE_Config__get_forward', |
|
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | - $route, |
|
| 1383 | - $status |
|
| 1384 | - ); |
|
| 1385 | - } |
|
| 1386 | - return null; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | - * results |
|
| 1393 | - * |
|
| 1394 | - * @access public |
|
| 1395 | - * @param string $route - "pretty" public alias for module method |
|
| 1396 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | - * allows different views to be served based on status |
|
| 1398 | - * @param string $view |
|
| 1399 | - * @param string $key - url param key indicating a route is being called |
|
| 1400 | - * @return bool |
|
| 1401 | - */ |
|
| 1402 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | - { |
|
| 1404 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | - $msg = sprintf( |
|
| 1407 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | - $route |
|
| 1409 | - ); |
|
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | - return false; |
|
| 1412 | - } |
|
| 1413 | - if (! is_readable($view)) { |
|
| 1414 | - $msg = sprintf( |
|
| 1415 | - __( |
|
| 1416 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | - 'event_espresso' |
|
| 1418 | - ), |
|
| 1419 | - $view |
|
| 1420 | - ); |
|
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | - return false; |
|
| 1423 | - } |
|
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | - return true; |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * get_view - get view for route and status |
|
| 1431 | - * |
|
| 1432 | - * @access public |
|
| 1433 | - * @param string $route - "pretty" public alias for module method |
|
| 1434 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | - * allows different views to be served based on status |
|
| 1436 | - * @param string $key - url param key indicating a route is being called |
|
| 1437 | - * @return string |
|
| 1438 | - */ |
|
| 1439 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | - { |
|
| 1441 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | - return apply_filters( |
|
| 1444 | - 'FHEE__EE_Config__get_view', |
|
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | - $route, |
|
| 1447 | - $status |
|
| 1448 | - ); |
|
| 1449 | - } |
|
| 1450 | - return null; |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - |
|
| 1454 | - public function update_addon_option_names() |
|
| 1455 | - { |
|
| 1456 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - public function shutdown() |
|
| 1461 | - { |
|
| 1462 | - $this->update_addon_option_names(); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * @return LegacyShortcodesManager |
|
| 1468 | - */ |
|
| 1469 | - public static function getLegacyShortcodesManager() |
|
| 1470 | - { |
|
| 1471 | - |
|
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | - EE_Registry::instance() |
|
| 1475 | - ); |
|
| 1476 | - } |
|
| 1477 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * register_shortcode - makes core aware of this shortcode |
|
| 1483 | - * |
|
| 1484 | - * @deprecated 4.9.26 |
|
| 1485 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | - * @return bool |
|
| 1487 | - */ |
|
| 1488 | - public static function register_shortcode($shortcode_path = null) |
|
| 1489 | - { |
|
| 1490 | - EE_Error::doing_it_wrong( |
|
| 1491 | - __METHOD__, |
|
| 1492 | - __( |
|
| 1493 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | - 'event_espresso' |
|
| 1495 | - ), |
|
| 1496 | - '4.9.26' |
|
| 1497 | - ); |
|
| 1498 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | - } |
|
| 1500 | -} |
|
| 1501 | - |
|
| 1502 | -/** |
|
| 1503 | - * Base class used for config classes. These classes should generally not have |
|
| 1504 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | - * basically, they should just be well-defined stdClasses |
|
| 1506 | - */ |
|
| 1507 | -class EE_Config_Base |
|
| 1508 | -{ |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * Utility function for escaping the value of a property and returning. |
|
| 1512 | - * |
|
| 1513 | - * @param string $property property name (checks to see if exists). |
|
| 1514 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | - * @throws \EE_Error |
|
| 1516 | - */ |
|
| 1517 | - public function get_pretty($property) |
|
| 1518 | - { |
|
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1520 | - throw new EE_Error( |
|
| 1521 | - sprintf( |
|
| 1522 | - __( |
|
| 1523 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | - 'event_espresso' |
|
| 1525 | - ), |
|
| 1526 | - get_class($this), |
|
| 1527 | - $property |
|
| 1528 | - ) |
|
| 1529 | - ); |
|
| 1530 | - } |
|
| 1531 | - // just handling escaping of strings for now. |
|
| 1532 | - if (is_string($this->{$property})) { |
|
| 1533 | - return stripslashes($this->{$property}); |
|
| 1534 | - } |
|
| 1535 | - return $this->{$property}; |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - public function populate() |
|
| 1540 | - { |
|
| 1541 | - // grab defaults via a new instance of this class. |
|
| 1542 | - $class_name = get_class($this); |
|
| 1543 | - $defaults = new $class_name; |
|
| 1544 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | - // default from our $defaults object. |
|
| 1546 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | - if ($this->{$property} === null) { |
|
| 1548 | - $this->{$property} = $value; |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - // cleanup |
|
| 1552 | - unset($defaults); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * __isset |
|
| 1558 | - * |
|
| 1559 | - * @param $a |
|
| 1560 | - * @return bool |
|
| 1561 | - */ |
|
| 1562 | - public function __isset($a) |
|
| 1563 | - { |
|
| 1564 | - return false; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * __unset |
|
| 1570 | - * |
|
| 1571 | - * @param $a |
|
| 1572 | - * @return bool |
|
| 1573 | - */ |
|
| 1574 | - public function __unset($a) |
|
| 1575 | - { |
|
| 1576 | - return false; |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - |
|
| 1580 | - /** |
|
| 1581 | - * __clone |
|
| 1582 | - */ |
|
| 1583 | - public function __clone() |
|
| 1584 | - { |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * __wakeup |
|
| 1590 | - */ |
|
| 1591 | - public function __wakeup() |
|
| 1592 | - { |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * __destruct |
|
| 1598 | - */ |
|
| 1599 | - public function __destruct() |
|
| 1600 | - { |
|
| 1601 | - } |
|
| 1602 | -} |
|
| 1603 | - |
|
| 1604 | -/** |
|
| 1605 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | - */ |
|
| 1607 | -class EE_Core_Config extends EE_Config_Base |
|
| 1608 | -{ |
|
| 1609 | - |
|
| 1610 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | - |
|
| 1612 | - |
|
| 1613 | - public $current_blog_id; |
|
| 1614 | - |
|
| 1615 | - public $ee_ueip_optin; |
|
| 1616 | - |
|
| 1617 | - public $ee_ueip_has_notified; |
|
| 1618 | - |
|
| 1619 | - /** |
|
| 1620 | - * Not to be confused with the 4 critical page variables (See |
|
| 1621 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | - * |
|
| 1625 | - * @var array |
|
| 1626 | - */ |
|
| 1627 | - public $post_shortcodes; |
|
| 1628 | - |
|
| 1629 | - public $module_route_map; |
|
| 1630 | - |
|
| 1631 | - public $module_forward_map; |
|
| 1632 | - |
|
| 1633 | - public $module_view_map; |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | - * |
|
| 1638 | - * @var int |
|
| 1639 | - */ |
|
| 1640 | - public $reg_page_id; |
|
| 1641 | - |
|
| 1642 | - public $txn_page_id; |
|
| 1643 | - |
|
| 1644 | - public $thank_you_page_id; |
|
| 1645 | - |
|
| 1646 | - public $cancel_page_id; |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | - * |
|
| 1651 | - * @var int |
|
| 1652 | - */ |
|
| 1653 | - public $reg_page_url; |
|
| 1654 | - |
|
| 1655 | - public $txn_page_url; |
|
| 1656 | - |
|
| 1657 | - public $thank_you_page_url; |
|
| 1658 | - |
|
| 1659 | - public $cancel_page_url; |
|
| 1660 | - |
|
| 1661 | - /** |
|
| 1662 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | - */ |
|
| 1664 | - public $event_cpt_slug; |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | - * request across blog switches in a multisite context. |
|
| 1669 | - * Avoids extra queries to the db for this option. |
|
| 1670 | - * |
|
| 1671 | - * @var bool |
|
| 1672 | - */ |
|
| 1673 | - public static $ee_ueip_option; |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * class constructor |
|
| 1678 | - * |
|
| 1679 | - * @access public |
|
| 1680 | - */ |
|
| 1681 | - public function __construct() |
|
| 1682 | - { |
|
| 1683 | - // set default organization settings |
|
| 1684 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | - $this->post_shortcodes = array(); |
|
| 1689 | - $this->module_route_map = array(); |
|
| 1690 | - $this->module_forward_map = array(); |
|
| 1691 | - $this->module_view_map = array(); |
|
| 1692 | - // critical EE page IDs |
|
| 1693 | - $this->reg_page_id = 0; |
|
| 1694 | - $this->txn_page_id = 0; |
|
| 1695 | - $this->thank_you_page_id = 0; |
|
| 1696 | - $this->cancel_page_id = 0; |
|
| 1697 | - // critical EE page URLs |
|
| 1698 | - $this->reg_page_url = ''; |
|
| 1699 | - $this->txn_page_url = ''; |
|
| 1700 | - $this->thank_you_page_url = ''; |
|
| 1701 | - $this->cancel_page_url = ''; |
|
| 1702 | - // cpt slugs |
|
| 1703 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | - // ueip constant check |
|
| 1705 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | - $this->ee_ueip_optin = false; |
|
| 1707 | - $this->ee_ueip_has_notified = true; |
|
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * @return array |
|
| 1714 | - */ |
|
| 1715 | - public function get_critical_pages_array() |
|
| 1716 | - { |
|
| 1717 | - return array( |
|
| 1718 | - $this->reg_page_id, |
|
| 1719 | - $this->txn_page_id, |
|
| 1720 | - $this->thank_you_page_id, |
|
| 1721 | - $this->cancel_page_id, |
|
| 1722 | - ); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * @return array |
|
| 1728 | - */ |
|
| 1729 | - public function get_critical_pages_shortcodes_array() |
|
| 1730 | - { |
|
| 1731 | - return array( |
|
| 1732 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | - ); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * gets/returns URL for EE reg_page |
|
| 1742 | - * |
|
| 1743 | - * @access public |
|
| 1744 | - * @return string |
|
| 1745 | - */ |
|
| 1746 | - public function reg_page_url() |
|
| 1747 | - { |
|
| 1748 | - if (! $this->reg_page_url) { |
|
| 1749 | - $this->reg_page_url = add_query_arg( |
|
| 1750 | - array('uts' => time()), |
|
| 1751 | - get_permalink($this->reg_page_id) |
|
| 1752 | - ) . '#checkout'; |
|
| 1753 | - } |
|
| 1754 | - return $this->reg_page_url; |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - |
|
| 1758 | - /** |
|
| 1759 | - * gets/returns URL for EE txn_page |
|
| 1760 | - * |
|
| 1761 | - * @param array $query_args like what gets passed to |
|
| 1762 | - * add_query_arg() as the first argument |
|
| 1763 | - * @access public |
|
| 1764 | - * @return string |
|
| 1765 | - */ |
|
| 1766 | - public function txn_page_url($query_args = array()) |
|
| 1767 | - { |
|
| 1768 | - if (! $this->txn_page_url) { |
|
| 1769 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | - } |
|
| 1771 | - if ($query_args) { |
|
| 1772 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | - } else { |
|
| 1774 | - return $this->txn_page_url; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * gets/returns URL for EE thank_you_page |
|
| 1781 | - * |
|
| 1782 | - * @param array $query_args like what gets passed to |
|
| 1783 | - * add_query_arg() as the first argument |
|
| 1784 | - * @access public |
|
| 1785 | - * @return string |
|
| 1786 | - */ |
|
| 1787 | - public function thank_you_page_url($query_args = array()) |
|
| 1788 | - { |
|
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1790 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | - } |
|
| 1792 | - if ($query_args) { |
|
| 1793 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | - } else { |
|
| 1795 | - return $this->thank_you_page_url; |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * gets/returns URL for EE cancel_page |
|
| 1802 | - * |
|
| 1803 | - * @access public |
|
| 1804 | - * @return string |
|
| 1805 | - */ |
|
| 1806 | - public function cancel_page_url() |
|
| 1807 | - { |
|
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1809 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | - } |
|
| 1811 | - return $this->cancel_page_url; |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | - * |
|
| 1818 | - * @since 4.7.5 |
|
| 1819 | - */ |
|
| 1820 | - protected function _reset_urls() |
|
| 1821 | - { |
|
| 1822 | - $this->reg_page_url = ''; |
|
| 1823 | - $this->txn_page_url = ''; |
|
| 1824 | - $this->cancel_page_url = ''; |
|
| 1825 | - $this->thank_you_page_url = ''; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | - * on the main site only. |
|
| 1833 | - * |
|
| 1834 | - * @return bool |
|
| 1835 | - */ |
|
| 1836 | - protected function _get_main_ee_ueip_optin() |
|
| 1837 | - { |
|
| 1838 | - // if this is the main site then we can just bypass our direct query. |
|
| 1839 | - if (is_main_site()) { |
|
| 1840 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | - } |
|
| 1842 | - // is this already cached for this request? If so use it. |
|
| 1843 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | - } |
|
| 1846 | - global $wpdb; |
|
| 1847 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | - $option = self::OPTION_NAME_UXIP; |
|
| 1850 | - // set correct table for query |
|
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | - // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | - // for the purpose of caching. |
|
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | - if (false !== $pre) { |
|
| 1859 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | - } |
|
| 1862 | - $row = $wpdb->get_row( |
|
| 1863 | - $wpdb->prepare( |
|
| 1864 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | - $option |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - if (is_object($row)) { |
|
| 1869 | - $value = $row->option_value; |
|
| 1870 | - } else { // option does not exist so use default. |
|
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | - } |
|
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * Utility function for escaping the value of a property and returning. |
|
| 1881 | - * |
|
| 1882 | - * @param string $property property name (checks to see if exists). |
|
| 1883 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | - * @throws \EE_Error |
|
| 1885 | - */ |
|
| 1886 | - public function get_pretty($property) |
|
| 1887 | - { |
|
| 1888 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | - } |
|
| 1891 | - return parent::get_pretty($property); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | - * on the object. |
|
| 1898 | - * |
|
| 1899 | - * @return array |
|
| 1900 | - */ |
|
| 1901 | - public function __sleep() |
|
| 1902 | - { |
|
| 1903 | - // reset all url properties |
|
| 1904 | - $this->_reset_urls(); |
|
| 1905 | - // return what to save to db |
|
| 1906 | - return array_keys(get_object_vars($this)); |
|
| 1907 | - } |
|
| 1908 | -} |
|
| 1909 | - |
|
| 1910 | -/** |
|
| 1911 | - * Config class for storing info on the Organization |
|
| 1912 | - */ |
|
| 1913 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | -{ |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * @var string $name |
|
| 1918 | - * eg EE4.1 |
|
| 1919 | - */ |
|
| 1920 | - public $name; |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * @var string $address_1 |
|
| 1924 | - * eg 123 Onna Road |
|
| 1925 | - */ |
|
| 1926 | - public $address_1 = ''; |
|
| 1927 | - |
|
| 1928 | - /** |
|
| 1929 | - * @var string $address_2 |
|
| 1930 | - * eg PO Box 123 |
|
| 1931 | - */ |
|
| 1932 | - public $address_2 = ''; |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * @var string $city |
|
| 1936 | - * eg Inna City |
|
| 1937 | - */ |
|
| 1938 | - public $city = ''; |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * @var int $STA_ID |
|
| 1942 | - * eg 4 |
|
| 1943 | - */ |
|
| 1944 | - public $STA_ID = 0; |
|
| 1945 | - |
|
| 1946 | - /** |
|
| 1947 | - * @var string $CNT_ISO |
|
| 1948 | - * eg US |
|
| 1949 | - */ |
|
| 1950 | - public $CNT_ISO = ''; |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * @var string $zip |
|
| 1954 | - * eg 12345 or V1A 2B3 |
|
| 1955 | - */ |
|
| 1956 | - public $zip = ''; |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * @var string $email |
|
| 1960 | - * eg [email protected] |
|
| 1961 | - */ |
|
| 1962 | - public $email; |
|
| 1963 | - |
|
| 1964 | - /** |
|
| 1965 | - * @var string $phone |
|
| 1966 | - * eg. 111-111-1111 |
|
| 1967 | - */ |
|
| 1968 | - public $phone = ''; |
|
| 1969 | - |
|
| 1970 | - /** |
|
| 1971 | - * @var string $vat |
|
| 1972 | - * VAT/Tax Number |
|
| 1973 | - */ |
|
| 1974 | - public $vat = ''; |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * @var string $logo_url |
|
| 1978 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | - */ |
|
| 1980 | - public $logo_url = ''; |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | - * |
|
| 1985 | - * @var string |
|
| 1986 | - */ |
|
| 1987 | - /** |
|
| 1988 | - * facebook (facebook.com/profile.name) |
|
| 1989 | - * |
|
| 1990 | - * @var string |
|
| 1991 | - */ |
|
| 1992 | - public $facebook = ''; |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * twitter (twitter.com/twitter_handle) |
|
| 1996 | - * |
|
| 1997 | - * @var string |
|
| 1998 | - */ |
|
| 1999 | - public $twitter = ''; |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | - * |
|
| 2004 | - * @var string |
|
| 2005 | - */ |
|
| 2006 | - public $linkedin = ''; |
|
| 2007 | - |
|
| 2008 | - /** |
|
| 2009 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | - * |
|
| 2011 | - * @var string |
|
| 2012 | - */ |
|
| 2013 | - public $pinterest = ''; |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * google+ (google.com/+profileName) |
|
| 2017 | - * |
|
| 2018 | - * @var string |
|
| 2019 | - */ |
|
| 2020 | - public $google = ''; |
|
| 2021 | - |
|
| 2022 | - /** |
|
| 2023 | - * instagram (instagram.com/handle) |
|
| 2024 | - * |
|
| 2025 | - * @var string |
|
| 2026 | - */ |
|
| 2027 | - public $instagram = ''; |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * class constructor |
|
| 2032 | - * |
|
| 2033 | - * @access public |
|
| 2034 | - */ |
|
| 2035 | - public function __construct() |
|
| 2036 | - { |
|
| 2037 | - // set default organization settings |
|
| 2038 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | - $this->email = get_bloginfo('admin_email'); |
|
| 2041 | - } |
|
| 2042 | -} |
|
| 2043 | - |
|
| 2044 | -/** |
|
| 2045 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | - */ |
|
| 2047 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | -{ |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * @var string $code |
|
| 2052 | - * eg 'US' |
|
| 2053 | - */ |
|
| 2054 | - public $code; |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * @var string $name |
|
| 2058 | - * eg 'Dollar' |
|
| 2059 | - */ |
|
| 2060 | - public $name; |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * plural name |
|
| 2064 | - * |
|
| 2065 | - * @var string $plural |
|
| 2066 | - * eg 'Dollars' |
|
| 2067 | - */ |
|
| 2068 | - public $plural; |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * currency sign |
|
| 2072 | - * |
|
| 2073 | - * @var string $sign |
|
| 2074 | - * eg '$' |
|
| 2075 | - */ |
|
| 2076 | - public $sign; |
|
| 2077 | - |
|
| 2078 | - /** |
|
| 2079 | - * Whether the currency sign should come before the number or not |
|
| 2080 | - * |
|
| 2081 | - * @var boolean $sign_b4 |
|
| 2082 | - */ |
|
| 2083 | - public $sign_b4; |
|
| 2084 | - |
|
| 2085 | - /** |
|
| 2086 | - * How many digits should come after the decimal place |
|
| 2087 | - * |
|
| 2088 | - * @var int $dec_plc |
|
| 2089 | - */ |
|
| 2090 | - public $dec_plc; |
|
| 2091 | - |
|
| 2092 | - /** |
|
| 2093 | - * Symbol to use for decimal mark |
|
| 2094 | - * |
|
| 2095 | - * @var string $dec_mrk |
|
| 2096 | - * eg '.' |
|
| 2097 | - */ |
|
| 2098 | - public $dec_mrk; |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * Symbol to use for thousands |
|
| 2102 | - * |
|
| 2103 | - * @var string $thsnds |
|
| 2104 | - * eg ',' |
|
| 2105 | - */ |
|
| 2106 | - public $thsnds; |
|
| 2107 | - |
|
| 2108 | - |
|
| 2109 | - /** |
|
| 2110 | - * class constructor |
|
| 2111 | - * |
|
| 2112 | - * @access public |
|
| 2113 | - * @param string $CNT_ISO |
|
| 2114 | - * @throws \EE_Error |
|
| 2115 | - */ |
|
| 2116 | - public function __construct($CNT_ISO = '') |
|
| 2117 | - { |
|
| 2118 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | - // get country code from organization settings or use default |
|
| 2121 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | - : ''; |
|
| 2125 | - // but override if requested |
|
| 2126 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | - if (! empty($CNT_ISO) |
|
| 2129 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | - ) { |
|
| 2132 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | - if ($country instanceof EE_Country) { |
|
| 2135 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | - $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | - $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | - $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | - } |
|
| 2147 | - } |
|
| 2148 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | - if (empty($this->code)) { |
|
| 2150 | - // set default currency settings |
|
| 2151 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | - $this->sign = '$'; // currency sign: $ |
|
| 2155 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | - } |
|
| 2160 | - } |
|
| 2161 | -} |
|
| 2162 | - |
|
| 2163 | -/** |
|
| 2164 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | - */ |
|
| 2166 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | -{ |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * Default registration status |
|
| 2171 | - * |
|
| 2172 | - * @var string $default_STS_ID |
|
| 2173 | - * eg 'RPP' |
|
| 2174 | - */ |
|
| 2175 | - public $default_STS_ID; |
|
| 2176 | - |
|
| 2177 | - /** |
|
| 2178 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | - * registrations) |
|
| 2180 | - * |
|
| 2181 | - * @var int |
|
| 2182 | - */ |
|
| 2183 | - public $default_maximum_number_of_tickets; |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * level of validation to apply to email addresses |
|
| 2187 | - * |
|
| 2188 | - * @var string $email_validation_level |
|
| 2189 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | - */ |
|
| 2191 | - public $email_validation_level; |
|
| 2192 | - |
|
| 2193 | - /** |
|
| 2194 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | - * |
|
| 2196 | - * @var boolean $show_pending_payment_options |
|
| 2197 | - */ |
|
| 2198 | - public $show_pending_payment_options; |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * Whether to skip the registration confirmation page |
|
| 2202 | - * |
|
| 2203 | - * @var boolean $skip_reg_confirmation |
|
| 2204 | - */ |
|
| 2205 | - public $skip_reg_confirmation; |
|
| 2206 | - |
|
| 2207 | - /** |
|
| 2208 | - * an array of SPCO reg steps where: |
|
| 2209 | - * the keys denotes the reg step order |
|
| 2210 | - * each element consists of an array with the following elements: |
|
| 2211 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | - * "slug" => the URL param used to trigger the reg step |
|
| 2214 | - * |
|
| 2215 | - * @var array $reg_steps |
|
| 2216 | - */ |
|
| 2217 | - public $reg_steps; |
|
| 2218 | - |
|
| 2219 | - /** |
|
| 2220 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | - * |
|
| 2222 | - * @var boolean $reg_confirmation_last |
|
| 2223 | - */ |
|
| 2224 | - public $reg_confirmation_last; |
|
| 2225 | - |
|
| 2226 | - /** |
|
| 2227 | - * Whether or not to enable the EE Bot Trap |
|
| 2228 | - * |
|
| 2229 | - * @var boolean $use_bot_trap |
|
| 2230 | - */ |
|
| 2231 | - public $use_bot_trap; |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | - * |
|
| 2236 | - * @var boolean $use_encryption |
|
| 2237 | - */ |
|
| 2238 | - public $use_encryption; |
|
| 2239 | - |
|
| 2240 | - /** |
|
| 2241 | - * Whether or not to use ReCaptcha |
|
| 2242 | - * |
|
| 2243 | - * @var boolean $use_captcha |
|
| 2244 | - */ |
|
| 2245 | - public $use_captcha; |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * ReCaptcha Theme |
|
| 2249 | - * |
|
| 2250 | - * @var string $recaptcha_theme |
|
| 2251 | - * options: 'dark', 'light', 'invisible' |
|
| 2252 | - */ |
|
| 2253 | - public $recaptcha_theme; |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | - * |
|
| 2258 | - * @var string $recaptcha_badge |
|
| 2259 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | - */ |
|
| 2261 | - public $recaptcha_badge; |
|
| 17 | + const OPTION_NAME = 'ee_config'; |
|
| 18 | + |
|
| 19 | + const LOG_NAME = 'ee_config_log'; |
|
| 20 | + |
|
| 21 | + const LOG_LENGTH = 100; |
|
| 22 | + |
|
| 23 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * instance of the EE_Config object |
|
| 27 | + * |
|
| 28 | + * @var EE_Config $_instance |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean $_logging_enabled |
|
| 35 | + */ |
|
| 36 | + private static $_logging_enabled = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | + */ |
|
| 41 | + private $legacy_shortcodes_manager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * An StdClass whose property names are addon slugs, |
|
| 45 | + * and values are their config classes |
|
| 46 | + * |
|
| 47 | + * @var StdClass |
|
| 48 | + */ |
|
| 49 | + public $addons; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Admin_Config |
|
| 53 | + */ |
|
| 54 | + public $admin; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Core_Config |
|
| 58 | + */ |
|
| 59 | + public $core; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Currency_Config |
|
| 63 | + */ |
|
| 64 | + public $currency; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Organization_Config |
|
| 68 | + */ |
|
| 69 | + public $organization; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_Registration_Config |
|
| 73 | + */ |
|
| 74 | + public $registration; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Template_Config |
|
| 78 | + */ |
|
| 79 | + public $template_settings; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Holds EE environment values. |
|
| 83 | + * |
|
| 84 | + * @var EE_Environment_Config |
|
| 85 | + */ |
|
| 86 | + public $environment; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * settings pertaining to Google maps |
|
| 90 | + * |
|
| 91 | + * @var EE_Map_Config |
|
| 92 | + */ |
|
| 93 | + public $map_settings; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * settings pertaining to Taxes |
|
| 97 | + * |
|
| 98 | + * @var EE_Tax_Config |
|
| 99 | + */ |
|
| 100 | + public $tax_settings; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Settings pertaining to global messages settings. |
|
| 104 | + * |
|
| 105 | + * @var EE_Messages_Config |
|
| 106 | + */ |
|
| 107 | + public $messages; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated |
|
| 111 | + * @var EE_Gateway_Config |
|
| 112 | + */ |
|
| 113 | + public $gateway; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var array $_addon_option_names |
|
| 117 | + * @access private |
|
| 118 | + */ |
|
| 119 | + private $_addon_option_names = array(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array $_module_route_map |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | + private static $_module_route_map = array(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array $_module_forward_map |
|
| 129 | + * @access private |
|
| 130 | + */ |
|
| 131 | + private static $_module_forward_map = array(); |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @var array $_module_view_map |
|
| 135 | + * @access private |
|
| 136 | + */ |
|
| 137 | + private static $_module_view_map = array(); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @singleton method used to instantiate class object |
|
| 142 | + * @access public |
|
| 143 | + * @return EE_Config instance |
|
| 144 | + */ |
|
| 145 | + public static function instance() |
|
| 146 | + { |
|
| 147 | + // check if class object is instantiated, and instantiated properly |
|
| 148 | + if (! self::$_instance instanceof EE_Config) { |
|
| 149 | + self::$_instance = new self(); |
|
| 150 | + } |
|
| 151 | + return self::$_instance; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Resets the config |
|
| 157 | + * |
|
| 158 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | + * reflect its state in the database |
|
| 161 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | + * site was put into maintenance mode) |
|
| 165 | + * @return EE_Config |
|
| 166 | + */ |
|
| 167 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | + { |
|
| 169 | + if (self::$_instance instanceof EE_Config) { |
|
| 170 | + if ($hard_reset) { |
|
| 171 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | + self::$_instance->_addon_option_names = array(); |
|
| 173 | + self::$_instance->_initialize_config(); |
|
| 174 | + self::$_instance->update_espresso_config(); |
|
| 175 | + } |
|
| 176 | + self::$_instance->update_addon_option_names(); |
|
| 177 | + } |
|
| 178 | + self::$_instance = null; |
|
| 179 | + // we don't need to reset the static properties imo because those should |
|
| 180 | + // only change when a module is added or removed. Currently we don't |
|
| 181 | + // support removing a module during a request when it previously existed |
|
| 182 | + if ($reinstantiate) { |
|
| 183 | + return self::instance(); |
|
| 184 | + } else { |
|
| 185 | + return null; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * class constructor |
|
| 192 | + * |
|
| 193 | + * @access private |
|
| 194 | + */ |
|
| 195 | + private function __construct() |
|
| 196 | + { |
|
| 197 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | + // setup empty config classes |
|
| 200 | + $this->_initialize_config(); |
|
| 201 | + // load existing EE site settings |
|
| 202 | + $this->_load_core_config(); |
|
| 203 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | + $this->_verify_config(); |
|
| 205 | + // register shortcodes and modules |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | + array($this, 'register_shortcodes_and_modules'), |
|
| 209 | + 999 |
|
| 210 | + ); |
|
| 211 | + // initialize shortcodes and modules |
|
| 212 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | + // register widgets |
|
| 214 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | + // shutdown |
|
| 216 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | + // construct__end hook |
|
| 218 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | + // hardcoded hack |
|
| 220 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return boolean |
|
| 226 | + */ |
|
| 227 | + public static function logging_enabled() |
|
| 228 | + { |
|
| 229 | + return self::$_logging_enabled; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * use to get the current theme if needed from static context |
|
| 235 | + * |
|
| 236 | + * @return string current theme set. |
|
| 237 | + */ |
|
| 238 | + public static function get_current_theme() |
|
| 239 | + { |
|
| 240 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * _initialize_config |
|
| 247 | + * |
|
| 248 | + * @access private |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + private function _initialize_config() |
|
| 252 | + { |
|
| 253 | + EE_Config::trim_log(); |
|
| 254 | + // set defaults |
|
| 255 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | + $this->addons = new stdClass(); |
|
| 257 | + // set _module_route_map |
|
| 258 | + EE_Config::$_module_route_map = array(); |
|
| 259 | + // set _module_forward_map |
|
| 260 | + EE_Config::$_module_forward_map = array(); |
|
| 261 | + // set _module_view_map |
|
| 262 | + EE_Config::$_module_view_map = array(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * load core plugin configuration |
|
| 268 | + * |
|
| 269 | + * @access private |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + private function _load_core_config() |
|
| 273 | + { |
|
| 274 | + // load_core_config__start hook |
|
| 275 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | + $espresso_config = $this->get_espresso_config(); |
|
| 277 | + foreach ($espresso_config as $config => $settings) { |
|
| 278 | + // load_core_config__start hook |
|
| 279 | + $settings = apply_filters( |
|
| 280 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | + $settings, |
|
| 282 | + $config, |
|
| 283 | + $this |
|
| 284 | + ); |
|
| 285 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | + // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | + if (method_exists($settings, 'populate')) { |
|
| 289 | + $this->{$config}->populate(); |
|
| 290 | + } |
|
| 291 | + if (method_exists($settings, 'do_hooks')) { |
|
| 292 | + $this->{$config}->do_hooks(); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | + $this->update_espresso_config(); |
|
| 298 | + } |
|
| 299 | + // load_core_config__end hook |
|
| 300 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * _verify_config |
|
| 306 | + * |
|
| 307 | + * @access protected |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + protected function _verify_config() |
|
| 311 | + { |
|
| 312 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | + ? $this->core |
|
| 314 | + : new EE_Core_Config(); |
|
| 315 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | + ? $this->organization |
|
| 318 | + : new EE_Organization_Config(); |
|
| 319 | + $this->organization = apply_filters( |
|
| 320 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | + $this->organization |
|
| 322 | + ); |
|
| 323 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | + ? $this->currency |
|
| 325 | + : new EE_Currency_Config(); |
|
| 326 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | + ? $this->registration |
|
| 329 | + : new EE_Registration_Config(); |
|
| 330 | + $this->registration = apply_filters( |
|
| 331 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | + $this->registration |
|
| 333 | + ); |
|
| 334 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | + ? $this->admin |
|
| 336 | + : new EE_Admin_Config(); |
|
| 337 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | + ? $this->template_settings |
|
| 340 | + : new EE_Template_Config(); |
|
| 341 | + $this->template_settings = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | + $this->template_settings |
|
| 344 | + ); |
|
| 345 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | + ? $this->map_settings |
|
| 347 | + : new EE_Map_Config(); |
|
| 348 | + $this->map_settings = apply_filters( |
|
| 349 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | + $this->map_settings |
|
| 351 | + ); |
|
| 352 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | + ? $this->environment |
|
| 354 | + : new EE_Environment_Config(); |
|
| 355 | + $this->environment = apply_filters( |
|
| 356 | + 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | + $this->environment |
|
| 358 | + ); |
|
| 359 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | + ? $this->tax_settings |
|
| 361 | + : new EE_Tax_Config(); |
|
| 362 | + $this->tax_settings = apply_filters( |
|
| 363 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | + $this->tax_settings |
|
| 365 | + ); |
|
| 366 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | + ? $this->messages |
|
| 369 | + : new EE_Messages_Config(); |
|
| 370 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | + ? $this->gateway |
|
| 372 | + : new EE_Gateway_Config(); |
|
| 373 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | + $this->legacy_shortcodes_manager = null; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * get_espresso_config |
|
| 380 | + * |
|
| 381 | + * @access public |
|
| 382 | + * @return array of espresso config stuff |
|
| 383 | + */ |
|
| 384 | + public function get_espresso_config() |
|
| 385 | + { |
|
| 386 | + // grab espresso configuration |
|
| 387 | + return apply_filters( |
|
| 388 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * double_check_config_comparison |
|
| 396 | + * |
|
| 397 | + * @access public |
|
| 398 | + * @param string $option |
|
| 399 | + * @param $old_value |
|
| 400 | + * @param $value |
|
| 401 | + */ |
|
| 402 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | + { |
|
| 404 | + // make sure we're checking the ee config |
|
| 405 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | + if ($value != $old_value) { |
|
| 409 | + // if they are NOT the same, then remove the hook, |
|
| 410 | + // which means the subsequent update results will be based solely on the update query results |
|
| 411 | + // the reason we do this is because, as stated above, |
|
| 412 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | + // If values are found to match their previous old value, |
|
| 415 | + // then WP bails before performing any update. |
|
| 416 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | + // MySQL MAY ALSO NOT perform the update because |
|
| 420 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * update_espresso_config |
|
| 431 | + * |
|
| 432 | + * @access public |
|
| 433 | + */ |
|
| 434 | + protected function _reset_espresso_addon_config() |
|
| 435 | + { |
|
| 436 | + $this->_addon_option_names = array(); |
|
| 437 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | + } |
|
| 442 | + $this->addons->{$addon_name} = null; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * update_espresso_config |
|
| 449 | + * |
|
| 450 | + * @access public |
|
| 451 | + * @param bool $add_success |
|
| 452 | + * @param bool $add_error |
|
| 453 | + * @return bool |
|
| 454 | + */ |
|
| 455 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | + { |
|
| 457 | + // don't allow config updates during WP heartbeats |
|
| 458 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | + // $clone = clone( self::$_instance ); |
|
| 463 | + // self::$_instance = NULL; |
|
| 464 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | + $this->_reset_espresso_addon_config(); |
|
| 466 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | + // but BEFORE the actual update occurs |
|
| 468 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | + $this->legacy_shortcodes_manager = null; |
|
| 472 | + // now update "ee_config" |
|
| 473 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | + // if not saved... check if the hook we just added still exists; |
|
| 477 | + // if it does, it means one of two things: |
|
| 478 | + // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | + // or... |
|
| 480 | + // the db update query returned 0 rows affected |
|
| 481 | + // (probably because the data value was the same from it's perspective) |
|
| 482 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | + // but just means no update occurred, so don't display an error to the user. |
|
| 484 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | + // then it means that something truly went wrong |
|
| 486 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | + // remove our action since we don't want it in the system anymore |
|
| 488 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | + // self::$_instance = $clone; |
|
| 491 | + // unset( $clone ); |
|
| 492 | + // if config remains the same or was updated successfully |
|
| 493 | + if ($saved) { |
|
| 494 | + if ($add_success) { |
|
| 495 | + EE_Error::add_success( |
|
| 496 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | + __FILE__, |
|
| 498 | + __FUNCTION__, |
|
| 499 | + __LINE__ |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + return true; |
|
| 503 | + } else { |
|
| 504 | + if ($add_error) { |
|
| 505 | + EE_Error::add_error( |
|
| 506 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * _verify_config_params |
|
| 519 | + * |
|
| 520 | + * @access private |
|
| 521 | + * @param string $section |
|
| 522 | + * @param string $name |
|
| 523 | + * @param string $config_class |
|
| 524 | + * @param EE_Config_Base $config_obj |
|
| 525 | + * @param array $tests_to_run |
|
| 526 | + * @param bool $display_errors |
|
| 527 | + * @return bool TRUE on success, FALSE on fail |
|
| 528 | + */ |
|
| 529 | + private function _verify_config_params( |
|
| 530 | + $section = '', |
|
| 531 | + $name = '', |
|
| 532 | + $config_class = '', |
|
| 533 | + $config_obj = null, |
|
| 534 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | + $display_errors = true |
|
| 536 | + ) { |
|
| 537 | + try { |
|
| 538 | + foreach ($tests_to_run as $test) { |
|
| 539 | + switch ($test) { |
|
| 540 | + // TEST #1 : check that section was set |
|
| 541 | + case 1: |
|
| 542 | + if (empty($section)) { |
|
| 543 | + if ($display_errors) { |
|
| 544 | + throw new EE_Error( |
|
| 545 | + sprintf( |
|
| 546 | + __( |
|
| 547 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ), |
|
| 550 | + $config_class |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + break; |
|
| 557 | + // TEST #2 : check that settings section exists |
|
| 558 | + case 2: |
|
| 559 | + if (! isset($this->{$section})) { |
|
| 560 | + if ($display_errors) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + sprintf( |
|
| 563 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | + $section |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + break; |
|
| 571 | + // TEST #3 : check that section is the proper format |
|
| 572 | + case 3: |
|
| 573 | + if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | + ) { |
|
| 575 | + if ($display_errors) { |
|
| 576 | + throw new EE_Error( |
|
| 577 | + sprintf( |
|
| 578 | + __( |
|
| 579 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ), |
|
| 582 | + $section |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + return false; |
|
| 587 | + } |
|
| 588 | + break; |
|
| 589 | + // TEST #4 : check that config section name has been set |
|
| 590 | + case 4: |
|
| 591 | + if (empty($name)) { |
|
| 592 | + if ($display_errors) { |
|
| 593 | + throw new EE_Error( |
|
| 594 | + __( |
|
| 595 | + 'No name has been provided for the specific configuration section.', |
|
| 596 | + 'event_espresso' |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + break; |
|
| 603 | + // TEST #5 : check that a config class name has been set |
|
| 604 | + case 5: |
|
| 605 | + if (empty($config_class)) { |
|
| 606 | + if ($display_errors) { |
|
| 607 | + throw new EE_Error( |
|
| 608 | + __( |
|
| 609 | + 'No class name has been provided for the specific configuration section.', |
|
| 610 | + 'event_espresso' |
|
| 611 | + ) |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 616 | + break; |
|
| 617 | + // TEST #6 : verify config class is accessible |
|
| 618 | + case 6: |
|
| 619 | + if (! class_exists($config_class)) { |
|
| 620 | + if ($display_errors) { |
|
| 621 | + throw new EE_Error( |
|
| 622 | + sprintf( |
|
| 623 | + __( |
|
| 624 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | + 'event_espresso' |
|
| 626 | + ), |
|
| 627 | + $config_class |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + break; |
|
| 634 | + // TEST #7 : check that config has even been set |
|
| 635 | + case 7: |
|
| 636 | + if (! isset($this->{$section}->{$name})) { |
|
| 637 | + if ($display_errors) { |
|
| 638 | + throw new EE_Error( |
|
| 639 | + sprintf( |
|
| 640 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | + $section, |
|
| 642 | + $name |
|
| 643 | + ) |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } else { |
|
| 648 | + // and make sure it's not serialized |
|
| 649 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | + } |
|
| 651 | + break; |
|
| 652 | + // TEST #8 : check that config is the requested type |
|
| 653 | + case 8: |
|
| 654 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | + if ($display_errors) { |
|
| 656 | + throw new EE_Error( |
|
| 657 | + sprintf( |
|
| 658 | + __( |
|
| 659 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | + 'event_espresso' |
|
| 661 | + ), |
|
| 662 | + $section, |
|
| 663 | + $name, |
|
| 664 | + $config_class |
|
| 665 | + ) |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 670 | + break; |
|
| 671 | + // TEST #9 : verify config object |
|
| 672 | + case 9: |
|
| 673 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | + if ($display_errors) { |
|
| 675 | + throw new EE_Error( |
|
| 676 | + sprintf( |
|
| 677 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | + print_r($config_obj, true) |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } catch (EE_Error $e) { |
|
| 688 | + $e->get_error(); |
|
| 689 | + } |
|
| 690 | + // you have successfully run the gauntlet |
|
| 691 | + return true; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * _generate_config_option_name |
|
| 697 | + * |
|
| 698 | + * @access protected |
|
| 699 | + * @param string $section |
|
| 700 | + * @param string $name |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | + { |
|
| 705 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * _set_config_class |
|
| 711 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | + * |
|
| 713 | + * @access private |
|
| 714 | + * @param string $config_class |
|
| 715 | + * @param string $name |
|
| 716 | + * @return string |
|
| 717 | + */ |
|
| 718 | + private function _set_config_class($config_class = '', $name = '') |
|
| 719 | + { |
|
| 720 | + return ! empty($config_class) |
|
| 721 | + ? $config_class |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * set_config |
|
| 728 | + * |
|
| 729 | + * @access protected |
|
| 730 | + * @param string $section |
|
| 731 | + * @param string $name |
|
| 732 | + * @param string $config_class |
|
| 733 | + * @param EE_Config_Base $config_obj |
|
| 734 | + * @return EE_Config_Base |
|
| 735 | + */ |
|
| 736 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | + { |
|
| 738 | + // ensure config class is set to something |
|
| 739 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | + return null; |
|
| 743 | + } |
|
| 744 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | + $this->update_addon_option_names(); |
|
| 749 | + } |
|
| 750 | + // verify the incoming config object but suppress errors |
|
| 751 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | + $config_obj = new $config_class(); |
|
| 753 | + } |
|
| 754 | + if (get_option($config_option_name)) { |
|
| 755 | + EE_Config::log($config_option_name); |
|
| 756 | + update_option($config_option_name, $config_obj); |
|
| 757 | + $this->{$section}->{$name} = $config_obj; |
|
| 758 | + return $this->{$section}->{$name}; |
|
| 759 | + } else { |
|
| 760 | + // create a wp-option for this config |
|
| 761 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | + return $this->{$section}->{$name}; |
|
| 764 | + } else { |
|
| 765 | + EE_Error::add_error( |
|
| 766 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | + __FILE__, |
|
| 768 | + __FUNCTION__, |
|
| 769 | + __LINE__ |
|
| 770 | + ); |
|
| 771 | + return null; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * update_config |
|
| 779 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | + * |
|
| 781 | + * @access public |
|
| 782 | + * @param string $section |
|
| 783 | + * @param string $name |
|
| 784 | + * @param EE_Config_Base|string $config_obj |
|
| 785 | + * @param bool $throw_errors |
|
| 786 | + * @return bool |
|
| 787 | + */ |
|
| 788 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | + { |
|
| 790 | + // don't allow config updates during WP heartbeats |
|
| 791 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + $config_obj = maybe_unserialize($config_obj); |
|
| 795 | + // get class name of the incoming object |
|
| 796 | + $config_class = get_class($config_obj); |
|
| 797 | + // run tests 1-5 and 9 to verify config |
|
| 798 | + if (! $this->_verify_config_params( |
|
| 799 | + $section, |
|
| 800 | + $name, |
|
| 801 | + $config_class, |
|
| 802 | + $config_obj, |
|
| 803 | + array(1, 2, 3, 4, 7, 9) |
|
| 804 | + ) |
|
| 805 | + ) { |
|
| 806 | + return false; |
|
| 807 | + } |
|
| 808 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | + // save new config to db |
|
| 812 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | + return true; |
|
| 814 | + } |
|
| 815 | + } else { |
|
| 816 | + // first check if the record already exists |
|
| 817 | + $existing_config = get_option($config_option_name); |
|
| 818 | + $config_obj = serialize($config_obj); |
|
| 819 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | + if ($existing_config == $config_obj) { |
|
| 821 | + $this->{$section}->{$name} = $config_obj; |
|
| 822 | + return true; |
|
| 823 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | + EE_Config::log($config_option_name); |
|
| 825 | + // update wp-option for this config class |
|
| 826 | + $this->{$section}->{$name} = $config_obj; |
|
| 827 | + return true; |
|
| 828 | + } elseif ($throw_errors) { |
|
| 829 | + EE_Error::add_error( |
|
| 830 | + sprintf( |
|
| 831 | + __( |
|
| 832 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | + 'event_espresso' |
|
| 834 | + ), |
|
| 835 | + $config_class, |
|
| 836 | + 'EE_Config->' . $section . '->' . $name |
|
| 837 | + ), |
|
| 838 | + __FILE__, |
|
| 839 | + __FUNCTION__, |
|
| 840 | + __LINE__ |
|
| 841 | + ); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * get_config |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @param string $section |
|
| 853 | + * @param string $name |
|
| 854 | + * @param string $config_class |
|
| 855 | + * @return mixed EE_Config_Base | NULL |
|
| 856 | + */ |
|
| 857 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | + { |
|
| 859 | + // ensure config class is set to something |
|
| 860 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | + return null; |
|
| 864 | + } |
|
| 865 | + // now test if the requested config object exists, but suppress errors |
|
| 866 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | + // config already exists, so pass it back |
|
| 868 | + return $this->{$section}->{$name}; |
|
| 869 | + } |
|
| 870 | + // load config option from db if it exists |
|
| 871 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | + // verify the newly retrieved config object, but suppress errors |
|
| 873 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | + // config is good, so set it and pass it back |
|
| 875 | + $this->{$section}->{$name} = $config_obj; |
|
| 876 | + return $this->{$section}->{$name}; |
|
| 877 | + } |
|
| 878 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | + // verify the newly created config object |
|
| 881 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | + return $this->{$section}->{$name}; |
|
| 883 | + } else { |
|
| 884 | + EE_Error::add_error( |
|
| 885 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | + __FILE__, |
|
| 887 | + __FUNCTION__, |
|
| 888 | + __LINE__ |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + return null; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * get_config_option |
|
| 897 | + * |
|
| 898 | + * @access public |
|
| 899 | + * @param string $config_option_name |
|
| 900 | + * @return mixed EE_Config_Base | FALSE |
|
| 901 | + */ |
|
| 902 | + public function get_config_option($config_option_name = '') |
|
| 903 | + { |
|
| 904 | + // retrieve the wp-option for this config class. |
|
| 905 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | + if (empty($config_option)) { |
|
| 907 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | + } |
|
| 909 | + return $config_option; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * log |
|
| 915 | + * |
|
| 916 | + * @param string $config_option_name |
|
| 917 | + */ |
|
| 918 | + public static function log($config_option_name = '') |
|
| 919 | + { |
|
| 920 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | + // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | + $_request = $_REQUEST; |
|
| 924 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | + $config_log[ (string) microtime(true) ] = array( |
|
| 926 | + 'config_name' => $config_option_name, |
|
| 927 | + 'request' => $_request, |
|
| 928 | + ); |
|
| 929 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * trim_log |
|
| 936 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | + */ |
|
| 938 | + public static function trim_log() |
|
| 939 | + { |
|
| 940 | + if (! EE_Config::logging_enabled()) { |
|
| 941 | + return; |
|
| 942 | + } |
|
| 943 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | + $log_length = count($config_log); |
|
| 945 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | + ksort($config_log); |
|
| 947 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * get_page_for_posts |
|
| 955 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | + * |
|
| 958 | + * @access public |
|
| 959 | + * @return string |
|
| 960 | + */ |
|
| 961 | + public static function get_page_for_posts() |
|
| 962 | + { |
|
| 963 | + $page_for_posts = get_option('page_for_posts'); |
|
| 964 | + if (! $page_for_posts) { |
|
| 965 | + return 'posts'; |
|
| 966 | + } |
|
| 967 | + /** @type WPDB $wpdb */ |
|
| 968 | + global $wpdb; |
|
| 969 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * register_shortcodes_and_modules. |
|
| 976 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | + * so they can help trigger maintenance mode if it's needed |
|
| 979 | + * |
|
| 980 | + * @access public |
|
| 981 | + * @return void |
|
| 982 | + */ |
|
| 983 | + public function register_shortcodes_and_modules() |
|
| 984 | + { |
|
| 985 | + // allow modules to set hooks for the rest of the system |
|
| 986 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * initialize_shortcodes_and_modules |
|
| 992 | + * meaning they can start adding their hooks to get stuff done |
|
| 993 | + * |
|
| 994 | + * @access public |
|
| 995 | + * @return void |
|
| 996 | + */ |
|
| 997 | + public function initialize_shortcodes_and_modules() |
|
| 998 | + { |
|
| 999 | + // allow modules to set hooks for the rest of the system |
|
| 1000 | + $this->_initialize_modules(); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * widgets_init |
|
| 1006 | + * |
|
| 1007 | + * @access private |
|
| 1008 | + * @return void |
|
| 1009 | + */ |
|
| 1010 | + public function widgets_init() |
|
| 1011 | + { |
|
| 1012 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | + // on frontend when not in any maintenance mode |
|
| 1014 | + if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | + || ( |
|
| 1016 | + is_admin() |
|
| 1017 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | + ) |
|
| 1019 | + ) { |
|
| 1020 | + // grab list of installed widgets |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | + // filter list of modules to register |
|
| 1023 | + $widgets_to_register = apply_filters( |
|
| 1024 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | + $widgets_to_register |
|
| 1026 | + ); |
|
| 1027 | + if (! empty($widgets_to_register)) { |
|
| 1028 | + // cycle thru widget folders |
|
| 1029 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | + // add to list of installed widget modules |
|
| 1031 | + EE_Config::register_ee_widget($widget_path); |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + // filter list of installed modules |
|
| 1035 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | + EE_Registry::instance()->widgets |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * register_ee_widget - makes core aware of this widget |
|
| 1045 | + * |
|
| 1046 | + * @access public |
|
| 1047 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function register_ee_widget($widget_path = null) |
|
| 1051 | + { |
|
| 1052 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | + $widget_ext = '.widget.php'; |
|
| 1054 | + // make all separators match |
|
| 1055 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | + $file_name = explode('.', basename($widget_path)); |
|
| 1060 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | + // sanitize shortcode directory name |
|
| 1063 | + $widget = sanitize_key($widget); |
|
| 1064 | + // now we need to rebuild the shortcode path |
|
| 1065 | + $widget_path = explode('/', $widget_path); |
|
| 1066 | + // remove last segment |
|
| 1067 | + array_pop($widget_path); |
|
| 1068 | + // glue it back together |
|
| 1069 | + $widget_path = implode(DS, $widget_path); |
|
| 1070 | + } else { |
|
| 1071 | + // grab and sanitize widget directory name |
|
| 1072 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | + } |
|
| 1074 | + // create classname from widget directory name |
|
| 1075 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | + // add class prefix |
|
| 1077 | + $widget_class = 'EEW_' . $widget; |
|
| 1078 | + // does the widget exist ? |
|
| 1079 | + if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1080 | + $msg = sprintf( |
|
| 1081 | + __( |
|
| 1082 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | + 'event_espresso' |
|
| 1084 | + ), |
|
| 1085 | + $widget_class, |
|
| 1086 | + $widget_path . '/' . $widget_class . $widget_ext |
|
| 1087 | + ); |
|
| 1088 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + // load the widget class file |
|
| 1092 | + require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1093 | + // verify that class exists |
|
| 1094 | + if (! class_exists($widget_class)) { |
|
| 1095 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | + return; |
|
| 1098 | + } |
|
| 1099 | + register_widget($widget_class); |
|
| 1100 | + // add to array of registered widgets |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * _register_modules |
|
| 1107 | + * |
|
| 1108 | + * @access private |
|
| 1109 | + * @return array |
|
| 1110 | + */ |
|
| 1111 | + private function _register_modules() |
|
| 1112 | + { |
|
| 1113 | + // grab list of installed modules |
|
| 1114 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | + // filter list of modules to register |
|
| 1116 | + $modules_to_register = apply_filters( |
|
| 1117 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | + $modules_to_register |
|
| 1119 | + ); |
|
| 1120 | + if (! empty($modules_to_register)) { |
|
| 1121 | + // loop through folders |
|
| 1122 | + foreach ($modules_to_register as $module_path) { |
|
| 1123 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | + if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | + ) { |
|
| 1127 | + // add to list of installed modules |
|
| 1128 | + EE_Config::register_module($module_path); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + // filter list of installed modules |
|
| 1133 | + return apply_filters( |
|
| 1134 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | + EE_Registry::instance()->modules |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * register_module - makes core aware of this module |
|
| 1142 | + * |
|
| 1143 | + * @access public |
|
| 1144 | + * @param string $module_path - full path up to and including module folder |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public static function register_module($module_path = null) |
|
| 1148 | + { |
|
| 1149 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | + $module_ext = '.module.php'; |
|
| 1151 | + // make all separators match |
|
| 1152 | + $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1153 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | + $module_file = explode('.', basename($module_path)); |
|
| 1157 | + // now we need to rebuild the shortcode path |
|
| 1158 | + $module_path = explode('/', $module_path); |
|
| 1159 | + // remove last segment |
|
| 1160 | + array_pop($module_path); |
|
| 1161 | + // glue it back together |
|
| 1162 | + $module_path = implode('/', $module_path) . '/'; |
|
| 1163 | + // take first segment from file name pieces and sanitize it |
|
| 1164 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | + // ensure class prefix is added |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | + } else { |
|
| 1168 | + // we need to generate the filename based off of the folder name |
|
| 1169 | + // grab and sanitize module name |
|
| 1170 | + $module = strtolower(basename($module_path)); |
|
| 1171 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | + // like trailingslashit() |
|
| 1173 | + $module_path = rtrim($module_path, '/') . '/'; |
|
| 1174 | + // create classname from module directory name |
|
| 1175 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | + // add class prefix |
|
| 1177 | + $module_class = 'EED_' . $module; |
|
| 1178 | + } |
|
| 1179 | + // does the module exist ? |
|
| 1180 | + if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1181 | + $msg = sprintf( |
|
| 1182 | + __( |
|
| 1183 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | + 'event_espresso' |
|
| 1185 | + ), |
|
| 1186 | + $module |
|
| 1187 | + ); |
|
| 1188 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | + return false; |
|
| 1190 | + } |
|
| 1191 | + // load the module class file |
|
| 1192 | + require_once($module_path . $module_class . $module_ext); |
|
| 1193 | + // verify that class exists |
|
| 1194 | + if (! class_exists($module_class)) { |
|
| 1195 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | + return false; |
|
| 1198 | + } |
|
| 1199 | + // add to array of registered modules |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | + do_action( |
|
| 1202 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | + $module_class, |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | + ); |
|
| 1206 | + return true; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * _initialize_modules |
|
| 1212 | + * allow modules to set hooks for the rest of the system |
|
| 1213 | + * |
|
| 1214 | + * @access private |
|
| 1215 | + * @return void |
|
| 1216 | + */ |
|
| 1217 | + private function _initialize_modules() |
|
| 1218 | + { |
|
| 1219 | + // cycle thru shortcode folders |
|
| 1220 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | + // which set hooks ? |
|
| 1223 | + if (is_admin()) { |
|
| 1224 | + // fire immediately |
|
| 1225 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | + } else { |
|
| 1227 | + // delay until other systems are online |
|
| 1228 | + add_action( |
|
| 1229 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | + array($module_class, 'set_hooks') |
|
| 1231 | + ); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * register_route - adds module method routes to route_map |
|
| 1239 | + * |
|
| 1240 | + * @access public |
|
| 1241 | + * @param string $route - "pretty" public alias for module method |
|
| 1242 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | + * @param string $method_name - the actual module method to be routed to |
|
| 1244 | + * @param string $key - url param key indicating a route is being called |
|
| 1245 | + * @return bool |
|
| 1246 | + */ |
|
| 1247 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | + { |
|
| 1249 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | + $module = str_replace('EED_', '', $module); |
|
| 1251 | + $module_class = 'EED_' . $module; |
|
| 1252 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | + return false; |
|
| 1256 | + } |
|
| 1257 | + if (empty($route)) { |
|
| 1258 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | + return false; |
|
| 1261 | + } |
|
| 1262 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | + $msg = sprintf( |
|
| 1264 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | + $route |
|
| 1266 | + ); |
|
| 1267 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | + return true; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * get_route - get module method route |
|
| 1277 | + * |
|
| 1278 | + * @access public |
|
| 1279 | + * @param string $route - "pretty" public alias for module method |
|
| 1280 | + * @param string $key - url param key indicating a route is being called |
|
| 1281 | + * @return string |
|
| 1282 | + */ |
|
| 1283 | + public static function get_route($route = null, $key = 'ee') |
|
| 1284 | + { |
|
| 1285 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | + } |
|
| 1290 | + return null; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * get_routes - get ALL module method routes |
|
| 1296 | + * |
|
| 1297 | + * @access public |
|
| 1298 | + * @return array |
|
| 1299 | + */ |
|
| 1300 | + public static function get_routes() |
|
| 1301 | + { |
|
| 1302 | + return EE_Config::$_module_route_map; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | + * |
|
| 1309 | + * @access public |
|
| 1310 | + * @param string $route - "pretty" public alias for module method |
|
| 1311 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | + * class, allows different forwards to be served based on status |
|
| 1313 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | + * @param string $key - url param key indicating a route is being called |
|
| 1315 | + * @return bool |
|
| 1316 | + */ |
|
| 1317 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | + { |
|
| 1319 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | + $msg = sprintf( |
|
| 1322 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | + $route |
|
| 1324 | + ); |
|
| 1325 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | + return false; |
|
| 1327 | + } |
|
| 1328 | + if (empty($forward)) { |
|
| 1329 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | + return false; |
|
| 1332 | + } |
|
| 1333 | + if (is_array($forward)) { |
|
| 1334 | + if (! isset($forward[1])) { |
|
| 1335 | + $msg = sprintf( |
|
| 1336 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | + $route |
|
| 1338 | + ); |
|
| 1339 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | + return false; |
|
| 1341 | + } |
|
| 1342 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | + $msg = sprintf( |
|
| 1344 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | + $forward[1], |
|
| 1346 | + $route |
|
| 1347 | + ); |
|
| 1348 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | + return false; |
|
| 1350 | + } |
|
| 1351 | + } elseif (! function_exists($forward)) { |
|
| 1352 | + $msg = sprintf( |
|
| 1353 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | + $forward, |
|
| 1355 | + $route |
|
| 1356 | + ); |
|
| 1357 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | + return false; |
|
| 1359 | + } |
|
| 1360 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | + return true; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + /** |
|
| 1366 | + * get_forward - get forwarding route |
|
| 1367 | + * |
|
| 1368 | + * @access public |
|
| 1369 | + * @param string $route - "pretty" public alias for module method |
|
| 1370 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | + * allows different forwards to be served based on status |
|
| 1372 | + * @param string $key - url param key indicating a route is being called |
|
| 1373 | + * @return string |
|
| 1374 | + */ |
|
| 1375 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | + { |
|
| 1377 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | + return apply_filters( |
|
| 1380 | + 'FHEE__EE_Config__get_forward', |
|
| 1381 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | + $route, |
|
| 1383 | + $status |
|
| 1384 | + ); |
|
| 1385 | + } |
|
| 1386 | + return null; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | + * results |
|
| 1393 | + * |
|
| 1394 | + * @access public |
|
| 1395 | + * @param string $route - "pretty" public alias for module method |
|
| 1396 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | + * allows different views to be served based on status |
|
| 1398 | + * @param string $view |
|
| 1399 | + * @param string $key - url param key indicating a route is being called |
|
| 1400 | + * @return bool |
|
| 1401 | + */ |
|
| 1402 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | + { |
|
| 1404 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | + $msg = sprintf( |
|
| 1407 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | + $route |
|
| 1409 | + ); |
|
| 1410 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | + return false; |
|
| 1412 | + } |
|
| 1413 | + if (! is_readable($view)) { |
|
| 1414 | + $msg = sprintf( |
|
| 1415 | + __( |
|
| 1416 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | + 'event_espresso' |
|
| 1418 | + ), |
|
| 1419 | + $view |
|
| 1420 | + ); |
|
| 1421 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | + return false; |
|
| 1423 | + } |
|
| 1424 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | + return true; |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * get_view - get view for route and status |
|
| 1431 | + * |
|
| 1432 | + * @access public |
|
| 1433 | + * @param string $route - "pretty" public alias for module method |
|
| 1434 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | + * allows different views to be served based on status |
|
| 1436 | + * @param string $key - url param key indicating a route is being called |
|
| 1437 | + * @return string |
|
| 1438 | + */ |
|
| 1439 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | + { |
|
| 1441 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | + return apply_filters( |
|
| 1444 | + 'FHEE__EE_Config__get_view', |
|
| 1445 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | + $route, |
|
| 1447 | + $status |
|
| 1448 | + ); |
|
| 1449 | + } |
|
| 1450 | + return null; |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + |
|
| 1454 | + public function update_addon_option_names() |
|
| 1455 | + { |
|
| 1456 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + public function shutdown() |
|
| 1461 | + { |
|
| 1462 | + $this->update_addon_option_names(); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * @return LegacyShortcodesManager |
|
| 1468 | + */ |
|
| 1469 | + public static function getLegacyShortcodesManager() |
|
| 1470 | + { |
|
| 1471 | + |
|
| 1472 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | + EE_Registry::instance() |
|
| 1475 | + ); |
|
| 1476 | + } |
|
| 1477 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * register_shortcode - makes core aware of this shortcode |
|
| 1483 | + * |
|
| 1484 | + * @deprecated 4.9.26 |
|
| 1485 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | + * @return bool |
|
| 1487 | + */ |
|
| 1488 | + public static function register_shortcode($shortcode_path = null) |
|
| 1489 | + { |
|
| 1490 | + EE_Error::doing_it_wrong( |
|
| 1491 | + __METHOD__, |
|
| 1492 | + __( |
|
| 1493 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | + 'event_espresso' |
|
| 1495 | + ), |
|
| 1496 | + '4.9.26' |
|
| 1497 | + ); |
|
| 1498 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | + } |
|
| 1500 | +} |
|
| 2262 | 1501 | |
| 2263 | - /** |
|
| 2264 | - * ReCaptcha Type |
|
| 2265 | - * |
|
| 2266 | - * @var string $recaptcha_type |
|
| 2267 | - * options: 'audio', 'image' |
|
| 2268 | - */ |
|
| 2269 | - public $recaptcha_type; |
|
| 1502 | +/** |
|
| 1503 | + * Base class used for config classes. These classes should generally not have |
|
| 1504 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | + * basically, they should just be well-defined stdClasses |
|
| 1506 | + */ |
|
| 1507 | +class EE_Config_Base |
|
| 1508 | +{ |
|
| 2270 | 1509 | |
| 2271 | - /** |
|
| 2272 | - * ReCaptcha language |
|
| 2273 | - * |
|
| 2274 | - * @var string $recaptcha_language |
|
| 2275 | - * eg 'en' |
|
| 2276 | - */ |
|
| 2277 | - public $recaptcha_language; |
|
| 1510 | + /** |
|
| 1511 | + * Utility function for escaping the value of a property and returning. |
|
| 1512 | + * |
|
| 1513 | + * @param string $property property name (checks to see if exists). |
|
| 1514 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | + * @throws \EE_Error |
|
| 1516 | + */ |
|
| 1517 | + public function get_pretty($property) |
|
| 1518 | + { |
|
| 1519 | + if (! property_exists($this, $property)) { |
|
| 1520 | + throw new EE_Error( |
|
| 1521 | + sprintf( |
|
| 1522 | + __( |
|
| 1523 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | + 'event_espresso' |
|
| 1525 | + ), |
|
| 1526 | + get_class($this), |
|
| 1527 | + $property |
|
| 1528 | + ) |
|
| 1529 | + ); |
|
| 1530 | + } |
|
| 1531 | + // just handling escaping of strings for now. |
|
| 1532 | + if (is_string($this->{$property})) { |
|
| 1533 | + return stripslashes($this->{$property}); |
|
| 1534 | + } |
|
| 1535 | + return $this->{$property}; |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + public function populate() |
|
| 1540 | + { |
|
| 1541 | + // grab defaults via a new instance of this class. |
|
| 1542 | + $class_name = get_class($this); |
|
| 1543 | + $defaults = new $class_name; |
|
| 1544 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | + // default from our $defaults object. |
|
| 1546 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | + if ($this->{$property} === null) { |
|
| 1548 | + $this->{$property} = $value; |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + // cleanup |
|
| 1552 | + unset($defaults); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * __isset |
|
| 1558 | + * |
|
| 1559 | + * @param $a |
|
| 1560 | + * @return bool |
|
| 1561 | + */ |
|
| 1562 | + public function __isset($a) |
|
| 1563 | + { |
|
| 1564 | + return false; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * __unset |
|
| 1570 | + * |
|
| 1571 | + * @param $a |
|
| 1572 | + * @return bool |
|
| 1573 | + */ |
|
| 1574 | + public function __unset($a) |
|
| 1575 | + { |
|
| 1576 | + return false; |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + |
|
| 1580 | + /** |
|
| 1581 | + * __clone |
|
| 1582 | + */ |
|
| 1583 | + public function __clone() |
|
| 1584 | + { |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * __wakeup |
|
| 1590 | + */ |
|
| 1591 | + public function __wakeup() |
|
| 1592 | + { |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * __destruct |
|
| 1598 | + */ |
|
| 1599 | + public function __destruct() |
|
| 1600 | + { |
|
| 1601 | + } |
|
| 1602 | +} |
|
| 2278 | 1603 | |
| 2279 | - /** |
|
| 2280 | - * ReCaptcha public key |
|
| 2281 | - * |
|
| 2282 | - * @var string $recaptcha_publickey |
|
| 2283 | - */ |
|
| 2284 | - public $recaptcha_publickey; |
|
| 1604 | +/** |
|
| 1605 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | + */ |
|
| 1607 | +class EE_Core_Config extends EE_Config_Base |
|
| 1608 | +{ |
|
| 2285 | 1609 | |
| 2286 | - /** |
|
| 2287 | - * ReCaptcha private key |
|
| 2288 | - * |
|
| 2289 | - * @var string $recaptcha_privatekey |
|
| 2290 | - */ |
|
| 2291 | - public $recaptcha_privatekey; |
|
| 1610 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | + |
|
| 1612 | + |
|
| 1613 | + public $current_blog_id; |
|
| 1614 | + |
|
| 1615 | + public $ee_ueip_optin; |
|
| 1616 | + |
|
| 1617 | + public $ee_ueip_has_notified; |
|
| 1618 | + |
|
| 1619 | + /** |
|
| 1620 | + * Not to be confused with the 4 critical page variables (See |
|
| 1621 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | + * |
|
| 1625 | + * @var array |
|
| 1626 | + */ |
|
| 1627 | + public $post_shortcodes; |
|
| 1628 | + |
|
| 1629 | + public $module_route_map; |
|
| 1630 | + |
|
| 1631 | + public $module_forward_map; |
|
| 1632 | + |
|
| 1633 | + public $module_view_map; |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | + * |
|
| 1638 | + * @var int |
|
| 1639 | + */ |
|
| 1640 | + public $reg_page_id; |
|
| 1641 | + |
|
| 1642 | + public $txn_page_id; |
|
| 1643 | + |
|
| 1644 | + public $thank_you_page_id; |
|
| 1645 | + |
|
| 1646 | + public $cancel_page_id; |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | + * |
|
| 1651 | + * @var int |
|
| 1652 | + */ |
|
| 1653 | + public $reg_page_url; |
|
| 1654 | + |
|
| 1655 | + public $txn_page_url; |
|
| 1656 | + |
|
| 1657 | + public $thank_you_page_url; |
|
| 1658 | + |
|
| 1659 | + public $cancel_page_url; |
|
| 1660 | + |
|
| 1661 | + /** |
|
| 1662 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | + */ |
|
| 1664 | + public $event_cpt_slug; |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | + * request across blog switches in a multisite context. |
|
| 1669 | + * Avoids extra queries to the db for this option. |
|
| 1670 | + * |
|
| 1671 | + * @var bool |
|
| 1672 | + */ |
|
| 1673 | + public static $ee_ueip_option; |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * class constructor |
|
| 1678 | + * |
|
| 1679 | + * @access public |
|
| 1680 | + */ |
|
| 1681 | + public function __construct() |
|
| 1682 | + { |
|
| 1683 | + // set default organization settings |
|
| 1684 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | + $this->post_shortcodes = array(); |
|
| 1689 | + $this->module_route_map = array(); |
|
| 1690 | + $this->module_forward_map = array(); |
|
| 1691 | + $this->module_view_map = array(); |
|
| 1692 | + // critical EE page IDs |
|
| 1693 | + $this->reg_page_id = 0; |
|
| 1694 | + $this->txn_page_id = 0; |
|
| 1695 | + $this->thank_you_page_id = 0; |
|
| 1696 | + $this->cancel_page_id = 0; |
|
| 1697 | + // critical EE page URLs |
|
| 1698 | + $this->reg_page_url = ''; |
|
| 1699 | + $this->txn_page_url = ''; |
|
| 1700 | + $this->thank_you_page_url = ''; |
|
| 1701 | + $this->cancel_page_url = ''; |
|
| 1702 | + // cpt slugs |
|
| 1703 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | + // ueip constant check |
|
| 1705 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | + $this->ee_ueip_optin = false; |
|
| 1707 | + $this->ee_ueip_has_notified = true; |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * @return array |
|
| 1714 | + */ |
|
| 1715 | + public function get_critical_pages_array() |
|
| 1716 | + { |
|
| 1717 | + return array( |
|
| 1718 | + $this->reg_page_id, |
|
| 1719 | + $this->txn_page_id, |
|
| 1720 | + $this->thank_you_page_id, |
|
| 1721 | + $this->cancel_page_id, |
|
| 1722 | + ); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * @return array |
|
| 1728 | + */ |
|
| 1729 | + public function get_critical_pages_shortcodes_array() |
|
| 1730 | + { |
|
| 1731 | + return array( |
|
| 1732 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | + ); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * gets/returns URL for EE reg_page |
|
| 1742 | + * |
|
| 1743 | + * @access public |
|
| 1744 | + * @return string |
|
| 1745 | + */ |
|
| 1746 | + public function reg_page_url() |
|
| 1747 | + { |
|
| 1748 | + if (! $this->reg_page_url) { |
|
| 1749 | + $this->reg_page_url = add_query_arg( |
|
| 1750 | + array('uts' => time()), |
|
| 1751 | + get_permalink($this->reg_page_id) |
|
| 1752 | + ) . '#checkout'; |
|
| 1753 | + } |
|
| 1754 | + return $this->reg_page_url; |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + |
|
| 1758 | + /** |
|
| 1759 | + * gets/returns URL for EE txn_page |
|
| 1760 | + * |
|
| 1761 | + * @param array $query_args like what gets passed to |
|
| 1762 | + * add_query_arg() as the first argument |
|
| 1763 | + * @access public |
|
| 1764 | + * @return string |
|
| 1765 | + */ |
|
| 1766 | + public function txn_page_url($query_args = array()) |
|
| 1767 | + { |
|
| 1768 | + if (! $this->txn_page_url) { |
|
| 1769 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | + } |
|
| 1771 | + if ($query_args) { |
|
| 1772 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | + } else { |
|
| 1774 | + return $this->txn_page_url; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * gets/returns URL for EE thank_you_page |
|
| 1781 | + * |
|
| 1782 | + * @param array $query_args like what gets passed to |
|
| 1783 | + * add_query_arg() as the first argument |
|
| 1784 | + * @access public |
|
| 1785 | + * @return string |
|
| 1786 | + */ |
|
| 1787 | + public function thank_you_page_url($query_args = array()) |
|
| 1788 | + { |
|
| 1789 | + if (! $this->thank_you_page_url) { |
|
| 1790 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | + } |
|
| 1792 | + if ($query_args) { |
|
| 1793 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | + } else { |
|
| 1795 | + return $this->thank_you_page_url; |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * gets/returns URL for EE cancel_page |
|
| 1802 | + * |
|
| 1803 | + * @access public |
|
| 1804 | + * @return string |
|
| 1805 | + */ |
|
| 1806 | + public function cancel_page_url() |
|
| 1807 | + { |
|
| 1808 | + if (! $this->cancel_page_url) { |
|
| 1809 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | + } |
|
| 1811 | + return $this->cancel_page_url; |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | + * |
|
| 1818 | + * @since 4.7.5 |
|
| 1819 | + */ |
|
| 1820 | + protected function _reset_urls() |
|
| 1821 | + { |
|
| 1822 | + $this->reg_page_url = ''; |
|
| 1823 | + $this->txn_page_url = ''; |
|
| 1824 | + $this->cancel_page_url = ''; |
|
| 1825 | + $this->thank_you_page_url = ''; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | + * on the main site only. |
|
| 1833 | + * |
|
| 1834 | + * @return bool |
|
| 1835 | + */ |
|
| 1836 | + protected function _get_main_ee_ueip_optin() |
|
| 1837 | + { |
|
| 1838 | + // if this is the main site then we can just bypass our direct query. |
|
| 1839 | + if (is_main_site()) { |
|
| 1840 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | + } |
|
| 1842 | + // is this already cached for this request? If so use it. |
|
| 1843 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | + } |
|
| 1846 | + global $wpdb; |
|
| 1847 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | + $option = self::OPTION_NAME_UXIP; |
|
| 1850 | + // set correct table for query |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | + // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | + // for the purpose of caching. |
|
| 1857 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | + if (false !== $pre) { |
|
| 1859 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | + } |
|
| 1862 | + $row = $wpdb->get_row( |
|
| 1863 | + $wpdb->prepare( |
|
| 1864 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | + $option |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + if (is_object($row)) { |
|
| 1869 | + $value = $row->option_value; |
|
| 1870 | + } else { // option does not exist so use default. |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | + } |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * Utility function for escaping the value of a property and returning. |
|
| 1881 | + * |
|
| 1882 | + * @param string $property property name (checks to see if exists). |
|
| 1883 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | + * @throws \EE_Error |
|
| 1885 | + */ |
|
| 1886 | + public function get_pretty($property) |
|
| 1887 | + { |
|
| 1888 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | + } |
|
| 1891 | + return parent::get_pretty($property); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | + * on the object. |
|
| 1898 | + * |
|
| 1899 | + * @return array |
|
| 1900 | + */ |
|
| 1901 | + public function __sleep() |
|
| 1902 | + { |
|
| 1903 | + // reset all url properties |
|
| 1904 | + $this->_reset_urls(); |
|
| 1905 | + // return what to save to db |
|
| 1906 | + return array_keys(get_object_vars($this)); |
|
| 1907 | + } |
|
| 1908 | +} |
|
| 2292 | 1909 | |
| 2293 | - /** |
|
| 2294 | - * array of form names protected by ReCaptcha |
|
| 2295 | - * |
|
| 2296 | - * @var array $recaptcha_protected_forms |
|
| 2297 | - */ |
|
| 2298 | - public $recaptcha_protected_forms; |
|
| 1910 | +/** |
|
| 1911 | + * Config class for storing info on the Organization |
|
| 1912 | + */ |
|
| 1913 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | +{ |
|
| 2299 | 1915 | |
| 2300 | - /** |
|
| 2301 | - * ReCaptcha width |
|
| 2302 | - * |
|
| 2303 | - * @var int $recaptcha_width |
|
| 2304 | - * @deprecated |
|
| 2305 | - */ |
|
| 2306 | - public $recaptcha_width; |
|
| 1916 | + /** |
|
| 1917 | + * @var string $name |
|
| 1918 | + * eg EE4.1 |
|
| 1919 | + */ |
|
| 1920 | + public $name; |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * @var string $address_1 |
|
| 1924 | + * eg 123 Onna Road |
|
| 1925 | + */ |
|
| 1926 | + public $address_1 = ''; |
|
| 1927 | + |
|
| 1928 | + /** |
|
| 1929 | + * @var string $address_2 |
|
| 1930 | + * eg PO Box 123 |
|
| 1931 | + */ |
|
| 1932 | + public $address_2 = ''; |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * @var string $city |
|
| 1936 | + * eg Inna City |
|
| 1937 | + */ |
|
| 1938 | + public $city = ''; |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * @var int $STA_ID |
|
| 1942 | + * eg 4 |
|
| 1943 | + */ |
|
| 1944 | + public $STA_ID = 0; |
|
| 1945 | + |
|
| 1946 | + /** |
|
| 1947 | + * @var string $CNT_ISO |
|
| 1948 | + * eg US |
|
| 1949 | + */ |
|
| 1950 | + public $CNT_ISO = ''; |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * @var string $zip |
|
| 1954 | + * eg 12345 or V1A 2B3 |
|
| 1955 | + */ |
|
| 1956 | + public $zip = ''; |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * @var string $email |
|
| 1960 | + * eg [email protected] |
|
| 1961 | + */ |
|
| 1962 | + public $email; |
|
| 1963 | + |
|
| 1964 | + /** |
|
| 1965 | + * @var string $phone |
|
| 1966 | + * eg. 111-111-1111 |
|
| 1967 | + */ |
|
| 1968 | + public $phone = ''; |
|
| 1969 | + |
|
| 1970 | + /** |
|
| 1971 | + * @var string $vat |
|
| 1972 | + * VAT/Tax Number |
|
| 1973 | + */ |
|
| 1974 | + public $vat = ''; |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * @var string $logo_url |
|
| 1978 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | + */ |
|
| 1980 | + public $logo_url = ''; |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | + * |
|
| 1985 | + * @var string |
|
| 1986 | + */ |
|
| 1987 | + /** |
|
| 1988 | + * facebook (facebook.com/profile.name) |
|
| 1989 | + * |
|
| 1990 | + * @var string |
|
| 1991 | + */ |
|
| 1992 | + public $facebook = ''; |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * twitter (twitter.com/twitter_handle) |
|
| 1996 | + * |
|
| 1997 | + * @var string |
|
| 1998 | + */ |
|
| 1999 | + public $twitter = ''; |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | + * |
|
| 2004 | + * @var string |
|
| 2005 | + */ |
|
| 2006 | + public $linkedin = ''; |
|
| 2007 | + |
|
| 2008 | + /** |
|
| 2009 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | + * |
|
| 2011 | + * @var string |
|
| 2012 | + */ |
|
| 2013 | + public $pinterest = ''; |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * google+ (google.com/+profileName) |
|
| 2017 | + * |
|
| 2018 | + * @var string |
|
| 2019 | + */ |
|
| 2020 | + public $google = ''; |
|
| 2021 | + |
|
| 2022 | + /** |
|
| 2023 | + * instagram (instagram.com/handle) |
|
| 2024 | + * |
|
| 2025 | + * @var string |
|
| 2026 | + */ |
|
| 2027 | + public $instagram = ''; |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * class constructor |
|
| 2032 | + * |
|
| 2033 | + * @access public |
|
| 2034 | + */ |
|
| 2035 | + public function __construct() |
|
| 2036 | + { |
|
| 2037 | + // set default organization settings |
|
| 2038 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | + $this->email = get_bloginfo('admin_email'); |
|
| 2041 | + } |
|
| 2042 | +} |
|
| 2307 | 2043 | |
| 2308 | - /** |
|
| 2309 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | - * |
|
| 2311 | - * @var boolean $track_invalid_checkout_access |
|
| 2312 | - */ |
|
| 2313 | - protected $track_invalid_checkout_access = true; |
|
| 2044 | +/** |
|
| 2045 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | + */ |
|
| 2047 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | +{ |
|
| 2314 | 2049 | |
| 2315 | - /** |
|
| 2316 | - * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | - * |
|
| 2318 | - * @var bool |
|
| 2319 | - */ |
|
| 2320 | - public $consent_checkbox_enabled; |
|
| 2050 | + /** |
|
| 2051 | + * @var string $code |
|
| 2052 | + * eg 'US' |
|
| 2053 | + */ |
|
| 2054 | + public $code; |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * @var string $name |
|
| 2058 | + * eg 'Dollar' |
|
| 2059 | + */ |
|
| 2060 | + public $name; |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * plural name |
|
| 2064 | + * |
|
| 2065 | + * @var string $plural |
|
| 2066 | + * eg 'Dollars' |
|
| 2067 | + */ |
|
| 2068 | + public $plural; |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * currency sign |
|
| 2072 | + * |
|
| 2073 | + * @var string $sign |
|
| 2074 | + * eg '$' |
|
| 2075 | + */ |
|
| 2076 | + public $sign; |
|
| 2077 | + |
|
| 2078 | + /** |
|
| 2079 | + * Whether the currency sign should come before the number or not |
|
| 2080 | + * |
|
| 2081 | + * @var boolean $sign_b4 |
|
| 2082 | + */ |
|
| 2083 | + public $sign_b4; |
|
| 2084 | + |
|
| 2085 | + /** |
|
| 2086 | + * How many digits should come after the decimal place |
|
| 2087 | + * |
|
| 2088 | + * @var int $dec_plc |
|
| 2089 | + */ |
|
| 2090 | + public $dec_plc; |
|
| 2091 | + |
|
| 2092 | + /** |
|
| 2093 | + * Symbol to use for decimal mark |
|
| 2094 | + * |
|
| 2095 | + * @var string $dec_mrk |
|
| 2096 | + * eg '.' |
|
| 2097 | + */ |
|
| 2098 | + public $dec_mrk; |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * Symbol to use for thousands |
|
| 2102 | + * |
|
| 2103 | + * @var string $thsnds |
|
| 2104 | + * eg ',' |
|
| 2105 | + */ |
|
| 2106 | + public $thsnds; |
|
| 2107 | + |
|
| 2108 | + |
|
| 2109 | + /** |
|
| 2110 | + * class constructor |
|
| 2111 | + * |
|
| 2112 | + * @access public |
|
| 2113 | + * @param string $CNT_ISO |
|
| 2114 | + * @throws \EE_Error |
|
| 2115 | + */ |
|
| 2116 | + public function __construct($CNT_ISO = '') |
|
| 2117 | + { |
|
| 2118 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | + // get country code from organization settings or use default |
|
| 2121 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | + : ''; |
|
| 2125 | + // but override if requested |
|
| 2126 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | + if (! empty($CNT_ISO) |
|
| 2129 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | + ) { |
|
| 2132 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | + if ($country instanceof EE_Country) { |
|
| 2135 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | + $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | + $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | + $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | + } |
|
| 2147 | + } |
|
| 2148 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | + if (empty($this->code)) { |
|
| 2150 | + // set default currency settings |
|
| 2151 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | + $this->sign = '$'; // currency sign: $ |
|
| 2155 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | + } |
|
| 2160 | + } |
|
| 2161 | +} |
|
| 2321 | 2162 | |
| 2322 | - /** |
|
| 2323 | - * Label text to show on the checkbox |
|
| 2324 | - * |
|
| 2325 | - * @var string |
|
| 2326 | - */ |
|
| 2327 | - public $consent_checkbox_label_text; |
|
| 2163 | +/** |
|
| 2164 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | + */ |
|
| 2166 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | +{ |
|
| 2328 | 2168 | |
| 2329 | - /* |
|
| 2169 | + /** |
|
| 2170 | + * Default registration status |
|
| 2171 | + * |
|
| 2172 | + * @var string $default_STS_ID |
|
| 2173 | + * eg 'RPP' |
|
| 2174 | + */ |
|
| 2175 | + public $default_STS_ID; |
|
| 2176 | + |
|
| 2177 | + /** |
|
| 2178 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | + * registrations) |
|
| 2180 | + * |
|
| 2181 | + * @var int |
|
| 2182 | + */ |
|
| 2183 | + public $default_maximum_number_of_tickets; |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * level of validation to apply to email addresses |
|
| 2187 | + * |
|
| 2188 | + * @var string $email_validation_level |
|
| 2189 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | + */ |
|
| 2191 | + public $email_validation_level; |
|
| 2192 | + |
|
| 2193 | + /** |
|
| 2194 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | + * |
|
| 2196 | + * @var boolean $show_pending_payment_options |
|
| 2197 | + */ |
|
| 2198 | + public $show_pending_payment_options; |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * Whether to skip the registration confirmation page |
|
| 2202 | + * |
|
| 2203 | + * @var boolean $skip_reg_confirmation |
|
| 2204 | + */ |
|
| 2205 | + public $skip_reg_confirmation; |
|
| 2206 | + |
|
| 2207 | + /** |
|
| 2208 | + * an array of SPCO reg steps where: |
|
| 2209 | + * the keys denotes the reg step order |
|
| 2210 | + * each element consists of an array with the following elements: |
|
| 2211 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | + * "slug" => the URL param used to trigger the reg step |
|
| 2214 | + * |
|
| 2215 | + * @var array $reg_steps |
|
| 2216 | + */ |
|
| 2217 | + public $reg_steps; |
|
| 2218 | + |
|
| 2219 | + /** |
|
| 2220 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | + * |
|
| 2222 | + * @var boolean $reg_confirmation_last |
|
| 2223 | + */ |
|
| 2224 | + public $reg_confirmation_last; |
|
| 2225 | + |
|
| 2226 | + /** |
|
| 2227 | + * Whether or not to enable the EE Bot Trap |
|
| 2228 | + * |
|
| 2229 | + * @var boolean $use_bot_trap |
|
| 2230 | + */ |
|
| 2231 | + public $use_bot_trap; |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | + * |
|
| 2236 | + * @var boolean $use_encryption |
|
| 2237 | + */ |
|
| 2238 | + public $use_encryption; |
|
| 2239 | + |
|
| 2240 | + /** |
|
| 2241 | + * Whether or not to use ReCaptcha |
|
| 2242 | + * |
|
| 2243 | + * @var boolean $use_captcha |
|
| 2244 | + */ |
|
| 2245 | + public $use_captcha; |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * ReCaptcha Theme |
|
| 2249 | + * |
|
| 2250 | + * @var string $recaptcha_theme |
|
| 2251 | + * options: 'dark', 'light', 'invisible' |
|
| 2252 | + */ |
|
| 2253 | + public $recaptcha_theme; |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | + * |
|
| 2258 | + * @var string $recaptcha_badge |
|
| 2259 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | + */ |
|
| 2261 | + public $recaptcha_badge; |
|
| 2262 | + |
|
| 2263 | + /** |
|
| 2264 | + * ReCaptcha Type |
|
| 2265 | + * |
|
| 2266 | + * @var string $recaptcha_type |
|
| 2267 | + * options: 'audio', 'image' |
|
| 2268 | + */ |
|
| 2269 | + public $recaptcha_type; |
|
| 2270 | + |
|
| 2271 | + /** |
|
| 2272 | + * ReCaptcha language |
|
| 2273 | + * |
|
| 2274 | + * @var string $recaptcha_language |
|
| 2275 | + * eg 'en' |
|
| 2276 | + */ |
|
| 2277 | + public $recaptcha_language; |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * ReCaptcha public key |
|
| 2281 | + * |
|
| 2282 | + * @var string $recaptcha_publickey |
|
| 2283 | + */ |
|
| 2284 | + public $recaptcha_publickey; |
|
| 2285 | + |
|
| 2286 | + /** |
|
| 2287 | + * ReCaptcha private key |
|
| 2288 | + * |
|
| 2289 | + * @var string $recaptcha_privatekey |
|
| 2290 | + */ |
|
| 2291 | + public $recaptcha_privatekey; |
|
| 2292 | + |
|
| 2293 | + /** |
|
| 2294 | + * array of form names protected by ReCaptcha |
|
| 2295 | + * |
|
| 2296 | + * @var array $recaptcha_protected_forms |
|
| 2297 | + */ |
|
| 2298 | + public $recaptcha_protected_forms; |
|
| 2299 | + |
|
| 2300 | + /** |
|
| 2301 | + * ReCaptcha width |
|
| 2302 | + * |
|
| 2303 | + * @var int $recaptcha_width |
|
| 2304 | + * @deprecated |
|
| 2305 | + */ |
|
| 2306 | + public $recaptcha_width; |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | + * |
|
| 2311 | + * @var boolean $track_invalid_checkout_access |
|
| 2312 | + */ |
|
| 2313 | + protected $track_invalid_checkout_access = true; |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | + * |
|
| 2318 | + * @var bool |
|
| 2319 | + */ |
|
| 2320 | + public $consent_checkbox_enabled; |
|
| 2321 | + |
|
| 2322 | + /** |
|
| 2323 | + * Label text to show on the checkbox |
|
| 2324 | + * |
|
| 2325 | + * @var string |
|
| 2326 | + */ |
|
| 2327 | + public $consent_checkbox_label_text; |
|
| 2328 | + |
|
| 2329 | + /* |
|
| 2330 | 2330 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2331 | 2331 | * @var string |
| 2332 | 2332 | */ |
| 2333 | - public $gateway_log_lifespan = '1 week'; |
|
| 2334 | - |
|
| 2335 | - |
|
| 2336 | - /** |
|
| 2337 | - * class constructor |
|
| 2338 | - * |
|
| 2339 | - * @access public |
|
| 2340 | - */ |
|
| 2341 | - public function __construct() |
|
| 2342 | - { |
|
| 2343 | - // set default registration settings |
|
| 2344 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2345 | - $this->email_validation_level = 'wp_default'; |
|
| 2346 | - $this->show_pending_payment_options = true; |
|
| 2347 | - $this->skip_reg_confirmation = true; |
|
| 2348 | - $this->reg_steps = array(); |
|
| 2349 | - $this->reg_confirmation_last = false; |
|
| 2350 | - $this->use_bot_trap = true; |
|
| 2351 | - $this->use_encryption = true; |
|
| 2352 | - $this->use_captcha = false; |
|
| 2353 | - $this->recaptcha_theme = 'light'; |
|
| 2354 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2355 | - $this->recaptcha_type = 'image'; |
|
| 2356 | - $this->recaptcha_language = 'en'; |
|
| 2357 | - $this->recaptcha_publickey = null; |
|
| 2358 | - $this->recaptcha_privatekey = null; |
|
| 2359 | - $this->recaptcha_protected_forms = array(); |
|
| 2360 | - $this->recaptcha_width = 500; |
|
| 2361 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2362 | - $this->consent_checkbox_enabled = false; |
|
| 2363 | - $this->consent_checkbox_label_text = ''; |
|
| 2364 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2365 | - } |
|
| 2366 | - |
|
| 2367 | - |
|
| 2368 | - /** |
|
| 2369 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2370 | - * |
|
| 2371 | - * @since 4.8.8.rc.019 |
|
| 2372 | - */ |
|
| 2373 | - public function do_hooks() |
|
| 2374 | - { |
|
| 2375 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2376 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2377 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2378 | - } |
|
| 2379 | - |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2383 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2384 | - */ |
|
| 2385 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2386 | - { |
|
| 2387 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2388 | - } |
|
| 2389 | - |
|
| 2390 | - |
|
| 2391 | - /** |
|
| 2392 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2393 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2394 | - */ |
|
| 2395 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2396 | - { |
|
| 2397 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2398 | - } |
|
| 2399 | - |
|
| 2400 | - |
|
| 2401 | - /** |
|
| 2402 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2403 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2404 | - * |
|
| 2405 | - * @throws InvalidArgumentException |
|
| 2406 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2407 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2408 | - */ |
|
| 2409 | - public function setDefaultCheckboxLabelText() |
|
| 2410 | - { |
|
| 2411 | - if ($this->getConsentCheckboxLabelText() === null |
|
| 2412 | - || $this->getConsentCheckboxLabelText() === '') { |
|
| 2413 | - $opening_a_tag = ''; |
|
| 2414 | - $closing_a_tag = ''; |
|
| 2415 | - if (function_exists('get_privacy_policy_url')) { |
|
| 2416 | - $privacy_page_url = get_privacy_policy_url(); |
|
| 2417 | - if (! empty($privacy_page_url)) { |
|
| 2418 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2419 | - $closing_a_tag = '</a>'; |
|
| 2420 | - } |
|
| 2421 | - } |
|
| 2422 | - $loader = LoaderFactory::getLoader(); |
|
| 2423 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2424 | - /** |
|
| 2425 | - * @var $org_config EE_Organization_Config |
|
| 2426 | - */ |
|
| 2427 | - |
|
| 2428 | - $this->setConsentCheckboxLabelText( |
|
| 2429 | - sprintf( |
|
| 2430 | - esc_html__( |
|
| 2431 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2432 | - 'event_espresso' |
|
| 2433 | - ), |
|
| 2434 | - $org_config->name, |
|
| 2435 | - $opening_a_tag, |
|
| 2436 | - $closing_a_tag |
|
| 2437 | - ) |
|
| 2438 | - ); |
|
| 2439 | - } |
|
| 2440 | - } |
|
| 2441 | - |
|
| 2442 | - |
|
| 2443 | - /** |
|
| 2444 | - * @return boolean |
|
| 2445 | - */ |
|
| 2446 | - public function track_invalid_checkout_access() |
|
| 2447 | - { |
|
| 2448 | - return $this->track_invalid_checkout_access; |
|
| 2449 | - } |
|
| 2450 | - |
|
| 2451 | - |
|
| 2452 | - /** |
|
| 2453 | - * @param boolean $track_invalid_checkout_access |
|
| 2454 | - */ |
|
| 2455 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2456 | - { |
|
| 2457 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2458 | - $track_invalid_checkout_access, |
|
| 2459 | - FILTER_VALIDATE_BOOLEAN |
|
| 2460 | - ); |
|
| 2461 | - } |
|
| 2462 | - |
|
| 2463 | - |
|
| 2464 | - /** |
|
| 2465 | - * Gets the options to make availalbe for the gateway log lifespan |
|
| 2466 | - * @return array |
|
| 2467 | - */ |
|
| 2468 | - public function gatewayLogLifespanOptions() |
|
| 2469 | - { |
|
| 2470 | - return (array) apply_filters( |
|
| 2471 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2472 | - array( |
|
| 2473 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2474 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2475 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2476 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2477 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2478 | - ) |
|
| 2479 | - ); |
|
| 2480 | - } |
|
| 2481 | - |
|
| 2482 | - |
|
| 2483 | - /** |
|
| 2484 | - * @return bool |
|
| 2485 | - */ |
|
| 2486 | - public function isConsentCheckboxEnabled() |
|
| 2487 | - { |
|
| 2488 | - return $this->consent_checkbox_enabled; |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - /** |
|
| 2493 | - * @param bool $consent_checkbox_enabled |
|
| 2494 | - */ |
|
| 2495 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2496 | - { |
|
| 2497 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2498 | - $consent_checkbox_enabled, |
|
| 2499 | - FILTER_VALIDATE_BOOLEAN |
|
| 2500 | - ); |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - |
|
| 2504 | - /** |
|
| 2505 | - * @return string |
|
| 2506 | - */ |
|
| 2507 | - public function getConsentCheckboxLabelText() |
|
| 2508 | - { |
|
| 2509 | - return $this->consent_checkbox_label_text; |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - |
|
| 2513 | - /** |
|
| 2514 | - * @param string $consent_checkbox_label_text |
|
| 2515 | - */ |
|
| 2516 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2517 | - { |
|
| 2518 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2519 | - } |
|
| 2333 | + public $gateway_log_lifespan = '1 week'; |
|
| 2334 | + |
|
| 2335 | + |
|
| 2336 | + /** |
|
| 2337 | + * class constructor |
|
| 2338 | + * |
|
| 2339 | + * @access public |
|
| 2340 | + */ |
|
| 2341 | + public function __construct() |
|
| 2342 | + { |
|
| 2343 | + // set default registration settings |
|
| 2344 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2345 | + $this->email_validation_level = 'wp_default'; |
|
| 2346 | + $this->show_pending_payment_options = true; |
|
| 2347 | + $this->skip_reg_confirmation = true; |
|
| 2348 | + $this->reg_steps = array(); |
|
| 2349 | + $this->reg_confirmation_last = false; |
|
| 2350 | + $this->use_bot_trap = true; |
|
| 2351 | + $this->use_encryption = true; |
|
| 2352 | + $this->use_captcha = false; |
|
| 2353 | + $this->recaptcha_theme = 'light'; |
|
| 2354 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2355 | + $this->recaptcha_type = 'image'; |
|
| 2356 | + $this->recaptcha_language = 'en'; |
|
| 2357 | + $this->recaptcha_publickey = null; |
|
| 2358 | + $this->recaptcha_privatekey = null; |
|
| 2359 | + $this->recaptcha_protected_forms = array(); |
|
| 2360 | + $this->recaptcha_width = 500; |
|
| 2361 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2362 | + $this->consent_checkbox_enabled = false; |
|
| 2363 | + $this->consent_checkbox_label_text = ''; |
|
| 2364 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2365 | + } |
|
| 2366 | + |
|
| 2367 | + |
|
| 2368 | + /** |
|
| 2369 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2370 | + * |
|
| 2371 | + * @since 4.8.8.rc.019 |
|
| 2372 | + */ |
|
| 2373 | + public function do_hooks() |
|
| 2374 | + { |
|
| 2375 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2376 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2377 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2378 | + } |
|
| 2379 | + |
|
| 2380 | + |
|
| 2381 | + /** |
|
| 2382 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2383 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2384 | + */ |
|
| 2385 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2386 | + { |
|
| 2387 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2388 | + } |
|
| 2389 | + |
|
| 2390 | + |
|
| 2391 | + /** |
|
| 2392 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2393 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2394 | + */ |
|
| 2395 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2396 | + { |
|
| 2397 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2398 | + } |
|
| 2399 | + |
|
| 2400 | + |
|
| 2401 | + /** |
|
| 2402 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2403 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2404 | + * |
|
| 2405 | + * @throws InvalidArgumentException |
|
| 2406 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2407 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2408 | + */ |
|
| 2409 | + public function setDefaultCheckboxLabelText() |
|
| 2410 | + { |
|
| 2411 | + if ($this->getConsentCheckboxLabelText() === null |
|
| 2412 | + || $this->getConsentCheckboxLabelText() === '') { |
|
| 2413 | + $opening_a_tag = ''; |
|
| 2414 | + $closing_a_tag = ''; |
|
| 2415 | + if (function_exists('get_privacy_policy_url')) { |
|
| 2416 | + $privacy_page_url = get_privacy_policy_url(); |
|
| 2417 | + if (! empty($privacy_page_url)) { |
|
| 2418 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2419 | + $closing_a_tag = '</a>'; |
|
| 2420 | + } |
|
| 2421 | + } |
|
| 2422 | + $loader = LoaderFactory::getLoader(); |
|
| 2423 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2424 | + /** |
|
| 2425 | + * @var $org_config EE_Organization_Config |
|
| 2426 | + */ |
|
| 2427 | + |
|
| 2428 | + $this->setConsentCheckboxLabelText( |
|
| 2429 | + sprintf( |
|
| 2430 | + esc_html__( |
|
| 2431 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2432 | + 'event_espresso' |
|
| 2433 | + ), |
|
| 2434 | + $org_config->name, |
|
| 2435 | + $opening_a_tag, |
|
| 2436 | + $closing_a_tag |
|
| 2437 | + ) |
|
| 2438 | + ); |
|
| 2439 | + } |
|
| 2440 | + } |
|
| 2441 | + |
|
| 2442 | + |
|
| 2443 | + /** |
|
| 2444 | + * @return boolean |
|
| 2445 | + */ |
|
| 2446 | + public function track_invalid_checkout_access() |
|
| 2447 | + { |
|
| 2448 | + return $this->track_invalid_checkout_access; |
|
| 2449 | + } |
|
| 2450 | + |
|
| 2451 | + |
|
| 2452 | + /** |
|
| 2453 | + * @param boolean $track_invalid_checkout_access |
|
| 2454 | + */ |
|
| 2455 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2456 | + { |
|
| 2457 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2458 | + $track_invalid_checkout_access, |
|
| 2459 | + FILTER_VALIDATE_BOOLEAN |
|
| 2460 | + ); |
|
| 2461 | + } |
|
| 2462 | + |
|
| 2463 | + |
|
| 2464 | + /** |
|
| 2465 | + * Gets the options to make availalbe for the gateway log lifespan |
|
| 2466 | + * @return array |
|
| 2467 | + */ |
|
| 2468 | + public function gatewayLogLifespanOptions() |
|
| 2469 | + { |
|
| 2470 | + return (array) apply_filters( |
|
| 2471 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2472 | + array( |
|
| 2473 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2474 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2475 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2476 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2477 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2478 | + ) |
|
| 2479 | + ); |
|
| 2480 | + } |
|
| 2481 | + |
|
| 2482 | + |
|
| 2483 | + /** |
|
| 2484 | + * @return bool |
|
| 2485 | + */ |
|
| 2486 | + public function isConsentCheckboxEnabled() |
|
| 2487 | + { |
|
| 2488 | + return $this->consent_checkbox_enabled; |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + /** |
|
| 2493 | + * @param bool $consent_checkbox_enabled |
|
| 2494 | + */ |
|
| 2495 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2496 | + { |
|
| 2497 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2498 | + $consent_checkbox_enabled, |
|
| 2499 | + FILTER_VALIDATE_BOOLEAN |
|
| 2500 | + ); |
|
| 2501 | + } |
|
| 2502 | + |
|
| 2503 | + |
|
| 2504 | + /** |
|
| 2505 | + * @return string |
|
| 2506 | + */ |
|
| 2507 | + public function getConsentCheckboxLabelText() |
|
| 2508 | + { |
|
| 2509 | + return $this->consent_checkbox_label_text; |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + |
|
| 2513 | + /** |
|
| 2514 | + * @param string $consent_checkbox_label_text |
|
| 2515 | + */ |
|
| 2516 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2517 | + { |
|
| 2518 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2519 | + } |
|
| 2520 | 2520 | } |
| 2521 | 2521 | |
| 2522 | 2522 | /** |
@@ -2525,157 +2525,157 @@ discard block |
||
| 2525 | 2525 | class EE_Admin_Config extends EE_Config_Base |
| 2526 | 2526 | { |
| 2527 | 2527 | |
| 2528 | - /** |
|
| 2529 | - * @var boolean $use_personnel_manager |
|
| 2530 | - */ |
|
| 2531 | - public $use_personnel_manager; |
|
| 2532 | - |
|
| 2533 | - /** |
|
| 2534 | - * @var boolean $use_dashboard_widget |
|
| 2535 | - */ |
|
| 2536 | - public $use_dashboard_widget; |
|
| 2537 | - |
|
| 2538 | - /** |
|
| 2539 | - * @var int $events_in_dashboard |
|
| 2540 | - */ |
|
| 2541 | - public $events_in_dashboard; |
|
| 2542 | - |
|
| 2543 | - /** |
|
| 2544 | - * @var boolean $use_event_timezones |
|
| 2545 | - */ |
|
| 2546 | - public $use_event_timezones; |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * @var boolean $use_full_logging |
|
| 2550 | - */ |
|
| 2551 | - public $use_full_logging; |
|
| 2552 | - |
|
| 2553 | - /** |
|
| 2554 | - * @var string $log_file_name |
|
| 2555 | - */ |
|
| 2556 | - public $log_file_name; |
|
| 2557 | - |
|
| 2558 | - /** |
|
| 2559 | - * @var string $debug_file_name |
|
| 2560 | - */ |
|
| 2561 | - public $debug_file_name; |
|
| 2562 | - |
|
| 2563 | - /** |
|
| 2564 | - * @var boolean $use_remote_logging |
|
| 2565 | - */ |
|
| 2566 | - public $use_remote_logging; |
|
| 2567 | - |
|
| 2568 | - /** |
|
| 2569 | - * @var string $remote_logging_url |
|
| 2570 | - */ |
|
| 2571 | - public $remote_logging_url; |
|
| 2572 | - |
|
| 2573 | - /** |
|
| 2574 | - * @var boolean $show_reg_footer |
|
| 2575 | - */ |
|
| 2576 | - public $show_reg_footer; |
|
| 2577 | - |
|
| 2578 | - /** |
|
| 2579 | - * @var string $affiliate_id |
|
| 2580 | - */ |
|
| 2581 | - public $affiliate_id; |
|
| 2582 | - |
|
| 2583 | - /** |
|
| 2584 | - * help tours on or off (global setting) |
|
| 2585 | - * |
|
| 2586 | - * @var boolean |
|
| 2587 | - */ |
|
| 2588 | - public $help_tour_activation; |
|
| 2589 | - |
|
| 2590 | - /** |
|
| 2591 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2592 | - * but is incompatible with some server configuration errors |
|
| 2593 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2594 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2595 | - * |
|
| 2596 | - * @var boolean $encode_session_data |
|
| 2597 | - */ |
|
| 2598 | - private $encode_session_data = false; |
|
| 2599 | - |
|
| 2600 | - |
|
| 2601 | - /** |
|
| 2602 | - * class constructor |
|
| 2603 | - * |
|
| 2604 | - * @access public |
|
| 2605 | - */ |
|
| 2606 | - public function __construct() |
|
| 2607 | - { |
|
| 2608 | - // set default general admin settings |
|
| 2609 | - $this->use_personnel_manager = true; |
|
| 2610 | - $this->use_dashboard_widget = true; |
|
| 2611 | - $this->events_in_dashboard = 30; |
|
| 2612 | - $this->use_event_timezones = false; |
|
| 2613 | - $this->use_full_logging = false; |
|
| 2614 | - $this->use_remote_logging = false; |
|
| 2615 | - $this->remote_logging_url = null; |
|
| 2616 | - $this->show_reg_footer = apply_filters( |
|
| 2617 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2618 | - false |
|
| 2619 | - ); |
|
| 2620 | - $this->affiliate_id = 'default'; |
|
| 2621 | - $this->help_tour_activation = true; |
|
| 2622 | - $this->encode_session_data = false; |
|
| 2623 | - } |
|
| 2624 | - |
|
| 2625 | - |
|
| 2626 | - /** |
|
| 2627 | - * @param bool $reset |
|
| 2628 | - * @return string |
|
| 2629 | - */ |
|
| 2630 | - public function log_file_name($reset = false) |
|
| 2631 | - { |
|
| 2632 | - if (empty($this->log_file_name) || $reset) { |
|
| 2633 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2634 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2635 | - } |
|
| 2636 | - return $this->log_file_name; |
|
| 2637 | - } |
|
| 2638 | - |
|
| 2639 | - |
|
| 2640 | - /** |
|
| 2641 | - * @param bool $reset |
|
| 2642 | - * @return string |
|
| 2643 | - */ |
|
| 2644 | - public function debug_file_name($reset = false) |
|
| 2645 | - { |
|
| 2646 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2647 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2648 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2649 | - } |
|
| 2650 | - return $this->debug_file_name; |
|
| 2651 | - } |
|
| 2652 | - |
|
| 2653 | - |
|
| 2654 | - /** |
|
| 2655 | - * @return string |
|
| 2656 | - */ |
|
| 2657 | - public function affiliate_id() |
|
| 2658 | - { |
|
| 2659 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2660 | - } |
|
| 2661 | - |
|
| 2662 | - |
|
| 2663 | - /** |
|
| 2664 | - * @return boolean |
|
| 2665 | - */ |
|
| 2666 | - public function encode_session_data() |
|
| 2667 | - { |
|
| 2668 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2669 | - } |
|
| 2670 | - |
|
| 2671 | - |
|
| 2672 | - /** |
|
| 2673 | - * @param boolean $encode_session_data |
|
| 2674 | - */ |
|
| 2675 | - public function set_encode_session_data($encode_session_data) |
|
| 2676 | - { |
|
| 2677 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2678 | - } |
|
| 2528 | + /** |
|
| 2529 | + * @var boolean $use_personnel_manager |
|
| 2530 | + */ |
|
| 2531 | + public $use_personnel_manager; |
|
| 2532 | + |
|
| 2533 | + /** |
|
| 2534 | + * @var boolean $use_dashboard_widget |
|
| 2535 | + */ |
|
| 2536 | + public $use_dashboard_widget; |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * @var int $events_in_dashboard |
|
| 2540 | + */ |
|
| 2541 | + public $events_in_dashboard; |
|
| 2542 | + |
|
| 2543 | + /** |
|
| 2544 | + * @var boolean $use_event_timezones |
|
| 2545 | + */ |
|
| 2546 | + public $use_event_timezones; |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * @var boolean $use_full_logging |
|
| 2550 | + */ |
|
| 2551 | + public $use_full_logging; |
|
| 2552 | + |
|
| 2553 | + /** |
|
| 2554 | + * @var string $log_file_name |
|
| 2555 | + */ |
|
| 2556 | + public $log_file_name; |
|
| 2557 | + |
|
| 2558 | + /** |
|
| 2559 | + * @var string $debug_file_name |
|
| 2560 | + */ |
|
| 2561 | + public $debug_file_name; |
|
| 2562 | + |
|
| 2563 | + /** |
|
| 2564 | + * @var boolean $use_remote_logging |
|
| 2565 | + */ |
|
| 2566 | + public $use_remote_logging; |
|
| 2567 | + |
|
| 2568 | + /** |
|
| 2569 | + * @var string $remote_logging_url |
|
| 2570 | + */ |
|
| 2571 | + public $remote_logging_url; |
|
| 2572 | + |
|
| 2573 | + /** |
|
| 2574 | + * @var boolean $show_reg_footer |
|
| 2575 | + */ |
|
| 2576 | + public $show_reg_footer; |
|
| 2577 | + |
|
| 2578 | + /** |
|
| 2579 | + * @var string $affiliate_id |
|
| 2580 | + */ |
|
| 2581 | + public $affiliate_id; |
|
| 2582 | + |
|
| 2583 | + /** |
|
| 2584 | + * help tours on or off (global setting) |
|
| 2585 | + * |
|
| 2586 | + * @var boolean |
|
| 2587 | + */ |
|
| 2588 | + public $help_tour_activation; |
|
| 2589 | + |
|
| 2590 | + /** |
|
| 2591 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2592 | + * but is incompatible with some server configuration errors |
|
| 2593 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2594 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2595 | + * |
|
| 2596 | + * @var boolean $encode_session_data |
|
| 2597 | + */ |
|
| 2598 | + private $encode_session_data = false; |
|
| 2599 | + |
|
| 2600 | + |
|
| 2601 | + /** |
|
| 2602 | + * class constructor |
|
| 2603 | + * |
|
| 2604 | + * @access public |
|
| 2605 | + */ |
|
| 2606 | + public function __construct() |
|
| 2607 | + { |
|
| 2608 | + // set default general admin settings |
|
| 2609 | + $this->use_personnel_manager = true; |
|
| 2610 | + $this->use_dashboard_widget = true; |
|
| 2611 | + $this->events_in_dashboard = 30; |
|
| 2612 | + $this->use_event_timezones = false; |
|
| 2613 | + $this->use_full_logging = false; |
|
| 2614 | + $this->use_remote_logging = false; |
|
| 2615 | + $this->remote_logging_url = null; |
|
| 2616 | + $this->show_reg_footer = apply_filters( |
|
| 2617 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2618 | + false |
|
| 2619 | + ); |
|
| 2620 | + $this->affiliate_id = 'default'; |
|
| 2621 | + $this->help_tour_activation = true; |
|
| 2622 | + $this->encode_session_data = false; |
|
| 2623 | + } |
|
| 2624 | + |
|
| 2625 | + |
|
| 2626 | + /** |
|
| 2627 | + * @param bool $reset |
|
| 2628 | + * @return string |
|
| 2629 | + */ |
|
| 2630 | + public function log_file_name($reset = false) |
|
| 2631 | + { |
|
| 2632 | + if (empty($this->log_file_name) || $reset) { |
|
| 2633 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2634 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2635 | + } |
|
| 2636 | + return $this->log_file_name; |
|
| 2637 | + } |
|
| 2638 | + |
|
| 2639 | + |
|
| 2640 | + /** |
|
| 2641 | + * @param bool $reset |
|
| 2642 | + * @return string |
|
| 2643 | + */ |
|
| 2644 | + public function debug_file_name($reset = false) |
|
| 2645 | + { |
|
| 2646 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2647 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2648 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2649 | + } |
|
| 2650 | + return $this->debug_file_name; |
|
| 2651 | + } |
|
| 2652 | + |
|
| 2653 | + |
|
| 2654 | + /** |
|
| 2655 | + * @return string |
|
| 2656 | + */ |
|
| 2657 | + public function affiliate_id() |
|
| 2658 | + { |
|
| 2659 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2660 | + } |
|
| 2661 | + |
|
| 2662 | + |
|
| 2663 | + /** |
|
| 2664 | + * @return boolean |
|
| 2665 | + */ |
|
| 2666 | + public function encode_session_data() |
|
| 2667 | + { |
|
| 2668 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2669 | + } |
|
| 2670 | + |
|
| 2671 | + |
|
| 2672 | + /** |
|
| 2673 | + * @param boolean $encode_session_data |
|
| 2674 | + */ |
|
| 2675 | + public function set_encode_session_data($encode_session_data) |
|
| 2676 | + { |
|
| 2677 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2678 | + } |
|
| 2679 | 2679 | } |
| 2680 | 2680 | |
| 2681 | 2681 | /** |
@@ -2684,70 +2684,70 @@ discard block |
||
| 2684 | 2684 | class EE_Template_Config extends EE_Config_Base |
| 2685 | 2685 | { |
| 2686 | 2686 | |
| 2687 | - /** |
|
| 2688 | - * @var boolean $enable_default_style |
|
| 2689 | - */ |
|
| 2690 | - public $enable_default_style; |
|
| 2691 | - |
|
| 2692 | - /** |
|
| 2693 | - * @var string $custom_style_sheet |
|
| 2694 | - */ |
|
| 2695 | - public $custom_style_sheet; |
|
| 2696 | - |
|
| 2697 | - /** |
|
| 2698 | - * @var boolean $display_address_in_regform |
|
| 2699 | - */ |
|
| 2700 | - public $display_address_in_regform; |
|
| 2701 | - |
|
| 2702 | - /** |
|
| 2703 | - * @var int $display_description_on_multi_reg_page |
|
| 2704 | - */ |
|
| 2705 | - public $display_description_on_multi_reg_page; |
|
| 2706 | - |
|
| 2707 | - /** |
|
| 2708 | - * @var boolean $use_custom_templates |
|
| 2709 | - */ |
|
| 2710 | - public $use_custom_templates; |
|
| 2711 | - |
|
| 2712 | - /** |
|
| 2713 | - * @var string $current_espresso_theme |
|
| 2714 | - */ |
|
| 2715 | - public $current_espresso_theme; |
|
| 2716 | - |
|
| 2717 | - /** |
|
| 2718 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2719 | - */ |
|
| 2720 | - public $EED_Ticket_Selector; |
|
| 2721 | - |
|
| 2722 | - /** |
|
| 2723 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2724 | - */ |
|
| 2725 | - public $EED_Event_Single; |
|
| 2726 | - |
|
| 2727 | - /** |
|
| 2728 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2729 | - */ |
|
| 2730 | - public $EED_Events_Archive; |
|
| 2731 | - |
|
| 2732 | - |
|
| 2733 | - /** |
|
| 2734 | - * class constructor |
|
| 2735 | - * |
|
| 2736 | - * @access public |
|
| 2737 | - */ |
|
| 2738 | - public function __construct() |
|
| 2739 | - { |
|
| 2740 | - // set default template settings |
|
| 2741 | - $this->enable_default_style = true; |
|
| 2742 | - $this->custom_style_sheet = null; |
|
| 2743 | - $this->display_address_in_regform = true; |
|
| 2744 | - $this->display_description_on_multi_reg_page = false; |
|
| 2745 | - $this->use_custom_templates = false; |
|
| 2746 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2747 | - $this->EED_Event_Single = null; |
|
| 2748 | - $this->EED_Events_Archive = null; |
|
| 2749 | - $this->EED_Ticket_Selector = null; |
|
| 2750 | - } |
|
| 2687 | + /** |
|
| 2688 | + * @var boolean $enable_default_style |
|
| 2689 | + */ |
|
| 2690 | + public $enable_default_style; |
|
| 2691 | + |
|
| 2692 | + /** |
|
| 2693 | + * @var string $custom_style_sheet |
|
| 2694 | + */ |
|
| 2695 | + public $custom_style_sheet; |
|
| 2696 | + |
|
| 2697 | + /** |
|
| 2698 | + * @var boolean $display_address_in_regform |
|
| 2699 | + */ |
|
| 2700 | + public $display_address_in_regform; |
|
| 2701 | + |
|
| 2702 | + /** |
|
| 2703 | + * @var int $display_description_on_multi_reg_page |
|
| 2704 | + */ |
|
| 2705 | + public $display_description_on_multi_reg_page; |
|
| 2706 | + |
|
| 2707 | + /** |
|
| 2708 | + * @var boolean $use_custom_templates |
|
| 2709 | + */ |
|
| 2710 | + public $use_custom_templates; |
|
| 2711 | + |
|
| 2712 | + /** |
|
| 2713 | + * @var string $current_espresso_theme |
|
| 2714 | + */ |
|
| 2715 | + public $current_espresso_theme; |
|
| 2716 | + |
|
| 2717 | + /** |
|
| 2718 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2719 | + */ |
|
| 2720 | + public $EED_Ticket_Selector; |
|
| 2721 | + |
|
| 2722 | + /** |
|
| 2723 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2724 | + */ |
|
| 2725 | + public $EED_Event_Single; |
|
| 2726 | + |
|
| 2727 | + /** |
|
| 2728 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2729 | + */ |
|
| 2730 | + public $EED_Events_Archive; |
|
| 2731 | + |
|
| 2732 | + |
|
| 2733 | + /** |
|
| 2734 | + * class constructor |
|
| 2735 | + * |
|
| 2736 | + * @access public |
|
| 2737 | + */ |
|
| 2738 | + public function __construct() |
|
| 2739 | + { |
|
| 2740 | + // set default template settings |
|
| 2741 | + $this->enable_default_style = true; |
|
| 2742 | + $this->custom_style_sheet = null; |
|
| 2743 | + $this->display_address_in_regform = true; |
|
| 2744 | + $this->display_description_on_multi_reg_page = false; |
|
| 2745 | + $this->use_custom_templates = false; |
|
| 2746 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2747 | + $this->EED_Event_Single = null; |
|
| 2748 | + $this->EED_Events_Archive = null; |
|
| 2749 | + $this->EED_Ticket_Selector = null; |
|
| 2750 | + } |
|
| 2751 | 2751 | } |
| 2752 | 2752 | |
| 2753 | 2753 | /** |
@@ -2756,114 +2756,114 @@ discard block |
||
| 2756 | 2756 | class EE_Map_Config extends EE_Config_Base |
| 2757 | 2757 | { |
| 2758 | 2758 | |
| 2759 | - /** |
|
| 2760 | - * @var boolean $use_google_maps |
|
| 2761 | - */ |
|
| 2762 | - public $use_google_maps; |
|
| 2763 | - |
|
| 2764 | - /** |
|
| 2765 | - * @var string $api_key |
|
| 2766 | - */ |
|
| 2767 | - public $google_map_api_key; |
|
| 2768 | - |
|
| 2769 | - /** |
|
| 2770 | - * @var int $event_details_map_width |
|
| 2771 | - */ |
|
| 2772 | - public $event_details_map_width; |
|
| 2773 | - |
|
| 2774 | - /** |
|
| 2775 | - * @var int $event_details_map_height |
|
| 2776 | - */ |
|
| 2777 | - public $event_details_map_height; |
|
| 2778 | - |
|
| 2779 | - /** |
|
| 2780 | - * @var int $event_details_map_zoom |
|
| 2781 | - */ |
|
| 2782 | - public $event_details_map_zoom; |
|
| 2783 | - |
|
| 2784 | - /** |
|
| 2785 | - * @var boolean $event_details_display_nav |
|
| 2786 | - */ |
|
| 2787 | - public $event_details_display_nav; |
|
| 2788 | - |
|
| 2789 | - /** |
|
| 2790 | - * @var boolean $event_details_nav_size |
|
| 2791 | - */ |
|
| 2792 | - public $event_details_nav_size; |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * @var string $event_details_control_type |
|
| 2796 | - */ |
|
| 2797 | - public $event_details_control_type; |
|
| 2798 | - |
|
| 2799 | - /** |
|
| 2800 | - * @var string $event_details_map_align |
|
| 2801 | - */ |
|
| 2802 | - public $event_details_map_align; |
|
| 2803 | - |
|
| 2804 | - /** |
|
| 2805 | - * @var int $event_list_map_width |
|
| 2806 | - */ |
|
| 2807 | - public $event_list_map_width; |
|
| 2808 | - |
|
| 2809 | - /** |
|
| 2810 | - * @var int $event_list_map_height |
|
| 2811 | - */ |
|
| 2812 | - public $event_list_map_height; |
|
| 2813 | - |
|
| 2814 | - /** |
|
| 2815 | - * @var int $event_list_map_zoom |
|
| 2816 | - */ |
|
| 2817 | - public $event_list_map_zoom; |
|
| 2818 | - |
|
| 2819 | - /** |
|
| 2820 | - * @var boolean $event_list_display_nav |
|
| 2821 | - */ |
|
| 2822 | - public $event_list_display_nav; |
|
| 2823 | - |
|
| 2824 | - /** |
|
| 2825 | - * @var boolean $event_list_nav_size |
|
| 2826 | - */ |
|
| 2827 | - public $event_list_nav_size; |
|
| 2828 | - |
|
| 2829 | - /** |
|
| 2830 | - * @var string $event_list_control_type |
|
| 2831 | - */ |
|
| 2832 | - public $event_list_control_type; |
|
| 2833 | - |
|
| 2834 | - /** |
|
| 2835 | - * @var string $event_list_map_align |
|
| 2836 | - */ |
|
| 2837 | - public $event_list_map_align; |
|
| 2838 | - |
|
| 2839 | - |
|
| 2840 | - /** |
|
| 2841 | - * class constructor |
|
| 2842 | - * |
|
| 2843 | - * @access public |
|
| 2844 | - */ |
|
| 2845 | - public function __construct() |
|
| 2846 | - { |
|
| 2847 | - // set default map settings |
|
| 2848 | - $this->use_google_maps = true; |
|
| 2849 | - $this->google_map_api_key = ''; |
|
| 2850 | - // for event details pages (reg page) |
|
| 2851 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2858 | - // for event list pages |
|
| 2859 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2866 | - } |
|
| 2759 | + /** |
|
| 2760 | + * @var boolean $use_google_maps |
|
| 2761 | + */ |
|
| 2762 | + public $use_google_maps; |
|
| 2763 | + |
|
| 2764 | + /** |
|
| 2765 | + * @var string $api_key |
|
| 2766 | + */ |
|
| 2767 | + public $google_map_api_key; |
|
| 2768 | + |
|
| 2769 | + /** |
|
| 2770 | + * @var int $event_details_map_width |
|
| 2771 | + */ |
|
| 2772 | + public $event_details_map_width; |
|
| 2773 | + |
|
| 2774 | + /** |
|
| 2775 | + * @var int $event_details_map_height |
|
| 2776 | + */ |
|
| 2777 | + public $event_details_map_height; |
|
| 2778 | + |
|
| 2779 | + /** |
|
| 2780 | + * @var int $event_details_map_zoom |
|
| 2781 | + */ |
|
| 2782 | + public $event_details_map_zoom; |
|
| 2783 | + |
|
| 2784 | + /** |
|
| 2785 | + * @var boolean $event_details_display_nav |
|
| 2786 | + */ |
|
| 2787 | + public $event_details_display_nav; |
|
| 2788 | + |
|
| 2789 | + /** |
|
| 2790 | + * @var boolean $event_details_nav_size |
|
| 2791 | + */ |
|
| 2792 | + public $event_details_nav_size; |
|
| 2793 | + |
|
| 2794 | + /** |
|
| 2795 | + * @var string $event_details_control_type |
|
| 2796 | + */ |
|
| 2797 | + public $event_details_control_type; |
|
| 2798 | + |
|
| 2799 | + /** |
|
| 2800 | + * @var string $event_details_map_align |
|
| 2801 | + */ |
|
| 2802 | + public $event_details_map_align; |
|
| 2803 | + |
|
| 2804 | + /** |
|
| 2805 | + * @var int $event_list_map_width |
|
| 2806 | + */ |
|
| 2807 | + public $event_list_map_width; |
|
| 2808 | + |
|
| 2809 | + /** |
|
| 2810 | + * @var int $event_list_map_height |
|
| 2811 | + */ |
|
| 2812 | + public $event_list_map_height; |
|
| 2813 | + |
|
| 2814 | + /** |
|
| 2815 | + * @var int $event_list_map_zoom |
|
| 2816 | + */ |
|
| 2817 | + public $event_list_map_zoom; |
|
| 2818 | + |
|
| 2819 | + /** |
|
| 2820 | + * @var boolean $event_list_display_nav |
|
| 2821 | + */ |
|
| 2822 | + public $event_list_display_nav; |
|
| 2823 | + |
|
| 2824 | + /** |
|
| 2825 | + * @var boolean $event_list_nav_size |
|
| 2826 | + */ |
|
| 2827 | + public $event_list_nav_size; |
|
| 2828 | + |
|
| 2829 | + /** |
|
| 2830 | + * @var string $event_list_control_type |
|
| 2831 | + */ |
|
| 2832 | + public $event_list_control_type; |
|
| 2833 | + |
|
| 2834 | + /** |
|
| 2835 | + * @var string $event_list_map_align |
|
| 2836 | + */ |
|
| 2837 | + public $event_list_map_align; |
|
| 2838 | + |
|
| 2839 | + |
|
| 2840 | + /** |
|
| 2841 | + * class constructor |
|
| 2842 | + * |
|
| 2843 | + * @access public |
|
| 2844 | + */ |
|
| 2845 | + public function __construct() |
|
| 2846 | + { |
|
| 2847 | + // set default map settings |
|
| 2848 | + $this->use_google_maps = true; |
|
| 2849 | + $this->google_map_api_key = ''; |
|
| 2850 | + // for event details pages (reg page) |
|
| 2851 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2858 | + // for event list pages |
|
| 2859 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2866 | + } |
|
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | 2869 | /** |
@@ -2872,46 +2872,46 @@ discard block |
||
| 2872 | 2872 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2873 | 2873 | { |
| 2874 | 2874 | |
| 2875 | - public $display_status_banner; |
|
| 2875 | + public $display_status_banner; |
|
| 2876 | 2876 | |
| 2877 | - public $display_description; |
|
| 2877 | + public $display_description; |
|
| 2878 | 2878 | |
| 2879 | - public $display_ticket_selector; |
|
| 2879 | + public $display_ticket_selector; |
|
| 2880 | 2880 | |
| 2881 | - public $display_datetimes; |
|
| 2881 | + public $display_datetimes; |
|
| 2882 | 2882 | |
| 2883 | - public $display_venue; |
|
| 2883 | + public $display_venue; |
|
| 2884 | 2884 | |
| 2885 | - public $display_expired_events; |
|
| 2885 | + public $display_expired_events; |
|
| 2886 | 2886 | |
| 2887 | - public $use_sortable_display_order; |
|
| 2887 | + public $use_sortable_display_order; |
|
| 2888 | 2888 | |
| 2889 | - public $display_order_tickets; |
|
| 2889 | + public $display_order_tickets; |
|
| 2890 | 2890 | |
| 2891 | - public $display_order_datetimes; |
|
| 2891 | + public $display_order_datetimes; |
|
| 2892 | 2892 | |
| 2893 | - public $display_order_event; |
|
| 2893 | + public $display_order_event; |
|
| 2894 | 2894 | |
| 2895 | - public $display_order_venue; |
|
| 2895 | + public $display_order_venue; |
|
| 2896 | 2896 | |
| 2897 | 2897 | |
| 2898 | - /** |
|
| 2899 | - * class constructor |
|
| 2900 | - */ |
|
| 2901 | - public function __construct() |
|
| 2902 | - { |
|
| 2903 | - $this->display_status_banner = 0; |
|
| 2904 | - $this->display_description = 1; |
|
| 2905 | - $this->display_ticket_selector = 0; |
|
| 2906 | - $this->display_datetimes = 1; |
|
| 2907 | - $this->display_venue = 0; |
|
| 2908 | - $this->display_expired_events = 0; |
|
| 2909 | - $this->use_sortable_display_order = false; |
|
| 2910 | - $this->display_order_tickets = 100; |
|
| 2911 | - $this->display_order_datetimes = 110; |
|
| 2912 | - $this->display_order_event = 120; |
|
| 2913 | - $this->display_order_venue = 130; |
|
| 2914 | - } |
|
| 2898 | + /** |
|
| 2899 | + * class constructor |
|
| 2900 | + */ |
|
| 2901 | + public function __construct() |
|
| 2902 | + { |
|
| 2903 | + $this->display_status_banner = 0; |
|
| 2904 | + $this->display_description = 1; |
|
| 2905 | + $this->display_ticket_selector = 0; |
|
| 2906 | + $this->display_datetimes = 1; |
|
| 2907 | + $this->display_venue = 0; |
|
| 2908 | + $this->display_expired_events = 0; |
|
| 2909 | + $this->use_sortable_display_order = false; |
|
| 2910 | + $this->display_order_tickets = 100; |
|
| 2911 | + $this->display_order_datetimes = 110; |
|
| 2912 | + $this->display_order_event = 120; |
|
| 2913 | + $this->display_order_venue = 130; |
|
| 2914 | + } |
|
| 2915 | 2915 | } |
| 2916 | 2916 | |
| 2917 | 2917 | /** |
@@ -2920,34 +2920,34 @@ discard block |
||
| 2920 | 2920 | class EE_Event_Single_Config extends EE_Config_Base |
| 2921 | 2921 | { |
| 2922 | 2922 | |
| 2923 | - public $display_status_banner_single; |
|
| 2923 | + public $display_status_banner_single; |
|
| 2924 | 2924 | |
| 2925 | - public $display_venue; |
|
| 2925 | + public $display_venue; |
|
| 2926 | 2926 | |
| 2927 | - public $use_sortable_display_order; |
|
| 2927 | + public $use_sortable_display_order; |
|
| 2928 | 2928 | |
| 2929 | - public $display_order_tickets; |
|
| 2929 | + public $display_order_tickets; |
|
| 2930 | 2930 | |
| 2931 | - public $display_order_datetimes; |
|
| 2931 | + public $display_order_datetimes; |
|
| 2932 | 2932 | |
| 2933 | - public $display_order_event; |
|
| 2933 | + public $display_order_event; |
|
| 2934 | 2934 | |
| 2935 | - public $display_order_venue; |
|
| 2935 | + public $display_order_venue; |
|
| 2936 | 2936 | |
| 2937 | 2937 | |
| 2938 | - /** |
|
| 2939 | - * class constructor |
|
| 2940 | - */ |
|
| 2941 | - public function __construct() |
|
| 2942 | - { |
|
| 2943 | - $this->display_status_banner_single = 0; |
|
| 2944 | - $this->display_venue = 1; |
|
| 2945 | - $this->use_sortable_display_order = false; |
|
| 2946 | - $this->display_order_tickets = 100; |
|
| 2947 | - $this->display_order_datetimes = 110; |
|
| 2948 | - $this->display_order_event = 120; |
|
| 2949 | - $this->display_order_venue = 130; |
|
| 2950 | - } |
|
| 2938 | + /** |
|
| 2939 | + * class constructor |
|
| 2940 | + */ |
|
| 2941 | + public function __construct() |
|
| 2942 | + { |
|
| 2943 | + $this->display_status_banner_single = 0; |
|
| 2944 | + $this->display_venue = 1; |
|
| 2945 | + $this->use_sortable_display_order = false; |
|
| 2946 | + $this->display_order_tickets = 100; |
|
| 2947 | + $this->display_order_datetimes = 110; |
|
| 2948 | + $this->display_order_event = 120; |
|
| 2949 | + $this->display_order_venue = 130; |
|
| 2950 | + } |
|
| 2951 | 2951 | } |
| 2952 | 2952 | |
| 2953 | 2953 | /** |
@@ -2956,172 +2956,172 @@ discard block |
||
| 2956 | 2956 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2957 | 2957 | { |
| 2958 | 2958 | |
| 2959 | - /** |
|
| 2960 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2961 | - */ |
|
| 2962 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2963 | - |
|
| 2964 | - /** |
|
| 2965 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2966 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2967 | - */ |
|
| 2968 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2969 | - |
|
| 2970 | - /** |
|
| 2971 | - * @var boolean $show_ticket_sale_columns |
|
| 2972 | - */ |
|
| 2973 | - public $show_ticket_sale_columns; |
|
| 2974 | - |
|
| 2975 | - /** |
|
| 2976 | - * @var boolean $show_ticket_details |
|
| 2977 | - */ |
|
| 2978 | - public $show_ticket_details; |
|
| 2979 | - |
|
| 2980 | - /** |
|
| 2981 | - * @var boolean $show_expired_tickets |
|
| 2982 | - */ |
|
| 2983 | - public $show_expired_tickets; |
|
| 2984 | - |
|
| 2985 | - /** |
|
| 2986 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2987 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 2988 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2989 | - * |
|
| 2990 | - * @var string $show_datetime_selector |
|
| 2991 | - */ |
|
| 2992 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2993 | - |
|
| 2994 | - /** |
|
| 2995 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2996 | - * |
|
| 2997 | - * @var int $datetime_selector_threshold |
|
| 2998 | - */ |
|
| 2999 | - private $datetime_selector_threshold = 3; |
|
| 3000 | - |
|
| 3001 | - /** |
|
| 3002 | - * determines the maximum number of "checked" dates in the date and time filter |
|
| 3003 | - * |
|
| 3004 | - * @var int $datetime_selector_checked |
|
| 3005 | - */ |
|
| 3006 | - private $datetime_selector_max_checked = 10; |
|
| 3007 | - |
|
| 3008 | - |
|
| 3009 | - /** |
|
| 3010 | - * class constructor |
|
| 3011 | - */ |
|
| 3012 | - public function __construct() |
|
| 3013 | - { |
|
| 3014 | - $this->show_ticket_sale_columns = true; |
|
| 3015 | - $this->show_ticket_details = true; |
|
| 3016 | - $this->show_expired_tickets = true; |
|
| 3017 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3018 | - $this->datetime_selector_threshold = 3; |
|
| 3019 | - $this->datetime_selector_max_checked = 10; |
|
| 3020 | - } |
|
| 3021 | - |
|
| 3022 | - |
|
| 3023 | - /** |
|
| 3024 | - * returns true if a datetime selector should be displayed |
|
| 3025 | - * |
|
| 3026 | - * @param array $datetimes |
|
| 3027 | - * @return bool |
|
| 3028 | - */ |
|
| 3029 | - public function showDatetimeSelector(array $datetimes) |
|
| 3030 | - { |
|
| 3031 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3032 | - return ! ( |
|
| 3033 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3034 | - || ( |
|
| 3035 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3036 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3037 | - ) |
|
| 3038 | - ); |
|
| 3039 | - } |
|
| 3040 | - |
|
| 3041 | - |
|
| 3042 | - /** |
|
| 3043 | - * @return string |
|
| 3044 | - */ |
|
| 3045 | - public function getShowDatetimeSelector() |
|
| 3046 | - { |
|
| 3047 | - return $this->show_datetime_selector; |
|
| 3048 | - } |
|
| 3049 | - |
|
| 3050 | - |
|
| 3051 | - /** |
|
| 3052 | - * @param bool $keys_only |
|
| 3053 | - * @return array |
|
| 3054 | - */ |
|
| 3055 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3056 | - { |
|
| 3057 | - return $keys_only |
|
| 3058 | - ? array( |
|
| 3059 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3060 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3061 | - ) |
|
| 3062 | - : array( |
|
| 3063 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3064 | - 'Do not show date & time filter', |
|
| 3065 | - 'event_espresso' |
|
| 3066 | - ), |
|
| 3067 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3068 | - 'Maybe show date & time filter', |
|
| 3069 | - 'event_espresso' |
|
| 3070 | - ), |
|
| 3071 | - ); |
|
| 3072 | - } |
|
| 3073 | - |
|
| 3074 | - |
|
| 3075 | - /** |
|
| 3076 | - * @param string $show_datetime_selector |
|
| 3077 | - */ |
|
| 3078 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3079 | - { |
|
| 3080 | - $this->show_datetime_selector = in_array( |
|
| 3081 | - $show_datetime_selector, |
|
| 3082 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3083 | - true |
|
| 3084 | - ) |
|
| 3085 | - ? $show_datetime_selector |
|
| 3086 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3087 | - } |
|
| 3088 | - |
|
| 3089 | - |
|
| 3090 | - /** |
|
| 3091 | - * @return int |
|
| 3092 | - */ |
|
| 3093 | - public function getDatetimeSelectorThreshold() |
|
| 3094 | - { |
|
| 3095 | - return $this->datetime_selector_threshold; |
|
| 3096 | - } |
|
| 3097 | - |
|
| 3098 | - |
|
| 3099 | - /** |
|
| 3100 | - * @param int $datetime_selector_threshold |
|
| 3101 | - */ |
|
| 3102 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3103 | - { |
|
| 3104 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3105 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3106 | - } |
|
| 3107 | - |
|
| 3108 | - |
|
| 3109 | - /** |
|
| 3110 | - * @return int |
|
| 3111 | - */ |
|
| 3112 | - public function getDatetimeSelectorMaxChecked() |
|
| 3113 | - { |
|
| 3114 | - return $this->datetime_selector_max_checked; |
|
| 3115 | - } |
|
| 3116 | - |
|
| 3117 | - |
|
| 3118 | - /** |
|
| 3119 | - * @param int $datetime_selector_max_checked |
|
| 3120 | - */ |
|
| 3121 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3122 | - { |
|
| 3123 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3124 | - } |
|
| 2959 | + /** |
|
| 2960 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2961 | + */ |
|
| 2962 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2963 | + |
|
| 2964 | + /** |
|
| 2965 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2966 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2967 | + */ |
|
| 2968 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2969 | + |
|
| 2970 | + /** |
|
| 2971 | + * @var boolean $show_ticket_sale_columns |
|
| 2972 | + */ |
|
| 2973 | + public $show_ticket_sale_columns; |
|
| 2974 | + |
|
| 2975 | + /** |
|
| 2976 | + * @var boolean $show_ticket_details |
|
| 2977 | + */ |
|
| 2978 | + public $show_ticket_details; |
|
| 2979 | + |
|
| 2980 | + /** |
|
| 2981 | + * @var boolean $show_expired_tickets |
|
| 2982 | + */ |
|
| 2983 | + public $show_expired_tickets; |
|
| 2984 | + |
|
| 2985 | + /** |
|
| 2986 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2987 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 2988 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2989 | + * |
|
| 2990 | + * @var string $show_datetime_selector |
|
| 2991 | + */ |
|
| 2992 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2993 | + |
|
| 2994 | + /** |
|
| 2995 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2996 | + * |
|
| 2997 | + * @var int $datetime_selector_threshold |
|
| 2998 | + */ |
|
| 2999 | + private $datetime_selector_threshold = 3; |
|
| 3000 | + |
|
| 3001 | + /** |
|
| 3002 | + * determines the maximum number of "checked" dates in the date and time filter |
|
| 3003 | + * |
|
| 3004 | + * @var int $datetime_selector_checked |
|
| 3005 | + */ |
|
| 3006 | + private $datetime_selector_max_checked = 10; |
|
| 3007 | + |
|
| 3008 | + |
|
| 3009 | + /** |
|
| 3010 | + * class constructor |
|
| 3011 | + */ |
|
| 3012 | + public function __construct() |
|
| 3013 | + { |
|
| 3014 | + $this->show_ticket_sale_columns = true; |
|
| 3015 | + $this->show_ticket_details = true; |
|
| 3016 | + $this->show_expired_tickets = true; |
|
| 3017 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3018 | + $this->datetime_selector_threshold = 3; |
|
| 3019 | + $this->datetime_selector_max_checked = 10; |
|
| 3020 | + } |
|
| 3021 | + |
|
| 3022 | + |
|
| 3023 | + /** |
|
| 3024 | + * returns true if a datetime selector should be displayed |
|
| 3025 | + * |
|
| 3026 | + * @param array $datetimes |
|
| 3027 | + * @return bool |
|
| 3028 | + */ |
|
| 3029 | + public function showDatetimeSelector(array $datetimes) |
|
| 3030 | + { |
|
| 3031 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3032 | + return ! ( |
|
| 3033 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3034 | + || ( |
|
| 3035 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3036 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3037 | + ) |
|
| 3038 | + ); |
|
| 3039 | + } |
|
| 3040 | + |
|
| 3041 | + |
|
| 3042 | + /** |
|
| 3043 | + * @return string |
|
| 3044 | + */ |
|
| 3045 | + public function getShowDatetimeSelector() |
|
| 3046 | + { |
|
| 3047 | + return $this->show_datetime_selector; |
|
| 3048 | + } |
|
| 3049 | + |
|
| 3050 | + |
|
| 3051 | + /** |
|
| 3052 | + * @param bool $keys_only |
|
| 3053 | + * @return array |
|
| 3054 | + */ |
|
| 3055 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3056 | + { |
|
| 3057 | + return $keys_only |
|
| 3058 | + ? array( |
|
| 3059 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3060 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3061 | + ) |
|
| 3062 | + : array( |
|
| 3063 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3064 | + 'Do not show date & time filter', |
|
| 3065 | + 'event_espresso' |
|
| 3066 | + ), |
|
| 3067 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3068 | + 'Maybe show date & time filter', |
|
| 3069 | + 'event_espresso' |
|
| 3070 | + ), |
|
| 3071 | + ); |
|
| 3072 | + } |
|
| 3073 | + |
|
| 3074 | + |
|
| 3075 | + /** |
|
| 3076 | + * @param string $show_datetime_selector |
|
| 3077 | + */ |
|
| 3078 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3079 | + { |
|
| 3080 | + $this->show_datetime_selector = in_array( |
|
| 3081 | + $show_datetime_selector, |
|
| 3082 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3083 | + true |
|
| 3084 | + ) |
|
| 3085 | + ? $show_datetime_selector |
|
| 3086 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3087 | + } |
|
| 3088 | + |
|
| 3089 | + |
|
| 3090 | + /** |
|
| 3091 | + * @return int |
|
| 3092 | + */ |
|
| 3093 | + public function getDatetimeSelectorThreshold() |
|
| 3094 | + { |
|
| 3095 | + return $this->datetime_selector_threshold; |
|
| 3096 | + } |
|
| 3097 | + |
|
| 3098 | + |
|
| 3099 | + /** |
|
| 3100 | + * @param int $datetime_selector_threshold |
|
| 3101 | + */ |
|
| 3102 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3103 | + { |
|
| 3104 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3105 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3106 | + } |
|
| 3107 | + |
|
| 3108 | + |
|
| 3109 | + /** |
|
| 3110 | + * @return int |
|
| 3111 | + */ |
|
| 3112 | + public function getDatetimeSelectorMaxChecked() |
|
| 3113 | + { |
|
| 3114 | + return $this->datetime_selector_max_checked; |
|
| 3115 | + } |
|
| 3116 | + |
|
| 3117 | + |
|
| 3118 | + /** |
|
| 3119 | + * @param int $datetime_selector_max_checked |
|
| 3120 | + */ |
|
| 3121 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3122 | + { |
|
| 3123 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3124 | + } |
|
| 3125 | 3125 | } |
| 3126 | 3126 | |
| 3127 | 3127 | /** |
@@ -3134,86 +3134,86 @@ discard block |
||
| 3134 | 3134 | class EE_Environment_Config extends EE_Config_Base |
| 3135 | 3135 | { |
| 3136 | 3136 | |
| 3137 | - /** |
|
| 3138 | - * Hold any php environment variables that we want to track. |
|
| 3139 | - * |
|
| 3140 | - * @var stdClass; |
|
| 3141 | - */ |
|
| 3142 | - public $php; |
|
| 3143 | - |
|
| 3144 | - |
|
| 3145 | - /** |
|
| 3146 | - * constructor |
|
| 3147 | - */ |
|
| 3148 | - public function __construct() |
|
| 3149 | - { |
|
| 3150 | - $this->php = new stdClass(); |
|
| 3151 | - $this->_set_php_values(); |
|
| 3152 | - } |
|
| 3153 | - |
|
| 3154 | - |
|
| 3155 | - /** |
|
| 3156 | - * This sets the php environment variables. |
|
| 3157 | - * |
|
| 3158 | - * @since 4.4.0 |
|
| 3159 | - * @return void |
|
| 3160 | - */ |
|
| 3161 | - protected function _set_php_values() |
|
| 3162 | - { |
|
| 3163 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3164 | - $this->php->version = phpversion(); |
|
| 3165 | - } |
|
| 3166 | - |
|
| 3167 | - |
|
| 3168 | - /** |
|
| 3169 | - * helper method for determining whether input_count is |
|
| 3170 | - * reaching the potential maximum the server can handle |
|
| 3171 | - * according to max_input_vars |
|
| 3172 | - * |
|
| 3173 | - * @param int $input_count the count of input vars. |
|
| 3174 | - * @return array { |
|
| 3175 | - * An array that represents whether available space and if no available space the error |
|
| 3176 | - * message. |
|
| 3177 | - * @type bool $has_space whether more inputs can be added. |
|
| 3178 | - * @type string $msg Any message to be displayed. |
|
| 3179 | - * } |
|
| 3180 | - */ |
|
| 3181 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3182 | - { |
|
| 3183 | - if (! empty($this->php->max_input_vars) |
|
| 3184 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3185 | - ) { |
|
| 3186 | - // check the server setting because the config value could be stale |
|
| 3187 | - $max_input_vars = ini_get('max_input_vars'); |
|
| 3188 | - if ($input_count >= $max_input_vars) { |
|
| 3189 | - return sprintf( |
|
| 3190 | - esc_html__( |
|
| 3191 | - 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3192 | - 'event_espresso' |
|
| 3193 | - ), |
|
| 3194 | - '<br>', |
|
| 3195 | - $input_count, |
|
| 3196 | - $max_input_vars |
|
| 3197 | - ); |
|
| 3198 | - } else { |
|
| 3199 | - return ''; |
|
| 3200 | - } |
|
| 3201 | - } else { |
|
| 3202 | - return ''; |
|
| 3203 | - } |
|
| 3204 | - } |
|
| 3205 | - |
|
| 3206 | - |
|
| 3207 | - /** |
|
| 3208 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3209 | - * |
|
| 3210 | - * @since 4.4.1 |
|
| 3211 | - * @return void |
|
| 3212 | - */ |
|
| 3213 | - public function recheck_values() |
|
| 3214 | - { |
|
| 3215 | - $this->_set_php_values(); |
|
| 3216 | - } |
|
| 3137 | + /** |
|
| 3138 | + * Hold any php environment variables that we want to track. |
|
| 3139 | + * |
|
| 3140 | + * @var stdClass; |
|
| 3141 | + */ |
|
| 3142 | + public $php; |
|
| 3143 | + |
|
| 3144 | + |
|
| 3145 | + /** |
|
| 3146 | + * constructor |
|
| 3147 | + */ |
|
| 3148 | + public function __construct() |
|
| 3149 | + { |
|
| 3150 | + $this->php = new stdClass(); |
|
| 3151 | + $this->_set_php_values(); |
|
| 3152 | + } |
|
| 3153 | + |
|
| 3154 | + |
|
| 3155 | + /** |
|
| 3156 | + * This sets the php environment variables. |
|
| 3157 | + * |
|
| 3158 | + * @since 4.4.0 |
|
| 3159 | + * @return void |
|
| 3160 | + */ |
|
| 3161 | + protected function _set_php_values() |
|
| 3162 | + { |
|
| 3163 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3164 | + $this->php->version = phpversion(); |
|
| 3165 | + } |
|
| 3166 | + |
|
| 3167 | + |
|
| 3168 | + /** |
|
| 3169 | + * helper method for determining whether input_count is |
|
| 3170 | + * reaching the potential maximum the server can handle |
|
| 3171 | + * according to max_input_vars |
|
| 3172 | + * |
|
| 3173 | + * @param int $input_count the count of input vars. |
|
| 3174 | + * @return array { |
|
| 3175 | + * An array that represents whether available space and if no available space the error |
|
| 3176 | + * message. |
|
| 3177 | + * @type bool $has_space whether more inputs can be added. |
|
| 3178 | + * @type string $msg Any message to be displayed. |
|
| 3179 | + * } |
|
| 3180 | + */ |
|
| 3181 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3182 | + { |
|
| 3183 | + if (! empty($this->php->max_input_vars) |
|
| 3184 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3185 | + ) { |
|
| 3186 | + // check the server setting because the config value could be stale |
|
| 3187 | + $max_input_vars = ini_get('max_input_vars'); |
|
| 3188 | + if ($input_count >= $max_input_vars) { |
|
| 3189 | + return sprintf( |
|
| 3190 | + esc_html__( |
|
| 3191 | + 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3192 | + 'event_espresso' |
|
| 3193 | + ), |
|
| 3194 | + '<br>', |
|
| 3195 | + $input_count, |
|
| 3196 | + $max_input_vars |
|
| 3197 | + ); |
|
| 3198 | + } else { |
|
| 3199 | + return ''; |
|
| 3200 | + } |
|
| 3201 | + } else { |
|
| 3202 | + return ''; |
|
| 3203 | + } |
|
| 3204 | + } |
|
| 3205 | + |
|
| 3206 | + |
|
| 3207 | + /** |
|
| 3208 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3209 | + * |
|
| 3210 | + * @since 4.4.1 |
|
| 3211 | + * @return void |
|
| 3212 | + */ |
|
| 3213 | + public function recheck_values() |
|
| 3214 | + { |
|
| 3215 | + $this->_set_php_values(); |
|
| 3216 | + } |
|
| 3217 | 3217 | } |
| 3218 | 3218 | |
| 3219 | 3219 | /** |
@@ -3226,21 +3226,21 @@ discard block |
||
| 3226 | 3226 | class EE_Tax_Config extends EE_Config_Base |
| 3227 | 3227 | { |
| 3228 | 3228 | |
| 3229 | - /* |
|
| 3229 | + /* |
|
| 3230 | 3230 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3231 | 3231 | * |
| 3232 | 3232 | * @var boolean $prices_displayed_including_taxes |
| 3233 | 3233 | */ |
| 3234 | - public $prices_displayed_including_taxes; |
|
| 3234 | + public $prices_displayed_including_taxes; |
|
| 3235 | 3235 | |
| 3236 | 3236 | |
| 3237 | - /** |
|
| 3238 | - * class constructor |
|
| 3239 | - */ |
|
| 3240 | - public function __construct() |
|
| 3241 | - { |
|
| 3242 | - $this->prices_displayed_including_taxes = true; |
|
| 3243 | - } |
|
| 3237 | + /** |
|
| 3238 | + * class constructor |
|
| 3239 | + */ |
|
| 3240 | + public function __construct() |
|
| 3241 | + { |
|
| 3242 | + $this->prices_displayed_including_taxes = true; |
|
| 3243 | + } |
|
| 3244 | 3244 | } |
| 3245 | 3245 | |
| 3246 | 3246 | /** |
@@ -3254,19 +3254,19 @@ discard block |
||
| 3254 | 3254 | class EE_Messages_Config extends EE_Config_Base |
| 3255 | 3255 | { |
| 3256 | 3256 | |
| 3257 | - /** |
|
| 3258 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3259 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3260 | - * |
|
| 3261 | - * @var integer |
|
| 3262 | - */ |
|
| 3263 | - public $delete_threshold; |
|
| 3257 | + /** |
|
| 3258 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3259 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3260 | + * |
|
| 3261 | + * @var integer |
|
| 3262 | + */ |
|
| 3263 | + public $delete_threshold; |
|
| 3264 | 3264 | |
| 3265 | 3265 | |
| 3266 | - public function __construct() |
|
| 3267 | - { |
|
| 3268 | - $this->delete_threshold = 0; |
|
| 3269 | - } |
|
| 3266 | + public function __construct() |
|
| 3267 | + { |
|
| 3268 | + $this->delete_threshold = 0; |
|
| 3269 | + } |
|
| 3270 | 3270 | } |
| 3271 | 3271 | |
| 3272 | 3272 | /** |
@@ -3277,31 +3277,31 @@ discard block |
||
| 3277 | 3277 | class EE_Gateway_Config extends EE_Config_Base |
| 3278 | 3278 | { |
| 3279 | 3279 | |
| 3280 | - /** |
|
| 3281 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3282 | - * with any config info the gateway wants to store |
|
| 3283 | - * |
|
| 3284 | - * @var array |
|
| 3285 | - */ |
|
| 3286 | - public $payment_settings; |
|
| 3287 | - |
|
| 3288 | - /** |
|
| 3289 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3290 | - * the gateway is stored in the uploads directory |
|
| 3291 | - * |
|
| 3292 | - * @var array |
|
| 3293 | - */ |
|
| 3294 | - public $active_gateways; |
|
| 3295 | - |
|
| 3296 | - |
|
| 3297 | - /** |
|
| 3298 | - * class constructor |
|
| 3299 | - * |
|
| 3300 | - * @deprecated |
|
| 3301 | - */ |
|
| 3302 | - public function __construct() |
|
| 3303 | - { |
|
| 3304 | - $this->payment_settings = array(); |
|
| 3305 | - $this->active_gateways = array('Invoice' => false); |
|
| 3306 | - } |
|
| 3280 | + /** |
|
| 3281 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3282 | + * with any config info the gateway wants to store |
|
| 3283 | + * |
|
| 3284 | + * @var array |
|
| 3285 | + */ |
|
| 3286 | + public $payment_settings; |
|
| 3287 | + |
|
| 3288 | + /** |
|
| 3289 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3290 | + * the gateway is stored in the uploads directory |
|
| 3291 | + * |
|
| 3292 | + * @var array |
|
| 3293 | + */ |
|
| 3294 | + public $active_gateways; |
|
| 3295 | + |
|
| 3296 | + |
|
| 3297 | + /** |
|
| 3298 | + * class constructor |
|
| 3299 | + * |
|
| 3300 | + * @deprecated |
|
| 3301 | + */ |
|
| 3302 | + public function __construct() |
|
| 3303 | + { |
|
| 3304 | + $this->payment_settings = array(); |
|
| 3305 | + $this->active_gateways = array('Invoice' => false); |
|
| 3306 | + } |
|
| 3307 | 3307 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | public static function instance() |
| 146 | 146 | { |
| 147 | 147 | // check if class object is instantiated, and instantiated properly |
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 148 | + if ( ! self::$_instance instanceof EE_Config) { |
|
| 149 | 149 | self::$_instance = new self(); |
| 150 | 150 | } |
| 151 | 151 | return self::$_instance; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | $this |
| 284 | 284 | ); |
| 285 | 285 | if (is_object($settings) && property_exists($this, $config)) { |
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings); |
|
| 287 | 287 | // call configs populate method to ensure any defaults are set for empty values. |
| 288 | 288 | if (method_exists($settings, 'populate')) { |
| 289 | 289 | $this->{$config}->populate(); |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | break; |
| 557 | 557 | // TEST #2 : check that settings section exists |
| 558 | 558 | case 2: |
| 559 | - if (! isset($this->{$section})) { |
|
| 559 | + if ( ! isset($this->{$section})) { |
|
| 560 | 560 | if ($display_errors) { |
| 561 | 561 | throw new EE_Error( |
| 562 | 562 | sprintf( |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | break; |
| 571 | 571 | // TEST #3 : check that section is the proper format |
| 572 | 572 | case 3: |
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 573 | + if ( ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | 574 | ) { |
| 575 | 575 | if ($display_errors) { |
| 576 | 576 | throw new EE_Error( |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | break; |
| 617 | 617 | // TEST #6 : verify config class is accessible |
| 618 | 618 | case 6: |
| 619 | - if (! class_exists($config_class)) { |
|
| 619 | + if ( ! class_exists($config_class)) { |
|
| 620 | 620 | if ($display_errors) { |
| 621 | 621 | throw new EE_Error( |
| 622 | 622 | sprintf( |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | break; |
| 634 | 634 | // TEST #7 : check that config has even been set |
| 635 | 635 | case 7: |
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 636 | + if ( ! isset($this->{$section}->{$name})) { |
|
| 637 | 637 | if ($display_errors) { |
| 638 | 638 | throw new EE_Error( |
| 639 | 639 | sprintf( |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | break; |
| 652 | 652 | // TEST #8 : check that config is the requested type |
| 653 | 653 | case 8: |
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 654 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | 655 | if ($display_errors) { |
| 656 | 656 | throw new EE_Error( |
| 657 | 657 | sprintf( |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | break; |
| 671 | 671 | // TEST #9 : verify config object |
| 672 | 672 | case 9: |
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 673 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 674 | 674 | if ($display_errors) { |
| 675 | 675 | throw new EE_Error( |
| 676 | 676 | sprintf( |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | private function _generate_config_option_name($section = '', $name = '') |
| 704 | 704 | { |
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 705 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | { |
| 720 | 720 | return ! empty($config_class) |
| 721 | 721 | ? $config_class |
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | |
@@ -738,17 +738,17 @@ discard block |
||
| 738 | 738 | // ensure config class is set to something |
| 739 | 739 | $config_class = $this->_set_config_class($config_class, $name); |
| 740 | 740 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 741 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | 742 | return null; |
| 743 | 743 | } |
| 744 | 744 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 745 | 745 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 746 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 747 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 748 | 748 | $this->update_addon_option_names(); |
| 749 | 749 | } |
| 750 | 750 | // verify the incoming config object but suppress errors |
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 751 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | 752 | $config_obj = new $config_class(); |
| 753 | 753 | } |
| 754 | 754 | if (get_option($config_option_name)) { |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | // get class name of the incoming object |
| 796 | 796 | $config_class = get_class($config_obj); |
| 797 | 797 | // run tests 1-5 and 9 to verify config |
| 798 | - if (! $this->_verify_config_params( |
|
| 798 | + if ( ! $this->_verify_config_params( |
|
| 799 | 799 | $section, |
| 800 | 800 | $name, |
| 801 | 801 | $config_class, |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | } |
| 808 | 808 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 809 | 809 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 810 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 811 | 811 | // save new config to db |
| 812 | 812 | if ($this->set_config($section, $name, $config_class, $config_obj)) { |
| 813 | 813 | return true; |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | 'event_espresso' |
| 834 | 834 | ), |
| 835 | 835 | $config_class, |
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 836 | + 'EE_Config->'.$section.'->'.$name |
|
| 837 | 837 | ), |
| 838 | 838 | __FILE__, |
| 839 | 839 | __FUNCTION__, |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | // ensure config class is set to something |
| 860 | 860 | $config_class = $this->_set_config_class($config_class, $name); |
| 861 | 861 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 862 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | 863 | return null; |
| 864 | 864 | } |
| 865 | 865 | // now test if the requested config object exists, but suppress errors |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | // retrieve the wp-option for this config class. |
| 905 | 905 | $config_option = maybe_unserialize(get_option($config_option_name, array())); |
| 906 | 906 | if (empty($config_option)) { |
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 907 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 908 | 908 | } |
| 909 | 909 | return $config_option; |
| 910 | 910 | } |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | // copy incoming $_REQUEST and sanitize it so we can save it |
| 923 | 923 | $_request = $_REQUEST; |
| 924 | 924 | array_walk_recursive($_request, 'sanitize_text_field'); |
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 925 | + $config_log[(string) microtime(true)] = array( |
|
| 926 | 926 | 'config_name' => $config_option_name, |
| 927 | 927 | 'request' => $_request, |
| 928 | 928 | ); |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | */ |
| 938 | 938 | public static function trim_log() |
| 939 | 939 | { |
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 940 | + if ( ! EE_Config::logging_enabled()) { |
|
| 941 | 941 | return; |
| 942 | 942 | } |
| 943 | 943 | $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | public static function get_page_for_posts() |
| 962 | 962 | { |
| 963 | 963 | $page_for_posts = get_option('page_for_posts'); |
| 964 | - if (! $page_for_posts) { |
|
| 964 | + if ( ! $page_for_posts) { |
|
| 965 | 965 | return 'posts'; |
| 966 | 966 | } |
| 967 | 967 | /** @type WPDB $wpdb */ |
@@ -1011,20 +1011,20 @@ discard block |
||
| 1011 | 1011 | { |
| 1012 | 1012 | // only init widgets on admin pages when not in complete maintenance, and |
| 1013 | 1013 | // on frontend when not in any maintenance mode |
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1014 | + if ( ! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | 1015 | || ( |
| 1016 | 1016 | is_admin() |
| 1017 | 1017 | && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
| 1018 | 1018 | ) |
| 1019 | 1019 | ) { |
| 1020 | 1020 | // grab list of installed widgets |
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 1022 | 1022 | // filter list of modules to register |
| 1023 | 1023 | $widgets_to_register = apply_filters( |
| 1024 | 1024 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 1025 | 1025 | $widgets_to_register |
| 1026 | 1026 | ); |
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1027 | + if ( ! empty($widgets_to_register)) { |
|
| 1028 | 1028 | // cycle thru widget folders |
| 1029 | 1029 | foreach ($widgets_to_register as $widget_path) { |
| 1030 | 1030 | // add to list of installed widget modules |
@@ -1074,31 +1074,31 @@ discard block |
||
| 1074 | 1074 | // create classname from widget directory name |
| 1075 | 1075 | $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
| 1076 | 1076 | // add class prefix |
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1077 | + $widget_class = 'EEW_'.$widget; |
|
| 1078 | 1078 | // does the widget exist ? |
| 1079 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1079 | + if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) { |
|
| 1080 | 1080 | $msg = sprintf( |
| 1081 | 1081 | __( |
| 1082 | 1082 | 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
| 1083 | 1083 | 'event_espresso' |
| 1084 | 1084 | ), |
| 1085 | 1085 | $widget_class, |
| 1086 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1086 | + $widget_path.'/'.$widget_class.$widget_ext |
|
| 1087 | 1087 | ); |
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1088 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | 1089 | return; |
| 1090 | 1090 | } |
| 1091 | 1091 | // load the widget class file |
| 1092 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1092 | + require_once($widget_path.'/'.$widget_class.$widget_ext); |
|
| 1093 | 1093 | // verify that class exists |
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1094 | + if ( ! class_exists($widget_class)) { |
|
| 1095 | 1095 | $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1096 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | 1097 | return; |
| 1098 | 1098 | } |
| 1099 | 1099 | register_widget($widget_class); |
| 1100 | 1100 | // add to array of registered widgets |
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext; |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1111,18 +1111,18 @@ discard block |
||
| 1111 | 1111 | private function _register_modules() |
| 1112 | 1112 | { |
| 1113 | 1113 | // grab list of installed modules |
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1114 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1115 | 1115 | // filter list of modules to register |
| 1116 | 1116 | $modules_to_register = apply_filters( |
| 1117 | 1117 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1118 | 1118 | $modules_to_register |
| 1119 | 1119 | ); |
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1120 | + if ( ! empty($modules_to_register)) { |
|
| 1121 | 1121 | // loop through folders |
| 1122 | 1122 | foreach ($modules_to_register as $module_path) { |
| 1123 | 1123 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1124 | + if ($module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1126 | 1126 | ) { |
| 1127 | 1127 | // add to list of installed modules |
| 1128 | 1128 | EE_Config::register_module($module_path); |
@@ -1159,25 +1159,25 @@ discard block |
||
| 1159 | 1159 | // remove last segment |
| 1160 | 1160 | array_pop($module_path); |
| 1161 | 1161 | // glue it back together |
| 1162 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1162 | + $module_path = implode('/', $module_path).'/'; |
|
| 1163 | 1163 | // take first segment from file name pieces and sanitize it |
| 1164 | 1164 | $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
| 1165 | 1165 | // ensure class prefix is added |
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1167 | 1167 | } else { |
| 1168 | 1168 | // we need to generate the filename based off of the folder name |
| 1169 | 1169 | // grab and sanitize module name |
| 1170 | 1170 | $module = strtolower(basename($module_path)); |
| 1171 | 1171 | $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
| 1172 | 1172 | // like trailingslashit() |
| 1173 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1173 | + $module_path = rtrim($module_path, '/').'/'; |
|
| 1174 | 1174 | // create classname from module directory name |
| 1175 | 1175 | $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
| 1176 | 1176 | // add class prefix |
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1177 | + $module_class = 'EED_'.$module; |
|
| 1178 | 1178 | } |
| 1179 | 1179 | // does the module exist ? |
| 1180 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1180 | + if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) { |
|
| 1181 | 1181 | $msg = sprintf( |
| 1182 | 1182 | __( |
| 1183 | 1183 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1185,19 +1185,19 @@ discard block |
||
| 1185 | 1185 | ), |
| 1186 | 1186 | $module |
| 1187 | 1187 | ); |
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1188 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | 1189 | return false; |
| 1190 | 1190 | } |
| 1191 | 1191 | // load the module class file |
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1192 | + require_once($module_path.$module_class.$module_ext); |
|
| 1193 | 1193 | // verify that class exists |
| 1194 | - if (! class_exists($module_class)) { |
|
| 1194 | + if ( ! class_exists($module_class)) { |
|
| 1195 | 1195 | $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1196 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | 1197 | return false; |
| 1198 | 1198 | } |
| 1199 | 1199 | // add to array of registered modules |
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1201 | 1201 | do_action( |
| 1202 | 1202 | 'AHEE__EE_Config__register_module__complete', |
| 1203 | 1203 | $module_class, |
@@ -1248,26 +1248,26 @@ discard block |
||
| 1248 | 1248 | { |
| 1249 | 1249 | do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
| 1250 | 1250 | $module = str_replace('EED_', '', $module); |
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1251 | + $module_class = 'EED_'.$module; |
|
| 1252 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | 1253 | $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1254 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | 1255 | return false; |
| 1256 | 1256 | } |
| 1257 | 1257 | if (empty($route)) { |
| 1258 | 1258 | $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | 1260 | return false; |
| 1261 | 1261 | } |
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1262 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1263 | 1263 | $msg = sprintf( |
| 1264 | 1264 | __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
| 1265 | 1265 | $route |
| 1266 | 1266 | ); |
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1267 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | 1268 | return false; |
| 1269 | 1269 | } |
| 1270 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1270 | + EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name); |
|
| 1271 | 1271 | return true; |
| 1272 | 1272 | } |
| 1273 | 1273 | |
@@ -1284,8 +1284,8 @@ discard block |
||
| 1284 | 1284 | { |
| 1285 | 1285 | do_action('AHEE__EE_Config__get_route__begin', $route); |
| 1286 | 1286 | $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1288 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | return null; |
| 1291 | 1291 | } |
@@ -1317,47 +1317,47 @@ discard block |
||
| 1317 | 1317 | public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
| 1318 | 1318 | { |
| 1319 | 1319 | do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1320 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1321 | 1321 | $msg = sprintf( |
| 1322 | 1322 | __('The module route %s for this forward has not been registered.', 'event_espresso'), |
| 1323 | 1323 | $route |
| 1324 | 1324 | ); |
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1325 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | 1326 | return false; |
| 1327 | 1327 | } |
| 1328 | 1328 | if (empty($forward)) { |
| 1329 | 1329 | $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | 1331 | return false; |
| 1332 | 1332 | } |
| 1333 | 1333 | if (is_array($forward)) { |
| 1334 | - if (! isset($forward[1])) { |
|
| 1334 | + if ( ! isset($forward[1])) { |
|
| 1335 | 1335 | $msg = sprintf( |
| 1336 | 1336 | __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
| 1337 | 1337 | $route |
| 1338 | 1338 | ); |
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1339 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | 1340 | return false; |
| 1341 | 1341 | } |
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1342 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1343 | 1343 | $msg = sprintf( |
| 1344 | 1344 | __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1345 | 1345 | $forward[1], |
| 1346 | 1346 | $route |
| 1347 | 1347 | ); |
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1348 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | 1349 | return false; |
| 1350 | 1350 | } |
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1351 | + } elseif ( ! function_exists($forward)) { |
|
| 1352 | 1352 | $msg = sprintf( |
| 1353 | 1353 | __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1354 | 1354 | $forward, |
| 1355 | 1355 | $route |
| 1356 | 1356 | ); |
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1357 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | 1358 | return false; |
| 1359 | 1359 | } |
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1360 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1361 | 1361 | return true; |
| 1362 | 1362 | } |
| 1363 | 1363 | |
@@ -1375,10 +1375,10 @@ discard block |
||
| 1375 | 1375 | public static function get_forward($route = null, $status = 0, $key = 'ee') |
| 1376 | 1376 | { |
| 1377 | 1377 | do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1379 | 1379 | return apply_filters( |
| 1380 | 1380 | 'FHEE__EE_Config__get_forward', |
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1381 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1382 | 1382 | $route, |
| 1383 | 1383 | $status |
| 1384 | 1384 | ); |
@@ -1402,15 +1402,15 @@ discard block |
||
| 1402 | 1402 | public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
| 1403 | 1403 | { |
| 1404 | 1404 | do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1405 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1406 | 1406 | $msg = sprintf( |
| 1407 | 1407 | __('The module route %s for this view has not been registered.', 'event_espresso'), |
| 1408 | 1408 | $route |
| 1409 | 1409 | ); |
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1410 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | 1411 | return false; |
| 1412 | 1412 | } |
| 1413 | - if (! is_readable($view)) { |
|
| 1413 | + if ( ! is_readable($view)) { |
|
| 1414 | 1414 | $msg = sprintf( |
| 1415 | 1415 | __( |
| 1416 | 1416 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1418,10 +1418,10 @@ discard block |
||
| 1418 | 1418 | ), |
| 1419 | 1419 | $view |
| 1420 | 1420 | ); |
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1421 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | 1422 | return false; |
| 1423 | 1423 | } |
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1424 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1425 | 1425 | return true; |
| 1426 | 1426 | } |
| 1427 | 1427 | |
@@ -1439,10 +1439,10 @@ discard block |
||
| 1439 | 1439 | public static function get_view($route = null, $status = 0, $key = 'ee') |
| 1440 | 1440 | { |
| 1441 | 1441 | do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1443 | 1443 | return apply_filters( |
| 1444 | 1444 | 'FHEE__EE_Config__get_view', |
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1445 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1446 | 1446 | $route, |
| 1447 | 1447 | $status |
| 1448 | 1448 | ); |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | public static function getLegacyShortcodesManager() |
| 1470 | 1470 | { |
| 1471 | 1471 | |
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1472 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | 1473 | EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
| 1474 | 1474 | EE_Registry::instance() |
| 1475 | 1475 | ); |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | */ |
| 1517 | 1517 | public function get_pretty($property) |
| 1518 | 1518 | { |
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1519 | + if ( ! property_exists($this, $property)) { |
|
| 1520 | 1520 | throw new EE_Error( |
| 1521 | 1521 | sprintf( |
| 1522 | 1522 | __( |
@@ -1745,11 +1745,11 @@ discard block |
||
| 1745 | 1745 | */ |
| 1746 | 1746 | public function reg_page_url() |
| 1747 | 1747 | { |
| 1748 | - if (! $this->reg_page_url) { |
|
| 1748 | + if ( ! $this->reg_page_url) { |
|
| 1749 | 1749 | $this->reg_page_url = add_query_arg( |
| 1750 | 1750 | array('uts' => time()), |
| 1751 | 1751 | get_permalink($this->reg_page_id) |
| 1752 | - ) . '#checkout'; |
|
| 1752 | + ).'#checkout'; |
|
| 1753 | 1753 | } |
| 1754 | 1754 | return $this->reg_page_url; |
| 1755 | 1755 | } |
@@ -1765,7 +1765,7 @@ discard block |
||
| 1765 | 1765 | */ |
| 1766 | 1766 | public function txn_page_url($query_args = array()) |
| 1767 | 1767 | { |
| 1768 | - if (! $this->txn_page_url) { |
|
| 1768 | + if ( ! $this->txn_page_url) { |
|
| 1769 | 1769 | $this->txn_page_url = get_permalink($this->txn_page_id); |
| 1770 | 1770 | } |
| 1771 | 1771 | if ($query_args) { |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | */ |
| 1787 | 1787 | public function thank_you_page_url($query_args = array()) |
| 1788 | 1788 | { |
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1789 | + if ( ! $this->thank_you_page_url) { |
|
| 1790 | 1790 | $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
| 1791 | 1791 | } |
| 1792 | 1792 | if ($query_args) { |
@@ -1805,7 +1805,7 @@ discard block |
||
| 1805 | 1805 | */ |
| 1806 | 1806 | public function cancel_page_url() |
| 1807 | 1807 | { |
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1808 | + if ( ! $this->cancel_page_url) { |
|
| 1809 | 1809 | $this->cancel_page_url = get_permalink($this->cancel_page_id); |
| 1810 | 1810 | } |
| 1811 | 1811 | return $this->cancel_page_url; |
@@ -1848,13 +1848,13 @@ discard block |
||
| 1848 | 1848 | $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
| 1849 | 1849 | $option = self::OPTION_NAME_UXIP; |
| 1850 | 1850 | // set correct table for query |
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1852 | 1852 | // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
| 1853 | 1853 | // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
| 1854 | 1854 | // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1855 | 1855 | // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1856 | 1856 | // for the purpose of caching. |
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1857 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1858 | 1858 | if (false !== $pre) { |
| 1859 | 1859 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1860 | 1860 | return EE_Core_Config::$ee_ueip_option; |
@@ -1868,10 +1868,10 @@ discard block |
||
| 1868 | 1868 | if (is_object($row)) { |
| 1869 | 1869 | $value = $row->option_value; |
| 1870 | 1870 | } else { // option does not exist so use default. |
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option); |
|
| 1872 | 1872 | return EE_Core_Config::$ee_ueip_option; |
| 1873 | 1873 | } |
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1875 | 1875 | return EE_Core_Config::$ee_ueip_option; |
| 1876 | 1876 | } |
| 1877 | 1877 | |
@@ -2125,37 +2125,37 @@ discard block |
||
| 2125 | 2125 | // but override if requested |
| 2126 | 2126 | $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
| 2127 | 2127 | // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
| 2128 | - if (! empty($CNT_ISO) |
|
| 2128 | + if ( ! empty($CNT_ISO) |
|
| 2129 | 2129 | && EE_Maintenance_Mode::instance()->models_can_query() |
| 2130 | 2130 | && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
| 2131 | 2131 | ) { |
| 2132 | 2132 | // retrieve the country settings from the db, just in case they have been customized |
| 2133 | 2133 | $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
| 2134 | 2134 | if ($country instanceof EE_Country) { |
| 2135 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2135 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | 2139 | $this->sign_b4 = $country->currency_sign_before( |
| 2140 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2140 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | 2142 | $this->dec_mrk = $country->currency_decimal_mark( |
| 2143 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2143 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | 2144 | $this->thsnds = $country->currency_thousands_separator( |
| 2145 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2145 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | 2146 | } |
| 2147 | 2147 | } |
| 2148 | 2148 | // fallback to hardcoded defaults, in case the above failed |
| 2149 | 2149 | if (empty($this->code)) { |
| 2150 | 2150 | // set default currency settings |
| 2151 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | - $this->sign = '$'; // currency sign: $ |
|
| 2155 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2151 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | + $this->sign = '$'; // currency sign: $ |
|
| 2155 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | 2159 | } |
| 2160 | 2160 | } |
| 2161 | 2161 | } |
@@ -2414,8 +2414,8 @@ discard block |
||
| 2414 | 2414 | $closing_a_tag = ''; |
| 2415 | 2415 | if (function_exists('get_privacy_policy_url')) { |
| 2416 | 2416 | $privacy_page_url = get_privacy_policy_url(); |
| 2417 | - if (! empty($privacy_page_url)) { |
|
| 2418 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2417 | + if ( ! empty($privacy_page_url)) { |
|
| 2418 | + $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">'; |
|
| 2419 | 2419 | $closing_a_tag = '</a>'; |
| 2420 | 2420 | } |
| 2421 | 2421 | } |
@@ -2630,7 +2630,7 @@ discard block |
||
| 2630 | 2630 | public function log_file_name($reset = false) |
| 2631 | 2631 | { |
| 2632 | 2632 | if (empty($this->log_file_name) || $reset) { |
| 2633 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2633 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2634 | 2634 | EE_Config::instance()->update_espresso_config(false, false); |
| 2635 | 2635 | } |
| 2636 | 2636 | return $this->log_file_name; |
@@ -2644,7 +2644,7 @@ discard block |
||
| 2644 | 2644 | public function debug_file_name($reset = false) |
| 2645 | 2645 | { |
| 2646 | 2646 | if (empty($this->debug_file_name) || $reset) { |
| 2647 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2647 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2648 | 2648 | EE_Config::instance()->update_espresso_config(false, false); |
| 2649 | 2649 | } |
| 2650 | 2650 | return $this->debug_file_name; |
@@ -2848,21 +2848,21 @@ discard block |
||
| 2848 | 2848 | $this->use_google_maps = true; |
| 2849 | 2849 | $this->google_map_api_key = ''; |
| 2850 | 2850 | // for event details pages (reg page) |
| 2851 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2851 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2852 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2853 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2854 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2855 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2856 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2857 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2858 | 2858 | // for event list pages |
| 2859 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2859 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2860 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2861 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2862 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2863 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2864 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2865 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2866 | 2866 | } |
| 2867 | 2867 | } |
| 2868 | 2868 | |
@@ -3180,7 +3180,7 @@ discard block |
||
| 3180 | 3180 | */ |
| 3181 | 3181 | public function max_input_vars_limit_check($input_count = 0) |
| 3182 | 3182 | { |
| 3183 | - if (! empty($this->php->max_input_vars) |
|
| 3183 | + if ( ! empty($this->php->max_input_vars) |
|
| 3184 | 3184 | && ($input_count >= $this->php->max_input_vars) |
| 3185 | 3185 | ) { |
| 3186 | 3186 | // check the server setting because the config value could be stale |
@@ -7,16 +7,16 @@ discard block |
||
| 7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
| 8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
| 9 | 9 | if (! defined('DS')) { |
| 10 | - define('DS', '/'); |
|
| 10 | + define('DS', '/'); |
|
| 11 | 11 | } |
| 12 | 12 | if (! defined('PS')) { |
| 13 | - define('PS', PATH_SEPARATOR); |
|
| 13 | + define('PS', PATH_SEPARATOR); |
|
| 14 | 14 | } |
| 15 | 15 | if (! defined('SP')) { |
| 16 | - define('SP', ' '); |
|
| 16 | + define('SP', ' '); |
|
| 17 | 17 | } |
| 18 | 18 | if (! defined('EENL')) { |
| 19 | - define('EENL', "\n"); |
|
| 19 | + define('EENL', "\n"); |
|
| 20 | 20 | } |
| 21 | 21 | // define the plugin directory and URL |
| 22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
@@ -70,16 +70,16 @@ discard block |
||
| 70 | 70 | define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
| 71 | 71 | // check for DOMPDF fonts in uploads |
| 72 | 72 | if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
| 73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
| 73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
| 74 | 74 | } |
| 75 | 75 | // ajax constants |
| 76 | 76 | define( |
| 77 | - 'EE_FRONT_AJAX', |
|
| 78 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
| 77 | + 'EE_FRONT_AJAX', |
|
| 78 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) |
|
| 79 | 79 | ); |
| 80 | 80 | define( |
| 81 | - 'EE_ADMIN_AJAX', |
|
| 82 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
| 81 | + 'EE_ADMIN_AJAX', |
|
| 82 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) |
|
| 83 | 83 | ); |
| 84 | 84 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
| 85 | 85 | // you're better to use this than its straight value (currently -1) in case you ever |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | define('EE_INF_IN_DB', -1); |
| 88 | 88 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
| 89 | 89 | if (! defined('EE_DEBUG')) { |
| 90 | - define('EE_DEBUG', false); |
|
| 90 | + define('EE_DEBUG', false); |
|
| 91 | 91 | } |
| 92 | 92 | // for older WP versions |
| 93 | 93 | if (! defined('MONTH_IN_SECONDS')) { |
| 94 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 94 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 95 | 95 | } |
@@ -6,71 +6,71 @@ discard block |
||
| 6 | 6 | define('EE_MIN_PHP_VER_RECOMMENDED', '5.6.32'); |
| 7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
| 8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
| 9 | -if (! defined('DS')) { |
|
| 9 | +if ( ! defined('DS')) { |
|
| 10 | 10 | define('DS', '/'); |
| 11 | 11 | } |
| 12 | -if (! defined('PS')) { |
|
| 12 | +if ( ! defined('PS')) { |
|
| 13 | 13 | define('PS', PATH_SEPARATOR); |
| 14 | 14 | } |
| 15 | -if (! defined('SP')) { |
|
| 15 | +if ( ! defined('SP')) { |
|
| 16 | 16 | define('SP', ' '); |
| 17 | 17 | } |
| 18 | -if (! defined('EENL')) { |
|
| 18 | +if ( ! defined('EENL')) { |
|
| 19 | 19 | define('EENL', "\n"); |
| 20 | 20 | } |
| 21 | 21 | // define the plugin directory and URL |
| 22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
| 23 | -define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . '/'); |
|
| 23 | +define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).'/'); |
|
| 24 | 24 | define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
| 25 | 25 | // main root folder paths |
| 26 | -define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages/'); |
|
| 27 | -define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core/'); |
|
| 28 | -define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules/'); |
|
| 29 | -define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public/'); |
|
| 30 | -define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes/'); |
|
| 31 | -define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets/'); |
|
| 32 | -define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods/'); |
|
| 33 | -define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated/'); |
|
| 26 | +define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages/'); |
|
| 27 | +define('EE_CORE', EE_PLUGIN_DIR_PATH.'core/'); |
|
| 28 | +define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules/'); |
|
| 29 | +define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public/'); |
|
| 30 | +define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes/'); |
|
| 31 | +define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets/'); |
|
| 32 | +define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods/'); |
|
| 33 | +define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated/'); |
|
| 34 | 34 | // core system paths |
| 35 | -define('EE_ADMIN', EE_CORE . 'admin/'); |
|
| 36 | -define('EE_CPTS', EE_CORE . 'CPTs/'); |
|
| 37 | -define('EE_CLASSES', EE_CORE . 'db_classes/'); |
|
| 38 | -define('EE_INTERFACES', EE_CORE . 'interfaces/'); |
|
| 39 | -define('EE_BUSINESS', EE_CORE . 'business/'); |
|
| 40 | -define('EE_MODELS', EE_CORE . 'db_models/'); |
|
| 41 | -define('EE_HELPERS', EE_CORE . 'helpers/'); |
|
| 42 | -define('EE_LIBRARIES', EE_CORE . 'libraries/'); |
|
| 43 | -define('EE_TEMPLATES', EE_CORE . 'templates/'); |
|
| 44 | -define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs/'); |
|
| 45 | -define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets/'); |
|
| 46 | -define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections/'); |
|
| 35 | +define('EE_ADMIN', EE_CORE.'admin/'); |
|
| 36 | +define('EE_CPTS', EE_CORE.'CPTs/'); |
|
| 37 | +define('EE_CLASSES', EE_CORE.'db_classes/'); |
|
| 38 | +define('EE_INTERFACES', EE_CORE.'interfaces/'); |
|
| 39 | +define('EE_BUSINESS', EE_CORE.'business/'); |
|
| 40 | +define('EE_MODELS', EE_CORE.'db_models/'); |
|
| 41 | +define('EE_HELPERS', EE_CORE.'helpers/'); |
|
| 42 | +define('EE_LIBRARIES', EE_CORE.'libraries/'); |
|
| 43 | +define('EE_TEMPLATES', EE_CORE.'templates/'); |
|
| 44 | +define('EE_THIRD_PARTY', EE_CORE.'third_party_libs/'); |
|
| 45 | +define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets/'); |
|
| 46 | +define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections/'); |
|
| 47 | 47 | // gateways |
| 48 | -define('EE_GATEWAYS', EE_MODULES . 'gateways/'); |
|
| 49 | -define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules/gateways/'); |
|
| 48 | +define('EE_GATEWAYS', EE_MODULES.'gateways/'); |
|
| 49 | +define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules/gateways/'); |
|
| 50 | 50 | // asset URL paths |
| 51 | -define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core/templates/'); |
|
| 52 | -define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets/'); |
|
| 53 | -define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images/'); |
|
| 54 | -define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core/third_party_libs/'); |
|
| 55 | -define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 56 | -define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 51 | +define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core/templates/'); |
|
| 52 | +define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets/'); |
|
| 53 | +define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images/'); |
|
| 54 | +define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core/third_party_libs/'); |
|
| 55 | +define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
| 56 | +define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
| 57 | 57 | // define upload paths |
| 58 | 58 | $uploads = wp_upload_dir(); |
| 59 | 59 | // define the uploads directory and URL |
| 60 | -define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . '/espresso/'); |
|
| 61 | -define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . '/espresso/'); |
|
| 60 | +define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].'/espresso/'); |
|
| 61 | +define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].'/espresso/'); |
|
| 62 | 62 | // define the templates directory and URL |
| 63 | -define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . '/espresso/templates/'); |
|
| 64 | -define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . '/espresso/templates/'); |
|
| 63 | +define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].'/espresso/templates/'); |
|
| 64 | +define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].'/espresso/templates/'); |
|
| 65 | 65 | // define the gateway directory and URL |
| 66 | -define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . '/espresso/gateways/'); |
|
| 67 | -define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . '/espresso/gateways/'); |
|
| 66 | +define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].'/espresso/gateways/'); |
|
| 67 | +define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].'/espresso/gateways/'); |
|
| 68 | 68 | // languages folder/path |
| 69 | -define('EE_LANGUAGES_SAFE_LOC', '../' . 'uploads/' . 'espresso/languages/'); |
|
| 70 | -define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
|
| 69 | +define('EE_LANGUAGES_SAFE_LOC', '../'.'uploads/'.'espresso/languages/'); |
|
| 70 | +define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages/'); |
|
| 71 | 71 | // check for DOMPDF fonts in uploads |
| 72 | -if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
|
| 73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
| 72 | +if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts/')) { |
|
| 73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts/'); |
|
| 74 | 74 | } |
| 75 | 75 | // ajax constants |
| 76 | 76 | define( |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | // want to change its default value! or find when -1 means infinity |
| 87 | 87 | define('EE_INF_IN_DB', -1); |
| 88 | 88 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
| 89 | -if (! defined('EE_DEBUG')) { |
|
| 89 | +if ( ! defined('EE_DEBUG')) { |
|
| 90 | 90 | define('EE_DEBUG', false); |
| 91 | 91 | } |
| 92 | 92 | // for older WP versions |
| 93 | -if (! defined('MONTH_IN_SECONDS')) { |
|
| 93 | +if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 94 | 94 | define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
| 95 | 95 | } |
@@ -20,488 +20,488 @@ discard block |
||
| 20 | 20 | final class EE_Admin implements InterminableInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var EE_Admin $_instance |
|
| 25 | - */ |
|
| 26 | - private static $_instance; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
| 30 | - */ |
|
| 31 | - private $persistent_admin_notice_manager; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var LoaderInterface |
|
| 35 | - */ |
|
| 36 | - protected $loader; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @singleton method used to instantiate class object |
|
| 40 | - * @return EE_Admin |
|
| 41 | - * @throws EE_Error |
|
| 42 | - */ |
|
| 43 | - public static function instance() |
|
| 44 | - { |
|
| 45 | - // check if class object is instantiated |
|
| 46 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 47 | - self::$_instance = new self(); |
|
| 48 | - } |
|
| 49 | - return self::$_instance; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @return EE_Admin |
|
| 55 | - * @throws EE_Error |
|
| 56 | - */ |
|
| 57 | - public static function reset() |
|
| 58 | - { |
|
| 59 | - self::$_instance = null; |
|
| 60 | - return self::instance(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * class constructor |
|
| 66 | - * |
|
| 67 | - * @throws EE_Error |
|
| 68 | - * @throws InvalidDataTypeException |
|
| 69 | - * @throws InvalidInterfaceException |
|
| 70 | - * @throws InvalidArgumentException |
|
| 71 | - */ |
|
| 72 | - protected function __construct() |
|
| 73 | - { |
|
| 74 | - // define global EE_Admin constants |
|
| 75 | - $this->_define_all_constants(); |
|
| 76 | - // set autoloaders for our admin page classes based on included path information |
|
| 77 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 78 | - // admin hooks |
|
| 79 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 80 | - // load EE_Request_Handler early |
|
| 81 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 82 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 83 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 84 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 85 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 86 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 87 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 88 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 89 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 90 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 91 | - add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage')); |
|
| 92 | - add_action('display_post_states', array($this, 'displayStateForCriticalPages'), 10, 2); |
|
| 93 | - add_filter('plugin_row_meta', array($this, 'addLinksToPluginRowMeta'), 10, 2); |
|
| 94 | - // reset Environment config (we only do this on admin page loads); |
|
| 95 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 96 | - do_action('AHEE__EE_Admin__loaded'); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * _define_all_constants |
|
| 102 | - * define constants that are set globally for all admin pages |
|
| 103 | - * |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - private function _define_all_constants() |
|
| 107 | - { |
|
| 108 | - if (! defined('EE_ADMIN_URL')) { |
|
| 109 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 110 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 111 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/'); |
|
| 112 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 113 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
| 120 | - * |
|
| 121 | - * @param array $links |
|
| 122 | - * @param string $plugin |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function filter_plugin_actions($links, $plugin) |
|
| 126 | - { |
|
| 127 | - // set $main_file in stone |
|
| 128 | - static $main_file; |
|
| 129 | - // if $main_file is not set yet |
|
| 130 | - if (! $main_file) { |
|
| 131 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 132 | - } |
|
| 133 | - if ($plugin === $main_file) { |
|
| 134 | - // compare current plugin to this one |
|
| 135 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 136 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 137 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 138 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 139 | - . '</a>'; |
|
| 140 | - array_unshift($links, $maintenance_link); |
|
| 141 | - } else { |
|
| 142 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 143 | - . esc_html__('Settings', 'event_espresso') |
|
| 144 | - . '</a>'; |
|
| 145 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 146 | - . esc_html__('Events', 'event_espresso') |
|
| 147 | - . '</a>'; |
|
| 148 | - // add before other links |
|
| 149 | - array_unshift($links, $org_settings_link, $events_link); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - return $links; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * _get_request |
|
| 158 | - * |
|
| 159 | - * @return void |
|
| 160 | - * @throws EE_Error |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - * @throws ReflectionException |
|
| 165 | - */ |
|
| 166 | - public function get_request() |
|
| 167 | - { |
|
| 168 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * hide_admin_pages_except_maintenance_mode |
|
| 174 | - * |
|
| 175 | - * @param array $admin_page_folder_names |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 179 | - { |
|
| 180 | - return array( |
|
| 181 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance/', |
|
| 182 | - 'about' => EE_ADMIN_PAGES . 'about/', |
|
| 183 | - 'support' => EE_ADMIN_PAGES . 'support/', |
|
| 184 | - ); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 190 | - * EE_Front_Controller's init phases have run |
|
| 191 | - * |
|
| 192 | - * @return void |
|
| 193 | - * @throws EE_Error |
|
| 194 | - * @throws InvalidArgumentException |
|
| 195 | - * @throws InvalidDataTypeException |
|
| 196 | - * @throws InvalidInterfaceException |
|
| 197 | - * @throws ReflectionException |
|
| 198 | - * @throws ServiceNotFoundException |
|
| 199 | - */ |
|
| 200 | - public function init() |
|
| 201 | - { |
|
| 202 | - // only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 203 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 204 | - $this->initModelsReady(); |
|
| 205 | - } |
|
| 206 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 207 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 208 | - try { |
|
| 209 | - // this loads the controller for the admin pages which will setup routing etc |
|
| 210 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 211 | - } catch (EE_Error $e) { |
|
| 212 | - $e->get_error(); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 216 | - // make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 217 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 218 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 219 | - // exclude EE critical pages from all nav menus and wp_list_pages |
|
| 220 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Gets the loader (and if it wasn't previously set, sets it) |
|
| 226 | - * @return LoaderInterface |
|
| 227 | - * @throws InvalidArgumentException |
|
| 228 | - * @throws InvalidDataTypeException |
|
| 229 | - * @throws InvalidInterfaceException |
|
| 230 | - */ |
|
| 231 | - protected function getLoader() |
|
| 232 | - { |
|
| 233 | - if (! $this->loader instanceof LoaderInterface) { |
|
| 234 | - $this->loader = LoaderFactory::getLoader(); |
|
| 235 | - } |
|
| 236 | - return $this->loader; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Method that's fired on admin requests (including admin ajax) but only when the models are usable |
|
| 242 | - * (ie, the site isn't in maintenance mode) |
|
| 243 | - * @since 4.9.63.p |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - protected function initModelsReady() |
|
| 247 | - { |
|
| 248 | - // ok so we want to enable the entire admin |
|
| 249 | - $this->persistent_admin_notice_manager = $this->getLoader()->getShared( |
|
| 250 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 251 | - ); |
|
| 252 | - $this->persistent_admin_notice_manager->setReturnUrl( |
|
| 253 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 254 | - array( |
|
| 255 | - 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
| 256 | - 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
| 257 | - ), |
|
| 258 | - EE_ADMIN_URL |
|
| 259 | - ) |
|
| 260 | - ); |
|
| 261 | - $this->maybeSetDatetimeWarningNotice(); |
|
| 262 | - // at a glance dashboard widget |
|
| 263 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 264 | - // filter for get_edit_post_link used on comments for custom post types |
|
| 265 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * get_persistent_admin_notices |
|
| 271 | - * |
|
| 272 | - * @access public |
|
| 273 | - * @return void |
|
| 274 | - * @throws EE_Error |
|
| 275 | - * @throws InvalidArgumentException |
|
| 276 | - * @throws InvalidDataTypeException |
|
| 277 | - * @throws InvalidInterfaceException |
|
| 278 | - */ |
|
| 279 | - public function maybeSetDatetimeWarningNotice() |
|
| 280 | - { |
|
| 281 | - // add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 282 | - // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 283 | - // with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 284 | - // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 285 | - if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
| 286 | - && ! get_option('timezone_string') |
|
| 287 | - && EEM_Event::instance()->count() > 0 |
|
| 288 | - ) { |
|
| 289 | - new PersistentAdminNotice( |
|
| 290 | - 'datetime_fix_notice', |
|
| 291 | - sprintf( |
|
| 292 | - esc_html__( |
|
| 293 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 294 | - 'event_espresso' |
|
| 295 | - ), |
|
| 296 | - '<strong>', |
|
| 297 | - '</strong>', |
|
| 298 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 299 | - '</a>', |
|
| 300 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 301 | - array( |
|
| 302 | - 'page' => 'espresso_maintenance_settings', |
|
| 303 | - 'action' => 'datetime_tools', |
|
| 304 | - ), |
|
| 305 | - admin_url('admin.php') |
|
| 306 | - ) . '">' |
|
| 307 | - ), |
|
| 308 | - false, |
|
| 309 | - 'manage_options', |
|
| 310 | - 'datetime_fix_persistent_notice' |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 318 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 319 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 320 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 321 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 322 | - * |
|
| 323 | - * @param WP_Post $post_type WP post type object |
|
| 324 | - * @return WP_Post |
|
| 325 | - * @throws InvalidArgumentException |
|
| 326 | - * @throws InvalidDataTypeException |
|
| 327 | - * @throws InvalidInterfaceException |
|
| 328 | - */ |
|
| 329 | - public function remove_pages_from_nav_menu($post_type) |
|
| 330 | - { |
|
| 331 | - // if this isn't the "pages" post type let's get out |
|
| 332 | - if ($post_type->name !== 'page') { |
|
| 333 | - return $post_type; |
|
| 334 | - } |
|
| 335 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 336 | - $post_type->_default_query = array( |
|
| 337 | - 'post__not_in' => $critical_pages, |
|
| 338 | - ); |
|
| 339 | - return $post_type; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 345 | - * metaboxes get shown as well |
|
| 346 | - * |
|
| 347 | - * @return void |
|
| 348 | - */ |
|
| 349 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 350 | - { |
|
| 351 | - global $wp_meta_boxes, $pagenow; |
|
| 352 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 353 | - return; |
|
| 354 | - } |
|
| 355 | - $user = wp_get_current_user(); |
|
| 356 | - // has this been done yet? |
|
| 357 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 358 | - return; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 362 | - $initial_meta_boxes = apply_filters( |
|
| 363 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 364 | - array( |
|
| 365 | - 'nav-menu-theme-locations', |
|
| 366 | - 'add-page', |
|
| 367 | - 'add-custom-links', |
|
| 368 | - 'add-category', |
|
| 369 | - 'add-espresso_events', |
|
| 370 | - 'add-espresso_venues', |
|
| 371 | - 'add-espresso_event_categories', |
|
| 372 | - 'add-espresso_venue_categories', |
|
| 373 | - 'add-post-type-post', |
|
| 374 | - 'add-post-type-page', |
|
| 375 | - ) |
|
| 376 | - ); |
|
| 377 | - |
|
| 378 | - if (is_array($hidden_meta_boxes)) { |
|
| 379 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 380 | - if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
| 381 | - unset($hidden_meta_boxes[ $key ]); |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 386 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 392 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 393 | - * |
|
| 394 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 395 | - * addons etc. |
|
| 396 | - * @return void |
|
| 397 | - */ |
|
| 398 | - public function register_custom_nav_menu_boxes() |
|
| 399 | - { |
|
| 400 | - add_meta_box( |
|
| 401 | - 'add-extra-nav-menu-pages', |
|
| 402 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 403 | - array($this, 'ee_cpt_archive_pages'), |
|
| 404 | - 'nav-menus', |
|
| 405 | - 'side', |
|
| 406 | - 'core' |
|
| 407 | - ); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 413 | - * |
|
| 414 | - * @since 4.3.0 |
|
| 415 | - * @param string $link the original link generated by wp |
|
| 416 | - * @param int $id post id |
|
| 417 | - * @return string the (maybe) modified link |
|
| 418 | - */ |
|
| 419 | - public function modify_edit_post_link($link, $id) |
|
| 420 | - { |
|
| 421 | - if (! $post = get_post($id)) { |
|
| 422 | - return $link; |
|
| 423 | - } |
|
| 424 | - if ($post->post_type === 'espresso_attendees') { |
|
| 425 | - $query_args = array( |
|
| 426 | - 'action' => 'edit_attendee', |
|
| 427 | - 'post' => $id, |
|
| 428 | - ); |
|
| 429 | - return EEH_URL::add_query_args_and_nonce( |
|
| 430 | - $query_args, |
|
| 431 | - admin_url('admin.php?page=espresso_registrations') |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return $link; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - public function ee_cpt_archive_pages() |
|
| 439 | - { |
|
| 440 | - global $nav_menu_selected_id; |
|
| 441 | - $db_fields = false; |
|
| 442 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 443 | - $current_tab = 'event-archives'; |
|
| 444 | - $removed_args = array( |
|
| 445 | - 'action', |
|
| 446 | - 'customlink-tab', |
|
| 447 | - 'edit-menu-item', |
|
| 448 | - 'menu-item', |
|
| 449 | - 'page-tab', |
|
| 450 | - '_wpnonce', |
|
| 451 | - ); |
|
| 452 | - ?> |
|
| 23 | + /** |
|
| 24 | + * @var EE_Admin $_instance |
|
| 25 | + */ |
|
| 26 | + private static $_instance; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
| 30 | + */ |
|
| 31 | + private $persistent_admin_notice_manager; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var LoaderInterface |
|
| 35 | + */ |
|
| 36 | + protected $loader; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @singleton method used to instantiate class object |
|
| 40 | + * @return EE_Admin |
|
| 41 | + * @throws EE_Error |
|
| 42 | + */ |
|
| 43 | + public static function instance() |
|
| 44 | + { |
|
| 45 | + // check if class object is instantiated |
|
| 46 | + if (! self::$_instance instanceof EE_Admin) { |
|
| 47 | + self::$_instance = new self(); |
|
| 48 | + } |
|
| 49 | + return self::$_instance; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @return EE_Admin |
|
| 55 | + * @throws EE_Error |
|
| 56 | + */ |
|
| 57 | + public static function reset() |
|
| 58 | + { |
|
| 59 | + self::$_instance = null; |
|
| 60 | + return self::instance(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * class constructor |
|
| 66 | + * |
|
| 67 | + * @throws EE_Error |
|
| 68 | + * @throws InvalidDataTypeException |
|
| 69 | + * @throws InvalidInterfaceException |
|
| 70 | + * @throws InvalidArgumentException |
|
| 71 | + */ |
|
| 72 | + protected function __construct() |
|
| 73 | + { |
|
| 74 | + // define global EE_Admin constants |
|
| 75 | + $this->_define_all_constants(); |
|
| 76 | + // set autoloaders for our admin page classes based on included path information |
|
| 77 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 78 | + // admin hooks |
|
| 79 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 80 | + // load EE_Request_Handler early |
|
| 81 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 82 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 83 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 84 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 85 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 86 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 87 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 88 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 89 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 90 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 91 | + add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage')); |
|
| 92 | + add_action('display_post_states', array($this, 'displayStateForCriticalPages'), 10, 2); |
|
| 93 | + add_filter('plugin_row_meta', array($this, 'addLinksToPluginRowMeta'), 10, 2); |
|
| 94 | + // reset Environment config (we only do this on admin page loads); |
|
| 95 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 96 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * _define_all_constants |
|
| 102 | + * define constants that are set globally for all admin pages |
|
| 103 | + * |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + private function _define_all_constants() |
|
| 107 | + { |
|
| 108 | + if (! defined('EE_ADMIN_URL')) { |
|
| 109 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 110 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 111 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/'); |
|
| 112 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 113 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
| 120 | + * |
|
| 121 | + * @param array $links |
|
| 122 | + * @param string $plugin |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function filter_plugin_actions($links, $plugin) |
|
| 126 | + { |
|
| 127 | + // set $main_file in stone |
|
| 128 | + static $main_file; |
|
| 129 | + // if $main_file is not set yet |
|
| 130 | + if (! $main_file) { |
|
| 131 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 132 | + } |
|
| 133 | + if ($plugin === $main_file) { |
|
| 134 | + // compare current plugin to this one |
|
| 135 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 136 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 137 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 138 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 139 | + . '</a>'; |
|
| 140 | + array_unshift($links, $maintenance_link); |
|
| 141 | + } else { |
|
| 142 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 143 | + . esc_html__('Settings', 'event_espresso') |
|
| 144 | + . '</a>'; |
|
| 145 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 146 | + . esc_html__('Events', 'event_espresso') |
|
| 147 | + . '</a>'; |
|
| 148 | + // add before other links |
|
| 149 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + return $links; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * _get_request |
|
| 158 | + * |
|
| 159 | + * @return void |
|
| 160 | + * @throws EE_Error |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + * @throws ReflectionException |
|
| 165 | + */ |
|
| 166 | + public function get_request() |
|
| 167 | + { |
|
| 168 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * hide_admin_pages_except_maintenance_mode |
|
| 174 | + * |
|
| 175 | + * @param array $admin_page_folder_names |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 179 | + { |
|
| 180 | + return array( |
|
| 181 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance/', |
|
| 182 | + 'about' => EE_ADMIN_PAGES . 'about/', |
|
| 183 | + 'support' => EE_ADMIN_PAGES . 'support/', |
|
| 184 | + ); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 190 | + * EE_Front_Controller's init phases have run |
|
| 191 | + * |
|
| 192 | + * @return void |
|
| 193 | + * @throws EE_Error |
|
| 194 | + * @throws InvalidArgumentException |
|
| 195 | + * @throws InvalidDataTypeException |
|
| 196 | + * @throws InvalidInterfaceException |
|
| 197 | + * @throws ReflectionException |
|
| 198 | + * @throws ServiceNotFoundException |
|
| 199 | + */ |
|
| 200 | + public function init() |
|
| 201 | + { |
|
| 202 | + // only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 203 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 204 | + $this->initModelsReady(); |
|
| 205 | + } |
|
| 206 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 207 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 208 | + try { |
|
| 209 | + // this loads the controller for the admin pages which will setup routing etc |
|
| 210 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 211 | + } catch (EE_Error $e) { |
|
| 212 | + $e->get_error(); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 216 | + // make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 217 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 218 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 219 | + // exclude EE critical pages from all nav menus and wp_list_pages |
|
| 220 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Gets the loader (and if it wasn't previously set, sets it) |
|
| 226 | + * @return LoaderInterface |
|
| 227 | + * @throws InvalidArgumentException |
|
| 228 | + * @throws InvalidDataTypeException |
|
| 229 | + * @throws InvalidInterfaceException |
|
| 230 | + */ |
|
| 231 | + protected function getLoader() |
|
| 232 | + { |
|
| 233 | + if (! $this->loader instanceof LoaderInterface) { |
|
| 234 | + $this->loader = LoaderFactory::getLoader(); |
|
| 235 | + } |
|
| 236 | + return $this->loader; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Method that's fired on admin requests (including admin ajax) but only when the models are usable |
|
| 242 | + * (ie, the site isn't in maintenance mode) |
|
| 243 | + * @since 4.9.63.p |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + protected function initModelsReady() |
|
| 247 | + { |
|
| 248 | + // ok so we want to enable the entire admin |
|
| 249 | + $this->persistent_admin_notice_manager = $this->getLoader()->getShared( |
|
| 250 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 251 | + ); |
|
| 252 | + $this->persistent_admin_notice_manager->setReturnUrl( |
|
| 253 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 254 | + array( |
|
| 255 | + 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
| 256 | + 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
| 257 | + ), |
|
| 258 | + EE_ADMIN_URL |
|
| 259 | + ) |
|
| 260 | + ); |
|
| 261 | + $this->maybeSetDatetimeWarningNotice(); |
|
| 262 | + // at a glance dashboard widget |
|
| 263 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 264 | + // filter for get_edit_post_link used on comments for custom post types |
|
| 265 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * get_persistent_admin_notices |
|
| 271 | + * |
|
| 272 | + * @access public |
|
| 273 | + * @return void |
|
| 274 | + * @throws EE_Error |
|
| 275 | + * @throws InvalidArgumentException |
|
| 276 | + * @throws InvalidDataTypeException |
|
| 277 | + * @throws InvalidInterfaceException |
|
| 278 | + */ |
|
| 279 | + public function maybeSetDatetimeWarningNotice() |
|
| 280 | + { |
|
| 281 | + // add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 282 | + // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 283 | + // with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 284 | + // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 285 | + if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
| 286 | + && ! get_option('timezone_string') |
|
| 287 | + && EEM_Event::instance()->count() > 0 |
|
| 288 | + ) { |
|
| 289 | + new PersistentAdminNotice( |
|
| 290 | + 'datetime_fix_notice', |
|
| 291 | + sprintf( |
|
| 292 | + esc_html__( |
|
| 293 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 294 | + 'event_espresso' |
|
| 295 | + ), |
|
| 296 | + '<strong>', |
|
| 297 | + '</strong>', |
|
| 298 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 299 | + '</a>', |
|
| 300 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 301 | + array( |
|
| 302 | + 'page' => 'espresso_maintenance_settings', |
|
| 303 | + 'action' => 'datetime_tools', |
|
| 304 | + ), |
|
| 305 | + admin_url('admin.php') |
|
| 306 | + ) . '">' |
|
| 307 | + ), |
|
| 308 | + false, |
|
| 309 | + 'manage_options', |
|
| 310 | + 'datetime_fix_persistent_notice' |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 318 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 319 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 320 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 321 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 322 | + * |
|
| 323 | + * @param WP_Post $post_type WP post type object |
|
| 324 | + * @return WP_Post |
|
| 325 | + * @throws InvalidArgumentException |
|
| 326 | + * @throws InvalidDataTypeException |
|
| 327 | + * @throws InvalidInterfaceException |
|
| 328 | + */ |
|
| 329 | + public function remove_pages_from_nav_menu($post_type) |
|
| 330 | + { |
|
| 331 | + // if this isn't the "pages" post type let's get out |
|
| 332 | + if ($post_type->name !== 'page') { |
|
| 333 | + return $post_type; |
|
| 334 | + } |
|
| 335 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 336 | + $post_type->_default_query = array( |
|
| 337 | + 'post__not_in' => $critical_pages, |
|
| 338 | + ); |
|
| 339 | + return $post_type; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 345 | + * metaboxes get shown as well |
|
| 346 | + * |
|
| 347 | + * @return void |
|
| 348 | + */ |
|
| 349 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 350 | + { |
|
| 351 | + global $wp_meta_boxes, $pagenow; |
|
| 352 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 353 | + return; |
|
| 354 | + } |
|
| 355 | + $user = wp_get_current_user(); |
|
| 356 | + // has this been done yet? |
|
| 357 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 358 | + return; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 362 | + $initial_meta_boxes = apply_filters( |
|
| 363 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 364 | + array( |
|
| 365 | + 'nav-menu-theme-locations', |
|
| 366 | + 'add-page', |
|
| 367 | + 'add-custom-links', |
|
| 368 | + 'add-category', |
|
| 369 | + 'add-espresso_events', |
|
| 370 | + 'add-espresso_venues', |
|
| 371 | + 'add-espresso_event_categories', |
|
| 372 | + 'add-espresso_venue_categories', |
|
| 373 | + 'add-post-type-post', |
|
| 374 | + 'add-post-type-page', |
|
| 375 | + ) |
|
| 376 | + ); |
|
| 377 | + |
|
| 378 | + if (is_array($hidden_meta_boxes)) { |
|
| 379 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 380 | + if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
| 381 | + unset($hidden_meta_boxes[ $key ]); |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 386 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 392 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 393 | + * |
|
| 394 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 395 | + * addons etc. |
|
| 396 | + * @return void |
|
| 397 | + */ |
|
| 398 | + public function register_custom_nav_menu_boxes() |
|
| 399 | + { |
|
| 400 | + add_meta_box( |
|
| 401 | + 'add-extra-nav-menu-pages', |
|
| 402 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 403 | + array($this, 'ee_cpt_archive_pages'), |
|
| 404 | + 'nav-menus', |
|
| 405 | + 'side', |
|
| 406 | + 'core' |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 413 | + * |
|
| 414 | + * @since 4.3.0 |
|
| 415 | + * @param string $link the original link generated by wp |
|
| 416 | + * @param int $id post id |
|
| 417 | + * @return string the (maybe) modified link |
|
| 418 | + */ |
|
| 419 | + public function modify_edit_post_link($link, $id) |
|
| 420 | + { |
|
| 421 | + if (! $post = get_post($id)) { |
|
| 422 | + return $link; |
|
| 423 | + } |
|
| 424 | + if ($post->post_type === 'espresso_attendees') { |
|
| 425 | + $query_args = array( |
|
| 426 | + 'action' => 'edit_attendee', |
|
| 427 | + 'post' => $id, |
|
| 428 | + ); |
|
| 429 | + return EEH_URL::add_query_args_and_nonce( |
|
| 430 | + $query_args, |
|
| 431 | + admin_url('admin.php?page=espresso_registrations') |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return $link; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + public function ee_cpt_archive_pages() |
|
| 439 | + { |
|
| 440 | + global $nav_menu_selected_id; |
|
| 441 | + $db_fields = false; |
|
| 442 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 443 | + $current_tab = 'event-archives'; |
|
| 444 | + $removed_args = array( |
|
| 445 | + 'action', |
|
| 446 | + 'customlink-tab', |
|
| 447 | + 'edit-menu-item', |
|
| 448 | + 'menu-item', |
|
| 449 | + 'page-tab', |
|
| 450 | + '_wpnonce', |
|
| 451 | + ); |
|
| 452 | + ?> |
|
| 453 | 453 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 454 | 454 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 455 | 455 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
| 456 | 456 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
| 457 | 457 | href="<?php |
| 458 | - if ($nav_menu_selected_id) { |
|
| 459 | - echo esc_url( |
|
| 460 | - add_query_arg( |
|
| 461 | - 'extra-nav-menu-pages-tab', |
|
| 462 | - 'event-archives', |
|
| 463 | - remove_query_arg($removed_args) |
|
| 464 | - ) |
|
| 465 | - ); |
|
| 466 | - } |
|
| 467 | - ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 458 | + if ($nav_menu_selected_id) { |
|
| 459 | + echo esc_url( |
|
| 460 | + add_query_arg( |
|
| 461 | + 'extra-nav-menu-pages-tab', |
|
| 462 | + 'event-archives', |
|
| 463 | + remove_query_arg($removed_args) |
|
| 464 | + ) |
|
| 465 | + ); |
|
| 466 | + } |
|
| 467 | + ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 468 | 468 | <?php esc_html_e('Event Archive Pages', 'event_espresso'); ?> |
| 469 | 469 | </a> |
| 470 | 470 | </li> |
| 471 | 471 | </ul><!-- .posttype-tabs --> |
| 472 | 472 | |
| 473 | 473 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 474 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 475 | - ?>"> |
|
| 474 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 475 | + ?>"> |
|
| 476 | 476 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 477 | 477 | <?php |
| 478 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 479 | - $args['walker'] = $walker; |
|
| 480 | - echo walk_nav_menu_tree( |
|
| 481 | - array_map( |
|
| 482 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 483 | - $pages |
|
| 484 | - ), |
|
| 485 | - 0, |
|
| 486 | - (object) $args |
|
| 487 | - ); |
|
| 488 | - ?> |
|
| 478 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 479 | + $args['walker'] = $walker; |
|
| 480 | + echo walk_nav_menu_tree( |
|
| 481 | + array_map( |
|
| 482 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 483 | + $pages |
|
| 484 | + ), |
|
| 485 | + 0, |
|
| 486 | + (object) $args |
|
| 487 | + ); |
|
| 488 | + ?> |
|
| 489 | 489 | </ul> |
| 490 | 490 | </div><!-- /.tabs-panel --> |
| 491 | 491 | |
| 492 | 492 | <p class="button-controls"> |
| 493 | 493 | <span class="list-controls"> |
| 494 | 494 | <a href="<?php |
| 495 | - echo esc_url( |
|
| 496 | - add_query_arg( |
|
| 497 | - array( |
|
| 498 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 499 | - 'selectall' => 1, |
|
| 500 | - ), |
|
| 501 | - remove_query_arg($removed_args) |
|
| 502 | - ) |
|
| 503 | - ); |
|
| 504 | - ?>#posttype-extra-nav-menu-pages" class="select-all"><?php esc_html_e('Select All', 'event_espresso'); ?></a> |
|
| 495 | + echo esc_url( |
|
| 496 | + add_query_arg( |
|
| 497 | + array( |
|
| 498 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 499 | + 'selectall' => 1, |
|
| 500 | + ), |
|
| 501 | + remove_query_arg($removed_args) |
|
| 502 | + ) |
|
| 503 | + ); |
|
| 504 | + ?>#posttype-extra-nav-menu-pages" class="select-all"><?php esc_html_e('Select All', 'event_espresso'); ?></a> |
|
| 505 | 505 | </span> |
| 506 | 506 | <span class="add-to-menu"> |
| 507 | 507 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -514,566 +514,566 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | </div><!-- /.posttypediv --> |
| 516 | 516 | <?php |
| 517 | - } |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Returns an array of event archive nav items. |
|
| 522 | - * |
|
| 523 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 524 | - * method we use for getting the extra nav menu items |
|
| 525 | - * @return array |
|
| 526 | - */ |
|
| 527 | - private function _get_extra_nav_menu_pages_items() |
|
| 528 | - { |
|
| 529 | - $menuitems[] = array( |
|
| 530 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 531 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
| 532 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 533 | - ); |
|
| 534 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 540 | - * the properties and converts it to the menu item object. |
|
| 541 | - * |
|
| 542 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 543 | - * @param $menu_item_values |
|
| 544 | - * @return stdClass |
|
| 545 | - */ |
|
| 546 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 547 | - { |
|
| 548 | - $menu_item = new stdClass(); |
|
| 549 | - $keys = array( |
|
| 550 | - 'ID' => 0, |
|
| 551 | - 'db_id' => 0, |
|
| 552 | - 'menu_item_parent' => 0, |
|
| 553 | - 'object_id' => -1, |
|
| 554 | - 'post_parent' => 0, |
|
| 555 | - 'type' => 'custom', |
|
| 556 | - 'object' => '', |
|
| 557 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 558 | - 'title' => '', |
|
| 559 | - 'url' => '', |
|
| 560 | - 'target' => '', |
|
| 561 | - 'attr_title' => '', |
|
| 562 | - 'description' => '', |
|
| 563 | - 'classes' => array(), |
|
| 564 | - 'xfn' => '', |
|
| 565 | - ); |
|
| 566 | - |
|
| 567 | - foreach ($keys as $key => $value) { |
|
| 568 | - $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value; |
|
| 569 | - } |
|
| 570 | - return $menu_item; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 576 | - * EE_Admin_Page route is called. |
|
| 577 | - * |
|
| 578 | - * @return void |
|
| 579 | - */ |
|
| 580 | - public function route_admin_request() |
|
| 581 | - { |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 587 | - * |
|
| 588 | - * @return void |
|
| 589 | - */ |
|
| 590 | - public function wp_loaded() |
|
| 591 | - { |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * admin_init |
|
| 597 | - * |
|
| 598 | - * @return void |
|
| 599 | - * @throws EE_Error |
|
| 600 | - * @throws InvalidArgumentException |
|
| 601 | - * @throws InvalidDataTypeException |
|
| 602 | - * @throws InvalidInterfaceException |
|
| 603 | - * @throws ReflectionException |
|
| 604 | - */ |
|
| 605 | - public function admin_init() |
|
| 606 | - { |
|
| 607 | - /** |
|
| 608 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 609 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 610 | - * - check if doing post processing. |
|
| 611 | - * - check if doing post processing of one of EE CPTs |
|
| 612 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 613 | - */ |
|
| 614 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 615 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 616 | - $custom_post_types = $this->getLoader()->getShared( |
|
| 617 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 618 | - ); |
|
| 619 | - $custom_post_types->getCustomPostTypeModels($_POST['post_type']); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 625 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 626 | - * Pages" tab in the EE General Settings Admin page. |
|
| 627 | - * This is for user-proofing. |
|
| 628 | - */ |
|
| 629 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 630 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 631 | - $this->adminInitModelsReady(); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode) |
|
| 638 | - */ |
|
| 639 | - protected function adminInitModelsReady() |
|
| 640 | - { |
|
| 641 | - if (function_exists('wp_add_privacy_policy_content')) { |
|
| 642 | - $this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager'); |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 649 | - * |
|
| 650 | - * @param string $output Current output. |
|
| 651 | - * @return string |
|
| 652 | - * @throws InvalidArgumentException |
|
| 653 | - * @throws InvalidDataTypeException |
|
| 654 | - * @throws InvalidInterfaceException |
|
| 655 | - */ |
|
| 656 | - public function modify_dropdown_pages($output) |
|
| 657 | - { |
|
| 658 | - // get critical pages |
|
| 659 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 660 | - |
|
| 661 | - // split current output by line break for easier parsing. |
|
| 662 | - $split_output = explode("\n", $output); |
|
| 663 | - |
|
| 664 | - // loop through to remove any critical pages from the array. |
|
| 665 | - foreach ($critical_pages as $page_id) { |
|
| 666 | - $needle = 'value="' . $page_id . '"'; |
|
| 667 | - foreach ($split_output as $key => $haystack) { |
|
| 668 | - if (strpos($haystack, $needle) !== false) { |
|
| 669 | - unset($split_output[ $key ]); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - // replace output with the new contents |
|
| 674 | - return implode("\n", $split_output); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * enqueue all admin scripts that need loaded for admin pages |
|
| 680 | - * |
|
| 681 | - * @return void |
|
| 682 | - */ |
|
| 683 | - public function enqueue_admin_scripts() |
|
| 684 | - { |
|
| 685 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 686 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 687 | - // calls. |
|
| 688 | - wp_enqueue_script( |
|
| 689 | - 'ee-inject-wp', |
|
| 690 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 691 | - array('jquery'), |
|
| 692 | - EVENT_ESPRESSO_VERSION, |
|
| 693 | - true |
|
| 694 | - ); |
|
| 695 | - // register cookie script for future dependencies |
|
| 696 | - wp_register_script( |
|
| 697 | - 'jquery-cookie', |
|
| 698 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 699 | - array('jquery'), |
|
| 700 | - '2.1', |
|
| 701 | - true |
|
| 702 | - ); |
|
| 703 | - // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 704 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 705 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
| 706 | - // joyride style |
|
| 707 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 708 | - wp_register_style( |
|
| 709 | - 'ee-joyride-css', |
|
| 710 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 711 | - array('joyride-css'), |
|
| 712 | - EVENT_ESPRESSO_VERSION |
|
| 713 | - ); |
|
| 714 | - wp_register_script( |
|
| 715 | - 'joyride-modernizr', |
|
| 716 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 717 | - array(), |
|
| 718 | - '2.1', |
|
| 719 | - true |
|
| 720 | - ); |
|
| 721 | - // joyride JS |
|
| 722 | - wp_register_script( |
|
| 723 | - 'jquery-joyride', |
|
| 724 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 725 | - array('jquery-cookie', 'joyride-modernizr'), |
|
| 726 | - '2.1', |
|
| 727 | - true |
|
| 728 | - ); |
|
| 729 | - // wanna go for a joyride? |
|
| 730 | - wp_enqueue_style('ee-joyride-css'); |
|
| 731 | - wp_enqueue_script('jquery-joyride'); |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * display_admin_notices |
|
| 738 | - * |
|
| 739 | - * @return void |
|
| 740 | - */ |
|
| 741 | - public function display_admin_notices() |
|
| 742 | - { |
|
| 743 | - echo EE_Error::get_notices(); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * @param array $elements |
|
| 749 | - * @return array |
|
| 750 | - * @throws EE_Error |
|
| 751 | - * @throws InvalidArgumentException |
|
| 752 | - * @throws InvalidDataTypeException |
|
| 753 | - * @throws InvalidInterfaceException |
|
| 754 | - */ |
|
| 755 | - public function dashboard_glance_items($elements) |
|
| 756 | - { |
|
| 757 | - $elements = is_array($elements) ? $elements : array($elements); |
|
| 758 | - $events = EEM_Event::instance()->count(); |
|
| 759 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 760 | - array('page' => 'espresso_events'), |
|
| 761 | - admin_url('admin.php') |
|
| 762 | - ); |
|
| 763 | - $items['events']['text'] = sprintf( |
|
| 764 | - esc_html( |
|
| 765 | - _n('%s Event', '%s Events', $events, 'event_espresso') |
|
| 766 | - ), |
|
| 767 | - number_format_i18n($events) |
|
| 768 | - ); |
|
| 769 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 770 | - $registrations = EEM_Registration::instance()->count( |
|
| 771 | - array( |
|
| 772 | - array( |
|
| 773 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 774 | - ), |
|
| 775 | - ) |
|
| 776 | - ); |
|
| 777 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | - array('page' => 'espresso_registrations'), |
|
| 779 | - admin_url('admin.php') |
|
| 780 | - ); |
|
| 781 | - $items['registrations']['text'] = sprintf( |
|
| 782 | - esc_html( |
|
| 783 | - _n('%s Registration', '%s Registrations', $registrations, 'event_espresso') |
|
| 784 | - ), |
|
| 785 | - number_format_i18n($registrations) |
|
| 786 | - ); |
|
| 787 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 788 | - |
|
| 789 | - $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 790 | - |
|
| 791 | - foreach ($items as $type => $item_properties) { |
|
| 792 | - $elements[] = sprintf( |
|
| 793 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 794 | - $item_properties['url'], |
|
| 795 | - $item_properties['title'], |
|
| 796 | - $item_properties['text'] |
|
| 797 | - ); |
|
| 798 | - } |
|
| 799 | - return $elements; |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * check_for_invalid_datetime_formats |
|
| 805 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 806 | - * their selected format can be parsed by PHP |
|
| 807 | - * |
|
| 808 | - * @param $value |
|
| 809 | - * @param $option |
|
| 810 | - * @throws EE_Error |
|
| 811 | - * @return string |
|
| 812 | - */ |
|
| 813 | - public function check_for_invalid_datetime_formats($value, $option) |
|
| 814 | - { |
|
| 815 | - // check for date_format or time_format |
|
| 816 | - switch ($option) { |
|
| 817 | - case 'date_format': |
|
| 818 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 819 | - break; |
|
| 820 | - case 'time_format': |
|
| 821 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 822 | - break; |
|
| 823 | - default: |
|
| 824 | - $date_time_format = false; |
|
| 825 | - } |
|
| 826 | - // do we have a date_time format to check ? |
|
| 827 | - if ($date_time_format) { |
|
| 828 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 829 | - |
|
| 830 | - if (is_array($error_msg)) { |
|
| 831 | - $msg = '<p>' |
|
| 832 | - . sprintf( |
|
| 833 | - esc_html__( |
|
| 834 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 835 | - 'event_espresso' |
|
| 836 | - ), |
|
| 837 | - date($date_time_format), |
|
| 838 | - $date_time_format |
|
| 839 | - ) |
|
| 840 | - . '</p><p><ul>'; |
|
| 841 | - |
|
| 842 | - |
|
| 843 | - foreach ($error_msg as $error) { |
|
| 844 | - $msg .= '<li>' . $error . '</li>'; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - $msg .= '</ul></p><p>' |
|
| 848 | - . sprintf( |
|
| 849 | - esc_html__( |
|
| 850 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ), |
|
| 853 | - '<span style="color:#D54E21;">', |
|
| 854 | - '</span>' |
|
| 855 | - ) |
|
| 856 | - . '</p>'; |
|
| 857 | - |
|
| 858 | - // trigger WP settings error |
|
| 859 | - add_settings_error( |
|
| 860 | - 'date_format', |
|
| 861 | - 'date_format', |
|
| 862 | - $msg |
|
| 863 | - ); |
|
| 864 | - |
|
| 865 | - // set format to something valid |
|
| 866 | - switch ($option) { |
|
| 867 | - case 'date_format': |
|
| 868 | - $value = 'F j, Y'; |
|
| 869 | - break; |
|
| 870 | - case 'time_format': |
|
| 871 | - $value = 'g:i a'; |
|
| 872 | - break; |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - } |
|
| 876 | - return $value; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 882 | - * |
|
| 883 | - * @param $content |
|
| 884 | - * @return string |
|
| 885 | - */ |
|
| 886 | - public function its_eSpresso($content) |
|
| 887 | - { |
|
| 888 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * espresso_admin_footer |
|
| 894 | - * |
|
| 895 | - * @return string |
|
| 896 | - */ |
|
| 897 | - public function espresso_admin_footer() |
|
| 898 | - { |
|
| 899 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * static method for registering ee admin page. |
|
| 905 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 906 | - * |
|
| 907 | - * @since 4.3.0 |
|
| 908 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 909 | - * @see EE_Register_Admin_Page::register() |
|
| 910 | - * @param $page_basename |
|
| 911 | - * @param $page_path |
|
| 912 | - * @param array $config |
|
| 913 | - * @return void |
|
| 914 | - * @throws EE_Error |
|
| 915 | - */ |
|
| 916 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 917 | - { |
|
| 918 | - EE_Error::doing_it_wrong( |
|
| 919 | - __METHOD__, |
|
| 920 | - sprintf( |
|
| 921 | - esc_html__( |
|
| 922 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 923 | - 'event_espresso' |
|
| 924 | - ), |
|
| 925 | - $page_basename |
|
| 926 | - ), |
|
| 927 | - '4.3' |
|
| 928 | - ); |
|
| 929 | - if (class_exists('EE_Register_Admin_Page')) { |
|
| 930 | - $config['page_path'] = $page_path; |
|
| 931 | - } |
|
| 932 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - /** |
|
| 937 | - * @deprecated 4.8.41 |
|
| 938 | - * @param int $post_ID |
|
| 939 | - * @param \WP_Post $post |
|
| 940 | - * @return void |
|
| 941 | - */ |
|
| 942 | - public static function parse_post_content_on_save($post_ID, $post) |
|
| 943 | - { |
|
| 944 | - EE_Error::doing_it_wrong( |
|
| 945 | - __METHOD__, |
|
| 946 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 947 | - '4.8.41' |
|
| 948 | - ); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * @deprecated 4.8.41 |
|
| 954 | - * @param $option |
|
| 955 | - * @param $old_value |
|
| 956 | - * @param $value |
|
| 957 | - * @return void |
|
| 958 | - */ |
|
| 959 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 960 | - { |
|
| 961 | - EE_Error::doing_it_wrong( |
|
| 962 | - __METHOD__, |
|
| 963 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 964 | - '4.8.41' |
|
| 965 | - ); |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * @deprecated 4.9.27 |
|
| 971 | - * @return void |
|
| 972 | - */ |
|
| 973 | - public function get_persistent_admin_notices() |
|
| 974 | - { |
|
| 975 | - EE_Error::doing_it_wrong( |
|
| 976 | - __METHOD__, |
|
| 977 | - sprintf( |
|
| 978 | - esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 979 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 980 | - ), |
|
| 981 | - '4.9.27' |
|
| 982 | - ); |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - |
|
| 986 | - /** |
|
| 987 | - * @deprecated 4.9.27 |
|
| 988 | - * @throws InvalidInterfaceException |
|
| 989 | - * @throws InvalidDataTypeException |
|
| 990 | - * @throws DomainException |
|
| 991 | - */ |
|
| 992 | - public function dismiss_ee_nag_notice_callback() |
|
| 993 | - { |
|
| 994 | - EE_Error::doing_it_wrong( |
|
| 995 | - __METHOD__, |
|
| 996 | - sprintf( |
|
| 997 | - esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 998 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 999 | - ), |
|
| 1000 | - '4.9.27' |
|
| 1001 | - ); |
|
| 1002 | - $this->persistent_admin_notice_manager->dismissNotice(); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page. |
|
| 1008 | - * |
|
| 1009 | - * @throws InvalidArgumentException |
|
| 1010 | - * @throws InvalidDataTypeException |
|
| 1011 | - * @throws InvalidInterfaceException |
|
| 1012 | - */ |
|
| 1013 | - public function hookIntoWpPluginsPage() |
|
| 1014 | - { |
|
| 1015 | - $this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal'); |
|
| 1016 | - $this->getLoader() |
|
| 1017 | - ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells') |
|
| 1018 | - ->decafUpsells(); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * Hooks into the "post states" filter in a wp post type list table. |
|
| 1024 | - * |
|
| 1025 | - * @param array $post_states |
|
| 1026 | - * @param WP_Post $post |
|
| 1027 | - * @return array |
|
| 1028 | - * @throws InvalidArgumentException |
|
| 1029 | - * @throws InvalidDataTypeException |
|
| 1030 | - * @throws InvalidInterfaceException |
|
| 1031 | - */ |
|
| 1032 | - public function displayStateForCriticalPages($post_states, $post) |
|
| 1033 | - { |
|
| 1034 | - $post_states = (array) $post_states; |
|
| 1035 | - if (! $post instanceof WP_Post || $post->post_type !== 'page') { |
|
| 1036 | - return $post_states; |
|
| 1037 | - } |
|
| 1038 | - /** @var EE_Core_Config $config */ |
|
| 1039 | - $config = $this->getLoader()->getShared('EE_Config')->core; |
|
| 1040 | - if (in_array($post->ID, $config->get_critical_pages_array(), true)) { |
|
| 1041 | - $post_states[] = sprintf( |
|
| 1042 | - /* Translators: Using company name - Event Espresso Critical Page */ |
|
| 1043 | - esc_html__('%s Critical Page', 'event_espresso'), |
|
| 1044 | - 'Event Espresso' |
|
| 1045 | - ); |
|
| 1046 | - } |
|
| 1047 | - return $post_states; |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - |
|
| 1051 | - /** |
|
| 1052 | - * Show documentation links on the plugins page |
|
| 1053 | - * |
|
| 1054 | - * @param mixed $meta Plugin Row Meta |
|
| 1055 | - * @param mixed $file Plugin Base file |
|
| 1056 | - * @return array |
|
| 1057 | - */ |
|
| 1058 | - public function addLinksToPluginRowMeta($meta, $file) |
|
| 1059 | - { |
|
| 1060 | - if (EE_PLUGIN_BASENAME === $file) { |
|
| 1061 | - $row_meta = array( |
|
| 1062 | - 'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"' |
|
| 1063 | - . ' aria-label="' |
|
| 1064 | - . esc_attr__('View Event Espresso documentation', 'event_espresso') |
|
| 1065 | - . '">' |
|
| 1066 | - . esc_html__('Docs', 'event_espresso') |
|
| 1067 | - . '</a>', |
|
| 1068 | - 'api' => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"' |
|
| 1069 | - . ' aria-label="' |
|
| 1070 | - . esc_attr__('View Event Espresso API docs', 'event_espresso') |
|
| 1071 | - . '">' |
|
| 1072 | - . esc_html__('API docs', 'event_espresso') |
|
| 1073 | - . '</a>', |
|
| 1074 | - ); |
|
| 1075 | - return array_merge($meta, $row_meta); |
|
| 1076 | - } |
|
| 1077 | - return (array) $meta; |
|
| 1078 | - } |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Returns an array of event archive nav items. |
|
| 522 | + * |
|
| 523 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 524 | + * method we use for getting the extra nav menu items |
|
| 525 | + * @return array |
|
| 526 | + */ |
|
| 527 | + private function _get_extra_nav_menu_pages_items() |
|
| 528 | + { |
|
| 529 | + $menuitems[] = array( |
|
| 530 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 531 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 532 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 533 | + ); |
|
| 534 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 540 | + * the properties and converts it to the menu item object. |
|
| 541 | + * |
|
| 542 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 543 | + * @param $menu_item_values |
|
| 544 | + * @return stdClass |
|
| 545 | + */ |
|
| 546 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 547 | + { |
|
| 548 | + $menu_item = new stdClass(); |
|
| 549 | + $keys = array( |
|
| 550 | + 'ID' => 0, |
|
| 551 | + 'db_id' => 0, |
|
| 552 | + 'menu_item_parent' => 0, |
|
| 553 | + 'object_id' => -1, |
|
| 554 | + 'post_parent' => 0, |
|
| 555 | + 'type' => 'custom', |
|
| 556 | + 'object' => '', |
|
| 557 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 558 | + 'title' => '', |
|
| 559 | + 'url' => '', |
|
| 560 | + 'target' => '', |
|
| 561 | + 'attr_title' => '', |
|
| 562 | + 'description' => '', |
|
| 563 | + 'classes' => array(), |
|
| 564 | + 'xfn' => '', |
|
| 565 | + ); |
|
| 566 | + |
|
| 567 | + foreach ($keys as $key => $value) { |
|
| 568 | + $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value; |
|
| 569 | + } |
|
| 570 | + return $menu_item; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 576 | + * EE_Admin_Page route is called. |
|
| 577 | + * |
|
| 578 | + * @return void |
|
| 579 | + */ |
|
| 580 | + public function route_admin_request() |
|
| 581 | + { |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 587 | + * |
|
| 588 | + * @return void |
|
| 589 | + */ |
|
| 590 | + public function wp_loaded() |
|
| 591 | + { |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * admin_init |
|
| 597 | + * |
|
| 598 | + * @return void |
|
| 599 | + * @throws EE_Error |
|
| 600 | + * @throws InvalidArgumentException |
|
| 601 | + * @throws InvalidDataTypeException |
|
| 602 | + * @throws InvalidInterfaceException |
|
| 603 | + * @throws ReflectionException |
|
| 604 | + */ |
|
| 605 | + public function admin_init() |
|
| 606 | + { |
|
| 607 | + /** |
|
| 608 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 609 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 610 | + * - check if doing post processing. |
|
| 611 | + * - check if doing post processing of one of EE CPTs |
|
| 612 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 613 | + */ |
|
| 614 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 615 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 616 | + $custom_post_types = $this->getLoader()->getShared( |
|
| 617 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 618 | + ); |
|
| 619 | + $custom_post_types->getCustomPostTypeModels($_POST['post_type']); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 625 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 626 | + * Pages" tab in the EE General Settings Admin page. |
|
| 627 | + * This is for user-proofing. |
|
| 628 | + */ |
|
| 629 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 630 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 631 | + $this->adminInitModelsReady(); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Runs on admin_init but only if models are usable (ie, we're not in maintenanc emode) |
|
| 638 | + */ |
|
| 639 | + protected function adminInitModelsReady() |
|
| 640 | + { |
|
| 641 | + if (function_exists('wp_add_privacy_policy_content')) { |
|
| 642 | + $this->getLoader()->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager'); |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 649 | + * |
|
| 650 | + * @param string $output Current output. |
|
| 651 | + * @return string |
|
| 652 | + * @throws InvalidArgumentException |
|
| 653 | + * @throws InvalidDataTypeException |
|
| 654 | + * @throws InvalidInterfaceException |
|
| 655 | + */ |
|
| 656 | + public function modify_dropdown_pages($output) |
|
| 657 | + { |
|
| 658 | + // get critical pages |
|
| 659 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 660 | + |
|
| 661 | + // split current output by line break for easier parsing. |
|
| 662 | + $split_output = explode("\n", $output); |
|
| 663 | + |
|
| 664 | + // loop through to remove any critical pages from the array. |
|
| 665 | + foreach ($critical_pages as $page_id) { |
|
| 666 | + $needle = 'value="' . $page_id . '"'; |
|
| 667 | + foreach ($split_output as $key => $haystack) { |
|
| 668 | + if (strpos($haystack, $needle) !== false) { |
|
| 669 | + unset($split_output[ $key ]); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + // replace output with the new contents |
|
| 674 | + return implode("\n", $split_output); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * enqueue all admin scripts that need loaded for admin pages |
|
| 680 | + * |
|
| 681 | + * @return void |
|
| 682 | + */ |
|
| 683 | + public function enqueue_admin_scripts() |
|
| 684 | + { |
|
| 685 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 686 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 687 | + // calls. |
|
| 688 | + wp_enqueue_script( |
|
| 689 | + 'ee-inject-wp', |
|
| 690 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 691 | + array('jquery'), |
|
| 692 | + EVENT_ESPRESSO_VERSION, |
|
| 693 | + true |
|
| 694 | + ); |
|
| 695 | + // register cookie script for future dependencies |
|
| 696 | + wp_register_script( |
|
| 697 | + 'jquery-cookie', |
|
| 698 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 699 | + array('jquery'), |
|
| 700 | + '2.1', |
|
| 701 | + true |
|
| 702 | + ); |
|
| 703 | + // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 704 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 705 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
| 706 | + // joyride style |
|
| 707 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 708 | + wp_register_style( |
|
| 709 | + 'ee-joyride-css', |
|
| 710 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 711 | + array('joyride-css'), |
|
| 712 | + EVENT_ESPRESSO_VERSION |
|
| 713 | + ); |
|
| 714 | + wp_register_script( |
|
| 715 | + 'joyride-modernizr', |
|
| 716 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 717 | + array(), |
|
| 718 | + '2.1', |
|
| 719 | + true |
|
| 720 | + ); |
|
| 721 | + // joyride JS |
|
| 722 | + wp_register_script( |
|
| 723 | + 'jquery-joyride', |
|
| 724 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 725 | + array('jquery-cookie', 'joyride-modernizr'), |
|
| 726 | + '2.1', |
|
| 727 | + true |
|
| 728 | + ); |
|
| 729 | + // wanna go for a joyride? |
|
| 730 | + wp_enqueue_style('ee-joyride-css'); |
|
| 731 | + wp_enqueue_script('jquery-joyride'); |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * display_admin_notices |
|
| 738 | + * |
|
| 739 | + * @return void |
|
| 740 | + */ |
|
| 741 | + public function display_admin_notices() |
|
| 742 | + { |
|
| 743 | + echo EE_Error::get_notices(); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * @param array $elements |
|
| 749 | + * @return array |
|
| 750 | + * @throws EE_Error |
|
| 751 | + * @throws InvalidArgumentException |
|
| 752 | + * @throws InvalidDataTypeException |
|
| 753 | + * @throws InvalidInterfaceException |
|
| 754 | + */ |
|
| 755 | + public function dashboard_glance_items($elements) |
|
| 756 | + { |
|
| 757 | + $elements = is_array($elements) ? $elements : array($elements); |
|
| 758 | + $events = EEM_Event::instance()->count(); |
|
| 759 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 760 | + array('page' => 'espresso_events'), |
|
| 761 | + admin_url('admin.php') |
|
| 762 | + ); |
|
| 763 | + $items['events']['text'] = sprintf( |
|
| 764 | + esc_html( |
|
| 765 | + _n('%s Event', '%s Events', $events, 'event_espresso') |
|
| 766 | + ), |
|
| 767 | + number_format_i18n($events) |
|
| 768 | + ); |
|
| 769 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 770 | + $registrations = EEM_Registration::instance()->count( |
|
| 771 | + array( |
|
| 772 | + array( |
|
| 773 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 774 | + ), |
|
| 775 | + ) |
|
| 776 | + ); |
|
| 777 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | + array('page' => 'espresso_registrations'), |
|
| 779 | + admin_url('admin.php') |
|
| 780 | + ); |
|
| 781 | + $items['registrations']['text'] = sprintf( |
|
| 782 | + esc_html( |
|
| 783 | + _n('%s Registration', '%s Registrations', $registrations, 'event_espresso') |
|
| 784 | + ), |
|
| 785 | + number_format_i18n($registrations) |
|
| 786 | + ); |
|
| 787 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 788 | + |
|
| 789 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 790 | + |
|
| 791 | + foreach ($items as $type => $item_properties) { |
|
| 792 | + $elements[] = sprintf( |
|
| 793 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 794 | + $item_properties['url'], |
|
| 795 | + $item_properties['title'], |
|
| 796 | + $item_properties['text'] |
|
| 797 | + ); |
|
| 798 | + } |
|
| 799 | + return $elements; |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * check_for_invalid_datetime_formats |
|
| 805 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 806 | + * their selected format can be parsed by PHP |
|
| 807 | + * |
|
| 808 | + * @param $value |
|
| 809 | + * @param $option |
|
| 810 | + * @throws EE_Error |
|
| 811 | + * @return string |
|
| 812 | + */ |
|
| 813 | + public function check_for_invalid_datetime_formats($value, $option) |
|
| 814 | + { |
|
| 815 | + // check for date_format or time_format |
|
| 816 | + switch ($option) { |
|
| 817 | + case 'date_format': |
|
| 818 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 819 | + break; |
|
| 820 | + case 'time_format': |
|
| 821 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 822 | + break; |
|
| 823 | + default: |
|
| 824 | + $date_time_format = false; |
|
| 825 | + } |
|
| 826 | + // do we have a date_time format to check ? |
|
| 827 | + if ($date_time_format) { |
|
| 828 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 829 | + |
|
| 830 | + if (is_array($error_msg)) { |
|
| 831 | + $msg = '<p>' |
|
| 832 | + . sprintf( |
|
| 833 | + esc_html__( |
|
| 834 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 835 | + 'event_espresso' |
|
| 836 | + ), |
|
| 837 | + date($date_time_format), |
|
| 838 | + $date_time_format |
|
| 839 | + ) |
|
| 840 | + . '</p><p><ul>'; |
|
| 841 | + |
|
| 842 | + |
|
| 843 | + foreach ($error_msg as $error) { |
|
| 844 | + $msg .= '<li>' . $error . '</li>'; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + $msg .= '</ul></p><p>' |
|
| 848 | + . sprintf( |
|
| 849 | + esc_html__( |
|
| 850 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ), |
|
| 853 | + '<span style="color:#D54E21;">', |
|
| 854 | + '</span>' |
|
| 855 | + ) |
|
| 856 | + . '</p>'; |
|
| 857 | + |
|
| 858 | + // trigger WP settings error |
|
| 859 | + add_settings_error( |
|
| 860 | + 'date_format', |
|
| 861 | + 'date_format', |
|
| 862 | + $msg |
|
| 863 | + ); |
|
| 864 | + |
|
| 865 | + // set format to something valid |
|
| 866 | + switch ($option) { |
|
| 867 | + case 'date_format': |
|
| 868 | + $value = 'F j, Y'; |
|
| 869 | + break; |
|
| 870 | + case 'time_format': |
|
| 871 | + $value = 'g:i a'; |
|
| 872 | + break; |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | + return $value; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 882 | + * |
|
| 883 | + * @param $content |
|
| 884 | + * @return string |
|
| 885 | + */ |
|
| 886 | + public function its_eSpresso($content) |
|
| 887 | + { |
|
| 888 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * espresso_admin_footer |
|
| 894 | + * |
|
| 895 | + * @return string |
|
| 896 | + */ |
|
| 897 | + public function espresso_admin_footer() |
|
| 898 | + { |
|
| 899 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * static method for registering ee admin page. |
|
| 905 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 906 | + * |
|
| 907 | + * @since 4.3.0 |
|
| 908 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 909 | + * @see EE_Register_Admin_Page::register() |
|
| 910 | + * @param $page_basename |
|
| 911 | + * @param $page_path |
|
| 912 | + * @param array $config |
|
| 913 | + * @return void |
|
| 914 | + * @throws EE_Error |
|
| 915 | + */ |
|
| 916 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 917 | + { |
|
| 918 | + EE_Error::doing_it_wrong( |
|
| 919 | + __METHOD__, |
|
| 920 | + sprintf( |
|
| 921 | + esc_html__( |
|
| 922 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 923 | + 'event_espresso' |
|
| 924 | + ), |
|
| 925 | + $page_basename |
|
| 926 | + ), |
|
| 927 | + '4.3' |
|
| 928 | + ); |
|
| 929 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 930 | + $config['page_path'] = $page_path; |
|
| 931 | + } |
|
| 932 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + /** |
|
| 937 | + * @deprecated 4.8.41 |
|
| 938 | + * @param int $post_ID |
|
| 939 | + * @param \WP_Post $post |
|
| 940 | + * @return void |
|
| 941 | + */ |
|
| 942 | + public static function parse_post_content_on_save($post_ID, $post) |
|
| 943 | + { |
|
| 944 | + EE_Error::doing_it_wrong( |
|
| 945 | + __METHOD__, |
|
| 946 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 947 | + '4.8.41' |
|
| 948 | + ); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * @deprecated 4.8.41 |
|
| 954 | + * @param $option |
|
| 955 | + * @param $old_value |
|
| 956 | + * @param $value |
|
| 957 | + * @return void |
|
| 958 | + */ |
|
| 959 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 960 | + { |
|
| 961 | + EE_Error::doing_it_wrong( |
|
| 962 | + __METHOD__, |
|
| 963 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 964 | + '4.8.41' |
|
| 965 | + ); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * @deprecated 4.9.27 |
|
| 971 | + * @return void |
|
| 972 | + */ |
|
| 973 | + public function get_persistent_admin_notices() |
|
| 974 | + { |
|
| 975 | + EE_Error::doing_it_wrong( |
|
| 976 | + __METHOD__, |
|
| 977 | + sprintf( |
|
| 978 | + esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 979 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 980 | + ), |
|
| 981 | + '4.9.27' |
|
| 982 | + ); |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + |
|
| 986 | + /** |
|
| 987 | + * @deprecated 4.9.27 |
|
| 988 | + * @throws InvalidInterfaceException |
|
| 989 | + * @throws InvalidDataTypeException |
|
| 990 | + * @throws DomainException |
|
| 991 | + */ |
|
| 992 | + public function dismiss_ee_nag_notice_callback() |
|
| 993 | + { |
|
| 994 | + EE_Error::doing_it_wrong( |
|
| 995 | + __METHOD__, |
|
| 996 | + sprintf( |
|
| 997 | + esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 998 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 999 | + ), |
|
| 1000 | + '4.9.27' |
|
| 1001 | + ); |
|
| 1002 | + $this->persistent_admin_notice_manager->dismissNotice(); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page. |
|
| 1008 | + * |
|
| 1009 | + * @throws InvalidArgumentException |
|
| 1010 | + * @throws InvalidDataTypeException |
|
| 1011 | + * @throws InvalidInterfaceException |
|
| 1012 | + */ |
|
| 1013 | + public function hookIntoWpPluginsPage() |
|
| 1014 | + { |
|
| 1015 | + $this->getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal'); |
|
| 1016 | + $this->getLoader() |
|
| 1017 | + ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells') |
|
| 1018 | + ->decafUpsells(); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * Hooks into the "post states" filter in a wp post type list table. |
|
| 1024 | + * |
|
| 1025 | + * @param array $post_states |
|
| 1026 | + * @param WP_Post $post |
|
| 1027 | + * @return array |
|
| 1028 | + * @throws InvalidArgumentException |
|
| 1029 | + * @throws InvalidDataTypeException |
|
| 1030 | + * @throws InvalidInterfaceException |
|
| 1031 | + */ |
|
| 1032 | + public function displayStateForCriticalPages($post_states, $post) |
|
| 1033 | + { |
|
| 1034 | + $post_states = (array) $post_states; |
|
| 1035 | + if (! $post instanceof WP_Post || $post->post_type !== 'page') { |
|
| 1036 | + return $post_states; |
|
| 1037 | + } |
|
| 1038 | + /** @var EE_Core_Config $config */ |
|
| 1039 | + $config = $this->getLoader()->getShared('EE_Config')->core; |
|
| 1040 | + if (in_array($post->ID, $config->get_critical_pages_array(), true)) { |
|
| 1041 | + $post_states[] = sprintf( |
|
| 1042 | + /* Translators: Using company name - Event Espresso Critical Page */ |
|
| 1043 | + esc_html__('%s Critical Page', 'event_espresso'), |
|
| 1044 | + 'Event Espresso' |
|
| 1045 | + ); |
|
| 1046 | + } |
|
| 1047 | + return $post_states; |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + |
|
| 1051 | + /** |
|
| 1052 | + * Show documentation links on the plugins page |
|
| 1053 | + * |
|
| 1054 | + * @param mixed $meta Plugin Row Meta |
|
| 1055 | + * @param mixed $file Plugin Base file |
|
| 1056 | + * @return array |
|
| 1057 | + */ |
|
| 1058 | + public function addLinksToPluginRowMeta($meta, $file) |
|
| 1059 | + { |
|
| 1060 | + if (EE_PLUGIN_BASENAME === $file) { |
|
| 1061 | + $row_meta = array( |
|
| 1062 | + 'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"' |
|
| 1063 | + . ' aria-label="' |
|
| 1064 | + . esc_attr__('View Event Espresso documentation', 'event_espresso') |
|
| 1065 | + . '">' |
|
| 1066 | + . esc_html__('Docs', 'event_espresso') |
|
| 1067 | + . '</a>', |
|
| 1068 | + 'api' => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"' |
|
| 1069 | + . ' aria-label="' |
|
| 1070 | + . esc_attr__('View Event Espresso API docs', 'event_espresso') |
|
| 1071 | + . '">' |
|
| 1072 | + . esc_html__('API docs', 'event_espresso') |
|
| 1073 | + . '</a>', |
|
| 1074 | + ); |
|
| 1075 | + return array_merge($meta, $row_meta); |
|
| 1076 | + } |
|
| 1077 | + return (array) $meta; |
|
| 1078 | + } |
|
| 1079 | 1079 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public static function instance() |
| 44 | 44 | { |
| 45 | 45 | // check if class object is instantiated |
| 46 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 46 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
| 47 | 47 | self::$_instance = new self(); |
| 48 | 48 | } |
| 49 | 49 | return self::$_instance; |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | private function _define_all_constants() |
| 107 | 107 | { |
| 108 | - if (! defined('EE_ADMIN_URL')) { |
|
| 109 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 110 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 111 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/'); |
|
| 112 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 108 | + if ( ! defined('EE_ADMIN_URL')) { |
|
| 109 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 110 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 111 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates/'); |
|
| 112 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 113 | 113 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | // set $main_file in stone |
| 128 | 128 | static $main_file; |
| 129 | 129 | // if $main_file is not set yet |
| 130 | - if (! $main_file) { |
|
| 130 | + if ( ! $main_file) { |
|
| 131 | 131 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
| 132 | 132 | } |
| 133 | 133 | if ($plugin === $main_file) { |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
| 179 | 179 | { |
| 180 | 180 | return array( |
| 181 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance/', |
|
| 182 | - 'about' => EE_ADMIN_PAGES . 'about/', |
|
| 183 | - 'support' => EE_ADMIN_PAGES . 'support/', |
|
| 181 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance/', |
|
| 182 | + 'about' => EE_ADMIN_PAGES.'about/', |
|
| 183 | + 'support' => EE_ADMIN_PAGES.'support/', |
|
| 184 | 184 | ); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $this->initModelsReady(); |
| 205 | 205 | } |
| 206 | 206 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 207 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 207 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 208 | 208 | try { |
| 209 | 209 | // this loads the controller for the admin pages which will setup routing etc |
| 210 | 210 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | protected function getLoader() |
| 232 | 232 | { |
| 233 | - if (! $this->loader instanceof LoaderInterface) { |
|
| 233 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
| 234 | 234 | $this->loader = LoaderFactory::getLoader(); |
| 235 | 235 | } |
| 236 | 236 | return $this->loader; |
@@ -297,13 +297,13 @@ discard block |
||
| 297 | 297 | '</strong>', |
| 298 | 298 | '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
| 299 | 299 | '</a>', |
| 300 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 300 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
| 301 | 301 | array( |
| 302 | 302 | 'page' => 'espresso_maintenance_settings', |
| 303 | 303 | 'action' => 'datetime_tools', |
| 304 | 304 | ), |
| 305 | 305 | admin_url('admin.php') |
| 306 | - ) . '">' |
|
| 306 | + ).'">' |
|
| 307 | 307 | ), |
| 308 | 308 | false, |
| 309 | 309 | 'manage_options', |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | public function enable_hidden_ee_nav_menu_metaboxes() |
| 350 | 350 | { |
| 351 | 351 | global $wp_meta_boxes, $pagenow; |
| 352 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 352 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 353 | 353 | return; |
| 354 | 354 | } |
| 355 | 355 | $user = wp_get_current_user(); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | if (is_array($hidden_meta_boxes)) { |
| 379 | 379 | foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
| 380 | 380 | if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
| 381 | - unset($hidden_meta_boxes[ $key ]); |
|
| 381 | + unset($hidden_meta_boxes[$key]); |
|
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function modify_edit_post_link($link, $id) |
| 420 | 420 | { |
| 421 | - if (! $post = get_post($id)) { |
|
| 421 | + if ( ! $post = get_post($id)) { |
|
| 422 | 422 | return $link; |
| 423 | 423 | } |
| 424 | 424 | if ($post->post_type === 'espresso_attendees') { |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | ); |
| 566 | 566 | |
| 567 | 567 | foreach ($keys as $key => $value) { |
| 568 | - $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value; |
|
| 568 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 569 | 569 | } |
| 570 | 570 | return $menu_item; |
| 571 | 571 | } |
@@ -663,10 +663,10 @@ discard block |
||
| 663 | 663 | |
| 664 | 664 | // loop through to remove any critical pages from the array. |
| 665 | 665 | foreach ($critical_pages as $page_id) { |
| 666 | - $needle = 'value="' . $page_id . '"'; |
|
| 666 | + $needle = 'value="'.$page_id.'"'; |
|
| 667 | 667 | foreach ($split_output as $key => $haystack) { |
| 668 | 668 | if (strpos($haystack, $needle) !== false) { |
| 669 | - unset($split_output[ $key ]); |
|
| 669 | + unset($split_output[$key]); |
|
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | // calls. |
| 688 | 688 | wp_enqueue_script( |
| 689 | 689 | 'ee-inject-wp', |
| 690 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 690 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
| 691 | 691 | array('jquery'), |
| 692 | 692 | EVENT_ESPRESSO_VERSION, |
| 693 | 693 | true |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | // register cookie script for future dependencies |
| 696 | 696 | wp_register_script( |
| 697 | 697 | 'jquery-cookie', |
| 698 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 698 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
| 699 | 699 | array('jquery'), |
| 700 | 700 | '2.1', |
| 701 | 701 | true |
@@ -704,16 +704,16 @@ discard block |
||
| 704 | 704 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
| 705 | 705 | if (apply_filters('FHEE_load_joyride', false)) { |
| 706 | 706 | // joyride style |
| 707 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 707 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 708 | 708 | wp_register_style( |
| 709 | 709 | 'ee-joyride-css', |
| 710 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 710 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 711 | 711 | array('joyride-css'), |
| 712 | 712 | EVENT_ESPRESSO_VERSION |
| 713 | 713 | ); |
| 714 | 714 | wp_register_script( |
| 715 | 715 | 'joyride-modernizr', |
| 716 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 716 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
| 717 | 717 | array(), |
| 718 | 718 | '2.1', |
| 719 | 719 | true |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | // joyride JS |
| 722 | 722 | wp_register_script( |
| 723 | 723 | 'jquery-joyride', |
| 724 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 724 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 725 | 725 | array('jquery-cookie', 'joyride-modernizr'), |
| 726 | 726 | '2.1', |
| 727 | 727 | true |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | |
| 791 | 791 | foreach ($items as $type => $item_properties) { |
| 792 | 792 | $elements[] = sprintf( |
| 793 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 793 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
| 794 | 794 | $item_properties['url'], |
| 795 | 795 | $item_properties['title'], |
| 796 | 796 | $item_properties['text'] |
@@ -815,10 +815,10 @@ discard block |
||
| 815 | 815 | // check for date_format or time_format |
| 816 | 816 | switch ($option) { |
| 817 | 817 | case 'date_format': |
| 818 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 818 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 819 | 819 | break; |
| 820 | 820 | case 'time_format': |
| 821 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 821 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 822 | 822 | break; |
| 823 | 823 | default: |
| 824 | 824 | $date_time_format = false; |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | |
| 842 | 842 | |
| 843 | 843 | foreach ($error_msg as $error) { |
| 844 | - $msg .= '<li>' . $error . '</li>'; |
|
| 844 | + $msg .= '<li>'.$error.'</li>'; |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | $msg .= '</ul></p><p>' |
@@ -1032,7 +1032,7 @@ discard block |
||
| 1032 | 1032 | public function displayStateForCriticalPages($post_states, $post) |
| 1033 | 1033 | { |
| 1034 | 1034 | $post_states = (array) $post_states; |
| 1035 | - if (! $post instanceof WP_Post || $post->post_type !== 'page') { |
|
| 1035 | + if ( ! $post instanceof WP_Post || $post->post_type !== 'page') { |
|
| 1036 | 1036 | return $post_states; |
| 1037 | 1037 | } |
| 1038 | 1038 | /** @var EE_Core_Config $config */ |
@@ -24,677 +24,677 @@ |
||
| 24 | 24 | class EE_Admin_Page_Loader |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * _installed_pages |
|
| 29 | - * objects for page_init objects detected and loaded |
|
| 30 | - * |
|
| 31 | - * @access private |
|
| 32 | - * @var \EE_Admin_Page_Init[] |
|
| 33 | - */ |
|
| 34 | - private $_installed_pages = array(); |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * this is used to hold the registry of menu slugs for all the installed admin pages |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $_menu_slugs = array(); |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * _caffeinated_extends |
|
| 47 | - * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
| 48 | - * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
| 49 | - * |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - private $_caffeinated_extends = array(); |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * _current_caf_extend_slug |
|
| 57 | - * This property is used for holding the page slug that is required for referencing the correct |
|
| 58 | - * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - private $_current_caf_extend_slug; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * _prepped_menu_maps |
|
| 66 | - * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
| 67 | - * |
|
| 68 | - * @since 4.4.0 |
|
| 69 | - * @var EE_Admin_Page_Menu_Map[] |
|
| 70 | - */ |
|
| 71 | - private $_prepped_menu_maps = array(); |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * _admin_menu_groups |
|
| 76 | - * array that holds the group headings and details for |
|
| 77 | - * |
|
| 78 | - * @access private |
|
| 79 | - * @var array |
|
| 80 | - */ |
|
| 81 | - private $_admin_menu_groups = array(); |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
| 86 | - * pages. |
|
| 87 | - * |
|
| 88 | - * @var string |
|
| 89 | - */ |
|
| 90 | - public $hook_file; |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * constructor |
|
| 95 | - * |
|
| 96 | - * @access public |
|
| 97 | - * @return \EE_Admin_Page_Loader |
|
| 98 | - */ |
|
| 99 | - public function __construct() |
|
| 100 | - { |
|
| 101 | - // load menu_map classes |
|
| 102 | - EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
| 103 | - // define the default "groups" for the admin_pages |
|
| 104 | - $this->_set_menu_groups(); |
|
| 105 | - |
|
| 106 | - // let's do a scan and see what installed pages we have |
|
| 107 | - $this->_get_installed_pages(); |
|
| 108 | - // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
| 109 | - add_action('admin_menu', array($this, 'set_menus')); |
|
| 110 | - add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
| 116 | - * files in the caffeinated folder. |
|
| 117 | - * |
|
| 118 | - * @access private |
|
| 119 | - * @return void |
|
| 120 | - */ |
|
| 121 | - private function _define_caffeinated_constants() |
|
| 122 | - { |
|
| 123 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 124 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 125 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 126 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 127 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 128 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 129 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * _set_menu_groups |
|
| 136 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
| 137 | - * |
|
| 138 | - * @access private |
|
| 139 | - * @return void |
|
| 140 | - */ |
|
| 141 | - private function _set_menu_groups() |
|
| 142 | - { |
|
| 143 | - |
|
| 144 | - // set array of EE_Admin_Page_Menu_Group objects |
|
| 145 | - $groups = array( |
|
| 146 | - 'main' => new EE_Admin_Page_Menu_Group( |
|
| 147 | - array( |
|
| 148 | - 'menu_label' => __('Main', 'event_espresso'), |
|
| 149 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
| 150 | - 'menu_slug' => 'main', |
|
| 151 | - 'capability' => 'ee_read_ee', |
|
| 152 | - 'menu_order' => 0, |
|
| 153 | - 'parent_slug' => 'espresso_events', |
|
| 154 | - ) |
|
| 155 | - ), |
|
| 156 | - 'management' => new EE_Admin_Page_Menu_Group( |
|
| 157 | - array( |
|
| 158 | - 'menu_label' => __('Management', 'event_espresso'), |
|
| 159 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 160 | - 'menu_slug' => 'management', |
|
| 161 | - 'capability' => 'ee_read_ee', |
|
| 162 | - 'menu_order' => 10, |
|
| 163 | - 'parent_slug' => 'espresso_events', |
|
| 164 | - ) |
|
| 165 | - ), |
|
| 166 | - 'settings' => new EE_Admin_Page_Menu_Group( |
|
| 167 | - array( |
|
| 168 | - 'menu_label' => __('Settings', 'event_espresso'), |
|
| 169 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 170 | - 'menu_slug' => 'settings', |
|
| 171 | - 'capability' => 'ee_read_ee', |
|
| 172 | - 'menu_order' => 30, |
|
| 173 | - 'parent_slug' => 'espresso_events', |
|
| 174 | - ) |
|
| 175 | - ), |
|
| 176 | - 'templates' => new EE_Admin_Page_Menu_Group( |
|
| 177 | - array( |
|
| 178 | - 'menu_label' => __('Templates', 'event_espresso'), |
|
| 179 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 180 | - 'menu_slug' => 'templates', |
|
| 181 | - 'capability' => 'ee_read_ee', |
|
| 182 | - 'menu_order' => 40, |
|
| 183 | - 'parent_slug' => 'espresso_events', |
|
| 184 | - ) |
|
| 185 | - ), |
|
| 186 | - 'extras' => new EE_Admin_Page_Menu_Group( |
|
| 187 | - array( |
|
| 188 | - 'menu_label' => __('Extras', 'event_espresso'), |
|
| 189 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 190 | - 'menu_slug' => 'extras', |
|
| 191 | - 'capability' => 'ee_read_ee', |
|
| 192 | - 'menu_order' => 50, |
|
| 193 | - 'parent_slug' => 'espresso_events', |
|
| 194 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 195 | - ) |
|
| 196 | - ), |
|
| 197 | - 'tools' => new EE_Admin_Page_Menu_Group( |
|
| 198 | - array( |
|
| 199 | - 'menu_label' => __("Tools", "event_espresso"), |
|
| 200 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 201 | - 'menu_slug' => 'tools', |
|
| 202 | - 'capability' => 'ee_read_ee', |
|
| 203 | - 'menu_order' => 60, |
|
| 204 | - 'parent_slug' => 'espresso_events', |
|
| 205 | - ) |
|
| 206 | - ), |
|
| 207 | - 'addons' => new EE_Admin_Page_Menu_Group( |
|
| 208 | - array( |
|
| 209 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 210 | - 'menu_label' => __('Add-ons', 'event_espresso'), |
|
| 211 | - 'menu_slug' => 'addons', |
|
| 212 | - 'capability' => 'ee_read_ee', |
|
| 213 | - 'menu_order' => 20, |
|
| 214 | - 'parent_slug' => 'espresso_events', |
|
| 215 | - ) |
|
| 216 | - ), |
|
| 217 | - ); |
|
| 218 | - $this->_admin_menu_groups = apply_filters( |
|
| 219 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
| 220 | - $groups |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
| 227 | - * slug. The other utility with this function is it validates that all the groups are instances of |
|
| 228 | - * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
| 229 | - * |
|
| 230 | - * @since 4.4.0 |
|
| 231 | - * @throws \EE_Error |
|
| 232 | - * @return EE_Admin_Page_Menu_Group[] |
|
| 233 | - */ |
|
| 234 | - private function _rearrange_menu_groups() |
|
| 235 | - { |
|
| 236 | - $groups = array(); |
|
| 237 | - // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
| 238 | - usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
| 239 | - foreach ($this->_admin_menu_groups as $group) { |
|
| 240 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 241 | - throw new EE_Error( |
|
| 242 | - sprintf( |
|
| 243 | - __( |
|
| 244 | - 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
| 245 | - 'event_espresso' |
|
| 246 | - ), |
|
| 247 | - print_r($group, true) |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - } |
|
| 251 | - $groups[ $group->menu_slug ] = $group; |
|
| 252 | - } |
|
| 253 | - return $groups; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * _get_installed_pages |
|
| 259 | - * This just gets the list of installed EE_Admin_pages. |
|
| 260 | - * |
|
| 261 | - * @access private |
|
| 262 | - * @throws EE_Error |
|
| 263 | - * @return void |
|
| 264 | - */ |
|
| 265 | - private function _get_installed_pages() |
|
| 266 | - { |
|
| 267 | - $installed_refs = array(); |
|
| 268 | - $exclude = array('assets', 'templates'); |
|
| 269 | - // grab everything in the admin core directory |
|
| 270 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
| 271 | - if ($admin_screens) { |
|
| 272 | - foreach ($admin_screens as $admin_screen) { |
|
| 273 | - // files and anything in the exclude array need not apply |
|
| 274 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 275 | - // these folders represent the different EE admin pages |
|
| 276 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - if (empty($installed_refs)) { |
|
| 281 | - $error_msg[] = __( |
|
| 282 | - 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
| 283 | - 'event_espresso' |
|
| 284 | - ); |
|
| 285 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
| 286 | - . sprintf( |
|
| 287 | - __( |
|
| 288 | - 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
| 289 | - 'event_espresso' |
|
| 290 | - ), |
|
| 291 | - EE_ADMIN_PAGES |
|
| 292 | - ); |
|
| 293 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 294 | - } |
|
| 295 | - // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
| 296 | - $installed_refs = $this->_set_caffeinated($installed_refs); |
|
| 297 | - // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
| 298 | - $installed_refs = apply_filters( |
|
| 299 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
| 300 | - $installed_refs |
|
| 301 | - ); |
|
| 302 | - $this->_caffeinated_extends = apply_filters( |
|
| 303 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
| 304 | - $this->_caffeinated_extends |
|
| 305 | - ); |
|
| 306 | - // loop through admin pages and setup the $_installed_pages array. |
|
| 307 | - $hooks_ref = array(); |
|
| 308 | - foreach ($installed_refs as $page => $path) { |
|
| 309 | - // set autoloaders for our admin page classes based on included path information |
|
| 310 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
| 311 | - // build list of installed pages |
|
| 312 | - $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
| 313 | - // verify returned object |
|
| 314 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
| 315 | - if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 316 | - continue; |
|
| 317 | - } |
|
| 318 | - // skip if in full maintenance mode and maintenance_mode_parent is set |
|
| 319 | - $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
| 320 | - if (empty($maintenance_mode_parent) |
|
| 321 | - && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 322 | - ) { |
|
| 323 | - unset($installed_refs[ $page ]); |
|
| 324 | - continue; |
|
| 325 | - } |
|
| 326 | - $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
| 327 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
| 328 | - // flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
| 329 | - $extend = false; |
|
| 330 | - // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
| 331 | - if (isset($this->_caffeinated_extends[ $page ])) { |
|
| 332 | - $this->_current_caf_extend_slug = $page; |
|
| 333 | - $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
| 334 | - $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
| 335 | - $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
| 336 | - add_filter( |
|
| 337 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
| 338 | - function ($path_to_file) use ($caf_path) { |
|
| 339 | - return $caf_path; |
|
| 340 | - } |
|
| 341 | - ); |
|
| 342 | - add_filter( |
|
| 343 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
| 344 | - function ($admin_page) use ($caf_admin_page) { |
|
| 345 | - return $caf_admin_page; |
|
| 346 | - } |
|
| 347 | - ); |
|
| 348 | - $extend = true; |
|
| 349 | - } |
|
| 350 | - // let's do the registered hooks |
|
| 351 | - $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
| 352 | - $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
| 356 | - // first make sure we've got unique values |
|
| 357 | - $hooks_ref = array_unique($hooks_ref); |
|
| 358 | - // now let's loop and require! |
|
| 359 | - foreach ($hooks_ref as $path) { |
|
| 360 | - require_once($path); |
|
| 361 | - } |
|
| 362 | - // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
| 363 | - global $ee_menu_slugs; |
|
| 364 | - $ee_menu_slugs = $this->_menu_slugs; |
|
| 365 | - // we need to loop again to run any early code |
|
| 366 | - foreach ($installed_refs as $page => $path) { |
|
| 367 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
| 368 | - $this->_installed_pages[ $page ]->do_initial_loads(); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * get_admin_page_object |
|
| 377 | - * |
|
| 378 | - * @param string $page_slug |
|
| 379 | - * @return EE_Admin_Page |
|
| 380 | - */ |
|
| 381 | - public function get_admin_page_object($page_slug = '') |
|
| 382 | - { |
|
| 383 | - if (isset($this->_installed_pages[ $page_slug ])) { |
|
| 384 | - return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
| 385 | - } |
|
| 386 | - return null; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * _get_classname_for_admin_page |
|
| 392 | - * generates an "Admin Page" class based on the directory name |
|
| 393 | - * |
|
| 394 | - * @param $dir_name |
|
| 395 | - * @return string |
|
| 396 | - */ |
|
| 397 | - private function _get_classname_for_admin_page($dir_name = '') |
|
| 398 | - { |
|
| 399 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 400 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * _get_classname_for_admin_init_page |
|
| 406 | - * generates an "Admin Page Init" class based on the directory name |
|
| 407 | - * |
|
| 408 | - * @param $dir_name |
|
| 409 | - * @return string |
|
| 410 | - */ |
|
| 411 | - private function _get_classname_for_admin_init_page($dir_name = '') |
|
| 412 | - { |
|
| 413 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 414 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * _load_admin_page |
|
| 420 | - * Loads and instantiates page_init object for a single EE_admin page. |
|
| 421 | - * |
|
| 422 | - * @param string $page page_reference |
|
| 423 | - * @param string $path |
|
| 424 | - * @throws EE_Error |
|
| 425 | - * @return object|bool return page object if valid, bool false if not. |
|
| 426 | - */ |
|
| 427 | - private function _load_admin_page($page = '', $path = '') |
|
| 428 | - { |
|
| 429 | - $class_name = $this->_get_classname_for_admin_init_page($page); |
|
| 430 | - EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
| 431 | - if (! class_exists($class_name)) { |
|
| 432 | - $inner_error_msg = '<br />' |
|
| 433 | - . sprintf( |
|
| 434 | - esc_html__( |
|
| 435 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 436 | - 'event_espresso' |
|
| 437 | - ), |
|
| 438 | - '<strong>' . $class_name . '</strong>' |
|
| 439 | - ); |
|
| 440 | - $error_msg[] = sprintf( |
|
| 441 | - __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
| 442 | - $page |
|
| 443 | - ); |
|
| 444 | - $error_msg[] = $error_msg[0] |
|
| 445 | - . "\r\n" |
|
| 446 | - . sprintf( |
|
| 447 | - esc_html__( |
|
| 448 | - 'There is no Init class in place for the %s admin page.', |
|
| 449 | - 'event_espresso' |
|
| 450 | - ), |
|
| 451 | - $page |
|
| 452 | - ) |
|
| 453 | - . $inner_error_msg; |
|
| 454 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 455 | - } |
|
| 456 | - $a = new ReflectionClass($class_name); |
|
| 457 | - return $a->newInstance(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * set_menus |
|
| 463 | - * This method sets up the menus for EE Admin Pages |
|
| 464 | - * |
|
| 465 | - * @access private |
|
| 466 | - * @return void |
|
| 467 | - */ |
|
| 468 | - public function set_menus() |
|
| 469 | - { |
|
| 470 | - // prep the menu pages (sort, group.) |
|
| 471 | - $this->_prep_pages(); |
|
| 472 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 473 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 474 | - $menu_map->add_menu_page(false); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * set_network_menus |
|
| 482 | - * This method sets up the menus for network EE Admin Pages. |
|
| 483 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
| 484 | - * are only added to the menu map if they are intended for the admin menu |
|
| 485 | - * |
|
| 486 | - * @return void |
|
| 487 | - */ |
|
| 488 | - public function set_network_menus() |
|
| 489 | - { |
|
| 490 | - $this->_prep_pages(); |
|
| 491 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 492 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 493 | - $menu_map->add_menu_page(true); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * _prep_pages |
|
| 501 | - * sets the _prepped_menu_maps property |
|
| 502 | - * |
|
| 503 | - * @access private |
|
| 504 | - * @throws EE_Error |
|
| 505 | - * @return void |
|
| 506 | - */ |
|
| 507 | - private function _prep_pages() |
|
| 508 | - { |
|
| 509 | - $pages_array = array(); |
|
| 510 | - // rearrange _admin_menu_groups to be indexed by group slug. |
|
| 511 | - $menu_groups = $this->_rearrange_menu_groups(); |
|
| 512 | - foreach ($this->_installed_pages as $page) { |
|
| 513 | - if ($page instanceof EE_Admin_page_Init) { |
|
| 514 | - $page_map = $page->get_menu_map(); |
|
| 515 | - // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
| 516 | - if (is_array($page_map) || empty($page_map)) { |
|
| 517 | - new PersistentAdminNotice( |
|
| 518 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
| 519 | - sprintf( |
|
| 520 | - __( |
|
| 521 | - 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
| 522 | - 'event_espresso' |
|
| 523 | - ), |
|
| 524 | - $page->label |
|
| 525 | - ) |
|
| 526 | - ); |
|
| 527 | - continue; |
|
| 528 | - } |
|
| 529 | - // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
| 530 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 531 | - throw new EE_Error( |
|
| 532 | - sprintf( |
|
| 533 | - __( |
|
| 534 | - 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
| 535 | - 'event_espresso' |
|
| 536 | - ), |
|
| 537 | - $page->label, |
|
| 538 | - $page_map |
|
| 539 | - ) |
|
| 540 | - ); |
|
| 541 | - } |
|
| 542 | - // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
| 543 | - if (empty($page_map->maintenance_mode_parent) |
|
| 544 | - && EE_Maintenance_Mode::instance()->level() |
|
| 545 | - == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 546 | - continue; |
|
| 547 | - } |
|
| 548 | - // assign to group (remember $page_map has the admin page stored in it). |
|
| 549 | - $pages_array[ $page_map->menu_group ][] = $page_map; |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - if (empty($pages_array)) { |
|
| 553 | - throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
| 554 | - } |
|
| 555 | - // let's sort the groups, make sure it's a valid group, add header (if to show). |
|
| 556 | - foreach ($pages_array as $group => $menu_maps) { |
|
| 557 | - // valid_group? |
|
| 558 | - if (! array_key_exists($group, $menu_groups)) { |
|
| 559 | - continue; |
|
| 560 | - } |
|
| 561 | - // sort pages. |
|
| 562 | - usort($menu_maps, array($this, '_sort_menu_maps')); |
|
| 563 | - // prepend header |
|
| 564 | - array_unshift($menu_maps, $menu_groups[ $group ]); |
|
| 565 | - // reset $pages_array with prepped data |
|
| 566 | - $pages_array[ $group ] = $menu_maps; |
|
| 567 | - } |
|
| 568 | - // now let's setup the _prepped_menu_maps property |
|
| 569 | - foreach ($menu_groups as $group => $group_objs) { |
|
| 570 | - if (isset($pages_array[ $group ])) { |
|
| 571 | - $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]); |
|
| 572 | - } |
|
| 573 | - }/**/ |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
| 579 | - * In this method there are three checks being done: |
|
| 580 | - * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
| 581 | - * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
| 582 | - * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
| 583 | - * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
| 584 | - * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
| 585 | - * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
| 586 | - * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
| 587 | - * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
| 588 | - * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
| 589 | - * admin_pages) |
|
| 590 | - * |
|
| 591 | - * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
| 592 | - * loaded. |
|
| 593 | - * @return array |
|
| 594 | - */ |
|
| 595 | - private function _set_caffeinated($installed_refs) |
|
| 596 | - { |
|
| 597 | - |
|
| 598 | - // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
| 599 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 600 | - return $installed_refs; |
|
| 601 | - } |
|
| 602 | - $this->_define_caffeinated_constants(); |
|
| 603 | - $exclude = array('tickets'); |
|
| 604 | - // okay let's setup an "New" pages first (we'll return installed refs later) |
|
| 605 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
| 606 | - if ($new_admin_screens) { |
|
| 607 | - foreach ($new_admin_screens as $admin_screen) { |
|
| 608 | - // files and anything in the exclude array need not apply |
|
| 609 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 610 | - // these folders represent the different NEW EE admin pages |
|
| 611 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
| 612 | - // set autoloaders for our admin page classes based on included path information |
|
| 613 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
| 618 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
| 619 | - if ($extends) { |
|
| 620 | - foreach ($extends as $extend) { |
|
| 621 | - if (is_dir($extend)) { |
|
| 622 | - $extend_ref = basename($extend); |
|
| 623 | - // now let's make sure there is a file that matches the expected format |
|
| 624 | - $filename = str_replace( |
|
| 625 | - ' ', |
|
| 626 | - '_', |
|
| 627 | - ucwords( |
|
| 628 | - str_replace( |
|
| 629 | - '_', |
|
| 630 | - ' ', |
|
| 631 | - $extend_ref |
|
| 632 | - ) |
|
| 633 | - ) |
|
| 634 | - ); |
|
| 635 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
| 636 | - $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
| 637 | - array('\\', '/'), |
|
| 638 | - '/', |
|
| 639 | - EE_CORE_CAF_ADMIN |
|
| 640 | - . 'extend/' |
|
| 641 | - . $extend_ref |
|
| 642 | - . '/' |
|
| 643 | - . $filename |
|
| 644 | - . '.core.php' |
|
| 645 | - ); |
|
| 646 | - $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
| 647 | - // set autoloaders for our admin page classes based on included path information |
|
| 648 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
| 653 | - $ee_admin_hooks = array(); |
|
| 654 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
| 655 | - if ($hooks) { |
|
| 656 | - foreach ($hooks as $hook) { |
|
| 657 | - if (is_readable($hook)) { |
|
| 658 | - require_once $hook; |
|
| 659 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
| 660 | - $classname = str_replace('.class.php', '', $classname); |
|
| 661 | - if (class_exists($classname)) { |
|
| 662 | - $a = new ReflectionClass($classname); |
|
| 663 | - $ee_admin_hooks[] = $a->newInstance(); |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - }/**/ |
|
| 668 | - $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
| 669 | - return $installed_refs; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Utility method for sorting the _menu_maps (callback for usort php function) |
|
| 675 | - * |
|
| 676 | - * @since 4.4.0 |
|
| 677 | - * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
| 678 | - * @param EE_Admin_Page_Menu_Map $b being compared to |
|
| 679 | - * @return int sort order |
|
| 680 | - */ |
|
| 681 | - private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
| 682 | - { |
|
| 683 | - if ($a->menu_order == $b->menu_order) { |
|
| 684 | - return 0; |
|
| 685 | - } |
|
| 686 | - return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * _default_header_link |
|
| 692 | - * This is just a dummy method to use with header submenu items |
|
| 693 | - * |
|
| 694 | - * @return bool false |
|
| 695 | - */ |
|
| 696 | - public function _default_header_link() |
|
| 697 | - { |
|
| 698 | - return false; |
|
| 699 | - } |
|
| 27 | + /** |
|
| 28 | + * _installed_pages |
|
| 29 | + * objects for page_init objects detected and loaded |
|
| 30 | + * |
|
| 31 | + * @access private |
|
| 32 | + * @var \EE_Admin_Page_Init[] |
|
| 33 | + */ |
|
| 34 | + private $_installed_pages = array(); |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * this is used to hold the registry of menu slugs for all the installed admin pages |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $_menu_slugs = array(); |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * _caffeinated_extends |
|
| 47 | + * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
| 48 | + * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + private $_caffeinated_extends = array(); |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * _current_caf_extend_slug |
|
| 57 | + * This property is used for holding the page slug that is required for referencing the correct |
|
| 58 | + * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + private $_current_caf_extend_slug; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * _prepped_menu_maps |
|
| 66 | + * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
| 67 | + * |
|
| 68 | + * @since 4.4.0 |
|
| 69 | + * @var EE_Admin_Page_Menu_Map[] |
|
| 70 | + */ |
|
| 71 | + private $_prepped_menu_maps = array(); |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * _admin_menu_groups |
|
| 76 | + * array that holds the group headings and details for |
|
| 77 | + * |
|
| 78 | + * @access private |
|
| 79 | + * @var array |
|
| 80 | + */ |
|
| 81 | + private $_admin_menu_groups = array(); |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
| 86 | + * pages. |
|
| 87 | + * |
|
| 88 | + * @var string |
|
| 89 | + */ |
|
| 90 | + public $hook_file; |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * constructor |
|
| 95 | + * |
|
| 96 | + * @access public |
|
| 97 | + * @return \EE_Admin_Page_Loader |
|
| 98 | + */ |
|
| 99 | + public function __construct() |
|
| 100 | + { |
|
| 101 | + // load menu_map classes |
|
| 102 | + EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
| 103 | + // define the default "groups" for the admin_pages |
|
| 104 | + $this->_set_menu_groups(); |
|
| 105 | + |
|
| 106 | + // let's do a scan and see what installed pages we have |
|
| 107 | + $this->_get_installed_pages(); |
|
| 108 | + // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
| 109 | + add_action('admin_menu', array($this, 'set_menus')); |
|
| 110 | + add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
| 116 | + * files in the caffeinated folder. |
|
| 117 | + * |
|
| 118 | + * @access private |
|
| 119 | + * @return void |
|
| 120 | + */ |
|
| 121 | + private function _define_caffeinated_constants() |
|
| 122 | + { |
|
| 123 | + if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 124 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 125 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 126 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 127 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 128 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 129 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * _set_menu_groups |
|
| 136 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
| 137 | + * |
|
| 138 | + * @access private |
|
| 139 | + * @return void |
|
| 140 | + */ |
|
| 141 | + private function _set_menu_groups() |
|
| 142 | + { |
|
| 143 | + |
|
| 144 | + // set array of EE_Admin_Page_Menu_Group objects |
|
| 145 | + $groups = array( |
|
| 146 | + 'main' => new EE_Admin_Page_Menu_Group( |
|
| 147 | + array( |
|
| 148 | + 'menu_label' => __('Main', 'event_espresso'), |
|
| 149 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
| 150 | + 'menu_slug' => 'main', |
|
| 151 | + 'capability' => 'ee_read_ee', |
|
| 152 | + 'menu_order' => 0, |
|
| 153 | + 'parent_slug' => 'espresso_events', |
|
| 154 | + ) |
|
| 155 | + ), |
|
| 156 | + 'management' => new EE_Admin_Page_Menu_Group( |
|
| 157 | + array( |
|
| 158 | + 'menu_label' => __('Management', 'event_espresso'), |
|
| 159 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 160 | + 'menu_slug' => 'management', |
|
| 161 | + 'capability' => 'ee_read_ee', |
|
| 162 | + 'menu_order' => 10, |
|
| 163 | + 'parent_slug' => 'espresso_events', |
|
| 164 | + ) |
|
| 165 | + ), |
|
| 166 | + 'settings' => new EE_Admin_Page_Menu_Group( |
|
| 167 | + array( |
|
| 168 | + 'menu_label' => __('Settings', 'event_espresso'), |
|
| 169 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 170 | + 'menu_slug' => 'settings', |
|
| 171 | + 'capability' => 'ee_read_ee', |
|
| 172 | + 'menu_order' => 30, |
|
| 173 | + 'parent_slug' => 'espresso_events', |
|
| 174 | + ) |
|
| 175 | + ), |
|
| 176 | + 'templates' => new EE_Admin_Page_Menu_Group( |
|
| 177 | + array( |
|
| 178 | + 'menu_label' => __('Templates', 'event_espresso'), |
|
| 179 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 180 | + 'menu_slug' => 'templates', |
|
| 181 | + 'capability' => 'ee_read_ee', |
|
| 182 | + 'menu_order' => 40, |
|
| 183 | + 'parent_slug' => 'espresso_events', |
|
| 184 | + ) |
|
| 185 | + ), |
|
| 186 | + 'extras' => new EE_Admin_Page_Menu_Group( |
|
| 187 | + array( |
|
| 188 | + 'menu_label' => __('Extras', 'event_espresso'), |
|
| 189 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 190 | + 'menu_slug' => 'extras', |
|
| 191 | + 'capability' => 'ee_read_ee', |
|
| 192 | + 'menu_order' => 50, |
|
| 193 | + 'parent_slug' => 'espresso_events', |
|
| 194 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 195 | + ) |
|
| 196 | + ), |
|
| 197 | + 'tools' => new EE_Admin_Page_Menu_Group( |
|
| 198 | + array( |
|
| 199 | + 'menu_label' => __("Tools", "event_espresso"), |
|
| 200 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 201 | + 'menu_slug' => 'tools', |
|
| 202 | + 'capability' => 'ee_read_ee', |
|
| 203 | + 'menu_order' => 60, |
|
| 204 | + 'parent_slug' => 'espresso_events', |
|
| 205 | + ) |
|
| 206 | + ), |
|
| 207 | + 'addons' => new EE_Admin_Page_Menu_Group( |
|
| 208 | + array( |
|
| 209 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 210 | + 'menu_label' => __('Add-ons', 'event_espresso'), |
|
| 211 | + 'menu_slug' => 'addons', |
|
| 212 | + 'capability' => 'ee_read_ee', |
|
| 213 | + 'menu_order' => 20, |
|
| 214 | + 'parent_slug' => 'espresso_events', |
|
| 215 | + ) |
|
| 216 | + ), |
|
| 217 | + ); |
|
| 218 | + $this->_admin_menu_groups = apply_filters( |
|
| 219 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
| 220 | + $groups |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
| 227 | + * slug. The other utility with this function is it validates that all the groups are instances of |
|
| 228 | + * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
| 229 | + * |
|
| 230 | + * @since 4.4.0 |
|
| 231 | + * @throws \EE_Error |
|
| 232 | + * @return EE_Admin_Page_Menu_Group[] |
|
| 233 | + */ |
|
| 234 | + private function _rearrange_menu_groups() |
|
| 235 | + { |
|
| 236 | + $groups = array(); |
|
| 237 | + // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
| 238 | + usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
| 239 | + foreach ($this->_admin_menu_groups as $group) { |
|
| 240 | + if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 241 | + throw new EE_Error( |
|
| 242 | + sprintf( |
|
| 243 | + __( |
|
| 244 | + 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
| 245 | + 'event_espresso' |
|
| 246 | + ), |
|
| 247 | + print_r($group, true) |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + } |
|
| 251 | + $groups[ $group->menu_slug ] = $group; |
|
| 252 | + } |
|
| 253 | + return $groups; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * _get_installed_pages |
|
| 259 | + * This just gets the list of installed EE_Admin_pages. |
|
| 260 | + * |
|
| 261 | + * @access private |
|
| 262 | + * @throws EE_Error |
|
| 263 | + * @return void |
|
| 264 | + */ |
|
| 265 | + private function _get_installed_pages() |
|
| 266 | + { |
|
| 267 | + $installed_refs = array(); |
|
| 268 | + $exclude = array('assets', 'templates'); |
|
| 269 | + // grab everything in the admin core directory |
|
| 270 | + $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
| 271 | + if ($admin_screens) { |
|
| 272 | + foreach ($admin_screens as $admin_screen) { |
|
| 273 | + // files and anything in the exclude array need not apply |
|
| 274 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 275 | + // these folders represent the different EE admin pages |
|
| 276 | + $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + if (empty($installed_refs)) { |
|
| 281 | + $error_msg[] = __( |
|
| 282 | + 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
| 283 | + 'event_espresso' |
|
| 284 | + ); |
|
| 285 | + $error_msg[] = $error_msg[0] . "\r\n" |
|
| 286 | + . sprintf( |
|
| 287 | + __( |
|
| 288 | + 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
| 289 | + 'event_espresso' |
|
| 290 | + ), |
|
| 291 | + EE_ADMIN_PAGES |
|
| 292 | + ); |
|
| 293 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 294 | + } |
|
| 295 | + // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
| 296 | + $installed_refs = $this->_set_caffeinated($installed_refs); |
|
| 297 | + // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
| 298 | + $installed_refs = apply_filters( |
|
| 299 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
| 300 | + $installed_refs |
|
| 301 | + ); |
|
| 302 | + $this->_caffeinated_extends = apply_filters( |
|
| 303 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
| 304 | + $this->_caffeinated_extends |
|
| 305 | + ); |
|
| 306 | + // loop through admin pages and setup the $_installed_pages array. |
|
| 307 | + $hooks_ref = array(); |
|
| 308 | + foreach ($installed_refs as $page => $path) { |
|
| 309 | + // set autoloaders for our admin page classes based on included path information |
|
| 310 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
| 311 | + // build list of installed pages |
|
| 312 | + $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
| 313 | + // verify returned object |
|
| 314 | + if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
| 315 | + if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 316 | + continue; |
|
| 317 | + } |
|
| 318 | + // skip if in full maintenance mode and maintenance_mode_parent is set |
|
| 319 | + $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
| 320 | + if (empty($maintenance_mode_parent) |
|
| 321 | + && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 322 | + ) { |
|
| 323 | + unset($installed_refs[ $page ]); |
|
| 324 | + continue; |
|
| 325 | + } |
|
| 326 | + $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
| 327 | + $this->_menu_slugs[ $menu_slug ] = $page; |
|
| 328 | + // flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
| 329 | + $extend = false; |
|
| 330 | + // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
| 331 | + if (isset($this->_caffeinated_extends[ $page ])) { |
|
| 332 | + $this->_current_caf_extend_slug = $page; |
|
| 333 | + $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
| 334 | + $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
| 335 | + $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
| 336 | + add_filter( |
|
| 337 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
| 338 | + function ($path_to_file) use ($caf_path) { |
|
| 339 | + return $caf_path; |
|
| 340 | + } |
|
| 341 | + ); |
|
| 342 | + add_filter( |
|
| 343 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
| 344 | + function ($admin_page) use ($caf_admin_page) { |
|
| 345 | + return $caf_admin_page; |
|
| 346 | + } |
|
| 347 | + ); |
|
| 348 | + $extend = true; |
|
| 349 | + } |
|
| 350 | + // let's do the registered hooks |
|
| 351 | + $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
| 352 | + $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
| 356 | + // first make sure we've got unique values |
|
| 357 | + $hooks_ref = array_unique($hooks_ref); |
|
| 358 | + // now let's loop and require! |
|
| 359 | + foreach ($hooks_ref as $path) { |
|
| 360 | + require_once($path); |
|
| 361 | + } |
|
| 362 | + // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
| 363 | + global $ee_menu_slugs; |
|
| 364 | + $ee_menu_slugs = $this->_menu_slugs; |
|
| 365 | + // we need to loop again to run any early code |
|
| 366 | + foreach ($installed_refs as $page => $path) { |
|
| 367 | + if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
| 368 | + $this->_installed_pages[ $page ]->do_initial_loads(); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * get_admin_page_object |
|
| 377 | + * |
|
| 378 | + * @param string $page_slug |
|
| 379 | + * @return EE_Admin_Page |
|
| 380 | + */ |
|
| 381 | + public function get_admin_page_object($page_slug = '') |
|
| 382 | + { |
|
| 383 | + if (isset($this->_installed_pages[ $page_slug ])) { |
|
| 384 | + return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
| 385 | + } |
|
| 386 | + return null; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * _get_classname_for_admin_page |
|
| 392 | + * generates an "Admin Page" class based on the directory name |
|
| 393 | + * |
|
| 394 | + * @param $dir_name |
|
| 395 | + * @return string |
|
| 396 | + */ |
|
| 397 | + private function _get_classname_for_admin_page($dir_name = '') |
|
| 398 | + { |
|
| 399 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 400 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * _get_classname_for_admin_init_page |
|
| 406 | + * generates an "Admin Page Init" class based on the directory name |
|
| 407 | + * |
|
| 408 | + * @param $dir_name |
|
| 409 | + * @return string |
|
| 410 | + */ |
|
| 411 | + private function _get_classname_for_admin_init_page($dir_name = '') |
|
| 412 | + { |
|
| 413 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 414 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * _load_admin_page |
|
| 420 | + * Loads and instantiates page_init object for a single EE_admin page. |
|
| 421 | + * |
|
| 422 | + * @param string $page page_reference |
|
| 423 | + * @param string $path |
|
| 424 | + * @throws EE_Error |
|
| 425 | + * @return object|bool return page object if valid, bool false if not. |
|
| 426 | + */ |
|
| 427 | + private function _load_admin_page($page = '', $path = '') |
|
| 428 | + { |
|
| 429 | + $class_name = $this->_get_classname_for_admin_init_page($page); |
|
| 430 | + EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
| 431 | + if (! class_exists($class_name)) { |
|
| 432 | + $inner_error_msg = '<br />' |
|
| 433 | + . sprintf( |
|
| 434 | + esc_html__( |
|
| 435 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 436 | + 'event_espresso' |
|
| 437 | + ), |
|
| 438 | + '<strong>' . $class_name . '</strong>' |
|
| 439 | + ); |
|
| 440 | + $error_msg[] = sprintf( |
|
| 441 | + __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
| 442 | + $page |
|
| 443 | + ); |
|
| 444 | + $error_msg[] = $error_msg[0] |
|
| 445 | + . "\r\n" |
|
| 446 | + . sprintf( |
|
| 447 | + esc_html__( |
|
| 448 | + 'There is no Init class in place for the %s admin page.', |
|
| 449 | + 'event_espresso' |
|
| 450 | + ), |
|
| 451 | + $page |
|
| 452 | + ) |
|
| 453 | + . $inner_error_msg; |
|
| 454 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 455 | + } |
|
| 456 | + $a = new ReflectionClass($class_name); |
|
| 457 | + return $a->newInstance(); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * set_menus |
|
| 463 | + * This method sets up the menus for EE Admin Pages |
|
| 464 | + * |
|
| 465 | + * @access private |
|
| 466 | + * @return void |
|
| 467 | + */ |
|
| 468 | + public function set_menus() |
|
| 469 | + { |
|
| 470 | + // prep the menu pages (sort, group.) |
|
| 471 | + $this->_prep_pages(); |
|
| 472 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 473 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 474 | + $menu_map->add_menu_page(false); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * set_network_menus |
|
| 482 | + * This method sets up the menus for network EE Admin Pages. |
|
| 483 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
| 484 | + * are only added to the menu map if they are intended for the admin menu |
|
| 485 | + * |
|
| 486 | + * @return void |
|
| 487 | + */ |
|
| 488 | + public function set_network_menus() |
|
| 489 | + { |
|
| 490 | + $this->_prep_pages(); |
|
| 491 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 492 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 493 | + $menu_map->add_menu_page(true); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * _prep_pages |
|
| 501 | + * sets the _prepped_menu_maps property |
|
| 502 | + * |
|
| 503 | + * @access private |
|
| 504 | + * @throws EE_Error |
|
| 505 | + * @return void |
|
| 506 | + */ |
|
| 507 | + private function _prep_pages() |
|
| 508 | + { |
|
| 509 | + $pages_array = array(); |
|
| 510 | + // rearrange _admin_menu_groups to be indexed by group slug. |
|
| 511 | + $menu_groups = $this->_rearrange_menu_groups(); |
|
| 512 | + foreach ($this->_installed_pages as $page) { |
|
| 513 | + if ($page instanceof EE_Admin_page_Init) { |
|
| 514 | + $page_map = $page->get_menu_map(); |
|
| 515 | + // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
| 516 | + if (is_array($page_map) || empty($page_map)) { |
|
| 517 | + new PersistentAdminNotice( |
|
| 518 | + 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
| 519 | + sprintf( |
|
| 520 | + __( |
|
| 521 | + 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
| 522 | + 'event_espresso' |
|
| 523 | + ), |
|
| 524 | + $page->label |
|
| 525 | + ) |
|
| 526 | + ); |
|
| 527 | + continue; |
|
| 528 | + } |
|
| 529 | + // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
| 530 | + if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 531 | + throw new EE_Error( |
|
| 532 | + sprintf( |
|
| 533 | + __( |
|
| 534 | + 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
| 535 | + 'event_espresso' |
|
| 536 | + ), |
|
| 537 | + $page->label, |
|
| 538 | + $page_map |
|
| 539 | + ) |
|
| 540 | + ); |
|
| 541 | + } |
|
| 542 | + // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
| 543 | + if (empty($page_map->maintenance_mode_parent) |
|
| 544 | + && EE_Maintenance_Mode::instance()->level() |
|
| 545 | + == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 546 | + continue; |
|
| 547 | + } |
|
| 548 | + // assign to group (remember $page_map has the admin page stored in it). |
|
| 549 | + $pages_array[ $page_map->menu_group ][] = $page_map; |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + if (empty($pages_array)) { |
|
| 553 | + throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
| 554 | + } |
|
| 555 | + // let's sort the groups, make sure it's a valid group, add header (if to show). |
|
| 556 | + foreach ($pages_array as $group => $menu_maps) { |
|
| 557 | + // valid_group? |
|
| 558 | + if (! array_key_exists($group, $menu_groups)) { |
|
| 559 | + continue; |
|
| 560 | + } |
|
| 561 | + // sort pages. |
|
| 562 | + usort($menu_maps, array($this, '_sort_menu_maps')); |
|
| 563 | + // prepend header |
|
| 564 | + array_unshift($menu_maps, $menu_groups[ $group ]); |
|
| 565 | + // reset $pages_array with prepped data |
|
| 566 | + $pages_array[ $group ] = $menu_maps; |
|
| 567 | + } |
|
| 568 | + // now let's setup the _prepped_menu_maps property |
|
| 569 | + foreach ($menu_groups as $group => $group_objs) { |
|
| 570 | + if (isset($pages_array[ $group ])) { |
|
| 571 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]); |
|
| 572 | + } |
|
| 573 | + }/**/ |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
| 579 | + * In this method there are three checks being done: |
|
| 580 | + * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
| 581 | + * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
| 582 | + * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
| 583 | + * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
| 584 | + * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
| 585 | + * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
| 586 | + * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
| 587 | + * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
| 588 | + * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
| 589 | + * admin_pages) |
|
| 590 | + * |
|
| 591 | + * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
| 592 | + * loaded. |
|
| 593 | + * @return array |
|
| 594 | + */ |
|
| 595 | + private function _set_caffeinated($installed_refs) |
|
| 596 | + { |
|
| 597 | + |
|
| 598 | + // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
| 599 | + if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 600 | + return $installed_refs; |
|
| 601 | + } |
|
| 602 | + $this->_define_caffeinated_constants(); |
|
| 603 | + $exclude = array('tickets'); |
|
| 604 | + // okay let's setup an "New" pages first (we'll return installed refs later) |
|
| 605 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
| 606 | + if ($new_admin_screens) { |
|
| 607 | + foreach ($new_admin_screens as $admin_screen) { |
|
| 608 | + // files and anything in the exclude array need not apply |
|
| 609 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 610 | + // these folders represent the different NEW EE admin pages |
|
| 611 | + $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
| 612 | + // set autoloaders for our admin page classes based on included path information |
|
| 613 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
| 618 | + $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
| 619 | + if ($extends) { |
|
| 620 | + foreach ($extends as $extend) { |
|
| 621 | + if (is_dir($extend)) { |
|
| 622 | + $extend_ref = basename($extend); |
|
| 623 | + // now let's make sure there is a file that matches the expected format |
|
| 624 | + $filename = str_replace( |
|
| 625 | + ' ', |
|
| 626 | + '_', |
|
| 627 | + ucwords( |
|
| 628 | + str_replace( |
|
| 629 | + '_', |
|
| 630 | + ' ', |
|
| 631 | + $extend_ref |
|
| 632 | + ) |
|
| 633 | + ) |
|
| 634 | + ); |
|
| 635 | + $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
| 636 | + $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
| 637 | + array('\\', '/'), |
|
| 638 | + '/', |
|
| 639 | + EE_CORE_CAF_ADMIN |
|
| 640 | + . 'extend/' |
|
| 641 | + . $extend_ref |
|
| 642 | + . '/' |
|
| 643 | + . $filename |
|
| 644 | + . '.core.php' |
|
| 645 | + ); |
|
| 646 | + $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
| 647 | + // set autoloaders for our admin page classes based on included path information |
|
| 648 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
| 653 | + $ee_admin_hooks = array(); |
|
| 654 | + $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
| 655 | + if ($hooks) { |
|
| 656 | + foreach ($hooks as $hook) { |
|
| 657 | + if (is_readable($hook)) { |
|
| 658 | + require_once $hook; |
|
| 659 | + $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
| 660 | + $classname = str_replace('.class.php', '', $classname); |
|
| 661 | + if (class_exists($classname)) { |
|
| 662 | + $a = new ReflectionClass($classname); |
|
| 663 | + $ee_admin_hooks[] = $a->newInstance(); |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + }/**/ |
|
| 668 | + $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
| 669 | + return $installed_refs; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Utility method for sorting the _menu_maps (callback for usort php function) |
|
| 675 | + * |
|
| 676 | + * @since 4.4.0 |
|
| 677 | + * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
| 678 | + * @param EE_Admin_Page_Menu_Map $b being compared to |
|
| 679 | + * @return int sort order |
|
| 680 | + */ |
|
| 681 | + private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
| 682 | + { |
|
| 683 | + if ($a->menu_order == $b->menu_order) { |
|
| 684 | + return 0; |
|
| 685 | + } |
|
| 686 | + return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * _default_header_link |
|
| 692 | + * This is just a dummy method to use with header submenu items |
|
| 693 | + * |
|
| 694 | + * @return bool false |
|
| 695 | + */ |
|
| 696 | + public function _default_header_link() |
|
| 697 | + { |
|
| 698 | + return false; |
|
| 699 | + } |
|
| 700 | 700 | } |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | private function _define_caffeinated_constants() |
| 122 | 122 | { |
| 123 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 124 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 125 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 126 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 127 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 128 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 129 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 123 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
| 124 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
| 125 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
| 126 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
| 127 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
| 128 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
| 129 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
| 238 | 238 | usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
| 239 | 239 | foreach ($this->_admin_menu_groups as $group) { |
| 240 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 240 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 241 | 241 | throw new EE_Error( |
| 242 | 242 | sprintf( |
| 243 | 243 | __( |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | ) |
| 249 | 249 | ); |
| 250 | 250 | } |
| 251 | - $groups[ $group->menu_slug ] = $group; |
|
| 251 | + $groups[$group->menu_slug] = $group; |
|
| 252 | 252 | } |
| 253 | 253 | return $groups; |
| 254 | 254 | } |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | $installed_refs = array(); |
| 268 | 268 | $exclude = array('assets', 'templates'); |
| 269 | 269 | // grab everything in the admin core directory |
| 270 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
| 270 | + $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR); |
|
| 271 | 271 | if ($admin_screens) { |
| 272 | 272 | foreach ($admin_screens as $admin_screen) { |
| 273 | 273 | // files and anything in the exclude array need not apply |
| 274 | 274 | if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
| 275 | 275 | // these folders represent the different EE admin pages |
| 276 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
| 276 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
| 283 | 283 | 'event_espresso' |
| 284 | 284 | ); |
| 285 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
| 285 | + $error_msg[] = $error_msg[0]."\r\n" |
|
| 286 | 286 | . sprintf( |
| 287 | 287 | __( |
| 288 | 288 | 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
@@ -309,46 +309,46 @@ discard block |
||
| 309 | 309 | // set autoloaders for our admin page classes based on included path information |
| 310 | 310 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
| 311 | 311 | // build list of installed pages |
| 312 | - $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
| 312 | + $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
| 313 | 313 | // verify returned object |
| 314 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
| 315 | - if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 314 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
| 315 | + if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 316 | 316 | continue; |
| 317 | 317 | } |
| 318 | 318 | // skip if in full maintenance mode and maintenance_mode_parent is set |
| 319 | - $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
| 319 | + $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
| 320 | 320 | if (empty($maintenance_mode_parent) |
| 321 | 321 | && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
| 322 | 322 | ) { |
| 323 | - unset($installed_refs[ $page ]); |
|
| 323 | + unset($installed_refs[$page]); |
|
| 324 | 324 | continue; |
| 325 | 325 | } |
| 326 | - $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
| 327 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
| 326 | + $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug; |
|
| 327 | + $this->_menu_slugs[$menu_slug] = $page; |
|
| 328 | 328 | // flag for register hooks on extended pages b/c extended pages use the default INIT. |
| 329 | 329 | $extend = false; |
| 330 | 330 | // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
| 331 | - if (isset($this->_caffeinated_extends[ $page ])) { |
|
| 331 | + if (isset($this->_caffeinated_extends[$page])) { |
|
| 332 | 332 | $this->_current_caf_extend_slug = $page; |
| 333 | - $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
| 334 | - $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
| 335 | - $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
| 333 | + $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name(); |
|
| 334 | + $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path']; |
|
| 335 | + $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page']; |
|
| 336 | 336 | add_filter( |
| 337 | 337 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
| 338 | - function ($path_to_file) use ($caf_path) { |
|
| 338 | + function($path_to_file) use ($caf_path) { |
|
| 339 | 339 | return $caf_path; |
| 340 | 340 | } |
| 341 | 341 | ); |
| 342 | 342 | add_filter( |
| 343 | 343 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
| 344 | - function ($admin_page) use ($caf_admin_page) { |
|
| 344 | + function($admin_page) use ($caf_admin_page) { |
|
| 345 | 345 | return $caf_admin_page; |
| 346 | 346 | } |
| 347 | 347 | ); |
| 348 | 348 | $extend = true; |
| 349 | 349 | } |
| 350 | 350 | // let's do the registered hooks |
| 351 | - $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
| 351 | + $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
| 352 | 352 | $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
| 353 | 353 | } |
| 354 | 354 | } |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | $ee_menu_slugs = $this->_menu_slugs; |
| 365 | 365 | // we need to loop again to run any early code |
| 366 | 366 | foreach ($installed_refs as $page => $path) { |
| 367 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
| 368 | - $this->_installed_pages[ $page ]->do_initial_loads(); |
|
| 367 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
| 368 | + $this->_installed_pages[$page]->do_initial_loads(); |
|
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
@@ -380,8 +380,8 @@ discard block |
||
| 380 | 380 | */ |
| 381 | 381 | public function get_admin_page_object($page_slug = '') |
| 382 | 382 | { |
| 383 | - if (isset($this->_installed_pages[ $page_slug ])) { |
|
| 384 | - return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
| 383 | + if (isset($this->_installed_pages[$page_slug])) { |
|
| 384 | + return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
| 385 | 385 | } |
| 386 | 386 | return null; |
| 387 | 387 | } |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | private function _get_classname_for_admin_page($dir_name = '') |
| 398 | 398 | { |
| 399 | 399 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
| 400 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
| 400 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page'; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | private function _get_classname_for_admin_init_page($dir_name = '') |
| 412 | 412 | { |
| 413 | 413 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
| 414 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 414 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
@@ -428,14 +428,14 @@ discard block |
||
| 428 | 428 | { |
| 429 | 429 | $class_name = $this->_get_classname_for_admin_init_page($page); |
| 430 | 430 | EE_Registry::instance()->load_file($path, $class_name, 'core'); |
| 431 | - if (! class_exists($class_name)) { |
|
| 431 | + if ( ! class_exists($class_name)) { |
|
| 432 | 432 | $inner_error_msg = '<br />' |
| 433 | 433 | . sprintf( |
| 434 | 434 | esc_html__( |
| 435 | 435 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
| 436 | 436 | 'event_espresso' |
| 437 | 437 | ), |
| 438 | - '<strong>' . $class_name . '</strong>' |
|
| 438 | + '<strong>'.$class_name.'</strong>' |
|
| 439 | 439 | ); |
| 440 | 440 | $error_msg[] = sprintf( |
| 441 | 441 | __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
| 516 | 516 | if (is_array($page_map) || empty($page_map)) { |
| 517 | 517 | new PersistentAdminNotice( |
| 518 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
| 518 | + 'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION, |
|
| 519 | 519 | sprintf( |
| 520 | 520 | __( |
| 521 | 521 | 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | continue; |
| 528 | 528 | } |
| 529 | 529 | // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
| 530 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 530 | + if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 531 | 531 | throw new EE_Error( |
| 532 | 532 | sprintf( |
| 533 | 533 | __( |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | continue; |
| 547 | 547 | } |
| 548 | 548 | // assign to group (remember $page_map has the admin page stored in it). |
| 549 | - $pages_array[ $page_map->menu_group ][] = $page_map; |
|
| 549 | + $pages_array[$page_map->menu_group][] = $page_map; |
|
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | if (empty($pages_array)) { |
@@ -555,20 +555,20 @@ discard block |
||
| 555 | 555 | // let's sort the groups, make sure it's a valid group, add header (if to show). |
| 556 | 556 | foreach ($pages_array as $group => $menu_maps) { |
| 557 | 557 | // valid_group? |
| 558 | - if (! array_key_exists($group, $menu_groups)) { |
|
| 558 | + if ( ! array_key_exists($group, $menu_groups)) { |
|
| 559 | 559 | continue; |
| 560 | 560 | } |
| 561 | 561 | // sort pages. |
| 562 | 562 | usort($menu_maps, array($this, '_sort_menu_maps')); |
| 563 | 563 | // prepend header |
| 564 | - array_unshift($menu_maps, $menu_groups[ $group ]); |
|
| 564 | + array_unshift($menu_maps, $menu_groups[$group]); |
|
| 565 | 565 | // reset $pages_array with prepped data |
| 566 | - $pages_array[ $group ] = $menu_maps; |
|
| 566 | + $pages_array[$group] = $menu_maps; |
|
| 567 | 567 | } |
| 568 | 568 | // now let's setup the _prepped_menu_maps property |
| 569 | 569 | foreach ($menu_groups as $group => $group_objs) { |
| 570 | - if (isset($pages_array[ $group ])) { |
|
| 571 | - $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]); |
|
| 570 | + if (isset($pages_array[$group])) { |
|
| 571 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
| 572 | 572 | } |
| 573 | 573 | }/**/ |
| 574 | 574 | } |
@@ -596,26 +596,26 @@ discard block |
||
| 596 | 596 | { |
| 597 | 597 | |
| 598 | 598 | // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
| 599 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 599 | + if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated/admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 600 | 600 | return $installed_refs; |
| 601 | 601 | } |
| 602 | 602 | $this->_define_caffeinated_constants(); |
| 603 | 603 | $exclude = array('tickets'); |
| 604 | 604 | // okay let's setup an "New" pages first (we'll return installed refs later) |
| 605 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
| 605 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR); |
|
| 606 | 606 | if ($new_admin_screens) { |
| 607 | 607 | foreach ($new_admin_screens as $admin_screen) { |
| 608 | 608 | // files and anything in the exclude array need not apply |
| 609 | 609 | if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
| 610 | 610 | // these folders represent the different NEW EE admin pages |
| 611 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
| 611 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
| 612 | 612 | // set autoloaders for our admin page classes based on included path information |
| 613 | 613 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
| 618 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
| 618 | + $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR); |
|
| 619 | 619 | if ($extends) { |
| 620 | 620 | foreach ($extends as $extend) { |
| 621 | 621 | if (is_dir($extend)) { |
@@ -632,8 +632,8 @@ discard block |
||
| 632 | 632 | ) |
| 633 | 633 | ) |
| 634 | 634 | ); |
| 635 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
| 636 | - $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
| 635 | + $filename = 'Extend_'.$filename.'_Admin_Page'; |
|
| 636 | + $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
| 637 | 637 | array('\\', '/'), |
| 638 | 638 | '/', |
| 639 | 639 | EE_CORE_CAF_ADMIN |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | . $filename |
| 644 | 644 | . '.core.php' |
| 645 | 645 | ); |
| 646 | - $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
| 646 | + $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
| 647 | 647 | // set autoloaders for our admin page classes based on included path information |
| 648 | 648 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
| 649 | 649 | } |
@@ -651,12 +651,12 @@ discard block |
||
| 651 | 651 | } |
| 652 | 652 | // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
| 653 | 653 | $ee_admin_hooks = array(); |
| 654 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
| 654 | + $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php'); |
|
| 655 | 655 | if ($hooks) { |
| 656 | 656 | foreach ($hooks as $hook) { |
| 657 | 657 | if (is_readable($hook)) { |
| 658 | 658 | require_once $hook; |
| 659 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
| 659 | + $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook); |
|
| 660 | 660 | $classname = str_replace('.class.php', '', $classname); |
| 661 | 661 | if (class_exists($classname)) { |
| 662 | 662 | $a = new ReflectionClass($classname); |
@@ -13,424 +13,424 @@ |
||
| 13 | 13 | abstract class EE_Admin_Page_Init extends EE_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - // identity properties (set in _set_defaults and _set_init_properties) |
|
| 17 | - public $label; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
| 21 | - * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - public $capability; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This holds the menu map object for this admin page. |
|
| 30 | - * |
|
| 31 | - * @var EE_Admin_Page_Menu_Map |
|
| 32 | - */ |
|
| 33 | - protected $_menu_map; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * deprecated |
|
| 37 | - */ |
|
| 38 | - public $menu_label; |
|
| 39 | - public $menu_slug; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - // set in _set_defaults |
|
| 43 | - protected $_folder_name; |
|
| 44 | - protected $_folder_path; |
|
| 45 | - protected $_file_name; |
|
| 46 | - public $hook_file; |
|
| 47 | - protected $_wp_page_slug; |
|
| 48 | - protected $_routing; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - // will hold page object. |
|
| 52 | - protected $_loaded_page_object; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - // for caf |
|
| 56 | - protected $_files_hooked; |
|
| 57 | - protected $_hook_paths; |
|
| 58 | - |
|
| 59 | - // load_page? |
|
| 60 | - private $_load_page; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @Constructor |
|
| 65 | - * @access public |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function __construct() |
|
| 69 | - { |
|
| 70 | - // set global defaults |
|
| 71 | - $this->_set_defaults(); |
|
| 72 | - // set properties that are always available with objects. |
|
| 73 | - $this->_set_init_properties(); |
|
| 74 | - // global styles/scripts across all wp admin pages |
|
| 75 | - add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
| 76 | - // load initial stuff. |
|
| 77 | - $this->_set_file_and_folder_name(); |
|
| 78 | - $this->_set_menu_map(); |
|
| 79 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 80 | - EE_Error::doing_it_wrong( |
|
| 81 | - get_class($this) . '::$_menu_map', |
|
| 82 | - sprintf( |
|
| 83 | - __( |
|
| 84 | - 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
| 85 | - 'event_espresso' |
|
| 86 | - ), |
|
| 87 | - get_class($this) |
|
| 88 | - ), |
|
| 89 | - '4.4.0' |
|
| 90 | - ); |
|
| 91 | - return; |
|
| 92 | - } |
|
| 93 | - // set default capability |
|
| 94 | - $this->_set_capability(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * _set_init_properties |
|
| 100 | - * Child classes use to set the following properties: |
|
| 101 | - * $label |
|
| 102 | - * |
|
| 103 | - * @abstract |
|
| 104 | - * @access protected |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - abstract protected function _set_init_properties(); |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
| 112 | - * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
| 113 | - * |
|
| 114 | - * @since 4.4.0 |
|
| 115 | - * @ return void. |
|
| 116 | - */ |
|
| 117 | - protected function _set_menu_map() |
|
| 118 | - { |
|
| 119 | - return array(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * returns the menu map for this admin page |
|
| 125 | - * |
|
| 126 | - * @since 4.4.0 |
|
| 127 | - * @return EE_Admin_Page_Menu_Map |
|
| 128 | - */ |
|
| 129 | - public function get_menu_map() |
|
| 130 | - { |
|
| 131 | - return $this->_menu_map; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * This loads scripts and styles for the EE_Admin system |
|
| 137 | - * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
| 138 | - * |
|
| 139 | - * @return void |
|
| 140 | - */ |
|
| 141 | - public function load_wp_global_scripts_styles() |
|
| 142 | - { |
|
| 143 | - wp_register_style( |
|
| 144 | - 'espresso_menu', |
|
| 145 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 146 | - array('dashicons'), |
|
| 147 | - EVENT_ESPRESSO_VERSION |
|
| 148 | - ); |
|
| 149 | - wp_enqueue_style('espresso_menu'); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * this sets default properties (might be overridden in _set_init_properties); |
|
| 155 | - * |
|
| 156 | - * @access private |
|
| 157 | - * @return void |
|
| 158 | - */ |
|
| 159 | - private function _set_defaults() |
|
| 160 | - { |
|
| 161 | - $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
| 162 | - $this->_routing = true; |
|
| 163 | - $this->_load_page = false; |
|
| 164 | - $this->_files_hooked = $this->_hook_paths = array(); |
|
| 165 | - // menu_map |
|
| 166 | - $this->_menu_map = $this->get_menu_map(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - protected function _set_capability() |
|
| 171 | - { |
|
| 172 | - $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
| 173 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * initialize_admin_page |
|
| 179 | - * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
| 180 | - * EE_Admin_Init class. |
|
| 181 | - * |
|
| 182 | - * @access public |
|
| 183 | - * @uses _initialize_admin_page() |
|
| 184 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 185 | - * @return void |
|
| 186 | - */ |
|
| 187 | - public function initialize_admin_page() |
|
| 188 | - { |
|
| 189 | - // let's check user access first |
|
| 190 | - $this->_check_user_access(); |
|
| 191 | - if (! is_object($this->_loaded_page_object)) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $this->_loaded_page_object->route_admin_request(); |
|
| 195 | - return; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - public function set_page_dependencies($wp_page_slug) |
|
| 200 | - { |
|
| 201 | - if (! $this->_load_page) { |
|
| 202 | - return; |
|
| 203 | - } |
|
| 204 | - if (! is_object($this->_loaded_page_object)) { |
|
| 205 | - $msg[] = __( |
|
| 206 | - 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
| 207 | - 'event_espresso' |
|
| 208 | - ); |
|
| 209 | - $msg[] = $msg[0] . "\r\n" |
|
| 210 | - . sprintf( |
|
| 211 | - __( |
|
| 212 | - 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
| 213 | - 'event_espresso' |
|
| 214 | - ), |
|
| 215 | - $this->_file_name, |
|
| 216 | - $this->_file_name, |
|
| 217 | - $this->_folder_path . $this->_file_name, |
|
| 218 | - $this->_menu_map->menu_slug |
|
| 219 | - ); |
|
| 220 | - throw new EE_Error(implode('||', $msg)); |
|
| 221 | - } |
|
| 222 | - $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
| 223 | - $page_hook = 'load-' . $wp_page_slug; |
|
| 224 | - // hook into page load hook so all page specific stuff get's loaded. |
|
| 225 | - if (! empty($wp_page_slug)) { |
|
| 226 | - add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
| 233 | - * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
| 234 | - * |
|
| 235 | - * @return void |
|
| 236 | - */ |
|
| 237 | - public function do_initial_loads() |
|
| 238 | - { |
|
| 239 | - // no loading or initializing if menu map is setup incorrectly. |
|
| 240 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 241 | - return; |
|
| 242 | - } |
|
| 243 | - $this->_initialize_admin_page(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * all we're doing here is setting the $_file_name property for later use. |
|
| 249 | - * |
|
| 250 | - * @access private |
|
| 251 | - * @return void |
|
| 252 | - */ |
|
| 253 | - private function _set_file_and_folder_name() |
|
| 254 | - { |
|
| 255 | - $bt = debug_backtrace(); |
|
| 256 | - // for more reliable determination of folder name |
|
| 257 | - // we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
| 258 | - $class = get_class($this); |
|
| 259 | - foreach ($bt as $index => $values) { |
|
| 260 | - if (isset($values['class']) && $values['class'] == $class) { |
|
| 261 | - $file_index = $index - 1; |
|
| 262 | - $this->_folder_name = basename(dirname($bt[ $file_index ]['file'])); |
|
| 263 | - if (! empty($this->_folder_name)) { |
|
| 264 | - break; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/'; |
|
| 269 | - $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
| 270 | - $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
| 271 | - $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
| 277 | - * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
| 278 | - * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
| 279 | - * events_Messages_Hooks.class.php |
|
| 280 | - * |
|
| 281 | - * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
| 282 | - * files/classes |
|
| 283 | - * @return array |
|
| 284 | - */ |
|
| 285 | - public function register_hooks($extend = false) |
|
| 286 | - { |
|
| 287 | - |
|
| 288 | - // get a list of files in the directory that have the "Hook" in their name an |
|
| 289 | - // if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
| 290 | - if ($extend) { |
|
| 291 | - $hook_files_glob_path = apply_filters( |
|
| 292 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
| 293 | - EE_CORE_CAF_ADMIN_EXTEND |
|
| 294 | - . $this->_folder_name |
|
| 295 | - . '/*' |
|
| 296 | - . $this->_file_name |
|
| 297 | - . '_Hooks_Extend.class.php' |
|
| 298 | - ); |
|
| 299 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 300 | - } |
|
| 301 | - // loop through decaf folders |
|
| 302 | - $hook_files_glob_path = apply_filters( |
|
| 303 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
| 304 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 305 | - ); |
|
| 306 | - $this->_hook_paths = array_merge( |
|
| 307 | - $this->_register_hook_files($hook_files_glob_path), |
|
| 308 | - $this->_hook_paths |
|
| 309 | - ); // making sure any extended hook paths are later in the array than the core hook paths! |
|
| 310 | - return $this->_hook_paths; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
| 315 | - { |
|
| 316 | - $hook_paths = array(); |
|
| 317 | - if ($hook_files = glob($hook_files_glob_path)) { |
|
| 318 | - if (empty($hook_files)) { |
|
| 319 | - return array(); |
|
| 320 | - } |
|
| 321 | - foreach ($hook_files as $file) { |
|
| 322 | - // lets get the linked admin. |
|
| 323 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file) |
|
| 324 | - : str_replace($this->_folder_path, '', $file); |
|
| 325 | - $replace = $extend |
|
| 326 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 327 | - : '_' |
|
| 328 | - . $this->_file_name |
|
| 329 | - . '_Hooks.class.php'; |
|
| 330 | - $rel_admin = str_replace($replace, '', $hook_file); |
|
| 331 | - $rel_admin = strtolower($rel_admin); |
|
| 332 | - $hook_paths[] = $file; |
|
| 333 | - // make sure we haven't already got a hook setup for this page path |
|
| 334 | - if (in_array($rel_admin, $this->_files_hooked)) { |
|
| 335 | - continue; |
|
| 336 | - } |
|
| 337 | - $this->hook_file = $hook_file; |
|
| 338 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 339 | - $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
| 340 | - $this->_files_hooked[] = $rel_admin; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - return $hook_paths; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - public function load_admin_hook($registered_pages) |
|
| 348 | - { |
|
| 349 | - $this->hook_file; |
|
| 350 | - $hook_file = (array) $this->hook_file; |
|
| 351 | - return array_merge($hook_file, $registered_pages); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * _initialize_admin_page |
|
| 357 | - * |
|
| 358 | - * @see initialize_admin_page() for info |
|
| 359 | - */ |
|
| 360 | - protected function _initialize_admin_page() |
|
| 361 | - { |
|
| 362 | - |
|
| 363 | - // JUST CHECK WE'RE ON RIGHT PAGE. |
|
| 364 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 365 | - return; |
|
| 366 | - } //not on the right page so let's get out. |
|
| 367 | - $this->_load_page = true; |
|
| 368 | - |
|
| 369 | - // we don't need to do a page_request check here because it's only called via WP menu system. |
|
| 370 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 371 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 372 | - $admin_page = apply_filters( |
|
| 373 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
| 374 | - $admin_page |
|
| 375 | - ); |
|
| 376 | - // define requested admin page class name then load the file and instantiate |
|
| 377 | - $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php'); |
|
| 378 | - $path_to_file = apply_filters( |
|
| 379 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
| 380 | - $path_to_file |
|
| 381 | - );// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 382 | - if (is_readable($path_to_file)) { |
|
| 383 | - // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
| 384 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
| 385 | - do_action( |
|
| 386 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 387 | - ); |
|
| 388 | - require_once($path_to_file); |
|
| 389 | - $a = new ReflectionClass($admin_page); |
|
| 390 | - $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
| 391 | - } |
|
| 392 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
| 393 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - public function get_admin_page_name() |
|
| 398 | - { |
|
| 399 | - return $this->_file_name . '_Admin_Page'; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @return mixed |
|
| 405 | - */ |
|
| 406 | - public function loaded_page_object() |
|
| 407 | - { |
|
| 408 | - return $this->_loaded_page_object; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - // public function set_autoloaders($className) |
|
| 413 | - // { |
|
| 414 | - // $dir_ref = array( |
|
| 415 | - // $this->_folder_path => array('core', 'class'), |
|
| 416 | - // ); |
|
| 417 | - // EEH_Autoloader::try_autoload($dir_ref, $className); |
|
| 418 | - // } |
|
| 419 | - /** |
|
| 420 | - * _check_user_access |
|
| 421 | - * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
| 422 | - * WordPress die message. |
|
| 423 | - * |
|
| 424 | - * @return bool|die true if pass (or admin) wp_die if fail |
|
| 425 | - */ |
|
| 426 | - private function _check_user_access() |
|
| 427 | - { |
|
| 428 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 429 | - $this->_menu_map->capability, |
|
| 430 | - $this->_menu_map->menu_slug |
|
| 431 | - )) { |
|
| 432 | - wp_die(__('You don\'t have access to this page.', 'event_espresso'), '', array('back_link' => true)); |
|
| 433 | - } |
|
| 434 | - return true; |
|
| 435 | - } |
|
| 16 | + // identity properties (set in _set_defaults and _set_init_properties) |
|
| 17 | + public $label; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
| 21 | + * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + public $capability; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This holds the menu map object for this admin page. |
|
| 30 | + * |
|
| 31 | + * @var EE_Admin_Page_Menu_Map |
|
| 32 | + */ |
|
| 33 | + protected $_menu_map; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * deprecated |
|
| 37 | + */ |
|
| 38 | + public $menu_label; |
|
| 39 | + public $menu_slug; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + // set in _set_defaults |
|
| 43 | + protected $_folder_name; |
|
| 44 | + protected $_folder_path; |
|
| 45 | + protected $_file_name; |
|
| 46 | + public $hook_file; |
|
| 47 | + protected $_wp_page_slug; |
|
| 48 | + protected $_routing; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + // will hold page object. |
|
| 52 | + protected $_loaded_page_object; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + // for caf |
|
| 56 | + protected $_files_hooked; |
|
| 57 | + protected $_hook_paths; |
|
| 58 | + |
|
| 59 | + // load_page? |
|
| 60 | + private $_load_page; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @Constructor |
|
| 65 | + * @access public |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function __construct() |
|
| 69 | + { |
|
| 70 | + // set global defaults |
|
| 71 | + $this->_set_defaults(); |
|
| 72 | + // set properties that are always available with objects. |
|
| 73 | + $this->_set_init_properties(); |
|
| 74 | + // global styles/scripts across all wp admin pages |
|
| 75 | + add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
| 76 | + // load initial stuff. |
|
| 77 | + $this->_set_file_and_folder_name(); |
|
| 78 | + $this->_set_menu_map(); |
|
| 79 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 80 | + EE_Error::doing_it_wrong( |
|
| 81 | + get_class($this) . '::$_menu_map', |
|
| 82 | + sprintf( |
|
| 83 | + __( |
|
| 84 | + 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
| 85 | + 'event_espresso' |
|
| 86 | + ), |
|
| 87 | + get_class($this) |
|
| 88 | + ), |
|
| 89 | + '4.4.0' |
|
| 90 | + ); |
|
| 91 | + return; |
|
| 92 | + } |
|
| 93 | + // set default capability |
|
| 94 | + $this->_set_capability(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * _set_init_properties |
|
| 100 | + * Child classes use to set the following properties: |
|
| 101 | + * $label |
|
| 102 | + * |
|
| 103 | + * @abstract |
|
| 104 | + * @access protected |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + abstract protected function _set_init_properties(); |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
| 112 | + * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
| 113 | + * |
|
| 114 | + * @since 4.4.0 |
|
| 115 | + * @ return void. |
|
| 116 | + */ |
|
| 117 | + protected function _set_menu_map() |
|
| 118 | + { |
|
| 119 | + return array(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * returns the menu map for this admin page |
|
| 125 | + * |
|
| 126 | + * @since 4.4.0 |
|
| 127 | + * @return EE_Admin_Page_Menu_Map |
|
| 128 | + */ |
|
| 129 | + public function get_menu_map() |
|
| 130 | + { |
|
| 131 | + return $this->_menu_map; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * This loads scripts and styles for the EE_Admin system |
|
| 137 | + * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
| 138 | + * |
|
| 139 | + * @return void |
|
| 140 | + */ |
|
| 141 | + public function load_wp_global_scripts_styles() |
|
| 142 | + { |
|
| 143 | + wp_register_style( |
|
| 144 | + 'espresso_menu', |
|
| 145 | + EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 146 | + array('dashicons'), |
|
| 147 | + EVENT_ESPRESSO_VERSION |
|
| 148 | + ); |
|
| 149 | + wp_enqueue_style('espresso_menu'); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * this sets default properties (might be overridden in _set_init_properties); |
|
| 155 | + * |
|
| 156 | + * @access private |
|
| 157 | + * @return void |
|
| 158 | + */ |
|
| 159 | + private function _set_defaults() |
|
| 160 | + { |
|
| 161 | + $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
| 162 | + $this->_routing = true; |
|
| 163 | + $this->_load_page = false; |
|
| 164 | + $this->_files_hooked = $this->_hook_paths = array(); |
|
| 165 | + // menu_map |
|
| 166 | + $this->_menu_map = $this->get_menu_map(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + protected function _set_capability() |
|
| 171 | + { |
|
| 172 | + $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
| 173 | + $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * initialize_admin_page |
|
| 179 | + * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
| 180 | + * EE_Admin_Init class. |
|
| 181 | + * |
|
| 182 | + * @access public |
|
| 183 | + * @uses _initialize_admin_page() |
|
| 184 | + * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 185 | + * @return void |
|
| 186 | + */ |
|
| 187 | + public function initialize_admin_page() |
|
| 188 | + { |
|
| 189 | + // let's check user access first |
|
| 190 | + $this->_check_user_access(); |
|
| 191 | + if (! is_object($this->_loaded_page_object)) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $this->_loaded_page_object->route_admin_request(); |
|
| 195 | + return; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + public function set_page_dependencies($wp_page_slug) |
|
| 200 | + { |
|
| 201 | + if (! $this->_load_page) { |
|
| 202 | + return; |
|
| 203 | + } |
|
| 204 | + if (! is_object($this->_loaded_page_object)) { |
|
| 205 | + $msg[] = __( |
|
| 206 | + 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
| 207 | + 'event_espresso' |
|
| 208 | + ); |
|
| 209 | + $msg[] = $msg[0] . "\r\n" |
|
| 210 | + . sprintf( |
|
| 211 | + __( |
|
| 212 | + 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
| 213 | + 'event_espresso' |
|
| 214 | + ), |
|
| 215 | + $this->_file_name, |
|
| 216 | + $this->_file_name, |
|
| 217 | + $this->_folder_path . $this->_file_name, |
|
| 218 | + $this->_menu_map->menu_slug |
|
| 219 | + ); |
|
| 220 | + throw new EE_Error(implode('||', $msg)); |
|
| 221 | + } |
|
| 222 | + $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
| 223 | + $page_hook = 'load-' . $wp_page_slug; |
|
| 224 | + // hook into page load hook so all page specific stuff get's loaded. |
|
| 225 | + if (! empty($wp_page_slug)) { |
|
| 226 | + add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
| 233 | + * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
| 234 | + * |
|
| 235 | + * @return void |
|
| 236 | + */ |
|
| 237 | + public function do_initial_loads() |
|
| 238 | + { |
|
| 239 | + // no loading or initializing if menu map is setup incorrectly. |
|
| 240 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 243 | + $this->_initialize_admin_page(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * all we're doing here is setting the $_file_name property for later use. |
|
| 249 | + * |
|
| 250 | + * @access private |
|
| 251 | + * @return void |
|
| 252 | + */ |
|
| 253 | + private function _set_file_and_folder_name() |
|
| 254 | + { |
|
| 255 | + $bt = debug_backtrace(); |
|
| 256 | + // for more reliable determination of folder name |
|
| 257 | + // we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
| 258 | + $class = get_class($this); |
|
| 259 | + foreach ($bt as $index => $values) { |
|
| 260 | + if (isset($values['class']) && $values['class'] == $class) { |
|
| 261 | + $file_index = $index - 1; |
|
| 262 | + $this->_folder_name = basename(dirname($bt[ $file_index ]['file'])); |
|
| 263 | + if (! empty($this->_folder_name)) { |
|
| 264 | + break; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/'; |
|
| 269 | + $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
| 270 | + $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
| 271 | + $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
| 277 | + * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
| 278 | + * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
| 279 | + * events_Messages_Hooks.class.php |
|
| 280 | + * |
|
| 281 | + * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
| 282 | + * files/classes |
|
| 283 | + * @return array |
|
| 284 | + */ |
|
| 285 | + public function register_hooks($extend = false) |
|
| 286 | + { |
|
| 287 | + |
|
| 288 | + // get a list of files in the directory that have the "Hook" in their name an |
|
| 289 | + // if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
| 290 | + if ($extend) { |
|
| 291 | + $hook_files_glob_path = apply_filters( |
|
| 292 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
| 293 | + EE_CORE_CAF_ADMIN_EXTEND |
|
| 294 | + . $this->_folder_name |
|
| 295 | + . '/*' |
|
| 296 | + . $this->_file_name |
|
| 297 | + . '_Hooks_Extend.class.php' |
|
| 298 | + ); |
|
| 299 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 300 | + } |
|
| 301 | + // loop through decaf folders |
|
| 302 | + $hook_files_glob_path = apply_filters( |
|
| 303 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
| 304 | + $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 305 | + ); |
|
| 306 | + $this->_hook_paths = array_merge( |
|
| 307 | + $this->_register_hook_files($hook_files_glob_path), |
|
| 308 | + $this->_hook_paths |
|
| 309 | + ); // making sure any extended hook paths are later in the array than the core hook paths! |
|
| 310 | + return $this->_hook_paths; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
| 315 | + { |
|
| 316 | + $hook_paths = array(); |
|
| 317 | + if ($hook_files = glob($hook_files_glob_path)) { |
|
| 318 | + if (empty($hook_files)) { |
|
| 319 | + return array(); |
|
| 320 | + } |
|
| 321 | + foreach ($hook_files as $file) { |
|
| 322 | + // lets get the linked admin. |
|
| 323 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file) |
|
| 324 | + : str_replace($this->_folder_path, '', $file); |
|
| 325 | + $replace = $extend |
|
| 326 | + ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 327 | + : '_' |
|
| 328 | + . $this->_file_name |
|
| 329 | + . '_Hooks.class.php'; |
|
| 330 | + $rel_admin = str_replace($replace, '', $hook_file); |
|
| 331 | + $rel_admin = strtolower($rel_admin); |
|
| 332 | + $hook_paths[] = $file; |
|
| 333 | + // make sure we haven't already got a hook setup for this page path |
|
| 334 | + if (in_array($rel_admin, $this->_files_hooked)) { |
|
| 335 | + continue; |
|
| 336 | + } |
|
| 337 | + $this->hook_file = $hook_file; |
|
| 338 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 339 | + $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
| 340 | + $this->_files_hooked[] = $rel_admin; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + return $hook_paths; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + public function load_admin_hook($registered_pages) |
|
| 348 | + { |
|
| 349 | + $this->hook_file; |
|
| 350 | + $hook_file = (array) $this->hook_file; |
|
| 351 | + return array_merge($hook_file, $registered_pages); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * _initialize_admin_page |
|
| 357 | + * |
|
| 358 | + * @see initialize_admin_page() for info |
|
| 359 | + */ |
|
| 360 | + protected function _initialize_admin_page() |
|
| 361 | + { |
|
| 362 | + |
|
| 363 | + // JUST CHECK WE'RE ON RIGHT PAGE. |
|
| 364 | + if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 365 | + return; |
|
| 366 | + } //not on the right page so let's get out. |
|
| 367 | + $this->_load_page = true; |
|
| 368 | + |
|
| 369 | + // we don't need to do a page_request check here because it's only called via WP menu system. |
|
| 370 | + $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 371 | + $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 372 | + $admin_page = apply_filters( |
|
| 373 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
| 374 | + $admin_page |
|
| 375 | + ); |
|
| 376 | + // define requested admin page class name then load the file and instantiate |
|
| 377 | + $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php'); |
|
| 378 | + $path_to_file = apply_filters( |
|
| 379 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
| 380 | + $path_to_file |
|
| 381 | + );// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 382 | + if (is_readable($path_to_file)) { |
|
| 383 | + // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
| 384 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
| 385 | + do_action( |
|
| 386 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 387 | + ); |
|
| 388 | + require_once($path_to_file); |
|
| 389 | + $a = new ReflectionClass($admin_page); |
|
| 390 | + $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
| 391 | + } |
|
| 392 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
| 393 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + public function get_admin_page_name() |
|
| 398 | + { |
|
| 399 | + return $this->_file_name . '_Admin_Page'; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @return mixed |
|
| 405 | + */ |
|
| 406 | + public function loaded_page_object() |
|
| 407 | + { |
|
| 408 | + return $this->_loaded_page_object; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + // public function set_autoloaders($className) |
|
| 413 | + // { |
|
| 414 | + // $dir_ref = array( |
|
| 415 | + // $this->_folder_path => array('core', 'class'), |
|
| 416 | + // ); |
|
| 417 | + // EEH_Autoloader::try_autoload($dir_ref, $className); |
|
| 418 | + // } |
|
| 419 | + /** |
|
| 420 | + * _check_user_access |
|
| 421 | + * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
| 422 | + * WordPress die message. |
|
| 423 | + * |
|
| 424 | + * @return bool|die true if pass (or admin) wp_die if fail |
|
| 425 | + */ |
|
| 426 | + private function _check_user_access() |
|
| 427 | + { |
|
| 428 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 429 | + $this->_menu_map->capability, |
|
| 430 | + $this->_menu_map->menu_slug |
|
| 431 | + )) { |
|
| 432 | + wp_die(__('You don\'t have access to this page.', 'event_espresso'), '', array('back_link' => true)); |
|
| 433 | + } |
|
| 434 | + return true; |
|
| 435 | + } |
|
| 436 | 436 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $this->_set_menu_map(); |
| 79 | 79 | if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
| 80 | 80 | EE_Error::doing_it_wrong( |
| 81 | - get_class($this) . '::$_menu_map', |
|
| 81 | + get_class($this).'::$_menu_map', |
|
| 82 | 82 | sprintf( |
| 83 | 83 | __( |
| 84 | 84 | 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | { |
| 143 | 143 | wp_register_style( |
| 144 | 144 | 'espresso_menu', |
| 145 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 145 | + EE_ADMIN_URL.'assets/admin-menu-styles.css', |
|
| 146 | 146 | array('dashicons'), |
| 147 | 147 | EVENT_ESPRESSO_VERSION |
| 148 | 148 | ); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | protected function _set_capability() |
| 171 | 171 | { |
| 172 | 172 | $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
| 173 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 173 | + $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | // let's check user access first |
| 190 | 190 | $this->_check_user_access(); |
| 191 | - if (! is_object($this->_loaded_page_object)) { |
|
| 191 | + if ( ! is_object($this->_loaded_page_object)) { |
|
| 192 | 192 | return; |
| 193 | 193 | } |
| 194 | 194 | $this->_loaded_page_object->route_admin_request(); |
@@ -198,15 +198,15 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | public function set_page_dependencies($wp_page_slug) |
| 200 | 200 | { |
| 201 | - if (! $this->_load_page) { |
|
| 201 | + if ( ! $this->_load_page) { |
|
| 202 | 202 | return; |
| 203 | 203 | } |
| 204 | - if (! is_object($this->_loaded_page_object)) { |
|
| 204 | + if ( ! is_object($this->_loaded_page_object)) { |
|
| 205 | 205 | $msg[] = __( |
| 206 | 206 | 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
| 207 | 207 | 'event_espresso' |
| 208 | 208 | ); |
| 209 | - $msg[] = $msg[0] . "\r\n" |
|
| 209 | + $msg[] = $msg[0]."\r\n" |
|
| 210 | 210 | . sprintf( |
| 211 | 211 | __( |
| 212 | 212 | 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
@@ -214,15 +214,15 @@ discard block |
||
| 214 | 214 | ), |
| 215 | 215 | $this->_file_name, |
| 216 | 216 | $this->_file_name, |
| 217 | - $this->_folder_path . $this->_file_name, |
|
| 217 | + $this->_folder_path.$this->_file_name, |
|
| 218 | 218 | $this->_menu_map->menu_slug |
| 219 | 219 | ); |
| 220 | 220 | throw new EE_Error(implode('||', $msg)); |
| 221 | 221 | } |
| 222 | 222 | $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
| 223 | - $page_hook = 'load-' . $wp_page_slug; |
|
| 223 | + $page_hook = 'load-'.$wp_page_slug; |
|
| 224 | 224 | // hook into page load hook so all page specific stuff get's loaded. |
| 225 | - if (! empty($wp_page_slug)) { |
|
| 225 | + if ( ! empty($wp_page_slug)) { |
|
| 226 | 226 | add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
| 227 | 227 | } |
| 228 | 228 | } |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | foreach ($bt as $index => $values) { |
| 260 | 260 | if (isset($values['class']) && $values['class'] == $class) { |
| 261 | 261 | $file_index = $index - 1; |
| 262 | - $this->_folder_name = basename(dirname($bt[ $file_index ]['file'])); |
|
| 263 | - if (! empty($this->_folder_name)) { |
|
| 262 | + $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
| 263 | + if ( ! empty($this->_folder_name)) { |
|
| 264 | 264 | break; |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/'; |
|
| 268 | + $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.'/'; |
|
| 269 | 269 | $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
| 270 | 270 | $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
| 271 | 271 | $this->_file_name = str_replace(' ', '_', $this->_file_name); |
@@ -301,12 +301,12 @@ discard block |
||
| 301 | 301 | // loop through decaf folders |
| 302 | 302 | $hook_files_glob_path = apply_filters( |
| 303 | 303 | 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
| 304 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 304 | + $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php' |
|
| 305 | 305 | ); |
| 306 | 306 | $this->_hook_paths = array_merge( |
| 307 | 307 | $this->_register_hook_files($hook_files_glob_path), |
| 308 | 308 | $this->_hook_paths |
| 309 | - ); // making sure any extended hook paths are later in the array than the core hook paths! |
|
| 309 | + ); // making sure any extended hook paths are later in the array than the core hook paths! |
|
| 310 | 310 | return $this->_hook_paths; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -320,10 +320,10 @@ discard block |
||
| 320 | 320 | } |
| 321 | 321 | foreach ($hook_files as $file) { |
| 322 | 322 | // lets get the linked admin. |
| 323 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file) |
|
| 323 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.'/', '', $file) |
|
| 324 | 324 | : str_replace($this->_folder_path, '', $file); |
| 325 | 325 | $replace = $extend |
| 326 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 326 | + ? '_'.$this->_file_name.'_Hooks_Extend.class.php' |
|
| 327 | 327 | : '_' |
| 328 | 328 | . $this->_file_name |
| 329 | 329 | . '_Hooks.class.php'; |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | continue; |
| 336 | 336 | } |
| 337 | 337 | $this->hook_file = $hook_file; |
| 338 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 338 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin; |
|
| 339 | 339 | $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
| 340 | 340 | $this->_files_hooked[] = $rel_admin; |
| 341 | 341 | } |
@@ -361,42 +361,42 @@ discard block |
||
| 361 | 361 | { |
| 362 | 362 | |
| 363 | 363 | // JUST CHECK WE'RE ON RIGHT PAGE. |
| 364 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 364 | + if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 365 | 365 | return; |
| 366 | 366 | } //not on the right page so let's get out. |
| 367 | 367 | $this->_load_page = true; |
| 368 | 368 | |
| 369 | 369 | // we don't need to do a page_request check here because it's only called via WP menu system. |
| 370 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 371 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 370 | + $admin_page = $this->_file_name.'_Admin_Page'; |
|
| 371 | + $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page; |
|
| 372 | 372 | $admin_page = apply_filters( |
| 373 | 373 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
| 374 | 374 | $admin_page |
| 375 | 375 | ); |
| 376 | 376 | // define requested admin page class name then load the file and instantiate |
| 377 | - $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php'); |
|
| 377 | + $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path.$admin_page.'.core.php'); |
|
| 378 | 378 | $path_to_file = apply_filters( |
| 379 | 379 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
| 380 | 380 | $path_to_file |
| 381 | - );// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 381 | + ); // so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 382 | 382 | if (is_readable($path_to_file)) { |
| 383 | 383 | // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
| 384 | 384 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
| 385 | 385 | do_action( |
| 386 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 386 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug |
|
| 387 | 387 | ); |
| 388 | 388 | require_once($path_to_file); |
| 389 | 389 | $a = new ReflectionClass($admin_page); |
| 390 | 390 | $this->_loaded_page_object = $a->newInstance($this->_routing); |
| 391 | 391 | } |
| 392 | 392 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
| 393 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 393 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
| 397 | 397 | public function get_admin_page_name() |
| 398 | 398 | { |
| 399 | - return $this->_file_name . '_Admin_Page'; |
|
| 399 | + return $this->_file_name.'_Admin_Page'; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | private function _check_user_access() |
| 427 | 427 | { |
| 428 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 428 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 429 | 429 | $this->_menu_map->capability, |
| 430 | 430 | $this->_menu_map->menu_slug |
| 431 | 431 | )) { |
@@ -13,722 +13,722 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * we're just going to use this to hold the name of the caller class (child class name) |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $caller; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
| 26 | - * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
| 27 | - * used later to make sure we require the needed files. |
|
| 28 | - * |
|
| 29 | - * @var bool |
|
| 30 | - */ |
|
| 31 | - protected $_extend; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * child classes MUST set this property so that the page object can be loaded correctly |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $_name; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * This is set by child classes and is an associative array of ajax hooks in the format: |
|
| 44 | - * array( |
|
| 45 | - * 'ajax_action_ref' => 'executing_method'; //must be public |
|
| 46 | - * ) |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $_ajax_func; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
| 55 | - * array( |
|
| 56 | - * 'page_route' => 'executing_method' //must be public |
|
| 57 | - * ) |
|
| 58 | - * |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - protected $_init_func; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
| 66 | - * array( |
|
| 67 | - * 0 => array( |
|
| 68 | - * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
| 69 | - * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
| 70 | - * will be added to each route. |
|
| 71 | - * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
| 72 | - * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
| 73 | - * method arguments. |
|
| 74 | - * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
| 75 | - * automatically) |
|
| 76 | - * 'priority' => 'default', //default 'default' (optional) |
|
| 77 | - * 'label' => __('Localized Title', 'event_espresso'), |
|
| 78 | - * 'context' => 'advanced' //advanced is default (optional), |
|
| 79 | - * 'callback_args' => array() //any callback args to include (optional) |
|
| 80 | - * ) |
|
| 81 | - * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
| 82 | - * |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - protected $_metaboxes; |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
| 90 | - * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
| 91 | - * array: array( |
|
| 92 | - * 0 => array( |
|
| 93 | - * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
| 94 | - * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
| 95 | - * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
| 96 | - * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
| 97 | - * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
| 98 | - * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
| 99 | - * id for the screen the metabox is on. |
|
| 100 | - * ) |
|
| 101 | - * ) |
|
| 102 | - * |
|
| 103 | - * @var array |
|
| 104 | - */ |
|
| 105 | - protected $_remove_metaboxes; |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
| 110 | - * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
| 111 | - * second array index is for indicating what routes each script/style loads on. array( |
|
| 112 | - * 'registers' => array( |
|
| 113 | - * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
| 114 | - * argument to link scripts together. |
|
| 115 | - * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
| 116 | - * 'url' => 'http://urltoscript.css.js', |
|
| 117 | - * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
| 118 | - * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
| 119 | - * gets loaded before the one you are setting here. |
|
| 120 | - * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
| 121 | - * ), |
|
| 122 | - * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
| 123 | - * the script gets enqueued on. |
|
| 124 | - * 'script_ref' => array('route_one', 'route_two') |
|
| 125 | - * ), |
|
| 126 | - * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
| 127 | - * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
| 128 | - * the object. |
|
| 129 | - * 'scrip_ref' => array( |
|
| 130 | - * 'NAME_OF_JS_OBJECT' => array( |
|
| 131 | - * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
| 132 | - * 'some_data' => 5 |
|
| 133 | - * ) |
|
| 134 | - * ) |
|
| 135 | - * ) |
|
| 136 | - * ) |
|
| 137 | - * |
|
| 138 | - * @var array |
|
| 139 | - */ |
|
| 140 | - protected $_scripts_styles; |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * This is a property that will contain the current route. |
|
| 145 | - * |
|
| 146 | - * @var string; |
|
| 147 | - */ |
|
| 148 | - protected $_current_route; |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
| 153 | - * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
| 154 | - * 'wp_hook_reference' => 1 |
|
| 155 | - * ) |
|
| 156 | - * ) |
|
| 157 | - * |
|
| 158 | - * @var array |
|
| 159 | - */ |
|
| 160 | - protected $_wp_action_filters_priority; |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
| 165 | - * |
|
| 166 | - * @var array |
|
| 167 | - */ |
|
| 168 | - protected $_req_data; |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * This just holds an instance of the page object for this hook |
|
| 173 | - * |
|
| 174 | - * @var EE_Admin_Page |
|
| 175 | - */ |
|
| 176 | - protected $_page_object; |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
| 181 | - * |
|
| 182 | - * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
| 183 | - */ |
|
| 184 | - protected $_adminpage_obj; |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Holds EE_Registry object |
|
| 189 | - * |
|
| 190 | - * @var EE_Registry |
|
| 191 | - */ |
|
| 192 | - protected $EE = null; |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * constructor |
|
| 197 | - * |
|
| 198 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 199 | - */ |
|
| 200 | - public function __construct(EE_Admin_Page $adminpage) |
|
| 201 | - { |
|
| 202 | - |
|
| 203 | - $this->_adminpage_obj = $adminpage; |
|
| 204 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 205 | - $this->_set_defaults(); |
|
| 206 | - $this->_set_hooks_properties(); |
|
| 207 | - // first let's verify we're on the right page |
|
| 208 | - if (! isset($this->_req_data['page']) |
|
| 209 | - || (isset($this->_req_data['page']) |
|
| 210 | - && $this->_adminpage_obj->page_slug |
|
| 211 | - != $this->_req_data['page'])) { |
|
| 212 | - return; |
|
| 213 | - } //get out nothing more to be done here. |
|
| 214 | - // allow for extends to modify properties |
|
| 215 | - if (method_exists($this, '_extend_properties')) { |
|
| 216 | - $this->_extend_properties(); |
|
| 217 | - } |
|
| 218 | - $this->_set_page_object(); |
|
| 219 | - $this->_init_hooks(); |
|
| 220 | - $this->_load_custom_methods(); |
|
| 221 | - $this->_load_routed_hooks(); |
|
| 222 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
| 223 | - add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
| 224 | - add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
| 225 | - $this->_ajax_hooks(); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * used by child classes to set the following properties: |
|
| 231 | - * $_ajax_func (optional) |
|
| 232 | - * $_init_func (optional) |
|
| 233 | - * $_metaboxes (optional) |
|
| 234 | - * $_scripts (optional) |
|
| 235 | - * $_styles (optional) |
|
| 236 | - * $_name (required) |
|
| 237 | - * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
| 238 | - * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
| 239 | - * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
| 240 | - * |
|
| 241 | - * @access protected |
|
| 242 | - * @abstract |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - abstract protected function _set_hooks_properties(); |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
| 250 | - * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
| 251 | - * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
| 252 | - * |
|
| 253 | - * @access public |
|
| 254 | - * @return void |
|
| 255 | - */ |
|
| 256 | - public function enqueue_scripts_styles() |
|
| 257 | - { |
|
| 258 | - |
|
| 259 | - if (! empty($this->_scripts_styles)) { |
|
| 260 | - // first let's do all the registrations |
|
| 261 | - if (! isset($this->_scripts_styles['registers'])) { |
|
| 262 | - $msg[] = __( |
|
| 263 | - 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
| 264 | - 'event_espresso' |
|
| 265 | - ); |
|
| 266 | - $msg[] = sprintf( |
|
| 267 | - __( |
|
| 268 | - 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ), |
|
| 271 | - '<strong>' . $this->caller . '</strong>' |
|
| 272 | - ); |
|
| 273 | - throw new EE_Error(implode('||', $msg)); |
|
| 274 | - } |
|
| 275 | - foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
| 276 | - $defaults = array( |
|
| 277 | - 'type' => 'js', |
|
| 278 | - 'url' => '', |
|
| 279 | - 'depends' => array(), |
|
| 280 | - 'version' => EVENT_ESPRESSO_VERSION, |
|
| 281 | - 'footer' => true, |
|
| 282 | - ); |
|
| 283 | - $details = wp_parse_args($details, $defaults); |
|
| 284 | - extract($details); |
|
| 285 | - // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
| 286 | - $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
| 287 | - // let's make sure we're not missing any REQUIRED parameters |
|
| 288 | - if (empty($url)) { |
|
| 289 | - $msg[] = sprintf( |
|
| 290 | - __('Missing the url for the requested %s', 'event_espresso'), |
|
| 291 | - $type == 'js' ? 'script' : 'stylesheet' |
|
| 292 | - ); |
|
| 293 | - $msg[] = sprintf( |
|
| 294 | - __( |
|
| 295 | - 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
| 296 | - 'event_espresso' |
|
| 297 | - ), |
|
| 298 | - '<strong>' . $this->caller . '</strong>', |
|
| 299 | - $ref |
|
| 300 | - ); |
|
| 301 | - throw new EE_Error(implode('||', $msg)); |
|
| 302 | - } |
|
| 303 | - // made it here so let's do the appropriate registration |
|
| 304 | - $type == 'js' |
|
| 305 | - ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
| 306 | - : wp_register_style( |
|
| 307 | - $ref, |
|
| 308 | - $url, |
|
| 309 | - $depends, |
|
| 310 | - $version |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - // k now lets do the enqueues |
|
| 314 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 315 | - return; |
|
| 316 | - } //not sure if we should throw an error here or not. |
|
| 317 | - |
|
| 318 | - foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
| 319 | - // make sure $routes is an array |
|
| 320 | - $routes = (array) $routes; |
|
| 321 | - if (in_array($this->_current_route, $routes)) { |
|
| 322 | - $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 323 | - : wp_enqueue_style($ref); |
|
| 324 | - // if we have a localization for the script let's do that too. |
|
| 325 | - if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
| 326 | - foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
| 327 | - wp_localize_script( |
|
| 328 | - $ref, |
|
| 329 | - $object_name, |
|
| 330 | - $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - // let's do the deregisters |
|
| 337 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 338 | - return; |
|
| 339 | - } |
|
| 340 | - foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
| 341 | - $defaults = array( |
|
| 342 | - 'type' => 'js', |
|
| 343 | - ); |
|
| 344 | - $details = wp_parse_args($details, $defaults); |
|
| 345 | - extract($details); |
|
| 346 | - $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * just set the defaults for the hooks properties. |
|
| 354 | - * |
|
| 355 | - * @access private |
|
| 356 | - * @return void |
|
| 357 | - */ |
|
| 358 | - private function _set_defaults() |
|
| 359 | - { |
|
| 360 | - $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
| 361 | - $this->_current_route = $this->getCurrentRoute(); |
|
| 362 | - $this->caller = get_class($this); |
|
| 363 | - $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * A helper for determining the current route. |
|
| 369 | - * @return string |
|
| 370 | - */ |
|
| 371 | - private function getCurrentRoute() |
|
| 372 | - { |
|
| 373 | - // list tables do something else with 'action' for bulk actions. |
|
| 374 | - $action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default'; |
|
| 375 | - // we set a 'route' variable in some cases where action is being used by something else. |
|
| 376 | - $action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action; |
|
| 377 | - return sanitize_key($action); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * this sets the _page_object property |
|
| 383 | - * |
|
| 384 | - * @access protected |
|
| 385 | - * @return void |
|
| 386 | - */ |
|
| 387 | - protected function _set_page_object() |
|
| 388 | - { |
|
| 389 | - // first make sure $this->_name is set |
|
| 390 | - if (empty($this->_name)) { |
|
| 391 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 392 | - $msg[] = sprintf( |
|
| 393 | - __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
| 394 | - $this->caller |
|
| 395 | - ); |
|
| 396 | - throw new EE_Error(implode('||', $msg)); |
|
| 397 | - } |
|
| 398 | - $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
|
| 399 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
| 400 | - // first default file (if exists) |
|
| 401 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php'; |
|
| 402 | - if (is_readable($decaf_file)) { |
|
| 403 | - require_once($decaf_file); |
|
| 404 | - } |
|
| 405 | - // now we have to do require for extended file (if needed) |
|
| 406 | - if ($this->_extend) { |
|
| 407 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php'); |
|
| 408 | - } |
|
| 409 | - // if we've got an extended class we use that! |
|
| 410 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 411 | - // let's make sure the class exists |
|
| 412 | - if (! class_exists($ref)) { |
|
| 413 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 414 | - $msg[] = sprintf( |
|
| 415 | - __( |
|
| 416 | - 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
| 417 | - 'event_espresso' |
|
| 418 | - ), |
|
| 419 | - $ref |
|
| 420 | - ); |
|
| 421 | - throw new EE_Error(implode('||', $msg)); |
|
| 422 | - } |
|
| 423 | - $a = new ReflectionClass($ref); |
|
| 424 | - $this->_page_object = $a->newInstance(false); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
| 430 | - * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
| 431 | - * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
| 432 | - * |
|
| 433 | - * @access private |
|
| 434 | - * @return void |
|
| 435 | - */ |
|
| 436 | - private function _load_custom_methods() |
|
| 437 | - { |
|
| 438 | - /** |
|
| 439 | - * method cannot be named 'default' (@see http://us3.php |
|
| 440 | - * .net/manual/en/reserved.keywords.php) so need to |
|
| 441 | - * handle routes that are "default" |
|
| 442 | - * |
|
| 443 | - * @since 4.3.0 |
|
| 444 | - */ |
|
| 445 | - $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
| 446 | - // these run before the Admin_Page route executes. |
|
| 447 | - if (method_exists($this, $method_callback)) { |
|
| 448 | - call_user_func(array($this, $method_callback)); |
|
| 449 | - } |
|
| 450 | - // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
| 451 | - // first the actions |
|
| 452 | - // note that these action hooks will have the $query_args value available. |
|
| 453 | - $admin_class_name = get_class($this->_adminpage_obj); |
|
| 454 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 455 | - add_action( |
|
| 456 | - 'AHEE__' |
|
| 457 | - . $admin_class_name |
|
| 458 | - . '___redirect_after_action__before_redirect_modification_' |
|
| 459 | - . $this->_current_route, |
|
| 460 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 461 | - 10 |
|
| 462 | - ); |
|
| 463 | - } |
|
| 464 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 465 | - add_action( |
|
| 466 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 467 | - array($this, '_redirect_action_' . $this->_current_route), |
|
| 468 | - 10 |
|
| 469 | - ); |
|
| 470 | - } |
|
| 471 | - // let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
| 472 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 473 | - add_filter( |
|
| 474 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 475 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
| 476 | - 10, |
|
| 477 | - 2 |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
| 485 | - * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
| 486 | - * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
| 487 | - * |
|
| 488 | - * @return void |
|
| 489 | - */ |
|
| 490 | - private function _load_routed_hooks() |
|
| 491 | - { |
|
| 492 | - |
|
| 493 | - // this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
| 494 | - $hook_filter_array = array( |
|
| 495 | - 'admin_footer' => array( |
|
| 496 | - 'type' => 'action', |
|
| 497 | - 'argnum' => 1, |
|
| 498 | - 'priority' => 10, |
|
| 499 | - ), |
|
| 500 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 501 | - 'type' => 'filter', |
|
| 502 | - 'argnum' => 1, |
|
| 503 | - 'priority' => 10, |
|
| 504 | - ), |
|
| 505 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 506 | - 'type' => 'filter', |
|
| 507 | - 'argnum' => 1, |
|
| 508 | - 'priority' => 10, |
|
| 509 | - ), |
|
| 510 | - 'FHEE_list_table_views' => array( |
|
| 511 | - 'type' => 'filter', |
|
| 512 | - 'argnum' => 1, |
|
| 513 | - 'priority' => 10, |
|
| 514 | - ), |
|
| 515 | - 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
| 516 | - 'type' => 'action', |
|
| 517 | - 'argnum' => 1, |
|
| 518 | - 'priority' => 10, |
|
| 519 | - ), |
|
| 520 | - ); |
|
| 521 | - foreach ($hook_filter_array as $hook => $args) { |
|
| 522 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 523 | - if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
| 524 | - $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
| 525 | - } |
|
| 526 | - if ($args['type'] == 'action') { |
|
| 527 | - add_action( |
|
| 528 | - $hook, |
|
| 529 | - array($this, $this->_current_route . '_' . $hook), |
|
| 530 | - $args['priority'], |
|
| 531 | - $args['argnum'] |
|
| 532 | - ); |
|
| 533 | - } else { |
|
| 534 | - add_filter( |
|
| 535 | - $hook, |
|
| 536 | - array($this, $this->_current_route . '_' . $hook), |
|
| 537 | - $args['priority'], |
|
| 538 | - $args['argnum'] |
|
| 539 | - ); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Loop throught the $_ajax_func array and add_actions for the array. |
|
| 548 | - * |
|
| 549 | - * @return void |
|
| 550 | - */ |
|
| 551 | - private function _ajax_hooks() |
|
| 552 | - { |
|
| 553 | - |
|
| 554 | - if (empty($this->_ajax_func)) { |
|
| 555 | - return; |
|
| 556 | - } //get out there's nothing to take care of. |
|
| 557 | - foreach ($this->_ajax_func as $action => $method) { |
|
| 558 | - // make sure method exists |
|
| 559 | - if (! method_exists($this, $method)) { |
|
| 560 | - $msg[] = __( |
|
| 561 | - 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
| 562 | - 'event_espresso' |
|
| 563 | - ) . '<br />'; |
|
| 564 | - $msg[] = sprintf( |
|
| 565 | - __( |
|
| 566 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 567 | - 'event_espresso' |
|
| 568 | - ), |
|
| 569 | - $method, |
|
| 570 | - $this->caller |
|
| 571 | - ); |
|
| 572 | - throw new EE_Error(implode('||', $msg)); |
|
| 573 | - } |
|
| 574 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Loop throught the $_init_func array and add_actions for the array. |
|
| 581 | - * |
|
| 582 | - * @return void |
|
| 583 | - */ |
|
| 584 | - protected function _init_hooks() |
|
| 585 | - { |
|
| 586 | - if (empty($this->_init_func)) { |
|
| 587 | - return; |
|
| 588 | - } //get out there's nothing to take care of. |
|
| 589 | - // We need to determine what page_route we are on! |
|
| 590 | - $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 591 | - foreach ($this->_init_func as $route => $method) { |
|
| 592 | - // make sure method exists |
|
| 593 | - if (! method_exists($this, $method)) { |
|
| 594 | - $msg[] = __( |
|
| 595 | - 'There is no corresponding method for the hook labeled in the _init_func array', |
|
| 596 | - 'event_espresso' |
|
| 597 | - ) . '<br />'; |
|
| 598 | - $msg[] = sprintf( |
|
| 599 | - __( |
|
| 600 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 601 | - 'event_espresso' |
|
| 602 | - ), |
|
| 603 | - $method, |
|
| 604 | - $this->caller |
|
| 605 | - ); |
|
| 606 | - throw new EE_Error(implode('||', $msg)); |
|
| 607 | - } |
|
| 608 | - if ($route == $this->_current_route) { |
|
| 609 | - add_action('admin_init', array($this, $method)); |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Loop through the _metaboxes property and add_metaboxes accordingly |
|
| 617 | - * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
| 618 | - * |
|
| 619 | - * @access public |
|
| 620 | - * @return void |
|
| 621 | - */ |
|
| 622 | - public function add_metaboxes() |
|
| 623 | - { |
|
| 624 | - if (empty($this->_metaboxes)) { |
|
| 625 | - return; |
|
| 626 | - } //get out we don't have any metaboxes to set for this connection |
|
| 627 | - $this->_handle_metabox_array($this->_metaboxes); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - private function _handle_metabox_array($boxes, $add = true) |
|
| 632 | - { |
|
| 633 | - |
|
| 634 | - foreach ($boxes as $box) { |
|
| 635 | - if (! isset($box['page_route'])) { |
|
| 636 | - continue; |
|
| 637 | - } //we dont' have a valid array |
|
| 638 | - // let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
| 639 | - $box['page_route'] = (array) $box['page_route']; |
|
| 640 | - foreach ($box['page_route'] as $route) { |
|
| 641 | - if ($route != $this->_current_route) { |
|
| 642 | - continue; |
|
| 643 | - } //get out we only add metaboxes for set route. |
|
| 644 | - if ($add) { |
|
| 645 | - $this->_add_metabox($box); |
|
| 646 | - } else { |
|
| 647 | - $this->_remove_metabox($box); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
| 656 | - * |
|
| 657 | - * @access public |
|
| 658 | - * @return void |
|
| 659 | - */ |
|
| 660 | - public function remove_metaboxes() |
|
| 661 | - { |
|
| 662 | - |
|
| 663 | - if (empty($this->_remove_metaboxes)) { |
|
| 664 | - return; |
|
| 665 | - } //get out there are no metaboxes to remove |
|
| 666 | - $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * This just handles adding a metabox |
|
| 672 | - * |
|
| 673 | - * @access private |
|
| 674 | - * @param array $args an array of args that have been set for this metabox by the child class |
|
| 675 | - */ |
|
| 676 | - private function _add_metabox($args) |
|
| 677 | - { |
|
| 678 | - $current_screen = get_current_screen(); |
|
| 679 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 680 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 681 | - // set defaults |
|
| 682 | - $defaults = array( |
|
| 683 | - 'func' => $func, |
|
| 684 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 685 | - 'priority' => 'default', |
|
| 686 | - 'label' => $this->caller, |
|
| 687 | - 'context' => 'advanced', |
|
| 688 | - 'callback_args' => array(), |
|
| 689 | - 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
| 690 | - ); |
|
| 691 | - $args = wp_parse_args($args, $defaults); |
|
| 692 | - extract($args); |
|
| 693 | - // make sure method exists |
|
| 694 | - if (! method_exists($this, $func)) { |
|
| 695 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 696 | - $msg[] = sprintf( |
|
| 697 | - __( |
|
| 698 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 699 | - 'event_espresso' |
|
| 700 | - ), |
|
| 701 | - $func, |
|
| 702 | - $this->caller |
|
| 703 | - ); |
|
| 704 | - throw new EE_Error(implode('||', $msg)); |
|
| 705 | - } |
|
| 706 | - // everything checks out so lets add the metabox |
|
| 707 | - add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - private function _remove_metabox($args) |
|
| 712 | - { |
|
| 713 | - $current_screen = get_current_screen(); |
|
| 714 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 715 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 716 | - // set defaults |
|
| 717 | - $defaults = array( |
|
| 718 | - 'id' => isset($args['id']) |
|
| 719 | - ? $args['id'] |
|
| 720 | - : $this->_current_route |
|
| 721 | - . '_' |
|
| 722 | - . $this->caller |
|
| 723 | - . '_' |
|
| 724 | - . $func |
|
| 725 | - . '_metabox', |
|
| 726 | - 'context' => 'default', |
|
| 727 | - 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id, |
|
| 728 | - ); |
|
| 729 | - $args = wp_parse_args($args, $defaults); |
|
| 730 | - extract($args); |
|
| 731 | - // everything checks out so lets remove the box! |
|
| 732 | - remove_meta_box($id, $screen, $context); |
|
| 733 | - } |
|
| 16 | + /** |
|
| 17 | + * we're just going to use this to hold the name of the caller class (child class name) |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $caller; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
| 26 | + * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
| 27 | + * used later to make sure we require the needed files. |
|
| 28 | + * |
|
| 29 | + * @var bool |
|
| 30 | + */ |
|
| 31 | + protected $_extend; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * child classes MUST set this property so that the page object can be loaded correctly |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $_name; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * This is set by child classes and is an associative array of ajax hooks in the format: |
|
| 44 | + * array( |
|
| 45 | + * 'ajax_action_ref' => 'executing_method'; //must be public |
|
| 46 | + * ) |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $_ajax_func; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
| 55 | + * array( |
|
| 56 | + * 'page_route' => 'executing_method' //must be public |
|
| 57 | + * ) |
|
| 58 | + * |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + protected $_init_func; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
| 66 | + * array( |
|
| 67 | + * 0 => array( |
|
| 68 | + * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
| 69 | + * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
| 70 | + * will be added to each route. |
|
| 71 | + * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
| 72 | + * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
| 73 | + * method arguments. |
|
| 74 | + * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
| 75 | + * automatically) |
|
| 76 | + * 'priority' => 'default', //default 'default' (optional) |
|
| 77 | + * 'label' => __('Localized Title', 'event_espresso'), |
|
| 78 | + * 'context' => 'advanced' //advanced is default (optional), |
|
| 79 | + * 'callback_args' => array() //any callback args to include (optional) |
|
| 80 | + * ) |
|
| 81 | + * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
| 82 | + * |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + protected $_metaboxes; |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
| 90 | + * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
| 91 | + * array: array( |
|
| 92 | + * 0 => array( |
|
| 93 | + * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
| 94 | + * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
| 95 | + * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
| 96 | + * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
| 97 | + * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
| 98 | + * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
| 99 | + * id for the screen the metabox is on. |
|
| 100 | + * ) |
|
| 101 | + * ) |
|
| 102 | + * |
|
| 103 | + * @var array |
|
| 104 | + */ |
|
| 105 | + protected $_remove_metaboxes; |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
| 110 | + * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
| 111 | + * second array index is for indicating what routes each script/style loads on. array( |
|
| 112 | + * 'registers' => array( |
|
| 113 | + * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
| 114 | + * argument to link scripts together. |
|
| 115 | + * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
| 116 | + * 'url' => 'http://urltoscript.css.js', |
|
| 117 | + * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
| 118 | + * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
| 119 | + * gets loaded before the one you are setting here. |
|
| 120 | + * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
| 121 | + * ), |
|
| 122 | + * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
| 123 | + * the script gets enqueued on. |
|
| 124 | + * 'script_ref' => array('route_one', 'route_two') |
|
| 125 | + * ), |
|
| 126 | + * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
| 127 | + * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
| 128 | + * the object. |
|
| 129 | + * 'scrip_ref' => array( |
|
| 130 | + * 'NAME_OF_JS_OBJECT' => array( |
|
| 131 | + * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
| 132 | + * 'some_data' => 5 |
|
| 133 | + * ) |
|
| 134 | + * ) |
|
| 135 | + * ) |
|
| 136 | + * ) |
|
| 137 | + * |
|
| 138 | + * @var array |
|
| 139 | + */ |
|
| 140 | + protected $_scripts_styles; |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * This is a property that will contain the current route. |
|
| 145 | + * |
|
| 146 | + * @var string; |
|
| 147 | + */ |
|
| 148 | + protected $_current_route; |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
| 153 | + * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
| 154 | + * 'wp_hook_reference' => 1 |
|
| 155 | + * ) |
|
| 156 | + * ) |
|
| 157 | + * |
|
| 158 | + * @var array |
|
| 159 | + */ |
|
| 160 | + protected $_wp_action_filters_priority; |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
| 165 | + * |
|
| 166 | + * @var array |
|
| 167 | + */ |
|
| 168 | + protected $_req_data; |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * This just holds an instance of the page object for this hook |
|
| 173 | + * |
|
| 174 | + * @var EE_Admin_Page |
|
| 175 | + */ |
|
| 176 | + protected $_page_object; |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
| 181 | + * |
|
| 182 | + * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
| 183 | + */ |
|
| 184 | + protected $_adminpage_obj; |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Holds EE_Registry object |
|
| 189 | + * |
|
| 190 | + * @var EE_Registry |
|
| 191 | + */ |
|
| 192 | + protected $EE = null; |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * constructor |
|
| 197 | + * |
|
| 198 | + * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 199 | + */ |
|
| 200 | + public function __construct(EE_Admin_Page $adminpage) |
|
| 201 | + { |
|
| 202 | + |
|
| 203 | + $this->_adminpage_obj = $adminpage; |
|
| 204 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 205 | + $this->_set_defaults(); |
|
| 206 | + $this->_set_hooks_properties(); |
|
| 207 | + // first let's verify we're on the right page |
|
| 208 | + if (! isset($this->_req_data['page']) |
|
| 209 | + || (isset($this->_req_data['page']) |
|
| 210 | + && $this->_adminpage_obj->page_slug |
|
| 211 | + != $this->_req_data['page'])) { |
|
| 212 | + return; |
|
| 213 | + } //get out nothing more to be done here. |
|
| 214 | + // allow for extends to modify properties |
|
| 215 | + if (method_exists($this, '_extend_properties')) { |
|
| 216 | + $this->_extend_properties(); |
|
| 217 | + } |
|
| 218 | + $this->_set_page_object(); |
|
| 219 | + $this->_init_hooks(); |
|
| 220 | + $this->_load_custom_methods(); |
|
| 221 | + $this->_load_routed_hooks(); |
|
| 222 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
| 223 | + add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
| 224 | + add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
| 225 | + $this->_ajax_hooks(); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * used by child classes to set the following properties: |
|
| 231 | + * $_ajax_func (optional) |
|
| 232 | + * $_init_func (optional) |
|
| 233 | + * $_metaboxes (optional) |
|
| 234 | + * $_scripts (optional) |
|
| 235 | + * $_styles (optional) |
|
| 236 | + * $_name (required) |
|
| 237 | + * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
| 238 | + * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
| 239 | + * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
| 240 | + * |
|
| 241 | + * @access protected |
|
| 242 | + * @abstract |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + abstract protected function _set_hooks_properties(); |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
| 250 | + * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
| 251 | + * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
| 252 | + * |
|
| 253 | + * @access public |
|
| 254 | + * @return void |
|
| 255 | + */ |
|
| 256 | + public function enqueue_scripts_styles() |
|
| 257 | + { |
|
| 258 | + |
|
| 259 | + if (! empty($this->_scripts_styles)) { |
|
| 260 | + // first let's do all the registrations |
|
| 261 | + if (! isset($this->_scripts_styles['registers'])) { |
|
| 262 | + $msg[] = __( |
|
| 263 | + 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
| 264 | + 'event_espresso' |
|
| 265 | + ); |
|
| 266 | + $msg[] = sprintf( |
|
| 267 | + __( |
|
| 268 | + 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ), |
|
| 271 | + '<strong>' . $this->caller . '</strong>' |
|
| 272 | + ); |
|
| 273 | + throw new EE_Error(implode('||', $msg)); |
|
| 274 | + } |
|
| 275 | + foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
| 276 | + $defaults = array( |
|
| 277 | + 'type' => 'js', |
|
| 278 | + 'url' => '', |
|
| 279 | + 'depends' => array(), |
|
| 280 | + 'version' => EVENT_ESPRESSO_VERSION, |
|
| 281 | + 'footer' => true, |
|
| 282 | + ); |
|
| 283 | + $details = wp_parse_args($details, $defaults); |
|
| 284 | + extract($details); |
|
| 285 | + // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
| 286 | + $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
| 287 | + // let's make sure we're not missing any REQUIRED parameters |
|
| 288 | + if (empty($url)) { |
|
| 289 | + $msg[] = sprintf( |
|
| 290 | + __('Missing the url for the requested %s', 'event_espresso'), |
|
| 291 | + $type == 'js' ? 'script' : 'stylesheet' |
|
| 292 | + ); |
|
| 293 | + $msg[] = sprintf( |
|
| 294 | + __( |
|
| 295 | + 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
| 296 | + 'event_espresso' |
|
| 297 | + ), |
|
| 298 | + '<strong>' . $this->caller . '</strong>', |
|
| 299 | + $ref |
|
| 300 | + ); |
|
| 301 | + throw new EE_Error(implode('||', $msg)); |
|
| 302 | + } |
|
| 303 | + // made it here so let's do the appropriate registration |
|
| 304 | + $type == 'js' |
|
| 305 | + ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
| 306 | + : wp_register_style( |
|
| 307 | + $ref, |
|
| 308 | + $url, |
|
| 309 | + $depends, |
|
| 310 | + $version |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + // k now lets do the enqueues |
|
| 314 | + if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 315 | + return; |
|
| 316 | + } //not sure if we should throw an error here or not. |
|
| 317 | + |
|
| 318 | + foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
| 319 | + // make sure $routes is an array |
|
| 320 | + $routes = (array) $routes; |
|
| 321 | + if (in_array($this->_current_route, $routes)) { |
|
| 322 | + $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 323 | + : wp_enqueue_style($ref); |
|
| 324 | + // if we have a localization for the script let's do that too. |
|
| 325 | + if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
| 326 | + foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
| 327 | + wp_localize_script( |
|
| 328 | + $ref, |
|
| 329 | + $object_name, |
|
| 330 | + $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + // let's do the deregisters |
|
| 337 | + if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 338 | + return; |
|
| 339 | + } |
|
| 340 | + foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
| 341 | + $defaults = array( |
|
| 342 | + 'type' => 'js', |
|
| 343 | + ); |
|
| 344 | + $details = wp_parse_args($details, $defaults); |
|
| 345 | + extract($details); |
|
| 346 | + $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * just set the defaults for the hooks properties. |
|
| 354 | + * |
|
| 355 | + * @access private |
|
| 356 | + * @return void |
|
| 357 | + */ |
|
| 358 | + private function _set_defaults() |
|
| 359 | + { |
|
| 360 | + $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
| 361 | + $this->_current_route = $this->getCurrentRoute(); |
|
| 362 | + $this->caller = get_class($this); |
|
| 363 | + $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * A helper for determining the current route. |
|
| 369 | + * @return string |
|
| 370 | + */ |
|
| 371 | + private function getCurrentRoute() |
|
| 372 | + { |
|
| 373 | + // list tables do something else with 'action' for bulk actions. |
|
| 374 | + $action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default'; |
|
| 375 | + // we set a 'route' variable in some cases where action is being used by something else. |
|
| 376 | + $action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action; |
|
| 377 | + return sanitize_key($action); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * this sets the _page_object property |
|
| 383 | + * |
|
| 384 | + * @access protected |
|
| 385 | + * @return void |
|
| 386 | + */ |
|
| 387 | + protected function _set_page_object() |
|
| 388 | + { |
|
| 389 | + // first make sure $this->_name is set |
|
| 390 | + if (empty($this->_name)) { |
|
| 391 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 392 | + $msg[] = sprintf( |
|
| 393 | + __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
| 394 | + $this->caller |
|
| 395 | + ); |
|
| 396 | + throw new EE_Error(implode('||', $msg)); |
|
| 397 | + } |
|
| 398 | + $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
|
| 399 | + $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
| 400 | + // first default file (if exists) |
|
| 401 | + $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php'; |
|
| 402 | + if (is_readable($decaf_file)) { |
|
| 403 | + require_once($decaf_file); |
|
| 404 | + } |
|
| 405 | + // now we have to do require for extended file (if needed) |
|
| 406 | + if ($this->_extend) { |
|
| 407 | + require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php'); |
|
| 408 | + } |
|
| 409 | + // if we've got an extended class we use that! |
|
| 410 | + $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 411 | + // let's make sure the class exists |
|
| 412 | + if (! class_exists($ref)) { |
|
| 413 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 414 | + $msg[] = sprintf( |
|
| 415 | + __( |
|
| 416 | + 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
| 417 | + 'event_espresso' |
|
| 418 | + ), |
|
| 419 | + $ref |
|
| 420 | + ); |
|
| 421 | + throw new EE_Error(implode('||', $msg)); |
|
| 422 | + } |
|
| 423 | + $a = new ReflectionClass($ref); |
|
| 424 | + $this->_page_object = $a->newInstance(false); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
| 430 | + * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
| 431 | + * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
| 432 | + * |
|
| 433 | + * @access private |
|
| 434 | + * @return void |
|
| 435 | + */ |
|
| 436 | + private function _load_custom_methods() |
|
| 437 | + { |
|
| 438 | + /** |
|
| 439 | + * method cannot be named 'default' (@see http://us3.php |
|
| 440 | + * .net/manual/en/reserved.keywords.php) so need to |
|
| 441 | + * handle routes that are "default" |
|
| 442 | + * |
|
| 443 | + * @since 4.3.0 |
|
| 444 | + */ |
|
| 445 | + $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
| 446 | + // these run before the Admin_Page route executes. |
|
| 447 | + if (method_exists($this, $method_callback)) { |
|
| 448 | + call_user_func(array($this, $method_callback)); |
|
| 449 | + } |
|
| 450 | + // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
| 451 | + // first the actions |
|
| 452 | + // note that these action hooks will have the $query_args value available. |
|
| 453 | + $admin_class_name = get_class($this->_adminpage_obj); |
|
| 454 | + if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 455 | + add_action( |
|
| 456 | + 'AHEE__' |
|
| 457 | + . $admin_class_name |
|
| 458 | + . '___redirect_after_action__before_redirect_modification_' |
|
| 459 | + . $this->_current_route, |
|
| 460 | + array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 461 | + 10 |
|
| 462 | + ); |
|
| 463 | + } |
|
| 464 | + if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 465 | + add_action( |
|
| 466 | + 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 467 | + array($this, '_redirect_action_' . $this->_current_route), |
|
| 468 | + 10 |
|
| 469 | + ); |
|
| 470 | + } |
|
| 471 | + // let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
| 472 | + if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 473 | + add_filter( |
|
| 474 | + 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 475 | + array($this, '_redirect_filter_' . $this->_current_route), |
|
| 476 | + 10, |
|
| 477 | + 2 |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
| 485 | + * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
| 486 | + * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
| 487 | + * |
|
| 488 | + * @return void |
|
| 489 | + */ |
|
| 490 | + private function _load_routed_hooks() |
|
| 491 | + { |
|
| 492 | + |
|
| 493 | + // this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
| 494 | + $hook_filter_array = array( |
|
| 495 | + 'admin_footer' => array( |
|
| 496 | + 'type' => 'action', |
|
| 497 | + 'argnum' => 1, |
|
| 498 | + 'priority' => 10, |
|
| 499 | + ), |
|
| 500 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 501 | + 'type' => 'filter', |
|
| 502 | + 'argnum' => 1, |
|
| 503 | + 'priority' => 10, |
|
| 504 | + ), |
|
| 505 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 506 | + 'type' => 'filter', |
|
| 507 | + 'argnum' => 1, |
|
| 508 | + 'priority' => 10, |
|
| 509 | + ), |
|
| 510 | + 'FHEE_list_table_views' => array( |
|
| 511 | + 'type' => 'filter', |
|
| 512 | + 'argnum' => 1, |
|
| 513 | + 'priority' => 10, |
|
| 514 | + ), |
|
| 515 | + 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
| 516 | + 'type' => 'action', |
|
| 517 | + 'argnum' => 1, |
|
| 518 | + 'priority' => 10, |
|
| 519 | + ), |
|
| 520 | + ); |
|
| 521 | + foreach ($hook_filter_array as $hook => $args) { |
|
| 522 | + if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 523 | + if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
| 524 | + $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
| 525 | + } |
|
| 526 | + if ($args['type'] == 'action') { |
|
| 527 | + add_action( |
|
| 528 | + $hook, |
|
| 529 | + array($this, $this->_current_route . '_' . $hook), |
|
| 530 | + $args['priority'], |
|
| 531 | + $args['argnum'] |
|
| 532 | + ); |
|
| 533 | + } else { |
|
| 534 | + add_filter( |
|
| 535 | + $hook, |
|
| 536 | + array($this, $this->_current_route . '_' . $hook), |
|
| 537 | + $args['priority'], |
|
| 538 | + $args['argnum'] |
|
| 539 | + ); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Loop throught the $_ajax_func array and add_actions for the array. |
|
| 548 | + * |
|
| 549 | + * @return void |
|
| 550 | + */ |
|
| 551 | + private function _ajax_hooks() |
|
| 552 | + { |
|
| 553 | + |
|
| 554 | + if (empty($this->_ajax_func)) { |
|
| 555 | + return; |
|
| 556 | + } //get out there's nothing to take care of. |
|
| 557 | + foreach ($this->_ajax_func as $action => $method) { |
|
| 558 | + // make sure method exists |
|
| 559 | + if (! method_exists($this, $method)) { |
|
| 560 | + $msg[] = __( |
|
| 561 | + 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
| 562 | + 'event_espresso' |
|
| 563 | + ) . '<br />'; |
|
| 564 | + $msg[] = sprintf( |
|
| 565 | + __( |
|
| 566 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 567 | + 'event_espresso' |
|
| 568 | + ), |
|
| 569 | + $method, |
|
| 570 | + $this->caller |
|
| 571 | + ); |
|
| 572 | + throw new EE_Error(implode('||', $msg)); |
|
| 573 | + } |
|
| 574 | + add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Loop throught the $_init_func array and add_actions for the array. |
|
| 581 | + * |
|
| 582 | + * @return void |
|
| 583 | + */ |
|
| 584 | + protected function _init_hooks() |
|
| 585 | + { |
|
| 586 | + if (empty($this->_init_func)) { |
|
| 587 | + return; |
|
| 588 | + } //get out there's nothing to take care of. |
|
| 589 | + // We need to determine what page_route we are on! |
|
| 590 | + $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 591 | + foreach ($this->_init_func as $route => $method) { |
|
| 592 | + // make sure method exists |
|
| 593 | + if (! method_exists($this, $method)) { |
|
| 594 | + $msg[] = __( |
|
| 595 | + 'There is no corresponding method for the hook labeled in the _init_func array', |
|
| 596 | + 'event_espresso' |
|
| 597 | + ) . '<br />'; |
|
| 598 | + $msg[] = sprintf( |
|
| 599 | + __( |
|
| 600 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 601 | + 'event_espresso' |
|
| 602 | + ), |
|
| 603 | + $method, |
|
| 604 | + $this->caller |
|
| 605 | + ); |
|
| 606 | + throw new EE_Error(implode('||', $msg)); |
|
| 607 | + } |
|
| 608 | + if ($route == $this->_current_route) { |
|
| 609 | + add_action('admin_init', array($this, $method)); |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Loop through the _metaboxes property and add_metaboxes accordingly |
|
| 617 | + * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
| 618 | + * |
|
| 619 | + * @access public |
|
| 620 | + * @return void |
|
| 621 | + */ |
|
| 622 | + public function add_metaboxes() |
|
| 623 | + { |
|
| 624 | + if (empty($this->_metaboxes)) { |
|
| 625 | + return; |
|
| 626 | + } //get out we don't have any metaboxes to set for this connection |
|
| 627 | + $this->_handle_metabox_array($this->_metaboxes); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + private function _handle_metabox_array($boxes, $add = true) |
|
| 632 | + { |
|
| 633 | + |
|
| 634 | + foreach ($boxes as $box) { |
|
| 635 | + if (! isset($box['page_route'])) { |
|
| 636 | + continue; |
|
| 637 | + } //we dont' have a valid array |
|
| 638 | + // let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
| 639 | + $box['page_route'] = (array) $box['page_route']; |
|
| 640 | + foreach ($box['page_route'] as $route) { |
|
| 641 | + if ($route != $this->_current_route) { |
|
| 642 | + continue; |
|
| 643 | + } //get out we only add metaboxes for set route. |
|
| 644 | + if ($add) { |
|
| 645 | + $this->_add_metabox($box); |
|
| 646 | + } else { |
|
| 647 | + $this->_remove_metabox($box); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
| 656 | + * |
|
| 657 | + * @access public |
|
| 658 | + * @return void |
|
| 659 | + */ |
|
| 660 | + public function remove_metaboxes() |
|
| 661 | + { |
|
| 662 | + |
|
| 663 | + if (empty($this->_remove_metaboxes)) { |
|
| 664 | + return; |
|
| 665 | + } //get out there are no metaboxes to remove |
|
| 666 | + $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * This just handles adding a metabox |
|
| 672 | + * |
|
| 673 | + * @access private |
|
| 674 | + * @param array $args an array of args that have been set for this metabox by the child class |
|
| 675 | + */ |
|
| 676 | + private function _add_metabox($args) |
|
| 677 | + { |
|
| 678 | + $current_screen = get_current_screen(); |
|
| 679 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 680 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 681 | + // set defaults |
|
| 682 | + $defaults = array( |
|
| 683 | + 'func' => $func, |
|
| 684 | + 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 685 | + 'priority' => 'default', |
|
| 686 | + 'label' => $this->caller, |
|
| 687 | + 'context' => 'advanced', |
|
| 688 | + 'callback_args' => array(), |
|
| 689 | + 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
| 690 | + ); |
|
| 691 | + $args = wp_parse_args($args, $defaults); |
|
| 692 | + extract($args); |
|
| 693 | + // make sure method exists |
|
| 694 | + if (! method_exists($this, $func)) { |
|
| 695 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 696 | + $msg[] = sprintf( |
|
| 697 | + __( |
|
| 698 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 699 | + 'event_espresso' |
|
| 700 | + ), |
|
| 701 | + $func, |
|
| 702 | + $this->caller |
|
| 703 | + ); |
|
| 704 | + throw new EE_Error(implode('||', $msg)); |
|
| 705 | + } |
|
| 706 | + // everything checks out so lets add the metabox |
|
| 707 | + add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + private function _remove_metabox($args) |
|
| 712 | + { |
|
| 713 | + $current_screen = get_current_screen(); |
|
| 714 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 715 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 716 | + // set defaults |
|
| 717 | + $defaults = array( |
|
| 718 | + 'id' => isset($args['id']) |
|
| 719 | + ? $args['id'] |
|
| 720 | + : $this->_current_route |
|
| 721 | + . '_' |
|
| 722 | + . $this->caller |
|
| 723 | + . '_' |
|
| 724 | + . $func |
|
| 725 | + . '_metabox', |
|
| 726 | + 'context' => 'default', |
|
| 727 | + 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id, |
|
| 728 | + ); |
|
| 729 | + $args = wp_parse_args($args, $defaults); |
|
| 730 | + extract($args); |
|
| 731 | + // everything checks out so lets remove the box! |
|
| 732 | + remove_meta_box($id, $screen, $context); |
|
| 733 | + } |
|
| 734 | 734 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $this->_set_defaults(); |
| 206 | 206 | $this->_set_hooks_properties(); |
| 207 | 207 | // first let's verify we're on the right page |
| 208 | - if (! isset($this->_req_data['page']) |
|
| 208 | + if ( ! isset($this->_req_data['page']) |
|
| 209 | 209 | || (isset($this->_req_data['page']) |
| 210 | 210 | && $this->_adminpage_obj->page_slug |
| 211 | 211 | != $this->_req_data['page'])) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | public function enqueue_scripts_styles() |
| 257 | 257 | { |
| 258 | 258 | |
| 259 | - if (! empty($this->_scripts_styles)) { |
|
| 259 | + if ( ! empty($this->_scripts_styles)) { |
|
| 260 | 260 | // first let's do all the registrations |
| 261 | - if (! isset($this->_scripts_styles['registers'])) { |
|
| 261 | + if ( ! isset($this->_scripts_styles['registers'])) { |
|
| 262 | 262 | $msg[] = __( |
| 263 | 263 | 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
| 264 | 264 | 'event_espresso' |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
| 269 | 269 | 'event_espresso' |
| 270 | 270 | ), |
| 271 | - '<strong>' . $this->caller . '</strong>' |
|
| 271 | + '<strong>'.$this->caller.'</strong>' |
|
| 272 | 272 | ); |
| 273 | 273 | throw new EE_Error(implode('||', $msg)); |
| 274 | 274 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | $details = wp_parse_args($details, $defaults); |
| 284 | 284 | extract($details); |
| 285 | 285 | // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
| 286 | - $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
| 286 | + $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
| 287 | 287 | // let's make sure we're not missing any REQUIRED parameters |
| 288 | 288 | if (empty($url)) { |
| 289 | 289 | $msg[] = sprintf( |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
| 296 | 296 | 'event_espresso' |
| 297 | 297 | ), |
| 298 | - '<strong>' . $this->caller . '</strong>', |
|
| 298 | + '<strong>'.$this->caller.'</strong>', |
|
| 299 | 299 | $ref |
| 300 | 300 | ); |
| 301 | 301 | throw new EE_Error(implode('||', $msg)); |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | ); |
| 312 | 312 | } |
| 313 | 313 | // k now lets do the enqueues |
| 314 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 314 | + if ( ! isset($this->_scripts_styles['enqueues'])) { |
|
| 315 | 315 | return; |
| 316 | 316 | } //not sure if we should throw an error here or not. |
| 317 | 317 | |
@@ -319,22 +319,22 @@ discard block |
||
| 319 | 319 | // make sure $routes is an array |
| 320 | 320 | $routes = (array) $routes; |
| 321 | 321 | if (in_array($this->_current_route, $routes)) { |
| 322 | - $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 322 | + $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 323 | 323 | : wp_enqueue_style($ref); |
| 324 | 324 | // if we have a localization for the script let's do that too. |
| 325 | - if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
| 326 | - foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
| 325 | + if (isset($this->_scripts_styles['localize'][$ref])) { |
|
| 326 | + foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
| 327 | 327 | wp_localize_script( |
| 328 | 328 | $ref, |
| 329 | 329 | $object_name, |
| 330 | - $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
| 330 | + $this->_scripts_styles['localize'][$ref][$object_name] |
|
| 331 | 331 | ); |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | // let's do the deregisters |
| 337 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 337 | + if ( ! isset($this->_scripts_styles['deregisters'])) { |
|
| 338 | 338 | return; |
| 339 | 339 | } |
| 340 | 340 | foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
@@ -396,20 +396,20 @@ discard block |
||
| 396 | 396 | throw new EE_Error(implode('||', $msg)); |
| 397 | 397 | } |
| 398 | 398 | $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
| 399 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
| 399 | + $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; // take the message -> The_Message |
|
| 400 | 400 | // first default file (if exists) |
| 401 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php'; |
|
| 401 | + $decaf_file = EE_ADMIN_PAGES.$this->_name.'/'.$ref.'.core.php'; |
|
| 402 | 402 | if (is_readable($decaf_file)) { |
| 403 | 403 | require_once($decaf_file); |
| 404 | 404 | } |
| 405 | 405 | // now we have to do require for extended file (if needed) |
| 406 | 406 | if ($this->_extend) { |
| 407 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php'); |
|
| 407 | + require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.'/Extend_'.$ref.'.core.php'); |
|
| 408 | 408 | } |
| 409 | 409 | // if we've got an extended class we use that! |
| 410 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 410 | + $ref = $this->_extend ? 'Extend_'.$ref : $ref; |
|
| 411 | 411 | // let's make sure the class exists |
| 412 | - if (! class_exists($ref)) { |
|
| 412 | + if ( ! class_exists($ref)) { |
|
| 413 | 413 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
| 414 | 414 | $msg[] = sprintf( |
| 415 | 415 | __( |
@@ -451,28 +451,28 @@ discard block |
||
| 451 | 451 | // first the actions |
| 452 | 452 | // note that these action hooks will have the $query_args value available. |
| 453 | 453 | $admin_class_name = get_class($this->_adminpage_obj); |
| 454 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 454 | + if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) { |
|
| 455 | 455 | add_action( |
| 456 | 456 | 'AHEE__' |
| 457 | 457 | . $admin_class_name |
| 458 | 458 | . '___redirect_after_action__before_redirect_modification_' |
| 459 | 459 | . $this->_current_route, |
| 460 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 460 | + array($this, '_redirect_action_early_'.$this->_current_route), |
|
| 461 | 461 | 10 |
| 462 | 462 | ); |
| 463 | 463 | } |
| 464 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 464 | + if (method_exists($this, '_redirect_action_'.$this->_current_route)) { |
|
| 465 | 465 | add_action( |
| 466 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 467 | - array($this, '_redirect_action_' . $this->_current_route), |
|
| 466 | + 'AHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
| 467 | + array($this, '_redirect_action_'.$this->_current_route), |
|
| 468 | 468 | 10 |
| 469 | 469 | ); |
| 470 | 470 | } |
| 471 | 471 | // let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
| 472 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 472 | + if (method_exists($this, '_redirect_filter_'.$this->_current_route)) { |
|
| 473 | 473 | add_filter( |
| 474 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 475 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
| 474 | + 'FHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
| 475 | + array($this, '_redirect_filter_'.$this->_current_route), |
|
| 476 | 476 | 10, |
| 477 | 477 | 2 |
| 478 | 478 | ); |
@@ -497,12 +497,12 @@ discard block |
||
| 497 | 497 | 'argnum' => 1, |
| 498 | 498 | 'priority' => 10, |
| 499 | 499 | ), |
| 500 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 500 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array( |
|
| 501 | 501 | 'type' => 'filter', |
| 502 | 502 | 'argnum' => 1, |
| 503 | 503 | 'priority' => 10, |
| 504 | 504 | ), |
| 505 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 505 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug => array( |
|
| 506 | 506 | 'type' => 'filter', |
| 507 | 507 | 'argnum' => 1, |
| 508 | 508 | 'priority' => 10, |
@@ -519,21 +519,21 @@ discard block |
||
| 519 | 519 | ), |
| 520 | 520 | ); |
| 521 | 521 | foreach ($hook_filter_array as $hook => $args) { |
| 522 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 523 | - if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
| 524 | - $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
| 522 | + if (method_exists($this, $this->_current_route.'_'.$hook)) { |
|
| 523 | + if (isset($this->_wp_action_filters_priority[$hook])) { |
|
| 524 | + $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
| 525 | 525 | } |
| 526 | 526 | if ($args['type'] == 'action') { |
| 527 | 527 | add_action( |
| 528 | 528 | $hook, |
| 529 | - array($this, $this->_current_route . '_' . $hook), |
|
| 529 | + array($this, $this->_current_route.'_'.$hook), |
|
| 530 | 530 | $args['priority'], |
| 531 | 531 | $args['argnum'] |
| 532 | 532 | ); |
| 533 | 533 | } else { |
| 534 | 534 | add_filter( |
| 535 | 535 | $hook, |
| 536 | - array($this, $this->_current_route . '_' . $hook), |
|
| 536 | + array($this, $this->_current_route.'_'.$hook), |
|
| 537 | 537 | $args['priority'], |
| 538 | 538 | $args['argnum'] |
| 539 | 539 | ); |
@@ -556,11 +556,11 @@ discard block |
||
| 556 | 556 | } //get out there's nothing to take care of. |
| 557 | 557 | foreach ($this->_ajax_func as $action => $method) { |
| 558 | 558 | // make sure method exists |
| 559 | - if (! method_exists($this, $method)) { |
|
| 559 | + if ( ! method_exists($this, $method)) { |
|
| 560 | 560 | $msg[] = __( |
| 561 | 561 | 'There is no corresponding method for the hook labeled in the _ajax_func array', |
| 562 | 562 | 'event_espresso' |
| 563 | - ) . '<br />'; |
|
| 563 | + ).'<br />'; |
|
| 564 | 564 | $msg[] = sprintf( |
| 565 | 565 | __( |
| 566 | 566 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | ); |
| 572 | 572 | throw new EE_Error(implode('||', $msg)); |
| 573 | 573 | } |
| 574 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 574 | + add_action('wp_ajax_'.$action, array($this, $method)); |
|
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | |
@@ -590,11 +590,11 @@ discard block |
||
| 590 | 590 | $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
| 591 | 591 | foreach ($this->_init_func as $route => $method) { |
| 592 | 592 | // make sure method exists |
| 593 | - if (! method_exists($this, $method)) { |
|
| 593 | + if ( ! method_exists($this, $method)) { |
|
| 594 | 594 | $msg[] = __( |
| 595 | 595 | 'There is no corresponding method for the hook labeled in the _init_func array', |
| 596 | 596 | 'event_espresso' |
| 597 | - ) . '<br />'; |
|
| 597 | + ).'<br />'; |
|
| 598 | 598 | $msg[] = sprintf( |
| 599 | 599 | __( |
| 600 | 600 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | { |
| 633 | 633 | |
| 634 | 634 | foreach ($boxes as $box) { |
| 635 | - if (! isset($box['page_route'])) { |
|
| 635 | + if ( ! isset($box['page_route'])) { |
|
| 636 | 636 | continue; |
| 637 | 637 | } //we dont' have a valid array |
| 638 | 638 | // let's make sure $box['page_route'] is an array so the "foreach" will work. |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | // set defaults |
| 682 | 682 | $defaults = array( |
| 683 | 683 | 'func' => $func, |
| 684 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 684 | + 'id' => $this->caller.'_'.$func.'_metabox', |
|
| 685 | 685 | 'priority' => 'default', |
| 686 | 686 | 'label' => $this->caller, |
| 687 | 687 | 'context' => 'advanced', |
@@ -691,8 +691,8 @@ discard block |
||
| 691 | 691 | $args = wp_parse_args($args, $defaults); |
| 692 | 692 | extract($args); |
| 693 | 693 | // make sure method exists |
| 694 | - if (! method_exists($this, $func)) { |
|
| 695 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 694 | + if ( ! method_exists($this, $func)) { |
|
| 695 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />'; |
|
| 696 | 696 | $msg[] = sprintf( |
| 697 | 697 | __( |
| 698 | 698 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -14,91 +14,91 @@ discard block |
||
| 14 | 14 | class EE_Import implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const do_insert = 'insert'; |
|
| 18 | - const do_update = 'update'; |
|
| 19 | - const do_nothing = 'nothing'; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - // instance of the EE_Import object |
|
| 23 | - private static $_instance = null; |
|
| 24 | - |
|
| 25 | - private static $_csv_array = array(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @var array of model names |
|
| 30 | - */ |
|
| 31 | - private static $_model_list = array(); |
|
| 32 | - |
|
| 33 | - private static $_columns_to_save = array(); |
|
| 34 | - |
|
| 35 | - protected $_total_inserts = 0; |
|
| 36 | - protected $_total_updates = 0; |
|
| 37 | - protected $_total_insert_errors = 0; |
|
| 38 | - protected $_total_update_errors = 0; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * private constructor to prevent direct creation |
|
| 43 | - * |
|
| 44 | - * @Constructor |
|
| 45 | - * @access private |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - private function __construct() |
|
| 49 | - { |
|
| 50 | - $this->_total_inserts = 0; |
|
| 51 | - $this->_total_updates = 0; |
|
| 52 | - $this->_total_insert_errors = 0; |
|
| 53 | - $this->_total_update_errors = 0; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @ singleton method used to instantiate class object |
|
| 59 | - * @ access public |
|
| 60 | - * |
|
| 61 | - * @return EE_Import |
|
| 62 | - */ |
|
| 63 | - public static function instance() |
|
| 64 | - { |
|
| 65 | - // check if class object is instantiated |
|
| 66 | - if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
| 67 | - self::$_instance = new self(); |
|
| 68 | - } |
|
| 69 | - return self::$_instance; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Resets the importer |
|
| 74 | - * |
|
| 75 | - * @return EE_Import |
|
| 76 | - */ |
|
| 77 | - public static function reset() |
|
| 78 | - { |
|
| 79 | - self::$_instance = null; |
|
| 80 | - return self::instance(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @ generates HTML for a file upload input and form |
|
| 86 | - * @ access public |
|
| 87 | - * |
|
| 88 | - * @param string $title - heading for the form |
|
| 89 | - * @param string $intro - additional text explaing what to do |
|
| 90 | - * @param string $page - EE Admin page to direct form to - in the form "espresso_{pageslug}" |
|
| 91 | - * @param string $action - EE Admin page route array "action" that form will direct to |
|
| 92 | - * @param string $type - type of file to import |
|
| 93 | - * @ return string |
|
| 94 | - */ |
|
| 95 | - public function upload_form($title, $intro, $form_url, $action, $type) |
|
| 96 | - { |
|
| 97 | - |
|
| 98 | - $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
| 99 | - |
|
| 100 | - ob_start(); |
|
| 101 | - ?> |
|
| 17 | + const do_insert = 'insert'; |
|
| 18 | + const do_update = 'update'; |
|
| 19 | + const do_nothing = 'nothing'; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + // instance of the EE_Import object |
|
| 23 | + private static $_instance = null; |
|
| 24 | + |
|
| 25 | + private static $_csv_array = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @var array of model names |
|
| 30 | + */ |
|
| 31 | + private static $_model_list = array(); |
|
| 32 | + |
|
| 33 | + private static $_columns_to_save = array(); |
|
| 34 | + |
|
| 35 | + protected $_total_inserts = 0; |
|
| 36 | + protected $_total_updates = 0; |
|
| 37 | + protected $_total_insert_errors = 0; |
|
| 38 | + protected $_total_update_errors = 0; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * private constructor to prevent direct creation |
|
| 43 | + * |
|
| 44 | + * @Constructor |
|
| 45 | + * @access private |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + private function __construct() |
|
| 49 | + { |
|
| 50 | + $this->_total_inserts = 0; |
|
| 51 | + $this->_total_updates = 0; |
|
| 52 | + $this->_total_insert_errors = 0; |
|
| 53 | + $this->_total_update_errors = 0; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @ singleton method used to instantiate class object |
|
| 59 | + * @ access public |
|
| 60 | + * |
|
| 61 | + * @return EE_Import |
|
| 62 | + */ |
|
| 63 | + public static function instance() |
|
| 64 | + { |
|
| 65 | + // check if class object is instantiated |
|
| 66 | + if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
| 67 | + self::$_instance = new self(); |
|
| 68 | + } |
|
| 69 | + return self::$_instance; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Resets the importer |
|
| 74 | + * |
|
| 75 | + * @return EE_Import |
|
| 76 | + */ |
|
| 77 | + public static function reset() |
|
| 78 | + { |
|
| 79 | + self::$_instance = null; |
|
| 80 | + return self::instance(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @ generates HTML for a file upload input and form |
|
| 86 | + * @ access public |
|
| 87 | + * |
|
| 88 | + * @param string $title - heading for the form |
|
| 89 | + * @param string $intro - additional text explaing what to do |
|
| 90 | + * @param string $page - EE Admin page to direct form to - in the form "espresso_{pageslug}" |
|
| 91 | + * @param string $action - EE Admin page route array "action" that form will direct to |
|
| 92 | + * @param string $type - type of file to import |
|
| 93 | + * @ return string |
|
| 94 | + */ |
|
| 95 | + public function upload_form($title, $intro, $form_url, $action, $type) |
|
| 96 | + { |
|
| 97 | + |
|
| 98 | + $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
| 99 | + |
|
| 100 | + ob_start(); |
|
| 101 | + ?> |
|
| 102 | 102 | <div class="ee-upload-form-dv"> |
| 103 | 103 | <h3><?php echo $title; ?></h3> |
| 104 | 104 | <p><?php echo $intro; ?></p> |
@@ -114,874 +114,874 @@ discard block |
||
| 114 | 114 | <b><?php _e('Attention', 'event_espresso'); ?></b><br/> |
| 115 | 115 | <?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?> |
| 116 | 116 | <?php echo __( |
| 117 | - 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', |
|
| 118 | - 'event_espresso' |
|
| 119 | - ); ?> |
|
| 117 | + 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', |
|
| 118 | + 'event_espresso' |
|
| 119 | + ); ?> |
|
| 120 | 120 | </p> |
| 121 | 121 | |
| 122 | 122 | </div> |
| 123 | 123 | |
| 124 | 124 | <?php |
| 125 | - $uploader = ob_get_clean(); |
|
| 126 | - return $uploader; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php |
|
| 132 | - * @access public |
|
| 133 | - * @return boolean success |
|
| 134 | - */ |
|
| 135 | - public function import() |
|
| 136 | - { |
|
| 137 | - |
|
| 138 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
| 139 | - $this->EE_CSV = EE_CSV::instance(); |
|
| 140 | - |
|
| 141 | - if (isset($_REQUEST['import'])) { |
|
| 142 | - if (isset($_POST['csv_submitted'])) { |
|
| 143 | - switch ($_FILES['file']['error'][0]) { |
|
| 144 | - case UPLOAD_ERR_OK: |
|
| 145 | - $error_msg = false; |
|
| 146 | - break; |
|
| 147 | - case UPLOAD_ERR_INI_SIZE: |
|
| 148 | - $error_msg = __( |
|
| 149 | - "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", |
|
| 150 | - "event_espresso" |
|
| 151 | - ); |
|
| 152 | - break; |
|
| 153 | - case UPLOAD_ERR_FORM_SIZE: |
|
| 154 | - $error_msg = __( |
|
| 155 | - 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', |
|
| 156 | - "event_espresso" |
|
| 157 | - ); |
|
| 158 | - break; |
|
| 159 | - case UPLOAD_ERR_PARTIAL: |
|
| 160 | - $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
| 161 | - break; |
|
| 162 | - case UPLOAD_ERR_NO_FILE: |
|
| 163 | - $error_msg = __('No file was uploaded.', "event_espresso"); |
|
| 164 | - break; |
|
| 165 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
| 166 | - $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
| 167 | - break; |
|
| 168 | - case UPLOAD_ERR_CANT_WRITE: |
|
| 169 | - $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
| 170 | - break; |
|
| 171 | - case UPLOAD_ERR_EXTENSION: |
|
| 172 | - $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
| 173 | - break; |
|
| 174 | - default: |
|
| 175 | - $error_msg = __( |
|
| 176 | - 'An unknown error occurred and the file could not be uploaded', |
|
| 177 | - "event_espresso" |
|
| 178 | - ); |
|
| 179 | - break; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (! $error_msg) { |
|
| 183 | - $filename = $_FILES['file']['name'][0]; |
|
| 184 | - $file_ext = substr(strrchr($filename, '.'), 1); |
|
| 185 | - $file_type = $_FILES['file']['type'][0]; |
|
| 186 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
| 187 | - $filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB |
|
| 188 | - |
|
| 189 | - if ($file_ext == 'csv') { |
|
| 190 | - $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
| 191 | - if ($filesize < $max_upload || true) { |
|
| 192 | - $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
|
| 193 | - $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
| 194 | - |
|
| 195 | - if (move_uploaded_file($temp_file, $path_to_file)) { |
|
| 196 | - // convert csv to array |
|
| 197 | - $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
| 198 | - |
|
| 199 | - // was data successfully stored in an array? |
|
| 200 | - if (is_array($this->csv_array)) { |
|
| 201 | - $import_what = str_replace('csv_import_', '', $_REQUEST['action']); |
|
| 202 | - $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
| 203 | - $processed_data = $this->csv_array; |
|
| 204 | - $this->columns_to_save = false; |
|
| 205 | - |
|
| 206 | - // if any imports require funcky processing, we'll catch them in the switch |
|
| 207 | - switch ($_REQUEST['action']) { |
|
| 208 | - case "import_events": |
|
| 209 | - case "event_list": |
|
| 210 | - $import_what = 'Event Details'; |
|
| 211 | - break; |
|
| 212 | - |
|
| 213 | - case 'groupon_import_csv': |
|
| 214 | - $import_what = 'Groupon Codes'; |
|
| 215 | - $processed_data = $this->process_groupon_codes(); |
|
| 216 | - break; |
|
| 217 | - } |
|
| 218 | - // save processed codes to db |
|
| 219 | - if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
| 220 | - return true; |
|
| 221 | - } |
|
| 222 | - } else { |
|
| 223 | - // no array? must be an error |
|
| 224 | - EE_Error::add_error( |
|
| 225 | - sprintf(__("No file seems to have been uploaded", "event_espresso")), |
|
| 226 | - __FILE__, |
|
| 227 | - __FUNCTION__, |
|
| 228 | - __LINE__ |
|
| 229 | - ); |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - } else { |
|
| 233 | - EE_Error::add_error( |
|
| 234 | - sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), |
|
| 235 | - __FILE__, |
|
| 236 | - __FUNCTION__, |
|
| 237 | - __LINE__ |
|
| 238 | - ); |
|
| 239 | - return false; |
|
| 240 | - } |
|
| 241 | - } else { |
|
| 242 | - EE_Error::add_error( |
|
| 243 | - sprintf( |
|
| 244 | - __( |
|
| 245 | - "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", |
|
| 246 | - "event_espresso" |
|
| 247 | - ), |
|
| 248 | - $filename, |
|
| 249 | - $max_upload |
|
| 250 | - ), |
|
| 251 | - __FILE__, |
|
| 252 | - __FUNCTION__, |
|
| 253 | - __LINE__ |
|
| 254 | - ); |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - } else { |
|
| 258 | - EE_Error::add_error( |
|
| 259 | - sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), |
|
| 260 | - __FILE__, |
|
| 261 | - __FUNCTION__, |
|
| 262 | - __LINE__ |
|
| 263 | - ); |
|
| 264 | - return false; |
|
| 265 | - } |
|
| 266 | - } else { |
|
| 267 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 268 | - return false; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - return; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
| 278 | - * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
| 279 | - * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
| 280 | - * being keys of model fields and their proposed values. |
|
| 281 | - * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
| 282 | - * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
| 283 | - * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
| 284 | - * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
| 285 | - * which can used elsewhere to refer to the same object. Once an item |
|
| 286 | - * with a temporary ID gets inserted, we record its mapping from temporary |
|
| 287 | - * ID to real ID, and use the real ID in place of the temporary ID |
|
| 288 | - * when that temporary ID was used as a foreign key. |
|
| 289 | - * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
| 290 | - * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
| 291 | - * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
| 292 | - * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
| 293 | - * An important exception are non-auto-increment primary keys. If one entry in the |
|
| 294 | - * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
| 295 | - * the same item, and instead update the item in the DB with that same ID. |
|
| 296 | - * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
| 297 | - * time you import a CSV from a different site, we remember their mappings, and |
|
| 298 | - * will try to update the item in the DB instead of inserting another item (eg |
|
| 299 | - * if we previously imported an event with temporary ID 1, and then it got a |
|
| 300 | - * real ID of 123, we remember that. So the next time we import an event with |
|
| 301 | - * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
| 302 | - * update that event, instead of adding a new event). |
|
| 303 | - * |
|
| 304 | - * @access public |
|
| 305 | - * @param array $csv_data_array - the array containing the csv data produced from |
|
| 306 | - * EE_CSV::import_csv_to_model_data_array() |
|
| 307 | - * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table |
|
| 308 | - * fields they will be saved to |
|
| 309 | - * @return TRUE on success, FALSE on fail |
|
| 310 | - * @throws \EE_Error |
|
| 311 | - */ |
|
| 312 | - public function save_csv_data_array_to_db($csv_data_array, $model_name = false) |
|
| 313 | - { |
|
| 314 | - $success = false; |
|
| 315 | - $error = false; |
|
| 316 | - // whther to treat this import as if it's data froma different database or not |
|
| 317 | - // ie, if it IS from a different database, ignore foreign keys whihf |
|
| 318 | - $export_from_site_a_to_b = true; |
|
| 319 | - // first level of array is not table information but a table name was passed to the function |
|
| 320 | - // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
|
| 321 | - if ($model_name) { |
|
| 322 | - $csv_data_array = array($csv_data_array); |
|
| 323 | - } |
|
| 324 | - // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
|
| 325 | - $old_site_url = 'none-specified'; |
|
| 326 | - // hanlde metadata |
|
| 327 | - if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
| 328 | - $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
| 329 | - // ok so its metadata, dont try to save it to ehte db obviously... |
|
| 330 | - if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
| 331 | - EE_Error::add_attention( |
|
| 332 | - sprintf( |
|
| 333 | - __( |
|
| 334 | - "CSV Data appears to be from the same database, so attempting to update data", |
|
| 335 | - "event_espresso" |
|
| 336 | - ) |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - $export_from_site_a_to_b = false; |
|
| 340 | - } else { |
|
| 341 | - $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
| 342 | - EE_Error::add_attention( |
|
| 343 | - sprintf( |
|
| 344 | - __( |
|
| 345 | - "CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", |
|
| 346 | - "event_espresso" |
|
| 347 | - ), |
|
| 348 | - $old_site_url, |
|
| 349 | - site_url() |
|
| 350 | - ) |
|
| 351 | - ); |
|
| 352 | - }; |
|
| 353 | - unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
| 354 | - } |
|
| 355 | - /** |
|
| 356 | - * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
| 357 | - * the value will be the newly-inserted ID. |
|
| 358 | - * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
| 359 | - */ |
|
| 360 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
| 361 | - if ($old_db_to_new_db_mapping) { |
|
| 362 | - EE_Error::add_attention( |
|
| 363 | - sprintf( |
|
| 364 | - __( |
|
| 365 | - "We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", |
|
| 366 | - "event_espresso" |
|
| 367 | - ), |
|
| 368 | - $old_site_url, |
|
| 369 | - site_url() |
|
| 370 | - ) |
|
| 371 | - ); |
|
| 372 | - } |
|
| 373 | - $old_db_to_new_db_mapping = $this->save_data_rows_to_db( |
|
| 374 | - $csv_data_array, |
|
| 375 | - $export_from_site_a_to_b, |
|
| 376 | - $old_db_to_new_db_mapping |
|
| 377 | - ); |
|
| 378 | - |
|
| 379 | - // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
|
| 380 | - update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
| 381 | - |
|
| 382 | - if ($this->_total_updates > 0) { |
|
| 383 | - EE_Error::add_success( |
|
| 384 | - sprintf( |
|
| 385 | - __("%s existing records in the database were updated.", "event_espresso"), |
|
| 386 | - $this->_total_updates |
|
| 387 | - ) |
|
| 388 | - ); |
|
| 389 | - $success = true; |
|
| 390 | - } |
|
| 391 | - if ($this->_total_inserts > 0) { |
|
| 392 | - EE_Error::add_success( |
|
| 393 | - sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts) |
|
| 394 | - ); |
|
| 395 | - $success = true; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - if ($this->_total_update_errors > 0) { |
|
| 399 | - EE_Error::add_error( |
|
| 400 | - sprintf( |
|
| 401 | - __( |
|
| 402 | - "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", |
|
| 403 | - "event_espresso" |
|
| 404 | - ), |
|
| 405 | - $this->_total_update_errors |
|
| 406 | - ), |
|
| 407 | - __FILE__, |
|
| 408 | - __FUNCTION__, |
|
| 409 | - __LINE__ |
|
| 410 | - ); |
|
| 411 | - $error = true; |
|
| 412 | - } |
|
| 413 | - if ($this->_total_insert_errors > 0) { |
|
| 414 | - EE_Error::add_error( |
|
| 415 | - sprintf( |
|
| 416 | - __( |
|
| 417 | - "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", |
|
| 418 | - "event_espresso" |
|
| 419 | - ), |
|
| 420 | - $this->_total_insert_errors |
|
| 421 | - ), |
|
| 422 | - __FILE__, |
|
| 423 | - __FUNCTION__, |
|
| 424 | - __LINE__ |
|
| 425 | - ); |
|
| 426 | - $error = true; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // lastly, we need to update the datetime and ticket sold amounts |
|
| 430 | - // as those may have been affected by this |
|
| 431 | - EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
|
| 432 | - |
|
| 433 | - // if there was at least one success and absolutely no errors |
|
| 434 | - if ($success && ! $error) { |
|
| 435 | - return true; |
|
| 436 | - } else { |
|
| 437 | - return false; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Processes the array of data, given the knowledge that it's from the same database or a different one, |
|
| 444 | - * and the mapping from temporary IDs to real IDs. |
|
| 445 | - * If the data is from a different database, we treat the primary keys and their corresponding |
|
| 446 | - * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys |
|
| 447 | - * in the real target database. As items are inserted, their temporary primary keys |
|
| 448 | - * are mapped to the real IDs in the target database. Also, before doing any update or |
|
| 449 | - * insert, we replace all the temp ID which are foreign keys with their mapped real IDs. |
|
| 450 | - * An exception: string primary keys are treated as real IDs, or else we'd need to |
|
| 451 | - * dynamically generate new string primary keys which would be very awkard for the country table etc. |
|
| 452 | - * Also, models with no primary key are strange too. We combine use their primar key INDEX (a |
|
| 453 | - * combination of fields) to create a unique string identifying the row and store |
|
| 454 | - * those in the mapping. |
|
| 455 | - * |
|
| 456 | - * If the data is from the same database, we usually treat primary keys as real IDs. |
|
| 457 | - * An exception is if there is nothing in the database for that ID. If that's the case, |
|
| 458 | - * we need to insert a new row for that ID, and then map from the non-existent ID |
|
| 459 | - * to the newly-inserted real ID. |
|
| 460 | - * |
|
| 461 | - * @param type $csv_data_array |
|
| 462 | - * @param type $export_from_site_a_to_b |
|
| 463 | - * @param type $old_db_to_new_db_mapping |
|
| 464 | - * @return array updated $old_db_to_new_db_mapping |
|
| 465 | - */ |
|
| 466 | - public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) |
|
| 467 | - { |
|
| 468 | - foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
| 469 | - // now check that assumption was correct. If |
|
| 470 | - if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
| 471 | - $model_name = $model_name_in_csv_data; |
|
| 472 | - } else { |
|
| 473 | - // no table info in the array and no table name passed to the function?? FAIL |
|
| 474 | - EE_Error::add_error( |
|
| 475 | - __( |
|
| 476 | - 'No table information was specified and/or found, therefore the import could not be completed', |
|
| 477 | - 'event_espresso' |
|
| 478 | - ), |
|
| 479 | - __FILE__, |
|
| 480 | - __FUNCTION__, |
|
| 481 | - __LINE__ |
|
| 482 | - ); |
|
| 483 | - return false; |
|
| 484 | - } |
|
| 485 | - /* @var $model EEM_Base */ |
|
| 486 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 487 | - |
|
| 488 | - // so without further ado, scanning all the data provided for primary keys and their inital values |
|
| 489 | - foreach ($model_data_from_import as $model_object_data) { |
|
| 490 | - // before we do ANYTHING, make sure the csv row wasn't just completely blank |
|
| 491 | - $row_is_completely_empty = true; |
|
| 492 | - foreach ($model_object_data as $field) { |
|
| 493 | - if ($field) { |
|
| 494 | - $row_is_completely_empty = false; |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - if ($row_is_completely_empty) { |
|
| 498 | - continue; |
|
| 499 | - } |
|
| 500 | - // find the PK in the row of data (or a combined key if |
|
| 501 | - // there is no primary key) |
|
| 502 | - if ($model->has_primary_key_field()) { |
|
| 503 | - $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
| 504 | - } else { |
|
| 505 | - $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - $model_object_data = $this->_replace_temp_ids_with_mappings( |
|
| 510 | - $model_object_data, |
|
| 511 | - $model, |
|
| 512 | - $old_db_to_new_db_mapping, |
|
| 513 | - $export_from_site_a_to_b |
|
| 514 | - ); |
|
| 515 | - // now we need to decide if we're going to add a new model object given the $model_object_data, |
|
| 516 | - // or just update. |
|
| 517 | - if ($export_from_site_a_to_b) { |
|
| 518 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( |
|
| 519 | - $id_in_csv, |
|
| 520 | - $model_object_data, |
|
| 521 | - $model, |
|
| 522 | - $old_db_to_new_db_mapping |
|
| 523 | - ); |
|
| 524 | - } else {// this is just a re-import |
|
| 525 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( |
|
| 526 | - $id_in_csv, |
|
| 527 | - $model_object_data, |
|
| 528 | - $model, |
|
| 529 | - $old_db_to_new_db_mapping |
|
| 530 | - ); |
|
| 531 | - } |
|
| 532 | - if ($what_to_do == self::do_nothing) { |
|
| 533 | - continue; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // double-check we actually want to insert, if that's what we're planning |
|
| 537 | - // based on whether this item would be unique in the DB or not |
|
| 538 | - if ($what_to_do == self::do_insert) { |
|
| 539 | - // we're supposed to be inserting. But wait, will this thing |
|
| 540 | - // be acceptable if inserted? |
|
| 541 | - $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
| 542 | - if ($conflicting) { |
|
| 543 | - // ok, this item would conflict if inserted. Just update the item that it conflicts with. |
|
| 544 | - $what_to_do = self::do_update; |
|
| 545 | - // and if this model has a primary key, remember its mapping |
|
| 546 | - if ($model->has_primary_key_field()) { |
|
| 547 | - $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
| 548 | - $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
| 549 | - } else { |
|
| 550 | - // we want to update this conflicting item, instead of inserting a conflicting item |
|
| 551 | - // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
|
| 552 | - // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
|
| 553 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 554 | - $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
| 555 | - $key_field->get_name() |
|
| 556 | - ); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - if ($what_to_do == self::do_insert) { |
|
| 562 | - $old_db_to_new_db_mapping = $this->_insert_from_data_array( |
|
| 563 | - $id_in_csv, |
|
| 564 | - $model_object_data, |
|
| 565 | - $model, |
|
| 566 | - $old_db_to_new_db_mapping |
|
| 567 | - ); |
|
| 568 | - } elseif ($what_to_do == self::do_update) { |
|
| 569 | - $old_db_to_new_db_mapping = $this->_update_from_data_array( |
|
| 570 | - $id_in_csv, |
|
| 571 | - $model_object_data, |
|
| 572 | - $model, |
|
| 573 | - $old_db_to_new_db_mapping |
|
| 574 | - ); |
|
| 575 | - } else { |
|
| 576 | - throw new EE_Error( |
|
| 577 | - sprintf( |
|
| 578 | - __( |
|
| 579 | - 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ), |
|
| 582 | - $what_to_do |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - return $old_db_to_new_db_mapping; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Decides whether or not to insert, given that this data is from another database. |
|
| 594 | - * So, if the primary key of this $model_object_data already exists in the database, |
|
| 595 | - * it's just a coincidence and we should still insert. The only time we should |
|
| 596 | - * update is when we know what it maps to, or there's something that would |
|
| 597 | - * conflict (and we should instead just update that conflicting thing) |
|
| 598 | - * |
|
| 599 | - * @param string $id_in_csv |
|
| 600 | - * @param array $model_object_data by reference so it can be modified |
|
| 601 | - * @param EEM_Base $model |
|
| 602 | - * @param array $old_db_to_new_db_mapping by reference so it can be modified |
|
| 603 | - * @return string one of the consts on this class that starts with do_* |
|
| 604 | - */ |
|
| 605 | - protected function _decide_whether_to_insert_or_update_given_data_from_other_db( |
|
| 606 | - $id_in_csv, |
|
| 607 | - $model_object_data, |
|
| 608 | - $model, |
|
| 609 | - $old_db_to_new_db_mapping |
|
| 610 | - ) { |
|
| 611 | - $model_name = $model->get_this_model_name(); |
|
| 612 | - // if it's a site-to-site export-and-import, see if this modelobject's id |
|
| 613 | - // in the old data that we know of |
|
| 614 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
| 615 | - return self::do_update; |
|
| 616 | - } else { |
|
| 617 | - return self::do_insert; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * If this thing basically already exists in the database, we want to update it; |
|
| 623 | - * otherwise insert it (ie, someone tweaked the CSV file, or the item was |
|
| 624 | - * deleted in the database so it should be re-inserted) |
|
| 625 | - * |
|
| 626 | - * @param type $id_in_csv |
|
| 627 | - * @param type $model_object_data |
|
| 628 | - * @param EEM_Base $model |
|
| 629 | - * @param type $old_db_to_new_db_mapping |
|
| 630 | - * @return |
|
| 631 | - */ |
|
| 632 | - protected function _decide_whether_to_insert_or_update_given_data_from_same_db( |
|
| 633 | - $id_in_csv, |
|
| 634 | - $model_object_data, |
|
| 635 | - $model |
|
| 636 | - ) { |
|
| 637 | - // in this case, check if this thing ACTUALLY exists in the database |
|
| 638 | - if ($model->get_one_conflicting($model_object_data)) { |
|
| 639 | - return self::do_update; |
|
| 640 | - } else { |
|
| 641 | - return self::do_insert; |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs |
|
| 647 | - * with their mapped real IDs. Eg, if importing from site A to B, the mapping |
|
| 648 | - * file may indicate that the ID "my_event_id" maps to an actual event ID of 123. |
|
| 649 | - * So this function searches for any event temp Ids called "my_event_id" and |
|
| 650 | - * replaces them with 123. |
|
| 651 | - * Also, if there is no temp ID for the INT foreign keys from another database, |
|
| 652 | - * replaces them with 0 or the field's default. |
|
| 653 | - * |
|
| 654 | - * @param type $model_object_data |
|
| 655 | - * @param EEM_Base $model |
|
| 656 | - * @param type $old_db_to_new_db_mapping |
|
| 657 | - * @param boolean $export_from_site_a_to_b |
|
| 658 | - * @return array updated model object data with temp IDs removed |
|
| 659 | - */ |
|
| 660 | - protected function _replace_temp_ids_with_mappings( |
|
| 661 | - $model_object_data, |
|
| 662 | - $model, |
|
| 663 | - $old_db_to_new_db_mapping, |
|
| 664 | - $export_from_site_a_to_b |
|
| 665 | - ) { |
|
| 666 | - // if this model object's primary key is in the mapping, replace it |
|
| 667 | - if ($model->has_primary_key_field() && |
|
| 668 | - $model->get_primary_key_field()->is_auto_increment() && |
|
| 669 | - isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
| 670 | - isset( |
|
| 671 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
| 672 | - )) { |
|
| 673 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
| 674 | - ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - try { |
|
| 678 | - $model_name_field = $model->get_field_containing_related_model_name(); |
|
| 679 | - $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
|
| 680 | - } catch (EE_Error $e) { |
|
| 681 | - $model_name_field = null; |
|
| 682 | - $models_pointed_to_by_model_name_field = array(); |
|
| 683 | - } |
|
| 684 | - foreach ($model->field_settings(true) as $field_obj) { |
|
| 685 | - if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
| 686 | - $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
|
| 687 | - $found_a_mapping = false; |
|
| 688 | - foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
| 689 | - if ($model_name_field) { |
|
| 690 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
| 691 | - if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
| 692 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
| 693 | - $model_object_data[ $field_obj->get_name() ], |
|
| 694 | - $model_pointed_to_by_fk, |
|
| 695 | - $old_db_to_new_db_mapping, |
|
| 696 | - $export_from_site_a_to_b |
|
| 697 | - ); |
|
| 698 | - $found_a_mapping = true; |
|
| 699 | - break; |
|
| 700 | - } |
|
| 701 | - } else { |
|
| 702 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
| 703 | - $model_object_data[ $field_obj->get_name() ], |
|
| 704 | - $model_pointed_to_by_fk, |
|
| 705 | - $old_db_to_new_db_mapping, |
|
| 706 | - $export_from_site_a_to_b |
|
| 707 | - ); |
|
| 708 | - $found_a_mapping = true; |
|
| 709 | - } |
|
| 710 | - // once we've found a mapping for this field no need to continue |
|
| 711 | - if ($found_a_mapping) { |
|
| 712 | - break; |
|
| 713 | - } |
|
| 714 | - } |
|
| 715 | - } else { |
|
| 716 | - // it's a string foreign key (which we leave alone, because those are things |
|
| 717 | - // like country names, which we'd really rather not make 2 USAs etc (we'd actually |
|
| 718 | - // prefer to just update one) |
|
| 719 | - // or it's just a regular value that ought to be replaced |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - // |
|
| 723 | - if ($model instanceof EEM_Term_Taxonomy) { |
|
| 724 | - $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
| 725 | - } |
|
| 726 | - return $model_object_data; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id |
|
| 731 | - * this term-taxonomy refers to may be out-of-date so we need to update it. |
|
| 732 | - * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ |
|
| 733 | - * |
|
| 734 | - * @param type $model_object_data |
|
| 735 | - * @return array new model object data |
|
| 736 | - */ |
|
| 737 | - protected function _handle_split_term_ids($model_object_data) |
|
| 738 | - { |
|
| 739 | - if (isset($model_object_data['term_id']) |
|
| 740 | - && isset($model_object_data['taxonomy']) |
|
| 741 | - && apply_filters( |
|
| 742 | - 'FHEE__EE_Import__handle_split_term_ids__function_exists', |
|
| 743 | - function_exists('wp_get_split_term'), |
|
| 744 | - $model_object_data |
|
| 745 | - )) { |
|
| 746 | - $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
| 747 | - if ($new_term_id) { |
|
| 748 | - $model_object_data['term_id'] = $new_term_id; |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - return $model_object_data; |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * Given the object's ID and its model's name, find it int he mapping data, |
|
| 756 | - * bearing in mind where it came from |
|
| 757 | - * |
|
| 758 | - * @param type $object_id |
|
| 759 | - * @param string $model_name |
|
| 760 | - * @param array $old_db_to_new_db_mapping |
|
| 761 | - * @param type $export_from_site_a_to_b |
|
| 762 | - * @return int |
|
| 763 | - */ |
|
| 764 | - protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
|
| 765 | - { |
|
| 766 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
| 767 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
| 768 | - } elseif ($object_id == '0' || $object_id == '') { |
|
| 769 | - // leave as-is |
|
| 770 | - return $object_id; |
|
| 771 | - } elseif ($export_from_site_a_to_b) { |
|
| 772 | - // we couldn't find a mapping for this, and it's from a different site, |
|
| 773 | - // so blank it out |
|
| 774 | - return null; |
|
| 775 | - } elseif (! $export_from_site_a_to_b) { |
|
| 776 | - // we coudln't find a mapping for this, but it's from thsi DB anyway |
|
| 777 | - // so let's just leave it as-is |
|
| 778 | - return $object_id; |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * |
|
| 784 | - * @param type $id_in_csv |
|
| 785 | - * @param type $model_object_data |
|
| 786 | - * @param EEM_Base $model |
|
| 787 | - * @param type $old_db_to_new_db_mapping |
|
| 788 | - * @return array updated $old_db_to_new_db_mapping |
|
| 789 | - */ |
|
| 790 | - protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
| 791 | - { |
|
| 792 | - // remove the primary key, if there is one (we don't want it for inserts OR updates) |
|
| 793 | - // we'll put it back in if we need it |
|
| 794 | - if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
| 795 | - $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
| 796 | - unset($model_object_data[ $model->primary_key_name() ]); |
|
| 797 | - } else { |
|
| 798 | - $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
| 799 | - } |
|
| 800 | - // the model takes care of validating the CSV's input |
|
| 801 | - try { |
|
| 802 | - $new_id = $model->insert($model_object_data); |
|
| 803 | - if ($new_id) { |
|
| 804 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
| 805 | - $this->_total_inserts++; |
|
| 806 | - EE_Error::add_success( |
|
| 807 | - sprintf( |
|
| 808 | - __("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), |
|
| 809 | - $model->get_this_model_name(), |
|
| 810 | - $new_id, |
|
| 811 | - implode(",", $model_object_data) |
|
| 812 | - ) |
|
| 813 | - ); |
|
| 814 | - } else { |
|
| 815 | - $this->_total_insert_errors++; |
|
| 816 | - // put the ID used back in there for the error message |
|
| 817 | - if ($model->has_primary_key_field()) { |
|
| 818 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
| 819 | - } |
|
| 820 | - EE_Error::add_error( |
|
| 821 | - sprintf( |
|
| 822 | - __("Could not insert new %s with the csv data: %s", "event_espresso"), |
|
| 823 | - $model->get_this_model_name(), |
|
| 824 | - http_build_query($model_object_data) |
|
| 825 | - ), |
|
| 826 | - __FILE__, |
|
| 827 | - __FUNCTION__, |
|
| 828 | - __LINE__ |
|
| 829 | - ); |
|
| 830 | - } |
|
| 831 | - } catch (EE_Error $e) { |
|
| 832 | - $this->_total_insert_errors++; |
|
| 833 | - if ($model->has_primary_key_field()) { |
|
| 834 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
| 835 | - } |
|
| 836 | - EE_Error::add_error( |
|
| 837 | - sprintf( |
|
| 838 | - __("Could not insert new %s with the csv data: %s because %s", "event_espresso"), |
|
| 839 | - $model->get_this_model_name(), |
|
| 840 | - implode(",", $model_object_data), |
|
| 841 | - $e->getMessage() |
|
| 842 | - ), |
|
| 843 | - __FILE__, |
|
| 844 | - __FUNCTION__, |
|
| 845 | - __LINE__ |
|
| 846 | - ); |
|
| 847 | - } |
|
| 848 | - return $old_db_to_new_db_mapping; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * Given the model object data, finds the row to update and updates it |
|
| 853 | - * |
|
| 854 | - * @param string|int $id_in_csv |
|
| 855 | - * @param array $model_object_data |
|
| 856 | - * @param EEM_Base $model |
|
| 857 | - * @param array $old_db_to_new_db_mapping |
|
| 858 | - * @return array updated $old_db_to_new_db_mapping |
|
| 859 | - */ |
|
| 860 | - protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
| 861 | - { |
|
| 862 | - try { |
|
| 863 | - // let's keep two copies of the model object data: |
|
| 864 | - // one for performing an update, one for everthing else |
|
| 865 | - $model_object_data_for_update = $model_object_data; |
|
| 866 | - if ($model->has_primary_key_field()) { |
|
| 867 | - $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
| 868 | - // remove the primary key because we shouldn't use it for updating |
|
| 869 | - unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
| 870 | - } elseif ($model->get_combined_primary_key_fields() > 1) { |
|
| 871 | - $conditions = array(); |
|
| 872 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 873 | - $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
| 874 | - } |
|
| 875 | - } else { |
|
| 876 | - $model->primary_key_name( |
|
| 877 | - );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - $success = $model->update($model_object_data_for_update, array($conditions)); |
|
| 881 | - if ($success) { |
|
| 882 | - $this->_total_updates++; |
|
| 883 | - EE_Error::add_success( |
|
| 884 | - sprintf( |
|
| 885 | - __("Successfully updated %s with csv data %s", "event_espresso"), |
|
| 886 | - $model->get_this_model_name(), |
|
| 887 | - implode(",", $model_object_data_for_update) |
|
| 888 | - ) |
|
| 889 | - ); |
|
| 890 | - // we should still record the mapping even though it was an update |
|
| 891 | - // because if we were going to insert somethign but it was going to conflict |
|
| 892 | - // we would have last-minute decided to update. So we'd like to know what we updated |
|
| 893 | - // and so we record what record ended up being updated using the mapping |
|
| 894 | - if ($model->has_primary_key_field()) { |
|
| 895 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
| 896 | - } else { |
|
| 897 | - // no primary key just a combined key |
|
| 898 | - $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
| 899 | - } |
|
| 900 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
| 901 | - } else { |
|
| 902 | - $matched_items = $model->get_all(array($conditions)); |
|
| 903 | - if (! $matched_items) { |
|
| 904 | - // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
|
| 905 | - $this->_total_update_errors++; |
|
| 906 | - EE_Error::add_error( |
|
| 907 | - sprintf( |
|
| 908 | - __( |
|
| 909 | - "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", |
|
| 910 | - "event_espresso" |
|
| 911 | - ), |
|
| 912 | - $model->get_this_model_name(), |
|
| 913 | - http_build_query($model_object_data), |
|
| 914 | - http_build_query($conditions) |
|
| 915 | - ), |
|
| 916 | - __FILE__, |
|
| 917 | - __FUNCTION__, |
|
| 918 | - __LINE__ |
|
| 919 | - ); |
|
| 920 | - } else { |
|
| 921 | - $this->_total_updates++; |
|
| 922 | - EE_Error::add_success( |
|
| 923 | - sprintf( |
|
| 924 | - __( |
|
| 925 | - "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", |
|
| 926 | - "event_espresso" |
|
| 927 | - ), |
|
| 928 | - $model->get_this_model_name(), |
|
| 929 | - implode(",", $model_object_data) |
|
| 930 | - ) |
|
| 931 | - ); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - } catch (EE_Error $e) { |
|
| 935 | - $this->_total_update_errors++; |
|
| 936 | - $basic_message = sprintf( |
|
| 937 | - __("Could not update %s with the csv data: %s because %s", "event_espresso"), |
|
| 938 | - $model->get_this_model_name(), |
|
| 939 | - implode(",", $model_object_data), |
|
| 940 | - $e->getMessage() |
|
| 941 | - ); |
|
| 942 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
| 943 | - EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
| 944 | - } |
|
| 945 | - return $old_db_to_new_db_mapping; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - /** |
|
| 949 | - * Gets the number of inserts performed since importer was instantiated or reset |
|
| 950 | - * |
|
| 951 | - * @return int |
|
| 952 | - */ |
|
| 953 | - public function get_total_inserts() |
|
| 954 | - { |
|
| 955 | - return $this->_total_inserts; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - /** |
|
| 959 | - * Gets the number of insert errors since importer was instantiated or reset |
|
| 960 | - * |
|
| 961 | - * @return int |
|
| 962 | - */ |
|
| 963 | - public function get_total_insert_errors() |
|
| 964 | - { |
|
| 965 | - return $this->_total_insert_errors; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - /** |
|
| 969 | - * Gets the number of updates performed since importer was instantiated or reset |
|
| 970 | - * |
|
| 971 | - * @return int |
|
| 972 | - */ |
|
| 973 | - public function get_total_updates() |
|
| 974 | - { |
|
| 975 | - return $this->_total_updates; |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * Gets the number of update errors since importer was instantiated or reset |
|
| 980 | - * |
|
| 981 | - * @return int |
|
| 982 | - */ |
|
| 983 | - public function get_total_update_errors() |
|
| 984 | - { |
|
| 985 | - return $this->_total_update_errors; |
|
| 986 | - } |
|
| 125 | + $uploader = ob_get_clean(); |
|
| 126 | + return $uploader; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php |
|
| 132 | + * @access public |
|
| 133 | + * @return boolean success |
|
| 134 | + */ |
|
| 135 | + public function import() |
|
| 136 | + { |
|
| 137 | + |
|
| 138 | + require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
| 139 | + $this->EE_CSV = EE_CSV::instance(); |
|
| 140 | + |
|
| 141 | + if (isset($_REQUEST['import'])) { |
|
| 142 | + if (isset($_POST['csv_submitted'])) { |
|
| 143 | + switch ($_FILES['file']['error'][0]) { |
|
| 144 | + case UPLOAD_ERR_OK: |
|
| 145 | + $error_msg = false; |
|
| 146 | + break; |
|
| 147 | + case UPLOAD_ERR_INI_SIZE: |
|
| 148 | + $error_msg = __( |
|
| 149 | + "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", |
|
| 150 | + "event_espresso" |
|
| 151 | + ); |
|
| 152 | + break; |
|
| 153 | + case UPLOAD_ERR_FORM_SIZE: |
|
| 154 | + $error_msg = __( |
|
| 155 | + 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', |
|
| 156 | + "event_espresso" |
|
| 157 | + ); |
|
| 158 | + break; |
|
| 159 | + case UPLOAD_ERR_PARTIAL: |
|
| 160 | + $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
| 161 | + break; |
|
| 162 | + case UPLOAD_ERR_NO_FILE: |
|
| 163 | + $error_msg = __('No file was uploaded.', "event_espresso"); |
|
| 164 | + break; |
|
| 165 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
| 166 | + $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
| 167 | + break; |
|
| 168 | + case UPLOAD_ERR_CANT_WRITE: |
|
| 169 | + $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
| 170 | + break; |
|
| 171 | + case UPLOAD_ERR_EXTENSION: |
|
| 172 | + $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
| 173 | + break; |
|
| 174 | + default: |
|
| 175 | + $error_msg = __( |
|
| 176 | + 'An unknown error occurred and the file could not be uploaded', |
|
| 177 | + "event_espresso" |
|
| 178 | + ); |
|
| 179 | + break; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (! $error_msg) { |
|
| 183 | + $filename = $_FILES['file']['name'][0]; |
|
| 184 | + $file_ext = substr(strrchr($filename, '.'), 1); |
|
| 185 | + $file_type = $_FILES['file']['type'][0]; |
|
| 186 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
| 187 | + $filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB |
|
| 188 | + |
|
| 189 | + if ($file_ext == 'csv') { |
|
| 190 | + $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
| 191 | + if ($filesize < $max_upload || true) { |
|
| 192 | + $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
|
| 193 | + $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
| 194 | + |
|
| 195 | + if (move_uploaded_file($temp_file, $path_to_file)) { |
|
| 196 | + // convert csv to array |
|
| 197 | + $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
| 198 | + |
|
| 199 | + // was data successfully stored in an array? |
|
| 200 | + if (is_array($this->csv_array)) { |
|
| 201 | + $import_what = str_replace('csv_import_', '', $_REQUEST['action']); |
|
| 202 | + $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
| 203 | + $processed_data = $this->csv_array; |
|
| 204 | + $this->columns_to_save = false; |
|
| 205 | + |
|
| 206 | + // if any imports require funcky processing, we'll catch them in the switch |
|
| 207 | + switch ($_REQUEST['action']) { |
|
| 208 | + case "import_events": |
|
| 209 | + case "event_list": |
|
| 210 | + $import_what = 'Event Details'; |
|
| 211 | + break; |
|
| 212 | + |
|
| 213 | + case 'groupon_import_csv': |
|
| 214 | + $import_what = 'Groupon Codes'; |
|
| 215 | + $processed_data = $this->process_groupon_codes(); |
|
| 216 | + break; |
|
| 217 | + } |
|
| 218 | + // save processed codes to db |
|
| 219 | + if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
| 220 | + return true; |
|
| 221 | + } |
|
| 222 | + } else { |
|
| 223 | + // no array? must be an error |
|
| 224 | + EE_Error::add_error( |
|
| 225 | + sprintf(__("No file seems to have been uploaded", "event_espresso")), |
|
| 226 | + __FILE__, |
|
| 227 | + __FUNCTION__, |
|
| 228 | + __LINE__ |
|
| 229 | + ); |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + } else { |
|
| 233 | + EE_Error::add_error( |
|
| 234 | + sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), |
|
| 235 | + __FILE__, |
|
| 236 | + __FUNCTION__, |
|
| 237 | + __LINE__ |
|
| 238 | + ); |
|
| 239 | + return false; |
|
| 240 | + } |
|
| 241 | + } else { |
|
| 242 | + EE_Error::add_error( |
|
| 243 | + sprintf( |
|
| 244 | + __( |
|
| 245 | + "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", |
|
| 246 | + "event_espresso" |
|
| 247 | + ), |
|
| 248 | + $filename, |
|
| 249 | + $max_upload |
|
| 250 | + ), |
|
| 251 | + __FILE__, |
|
| 252 | + __FUNCTION__, |
|
| 253 | + __LINE__ |
|
| 254 | + ); |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 257 | + } else { |
|
| 258 | + EE_Error::add_error( |
|
| 259 | + sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), |
|
| 260 | + __FILE__, |
|
| 261 | + __FUNCTION__, |
|
| 262 | + __LINE__ |
|
| 263 | + ); |
|
| 264 | + return false; |
|
| 265 | + } |
|
| 266 | + } else { |
|
| 267 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 268 | + return false; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + return; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
| 278 | + * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
| 279 | + * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
| 280 | + * being keys of model fields and their proposed values. |
|
| 281 | + * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
| 282 | + * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
| 283 | + * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
| 284 | + * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
| 285 | + * which can used elsewhere to refer to the same object. Once an item |
|
| 286 | + * with a temporary ID gets inserted, we record its mapping from temporary |
|
| 287 | + * ID to real ID, and use the real ID in place of the temporary ID |
|
| 288 | + * when that temporary ID was used as a foreign key. |
|
| 289 | + * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
| 290 | + * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
| 291 | + * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
| 292 | + * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
| 293 | + * An important exception are non-auto-increment primary keys. If one entry in the |
|
| 294 | + * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
| 295 | + * the same item, and instead update the item in the DB with that same ID. |
|
| 296 | + * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
| 297 | + * time you import a CSV from a different site, we remember their mappings, and |
|
| 298 | + * will try to update the item in the DB instead of inserting another item (eg |
|
| 299 | + * if we previously imported an event with temporary ID 1, and then it got a |
|
| 300 | + * real ID of 123, we remember that. So the next time we import an event with |
|
| 301 | + * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
| 302 | + * update that event, instead of adding a new event). |
|
| 303 | + * |
|
| 304 | + * @access public |
|
| 305 | + * @param array $csv_data_array - the array containing the csv data produced from |
|
| 306 | + * EE_CSV::import_csv_to_model_data_array() |
|
| 307 | + * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table |
|
| 308 | + * fields they will be saved to |
|
| 309 | + * @return TRUE on success, FALSE on fail |
|
| 310 | + * @throws \EE_Error |
|
| 311 | + */ |
|
| 312 | + public function save_csv_data_array_to_db($csv_data_array, $model_name = false) |
|
| 313 | + { |
|
| 314 | + $success = false; |
|
| 315 | + $error = false; |
|
| 316 | + // whther to treat this import as if it's data froma different database or not |
|
| 317 | + // ie, if it IS from a different database, ignore foreign keys whihf |
|
| 318 | + $export_from_site_a_to_b = true; |
|
| 319 | + // first level of array is not table information but a table name was passed to the function |
|
| 320 | + // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
|
| 321 | + if ($model_name) { |
|
| 322 | + $csv_data_array = array($csv_data_array); |
|
| 323 | + } |
|
| 324 | + // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
|
| 325 | + $old_site_url = 'none-specified'; |
|
| 326 | + // hanlde metadata |
|
| 327 | + if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
| 328 | + $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
| 329 | + // ok so its metadata, dont try to save it to ehte db obviously... |
|
| 330 | + if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
| 331 | + EE_Error::add_attention( |
|
| 332 | + sprintf( |
|
| 333 | + __( |
|
| 334 | + "CSV Data appears to be from the same database, so attempting to update data", |
|
| 335 | + "event_espresso" |
|
| 336 | + ) |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + $export_from_site_a_to_b = false; |
|
| 340 | + } else { |
|
| 341 | + $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
| 342 | + EE_Error::add_attention( |
|
| 343 | + sprintf( |
|
| 344 | + __( |
|
| 345 | + "CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", |
|
| 346 | + "event_espresso" |
|
| 347 | + ), |
|
| 348 | + $old_site_url, |
|
| 349 | + site_url() |
|
| 350 | + ) |
|
| 351 | + ); |
|
| 352 | + }; |
|
| 353 | + unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
| 354 | + } |
|
| 355 | + /** |
|
| 356 | + * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
| 357 | + * the value will be the newly-inserted ID. |
|
| 358 | + * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
| 359 | + */ |
|
| 360 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
| 361 | + if ($old_db_to_new_db_mapping) { |
|
| 362 | + EE_Error::add_attention( |
|
| 363 | + sprintf( |
|
| 364 | + __( |
|
| 365 | + "We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", |
|
| 366 | + "event_espresso" |
|
| 367 | + ), |
|
| 368 | + $old_site_url, |
|
| 369 | + site_url() |
|
| 370 | + ) |
|
| 371 | + ); |
|
| 372 | + } |
|
| 373 | + $old_db_to_new_db_mapping = $this->save_data_rows_to_db( |
|
| 374 | + $csv_data_array, |
|
| 375 | + $export_from_site_a_to_b, |
|
| 376 | + $old_db_to_new_db_mapping |
|
| 377 | + ); |
|
| 378 | + |
|
| 379 | + // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
|
| 380 | + update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
| 381 | + |
|
| 382 | + if ($this->_total_updates > 0) { |
|
| 383 | + EE_Error::add_success( |
|
| 384 | + sprintf( |
|
| 385 | + __("%s existing records in the database were updated.", "event_espresso"), |
|
| 386 | + $this->_total_updates |
|
| 387 | + ) |
|
| 388 | + ); |
|
| 389 | + $success = true; |
|
| 390 | + } |
|
| 391 | + if ($this->_total_inserts > 0) { |
|
| 392 | + EE_Error::add_success( |
|
| 393 | + sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts) |
|
| 394 | + ); |
|
| 395 | + $success = true; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + if ($this->_total_update_errors > 0) { |
|
| 399 | + EE_Error::add_error( |
|
| 400 | + sprintf( |
|
| 401 | + __( |
|
| 402 | + "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", |
|
| 403 | + "event_espresso" |
|
| 404 | + ), |
|
| 405 | + $this->_total_update_errors |
|
| 406 | + ), |
|
| 407 | + __FILE__, |
|
| 408 | + __FUNCTION__, |
|
| 409 | + __LINE__ |
|
| 410 | + ); |
|
| 411 | + $error = true; |
|
| 412 | + } |
|
| 413 | + if ($this->_total_insert_errors > 0) { |
|
| 414 | + EE_Error::add_error( |
|
| 415 | + sprintf( |
|
| 416 | + __( |
|
| 417 | + "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", |
|
| 418 | + "event_espresso" |
|
| 419 | + ), |
|
| 420 | + $this->_total_insert_errors |
|
| 421 | + ), |
|
| 422 | + __FILE__, |
|
| 423 | + __FUNCTION__, |
|
| 424 | + __LINE__ |
|
| 425 | + ); |
|
| 426 | + $error = true; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // lastly, we need to update the datetime and ticket sold amounts |
|
| 430 | + // as those may have been affected by this |
|
| 431 | + EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
|
| 432 | + |
|
| 433 | + // if there was at least one success and absolutely no errors |
|
| 434 | + if ($success && ! $error) { |
|
| 435 | + return true; |
|
| 436 | + } else { |
|
| 437 | + return false; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Processes the array of data, given the knowledge that it's from the same database or a different one, |
|
| 444 | + * and the mapping from temporary IDs to real IDs. |
|
| 445 | + * If the data is from a different database, we treat the primary keys and their corresponding |
|
| 446 | + * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys |
|
| 447 | + * in the real target database. As items are inserted, their temporary primary keys |
|
| 448 | + * are mapped to the real IDs in the target database. Also, before doing any update or |
|
| 449 | + * insert, we replace all the temp ID which are foreign keys with their mapped real IDs. |
|
| 450 | + * An exception: string primary keys are treated as real IDs, or else we'd need to |
|
| 451 | + * dynamically generate new string primary keys which would be very awkard for the country table etc. |
|
| 452 | + * Also, models with no primary key are strange too. We combine use their primar key INDEX (a |
|
| 453 | + * combination of fields) to create a unique string identifying the row and store |
|
| 454 | + * those in the mapping. |
|
| 455 | + * |
|
| 456 | + * If the data is from the same database, we usually treat primary keys as real IDs. |
|
| 457 | + * An exception is if there is nothing in the database for that ID. If that's the case, |
|
| 458 | + * we need to insert a new row for that ID, and then map from the non-existent ID |
|
| 459 | + * to the newly-inserted real ID. |
|
| 460 | + * |
|
| 461 | + * @param type $csv_data_array |
|
| 462 | + * @param type $export_from_site_a_to_b |
|
| 463 | + * @param type $old_db_to_new_db_mapping |
|
| 464 | + * @return array updated $old_db_to_new_db_mapping |
|
| 465 | + */ |
|
| 466 | + public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) |
|
| 467 | + { |
|
| 468 | + foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
| 469 | + // now check that assumption was correct. If |
|
| 470 | + if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
| 471 | + $model_name = $model_name_in_csv_data; |
|
| 472 | + } else { |
|
| 473 | + // no table info in the array and no table name passed to the function?? FAIL |
|
| 474 | + EE_Error::add_error( |
|
| 475 | + __( |
|
| 476 | + 'No table information was specified and/or found, therefore the import could not be completed', |
|
| 477 | + 'event_espresso' |
|
| 478 | + ), |
|
| 479 | + __FILE__, |
|
| 480 | + __FUNCTION__, |
|
| 481 | + __LINE__ |
|
| 482 | + ); |
|
| 483 | + return false; |
|
| 484 | + } |
|
| 485 | + /* @var $model EEM_Base */ |
|
| 486 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 487 | + |
|
| 488 | + // so without further ado, scanning all the data provided for primary keys and their inital values |
|
| 489 | + foreach ($model_data_from_import as $model_object_data) { |
|
| 490 | + // before we do ANYTHING, make sure the csv row wasn't just completely blank |
|
| 491 | + $row_is_completely_empty = true; |
|
| 492 | + foreach ($model_object_data as $field) { |
|
| 493 | + if ($field) { |
|
| 494 | + $row_is_completely_empty = false; |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + if ($row_is_completely_empty) { |
|
| 498 | + continue; |
|
| 499 | + } |
|
| 500 | + // find the PK in the row of data (or a combined key if |
|
| 501 | + // there is no primary key) |
|
| 502 | + if ($model->has_primary_key_field()) { |
|
| 503 | + $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
| 504 | + } else { |
|
| 505 | + $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + $model_object_data = $this->_replace_temp_ids_with_mappings( |
|
| 510 | + $model_object_data, |
|
| 511 | + $model, |
|
| 512 | + $old_db_to_new_db_mapping, |
|
| 513 | + $export_from_site_a_to_b |
|
| 514 | + ); |
|
| 515 | + // now we need to decide if we're going to add a new model object given the $model_object_data, |
|
| 516 | + // or just update. |
|
| 517 | + if ($export_from_site_a_to_b) { |
|
| 518 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( |
|
| 519 | + $id_in_csv, |
|
| 520 | + $model_object_data, |
|
| 521 | + $model, |
|
| 522 | + $old_db_to_new_db_mapping |
|
| 523 | + ); |
|
| 524 | + } else {// this is just a re-import |
|
| 525 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( |
|
| 526 | + $id_in_csv, |
|
| 527 | + $model_object_data, |
|
| 528 | + $model, |
|
| 529 | + $old_db_to_new_db_mapping |
|
| 530 | + ); |
|
| 531 | + } |
|
| 532 | + if ($what_to_do == self::do_nothing) { |
|
| 533 | + continue; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // double-check we actually want to insert, if that's what we're planning |
|
| 537 | + // based on whether this item would be unique in the DB or not |
|
| 538 | + if ($what_to_do == self::do_insert) { |
|
| 539 | + // we're supposed to be inserting. But wait, will this thing |
|
| 540 | + // be acceptable if inserted? |
|
| 541 | + $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
| 542 | + if ($conflicting) { |
|
| 543 | + // ok, this item would conflict if inserted. Just update the item that it conflicts with. |
|
| 544 | + $what_to_do = self::do_update; |
|
| 545 | + // and if this model has a primary key, remember its mapping |
|
| 546 | + if ($model->has_primary_key_field()) { |
|
| 547 | + $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
| 548 | + $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
| 549 | + } else { |
|
| 550 | + // we want to update this conflicting item, instead of inserting a conflicting item |
|
| 551 | + // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
|
| 552 | + // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
|
| 553 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 554 | + $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
| 555 | + $key_field->get_name() |
|
| 556 | + ); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + if ($what_to_do == self::do_insert) { |
|
| 562 | + $old_db_to_new_db_mapping = $this->_insert_from_data_array( |
|
| 563 | + $id_in_csv, |
|
| 564 | + $model_object_data, |
|
| 565 | + $model, |
|
| 566 | + $old_db_to_new_db_mapping |
|
| 567 | + ); |
|
| 568 | + } elseif ($what_to_do == self::do_update) { |
|
| 569 | + $old_db_to_new_db_mapping = $this->_update_from_data_array( |
|
| 570 | + $id_in_csv, |
|
| 571 | + $model_object_data, |
|
| 572 | + $model, |
|
| 573 | + $old_db_to_new_db_mapping |
|
| 574 | + ); |
|
| 575 | + } else { |
|
| 576 | + throw new EE_Error( |
|
| 577 | + sprintf( |
|
| 578 | + __( |
|
| 579 | + 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ), |
|
| 582 | + $what_to_do |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + return $old_db_to_new_db_mapping; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Decides whether or not to insert, given that this data is from another database. |
|
| 594 | + * So, if the primary key of this $model_object_data already exists in the database, |
|
| 595 | + * it's just a coincidence and we should still insert. The only time we should |
|
| 596 | + * update is when we know what it maps to, or there's something that would |
|
| 597 | + * conflict (and we should instead just update that conflicting thing) |
|
| 598 | + * |
|
| 599 | + * @param string $id_in_csv |
|
| 600 | + * @param array $model_object_data by reference so it can be modified |
|
| 601 | + * @param EEM_Base $model |
|
| 602 | + * @param array $old_db_to_new_db_mapping by reference so it can be modified |
|
| 603 | + * @return string one of the consts on this class that starts with do_* |
|
| 604 | + */ |
|
| 605 | + protected function _decide_whether_to_insert_or_update_given_data_from_other_db( |
|
| 606 | + $id_in_csv, |
|
| 607 | + $model_object_data, |
|
| 608 | + $model, |
|
| 609 | + $old_db_to_new_db_mapping |
|
| 610 | + ) { |
|
| 611 | + $model_name = $model->get_this_model_name(); |
|
| 612 | + // if it's a site-to-site export-and-import, see if this modelobject's id |
|
| 613 | + // in the old data that we know of |
|
| 614 | + if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
| 615 | + return self::do_update; |
|
| 616 | + } else { |
|
| 617 | + return self::do_insert; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * If this thing basically already exists in the database, we want to update it; |
|
| 623 | + * otherwise insert it (ie, someone tweaked the CSV file, or the item was |
|
| 624 | + * deleted in the database so it should be re-inserted) |
|
| 625 | + * |
|
| 626 | + * @param type $id_in_csv |
|
| 627 | + * @param type $model_object_data |
|
| 628 | + * @param EEM_Base $model |
|
| 629 | + * @param type $old_db_to_new_db_mapping |
|
| 630 | + * @return |
|
| 631 | + */ |
|
| 632 | + protected function _decide_whether_to_insert_or_update_given_data_from_same_db( |
|
| 633 | + $id_in_csv, |
|
| 634 | + $model_object_data, |
|
| 635 | + $model |
|
| 636 | + ) { |
|
| 637 | + // in this case, check if this thing ACTUALLY exists in the database |
|
| 638 | + if ($model->get_one_conflicting($model_object_data)) { |
|
| 639 | + return self::do_update; |
|
| 640 | + } else { |
|
| 641 | + return self::do_insert; |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs |
|
| 647 | + * with their mapped real IDs. Eg, if importing from site A to B, the mapping |
|
| 648 | + * file may indicate that the ID "my_event_id" maps to an actual event ID of 123. |
|
| 649 | + * So this function searches for any event temp Ids called "my_event_id" and |
|
| 650 | + * replaces them with 123. |
|
| 651 | + * Also, if there is no temp ID for the INT foreign keys from another database, |
|
| 652 | + * replaces them with 0 or the field's default. |
|
| 653 | + * |
|
| 654 | + * @param type $model_object_data |
|
| 655 | + * @param EEM_Base $model |
|
| 656 | + * @param type $old_db_to_new_db_mapping |
|
| 657 | + * @param boolean $export_from_site_a_to_b |
|
| 658 | + * @return array updated model object data with temp IDs removed |
|
| 659 | + */ |
|
| 660 | + protected function _replace_temp_ids_with_mappings( |
|
| 661 | + $model_object_data, |
|
| 662 | + $model, |
|
| 663 | + $old_db_to_new_db_mapping, |
|
| 664 | + $export_from_site_a_to_b |
|
| 665 | + ) { |
|
| 666 | + // if this model object's primary key is in the mapping, replace it |
|
| 667 | + if ($model->has_primary_key_field() && |
|
| 668 | + $model->get_primary_key_field()->is_auto_increment() && |
|
| 669 | + isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
| 670 | + isset( |
|
| 671 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
| 672 | + )) { |
|
| 673 | + $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
| 674 | + ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + try { |
|
| 678 | + $model_name_field = $model->get_field_containing_related_model_name(); |
|
| 679 | + $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
|
| 680 | + } catch (EE_Error $e) { |
|
| 681 | + $model_name_field = null; |
|
| 682 | + $models_pointed_to_by_model_name_field = array(); |
|
| 683 | + } |
|
| 684 | + foreach ($model->field_settings(true) as $field_obj) { |
|
| 685 | + if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
| 686 | + $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
|
| 687 | + $found_a_mapping = false; |
|
| 688 | + foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
| 689 | + if ($model_name_field) { |
|
| 690 | + $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
| 691 | + if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
| 692 | + $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
| 693 | + $model_object_data[ $field_obj->get_name() ], |
|
| 694 | + $model_pointed_to_by_fk, |
|
| 695 | + $old_db_to_new_db_mapping, |
|
| 696 | + $export_from_site_a_to_b |
|
| 697 | + ); |
|
| 698 | + $found_a_mapping = true; |
|
| 699 | + break; |
|
| 700 | + } |
|
| 701 | + } else { |
|
| 702 | + $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
| 703 | + $model_object_data[ $field_obj->get_name() ], |
|
| 704 | + $model_pointed_to_by_fk, |
|
| 705 | + $old_db_to_new_db_mapping, |
|
| 706 | + $export_from_site_a_to_b |
|
| 707 | + ); |
|
| 708 | + $found_a_mapping = true; |
|
| 709 | + } |
|
| 710 | + // once we've found a mapping for this field no need to continue |
|
| 711 | + if ($found_a_mapping) { |
|
| 712 | + break; |
|
| 713 | + } |
|
| 714 | + } |
|
| 715 | + } else { |
|
| 716 | + // it's a string foreign key (which we leave alone, because those are things |
|
| 717 | + // like country names, which we'd really rather not make 2 USAs etc (we'd actually |
|
| 718 | + // prefer to just update one) |
|
| 719 | + // or it's just a regular value that ought to be replaced |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + // |
|
| 723 | + if ($model instanceof EEM_Term_Taxonomy) { |
|
| 724 | + $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
| 725 | + } |
|
| 726 | + return $model_object_data; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id |
|
| 731 | + * this term-taxonomy refers to may be out-of-date so we need to update it. |
|
| 732 | + * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ |
|
| 733 | + * |
|
| 734 | + * @param type $model_object_data |
|
| 735 | + * @return array new model object data |
|
| 736 | + */ |
|
| 737 | + protected function _handle_split_term_ids($model_object_data) |
|
| 738 | + { |
|
| 739 | + if (isset($model_object_data['term_id']) |
|
| 740 | + && isset($model_object_data['taxonomy']) |
|
| 741 | + && apply_filters( |
|
| 742 | + 'FHEE__EE_Import__handle_split_term_ids__function_exists', |
|
| 743 | + function_exists('wp_get_split_term'), |
|
| 744 | + $model_object_data |
|
| 745 | + )) { |
|
| 746 | + $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
| 747 | + if ($new_term_id) { |
|
| 748 | + $model_object_data['term_id'] = $new_term_id; |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + return $model_object_data; |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * Given the object's ID and its model's name, find it int he mapping data, |
|
| 756 | + * bearing in mind where it came from |
|
| 757 | + * |
|
| 758 | + * @param type $object_id |
|
| 759 | + * @param string $model_name |
|
| 760 | + * @param array $old_db_to_new_db_mapping |
|
| 761 | + * @param type $export_from_site_a_to_b |
|
| 762 | + * @return int |
|
| 763 | + */ |
|
| 764 | + protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
|
| 765 | + { |
|
| 766 | + if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
| 767 | + return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
| 768 | + } elseif ($object_id == '0' || $object_id == '') { |
|
| 769 | + // leave as-is |
|
| 770 | + return $object_id; |
|
| 771 | + } elseif ($export_from_site_a_to_b) { |
|
| 772 | + // we couldn't find a mapping for this, and it's from a different site, |
|
| 773 | + // so blank it out |
|
| 774 | + return null; |
|
| 775 | + } elseif (! $export_from_site_a_to_b) { |
|
| 776 | + // we coudln't find a mapping for this, but it's from thsi DB anyway |
|
| 777 | + // so let's just leave it as-is |
|
| 778 | + return $object_id; |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * |
|
| 784 | + * @param type $id_in_csv |
|
| 785 | + * @param type $model_object_data |
|
| 786 | + * @param EEM_Base $model |
|
| 787 | + * @param type $old_db_to_new_db_mapping |
|
| 788 | + * @return array updated $old_db_to_new_db_mapping |
|
| 789 | + */ |
|
| 790 | + protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
| 791 | + { |
|
| 792 | + // remove the primary key, if there is one (we don't want it for inserts OR updates) |
|
| 793 | + // we'll put it back in if we need it |
|
| 794 | + if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
| 795 | + $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
| 796 | + unset($model_object_data[ $model->primary_key_name() ]); |
|
| 797 | + } else { |
|
| 798 | + $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
| 799 | + } |
|
| 800 | + // the model takes care of validating the CSV's input |
|
| 801 | + try { |
|
| 802 | + $new_id = $model->insert($model_object_data); |
|
| 803 | + if ($new_id) { |
|
| 804 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
| 805 | + $this->_total_inserts++; |
|
| 806 | + EE_Error::add_success( |
|
| 807 | + sprintf( |
|
| 808 | + __("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), |
|
| 809 | + $model->get_this_model_name(), |
|
| 810 | + $new_id, |
|
| 811 | + implode(",", $model_object_data) |
|
| 812 | + ) |
|
| 813 | + ); |
|
| 814 | + } else { |
|
| 815 | + $this->_total_insert_errors++; |
|
| 816 | + // put the ID used back in there for the error message |
|
| 817 | + if ($model->has_primary_key_field()) { |
|
| 818 | + $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
| 819 | + } |
|
| 820 | + EE_Error::add_error( |
|
| 821 | + sprintf( |
|
| 822 | + __("Could not insert new %s with the csv data: %s", "event_espresso"), |
|
| 823 | + $model->get_this_model_name(), |
|
| 824 | + http_build_query($model_object_data) |
|
| 825 | + ), |
|
| 826 | + __FILE__, |
|
| 827 | + __FUNCTION__, |
|
| 828 | + __LINE__ |
|
| 829 | + ); |
|
| 830 | + } |
|
| 831 | + } catch (EE_Error $e) { |
|
| 832 | + $this->_total_insert_errors++; |
|
| 833 | + if ($model->has_primary_key_field()) { |
|
| 834 | + $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
| 835 | + } |
|
| 836 | + EE_Error::add_error( |
|
| 837 | + sprintf( |
|
| 838 | + __("Could not insert new %s with the csv data: %s because %s", "event_espresso"), |
|
| 839 | + $model->get_this_model_name(), |
|
| 840 | + implode(",", $model_object_data), |
|
| 841 | + $e->getMessage() |
|
| 842 | + ), |
|
| 843 | + __FILE__, |
|
| 844 | + __FUNCTION__, |
|
| 845 | + __LINE__ |
|
| 846 | + ); |
|
| 847 | + } |
|
| 848 | + return $old_db_to_new_db_mapping; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * Given the model object data, finds the row to update and updates it |
|
| 853 | + * |
|
| 854 | + * @param string|int $id_in_csv |
|
| 855 | + * @param array $model_object_data |
|
| 856 | + * @param EEM_Base $model |
|
| 857 | + * @param array $old_db_to_new_db_mapping |
|
| 858 | + * @return array updated $old_db_to_new_db_mapping |
|
| 859 | + */ |
|
| 860 | + protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
| 861 | + { |
|
| 862 | + try { |
|
| 863 | + // let's keep two copies of the model object data: |
|
| 864 | + // one for performing an update, one for everthing else |
|
| 865 | + $model_object_data_for_update = $model_object_data; |
|
| 866 | + if ($model->has_primary_key_field()) { |
|
| 867 | + $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
| 868 | + // remove the primary key because we shouldn't use it for updating |
|
| 869 | + unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
| 870 | + } elseif ($model->get_combined_primary_key_fields() > 1) { |
|
| 871 | + $conditions = array(); |
|
| 872 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 873 | + $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
| 874 | + } |
|
| 875 | + } else { |
|
| 876 | + $model->primary_key_name( |
|
| 877 | + );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + $success = $model->update($model_object_data_for_update, array($conditions)); |
|
| 881 | + if ($success) { |
|
| 882 | + $this->_total_updates++; |
|
| 883 | + EE_Error::add_success( |
|
| 884 | + sprintf( |
|
| 885 | + __("Successfully updated %s with csv data %s", "event_espresso"), |
|
| 886 | + $model->get_this_model_name(), |
|
| 887 | + implode(",", $model_object_data_for_update) |
|
| 888 | + ) |
|
| 889 | + ); |
|
| 890 | + // we should still record the mapping even though it was an update |
|
| 891 | + // because if we were going to insert somethign but it was going to conflict |
|
| 892 | + // we would have last-minute decided to update. So we'd like to know what we updated |
|
| 893 | + // and so we record what record ended up being updated using the mapping |
|
| 894 | + if ($model->has_primary_key_field()) { |
|
| 895 | + $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
| 896 | + } else { |
|
| 897 | + // no primary key just a combined key |
|
| 898 | + $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
| 899 | + } |
|
| 900 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
| 901 | + } else { |
|
| 902 | + $matched_items = $model->get_all(array($conditions)); |
|
| 903 | + if (! $matched_items) { |
|
| 904 | + // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
|
| 905 | + $this->_total_update_errors++; |
|
| 906 | + EE_Error::add_error( |
|
| 907 | + sprintf( |
|
| 908 | + __( |
|
| 909 | + "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", |
|
| 910 | + "event_espresso" |
|
| 911 | + ), |
|
| 912 | + $model->get_this_model_name(), |
|
| 913 | + http_build_query($model_object_data), |
|
| 914 | + http_build_query($conditions) |
|
| 915 | + ), |
|
| 916 | + __FILE__, |
|
| 917 | + __FUNCTION__, |
|
| 918 | + __LINE__ |
|
| 919 | + ); |
|
| 920 | + } else { |
|
| 921 | + $this->_total_updates++; |
|
| 922 | + EE_Error::add_success( |
|
| 923 | + sprintf( |
|
| 924 | + __( |
|
| 925 | + "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", |
|
| 926 | + "event_espresso" |
|
| 927 | + ), |
|
| 928 | + $model->get_this_model_name(), |
|
| 929 | + implode(",", $model_object_data) |
|
| 930 | + ) |
|
| 931 | + ); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + } catch (EE_Error $e) { |
|
| 935 | + $this->_total_update_errors++; |
|
| 936 | + $basic_message = sprintf( |
|
| 937 | + __("Could not update %s with the csv data: %s because %s", "event_espresso"), |
|
| 938 | + $model->get_this_model_name(), |
|
| 939 | + implode(",", $model_object_data), |
|
| 940 | + $e->getMessage() |
|
| 941 | + ); |
|
| 942 | + $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
| 943 | + EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
| 944 | + } |
|
| 945 | + return $old_db_to_new_db_mapping; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + /** |
|
| 949 | + * Gets the number of inserts performed since importer was instantiated or reset |
|
| 950 | + * |
|
| 951 | + * @return int |
|
| 952 | + */ |
|
| 953 | + public function get_total_inserts() |
|
| 954 | + { |
|
| 955 | + return $this->_total_inserts; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + /** |
|
| 959 | + * Gets the number of insert errors since importer was instantiated or reset |
|
| 960 | + * |
|
| 961 | + * @return int |
|
| 962 | + */ |
|
| 963 | + public function get_total_insert_errors() |
|
| 964 | + { |
|
| 965 | + return $this->_total_insert_errors; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /** |
|
| 969 | + * Gets the number of updates performed since importer was instantiated or reset |
|
| 970 | + * |
|
| 971 | + * @return int |
|
| 972 | + */ |
|
| 973 | + public function get_total_updates() |
|
| 974 | + { |
|
| 975 | + return $this->_total_updates; |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * Gets the number of update errors since importer was instantiated or reset |
|
| 980 | + * |
|
| 981 | + * @return int |
|
| 982 | + */ |
|
| 983 | + public function get_total_update_errors() |
|
| 984 | + { |
|
| 985 | + return $this->_total_update_errors; |
|
| 986 | + } |
|
| 987 | 987 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | public function import() |
| 136 | 136 | { |
| 137 | 137 | |
| 138 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
| 138 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
| 139 | 139 | $this->EE_CSV = EE_CSV::instance(); |
| 140 | 140 | |
| 141 | 141 | if (isset($_REQUEST['import'])) { |
@@ -179,18 +179,18 @@ discard block |
||
| 179 | 179 | break; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if (! $error_msg) { |
|
| 182 | + if ( ! $error_msg) { |
|
| 183 | 183 | $filename = $_FILES['file']['name'][0]; |
| 184 | 184 | $file_ext = substr(strrchr($filename, '.'), 1); |
| 185 | 185 | $file_type = $_FILES['file']['type'][0]; |
| 186 | 186 | $temp_file = $_FILES['file']['tmp_name'][0]; |
| 187 | - $filesize = $_FILES['file']['size'][0] / 1024;// convert from bytes to KB |
|
| 187 | + $filesize = $_FILES['file']['size'][0] / 1024; // convert from bytes to KB |
|
| 188 | 188 | |
| 189 | 189 | if ($file_ext == 'csv') { |
| 190 | - $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
| 190 | + $max_upload = $this->EE_CSV->get_max_upload_size(); // max upload size in KB |
|
| 191 | 191 | if ($filesize < $max_upload || true) { |
| 192 | 192 | $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
| 193 | - $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
| 193 | + $path_to_file = $wp_upload_dir['basedir'].'/espresso/'.$filename; |
|
| 194 | 194 | |
| 195 | 195 | if (move_uploaded_file($temp_file, $path_to_file)) { |
| 196 | 196 | // convert csv to array |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
| 325 | 325 | $old_site_url = 'none-specified'; |
| 326 | 326 | // hanlde metadata |
| 327 | - if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
| 328 | - $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
| 327 | + if (isset($csv_data_array[EE_CSV::metadata_header])) { |
|
| 328 | + $csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]); |
|
| 329 | 329 | // ok so its metadata, dont try to save it to ehte db obviously... |
| 330 | 330 | if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
| 331 | 331 | EE_Error::add_attention( |
@@ -350,14 +350,14 @@ discard block |
||
| 350 | 350 | ) |
| 351 | 351 | ); |
| 352 | 352 | }; |
| 353 | - unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
| 353 | + unset($csv_data_array[EE_CSV::metadata_header]); |
|
| 354 | 354 | } |
| 355 | 355 | /** |
| 356 | 356 | * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
| 357 | 357 | * the value will be the newly-inserted ID. |
| 358 | 358 | * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
| 359 | 359 | */ |
| 360 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
| 360 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array()); |
|
| 361 | 361 | if ($old_db_to_new_db_mapping) { |
| 362 | 362 | EE_Error::add_attention( |
| 363 | 363 | sprintf( |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | ); |
| 378 | 378 | |
| 379 | 379 | // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
| 380 | - update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
| 380 | + update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
| 381 | 381 | |
| 382 | 382 | if ($this->_total_updates > 0) { |
| 383 | 383 | EE_Error::add_success( |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | // find the PK in the row of data (or a combined key if |
| 501 | 501 | // there is no primary key) |
| 502 | 502 | if ($model->has_primary_key_field()) { |
| 503 | - $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
| 503 | + $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
| 504 | 504 | } else { |
| 505 | 505 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
| 506 | 506 | } |
@@ -544,14 +544,14 @@ discard block |
||
| 544 | 544 | $what_to_do = self::do_update; |
| 545 | 545 | // and if this model has a primary key, remember its mapping |
| 546 | 546 | if ($model->has_primary_key_field()) { |
| 547 | - $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
| 548 | - $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
| 547 | + $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
|
| 548 | + $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
|
| 549 | 549 | } else { |
| 550 | 550 | // we want to update this conflicting item, instead of inserting a conflicting item |
| 551 | 551 | // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
| 552 | 552 | // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
| 553 | 553 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
| 554 | - $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
| 554 | + $model_object_data[$key_field->get_name()] = $conflicting->get( |
|
| 555 | 555 | $key_field->get_name() |
| 556 | 556 | ); |
| 557 | 557 | } |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | $model_name = $model->get_this_model_name(); |
| 612 | 612 | // if it's a site-to-site export-and-import, see if this modelobject's id |
| 613 | 613 | // in the old data that we know of |
| 614 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
| 614 | + if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) { |
|
| 615 | 615 | return self::do_update; |
| 616 | 616 | } else { |
| 617 | 617 | return self::do_insert; |
@@ -666,12 +666,12 @@ discard block |
||
| 666 | 666 | // if this model object's primary key is in the mapping, replace it |
| 667 | 667 | if ($model->has_primary_key_field() && |
| 668 | 668 | $model->get_primary_key_field()->is_auto_increment() && |
| 669 | - isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
| 669 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && |
|
| 670 | 670 | isset( |
| 671 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
| 671 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]] |
|
| 672 | 672 | )) { |
| 673 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
| 674 | - ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
| 673 | + $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name( |
|
| 674 | + )][$model_object_data[$model->primary_key_name()]]; |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | try { |
@@ -687,10 +687,10 @@ discard block |
||
| 687 | 687 | $found_a_mapping = false; |
| 688 | 688 | foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
| 689 | 689 | if ($model_name_field) { |
| 690 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
| 690 | + $value_of_model_name_field = $model_object_data[$model_name_field->get_name()]; |
|
| 691 | 691 | if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
| 692 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
| 693 | - $model_object_data[ $field_obj->get_name() ], |
|
| 692 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
| 693 | + $model_object_data[$field_obj->get_name()], |
|
| 694 | 694 | $model_pointed_to_by_fk, |
| 695 | 695 | $old_db_to_new_db_mapping, |
| 696 | 696 | $export_from_site_a_to_b |
@@ -699,8 +699,8 @@ discard block |
||
| 699 | 699 | break; |
| 700 | 700 | } |
| 701 | 701 | } else { |
| 702 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
| 703 | - $model_object_data[ $field_obj->get_name() ], |
|
| 702 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
| 703 | + $model_object_data[$field_obj->get_name()], |
|
| 704 | 704 | $model_pointed_to_by_fk, |
| 705 | 705 | $old_db_to_new_db_mapping, |
| 706 | 706 | $export_from_site_a_to_b |
@@ -763,8 +763,8 @@ discard block |
||
| 763 | 763 | */ |
| 764 | 764 | protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
| 765 | 765 | { |
| 766 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
| 767 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
| 766 | + if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) { |
|
| 767 | + return $old_db_to_new_db_mapping[$model_name][$object_id]; |
|
| 768 | 768 | } elseif ($object_id == '0' || $object_id == '') { |
| 769 | 769 | // leave as-is |
| 770 | 770 | return $object_id; |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | // we couldn't find a mapping for this, and it's from a different site, |
| 773 | 773 | // so blank it out |
| 774 | 774 | return null; |
| 775 | - } elseif (! $export_from_site_a_to_b) { |
|
| 775 | + } elseif ( ! $export_from_site_a_to_b) { |
|
| 776 | 776 | // we coudln't find a mapping for this, but it's from thsi DB anyway |
| 777 | 777 | // so let's just leave it as-is |
| 778 | 778 | return $object_id; |
@@ -792,8 +792,8 @@ discard block |
||
| 792 | 792 | // remove the primary key, if there is one (we don't want it for inserts OR updates) |
| 793 | 793 | // we'll put it back in if we need it |
| 794 | 794 | if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
| 795 | - $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
| 796 | - unset($model_object_data[ $model->primary_key_name() ]); |
|
| 795 | + $effective_id = $model_object_data[$model->primary_key_name()]; |
|
| 796 | + unset($model_object_data[$model->primary_key_name()]); |
|
| 797 | 797 | } else { |
| 798 | 798 | $effective_id = $model->get_index_primary_key_string($model_object_data); |
| 799 | 799 | } |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | try { |
| 802 | 802 | $new_id = $model->insert($model_object_data); |
| 803 | 803 | if ($new_id) { |
| 804 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
| 804 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
|
| 805 | 805 | $this->_total_inserts++; |
| 806 | 806 | EE_Error::add_success( |
| 807 | 807 | sprintf( |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | $this->_total_insert_errors++; |
| 816 | 816 | // put the ID used back in there for the error message |
| 817 | 817 | if ($model->has_primary_key_field()) { |
| 818 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
| 818 | + $model_object_data[$model->primary_key_name()] = $effective_id; |
|
| 819 | 819 | } |
| 820 | 820 | EE_Error::add_error( |
| 821 | 821 | sprintf( |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | } catch (EE_Error $e) { |
| 832 | 832 | $this->_total_insert_errors++; |
| 833 | 833 | if ($model->has_primary_key_field()) { |
| 834 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
| 834 | + $model_object_data[$model->primary_key_name()] = $effective_id; |
|
| 835 | 835 | } |
| 836 | 836 | EE_Error::add_error( |
| 837 | 837 | sprintf( |
@@ -864,17 +864,17 @@ discard block |
||
| 864 | 864 | // one for performing an update, one for everthing else |
| 865 | 865 | $model_object_data_for_update = $model_object_data; |
| 866 | 866 | if ($model->has_primary_key_field()) { |
| 867 | - $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
| 867 | + $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
|
| 868 | 868 | // remove the primary key because we shouldn't use it for updating |
| 869 | - unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
| 869 | + unset($model_object_data_for_update[$model->primary_key_name()]); |
|
| 870 | 870 | } elseif ($model->get_combined_primary_key_fields() > 1) { |
| 871 | 871 | $conditions = array(); |
| 872 | 872 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
| 873 | - $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
| 873 | + $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
|
| 874 | 874 | } |
| 875 | 875 | } else { |
| 876 | 876 | $model->primary_key_name( |
| 877 | - );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
| 877 | + ); // this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | $success = $model->update($model_object_data_for_update, array($conditions)); |
@@ -892,15 +892,15 @@ discard block |
||
| 892 | 892 | // we would have last-minute decided to update. So we'd like to know what we updated |
| 893 | 893 | // and so we record what record ended up being updated using the mapping |
| 894 | 894 | if ($model->has_primary_key_field()) { |
| 895 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
| 895 | + $new_key_for_mapping = $model_object_data[$model->primary_key_name()]; |
|
| 896 | 896 | } else { |
| 897 | 897 | // no primary key just a combined key |
| 898 | 898 | $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
| 899 | 899 | } |
| 900 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
| 900 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping; |
|
| 901 | 901 | } else { |
| 902 | 902 | $matched_items = $model->get_all(array($conditions)); |
| 903 | - if (! $matched_items) { |
|
| 903 | + if ( ! $matched_items) { |
|
| 904 | 904 | // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
| 905 | 905 | $this->_total_update_errors++; |
| 906 | 906 | EE_Error::add_error( |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | implode(",", $model_object_data), |
| 940 | 940 | $e->getMessage() |
| 941 | 941 | ); |
| 942 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
| 942 | + $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString(); |
|
| 943 | 943 | EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
| 944 | 944 | } |
| 945 | 945 | return $old_db_to_new_db_mapping; |
@@ -22,1225 +22,1225 @@ |
||
| 22 | 22 | class EE_Register_Addon implements EEI_Plugin_API |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * possibly truncated version of the EE core version string |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected static $_core_version = ''; |
|
| 25 | + /** |
|
| 26 | + * possibly truncated version of the EE core version string |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected static $_core_version = ''; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Holds values for registered addons |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected static $_settings = array(); |
|
| 32 | + /** |
|
| 33 | + * Holds values for registered addons |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected static $_settings = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 41 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 42 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 43 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 44 | - * EE core with knowledge of ALL the addons out there. |
|
| 45 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 46 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 47 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 48 | - * minimum plugin version. |
|
| 49 | - * @access protected |
|
| 50 | - */ |
|
| 51 | - protected static $_incompatible_addons = array( |
|
| 52 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 53 | - 'Promotions' => '1.0.0.rc.084', |
|
| 54 | - ); |
|
| 39 | + /** |
|
| 40 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 41 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 42 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 43 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 44 | + * EE core with knowledge of ALL the addons out there. |
|
| 45 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 46 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 47 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 48 | + * minimum plugin version. |
|
| 49 | + * @access protected |
|
| 50 | + */ |
|
| 51 | + protected static $_incompatible_addons = array( |
|
| 52 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 53 | + 'Promotions' => '1.0.0.rc.084', |
|
| 54 | + ); |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 59 | - * not just '4.3.0'. |
|
| 60 | - * So if the addon developer doesn't provide that full version string, |
|
| 61 | - * fill in the blanks for them |
|
| 62 | - * |
|
| 63 | - * @param string $min_core_version |
|
| 64 | - * @return string always like '4.3.0.rc.000' |
|
| 65 | - */ |
|
| 66 | - protected static function _effective_version($min_core_version) |
|
| 67 | - { |
|
| 68 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 69 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 70 | - $version_parts = explode('.', $min_core_version); |
|
| 71 | - // check they specified the micro version (after 2nd period) |
|
| 72 | - if (! isset($version_parts[2])) { |
|
| 73 | - $version_parts[2] = '0'; |
|
| 74 | - } |
|
| 75 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 76 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 77 | - if (! isset($version_parts[3])) { |
|
| 78 | - $version_parts[3] = 'dev'; |
|
| 79 | - } |
|
| 80 | - if (! isset($version_parts[4])) { |
|
| 81 | - $version_parts[4] = '000'; |
|
| 82 | - } |
|
| 83 | - return implode('.', $version_parts); |
|
| 84 | - } |
|
| 57 | + /** |
|
| 58 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 59 | + * not just '4.3.0'. |
|
| 60 | + * So if the addon developer doesn't provide that full version string, |
|
| 61 | + * fill in the blanks for them |
|
| 62 | + * |
|
| 63 | + * @param string $min_core_version |
|
| 64 | + * @return string always like '4.3.0.rc.000' |
|
| 65 | + */ |
|
| 66 | + protected static function _effective_version($min_core_version) |
|
| 67 | + { |
|
| 68 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 69 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 70 | + $version_parts = explode('.', $min_core_version); |
|
| 71 | + // check they specified the micro version (after 2nd period) |
|
| 72 | + if (! isset($version_parts[2])) { |
|
| 73 | + $version_parts[2] = '0'; |
|
| 74 | + } |
|
| 75 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 76 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 77 | + if (! isset($version_parts[3])) { |
|
| 78 | + $version_parts[3] = 'dev'; |
|
| 79 | + } |
|
| 80 | + if (! isset($version_parts[4])) { |
|
| 81 | + $version_parts[4] = '000'; |
|
| 82 | + } |
|
| 83 | + return implode('.', $version_parts); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 89 | - * |
|
| 90 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 91 | - * @param string $actual_core_version the actual core version, optional |
|
| 92 | - * @return boolean |
|
| 93 | - */ |
|
| 94 | - public static function _meets_min_core_version_requirement( |
|
| 95 | - $min_core_version, |
|
| 96 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 97 | - ) { |
|
| 98 | - return version_compare( |
|
| 99 | - self::_effective_version($actual_core_version), |
|
| 100 | - self::_effective_version($min_core_version), |
|
| 101 | - '>=' |
|
| 102 | - ); |
|
| 103 | - } |
|
| 87 | + /** |
|
| 88 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 89 | + * |
|
| 90 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 91 | + * @param string $actual_core_version the actual core version, optional |
|
| 92 | + * @return boolean |
|
| 93 | + */ |
|
| 94 | + public static function _meets_min_core_version_requirement( |
|
| 95 | + $min_core_version, |
|
| 96 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 97 | + ) { |
|
| 98 | + return version_compare( |
|
| 99 | + self::_effective_version($actual_core_version), |
|
| 100 | + self::_effective_version($min_core_version), |
|
| 101 | + '>=' |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Method for registering new EE_Addons. |
|
| 108 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 109 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 110 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 111 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 112 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 113 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 114 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 115 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 116 | - * |
|
| 117 | - * @since 4.3.0 |
|
| 118 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
| 119 | - * @param array $setup_args { |
|
| 120 | - * An array of arguments provided for registering |
|
| 121 | - * the message type. |
|
| 122 | - * @type string $class_name the addon's main file name. |
|
| 123 | - * If left blank, generated from the addon name, |
|
| 124 | - * changes something like "calendar" to |
|
| 125 | - * "EE_Calendar" |
|
| 126 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 127 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 128 | - * @type string $version the "software" version for the addon. eg |
|
| 129 | - * "1.0.0.p" for a first stable release, or |
|
| 130 | - * "1.0.0.rc.043" for a version in progress |
|
| 131 | - * @type string $main_file_path the full server path to the main file |
|
| 132 | - * loaded directly by WP |
|
| 133 | - * @type DomainInterface $domain child class of |
|
| 134 | - * EventEspresso\core\domain\DomainBase |
|
| 135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
| 136 | - * for the addon's Domain class |
|
| 137 | - * (see EventEspresso\core\domain\Domain) |
|
| 138 | - * @type string $admin_path full server path to the folder where the |
|
| 139 | - * addon\'s admin files reside |
|
| 140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 141 | - * first invoked, can be used for hooking into |
|
| 142 | - * any admin page |
|
| 143 | - * @type string $config_section the section name for this addon's |
|
| 144 | - * configuration settings section |
|
| 145 | - * (defaults to "addons") |
|
| 146 | - * @type string $config_class the class name for this addon's |
|
| 147 | - * configuration settings object |
|
| 148 | - * @type string $config_name the class name for this addon's |
|
| 149 | - * configuration settings object |
|
| 150 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 151 | - * server paths to those files. |
|
| 152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 153 | - * folders containing classes that might be |
|
| 154 | - * invoked by the addon |
|
| 155 | - * @type string $dms_paths [Required] an array of full server paths to |
|
| 156 | - * folders that contain data migration scripts. |
|
| 157 | - * The key should be the EE_Addon class name that |
|
| 158 | - * this set of data migration scripts belongs to. |
|
| 159 | - * If the EE_Addon class is namespaced, then this |
|
| 160 | - * needs to be the Fully Qualified Class Name |
|
| 161 | - * @type string $module_paths an array of full server paths to any |
|
| 162 | - * EED_Modules used by the addon |
|
| 163 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 164 | - * that contain EES_Shortcodes |
|
| 165 | - * @type string $widget_paths an array of full server paths to folders |
|
| 166 | - * that contain WP_Widgets |
|
| 167 | - * @type string $pue_options |
|
| 168 | - * @type array $capabilities an array indexed by role name |
|
| 169 | - * (i.e administrator,author ) and the values |
|
| 170 | - * are an array of caps to add to the role. |
|
| 171 | - * 'administrator' => array( |
|
| 172 | - * 'read_addon', |
|
| 173 | - * 'edit_addon', |
|
| 174 | - * etc. |
|
| 175 | - * ). |
|
| 176 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 177 | - * for any addons that need to register any |
|
| 178 | - * special meta mapped capabilities. Should |
|
| 179 | - * be indexed where the key is the |
|
| 180 | - * EE_Meta_Capability_Map class name and the |
|
| 181 | - * values are the arguments sent to the class. |
|
| 182 | - * @type array $model_paths array of folders containing DB models |
|
| 183 | - * @see EE_Register_Model |
|
| 184 | - * @type array $class_paths array of folders containing DB classes |
|
| 185 | - * @see EE_Register_Model |
|
| 186 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 187 | - * extensions |
|
| 188 | - * @see EE_Register_Model_Extension |
|
| 189 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 190 | - * extensions |
|
| 191 | - * @see EE_Register_Model_Extension |
|
| 192 | - * @type array message_types { |
|
| 193 | - * An array of message types with the key as |
|
| 194 | - * the message type name and the values as |
|
| 195 | - * below: |
|
| 196 | - * @type string $mtfilename [Required] The filename of the message type |
|
| 197 | - * being registered. This will be the main |
|
| 198 | - * EE_{Message Type Name}_message_type class. |
|
| 199 | - * for example: |
|
| 200 | - * EE_Declined_Registration_message_type.class.php |
|
| 201 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 202 | - * messages autoloader for the new message type. |
|
| 203 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 204 | - * type should activate with. Each value in |
|
| 205 | - * the |
|
| 206 | - * array |
|
| 207 | - * should match the name property of a |
|
| 208 | - * EE_messenger. Optional. |
|
| 209 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 210 | - * type should validate with. Each value in |
|
| 211 | - * the |
|
| 212 | - * array |
|
| 213 | - * should match the name property of an |
|
| 214 | - * EE_messenger. |
|
| 215 | - * Optional. |
|
| 216 | - * } |
|
| 217 | - * @type array $custom_post_types |
|
| 218 | - * @type array $custom_taxonomies |
|
| 219 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 220 | - * EE_PMT_Base child class |
|
| 221 | - * (eg, |
|
| 222 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 223 | - * which contains the files |
|
| 224 | - * EE_PMT_Payomatic.pm.php) |
|
| 225 | - * @type array $default_terms |
|
| 226 | - * @type array $namespace { |
|
| 227 | - * An array with two items for registering the |
|
| 228 | - * addon's namespace. (If, for some reason, you |
|
| 229 | - * require additional namespaces, |
|
| 230 | - * use |
|
| 231 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 232 | - * directly) |
|
| 233 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 234 | - * @type string $FQNS the namespace prefix |
|
| 235 | - * @type string $DIR a base directory for class files in the |
|
| 236 | - * namespace. |
|
| 237 | - * } |
|
| 238 | - * } |
|
| 239 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
| 240 | - * privacy policy classes) or FQCNs (specific |
|
| 241 | - * classnames of privacy policy classes) |
|
| 242 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
| 243 | - * privacy policy classes) or FQCNs (specific |
|
| 244 | - * classnames of privacy policy classes) |
|
| 245 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
| 246 | - * privacy policy classes) or FQCNs (specific |
|
| 247 | - * classnames of privacy policy classes) |
|
| 248 | - * @return void |
|
| 249 | - * @throws DomainException |
|
| 250 | - * @throws EE_Error |
|
| 251 | - * @throws InvalidArgumentException |
|
| 252 | - * @throws ReflectionException |
|
| 253 | - * @throws InvalidDataTypeException |
|
| 254 | - * @throws InvalidInterfaceException |
|
| 255 | - */ |
|
| 256 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 257 | - { |
|
| 258 | - // required fields MUST be present, so let's make sure they are. |
|
| 259 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 260 | - // get class name for addon |
|
| 261 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 262 | - // setup $_settings array from incoming values. |
|
| 263 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 264 | - // setup PUE |
|
| 265 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 266 | - // does this addon work with this version of core or WordPress ? |
|
| 267 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 268 | - return; |
|
| 269 | - } |
|
| 270 | - // register namespaces |
|
| 271 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 272 | - // check if this is an activation request |
|
| 273 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 274 | - // dont bother setting up the rest of the addon atm |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - // we need cars |
|
| 278 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 279 | - // register new models and extensions |
|
| 280 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 281 | - // setup DMS |
|
| 282 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 283 | - // if config_class is present let's register config. |
|
| 284 | - EE_Register_Addon::_register_config($addon_name); |
|
| 285 | - // register admin pages |
|
| 286 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 287 | - // add to list of modules to be registered |
|
| 288 | - EE_Register_Addon::_register_modules($addon_name); |
|
| 289 | - // add to list of shortcodes to be registered |
|
| 290 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 291 | - // add to list of widgets to be registered |
|
| 292 | - EE_Register_Addon::_register_widgets($addon_name); |
|
| 293 | - // register capability related stuff. |
|
| 294 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
| 295 | - // any message type to register? |
|
| 296 | - EE_Register_Addon::_register_message_types($addon_name); |
|
| 297 | - // any custom post type/ custom capabilities or default terms to register |
|
| 298 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 299 | - // and any payment methods |
|
| 300 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 301 | - // and privacy policy generators |
|
| 302 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
| 303 | - // and privacy policy generators |
|
| 304 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
| 305 | - // and privacy policy generators |
|
| 306 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
| 307 | - // load and instantiate main addon class |
|
| 308 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 309 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 310 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 311 | - } |
|
| 106 | + /** |
|
| 107 | + * Method for registering new EE_Addons. |
|
| 108 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 109 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 110 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 111 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 112 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 113 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 114 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 115 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 116 | + * |
|
| 117 | + * @since 4.3.0 |
|
| 118 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
| 119 | + * @param array $setup_args { |
|
| 120 | + * An array of arguments provided for registering |
|
| 121 | + * the message type. |
|
| 122 | + * @type string $class_name the addon's main file name. |
|
| 123 | + * If left blank, generated from the addon name, |
|
| 124 | + * changes something like "calendar" to |
|
| 125 | + * "EE_Calendar" |
|
| 126 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 127 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 128 | + * @type string $version the "software" version for the addon. eg |
|
| 129 | + * "1.0.0.p" for a first stable release, or |
|
| 130 | + * "1.0.0.rc.043" for a version in progress |
|
| 131 | + * @type string $main_file_path the full server path to the main file |
|
| 132 | + * loaded directly by WP |
|
| 133 | + * @type DomainInterface $domain child class of |
|
| 134 | + * EventEspresso\core\domain\DomainBase |
|
| 135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
| 136 | + * for the addon's Domain class |
|
| 137 | + * (see EventEspresso\core\domain\Domain) |
|
| 138 | + * @type string $admin_path full server path to the folder where the |
|
| 139 | + * addon\'s admin files reside |
|
| 140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 141 | + * first invoked, can be used for hooking into |
|
| 142 | + * any admin page |
|
| 143 | + * @type string $config_section the section name for this addon's |
|
| 144 | + * configuration settings section |
|
| 145 | + * (defaults to "addons") |
|
| 146 | + * @type string $config_class the class name for this addon's |
|
| 147 | + * configuration settings object |
|
| 148 | + * @type string $config_name the class name for this addon's |
|
| 149 | + * configuration settings object |
|
| 150 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 151 | + * server paths to those files. |
|
| 152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 153 | + * folders containing classes that might be |
|
| 154 | + * invoked by the addon |
|
| 155 | + * @type string $dms_paths [Required] an array of full server paths to |
|
| 156 | + * folders that contain data migration scripts. |
|
| 157 | + * The key should be the EE_Addon class name that |
|
| 158 | + * this set of data migration scripts belongs to. |
|
| 159 | + * If the EE_Addon class is namespaced, then this |
|
| 160 | + * needs to be the Fully Qualified Class Name |
|
| 161 | + * @type string $module_paths an array of full server paths to any |
|
| 162 | + * EED_Modules used by the addon |
|
| 163 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 164 | + * that contain EES_Shortcodes |
|
| 165 | + * @type string $widget_paths an array of full server paths to folders |
|
| 166 | + * that contain WP_Widgets |
|
| 167 | + * @type string $pue_options |
|
| 168 | + * @type array $capabilities an array indexed by role name |
|
| 169 | + * (i.e administrator,author ) and the values |
|
| 170 | + * are an array of caps to add to the role. |
|
| 171 | + * 'administrator' => array( |
|
| 172 | + * 'read_addon', |
|
| 173 | + * 'edit_addon', |
|
| 174 | + * etc. |
|
| 175 | + * ). |
|
| 176 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 177 | + * for any addons that need to register any |
|
| 178 | + * special meta mapped capabilities. Should |
|
| 179 | + * be indexed where the key is the |
|
| 180 | + * EE_Meta_Capability_Map class name and the |
|
| 181 | + * values are the arguments sent to the class. |
|
| 182 | + * @type array $model_paths array of folders containing DB models |
|
| 183 | + * @see EE_Register_Model |
|
| 184 | + * @type array $class_paths array of folders containing DB classes |
|
| 185 | + * @see EE_Register_Model |
|
| 186 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 187 | + * extensions |
|
| 188 | + * @see EE_Register_Model_Extension |
|
| 189 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 190 | + * extensions |
|
| 191 | + * @see EE_Register_Model_Extension |
|
| 192 | + * @type array message_types { |
|
| 193 | + * An array of message types with the key as |
|
| 194 | + * the message type name and the values as |
|
| 195 | + * below: |
|
| 196 | + * @type string $mtfilename [Required] The filename of the message type |
|
| 197 | + * being registered. This will be the main |
|
| 198 | + * EE_{Message Type Name}_message_type class. |
|
| 199 | + * for example: |
|
| 200 | + * EE_Declined_Registration_message_type.class.php |
|
| 201 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 202 | + * messages autoloader for the new message type. |
|
| 203 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 204 | + * type should activate with. Each value in |
|
| 205 | + * the |
|
| 206 | + * array |
|
| 207 | + * should match the name property of a |
|
| 208 | + * EE_messenger. Optional. |
|
| 209 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 210 | + * type should validate with. Each value in |
|
| 211 | + * the |
|
| 212 | + * array |
|
| 213 | + * should match the name property of an |
|
| 214 | + * EE_messenger. |
|
| 215 | + * Optional. |
|
| 216 | + * } |
|
| 217 | + * @type array $custom_post_types |
|
| 218 | + * @type array $custom_taxonomies |
|
| 219 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 220 | + * EE_PMT_Base child class |
|
| 221 | + * (eg, |
|
| 222 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 223 | + * which contains the files |
|
| 224 | + * EE_PMT_Payomatic.pm.php) |
|
| 225 | + * @type array $default_terms |
|
| 226 | + * @type array $namespace { |
|
| 227 | + * An array with two items for registering the |
|
| 228 | + * addon's namespace. (If, for some reason, you |
|
| 229 | + * require additional namespaces, |
|
| 230 | + * use |
|
| 231 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 232 | + * directly) |
|
| 233 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 234 | + * @type string $FQNS the namespace prefix |
|
| 235 | + * @type string $DIR a base directory for class files in the |
|
| 236 | + * namespace. |
|
| 237 | + * } |
|
| 238 | + * } |
|
| 239 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
| 240 | + * privacy policy classes) or FQCNs (specific |
|
| 241 | + * classnames of privacy policy classes) |
|
| 242 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
| 243 | + * privacy policy classes) or FQCNs (specific |
|
| 244 | + * classnames of privacy policy classes) |
|
| 245 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
| 246 | + * privacy policy classes) or FQCNs (specific |
|
| 247 | + * classnames of privacy policy classes) |
|
| 248 | + * @return void |
|
| 249 | + * @throws DomainException |
|
| 250 | + * @throws EE_Error |
|
| 251 | + * @throws InvalidArgumentException |
|
| 252 | + * @throws ReflectionException |
|
| 253 | + * @throws InvalidDataTypeException |
|
| 254 | + * @throws InvalidInterfaceException |
|
| 255 | + */ |
|
| 256 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 257 | + { |
|
| 258 | + // required fields MUST be present, so let's make sure they are. |
|
| 259 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 260 | + // get class name for addon |
|
| 261 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 262 | + // setup $_settings array from incoming values. |
|
| 263 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 264 | + // setup PUE |
|
| 265 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 266 | + // does this addon work with this version of core or WordPress ? |
|
| 267 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 268 | + return; |
|
| 269 | + } |
|
| 270 | + // register namespaces |
|
| 271 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 272 | + // check if this is an activation request |
|
| 273 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 274 | + // dont bother setting up the rest of the addon atm |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + // we need cars |
|
| 278 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 279 | + // register new models and extensions |
|
| 280 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 281 | + // setup DMS |
|
| 282 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 283 | + // if config_class is present let's register config. |
|
| 284 | + EE_Register_Addon::_register_config($addon_name); |
|
| 285 | + // register admin pages |
|
| 286 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 287 | + // add to list of modules to be registered |
|
| 288 | + EE_Register_Addon::_register_modules($addon_name); |
|
| 289 | + // add to list of shortcodes to be registered |
|
| 290 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 291 | + // add to list of widgets to be registered |
|
| 292 | + EE_Register_Addon::_register_widgets($addon_name); |
|
| 293 | + // register capability related stuff. |
|
| 294 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
| 295 | + // any message type to register? |
|
| 296 | + EE_Register_Addon::_register_message_types($addon_name); |
|
| 297 | + // any custom post type/ custom capabilities or default terms to register |
|
| 298 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 299 | + // and any payment methods |
|
| 300 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 301 | + // and privacy policy generators |
|
| 302 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
| 303 | + // and privacy policy generators |
|
| 304 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
| 305 | + // and privacy policy generators |
|
| 306 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
| 307 | + // load and instantiate main addon class |
|
| 308 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 309 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 310 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * @param string $addon_name |
|
| 316 | - * @param array $setup_args |
|
| 317 | - * @return void |
|
| 318 | - * @throws EE_Error |
|
| 319 | - */ |
|
| 320 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 321 | - { |
|
| 322 | - // required fields MUST be present, so let's make sure they are. |
|
| 323 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 324 | - throw new EE_Error( |
|
| 325 | - __( |
|
| 326 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 327 | - 'event_espresso' |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 332 | - throw new EE_Error( |
|
| 333 | - sprintf( |
|
| 334 | - __( |
|
| 335 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 336 | - 'event_espresso' |
|
| 337 | - ), |
|
| 338 | - implode(',', array_keys($setup_args)) |
|
| 339 | - ) |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - // check that addon has not already been registered with that name |
|
| 343 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 344 | - throw new EE_Error( |
|
| 345 | - sprintf( |
|
| 346 | - __( |
|
| 347 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 348 | - 'event_espresso' |
|
| 349 | - ), |
|
| 350 | - $addon_name |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - } |
|
| 314 | + /** |
|
| 315 | + * @param string $addon_name |
|
| 316 | + * @param array $setup_args |
|
| 317 | + * @return void |
|
| 318 | + * @throws EE_Error |
|
| 319 | + */ |
|
| 320 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 321 | + { |
|
| 322 | + // required fields MUST be present, so let's make sure they are. |
|
| 323 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 324 | + throw new EE_Error( |
|
| 325 | + __( |
|
| 326 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 327 | + 'event_espresso' |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 332 | + throw new EE_Error( |
|
| 333 | + sprintf( |
|
| 334 | + __( |
|
| 335 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 336 | + 'event_espresso' |
|
| 337 | + ), |
|
| 338 | + implode(',', array_keys($setup_args)) |
|
| 339 | + ) |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + // check that addon has not already been registered with that name |
|
| 343 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 344 | + throw new EE_Error( |
|
| 345 | + sprintf( |
|
| 346 | + __( |
|
| 347 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 348 | + 'event_espresso' |
|
| 349 | + ), |
|
| 350 | + $addon_name |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * @param string $addon_name |
|
| 359 | - * @param array $setup_args |
|
| 360 | - * @return string |
|
| 361 | - */ |
|
| 362 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 363 | - { |
|
| 364 | - if (empty($setup_args['class_name'])) { |
|
| 365 | - // generate one by first separating name with spaces |
|
| 366 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 367 | - // capitalize, then replace spaces with underscores |
|
| 368 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 369 | - } else { |
|
| 370 | - $class_name = $setup_args['class_name']; |
|
| 371 | - } |
|
| 372 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 373 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 374 | - ? $class_name |
|
| 375 | - : 'EE_' . $class_name; |
|
| 376 | - } |
|
| 357 | + /** |
|
| 358 | + * @param string $addon_name |
|
| 359 | + * @param array $setup_args |
|
| 360 | + * @return string |
|
| 361 | + */ |
|
| 362 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 363 | + { |
|
| 364 | + if (empty($setup_args['class_name'])) { |
|
| 365 | + // generate one by first separating name with spaces |
|
| 366 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 367 | + // capitalize, then replace spaces with underscores |
|
| 368 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 369 | + } else { |
|
| 370 | + $class_name = $setup_args['class_name']; |
|
| 371 | + } |
|
| 372 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 373 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 374 | + ? $class_name |
|
| 375 | + : 'EE_' . $class_name; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * @param string $class_name |
|
| 381 | - * @param array $setup_args |
|
| 382 | - * @return array |
|
| 383 | - */ |
|
| 384 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 385 | - { |
|
| 386 | - // setup $_settings array from incoming values. |
|
| 387 | - $addon_settings = array( |
|
| 388 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 389 | - 'class_name' => $class_name, |
|
| 390 | - // the addon slug for use in URLs, etc |
|
| 391 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 392 | - ? (string) $setup_args['plugin_slug'] |
|
| 393 | - : '', |
|
| 394 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 395 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 396 | - ? (string) $setup_args['plugin_action_slug'] |
|
| 397 | - : '', |
|
| 398 | - // the "software" version for the addon |
|
| 399 | - 'version' => isset($setup_args['version']) |
|
| 400 | - ? (string) $setup_args['version'] |
|
| 401 | - : '', |
|
| 402 | - // the minimum version of EE Core that the addon will work with |
|
| 403 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 404 | - ? (string) $setup_args['min_core_version'] |
|
| 405 | - : '', |
|
| 406 | - // the minimum version of WordPress that the addon will work with |
|
| 407 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 408 | - ? (string) $setup_args['min_wp_version'] |
|
| 409 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 410 | - // full server path to main file (file loaded directly by WP) |
|
| 411 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 412 | - ? (string) $setup_args['main_file_path'] |
|
| 413 | - : '', |
|
| 414 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
| 415 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
| 416 | - ? $setup_args['domain'] |
|
| 417 | - : null, |
|
| 418 | - // Fully Qualified Class Name for the addon's Domain class |
|
| 419 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 420 | - ? (string) $setup_args['domain_fqcn'] |
|
| 421 | - : '', |
|
| 422 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 423 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 424 | - ? (string) $setup_args['admin_path'] : '', |
|
| 425 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 426 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 427 | - ? (string) $setup_args['admin_callback'] |
|
| 428 | - : '', |
|
| 429 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 430 | - 'config_section' => isset($setup_args['config_section']) |
|
| 431 | - ? (string) $setup_args['config_section'] |
|
| 432 | - : 'addons', |
|
| 433 | - // the class name for this addon's configuration settings object |
|
| 434 | - 'config_class' => isset($setup_args['config_class']) |
|
| 435 | - ? (string) $setup_args['config_class'] : '', |
|
| 436 | - // the name given to the config for this addons' configuration settings object (optional) |
|
| 437 | - 'config_name' => isset($setup_args['config_name']) |
|
| 438 | - ? (string) $setup_args['config_name'] : '', |
|
| 439 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 440 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 441 | - ? (array) $setup_args['autoloader_paths'] |
|
| 442 | - : array(), |
|
| 443 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 444 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 445 | - ? (array) $setup_args['autoloader_folders'] |
|
| 446 | - : array(), |
|
| 447 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 448 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 449 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 450 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 451 | - ? (array) $setup_args['dms_paths'] |
|
| 452 | - : array(), |
|
| 453 | - // array of full server paths to any EED_Modules used by the addon |
|
| 454 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 455 | - ? (array) $setup_args['module_paths'] |
|
| 456 | - : array(), |
|
| 457 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 458 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 459 | - ? (array) $setup_args['shortcode_paths'] |
|
| 460 | - : array(), |
|
| 461 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 462 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 463 | - : array(), |
|
| 464 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 465 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 466 | - ? (array) $setup_args['widget_paths'] |
|
| 467 | - : array(), |
|
| 468 | - // array of PUE options used by the addon |
|
| 469 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 470 | - ? (array) $setup_args['pue_options'] |
|
| 471 | - : array(), |
|
| 472 | - 'message_types' => isset($setup_args['message_types']) |
|
| 473 | - ? (array) $setup_args['message_types'] |
|
| 474 | - : array(), |
|
| 475 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 476 | - ? (array) $setup_args['capabilities'] |
|
| 477 | - : array(), |
|
| 478 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 479 | - ? (array) $setup_args['capability_maps'] |
|
| 480 | - : array(), |
|
| 481 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 482 | - ? (array) $setup_args['model_paths'] |
|
| 483 | - : array(), |
|
| 484 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 485 | - ? (array) $setup_args['class_paths'] |
|
| 486 | - : array(), |
|
| 487 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 488 | - ? (array) $setup_args['model_extension_paths'] |
|
| 489 | - : array(), |
|
| 490 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 491 | - ? (array) $setup_args['class_extension_paths'] |
|
| 492 | - : array(), |
|
| 493 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 494 | - ? (array) $setup_args['custom_post_types'] |
|
| 495 | - : array(), |
|
| 496 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 497 | - ? (array) $setup_args['custom_taxonomies'] |
|
| 498 | - : array(), |
|
| 499 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 500 | - ? (array) $setup_args['payment_method_paths'] |
|
| 501 | - : array(), |
|
| 502 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 503 | - ? (array) $setup_args['default_terms'] |
|
| 504 | - : array(), |
|
| 505 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 506 | - // that can be used for adding upgrading/marketing info |
|
| 507 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 508 | - ? $setup_args['plugins_page_row'] |
|
| 509 | - : '', |
|
| 510 | - 'namespace' => isset( |
|
| 511 | - $setup_args['namespace']['FQNS'], |
|
| 512 | - $setup_args['namespace']['DIR'] |
|
| 513 | - ) |
|
| 514 | - ? (array) $setup_args['namespace'] |
|
| 515 | - : array(), |
|
| 516 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
| 517 | - ? (array) $setup_args['privacy_policies'] |
|
| 518 | - : '', |
|
| 519 | - ); |
|
| 520 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 521 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 522 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 523 | - && ! empty($addon_settings['admin_path']) |
|
| 524 | - ? $addon_settings['plugin_slug'] |
|
| 525 | - : $addon_settings['plugin_action_slug']; |
|
| 526 | - // full server path to main file (file loaded directly by WP) |
|
| 527 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 528 | - return $addon_settings; |
|
| 529 | - } |
|
| 379 | + /** |
|
| 380 | + * @param string $class_name |
|
| 381 | + * @param array $setup_args |
|
| 382 | + * @return array |
|
| 383 | + */ |
|
| 384 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 385 | + { |
|
| 386 | + // setup $_settings array from incoming values. |
|
| 387 | + $addon_settings = array( |
|
| 388 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 389 | + 'class_name' => $class_name, |
|
| 390 | + // the addon slug for use in URLs, etc |
|
| 391 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 392 | + ? (string) $setup_args['plugin_slug'] |
|
| 393 | + : '', |
|
| 394 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 395 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 396 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 397 | + : '', |
|
| 398 | + // the "software" version for the addon |
|
| 399 | + 'version' => isset($setup_args['version']) |
|
| 400 | + ? (string) $setup_args['version'] |
|
| 401 | + : '', |
|
| 402 | + // the minimum version of EE Core that the addon will work with |
|
| 403 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 404 | + ? (string) $setup_args['min_core_version'] |
|
| 405 | + : '', |
|
| 406 | + // the minimum version of WordPress that the addon will work with |
|
| 407 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 408 | + ? (string) $setup_args['min_wp_version'] |
|
| 409 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 410 | + // full server path to main file (file loaded directly by WP) |
|
| 411 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 412 | + ? (string) $setup_args['main_file_path'] |
|
| 413 | + : '', |
|
| 414 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
| 415 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
| 416 | + ? $setup_args['domain'] |
|
| 417 | + : null, |
|
| 418 | + // Fully Qualified Class Name for the addon's Domain class |
|
| 419 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 420 | + ? (string) $setup_args['domain_fqcn'] |
|
| 421 | + : '', |
|
| 422 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 423 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 424 | + ? (string) $setup_args['admin_path'] : '', |
|
| 425 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 426 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 427 | + ? (string) $setup_args['admin_callback'] |
|
| 428 | + : '', |
|
| 429 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 430 | + 'config_section' => isset($setup_args['config_section']) |
|
| 431 | + ? (string) $setup_args['config_section'] |
|
| 432 | + : 'addons', |
|
| 433 | + // the class name for this addon's configuration settings object |
|
| 434 | + 'config_class' => isset($setup_args['config_class']) |
|
| 435 | + ? (string) $setup_args['config_class'] : '', |
|
| 436 | + // the name given to the config for this addons' configuration settings object (optional) |
|
| 437 | + 'config_name' => isset($setup_args['config_name']) |
|
| 438 | + ? (string) $setup_args['config_name'] : '', |
|
| 439 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 440 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 441 | + ? (array) $setup_args['autoloader_paths'] |
|
| 442 | + : array(), |
|
| 443 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 444 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 445 | + ? (array) $setup_args['autoloader_folders'] |
|
| 446 | + : array(), |
|
| 447 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 448 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 449 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 450 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 451 | + ? (array) $setup_args['dms_paths'] |
|
| 452 | + : array(), |
|
| 453 | + // array of full server paths to any EED_Modules used by the addon |
|
| 454 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 455 | + ? (array) $setup_args['module_paths'] |
|
| 456 | + : array(), |
|
| 457 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 458 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 459 | + ? (array) $setup_args['shortcode_paths'] |
|
| 460 | + : array(), |
|
| 461 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 462 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 463 | + : array(), |
|
| 464 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 465 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 466 | + ? (array) $setup_args['widget_paths'] |
|
| 467 | + : array(), |
|
| 468 | + // array of PUE options used by the addon |
|
| 469 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 470 | + ? (array) $setup_args['pue_options'] |
|
| 471 | + : array(), |
|
| 472 | + 'message_types' => isset($setup_args['message_types']) |
|
| 473 | + ? (array) $setup_args['message_types'] |
|
| 474 | + : array(), |
|
| 475 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 476 | + ? (array) $setup_args['capabilities'] |
|
| 477 | + : array(), |
|
| 478 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 479 | + ? (array) $setup_args['capability_maps'] |
|
| 480 | + : array(), |
|
| 481 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 482 | + ? (array) $setup_args['model_paths'] |
|
| 483 | + : array(), |
|
| 484 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 485 | + ? (array) $setup_args['class_paths'] |
|
| 486 | + : array(), |
|
| 487 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 488 | + ? (array) $setup_args['model_extension_paths'] |
|
| 489 | + : array(), |
|
| 490 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 491 | + ? (array) $setup_args['class_extension_paths'] |
|
| 492 | + : array(), |
|
| 493 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 494 | + ? (array) $setup_args['custom_post_types'] |
|
| 495 | + : array(), |
|
| 496 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 497 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 498 | + : array(), |
|
| 499 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 500 | + ? (array) $setup_args['payment_method_paths'] |
|
| 501 | + : array(), |
|
| 502 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 503 | + ? (array) $setup_args['default_terms'] |
|
| 504 | + : array(), |
|
| 505 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 506 | + // that can be used for adding upgrading/marketing info |
|
| 507 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 508 | + ? $setup_args['plugins_page_row'] |
|
| 509 | + : '', |
|
| 510 | + 'namespace' => isset( |
|
| 511 | + $setup_args['namespace']['FQNS'], |
|
| 512 | + $setup_args['namespace']['DIR'] |
|
| 513 | + ) |
|
| 514 | + ? (array) $setup_args['namespace'] |
|
| 515 | + : array(), |
|
| 516 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
| 517 | + ? (array) $setup_args['privacy_policies'] |
|
| 518 | + : '', |
|
| 519 | + ); |
|
| 520 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 521 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 522 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 523 | + && ! empty($addon_settings['admin_path']) |
|
| 524 | + ? $addon_settings['plugin_slug'] |
|
| 525 | + : $addon_settings['plugin_action_slug']; |
|
| 526 | + // full server path to main file (file loaded directly by WP) |
|
| 527 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 528 | + return $addon_settings; |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | 531 | |
| 532 | - /** |
|
| 533 | - * @param string $addon_name |
|
| 534 | - * @param array $addon_settings |
|
| 535 | - * @return boolean |
|
| 536 | - */ |
|
| 537 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 538 | - { |
|
| 539 | - global $wp_version; |
|
| 540 | - $incompatibility_message = ''; |
|
| 541 | - // check whether this addon version is compatible with EE core |
|
| 542 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 543 | - && ! self::_meets_min_core_version_requirement( |
|
| 544 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 545 | - $addon_settings['version'] |
|
| 546 | - ) |
|
| 547 | - ) { |
|
| 548 | - $incompatibility_message = sprintf( |
|
| 549 | - __( |
|
| 550 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
| 551 | - 'event_espresso' |
|
| 552 | - ), |
|
| 553 | - $addon_name, |
|
| 554 | - '<br />', |
|
| 555 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 556 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 557 | - '</span><br />' |
|
| 558 | - ); |
|
| 559 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 560 | - ) { |
|
| 561 | - $incompatibility_message = sprintf( |
|
| 562 | - __( |
|
| 563 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 564 | - 'event_espresso' |
|
| 565 | - ), |
|
| 566 | - $addon_name, |
|
| 567 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 568 | - self::_effective_version(espresso_version()), |
|
| 569 | - '<br />', |
|
| 570 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 571 | - '</span><br />' |
|
| 572 | - ); |
|
| 573 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 574 | - $incompatibility_message = sprintf( |
|
| 575 | - __( |
|
| 576 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 577 | - 'event_espresso' |
|
| 578 | - ), |
|
| 579 | - $addon_name, |
|
| 580 | - $addon_settings['min_wp_version'], |
|
| 581 | - '<br />', |
|
| 582 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 583 | - '</span><br />' |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - if (! empty($incompatibility_message)) { |
|
| 587 | - // remove 'activate' from the REQUEST |
|
| 588 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 589 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 590 | - if (current_user_can('activate_plugins')) { |
|
| 591 | - // show an error message indicating the plugin didn't activate properly |
|
| 592 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 593 | - } |
|
| 594 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 595 | - return false; |
|
| 596 | - } |
|
| 597 | - // addon IS compatible |
|
| 598 | - return true; |
|
| 599 | - } |
|
| 532 | + /** |
|
| 533 | + * @param string $addon_name |
|
| 534 | + * @param array $addon_settings |
|
| 535 | + * @return boolean |
|
| 536 | + */ |
|
| 537 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 538 | + { |
|
| 539 | + global $wp_version; |
|
| 540 | + $incompatibility_message = ''; |
|
| 541 | + // check whether this addon version is compatible with EE core |
|
| 542 | + if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 543 | + && ! self::_meets_min_core_version_requirement( |
|
| 544 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 545 | + $addon_settings['version'] |
|
| 546 | + ) |
|
| 547 | + ) { |
|
| 548 | + $incompatibility_message = sprintf( |
|
| 549 | + __( |
|
| 550 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
| 551 | + 'event_espresso' |
|
| 552 | + ), |
|
| 553 | + $addon_name, |
|
| 554 | + '<br />', |
|
| 555 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 556 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 557 | + '</span><br />' |
|
| 558 | + ); |
|
| 559 | + } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 560 | + ) { |
|
| 561 | + $incompatibility_message = sprintf( |
|
| 562 | + __( |
|
| 563 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 564 | + 'event_espresso' |
|
| 565 | + ), |
|
| 566 | + $addon_name, |
|
| 567 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 568 | + self::_effective_version(espresso_version()), |
|
| 569 | + '<br />', |
|
| 570 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 571 | + '</span><br />' |
|
| 572 | + ); |
|
| 573 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 574 | + $incompatibility_message = sprintf( |
|
| 575 | + __( |
|
| 576 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 577 | + 'event_espresso' |
|
| 578 | + ), |
|
| 579 | + $addon_name, |
|
| 580 | + $addon_settings['min_wp_version'], |
|
| 581 | + '<br />', |
|
| 582 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 583 | + '</span><br />' |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + if (! empty($incompatibility_message)) { |
|
| 587 | + // remove 'activate' from the REQUEST |
|
| 588 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 589 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 590 | + if (current_user_can('activate_plugins')) { |
|
| 591 | + // show an error message indicating the plugin didn't activate properly |
|
| 592 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 593 | + } |
|
| 594 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 595 | + return false; |
|
| 596 | + } |
|
| 597 | + // addon IS compatible |
|
| 598 | + return true; |
|
| 599 | + } |
|
| 600 | 600 | |
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * if plugin update engine is being used for auto-updates, |
|
| 604 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 605 | - * (not needed if PUE is not being used) |
|
| 606 | - * |
|
| 607 | - * @param string $addon_name |
|
| 608 | - * @param string $class_name |
|
| 609 | - * @param array $setup_args |
|
| 610 | - * @return void |
|
| 611 | - */ |
|
| 612 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 613 | - { |
|
| 614 | - if (! empty($setup_args['pue_options'])) { |
|
| 615 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 616 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 617 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 618 | - : 'espresso_' . strtolower($class_name), |
|
| 619 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 620 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 621 | - : plugin_basename($setup_args['main_file_path']), |
|
| 622 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 623 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 624 | - : '24', |
|
| 625 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 626 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 627 | - : false, |
|
| 628 | - ); |
|
| 629 | - add_action( |
|
| 630 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 631 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 632 | - ); |
|
| 633 | - } |
|
| 634 | - } |
|
| 602 | + /** |
|
| 603 | + * if plugin update engine is being used for auto-updates, |
|
| 604 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 605 | + * (not needed if PUE is not being used) |
|
| 606 | + * |
|
| 607 | + * @param string $addon_name |
|
| 608 | + * @param string $class_name |
|
| 609 | + * @param array $setup_args |
|
| 610 | + * @return void |
|
| 611 | + */ |
|
| 612 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 613 | + { |
|
| 614 | + if (! empty($setup_args['pue_options'])) { |
|
| 615 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 616 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 617 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 618 | + : 'espresso_' . strtolower($class_name), |
|
| 619 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 620 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 621 | + : plugin_basename($setup_args['main_file_path']), |
|
| 622 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 623 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 624 | + : '24', |
|
| 625 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 626 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 627 | + : false, |
|
| 628 | + ); |
|
| 629 | + add_action( |
|
| 630 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 631 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 632 | + ); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | 635 | |
| 636 | 636 | |
| 637 | - /** |
|
| 638 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 639 | - * |
|
| 640 | - * @param array $addon_settings |
|
| 641 | - * @return void |
|
| 642 | - */ |
|
| 643 | - private static function _setup_namespaces(array $addon_settings) |
|
| 644 | - { |
|
| 645 | - // |
|
| 646 | - if (isset( |
|
| 647 | - $addon_settings['namespace']['FQNS'], |
|
| 648 | - $addon_settings['namespace']['DIR'] |
|
| 649 | - )) { |
|
| 650 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 651 | - $addon_settings['namespace']['FQNS'], |
|
| 652 | - $addon_settings['namespace']['DIR'] |
|
| 653 | - ); |
|
| 654 | - } |
|
| 655 | - } |
|
| 637 | + /** |
|
| 638 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 639 | + * |
|
| 640 | + * @param array $addon_settings |
|
| 641 | + * @return void |
|
| 642 | + */ |
|
| 643 | + private static function _setup_namespaces(array $addon_settings) |
|
| 644 | + { |
|
| 645 | + // |
|
| 646 | + if (isset( |
|
| 647 | + $addon_settings['namespace']['FQNS'], |
|
| 648 | + $addon_settings['namespace']['DIR'] |
|
| 649 | + )) { |
|
| 650 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 651 | + $addon_settings['namespace']['FQNS'], |
|
| 652 | + $addon_settings['namespace']['DIR'] |
|
| 653 | + ); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | 656 | |
| 657 | 657 | |
| 658 | - /** |
|
| 659 | - * @param string $addon_name |
|
| 660 | - * @param array $addon_settings |
|
| 661 | - * @return bool |
|
| 662 | - * @throws EE_Error |
|
| 663 | - * @throws InvalidArgumentException |
|
| 664 | - * @throws ReflectionException |
|
| 665 | - * @throws InvalidDataTypeException |
|
| 666 | - * @throws InvalidInterfaceException |
|
| 667 | - */ |
|
| 668 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 669 | - { |
|
| 670 | - // this is an activation request |
|
| 671 | - if (did_action( |
|
| 672 | - 'activate_plugin' |
|
| 673 | - )) {// to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 674 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
| 675 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 676 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 677 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 678 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 679 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 680 | - ) |
|
| 681 | - ) { |
|
| 682 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 683 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 684 | - $addon->set_activation_indicator_option(); |
|
| 685 | - // dont bother setting up the rest of the addon. |
|
| 686 | - // we know it was just activated and the request will end soon |
|
| 687 | - } |
|
| 688 | - return true; |
|
| 689 | - } |
|
| 690 | - // make sure this was called in the right place! |
|
| 691 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 692 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 693 | - ) { |
|
| 694 | - EE_Error::doing_it_wrong( |
|
| 695 | - __METHOD__, |
|
| 696 | - sprintf( |
|
| 697 | - __( |
|
| 698 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 699 | - 'event_espresso' |
|
| 700 | - ), |
|
| 701 | - $addon_name |
|
| 702 | - ), |
|
| 703 | - '4.3.0' |
|
| 704 | - ); |
|
| 705 | - } |
|
| 706 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 707 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 708 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 709 | - } else { |
|
| 710 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 711 | - } |
|
| 712 | - return false; |
|
| 713 | - } |
|
| 658 | + /** |
|
| 659 | + * @param string $addon_name |
|
| 660 | + * @param array $addon_settings |
|
| 661 | + * @return bool |
|
| 662 | + * @throws EE_Error |
|
| 663 | + * @throws InvalidArgumentException |
|
| 664 | + * @throws ReflectionException |
|
| 665 | + * @throws InvalidDataTypeException |
|
| 666 | + * @throws InvalidInterfaceException |
|
| 667 | + */ |
|
| 668 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 669 | + { |
|
| 670 | + // this is an activation request |
|
| 671 | + if (did_action( |
|
| 672 | + 'activate_plugin' |
|
| 673 | + )) {// to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 674 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
| 675 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 676 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 677 | + if (! isset(self::$_settings[ $addon_name ]) |
|
| 678 | + || (isset(self::$_settings[ $addon_name ]) |
|
| 679 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 680 | + ) |
|
| 681 | + ) { |
|
| 682 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 683 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 684 | + $addon->set_activation_indicator_option(); |
|
| 685 | + // dont bother setting up the rest of the addon. |
|
| 686 | + // we know it was just activated and the request will end soon |
|
| 687 | + } |
|
| 688 | + return true; |
|
| 689 | + } |
|
| 690 | + // make sure this was called in the right place! |
|
| 691 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 692 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 693 | + ) { |
|
| 694 | + EE_Error::doing_it_wrong( |
|
| 695 | + __METHOD__, |
|
| 696 | + sprintf( |
|
| 697 | + __( |
|
| 698 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 699 | + 'event_espresso' |
|
| 700 | + ), |
|
| 701 | + $addon_name |
|
| 702 | + ), |
|
| 703 | + '4.3.0' |
|
| 704 | + ); |
|
| 705 | + } |
|
| 706 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 707 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 708 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
| 709 | + } else { |
|
| 710 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 711 | + } |
|
| 712 | + return false; |
|
| 713 | + } |
|
| 714 | 714 | |
| 715 | 715 | |
| 716 | - /** |
|
| 717 | - * @param string $addon_name |
|
| 718 | - * @return void |
|
| 719 | - * @throws EE_Error |
|
| 720 | - */ |
|
| 721 | - private static function _setup_autoloaders($addon_name) |
|
| 722 | - { |
|
| 723 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 724 | - // setup autoloader for single file |
|
| 725 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 726 | - } |
|
| 727 | - // setup autoloaders for folders |
|
| 728 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 729 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 730 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - } |
|
| 716 | + /** |
|
| 717 | + * @param string $addon_name |
|
| 718 | + * @return void |
|
| 719 | + * @throws EE_Error |
|
| 720 | + */ |
|
| 721 | + private static function _setup_autoloaders($addon_name) |
|
| 722 | + { |
|
| 723 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 724 | + // setup autoloader for single file |
|
| 725 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 726 | + } |
|
| 727 | + // setup autoloaders for folders |
|
| 728 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 729 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 730 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | 735 | |
| 736 | - /** |
|
| 737 | - * register new models and extensions |
|
| 738 | - * |
|
| 739 | - * @param string $addon_name |
|
| 740 | - * @return void |
|
| 741 | - * @throws EE_Error |
|
| 742 | - */ |
|
| 743 | - private static function _register_models_and_extensions($addon_name) |
|
| 744 | - { |
|
| 745 | - // register new models |
|
| 746 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 747 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 748 | - ) { |
|
| 749 | - EE_Register_Model::register( |
|
| 750 | - $addon_name, |
|
| 751 | - array( |
|
| 752 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 753 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 754 | - ) |
|
| 755 | - ); |
|
| 756 | - } |
|
| 757 | - // register model extensions |
|
| 758 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 759 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 760 | - ) { |
|
| 761 | - EE_Register_Model_Extensions::register( |
|
| 762 | - $addon_name, |
|
| 763 | - array( |
|
| 764 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 765 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 766 | - ) |
|
| 767 | - ); |
|
| 768 | - } |
|
| 769 | - } |
|
| 736 | + /** |
|
| 737 | + * register new models and extensions |
|
| 738 | + * |
|
| 739 | + * @param string $addon_name |
|
| 740 | + * @return void |
|
| 741 | + * @throws EE_Error |
|
| 742 | + */ |
|
| 743 | + private static function _register_models_and_extensions($addon_name) |
|
| 744 | + { |
|
| 745 | + // register new models |
|
| 746 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 747 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 748 | + ) { |
|
| 749 | + EE_Register_Model::register( |
|
| 750 | + $addon_name, |
|
| 751 | + array( |
|
| 752 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 753 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 754 | + ) |
|
| 755 | + ); |
|
| 756 | + } |
|
| 757 | + // register model extensions |
|
| 758 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 759 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 760 | + ) { |
|
| 761 | + EE_Register_Model_Extensions::register( |
|
| 762 | + $addon_name, |
|
| 763 | + array( |
|
| 764 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 765 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 766 | + ) |
|
| 767 | + ); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | 770 | |
| 771 | 771 | |
| 772 | - /** |
|
| 773 | - * @param string $addon_name |
|
| 774 | - * @return void |
|
| 775 | - * @throws EE_Error |
|
| 776 | - */ |
|
| 777 | - private static function _register_data_migration_scripts($addon_name) |
|
| 778 | - { |
|
| 779 | - // setup DMS |
|
| 780 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 781 | - EE_Register_Data_Migration_Scripts::register( |
|
| 782 | - $addon_name, |
|
| 783 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 784 | - ); |
|
| 785 | - } |
|
| 786 | - } |
|
| 772 | + /** |
|
| 773 | + * @param string $addon_name |
|
| 774 | + * @return void |
|
| 775 | + * @throws EE_Error |
|
| 776 | + */ |
|
| 777 | + private static function _register_data_migration_scripts($addon_name) |
|
| 778 | + { |
|
| 779 | + // setup DMS |
|
| 780 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 781 | + EE_Register_Data_Migration_Scripts::register( |
|
| 782 | + $addon_name, |
|
| 783 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 784 | + ); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | 787 | |
| 788 | 788 | |
| 789 | - /** |
|
| 790 | - * @param string $addon_name |
|
| 791 | - * @return void |
|
| 792 | - * @throws EE_Error |
|
| 793 | - */ |
|
| 794 | - private static function _register_config($addon_name) |
|
| 795 | - { |
|
| 796 | - // if config_class is present let's register config. |
|
| 797 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 798 | - EE_Register_Config::register( |
|
| 799 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 800 | - array( |
|
| 801 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 802 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 803 | - ) |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - } |
|
| 789 | + /** |
|
| 790 | + * @param string $addon_name |
|
| 791 | + * @return void |
|
| 792 | + * @throws EE_Error |
|
| 793 | + */ |
|
| 794 | + private static function _register_config($addon_name) |
|
| 795 | + { |
|
| 796 | + // if config_class is present let's register config. |
|
| 797 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 798 | + EE_Register_Config::register( |
|
| 799 | + self::$_settings[ $addon_name ]['config_class'], |
|
| 800 | + array( |
|
| 801 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 802 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 803 | + ) |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | 807 | |
| 808 | 808 | |
| 809 | - /** |
|
| 810 | - * @param string $addon_name |
|
| 811 | - * @return void |
|
| 812 | - * @throws EE_Error |
|
| 813 | - */ |
|
| 814 | - private static function _register_admin_pages($addon_name) |
|
| 815 | - { |
|
| 816 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 817 | - EE_Register_Admin_Page::register( |
|
| 818 | - $addon_name, |
|
| 819 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 820 | - ); |
|
| 821 | - } |
|
| 822 | - } |
|
| 809 | + /** |
|
| 810 | + * @param string $addon_name |
|
| 811 | + * @return void |
|
| 812 | + * @throws EE_Error |
|
| 813 | + */ |
|
| 814 | + private static function _register_admin_pages($addon_name) |
|
| 815 | + { |
|
| 816 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 817 | + EE_Register_Admin_Page::register( |
|
| 818 | + $addon_name, |
|
| 819 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 820 | + ); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | 823 | |
| 824 | 824 | |
| 825 | - /** |
|
| 826 | - * @param string $addon_name |
|
| 827 | - * @return void |
|
| 828 | - * @throws EE_Error |
|
| 829 | - */ |
|
| 830 | - private static function _register_modules($addon_name) |
|
| 831 | - { |
|
| 832 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 833 | - EE_Register_Module::register( |
|
| 834 | - $addon_name, |
|
| 835 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 836 | - ); |
|
| 837 | - } |
|
| 838 | - } |
|
| 825 | + /** |
|
| 826 | + * @param string $addon_name |
|
| 827 | + * @return void |
|
| 828 | + * @throws EE_Error |
|
| 829 | + */ |
|
| 830 | + private static function _register_modules($addon_name) |
|
| 831 | + { |
|
| 832 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 833 | + EE_Register_Module::register( |
|
| 834 | + $addon_name, |
|
| 835 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 836 | + ); |
|
| 837 | + } |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | 840 | |
| 841 | - /** |
|
| 842 | - * @param string $addon_name |
|
| 843 | - * @return void |
|
| 844 | - * @throws EE_Error |
|
| 845 | - */ |
|
| 846 | - private static function _register_shortcodes($addon_name) |
|
| 847 | - { |
|
| 848 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 849 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 850 | - ) { |
|
| 851 | - EE_Register_Shortcode::register( |
|
| 852 | - $addon_name, |
|
| 853 | - array( |
|
| 854 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 855 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 856 | - : array(), |
|
| 857 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 858 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 859 | - : array(), |
|
| 860 | - ) |
|
| 861 | - ); |
|
| 862 | - } |
|
| 863 | - } |
|
| 841 | + /** |
|
| 842 | + * @param string $addon_name |
|
| 843 | + * @return void |
|
| 844 | + * @throws EE_Error |
|
| 845 | + */ |
|
| 846 | + private static function _register_shortcodes($addon_name) |
|
| 847 | + { |
|
| 848 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 849 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 850 | + ) { |
|
| 851 | + EE_Register_Shortcode::register( |
|
| 852 | + $addon_name, |
|
| 853 | + array( |
|
| 854 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 855 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 856 | + : array(), |
|
| 857 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 858 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 859 | + : array(), |
|
| 860 | + ) |
|
| 861 | + ); |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | 865 | |
| 866 | - /** |
|
| 867 | - * @param string $addon_name |
|
| 868 | - * @return void |
|
| 869 | - * @throws EE_Error |
|
| 870 | - */ |
|
| 871 | - private static function _register_widgets($addon_name) |
|
| 872 | - { |
|
| 873 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 874 | - EE_Register_Widget::register( |
|
| 875 | - $addon_name, |
|
| 876 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 877 | - ); |
|
| 878 | - } |
|
| 879 | - } |
|
| 866 | + /** |
|
| 867 | + * @param string $addon_name |
|
| 868 | + * @return void |
|
| 869 | + * @throws EE_Error |
|
| 870 | + */ |
|
| 871 | + private static function _register_widgets($addon_name) |
|
| 872 | + { |
|
| 873 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 874 | + EE_Register_Widget::register( |
|
| 875 | + $addon_name, |
|
| 876 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 877 | + ); |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | 881 | |
| 882 | - /** |
|
| 883 | - * @param string $addon_name |
|
| 884 | - * @return void |
|
| 885 | - * @throws EE_Error |
|
| 886 | - */ |
|
| 887 | - private static function _register_capabilities($addon_name) |
|
| 888 | - { |
|
| 889 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 890 | - EE_Register_Capabilities::register( |
|
| 891 | - $addon_name, |
|
| 892 | - array( |
|
| 893 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 894 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 895 | - ) |
|
| 896 | - ); |
|
| 897 | - } |
|
| 898 | - } |
|
| 882 | + /** |
|
| 883 | + * @param string $addon_name |
|
| 884 | + * @return void |
|
| 885 | + * @throws EE_Error |
|
| 886 | + */ |
|
| 887 | + private static function _register_capabilities($addon_name) |
|
| 888 | + { |
|
| 889 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 890 | + EE_Register_Capabilities::register( |
|
| 891 | + $addon_name, |
|
| 892 | + array( |
|
| 893 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 894 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 895 | + ) |
|
| 896 | + ); |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | 899 | |
| 900 | 900 | |
| 901 | - /** |
|
| 902 | - * @param string $addon_name |
|
| 903 | - * @return void |
|
| 904 | - * @throws EE_Error |
|
| 905 | - */ |
|
| 906 | - private static function _register_message_types($addon_name) |
|
| 907 | - { |
|
| 908 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 909 | - add_action( |
|
| 910 | - 'EE_Brewing_Regular___messages_caf', |
|
| 911 | - array('EE_Register_Addon', 'register_message_types') |
|
| 912 | - ); |
|
| 913 | - } |
|
| 914 | - } |
|
| 901 | + /** |
|
| 902 | + * @param string $addon_name |
|
| 903 | + * @return void |
|
| 904 | + * @throws EE_Error |
|
| 905 | + */ |
|
| 906 | + private static function _register_message_types($addon_name) |
|
| 907 | + { |
|
| 908 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 909 | + add_action( |
|
| 910 | + 'EE_Brewing_Regular___messages_caf', |
|
| 911 | + array('EE_Register_Addon', 'register_message_types') |
|
| 912 | + ); |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | 915 | |
| 916 | 916 | |
| 917 | - /** |
|
| 918 | - * @param string $addon_name |
|
| 919 | - * @return void |
|
| 920 | - * @throws EE_Error |
|
| 921 | - */ |
|
| 922 | - private static function _register_custom_post_types($addon_name) |
|
| 923 | - { |
|
| 924 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 925 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 926 | - ) { |
|
| 927 | - EE_Register_CPT::register( |
|
| 928 | - $addon_name, |
|
| 929 | - array( |
|
| 930 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 931 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 932 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 933 | - ) |
|
| 934 | - ); |
|
| 935 | - } |
|
| 936 | - } |
|
| 917 | + /** |
|
| 918 | + * @param string $addon_name |
|
| 919 | + * @return void |
|
| 920 | + * @throws EE_Error |
|
| 921 | + */ |
|
| 922 | + private static function _register_custom_post_types($addon_name) |
|
| 923 | + { |
|
| 924 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 925 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 926 | + ) { |
|
| 927 | + EE_Register_CPT::register( |
|
| 928 | + $addon_name, |
|
| 929 | + array( |
|
| 930 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 931 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 932 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 933 | + ) |
|
| 934 | + ); |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | 937 | |
| 938 | 938 | |
| 939 | - /** |
|
| 940 | - * @param string $addon_name |
|
| 941 | - * @return void |
|
| 942 | - * @throws InvalidArgumentException |
|
| 943 | - * @throws InvalidInterfaceException |
|
| 944 | - * @throws InvalidDataTypeException |
|
| 945 | - * @throws DomainException |
|
| 946 | - * @throws EE_Error |
|
| 947 | - */ |
|
| 948 | - private static function _register_payment_methods($addon_name) |
|
| 949 | - { |
|
| 950 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 951 | - EE_Register_Payment_Method::register( |
|
| 952 | - $addon_name, |
|
| 953 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 954 | - ); |
|
| 955 | - } |
|
| 956 | - } |
|
| 939 | + /** |
|
| 940 | + * @param string $addon_name |
|
| 941 | + * @return void |
|
| 942 | + * @throws InvalidArgumentException |
|
| 943 | + * @throws InvalidInterfaceException |
|
| 944 | + * @throws InvalidDataTypeException |
|
| 945 | + * @throws DomainException |
|
| 946 | + * @throws EE_Error |
|
| 947 | + */ |
|
| 948 | + private static function _register_payment_methods($addon_name) |
|
| 949 | + { |
|
| 950 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 951 | + EE_Register_Payment_Method::register( |
|
| 952 | + $addon_name, |
|
| 953 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 954 | + ); |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | 957 | |
| 958 | 958 | |
| 959 | - /** |
|
| 960 | - * @param string $addon_name |
|
| 961 | - * @return void |
|
| 962 | - * @throws InvalidArgumentException |
|
| 963 | - * @throws InvalidInterfaceException |
|
| 964 | - * @throws InvalidDataTypeException |
|
| 965 | - * @throws DomainException |
|
| 966 | - * @throws EE_Error |
|
| 967 | - */ |
|
| 968 | - private static function registerPrivacyPolicies($addon_name) |
|
| 969 | - { |
|
| 970 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 971 | - EE_Register_Privacy_Policy::register( |
|
| 972 | - $addon_name, |
|
| 973 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 974 | - ); |
|
| 975 | - } |
|
| 976 | - } |
|
| 959 | + /** |
|
| 960 | + * @param string $addon_name |
|
| 961 | + * @return void |
|
| 962 | + * @throws InvalidArgumentException |
|
| 963 | + * @throws InvalidInterfaceException |
|
| 964 | + * @throws InvalidDataTypeException |
|
| 965 | + * @throws DomainException |
|
| 966 | + * @throws EE_Error |
|
| 967 | + */ |
|
| 968 | + private static function registerPrivacyPolicies($addon_name) |
|
| 969 | + { |
|
| 970 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 971 | + EE_Register_Privacy_Policy::register( |
|
| 972 | + $addon_name, |
|
| 973 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 974 | + ); |
|
| 975 | + } |
|
| 976 | + } |
|
| 977 | 977 | |
| 978 | 978 | |
| 979 | - /** |
|
| 980 | - * @param string $addon_name |
|
| 981 | - * @return void |
|
| 982 | - */ |
|
| 983 | - private static function registerPersonalDataExporters($addon_name) |
|
| 984 | - { |
|
| 985 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 986 | - EE_Register_Personal_Data_Eraser::register( |
|
| 987 | - $addon_name, |
|
| 988 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 989 | - ); |
|
| 990 | - } |
|
| 991 | - } |
|
| 979 | + /** |
|
| 980 | + * @param string $addon_name |
|
| 981 | + * @return void |
|
| 982 | + */ |
|
| 983 | + private static function registerPersonalDataExporters($addon_name) |
|
| 984 | + { |
|
| 985 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 986 | + EE_Register_Personal_Data_Eraser::register( |
|
| 987 | + $addon_name, |
|
| 988 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 989 | + ); |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | 992 | |
| 993 | 993 | |
| 994 | - /** |
|
| 995 | - * @param string $addon_name |
|
| 996 | - * @return void |
|
| 997 | - */ |
|
| 998 | - private static function registerPersonalDataErasers($addon_name) |
|
| 999 | - { |
|
| 1000 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1001 | - EE_Register_Personal_Data_Eraser::register( |
|
| 1002 | - $addon_name, |
|
| 1003 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1004 | - ); |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 994 | + /** |
|
| 995 | + * @param string $addon_name |
|
| 996 | + * @return void |
|
| 997 | + */ |
|
| 998 | + private static function registerPersonalDataErasers($addon_name) |
|
| 999 | + { |
|
| 1000 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1001 | + EE_Register_Personal_Data_Eraser::register( |
|
| 1002 | + $addon_name, |
|
| 1003 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1004 | + ); |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | 1007 | |
| 1008 | 1008 | |
| 1009 | - /** |
|
| 1010 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 1011 | - * |
|
| 1012 | - * @param string $addon_name |
|
| 1013 | - * @return EE_Addon |
|
| 1014 | - * @throws InvalidArgumentException |
|
| 1015 | - * @throws InvalidInterfaceException |
|
| 1016 | - * @throws InvalidDataTypeException |
|
| 1017 | - * @throws ReflectionException |
|
| 1018 | - * @throws EE_Error |
|
| 1019 | - */ |
|
| 1020 | - private static function _load_and_init_addon_class($addon_name) |
|
| 1021 | - { |
|
| 1022 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 1023 | - $addon = $loader->getShared( |
|
| 1024 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 1025 | - array('EE_Registry::create(addon)' => true) |
|
| 1026 | - ); |
|
| 1027 | - // setter inject dep map if required |
|
| 1028 | - if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 1029 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 1030 | - } |
|
| 1031 | - // setter inject domain if required |
|
| 1032 | - if ($addon instanceof RequiresDomainInterface |
|
| 1033 | - && $addon->domain() === null |
|
| 1034 | - ) { |
|
| 1035 | - // using supplied Domain object |
|
| 1036 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1037 | - ? self::$_settings[ $addon_name ]['domain'] |
|
| 1038 | - : null; |
|
| 1039 | - // or construct one using Domain FQCN |
|
| 1040 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1041 | - $domain = $loader->getShared( |
|
| 1042 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1043 | - array( |
|
| 1044 | - new EventEspresso\core\domain\values\FilePath( |
|
| 1045 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1046 | - ), |
|
| 1047 | - EventEspresso\core\domain\values\Version::fromString( |
|
| 1048 | - self::$_settings[ $addon_name ]['version'] |
|
| 1049 | - ), |
|
| 1050 | - ) |
|
| 1051 | - ); |
|
| 1052 | - } |
|
| 1053 | - if ($domain instanceof DomainInterface) { |
|
| 1054 | - $addon->setDomain($domain); |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - $addon->set_name($addon_name); |
|
| 1058 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1059 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1060 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1061 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1062 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1063 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1064 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1065 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1066 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1067 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1068 | - // unfortunately this can't be hooked in upon construction, because we don't have |
|
| 1069 | - // the plugin mainfile's path upon construction. |
|
| 1070 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 1071 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 1072 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1073 | - add_action( |
|
| 1074 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1075 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1076 | - ); |
|
| 1077 | - } |
|
| 1078 | - return $addon; |
|
| 1079 | - } |
|
| 1009 | + /** |
|
| 1010 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 1011 | + * |
|
| 1012 | + * @param string $addon_name |
|
| 1013 | + * @return EE_Addon |
|
| 1014 | + * @throws InvalidArgumentException |
|
| 1015 | + * @throws InvalidInterfaceException |
|
| 1016 | + * @throws InvalidDataTypeException |
|
| 1017 | + * @throws ReflectionException |
|
| 1018 | + * @throws EE_Error |
|
| 1019 | + */ |
|
| 1020 | + private static function _load_and_init_addon_class($addon_name) |
|
| 1021 | + { |
|
| 1022 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 1023 | + $addon = $loader->getShared( |
|
| 1024 | + self::$_settings[ $addon_name ]['class_name'], |
|
| 1025 | + array('EE_Registry::create(addon)' => true) |
|
| 1026 | + ); |
|
| 1027 | + // setter inject dep map if required |
|
| 1028 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 1029 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 1030 | + } |
|
| 1031 | + // setter inject domain if required |
|
| 1032 | + if ($addon instanceof RequiresDomainInterface |
|
| 1033 | + && $addon->domain() === null |
|
| 1034 | + ) { |
|
| 1035 | + // using supplied Domain object |
|
| 1036 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1037 | + ? self::$_settings[ $addon_name ]['domain'] |
|
| 1038 | + : null; |
|
| 1039 | + // or construct one using Domain FQCN |
|
| 1040 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1041 | + $domain = $loader->getShared( |
|
| 1042 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1043 | + array( |
|
| 1044 | + new EventEspresso\core\domain\values\FilePath( |
|
| 1045 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1046 | + ), |
|
| 1047 | + EventEspresso\core\domain\values\Version::fromString( |
|
| 1048 | + self::$_settings[ $addon_name ]['version'] |
|
| 1049 | + ), |
|
| 1050 | + ) |
|
| 1051 | + ); |
|
| 1052 | + } |
|
| 1053 | + if ($domain instanceof DomainInterface) { |
|
| 1054 | + $addon->setDomain($domain); |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + $addon->set_name($addon_name); |
|
| 1058 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1059 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1060 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1061 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1062 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1063 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1064 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1065 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1066 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1067 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1068 | + // unfortunately this can't be hooked in upon construction, because we don't have |
|
| 1069 | + // the plugin mainfile's path upon construction. |
|
| 1070 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 1071 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 1072 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1073 | + add_action( |
|
| 1074 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1075 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1076 | + ); |
|
| 1077 | + } |
|
| 1078 | + return $addon; |
|
| 1079 | + } |
|
| 1080 | 1080 | |
| 1081 | 1081 | |
| 1082 | - /** |
|
| 1083 | - * load_pue_update - Update notifications |
|
| 1084 | - * |
|
| 1085 | - * @return void |
|
| 1086 | - * @throws InvalidArgumentException |
|
| 1087 | - * @throws InvalidDataTypeException |
|
| 1088 | - * @throws InvalidInterfaceException |
|
| 1089 | - */ |
|
| 1090 | - public static function load_pue_update() |
|
| 1091 | - { |
|
| 1092 | - // load PUE client |
|
| 1093 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1094 | - $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
| 1095 | - // cycle thru settings |
|
| 1096 | - foreach (self::$_settings as $settings) { |
|
| 1097 | - if (! empty($settings['pue_options'])) { |
|
| 1098 | - // initiate the class and start the plugin update engine! |
|
| 1099 | - new PluginUpdateEngineChecker( |
|
| 1100 | - // host file URL |
|
| 1101 | - $license_server, |
|
| 1102 | - // plugin slug(s) |
|
| 1103 | - array( |
|
| 1104 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1105 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1106 | - ), |
|
| 1107 | - // options |
|
| 1108 | - array( |
|
| 1109 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1110 | - 'lang_domain' => 'event_espresso', |
|
| 1111 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1112 | - 'option_key' => 'ee_site_license_key', |
|
| 1113 | - 'options_page_slug' => 'event_espresso', |
|
| 1114 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1115 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1116 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1117 | - ) |
|
| 1118 | - ); |
|
| 1119 | - } |
|
| 1120 | - } |
|
| 1121 | - } |
|
| 1082 | + /** |
|
| 1083 | + * load_pue_update - Update notifications |
|
| 1084 | + * |
|
| 1085 | + * @return void |
|
| 1086 | + * @throws InvalidArgumentException |
|
| 1087 | + * @throws InvalidDataTypeException |
|
| 1088 | + * @throws InvalidInterfaceException |
|
| 1089 | + */ |
|
| 1090 | + public static function load_pue_update() |
|
| 1091 | + { |
|
| 1092 | + // load PUE client |
|
| 1093 | + require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1094 | + $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
| 1095 | + // cycle thru settings |
|
| 1096 | + foreach (self::$_settings as $settings) { |
|
| 1097 | + if (! empty($settings['pue_options'])) { |
|
| 1098 | + // initiate the class and start the plugin update engine! |
|
| 1099 | + new PluginUpdateEngineChecker( |
|
| 1100 | + // host file URL |
|
| 1101 | + $license_server, |
|
| 1102 | + // plugin slug(s) |
|
| 1103 | + array( |
|
| 1104 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1105 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1106 | + ), |
|
| 1107 | + // options |
|
| 1108 | + array( |
|
| 1109 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1110 | + 'lang_domain' => 'event_espresso', |
|
| 1111 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1112 | + 'option_key' => 'ee_site_license_key', |
|
| 1113 | + 'options_page_slug' => 'event_espresso', |
|
| 1114 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1115 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1116 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1117 | + ) |
|
| 1118 | + ); |
|
| 1119 | + } |
|
| 1120 | + } |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | 1123 | |
| 1124 | - /** |
|
| 1125 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1126 | - * |
|
| 1127 | - * @since 4.4.0 |
|
| 1128 | - * @return void |
|
| 1129 | - * @throws EE_Error |
|
| 1130 | - */ |
|
| 1131 | - public static function register_message_types() |
|
| 1132 | - { |
|
| 1133 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 1134 | - if (! empty($settings['message_types'])) { |
|
| 1135 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1136 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1124 | + /** |
|
| 1125 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1126 | + * |
|
| 1127 | + * @since 4.4.0 |
|
| 1128 | + * @return void |
|
| 1129 | + * @throws EE_Error |
|
| 1130 | + */ |
|
| 1131 | + public static function register_message_types() |
|
| 1132 | + { |
|
| 1133 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 1134 | + if (! empty($settings['message_types'])) { |
|
| 1135 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1136 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | 1141 | |
| 1142 | 1142 | |
| 1143 | - /** |
|
| 1144 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1145 | - * |
|
| 1146 | - * @since 4.3.0 |
|
| 1147 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1148 | - * @throws DomainException |
|
| 1149 | - * @throws EE_Error |
|
| 1150 | - * @throws InvalidArgumentException |
|
| 1151 | - * @throws InvalidDataTypeException |
|
| 1152 | - * @throws InvalidInterfaceException |
|
| 1153 | - */ |
|
| 1154 | - public static function deregister($addon_name = null) |
|
| 1155 | - { |
|
| 1156 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1157 | - try { |
|
| 1158 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1159 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1160 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1161 | - // setup DMS |
|
| 1162 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1163 | - } |
|
| 1164 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1165 | - // register admin page |
|
| 1166 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1167 | - } |
|
| 1168 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1169 | - // add to list of modules to be registered |
|
| 1170 | - EE_Register_Module::deregister($addon_name); |
|
| 1171 | - } |
|
| 1172 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1173 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1174 | - ) { |
|
| 1175 | - // add to list of shortcodes to be registered |
|
| 1176 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1177 | - } |
|
| 1178 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1179 | - // if config_class present let's register config. |
|
| 1180 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1181 | - } |
|
| 1182 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1183 | - // add to list of widgets to be registered |
|
| 1184 | - EE_Register_Widget::deregister($addon_name); |
|
| 1185 | - } |
|
| 1186 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1187 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1188 | - ) { |
|
| 1189 | - // add to list of shortcodes to be registered |
|
| 1190 | - EE_Register_Model::deregister($addon_name); |
|
| 1191 | - } |
|
| 1192 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1193 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1194 | - ) { |
|
| 1195 | - // add to list of shortcodes to be registered |
|
| 1196 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1197 | - } |
|
| 1198 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1199 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1200 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1201 | - } |
|
| 1202 | - } |
|
| 1203 | - // deregister capabilities for addon |
|
| 1204 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1205 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1206 | - ) { |
|
| 1207 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1208 | - } |
|
| 1209 | - // deregister custom_post_types for addon |
|
| 1210 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1211 | - EE_Register_CPT::deregister($addon_name); |
|
| 1212 | - } |
|
| 1213 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1214 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1215 | - } |
|
| 1216 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1217 | - if ($addon instanceof EE_Addon) { |
|
| 1218 | - remove_action( |
|
| 1219 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1220 | - array($addon, 'deactivation') |
|
| 1221 | - ); |
|
| 1222 | - remove_action( |
|
| 1223 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1224 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1225 | - ); |
|
| 1226 | - // remove `after_registration` call |
|
| 1227 | - remove_action( |
|
| 1228 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1229 | - array($addon, 'after_registration'), |
|
| 1230 | - 999 |
|
| 1231 | - ); |
|
| 1232 | - } |
|
| 1233 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1234 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1235 | - // the add-on was not yet registered in the registry, |
|
| 1236 | - // so RegistryContainer::__get() throws this exception. |
|
| 1237 | - // also no need to worry about this or log it, |
|
| 1238 | - // it's ok to deregister an add-on before its registered in the registry |
|
| 1239 | - } catch (Exception $e) { |
|
| 1240 | - new ExceptionLogger($e); |
|
| 1241 | - } |
|
| 1242 | - unset(self::$_settings[ $addon_name ]); |
|
| 1243 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1244 | - } |
|
| 1245 | - } |
|
| 1143 | + /** |
|
| 1144 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1145 | + * |
|
| 1146 | + * @since 4.3.0 |
|
| 1147 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1148 | + * @throws DomainException |
|
| 1149 | + * @throws EE_Error |
|
| 1150 | + * @throws InvalidArgumentException |
|
| 1151 | + * @throws InvalidDataTypeException |
|
| 1152 | + * @throws InvalidInterfaceException |
|
| 1153 | + */ |
|
| 1154 | + public static function deregister($addon_name = null) |
|
| 1155 | + { |
|
| 1156 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1157 | + try { |
|
| 1158 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1159 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1160 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1161 | + // setup DMS |
|
| 1162 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1163 | + } |
|
| 1164 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1165 | + // register admin page |
|
| 1166 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1167 | + } |
|
| 1168 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1169 | + // add to list of modules to be registered |
|
| 1170 | + EE_Register_Module::deregister($addon_name); |
|
| 1171 | + } |
|
| 1172 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1173 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1174 | + ) { |
|
| 1175 | + // add to list of shortcodes to be registered |
|
| 1176 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1177 | + } |
|
| 1178 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1179 | + // if config_class present let's register config. |
|
| 1180 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1181 | + } |
|
| 1182 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1183 | + // add to list of widgets to be registered |
|
| 1184 | + EE_Register_Widget::deregister($addon_name); |
|
| 1185 | + } |
|
| 1186 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1187 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1188 | + ) { |
|
| 1189 | + // add to list of shortcodes to be registered |
|
| 1190 | + EE_Register_Model::deregister($addon_name); |
|
| 1191 | + } |
|
| 1192 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1193 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1194 | + ) { |
|
| 1195 | + // add to list of shortcodes to be registered |
|
| 1196 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1197 | + } |
|
| 1198 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1199 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1200 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1201 | + } |
|
| 1202 | + } |
|
| 1203 | + // deregister capabilities for addon |
|
| 1204 | + if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1205 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1206 | + ) { |
|
| 1207 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1208 | + } |
|
| 1209 | + // deregister custom_post_types for addon |
|
| 1210 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1211 | + EE_Register_CPT::deregister($addon_name); |
|
| 1212 | + } |
|
| 1213 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1214 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1215 | + } |
|
| 1216 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1217 | + if ($addon instanceof EE_Addon) { |
|
| 1218 | + remove_action( |
|
| 1219 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1220 | + array($addon, 'deactivation') |
|
| 1221 | + ); |
|
| 1222 | + remove_action( |
|
| 1223 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1224 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1225 | + ); |
|
| 1226 | + // remove `after_registration` call |
|
| 1227 | + remove_action( |
|
| 1228 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1229 | + array($addon, 'after_registration'), |
|
| 1230 | + 999 |
|
| 1231 | + ); |
|
| 1232 | + } |
|
| 1233 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1234 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1235 | + // the add-on was not yet registered in the registry, |
|
| 1236 | + // so RegistryContainer::__get() throws this exception. |
|
| 1237 | + // also no need to worry about this or log it, |
|
| 1238 | + // it's ok to deregister an add-on before its registered in the registry |
|
| 1239 | + } catch (Exception $e) { |
|
| 1240 | + new ExceptionLogger($e); |
|
| 1241 | + } |
|
| 1242 | + unset(self::$_settings[ $addon_name ]); |
|
| 1243 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1244 | + } |
|
| 1245 | + } |
|
| 1246 | 1246 | } |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 70 | 70 | $version_parts = explode('.', $min_core_version); |
| 71 | 71 | // check they specified the micro version (after 2nd period) |
| 72 | - if (! isset($version_parts[2])) { |
|
| 72 | + if ( ! isset($version_parts[2])) { |
|
| 73 | 73 | $version_parts[2] = '0'; |
| 74 | 74 | } |
| 75 | 75 | // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 76 | 76 | // soon we can assume that's 'rc', but this current version is 'alpha' |
| 77 | - if (! isset($version_parts[3])) { |
|
| 77 | + if ( ! isset($version_parts[3])) { |
|
| 78 | 78 | $version_parts[3] = 'dev'; |
| 79 | 79 | } |
| 80 | - if (! isset($version_parts[4])) { |
|
| 80 | + if ( ! isset($version_parts[4])) { |
|
| 81 | 81 | $version_parts[4] = '000'; |
| 82 | 82 | } |
| 83 | 83 | return implode('.', $version_parts); |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | // setup PUE |
| 265 | 265 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 266 | 266 | // does this addon work with this version of core or WordPress ? |
| 267 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 267 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 268 | 268 | return; |
| 269 | 269 | } |
| 270 | 270 | // register namespaces |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | ) |
| 329 | 329 | ); |
| 330 | 330 | } |
| 331 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 331 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 332 | 332 | throw new EE_Error( |
| 333 | 333 | sprintf( |
| 334 | 334 | __( |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | ); |
| 341 | 341 | } |
| 342 | 342 | // check that addon has not already been registered with that name |
| 343 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 343 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 344 | 344 | throw new EE_Error( |
| 345 | 345 | sprintf( |
| 346 | 346 | __( |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 373 | 373 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 374 | 374 | ? $class_name |
| 375 | - : 'EE_' . $class_name; |
|
| 375 | + : 'EE_'.$class_name; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
@@ -539,9 +539,9 @@ discard block |
||
| 539 | 539 | global $wp_version; |
| 540 | 540 | $incompatibility_message = ''; |
| 541 | 541 | // check whether this addon version is compatible with EE core |
| 542 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 542 | + if (isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 543 | 543 | && ! self::_meets_min_core_version_requirement( |
| 544 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 544 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 545 | 545 | $addon_settings['version'] |
| 546 | 546 | ) |
| 547 | 547 | ) { |
@@ -552,11 +552,11 @@ discard block |
||
| 552 | 552 | ), |
| 553 | 553 | $addon_name, |
| 554 | 554 | '<br />', |
| 555 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 555 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 556 | 556 | '<span style="font-weight: bold; color: #D54E21;">', |
| 557 | 557 | '</span><br />' |
| 558 | 558 | ); |
| 559 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 559 | + } elseif ( ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 560 | 560 | ) { |
| 561 | 561 | $incompatibility_message = sprintf( |
| 562 | 562 | __( |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | '</span><br />' |
| 584 | 584 | ); |
| 585 | 585 | } |
| 586 | - if (! empty($incompatibility_message)) { |
|
| 586 | + if ( ! empty($incompatibility_message)) { |
|
| 587 | 587 | // remove 'activate' from the REQUEST |
| 588 | 588 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 589 | 589 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -611,11 +611,11 @@ discard block |
||
| 611 | 611 | */ |
| 612 | 612 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 613 | 613 | { |
| 614 | - if (! empty($setup_args['pue_options'])) { |
|
| 615 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 614 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 615 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 616 | 616 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 617 | 617 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
| 618 | - : 'espresso_' . strtolower($class_name), |
|
| 618 | + : 'espresso_'.strtolower($class_name), |
|
| 619 | 619 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 620 | 620 | ? (string) $setup_args['pue_options']['plugin_basename'] |
| 621 | 621 | : plugin_basename($setup_args['main_file_path']), |
@@ -674,12 +674,12 @@ discard block |
||
| 674 | 674 | // (as the newly-activated addon wasn't around the first time addons were registered). |
| 675 | 675 | // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 676 | 676 | // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 677 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 678 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 679 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 677 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 678 | + || (isset(self::$_settings[$addon_name]) |
|
| 679 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 680 | 680 | ) |
| 681 | 681 | ) { |
| 682 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 682 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 683 | 683 | $addon = self::_load_and_init_addon_class($addon_name); |
| 684 | 684 | $addon->set_activation_indicator_option(); |
| 685 | 685 | // dont bother setting up the rest of the addon. |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | return true; |
| 689 | 689 | } |
| 690 | 690 | // make sure this was called in the right place! |
| 691 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 691 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 692 | 692 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
| 693 | 693 | ) { |
| 694 | 694 | EE_Error::doing_it_wrong( |
@@ -704,10 +704,10 @@ discard block |
||
| 704 | 704 | ); |
| 705 | 705 | } |
| 706 | 706 | // make sure addon settings are set correctly without overwriting anything existing |
| 707 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 708 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 707 | + if (isset(self::$_settings[$addon_name])) { |
|
| 708 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 709 | 709 | } else { |
| 710 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 710 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 711 | 711 | } |
| 712 | 712 | return false; |
| 713 | 713 | } |
@@ -720,13 +720,13 @@ discard block |
||
| 720 | 720 | */ |
| 721 | 721 | private static function _setup_autoloaders($addon_name) |
| 722 | 722 | { |
| 723 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 723 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 724 | 724 | // setup autoloader for single file |
| 725 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 725 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 726 | 726 | } |
| 727 | 727 | // setup autoloaders for folders |
| 728 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 729 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 728 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 729 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 730 | 730 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 731 | 731 | } |
| 732 | 732 | } |
@@ -743,26 +743,26 @@ discard block |
||
| 743 | 743 | private static function _register_models_and_extensions($addon_name) |
| 744 | 744 | { |
| 745 | 745 | // register new models |
| 746 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 747 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 746 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 747 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 748 | 748 | ) { |
| 749 | 749 | EE_Register_Model::register( |
| 750 | 750 | $addon_name, |
| 751 | 751 | array( |
| 752 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 753 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 752 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 753 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 754 | 754 | ) |
| 755 | 755 | ); |
| 756 | 756 | } |
| 757 | 757 | // register model extensions |
| 758 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 759 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 758 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 759 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 760 | 760 | ) { |
| 761 | 761 | EE_Register_Model_Extensions::register( |
| 762 | 762 | $addon_name, |
| 763 | 763 | array( |
| 764 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 765 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 764 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 765 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 766 | 766 | ) |
| 767 | 767 | ); |
| 768 | 768 | } |
@@ -777,10 +777,10 @@ discard block |
||
| 777 | 777 | private static function _register_data_migration_scripts($addon_name) |
| 778 | 778 | { |
| 779 | 779 | // setup DMS |
| 780 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 780 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 781 | 781 | EE_Register_Data_Migration_Scripts::register( |
| 782 | 782 | $addon_name, |
| 783 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 783 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 784 | 784 | ); |
| 785 | 785 | } |
| 786 | 786 | } |
@@ -794,12 +794,12 @@ discard block |
||
| 794 | 794 | private static function _register_config($addon_name) |
| 795 | 795 | { |
| 796 | 796 | // if config_class is present let's register config. |
| 797 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 797 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 798 | 798 | EE_Register_Config::register( |
| 799 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 799 | + self::$_settings[$addon_name]['config_class'], |
|
| 800 | 800 | array( |
| 801 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 802 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 801 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 802 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 803 | 803 | ) |
| 804 | 804 | ); |
| 805 | 805 | } |
@@ -813,10 +813,10 @@ discard block |
||
| 813 | 813 | */ |
| 814 | 814 | private static function _register_admin_pages($addon_name) |
| 815 | 815 | { |
| 816 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 816 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 817 | 817 | EE_Register_Admin_Page::register( |
| 818 | 818 | $addon_name, |
| 819 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 819 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 820 | 820 | ); |
| 821 | 821 | } |
| 822 | 822 | } |
@@ -829,10 +829,10 @@ discard block |
||
| 829 | 829 | */ |
| 830 | 830 | private static function _register_modules($addon_name) |
| 831 | 831 | { |
| 832 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 832 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 833 | 833 | EE_Register_Module::register( |
| 834 | 834 | $addon_name, |
| 835 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 835 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 836 | 836 | ); |
| 837 | 837 | } |
| 838 | 838 | } |
@@ -845,17 +845,17 @@ discard block |
||
| 845 | 845 | */ |
| 846 | 846 | private static function _register_shortcodes($addon_name) |
| 847 | 847 | { |
| 848 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 849 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 848 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 849 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 850 | 850 | ) { |
| 851 | 851 | EE_Register_Shortcode::register( |
| 852 | 852 | $addon_name, |
| 853 | 853 | array( |
| 854 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 855 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 854 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 855 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 856 | 856 | : array(), |
| 857 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 858 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 857 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 858 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 859 | 859 | : array(), |
| 860 | 860 | ) |
| 861 | 861 | ); |
@@ -870,10 +870,10 @@ discard block |
||
| 870 | 870 | */ |
| 871 | 871 | private static function _register_widgets($addon_name) |
| 872 | 872 | { |
| 873 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 873 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 874 | 874 | EE_Register_Widget::register( |
| 875 | 875 | $addon_name, |
| 876 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 876 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 877 | 877 | ); |
| 878 | 878 | } |
| 879 | 879 | } |
@@ -886,12 +886,12 @@ discard block |
||
| 886 | 886 | */ |
| 887 | 887 | private static function _register_capabilities($addon_name) |
| 888 | 888 | { |
| 889 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 889 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 890 | 890 | EE_Register_Capabilities::register( |
| 891 | 891 | $addon_name, |
| 892 | 892 | array( |
| 893 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 894 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 893 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 894 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 895 | 895 | ) |
| 896 | 896 | ); |
| 897 | 897 | } |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | */ |
| 906 | 906 | private static function _register_message_types($addon_name) |
| 907 | 907 | { |
| 908 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 908 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 909 | 909 | add_action( |
| 910 | 910 | 'EE_Brewing_Regular___messages_caf', |
| 911 | 911 | array('EE_Register_Addon', 'register_message_types') |
@@ -921,15 +921,15 @@ discard block |
||
| 921 | 921 | */ |
| 922 | 922 | private static function _register_custom_post_types($addon_name) |
| 923 | 923 | { |
| 924 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 925 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 924 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 925 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 926 | 926 | ) { |
| 927 | 927 | EE_Register_CPT::register( |
| 928 | 928 | $addon_name, |
| 929 | 929 | array( |
| 930 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 931 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 932 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 930 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 931 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 932 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 933 | 933 | ) |
| 934 | 934 | ); |
| 935 | 935 | } |
@@ -947,10 +947,10 @@ discard block |
||
| 947 | 947 | */ |
| 948 | 948 | private static function _register_payment_methods($addon_name) |
| 949 | 949 | { |
| 950 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 950 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 951 | 951 | EE_Register_Payment_Method::register( |
| 952 | 952 | $addon_name, |
| 953 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 953 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 954 | 954 | ); |
| 955 | 955 | } |
| 956 | 956 | } |
@@ -967,10 +967,10 @@ discard block |
||
| 967 | 967 | */ |
| 968 | 968 | private static function registerPrivacyPolicies($addon_name) |
| 969 | 969 | { |
| 970 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 970 | + if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) { |
|
| 971 | 971 | EE_Register_Privacy_Policy::register( |
| 972 | 972 | $addon_name, |
| 973 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 973 | + self::$_settings[$addon_name]['privacy_policies'] |
|
| 974 | 974 | ); |
| 975 | 975 | } |
| 976 | 976 | } |
@@ -982,10 +982,10 @@ discard block |
||
| 982 | 982 | */ |
| 983 | 983 | private static function registerPersonalDataExporters($addon_name) |
| 984 | 984 | { |
| 985 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 985 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) { |
|
| 986 | 986 | EE_Register_Personal_Data_Eraser::register( |
| 987 | 987 | $addon_name, |
| 988 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 988 | + self::$_settings[$addon_name]['personal_data_exporters'] |
|
| 989 | 989 | ); |
| 990 | 990 | } |
| 991 | 991 | } |
@@ -997,10 +997,10 @@ discard block |
||
| 997 | 997 | */ |
| 998 | 998 | private static function registerPersonalDataErasers($addon_name) |
| 999 | 999 | { |
| 1000 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1000 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) { |
|
| 1001 | 1001 | EE_Register_Personal_Data_Eraser::register( |
| 1002 | 1002 | $addon_name, |
| 1003 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1003 | + self::$_settings[$addon_name]['personal_data_erasers'] |
|
| 1004 | 1004 | ); |
| 1005 | 1005 | } |
| 1006 | 1006 | } |
@@ -1021,7 +1021,7 @@ discard block |
||
| 1021 | 1021 | { |
| 1022 | 1022 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
| 1023 | 1023 | $addon = $loader->getShared( |
| 1024 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 1024 | + self::$_settings[$addon_name]['class_name'], |
|
| 1025 | 1025 | array('EE_Registry::create(addon)' => true) |
| 1026 | 1026 | ); |
| 1027 | 1027 | // setter inject dep map if required |
@@ -1033,19 +1033,19 @@ discard block |
||
| 1033 | 1033 | && $addon->domain() === null |
| 1034 | 1034 | ) { |
| 1035 | 1035 | // using supplied Domain object |
| 1036 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1037 | - ? self::$_settings[ $addon_name ]['domain'] |
|
| 1036 | + $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface |
|
| 1037 | + ? self::$_settings[$addon_name]['domain'] |
|
| 1038 | 1038 | : null; |
| 1039 | 1039 | // or construct one using Domain FQCN |
| 1040 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1040 | + if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') { |
|
| 1041 | 1041 | $domain = $loader->getShared( |
| 1042 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1042 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
| 1043 | 1043 | array( |
| 1044 | 1044 | new EventEspresso\core\domain\values\FilePath( |
| 1045 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1045 | + self::$_settings[$addon_name]['main_file_path'] |
|
| 1046 | 1046 | ), |
| 1047 | 1047 | EventEspresso\core\domain\values\Version::fromString( |
| 1048 | - self::$_settings[ $addon_name ]['version'] |
|
| 1048 | + self::$_settings[$addon_name]['version'] |
|
| 1049 | 1049 | ), |
| 1050 | 1050 | ) |
| 1051 | 1051 | ); |
@@ -1055,24 +1055,24 @@ discard block |
||
| 1055 | 1055 | } |
| 1056 | 1056 | } |
| 1057 | 1057 | $addon->set_name($addon_name); |
| 1058 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1059 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1060 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1061 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1062 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1063 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1064 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1065 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1066 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1067 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1058 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 1059 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 1060 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 1061 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 1062 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 1063 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 1064 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 1065 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 1066 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 1067 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 1068 | 1068 | // unfortunately this can't be hooked in upon construction, because we don't have |
| 1069 | 1069 | // the plugin mainfile's path upon construction. |
| 1070 | 1070 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 1071 | 1071 | // call any additional admin_callback functions during load_admin_controller hook |
| 1072 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1072 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 1073 | 1073 | add_action( |
| 1074 | 1074 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 1075 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1075 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 1076 | 1076 | ); |
| 1077 | 1077 | } |
| 1078 | 1078 | return $addon; |
@@ -1090,11 +1090,11 @@ discard block |
||
| 1090 | 1090 | public static function load_pue_update() |
| 1091 | 1091 | { |
| 1092 | 1092 | // load PUE client |
| 1093 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1093 | + require_once EE_THIRD_PARTY.'pue/pue-client.php'; |
|
| 1094 | 1094 | $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
| 1095 | 1095 | // cycle thru settings |
| 1096 | 1096 | foreach (self::$_settings as $settings) { |
| 1097 | - if (! empty($settings['pue_options'])) { |
|
| 1097 | + if ( ! empty($settings['pue_options'])) { |
|
| 1098 | 1098 | // initiate the class and start the plugin update engine! |
| 1099 | 1099 | new PluginUpdateEngineChecker( |
| 1100 | 1100 | // host file URL |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | // plugin slug(s) |
| 1103 | 1103 | array( |
| 1104 | 1104 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 1105 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1105 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 1106 | 1106 | ), |
| 1107 | 1107 | // options |
| 1108 | 1108 | array( |
@@ -1131,7 +1131,7 @@ discard block |
||
| 1131 | 1131 | public static function register_message_types() |
| 1132 | 1132 | { |
| 1133 | 1133 | foreach (self::$_settings as $addon_name => $settings) { |
| 1134 | - if (! empty($settings['message_types'])) { |
|
| 1134 | + if ( ! empty($settings['message_types'])) { |
|
| 1135 | 1135 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
| 1136 | 1136 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 1137 | 1137 | } |
@@ -1153,70 +1153,70 @@ discard block |
||
| 1153 | 1153 | */ |
| 1154 | 1154 | public static function deregister($addon_name = null) |
| 1155 | 1155 | { |
| 1156 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1156 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
| 1157 | 1157 | try { |
| 1158 | 1158 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1159 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1160 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1159 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1160 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1161 | 1161 | // setup DMS |
| 1162 | 1162 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1163 | 1163 | } |
| 1164 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1164 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1165 | 1165 | // register admin page |
| 1166 | 1166 | EE_Register_Admin_Page::deregister($addon_name); |
| 1167 | 1167 | } |
| 1168 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1168 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1169 | 1169 | // add to list of modules to be registered |
| 1170 | 1170 | EE_Register_Module::deregister($addon_name); |
| 1171 | 1171 | } |
| 1172 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1173 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1172 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1173 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1174 | 1174 | ) { |
| 1175 | 1175 | // add to list of shortcodes to be registered |
| 1176 | 1176 | EE_Register_Shortcode::deregister($addon_name); |
| 1177 | 1177 | } |
| 1178 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1178 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1179 | 1179 | // if config_class present let's register config. |
| 1180 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1180 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1181 | 1181 | } |
| 1182 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1182 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1183 | 1183 | // add to list of widgets to be registered |
| 1184 | 1184 | EE_Register_Widget::deregister($addon_name); |
| 1185 | 1185 | } |
| 1186 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1187 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1186 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1187 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1188 | 1188 | ) { |
| 1189 | 1189 | // add to list of shortcodes to be registered |
| 1190 | 1190 | EE_Register_Model::deregister($addon_name); |
| 1191 | 1191 | } |
| 1192 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1193 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1192 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1193 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1194 | 1194 | ) { |
| 1195 | 1195 | // add to list of shortcodes to be registered |
| 1196 | 1196 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1197 | 1197 | } |
| 1198 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1199 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1198 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1199 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1200 | 1200 | EE_Register_Message_Type::deregister($message_type); |
| 1201 | 1201 | } |
| 1202 | 1202 | } |
| 1203 | 1203 | // deregister capabilities for addon |
| 1204 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1205 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1204 | + if ( ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1205 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1206 | 1206 | ) { |
| 1207 | 1207 | EE_Register_Capabilities::deregister($addon_name); |
| 1208 | 1208 | } |
| 1209 | 1209 | // deregister custom_post_types for addon |
| 1210 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1210 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1211 | 1211 | EE_Register_CPT::deregister($addon_name); |
| 1212 | 1212 | } |
| 1213 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1213 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1214 | 1214 | EE_Register_Payment_Method::deregister($addon_name); |
| 1215 | 1215 | } |
| 1216 | 1216 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1217 | 1217 | if ($addon instanceof EE_Addon) { |
| 1218 | 1218 | remove_action( |
| 1219 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1219 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1220 | 1220 | array($addon, 'deactivation') |
| 1221 | 1221 | ); |
| 1222 | 1222 | remove_action( |
@@ -1239,7 +1239,7 @@ discard block |
||
| 1239 | 1239 | } catch (Exception $e) { |
| 1240 | 1240 | new ExceptionLogger($e); |
| 1241 | 1241 | } |
| 1242 | - unset(self::$_settings[ $addon_name ]); |
|
| 1242 | + unset(self::$_settings[$addon_name]); |
|
| 1243 | 1243 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
| 1244 | 1244 | } |
| 1245 | 1245 | } |