@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ), |
| 107 | 107 | ), |
| 108 | 108 | ); |
| 109 | - $this->_model_relations = array(); |
|
| 109 | + $this->_model_relations = array(); |
|
| 110 | 110 | foreach ($models_this_can_attach_to as $model) { |
| 111 | 111 | if ($model == 'WP_User') { |
| 112 | 112 | $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function gateway_log($message, $related_obj_id, $related_obj_type) |
| 165 | 165 | { |
| 166 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
| 166 | + if ( ! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
| 167 | 167 | throw new EE_Error( |
| 168 | 168 | sprintf( |
| 169 | 169 | esc_html__( |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | global $wpdb; |
| 213 | 213 | return $wpdb->query( |
| 214 | 214 | $wpdb->prepare( |
| 215 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 215 | + 'DELETE FROM '.$this->table().' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 216 | 216 | EEM_Change_Log::type_gateway, |
| 217 | 217 | $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
| 218 | 218 | ) |
@@ -13,246 +13,246 @@ |
||
| 13 | 13 | class EEM_Change_Log extends EEM_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * the related object was created log type |
|
| 18 | - */ |
|
| 19 | - const type_create = 'create'; |
|
| 20 | - /** |
|
| 21 | - * the related object was updated (changed, or soft-deleted) |
|
| 22 | - */ |
|
| 23 | - const type_update = 'update'; |
|
| 24 | - /** |
|
| 25 | - * the related object was deleted permanently |
|
| 26 | - */ |
|
| 27 | - const type_delete = 'delete'; |
|
| 28 | - /** |
|
| 29 | - * the related item had something worth noting happen on it, but |
|
| 30 | - * only for the purposes of debugging problems |
|
| 31 | - */ |
|
| 32 | - const type_debug = 'debug'; |
|
| 33 | - /** |
|
| 34 | - * the related item had an error occur on it |
|
| 35 | - */ |
|
| 36 | - const type_error = 'error'; |
|
| 37 | - /** |
|
| 38 | - * the related item is regarding some gateway interaction, like an IPN |
|
| 39 | - * or request to process a payment |
|
| 40 | - */ |
|
| 41 | - const type_gateway = 'gateway'; |
|
| 16 | + /** |
|
| 17 | + * the related object was created log type |
|
| 18 | + */ |
|
| 19 | + const type_create = 'create'; |
|
| 20 | + /** |
|
| 21 | + * the related object was updated (changed, or soft-deleted) |
|
| 22 | + */ |
|
| 23 | + const type_update = 'update'; |
|
| 24 | + /** |
|
| 25 | + * the related object was deleted permanently |
|
| 26 | + */ |
|
| 27 | + const type_delete = 'delete'; |
|
| 28 | + /** |
|
| 29 | + * the related item had something worth noting happen on it, but |
|
| 30 | + * only for the purposes of debugging problems |
|
| 31 | + */ |
|
| 32 | + const type_debug = 'debug'; |
|
| 33 | + /** |
|
| 34 | + * the related item had an error occur on it |
|
| 35 | + */ |
|
| 36 | + const type_error = 'error'; |
|
| 37 | + /** |
|
| 38 | + * the related item is regarding some gateway interaction, like an IPN |
|
| 39 | + * or request to process a payment |
|
| 40 | + */ |
|
| 41 | + const type_gateway = 'gateway'; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * private instance of the EEM_Change_Log object |
|
| 45 | - * |
|
| 46 | - * @access private |
|
| 47 | - * @var EEM_Change_Log $_instance |
|
| 48 | - */ |
|
| 49 | - protected static $_instance = null; |
|
| 43 | + /** |
|
| 44 | + * private instance of the EEM_Change_Log object |
|
| 45 | + * |
|
| 46 | + * @access private |
|
| 47 | + * @var EEM_Change_Log $_instance |
|
| 48 | + */ |
|
| 49 | + protected static $_instance = null; |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * constructor |
|
| 54 | - * |
|
| 55 | - * @access protected |
|
| 56 | - * @param null $timezone |
|
| 57 | - * @throws EE_Error |
|
| 58 | - */ |
|
| 59 | - protected function __construct($timezone = null) |
|
| 60 | - { |
|
| 61 | - global $current_user; |
|
| 62 | - $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
| 63 | - $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
| 64 | - $this->_tables = array( |
|
| 65 | - 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
| 66 | - ); |
|
| 67 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
| 68 | - $this->_fields = array( |
|
| 69 | - 'Log' => array( |
|
| 70 | - 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
| 71 | - 'LOG_time' => new EE_Datetime_Field( |
|
| 72 | - 'LOG_time', |
|
| 73 | - esc_html__("Log Time", 'event_espresso'), |
|
| 74 | - false, |
|
| 75 | - EE_Datetime_Field::now |
|
| 76 | - ), |
|
| 77 | - 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
| 78 | - 'OBJ_ID', |
|
| 79 | - esc_html__("Object ID (int or string)", 'event_espresso'), |
|
| 80 | - true, |
|
| 81 | - null, |
|
| 82 | - $models_this_can_attach_to |
|
| 83 | - ), |
|
| 84 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
| 85 | - 'OBJ_type', |
|
| 86 | - esc_html__("Object Type", 'event_espresso'), |
|
| 87 | - true, |
|
| 88 | - null, |
|
| 89 | - $models_this_can_attach_to |
|
| 90 | - ), |
|
| 91 | - 'LOG_type' => new EE_Plain_Text_Field( |
|
| 92 | - 'LOG_type', |
|
| 93 | - esc_html__("Type of log entry", "event_espresso"), |
|
| 94 | - false, |
|
| 95 | - self::type_debug |
|
| 96 | - ), |
|
| 97 | - 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
| 98 | - 'LOG_message', |
|
| 99 | - esc_html__("Log Message (body)", 'event_espresso'), |
|
| 100 | - true |
|
| 101 | - ), |
|
| 102 | - 'LOG_wp_user' => new EE_WP_User_Field( |
|
| 103 | - 'LOG_wp_user', |
|
| 104 | - esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
| 105 | - true |
|
| 106 | - ), |
|
| 107 | - ), |
|
| 108 | - ); |
|
| 109 | - $this->_model_relations = array(); |
|
| 110 | - foreach ($models_this_can_attach_to as $model) { |
|
| 111 | - if ($model == 'WP_User') { |
|
| 112 | - $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
| 113 | - } elseif ($model != 'Change_Log') { |
|
| 114 | - $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - //use completely custom caps for this |
|
| 118 | - $this->_cap_restriction_generators = false; |
|
| 119 | - //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
| 120 | - foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
| 121 | - $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] |
|
| 122 | - = new EE_Return_None_Where_Conditions(); |
|
| 123 | - } |
|
| 124 | - parent::__construct($timezone); |
|
| 125 | - } |
|
| 52 | + /** |
|
| 53 | + * constructor |
|
| 54 | + * |
|
| 55 | + * @access protected |
|
| 56 | + * @param null $timezone |
|
| 57 | + * @throws EE_Error |
|
| 58 | + */ |
|
| 59 | + protected function __construct($timezone = null) |
|
| 60 | + { |
|
| 61 | + global $current_user; |
|
| 62 | + $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
| 63 | + $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
| 64 | + $this->_tables = array( |
|
| 65 | + 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
| 66 | + ); |
|
| 67 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
| 68 | + $this->_fields = array( |
|
| 69 | + 'Log' => array( |
|
| 70 | + 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
| 71 | + 'LOG_time' => new EE_Datetime_Field( |
|
| 72 | + 'LOG_time', |
|
| 73 | + esc_html__("Log Time", 'event_espresso'), |
|
| 74 | + false, |
|
| 75 | + EE_Datetime_Field::now |
|
| 76 | + ), |
|
| 77 | + 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
| 78 | + 'OBJ_ID', |
|
| 79 | + esc_html__("Object ID (int or string)", 'event_espresso'), |
|
| 80 | + true, |
|
| 81 | + null, |
|
| 82 | + $models_this_can_attach_to |
|
| 83 | + ), |
|
| 84 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
| 85 | + 'OBJ_type', |
|
| 86 | + esc_html__("Object Type", 'event_espresso'), |
|
| 87 | + true, |
|
| 88 | + null, |
|
| 89 | + $models_this_can_attach_to |
|
| 90 | + ), |
|
| 91 | + 'LOG_type' => new EE_Plain_Text_Field( |
|
| 92 | + 'LOG_type', |
|
| 93 | + esc_html__("Type of log entry", "event_espresso"), |
|
| 94 | + false, |
|
| 95 | + self::type_debug |
|
| 96 | + ), |
|
| 97 | + 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
| 98 | + 'LOG_message', |
|
| 99 | + esc_html__("Log Message (body)", 'event_espresso'), |
|
| 100 | + true |
|
| 101 | + ), |
|
| 102 | + 'LOG_wp_user' => new EE_WP_User_Field( |
|
| 103 | + 'LOG_wp_user', |
|
| 104 | + esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
| 105 | + true |
|
| 106 | + ), |
|
| 107 | + ), |
|
| 108 | + ); |
|
| 109 | + $this->_model_relations = array(); |
|
| 110 | + foreach ($models_this_can_attach_to as $model) { |
|
| 111 | + if ($model == 'WP_User') { |
|
| 112 | + $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
| 113 | + } elseif ($model != 'Change_Log') { |
|
| 114 | + $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + //use completely custom caps for this |
|
| 118 | + $this->_cap_restriction_generators = false; |
|
| 119 | + //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
| 120 | + foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
| 121 | + $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] |
|
| 122 | + = new EE_Return_None_Where_Conditions(); |
|
| 123 | + } |
|
| 124 | + parent::__construct($timezone); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
| 129 | - * @param mixed $message array|string of the message you want to record |
|
| 130 | - * @param EE_Base_Class $related_model_obj |
|
| 131 | - * @return EE_Change_Log |
|
| 132 | - * @throws EE_Error |
|
| 133 | - */ |
|
| 134 | - public function log($log_type, $message, $related_model_obj) |
|
| 135 | - { |
|
| 136 | - if ($related_model_obj instanceof EE_Base_Class) { |
|
| 137 | - $obj_id = $related_model_obj->ID(); |
|
| 138 | - $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
| 139 | - } else { |
|
| 140 | - $obj_id = null; |
|
| 141 | - $obj_type = null; |
|
| 142 | - } |
|
| 143 | - /** @var EE_Change_Log $log */ |
|
| 144 | - $log = EE_Change_Log::new_instance(array( |
|
| 145 | - 'LOG_type' => $log_type, |
|
| 146 | - 'LOG_message' => $message, |
|
| 147 | - 'OBJ_ID' => $obj_id, |
|
| 148 | - 'OBJ_type' => $obj_type, |
|
| 149 | - )); |
|
| 150 | - $log->save(); |
|
| 151 | - return $log; |
|
| 152 | - } |
|
| 127 | + /** |
|
| 128 | + * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
| 129 | + * @param mixed $message array|string of the message you want to record |
|
| 130 | + * @param EE_Base_Class $related_model_obj |
|
| 131 | + * @return EE_Change_Log |
|
| 132 | + * @throws EE_Error |
|
| 133 | + */ |
|
| 134 | + public function log($log_type, $message, $related_model_obj) |
|
| 135 | + { |
|
| 136 | + if ($related_model_obj instanceof EE_Base_Class) { |
|
| 137 | + $obj_id = $related_model_obj->ID(); |
|
| 138 | + $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
| 139 | + } else { |
|
| 140 | + $obj_id = null; |
|
| 141 | + $obj_type = null; |
|
| 142 | + } |
|
| 143 | + /** @var EE_Change_Log $log */ |
|
| 144 | + $log = EE_Change_Log::new_instance(array( |
|
| 145 | + 'LOG_type' => $log_type, |
|
| 146 | + 'LOG_message' => $message, |
|
| 147 | + 'OBJ_ID' => $obj_id, |
|
| 148 | + 'OBJ_type' => $obj_type, |
|
| 149 | + )); |
|
| 150 | + $log->save(); |
|
| 151 | + return $log; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Adds a gateway log for the specified object, given its ID and type |
|
| 157 | - * |
|
| 158 | - * @param string $message |
|
| 159 | - * @param mixed $related_obj_id |
|
| 160 | - * @param string $related_obj_type |
|
| 161 | - * @throws EE_Error |
|
| 162 | - * @return EE_Change_Log |
|
| 163 | - */ |
|
| 164 | - public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
| 165 | - { |
|
| 166 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
| 167 | - throw new EE_Error( |
|
| 168 | - sprintf( |
|
| 169 | - esc_html__( |
|
| 170 | - "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
| 171 | - "event_espresso" |
|
| 172 | - ), |
|
| 173 | - $related_obj_type |
|
| 174 | - ) |
|
| 175 | - ); |
|
| 176 | - } |
|
| 177 | - /** @var EE_Change_Log $log */ |
|
| 178 | - $log = EE_Change_Log::new_instance(array( |
|
| 179 | - 'LOG_type' => EEM_Change_Log::type_gateway, |
|
| 180 | - 'LOG_message' => $message, |
|
| 181 | - 'OBJ_ID' => $related_obj_id, |
|
| 182 | - 'OBJ_type' => $related_obj_type, |
|
| 183 | - )); |
|
| 184 | - $log->save(); |
|
| 185 | - return $log; |
|
| 186 | - } |
|
| 155 | + /** |
|
| 156 | + * Adds a gateway log for the specified object, given its ID and type |
|
| 157 | + * |
|
| 158 | + * @param string $message |
|
| 159 | + * @param mixed $related_obj_id |
|
| 160 | + * @param string $related_obj_type |
|
| 161 | + * @throws EE_Error |
|
| 162 | + * @return EE_Change_Log |
|
| 163 | + */ |
|
| 164 | + public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
| 165 | + { |
|
| 166 | + if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
| 167 | + throw new EE_Error( |
|
| 168 | + sprintf( |
|
| 169 | + esc_html__( |
|
| 170 | + "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
| 171 | + "event_espresso" |
|
| 172 | + ), |
|
| 173 | + $related_obj_type |
|
| 174 | + ) |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | + /** @var EE_Change_Log $log */ |
|
| 178 | + $log = EE_Change_Log::new_instance(array( |
|
| 179 | + 'LOG_type' => EEM_Change_Log::type_gateway, |
|
| 180 | + 'LOG_message' => $message, |
|
| 181 | + 'OBJ_ID' => $related_obj_id, |
|
| 182 | + 'OBJ_type' => $related_obj_type, |
|
| 183 | + )); |
|
| 184 | + $log->save(); |
|
| 185 | + return $log; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
| 191 | - * |
|
| 192 | - * @param array $query_params @see EEM_Base::get_all |
|
| 193 | - * @return array of arrays |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - public function get_all_efficiently($query_params) |
|
| 197 | - { |
|
| 198 | - return $this->_get_all_wpdb_results($query_params); |
|
| 199 | - } |
|
| 189 | + /** |
|
| 190 | + * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
| 191 | + * |
|
| 192 | + * @param array $query_params @see EEM_Base::get_all |
|
| 193 | + * @return array of arrays |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + public function get_all_efficiently($query_params) |
|
| 197 | + { |
|
| 198 | + return $this->_get_all_wpdb_results($query_params); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
| 204 | - * models after this, they may be out-of-sync with the database |
|
| 205 | - * |
|
| 206 | - * @param DateTime $datetime |
|
| 207 | - * @return false|int |
|
| 208 | - * @throws EE_Error |
|
| 209 | - */ |
|
| 210 | - public function delete_gateway_logs_older_than(DateTime $datetime) |
|
| 211 | - { |
|
| 212 | - global $wpdb; |
|
| 213 | - return $wpdb->query( |
|
| 214 | - $wpdb->prepare( |
|
| 215 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 216 | - EEM_Change_Log::type_gateway, |
|
| 217 | - $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
| 218 | - ) |
|
| 219 | - ); |
|
| 220 | - } |
|
| 202 | + /** |
|
| 203 | + * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
| 204 | + * models after this, they may be out-of-sync with the database |
|
| 205 | + * |
|
| 206 | + * @param DateTime $datetime |
|
| 207 | + * @return false|int |
|
| 208 | + * @throws EE_Error |
|
| 209 | + */ |
|
| 210 | + public function delete_gateway_logs_older_than(DateTime $datetime) |
|
| 211 | + { |
|
| 212 | + global $wpdb; |
|
| 213 | + return $wpdb->query( |
|
| 214 | + $wpdb->prepare( |
|
| 215 | + 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 216 | + EEM_Change_Log::type_gateway, |
|
| 217 | + $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
| 218 | + ) |
|
| 219 | + ); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
| 225 | - * map vai the given filter. |
|
| 226 | - * |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - public static function get_pretty_label_map_for_registered_types() |
|
| 230 | - { |
|
| 231 | - return apply_filters( |
|
| 232 | - 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
| 233 | - array( |
|
| 234 | - self::type_create=> esc_html__("Create", "event_espresso"), |
|
| 235 | - self::type_update=> esc_html__("Update", "event_espresso"), |
|
| 236 | - self::type_delete => esc_html__("Delete", "event_espresso"), |
|
| 237 | - self::type_debug=> esc_html__("Debug", "event_espresso"), |
|
| 238 | - self::type_error=> esc_html__("Error", "event_espresso"), |
|
| 239 | - self::type_gateway=> esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - } |
|
| 223 | + /** |
|
| 224 | + * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
| 225 | + * map vai the given filter. |
|
| 226 | + * |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + public static function get_pretty_label_map_for_registered_types() |
|
| 230 | + { |
|
| 231 | + return apply_filters( |
|
| 232 | + 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
| 233 | + array( |
|
| 234 | + self::type_create=> esc_html__("Create", "event_espresso"), |
|
| 235 | + self::type_update=> esc_html__("Update", "event_espresso"), |
|
| 236 | + self::type_delete => esc_html__("Delete", "event_espresso"), |
|
| 237 | + self::type_debug=> esc_html__("Debug", "event_espresso"), |
|
| 238 | + self::type_error=> esc_html__("Error", "event_espresso"), |
|
| 239 | + self::type_gateway=> esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Return the pretty (localized) label for the given log type identifier. |
|
| 247 | - * @param string $type_identifier |
|
| 248 | - * @return string |
|
| 249 | - */ |
|
| 250 | - public static function get_pretty_label_for_type($type_identifier) |
|
| 251 | - { |
|
| 252 | - $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
| 253 | - //we fallback to the incoming type identifier if there is no localized label for it. |
|
| 254 | - return isset($type_identifier_map[$type_identifier]) |
|
| 255 | - ? $type_identifier_map[$type_identifier] |
|
| 256 | - : $type_identifier; |
|
| 257 | - } |
|
| 245 | + /** |
|
| 246 | + * Return the pretty (localized) label for the given log type identifier. |
|
| 247 | + * @param string $type_identifier |
|
| 248 | + * @return string |
|
| 249 | + */ |
|
| 250 | + public static function get_pretty_label_for_type($type_identifier) |
|
| 251 | + { |
|
| 252 | + $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
| 253 | + //we fallback to the incoming type identifier if there is no localized label for it. |
|
| 254 | + return isset($type_identifier_map[$type_identifier]) |
|
| 255 | + ? $type_identifier_map[$type_identifier] |
|
| 256 | + : $type_identifier; |
|
| 257 | + } |
|
| 258 | 258 | } |
@@ -13,216 +13,216 @@ |
||
| 13 | 13 | class EE_Change_Log extends EE_Base_Class |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param array $props_n_values incoming values |
|
| 18 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 19 | - * used.) |
|
| 20 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 21 | - * date_format and the second value is the time format |
|
| 22 | - * @return EE_Change_Log |
|
| 23 | - * @throws EE_Error |
|
| 24 | - */ |
|
| 25 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 26 | - { |
|
| 27 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 28 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param array $props_n_values incoming values from the database |
|
| 34 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 35 | - * the website will be used. |
|
| 36 | - * @return EE_Change_Log |
|
| 37 | - */ |
|
| 38 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 39 | - { |
|
| 40 | - return new self($props_n_values, true, $timezone); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Gets message |
|
| 45 | - * |
|
| 46 | - * @return mixed |
|
| 47 | - * @throws EE_Error |
|
| 48 | - */ |
|
| 49 | - public function message() |
|
| 50 | - { |
|
| 51 | - return $this->get('LOG_message'); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Sets message |
|
| 56 | - * |
|
| 57 | - * @param mixed $message |
|
| 58 | - * @throws EE_Error |
|
| 59 | - */ |
|
| 60 | - public function set_message($message) |
|
| 61 | - { |
|
| 62 | - $this->set('LOG_message', $message); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gets time |
|
| 67 | - * |
|
| 68 | - * @return string |
|
| 69 | - * @throws EE_Error |
|
| 70 | - */ |
|
| 71 | - public function time() |
|
| 72 | - { |
|
| 73 | - return $this->get('LOG_time'); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Sets time |
|
| 78 | - * |
|
| 79 | - * @param string $time |
|
| 80 | - * @throws EE_Error |
|
| 81 | - */ |
|
| 82 | - public function set_time($time) |
|
| 83 | - { |
|
| 84 | - $this->set('LOG_time', $time); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Gets log_type |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - * @throws EE_Error |
|
| 92 | - */ |
|
| 93 | - public function log_type() |
|
| 94 | - { |
|
| 95 | - return $this->get('LOG_type'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Return the localized log type label. |
|
| 101 | - * @return string |
|
| 102 | - * @throws EE_Error |
|
| 103 | - */ |
|
| 104 | - public function log_type_label() |
|
| 105 | - { |
|
| 106 | - return EEM_Change_Log::get_pretty_label_for_type($this->log_type()); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Sets log_type |
|
| 111 | - * |
|
| 112 | - * @param string $log_type |
|
| 113 | - * @throws EE_Error |
|
| 114 | - */ |
|
| 115 | - public function set_log_type($log_type) |
|
| 116 | - { |
|
| 117 | - $this->set('LOG_type', $log_type); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Gets type of the model object related to this log |
|
| 122 | - * |
|
| 123 | - * @return string |
|
| 124 | - * @throws EE_Error |
|
| 125 | - */ |
|
| 126 | - public function OBJ_type() |
|
| 127 | - { |
|
| 128 | - return $this->get('OBJ_type'); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Sets type |
|
| 133 | - * |
|
| 134 | - * @param string $type |
|
| 135 | - * @throws EE_Error |
|
| 136 | - */ |
|
| 137 | - public function set_OBJ_type($type) |
|
| 138 | - { |
|
| 139 | - $this->set('OBJ_type', $type); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Gets OBJ_ID (the ID of the item related to this log) |
|
| 144 | - * |
|
| 145 | - * @return mixed |
|
| 146 | - * @throws EE_Error |
|
| 147 | - */ |
|
| 148 | - public function OBJ_ID() |
|
| 149 | - { |
|
| 150 | - return $this->get('OBJ_ID'); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Sets OBJ_ID |
|
| 155 | - * |
|
| 156 | - * @param mixed $OBJ_ID |
|
| 157 | - * @throws EE_Error |
|
| 158 | - */ |
|
| 159 | - public function set_OBJ_ID($OBJ_ID) |
|
| 160 | - { |
|
| 161 | - $this->set('OBJ_ID', $OBJ_ID); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Gets wp_user |
|
| 166 | - * |
|
| 167 | - * @return int |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function wp_user() |
|
| 171 | - { |
|
| 172 | - return $this->get('LOG_wp_user'); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Sets wp_user |
|
| 177 | - * |
|
| 178 | - * @param int $wp_user_id |
|
| 179 | - * @throws EE_Error |
|
| 180 | - */ |
|
| 181 | - public function set_wp_user($wp_user_id) |
|
| 182 | - { |
|
| 183 | - $this->set('LOG_wp_user', $wp_user_id); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Gets the model object attached to this log |
|
| 188 | - * |
|
| 189 | - * @return EE_Base_Class |
|
| 190 | - * @throws EE_Error |
|
| 191 | - */ |
|
| 192 | - public function object() |
|
| 193 | - { |
|
| 194 | - $model_name_of_related_obj = $this->OBJ_type(); |
|
| 195 | - $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
|
| 196 | - if (! $is_model_name) { |
|
| 197 | - return null; |
|
| 198 | - } else { |
|
| 199 | - return $this->get_first_related($model_name_of_related_obj); |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using |
|
| 205 | - * _add_relation_to because you don't have to specify what type of model you're |
|
| 206 | - * associating it with |
|
| 207 | - * |
|
| 208 | - * @param EE_Base_Class $object |
|
| 209 | - * @param boolean $save |
|
| 210 | - * @return bool if $save=true, NULL is $save=false |
|
| 211 | - * @throws EE_Error |
|
| 212 | - */ |
|
| 213 | - public function set_object($object, $save = true) |
|
| 214 | - { |
|
| 215 | - if ($object instanceof EE_Base_Class) { |
|
| 216 | - $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
|
| 217 | - $this->set_OBJ_ID($object->ID()); |
|
| 218 | - } else { |
|
| 219 | - $this->set_OBJ_type(null); |
|
| 220 | - $this->set_OBJ_ID(null); |
|
| 221 | - } |
|
| 222 | - if ($save) { |
|
| 223 | - return $this->save(); |
|
| 224 | - } else { |
|
| 225 | - return null; |
|
| 226 | - } |
|
| 227 | - } |
|
| 16 | + /** |
|
| 17 | + * @param array $props_n_values incoming values |
|
| 18 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 19 | + * used.) |
|
| 20 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 21 | + * date_format and the second value is the time format |
|
| 22 | + * @return EE_Change_Log |
|
| 23 | + * @throws EE_Error |
|
| 24 | + */ |
|
| 25 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 26 | + { |
|
| 27 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 28 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param array $props_n_values incoming values from the database |
|
| 34 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 35 | + * the website will be used. |
|
| 36 | + * @return EE_Change_Log |
|
| 37 | + */ |
|
| 38 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 39 | + { |
|
| 40 | + return new self($props_n_values, true, $timezone); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Gets message |
|
| 45 | + * |
|
| 46 | + * @return mixed |
|
| 47 | + * @throws EE_Error |
|
| 48 | + */ |
|
| 49 | + public function message() |
|
| 50 | + { |
|
| 51 | + return $this->get('LOG_message'); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Sets message |
|
| 56 | + * |
|
| 57 | + * @param mixed $message |
|
| 58 | + * @throws EE_Error |
|
| 59 | + */ |
|
| 60 | + public function set_message($message) |
|
| 61 | + { |
|
| 62 | + $this->set('LOG_message', $message); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gets time |
|
| 67 | + * |
|
| 68 | + * @return string |
|
| 69 | + * @throws EE_Error |
|
| 70 | + */ |
|
| 71 | + public function time() |
|
| 72 | + { |
|
| 73 | + return $this->get('LOG_time'); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Sets time |
|
| 78 | + * |
|
| 79 | + * @param string $time |
|
| 80 | + * @throws EE_Error |
|
| 81 | + */ |
|
| 82 | + public function set_time($time) |
|
| 83 | + { |
|
| 84 | + $this->set('LOG_time', $time); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Gets log_type |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + * @throws EE_Error |
|
| 92 | + */ |
|
| 93 | + public function log_type() |
|
| 94 | + { |
|
| 95 | + return $this->get('LOG_type'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Return the localized log type label. |
|
| 101 | + * @return string |
|
| 102 | + * @throws EE_Error |
|
| 103 | + */ |
|
| 104 | + public function log_type_label() |
|
| 105 | + { |
|
| 106 | + return EEM_Change_Log::get_pretty_label_for_type($this->log_type()); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Sets log_type |
|
| 111 | + * |
|
| 112 | + * @param string $log_type |
|
| 113 | + * @throws EE_Error |
|
| 114 | + */ |
|
| 115 | + public function set_log_type($log_type) |
|
| 116 | + { |
|
| 117 | + $this->set('LOG_type', $log_type); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Gets type of the model object related to this log |
|
| 122 | + * |
|
| 123 | + * @return string |
|
| 124 | + * @throws EE_Error |
|
| 125 | + */ |
|
| 126 | + public function OBJ_type() |
|
| 127 | + { |
|
| 128 | + return $this->get('OBJ_type'); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Sets type |
|
| 133 | + * |
|
| 134 | + * @param string $type |
|
| 135 | + * @throws EE_Error |
|
| 136 | + */ |
|
| 137 | + public function set_OBJ_type($type) |
|
| 138 | + { |
|
| 139 | + $this->set('OBJ_type', $type); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Gets OBJ_ID (the ID of the item related to this log) |
|
| 144 | + * |
|
| 145 | + * @return mixed |
|
| 146 | + * @throws EE_Error |
|
| 147 | + */ |
|
| 148 | + public function OBJ_ID() |
|
| 149 | + { |
|
| 150 | + return $this->get('OBJ_ID'); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Sets OBJ_ID |
|
| 155 | + * |
|
| 156 | + * @param mixed $OBJ_ID |
|
| 157 | + * @throws EE_Error |
|
| 158 | + */ |
|
| 159 | + public function set_OBJ_ID($OBJ_ID) |
|
| 160 | + { |
|
| 161 | + $this->set('OBJ_ID', $OBJ_ID); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Gets wp_user |
|
| 166 | + * |
|
| 167 | + * @return int |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function wp_user() |
|
| 171 | + { |
|
| 172 | + return $this->get('LOG_wp_user'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Sets wp_user |
|
| 177 | + * |
|
| 178 | + * @param int $wp_user_id |
|
| 179 | + * @throws EE_Error |
|
| 180 | + */ |
|
| 181 | + public function set_wp_user($wp_user_id) |
|
| 182 | + { |
|
| 183 | + $this->set('LOG_wp_user', $wp_user_id); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Gets the model object attached to this log |
|
| 188 | + * |
|
| 189 | + * @return EE_Base_Class |
|
| 190 | + * @throws EE_Error |
|
| 191 | + */ |
|
| 192 | + public function object() |
|
| 193 | + { |
|
| 194 | + $model_name_of_related_obj = $this->OBJ_type(); |
|
| 195 | + $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
|
| 196 | + if (! $is_model_name) { |
|
| 197 | + return null; |
|
| 198 | + } else { |
|
| 199 | + return $this->get_first_related($model_name_of_related_obj); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using |
|
| 205 | + * _add_relation_to because you don't have to specify what type of model you're |
|
| 206 | + * associating it with |
|
| 207 | + * |
|
| 208 | + * @param EE_Base_Class $object |
|
| 209 | + * @param boolean $save |
|
| 210 | + * @return bool if $save=true, NULL is $save=false |
|
| 211 | + * @throws EE_Error |
|
| 212 | + */ |
|
| 213 | + public function set_object($object, $save = true) |
|
| 214 | + { |
|
| 215 | + if ($object instanceof EE_Base_Class) { |
|
| 216 | + $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
|
| 217 | + $this->set_OBJ_ID($object->ID()); |
|
| 218 | + } else { |
|
| 219 | + $this->set_OBJ_type(null); |
|
| 220 | + $this->set_OBJ_ID(null); |
|
| 221 | + } |
|
| 222 | + if ($save) { |
|
| 223 | + return $this->save(); |
|
| 224 | + } else { |
|
| 225 | + return null; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | } |
@@ -193,7 +193,7 @@ |
||
| 193 | 193 | { |
| 194 | 194 | $model_name_of_related_obj = $this->OBJ_type(); |
| 195 | 195 | $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
| 196 | - if (! $is_model_name) { |
|
| 196 | + if ( ! $is_model_name) { |
|
| 197 | 197 | return null; |
| 198 | 198 | } else { |
| 199 | 199 | return $this->get_first_related($model_name_of_related_obj); |
@@ -270,7 +270,7 @@ |
||
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | - * @param $module |
|
| 273 | + * @param string $module |
|
| 274 | 274 | * @throws EE_Error |
| 275 | 275 | * @throws ReflectionException |
| 276 | 276 | */ |
@@ -20,1466 +20,1466 @@ |
||
| 20 | 20 | class EE_Registry implements ResettableInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var EE_Registry $_instance |
|
| 25 | - */ |
|
| 26 | - private static $_instance; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var EE_Dependency_Map $_dependency_map |
|
| 30 | - */ |
|
| 31 | - protected $_dependency_map; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array $_class_abbreviations |
|
| 35 | - */ |
|
| 36 | - protected $_class_abbreviations = array(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var CommandBusInterface $BUS |
|
| 40 | - */ |
|
| 41 | - public $BUS; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Cart $CART |
|
| 45 | - */ |
|
| 46 | - public $CART; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var EE_Config $CFG |
|
| 50 | - */ |
|
| 51 | - public $CFG; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var EE_Network_Config $NET_CFG |
|
| 55 | - */ |
|
| 56 | - public $NET_CFG; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * StdClass object for storing library classes in |
|
| 60 | - * |
|
| 61 | - * @var StdClass $LIB |
|
| 62 | - */ |
|
| 63 | - public $LIB; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var EE_Request_Handler $REQ |
|
| 67 | - */ |
|
| 68 | - public $REQ; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var EE_Session $SSN |
|
| 72 | - */ |
|
| 73 | - public $SSN; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @since 4.5.0 |
|
| 77 | - * @var EE_Capabilities $CAP |
|
| 78 | - */ |
|
| 79 | - public $CAP; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @since 4.9.0 |
|
| 83 | - * @var EE_Message_Resource_Manager $MRM |
|
| 84 | - */ |
|
| 85 | - public $MRM; |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @var Registry $AssetsRegistry |
|
| 90 | - */ |
|
| 91 | - public $AssetsRegistry; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 95 | - * |
|
| 96 | - * @var EE_Addon[] $addons |
|
| 97 | - */ |
|
| 98 | - public $addons; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 102 | - * |
|
| 103 | - * @var EEM_Base[] $models |
|
| 104 | - */ |
|
| 105 | - public $models = array(); |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @var EED_Module[] $modules |
|
| 109 | - */ |
|
| 110 | - public $modules; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @var EES_Shortcode[] $shortcodes |
|
| 114 | - */ |
|
| 115 | - public $shortcodes; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @var WP_Widget[] $widgets |
|
| 119 | - */ |
|
| 120 | - public $widgets; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 124 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 125 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 126 | - * classnames (eg "EEM_Event") |
|
| 127 | - * |
|
| 128 | - * @var array $non_abstract_db_models |
|
| 129 | - */ |
|
| 130 | - public $non_abstract_db_models = array(); |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * internationalization for JS strings |
|
| 135 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 136 | - * in js file: var translatedString = eei18n.string_key; |
|
| 137 | - * |
|
| 138 | - * @var array $i18n_js_strings |
|
| 139 | - */ |
|
| 140 | - public static $i18n_js_strings = array(); |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * $main_file - path to espresso.php |
|
| 145 | - * |
|
| 146 | - * @var array $main_file |
|
| 147 | - */ |
|
| 148 | - public $main_file; |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * array of ReflectionClass objects where the key is the class name |
|
| 152 | - * |
|
| 153 | - * @var ReflectionClass[] $_reflectors |
|
| 154 | - */ |
|
| 155 | - public $_reflectors; |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 159 | - * |
|
| 160 | - * @var boolean $_cache_on |
|
| 161 | - */ |
|
| 162 | - protected $_cache_on = true; |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @singleton method used to instantiate class object |
|
| 168 | - * @param EE_Dependency_Map $dependency_map |
|
| 169 | - * @return EE_Registry instance |
|
| 170 | - */ |
|
| 171 | - public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 172 | - { |
|
| 173 | - // check if class object is instantiated |
|
| 174 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 175 | - self::$_instance = new self($dependency_map); |
|
| 176 | - } |
|
| 177 | - return self::$_instance; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * protected constructor to prevent direct creation |
|
| 184 | - * |
|
| 185 | - * @Constructor |
|
| 186 | - * @param EE_Dependency_Map $dependency_map |
|
| 187 | - */ |
|
| 188 | - protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 189 | - { |
|
| 190 | - $this->_dependency_map = $dependency_map; |
|
| 191 | - $this->LIB = new stdClass(); |
|
| 192 | - $this->addons = new stdClass(); |
|
| 193 | - $this->modules = new stdClass(); |
|
| 194 | - $this->shortcodes = new stdClass(); |
|
| 195 | - $this->widgets = new stdClass(); |
|
| 196 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * initialize |
|
| 203 | - * |
|
| 204 | - * @throws EE_Error |
|
| 205 | - * @throws ReflectionException |
|
| 206 | - */ |
|
| 207 | - public function initialize() |
|
| 208 | - { |
|
| 209 | - $this->_class_abbreviations = apply_filters( |
|
| 210 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 211 | - array( |
|
| 212 | - 'EE_Config' => 'CFG', |
|
| 213 | - 'EE_Session' => 'SSN', |
|
| 214 | - 'EE_Capabilities' => 'CAP', |
|
| 215 | - 'EE_Cart' => 'CART', |
|
| 216 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 217 | - 'EE_Request_Handler' => 'REQ', |
|
| 218 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 219 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 220 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 221 | - ) |
|
| 222 | - ); |
|
| 223 | - $this->load_core('Base', array(), true); |
|
| 224 | - // add our request and response objects to the cache |
|
| 225 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 226 | - $this->_set_cached_class( |
|
| 227 | - $request_loader(), |
|
| 228 | - 'EE_Request' |
|
| 229 | - ); |
|
| 230 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 231 | - $this->_set_cached_class( |
|
| 232 | - $response_loader(), |
|
| 233 | - 'EE_Response' |
|
| 234 | - ); |
|
| 235 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @return void |
|
| 242 | - */ |
|
| 243 | - public function init() |
|
| 244 | - { |
|
| 245 | - // Get current page protocol |
|
| 246 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 247 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 248 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 249 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * localize_i18n_js_strings |
|
| 256 | - * |
|
| 257 | - * @return string |
|
| 258 | - */ |
|
| 259 | - public static function localize_i18n_js_strings() |
|
| 260 | - { |
|
| 261 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 262 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 263 | - if (is_scalar($value)) { |
|
| 264 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * @param $module |
|
| 274 | - * @throws EE_Error |
|
| 275 | - * @throws ReflectionException |
|
| 276 | - */ |
|
| 277 | - public function add_module($module) |
|
| 278 | - { |
|
| 279 | - if ($module instanceof EED_Module) { |
|
| 280 | - $module_class = get_class($module); |
|
| 281 | - $this->modules->{$module_class} = $module; |
|
| 282 | - } else { |
|
| 283 | - if (! class_exists('EE_Module_Request_Router')) { |
|
| 284 | - $this->load_core('Module_Request_Router'); |
|
| 285 | - } |
|
| 286 | - EE_Module_Request_Router::module_factory($module); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @param string $module_name |
|
| 294 | - * @return mixed EED_Module | NULL |
|
| 295 | - */ |
|
| 296 | - public function get_module($module_name = '') |
|
| 297 | - { |
|
| 298 | - return isset($this->modules->{$module_name}) |
|
| 299 | - ? $this->modules->{$module_name} |
|
| 300 | - : null; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * loads core classes - must be singletons |
|
| 307 | - * |
|
| 308 | - * @param string $class_name - simple class name ie: session |
|
| 309 | - * @param mixed $arguments |
|
| 310 | - * @param bool $load_only |
|
| 311 | - * @return mixed |
|
| 312 | - * @throws EE_Error |
|
| 313 | - * @throws ReflectionException |
|
| 314 | - */ |
|
| 315 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 316 | - { |
|
| 317 | - $core_paths = apply_filters( |
|
| 318 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 319 | - array( |
|
| 320 | - EE_CORE, |
|
| 321 | - EE_ADMIN, |
|
| 322 | - EE_CPTS, |
|
| 323 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 324 | - EE_CORE . 'capabilities' . DS, |
|
| 325 | - EE_CORE . 'request_stack' . DS, |
|
| 326 | - EE_CORE . 'middleware' . DS, |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - // retrieve instantiated class |
|
| 330 | - return $this->_load( |
|
| 331 | - $core_paths, |
|
| 332 | - 'EE_', |
|
| 333 | - $class_name, |
|
| 334 | - 'core', |
|
| 335 | - $arguments, |
|
| 336 | - false, |
|
| 337 | - true, |
|
| 338 | - $load_only |
|
| 339 | - ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * loads service classes |
|
| 346 | - * |
|
| 347 | - * @param string $class_name - simple class name ie: session |
|
| 348 | - * @param mixed $arguments |
|
| 349 | - * @param bool $load_only |
|
| 350 | - * @return mixed |
|
| 351 | - * @throws EE_Error |
|
| 352 | - * @throws ReflectionException |
|
| 353 | - */ |
|
| 354 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 355 | - { |
|
| 356 | - $service_paths = apply_filters( |
|
| 357 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 358 | - array( |
|
| 359 | - EE_CORE . 'services' . DS, |
|
| 360 | - ) |
|
| 361 | - ); |
|
| 362 | - // retrieve instantiated class |
|
| 363 | - return $this->_load( |
|
| 364 | - $service_paths, |
|
| 365 | - 'EE_', |
|
| 366 | - $class_name, |
|
| 367 | - 'class', |
|
| 368 | - $arguments, |
|
| 369 | - false, |
|
| 370 | - true, |
|
| 371 | - $load_only |
|
| 372 | - ); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * loads data_migration_scripts |
|
| 379 | - * |
|
| 380 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 381 | - * @param mixed $arguments |
|
| 382 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 383 | - * @throws EE_Error |
|
| 384 | - * @throws ReflectionException |
|
| 385 | - */ |
|
| 386 | - public function load_dms($class_name, $arguments = array()) |
|
| 387 | - { |
|
| 388 | - // retrieve instantiated class |
|
| 389 | - return $this->_load( |
|
| 390 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 391 | - 'EE_DMS_', |
|
| 392 | - $class_name, |
|
| 393 | - 'dms', |
|
| 394 | - $arguments, |
|
| 395 | - false, |
|
| 396 | - false |
|
| 397 | - ); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * loads object creating classes - must be singletons |
|
| 404 | - * |
|
| 405 | - * @param string $class_name - simple class name ie: attendee |
|
| 406 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 407 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 408 | - * instantiate |
|
| 409 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 410 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 411 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 412 | - * (default) |
|
| 413 | - * @return EE_Base_Class | bool |
|
| 414 | - * @throws EE_Error |
|
| 415 | - * @throws ReflectionException |
|
| 416 | - */ |
|
| 417 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 418 | - { |
|
| 419 | - $paths = apply_filters( |
|
| 420 | - 'FHEE__EE_Registry__load_class__paths', array( |
|
| 421 | - EE_CORE, |
|
| 422 | - EE_CLASSES, |
|
| 423 | - EE_BUSINESS, |
|
| 424 | - ) |
|
| 425 | - ); |
|
| 426 | - // retrieve instantiated class |
|
| 427 | - return $this->_load( |
|
| 428 | - $paths, |
|
| 429 | - 'EE_', |
|
| 430 | - $class_name, |
|
| 431 | - 'class', |
|
| 432 | - $arguments, |
|
| 433 | - $from_db, |
|
| 434 | - $cache, |
|
| 435 | - $load_only |
|
| 436 | - ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * loads helper classes - must be singletons |
|
| 443 | - * |
|
| 444 | - * @param string $class_name - simple class name ie: price |
|
| 445 | - * @param mixed $arguments |
|
| 446 | - * @param bool $load_only |
|
| 447 | - * @return EEH_Base | bool |
|
| 448 | - * @throws EE_Error |
|
| 449 | - * @throws ReflectionException |
|
| 450 | - */ |
|
| 451 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 452 | - { |
|
| 453 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 454 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 455 | - // retrieve instantiated class |
|
| 456 | - return $this->_load( |
|
| 457 | - $helper_paths, |
|
| 458 | - 'EEH_', |
|
| 459 | - $class_name, |
|
| 460 | - 'helper', |
|
| 461 | - $arguments, |
|
| 462 | - false, |
|
| 463 | - true, |
|
| 464 | - $load_only |
|
| 465 | - ); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * loads core classes - must be singletons |
|
| 472 | - * |
|
| 473 | - * @param string $class_name - simple class name ie: session |
|
| 474 | - * @param mixed $arguments |
|
| 475 | - * @param bool $load_only |
|
| 476 | - * @param bool $cache whether to cache the object or not. |
|
| 477 | - * @return mixed |
|
| 478 | - * @throws EE_Error |
|
| 479 | - * @throws ReflectionException |
|
| 480 | - */ |
|
| 481 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 482 | - { |
|
| 483 | - $paths = array( |
|
| 484 | - EE_LIBRARIES, |
|
| 485 | - EE_LIBRARIES . 'messages' . DS, |
|
| 486 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 487 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 488 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 489 | - ); |
|
| 490 | - // retrieve instantiated class |
|
| 491 | - return $this->_load( |
|
| 492 | - $paths, |
|
| 493 | - 'EE_', |
|
| 494 | - $class_name, |
|
| 495 | - 'lib', |
|
| 496 | - $arguments, |
|
| 497 | - false, |
|
| 498 | - $cache, |
|
| 499 | - $load_only |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * loads model classes - must be singletons |
|
| 507 | - * |
|
| 508 | - * @param string $class_name - simple class name ie: price |
|
| 509 | - * @param mixed $arguments |
|
| 510 | - * @param bool $load_only |
|
| 511 | - * @return EEM_Base | bool |
|
| 512 | - * @throws EE_Error |
|
| 513 | - * @throws ReflectionException |
|
| 514 | - */ |
|
| 515 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 516 | - { |
|
| 517 | - $paths = apply_filters( |
|
| 518 | - 'FHEE__EE_Registry__load_model__paths', array( |
|
| 519 | - EE_MODELS, |
|
| 520 | - EE_CORE, |
|
| 521 | - ) |
|
| 522 | - ); |
|
| 523 | - // retrieve instantiated class |
|
| 524 | - return $this->_load( |
|
| 525 | - $paths, |
|
| 526 | - 'EEM_', |
|
| 527 | - $class_name, |
|
| 528 | - 'model', |
|
| 529 | - $arguments, |
|
| 530 | - false, |
|
| 531 | - true, |
|
| 532 | - $load_only |
|
| 533 | - ); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * loads model classes - must be singletons |
|
| 540 | - * |
|
| 541 | - * @param string $class_name - simple class name ie: price |
|
| 542 | - * @param mixed $arguments |
|
| 543 | - * @param bool $load_only |
|
| 544 | - * @return mixed | bool |
|
| 545 | - * @throws EE_Error |
|
| 546 | - * @throws ReflectionException |
|
| 547 | - */ |
|
| 548 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 549 | - { |
|
| 550 | - $paths = array( |
|
| 551 | - EE_MODELS . 'fields' . DS, |
|
| 552 | - EE_MODELS . 'helpers' . DS, |
|
| 553 | - EE_MODELS . 'relations' . DS, |
|
| 554 | - EE_MODELS . 'strategies' . DS, |
|
| 555 | - ); |
|
| 556 | - // retrieve instantiated class |
|
| 557 | - return $this->_load( |
|
| 558 | - $paths, |
|
| 559 | - 'EE_', |
|
| 560 | - $class_name, |
|
| 561 | - '', |
|
| 562 | - $arguments, |
|
| 563 | - false, |
|
| 564 | - true, |
|
| 565 | - $load_only |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Determines if $model_name is the name of an actual EE model. |
|
| 573 | - * |
|
| 574 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 575 | - * @return boolean |
|
| 576 | - */ |
|
| 577 | - public function is_model_name($model_name) |
|
| 578 | - { |
|
| 579 | - return isset($this->models[$model_name]); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * generic class loader |
|
| 586 | - * |
|
| 587 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 588 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 589 | - * @param string $type - file type - core? class? helper? model? |
|
| 590 | - * @param mixed $arguments |
|
| 591 | - * @param bool $load_only |
|
| 592 | - * @return mixed |
|
| 593 | - * @throws EE_Error |
|
| 594 | - * @throws ReflectionException |
|
| 595 | - */ |
|
| 596 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 597 | - { |
|
| 598 | - // retrieve instantiated class |
|
| 599 | - return $this->_load( |
|
| 600 | - $path_to_file, |
|
| 601 | - '', |
|
| 602 | - $file_name, |
|
| 603 | - $type, |
|
| 604 | - $arguments, |
|
| 605 | - false, |
|
| 606 | - true, |
|
| 607 | - $load_only |
|
| 608 | - ); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 615 | - * @param string $class_name - full class name ie: My_Class |
|
| 616 | - * @param string $type - file type - core? class? helper? model? |
|
| 617 | - * @param mixed $arguments |
|
| 618 | - * @param bool $load_only |
|
| 619 | - * @return bool|EE_Addon|object |
|
| 620 | - * @throws EE_Error |
|
| 621 | - * @throws ReflectionException |
|
| 622 | - */ |
|
| 623 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 624 | - { |
|
| 625 | - // retrieve instantiated class |
|
| 626 | - return $this->_load( |
|
| 627 | - $path_to_file, |
|
| 628 | - 'addon', |
|
| 629 | - $class_name, |
|
| 630 | - $type, |
|
| 631 | - $arguments, |
|
| 632 | - false, |
|
| 633 | - true, |
|
| 634 | - $load_only |
|
| 635 | - ); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * instantiates, caches, and automatically resolves dependencies |
|
| 642 | - * for classes that use a Fully Qualified Class Name. |
|
| 643 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 644 | - * then you need to use one of the existing load_*() methods |
|
| 645 | - * which can resolve the classname and filepath from the passed arguments |
|
| 646 | - * |
|
| 647 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 648 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 649 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 650 | - * @param bool $from_db some classes are instantiated from the db |
|
| 651 | - * and thus call a different method to instantiate |
|
| 652 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 653 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 654 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
| 655 | - * object = class loaded and instantiated successfully. |
|
| 656 | - * bool = fail or success when $load_only is true |
|
| 657 | - * @throws EE_Error |
|
| 658 | - * @throws ReflectionException |
|
| 659 | - */ |
|
| 660 | - public function create( |
|
| 661 | - $class_name = false, |
|
| 662 | - $arguments = array(), |
|
| 663 | - $cache = false, |
|
| 664 | - $from_db = false, |
|
| 665 | - $load_only = false, |
|
| 666 | - $addon = false |
|
| 667 | - ) { |
|
| 668 | - $class_name = ltrim($class_name, '\\'); |
|
| 669 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 670 | - if (! class_exists($class_name)) { |
|
| 671 | - // maybe the class is registered with a preceding \ |
|
| 672 | - $class_name = strpos($class_name, '\\') !== 0 |
|
| 673 | - ? '\\' . $class_name |
|
| 674 | - : $class_name; |
|
| 675 | - // still doesn't exist ? |
|
| 676 | - if (! class_exists($class_name)) { |
|
| 677 | - return null; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 681 | - if ($load_only) { |
|
| 682 | - return true; |
|
| 683 | - } |
|
| 684 | - $addon = $addon |
|
| 685 | - ? 'addon' |
|
| 686 | - : ''; |
|
| 687 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 688 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 689 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 690 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 691 | - // return object if it's already cached |
|
| 692 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 693 | - if ($cached_class !== null) { |
|
| 694 | - return $cached_class; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - // instantiate the requested object |
|
| 698 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 699 | - if ($this->_cache_on && $cache) { |
|
| 700 | - // save it for later... kinda like gum { : $ |
|
| 701 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 702 | - } |
|
| 703 | - $this->_cache_on = true; |
|
| 704 | - return $class_obj; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * instantiates, caches, and injects dependencies for classes |
|
| 711 | - * |
|
| 712 | - * @param array $file_paths an array of paths to folders to look in |
|
| 713 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 714 | - * @param bool|string $class_name $class name |
|
| 715 | - * @param string $type file type - core? class? helper? model? |
|
| 716 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 717 | - * @param bool $from_db some classes are instantiated from the db |
|
| 718 | - * and thus call a different method to instantiate |
|
| 719 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 720 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 721 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
| 722 | - * object = class loaded and instantiated successfully. |
|
| 723 | - * bool = fail or success when $load_only is true |
|
| 724 | - * @throws EE_Error |
|
| 725 | - * @throws ReflectionException |
|
| 726 | - */ |
|
| 727 | - protected function _load( |
|
| 728 | - $file_paths = array(), |
|
| 729 | - $class_prefix = 'EE_', |
|
| 730 | - $class_name = false, |
|
| 731 | - $type = 'class', |
|
| 732 | - $arguments = array(), |
|
| 733 | - $from_db = false, |
|
| 734 | - $cache = true, |
|
| 735 | - $load_only = false |
|
| 736 | - ) { |
|
| 737 | - $class_name = ltrim($class_name, '\\'); |
|
| 738 | - // strip php file extension |
|
| 739 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 740 | - // does the class have a prefix ? |
|
| 741 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 742 | - // make sure $class_prefix is uppercase |
|
| 743 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 744 | - // add class prefix ONCE!!! |
|
| 745 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 746 | - } |
|
| 747 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 748 | - $class_exists = class_exists($class_name); |
|
| 749 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 750 | - if ($load_only && $class_exists) { |
|
| 751 | - return true; |
|
| 752 | - } |
|
| 753 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 754 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 755 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 756 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 757 | - // return object if it's already cached |
|
| 758 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 759 | - if ($cached_class !== null) { |
|
| 760 | - return $cached_class; |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 764 | - if (! $class_exists) { |
|
| 765 | - // get full path to file |
|
| 766 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 767 | - // load the file |
|
| 768 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 769 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 770 | - if (! $loaded || $load_only) { |
|
| 771 | - // return boolean if only loading, or null if an object was expected |
|
| 772 | - return $load_only |
|
| 773 | - ? $loaded |
|
| 774 | - : null; |
|
| 775 | - } |
|
| 776 | - } |
|
| 777 | - // instantiate the requested object |
|
| 778 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 779 | - if ($this->_cache_on && $cache) { |
|
| 780 | - // save it for later... kinda like gum { : $ |
|
| 781 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 782 | - } |
|
| 783 | - $this->_cache_on = true; |
|
| 784 | - return $class_obj; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * attempts to find a cached version of the requested class |
|
| 791 | - * by looking in the following places: |
|
| 792 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 793 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 794 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 795 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 796 | - * |
|
| 797 | - * @param string $class_name |
|
| 798 | - * @param string $class_prefix |
|
| 799 | - * @return mixed |
|
| 800 | - */ |
|
| 801 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 802 | - { |
|
| 803 | - if ($class_name === 'EE_Registry') { |
|
| 804 | - return $this; |
|
| 805 | - } |
|
| 806 | - // have to specify something, but not anything that will conflict |
|
| 807 | - $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
| 808 | - ? $this->_class_abbreviations[$class_name] |
|
| 809 | - : 'FANCY_BATMAN_PANTS'; |
|
| 810 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 811 | - // check if class has already been loaded, and return it if it has been |
|
| 812 | - if (isset($this->{$class_abbreviation})) { |
|
| 813 | - return $this->{$class_abbreviation}; |
|
| 814 | - } |
|
| 815 | - if (isset ($this->{$class_name})) { |
|
| 816 | - return $this->{$class_name}; |
|
| 817 | - } |
|
| 818 | - if (isset ($this->LIB->{$class_name})) { |
|
| 819 | - return $this->LIB->{$class_name}; |
|
| 820 | - } |
|
| 821 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 822 | - return $this->addons->{$class_name}; |
|
| 823 | - } |
|
| 824 | - return null; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * removes a cached version of the requested class |
|
| 831 | - * |
|
| 832 | - * @param string $class_name |
|
| 833 | - * @param boolean $addon |
|
| 834 | - * @return boolean |
|
| 835 | - */ |
|
| 836 | - public function clear_cached_class($class_name, $addon = false) |
|
| 837 | - { |
|
| 838 | - // have to specify something, but not anything that will conflict |
|
| 839 | - $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
| 840 | - ? $this->_class_abbreviations[$class_name] |
|
| 841 | - : 'FANCY_BATMAN_PANTS'; |
|
| 842 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 843 | - // check if class has already been loaded, and return it if it has been |
|
| 844 | - if (isset($this->{$class_abbreviation})) { |
|
| 845 | - $this->{$class_abbreviation} = null; |
|
| 846 | - return true; |
|
| 847 | - } |
|
| 848 | - if (isset($this->{$class_name})) { |
|
| 849 | - $this->{$class_name} = null; |
|
| 850 | - return true; |
|
| 851 | - } |
|
| 852 | - if (isset($this->LIB->{$class_name})) { |
|
| 853 | - unset($this->LIB->{$class_name}); |
|
| 854 | - return true; |
|
| 855 | - } |
|
| 856 | - if ($addon && isset($this->addons->{$class_name})) { |
|
| 857 | - unset($this->addons->{$class_name}); |
|
| 858 | - return true; |
|
| 859 | - } |
|
| 860 | - return false; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * attempts to find a full valid filepath for the requested class. |
|
| 867 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 868 | - * then returns that path if the target file has been found and is readable |
|
| 869 | - * |
|
| 870 | - * @param string $class_name |
|
| 871 | - * @param string $type |
|
| 872 | - * @param array $file_paths |
|
| 873 | - * @return string | bool |
|
| 874 | - */ |
|
| 875 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 876 | - { |
|
| 877 | - // make sure $file_paths is an array |
|
| 878 | - $file_paths = is_array($file_paths) |
|
| 879 | - ? $file_paths |
|
| 880 | - : array($file_paths); |
|
| 881 | - // cycle thru paths |
|
| 882 | - foreach ($file_paths as $key => $file_path) { |
|
| 883 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 884 | - $file_path = $file_path |
|
| 885 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 886 | - : EE_CLASSES; |
|
| 887 | - // prep file type |
|
| 888 | - $type = ! empty($type) |
|
| 889 | - ? trim($type, '.') . '.' |
|
| 890 | - : ''; |
|
| 891 | - // build full file path |
|
| 892 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 893 | - //does the file exist and can be read ? |
|
| 894 | - if (is_readable($file_paths[$key])) { |
|
| 895 | - return $file_paths[$key]; |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - return false; |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * basically just performs a require_once() |
|
| 905 | - * but with some error handling |
|
| 906 | - * |
|
| 907 | - * @param string $path |
|
| 908 | - * @param string $class_name |
|
| 909 | - * @param string $type |
|
| 910 | - * @param array $file_paths |
|
| 911 | - * @return bool |
|
| 912 | - * @throws EE_Error |
|
| 913 | - * @throws ReflectionException |
|
| 914 | - */ |
|
| 915 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 916 | - { |
|
| 917 | - // don't give up! you gotta... |
|
| 918 | - try { |
|
| 919 | - //does the file exist and can it be read ? |
|
| 920 | - if (! $path) { |
|
| 921 | - // so sorry, can't find the file |
|
| 922 | - throw new EE_Error ( |
|
| 923 | - sprintf( |
|
| 924 | - esc_html__( |
|
| 925 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 926 | - 'event_espresso' |
|
| 927 | - ), |
|
| 928 | - trim($type, '.'), |
|
| 929 | - $class_name, |
|
| 930 | - '<br />' . implode(',<br />', $file_paths) |
|
| 931 | - ) |
|
| 932 | - ); |
|
| 933 | - } |
|
| 934 | - // get the file |
|
| 935 | - require_once($path); |
|
| 936 | - // if the class isn't already declared somewhere |
|
| 937 | - if (class_exists($class_name, false) === false) { |
|
| 938 | - // so sorry, not a class |
|
| 939 | - throw new EE_Error( |
|
| 940 | - sprintf( |
|
| 941 | - esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 942 | - $type, |
|
| 943 | - $path, |
|
| 944 | - $class_name |
|
| 945 | - ) |
|
| 946 | - ); |
|
| 947 | - } |
|
| 948 | - } catch (EE_Error $e) { |
|
| 949 | - $e->get_error(); |
|
| 950 | - return false; |
|
| 951 | - } |
|
| 952 | - return true; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * _create_object |
|
| 959 | - * Attempts to instantiate the requested class via any of the |
|
| 960 | - * commonly used instantiation methods employed throughout EE. |
|
| 961 | - * The priority for instantiation is as follows: |
|
| 962 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 963 | - * - model objects via their 'new_instance_from_db' method |
|
| 964 | - * - model objects via their 'new_instance' method |
|
| 965 | - * - "singleton" classes" via their 'instance' method |
|
| 966 | - * - standard instantiable classes via their __constructor |
|
| 967 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 968 | - * then the constructor for the requested class will be examined to determine |
|
| 969 | - * if any dependencies exist, and if they can be injected. |
|
| 970 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 971 | - * |
|
| 972 | - * @param string $class_name |
|
| 973 | - * @param array $arguments |
|
| 974 | - * @param string $type |
|
| 975 | - * @param bool $from_db |
|
| 976 | - * @return null|object |
|
| 977 | - * @throws EE_Error |
|
| 978 | - * @throws ReflectionException |
|
| 979 | - */ |
|
| 980 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 981 | - { |
|
| 982 | - $class_obj = null; |
|
| 983 | - $instantiation_mode = '0) none'; |
|
| 984 | - // don't give up! you gotta... |
|
| 985 | - try { |
|
| 986 | - // create reflection |
|
| 987 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 988 | - // make sure arguments are an array |
|
| 989 | - $arguments = is_array($arguments) |
|
| 990 | - ? $arguments |
|
| 991 | - : array($arguments); |
|
| 992 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 993 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 994 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 995 | - ? $arguments |
|
| 996 | - : array($arguments); |
|
| 997 | - // attempt to inject dependencies ? |
|
| 998 | - if ($this->_dependency_map->has($class_name)) { |
|
| 999 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1000 | - } |
|
| 1001 | - // instantiate the class if possible |
|
| 1002 | - if ($reflector->isAbstract()) { |
|
| 1003 | - // nothing to instantiate, loading file was enough |
|
| 1004 | - // does not throw an exception so $instantiation_mode is unused |
|
| 1005 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1006 | - $class_obj = true; |
|
| 1007 | - } else if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1008 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1009 | - $instantiation_mode = '2) no constructor but instantiable'; |
|
| 1010 | - $class_obj = $reflector->newInstance(); |
|
| 1011 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1012 | - $instantiation_mode = '3) new_instance_from_db()'; |
|
| 1013 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1014 | - } else if (method_exists($class_name, 'new_instance')) { |
|
| 1015 | - $instantiation_mode = '4) new_instance()'; |
|
| 1016 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1017 | - } else if (method_exists($class_name, 'instance')) { |
|
| 1018 | - $instantiation_mode = '5) instance()'; |
|
| 1019 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1020 | - } else if ($reflector->isInstantiable()) { |
|
| 1021 | - $instantiation_mode = '6) constructor'; |
|
| 1022 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 1023 | - } else { |
|
| 1024 | - // heh ? something's not right ! |
|
| 1025 | - throw new EE_Error( |
|
| 1026 | - sprintf( |
|
| 1027 | - esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1028 | - $type, |
|
| 1029 | - $class_name |
|
| 1030 | - ) |
|
| 1031 | - ); |
|
| 1032 | - } |
|
| 1033 | - } catch (Exception $e) { |
|
| 1034 | - if (! $e instanceof EE_Error) { |
|
| 1035 | - $e = new EE_Error( |
|
| 1036 | - sprintf( |
|
| 1037 | - esc_html__( |
|
| 1038 | - 'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', |
|
| 1039 | - 'event_espresso' |
|
| 1040 | - ), |
|
| 1041 | - $class_name, |
|
| 1042 | - '<br />', |
|
| 1043 | - $e->getMessage(), |
|
| 1044 | - $instantiation_mode |
|
| 1045 | - ) |
|
| 1046 | - ); |
|
| 1047 | - } |
|
| 1048 | - $e->get_error(); |
|
| 1049 | - } |
|
| 1050 | - return $class_obj; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - |
|
| 1055 | - /** |
|
| 1056 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1057 | - * @param array $array |
|
| 1058 | - * @return bool |
|
| 1059 | - */ |
|
| 1060 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1061 | - { |
|
| 1062 | - return ! empty($array) |
|
| 1063 | - ? array_keys($array) === range(0, count($array) - 1) |
|
| 1064 | - : true; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * getReflectionClass |
|
| 1071 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 1072 | - * and returns that instead of creating a new one |
|
| 1073 | - * |
|
| 1074 | - * @param string $class_name |
|
| 1075 | - * @return ReflectionClass |
|
| 1076 | - * @throws ReflectionException |
|
| 1077 | - */ |
|
| 1078 | - public function get_ReflectionClass($class_name) |
|
| 1079 | - { |
|
| 1080 | - if ( |
|
| 1081 | - ! isset($this->_reflectors[$class_name]) |
|
| 1082 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1083 | - ) { |
|
| 1084 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1085 | - } |
|
| 1086 | - return $this->_reflectors[$class_name]; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - |
|
| 1091 | - /** |
|
| 1092 | - * _resolve_dependencies |
|
| 1093 | - * examines the constructor for the requested class to determine |
|
| 1094 | - * if any dependencies exist, and if they can be injected. |
|
| 1095 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1096 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1097 | - * For example: |
|
| 1098 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 1099 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1100 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1101 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 1102 | - * and the correct classes can be loaded |
|
| 1103 | - * |
|
| 1104 | - * @param ReflectionClass $reflector |
|
| 1105 | - * @param string $class_name |
|
| 1106 | - * @param array $arguments |
|
| 1107 | - * @return array |
|
| 1108 | - * @throws EE_Error |
|
| 1109 | - * @throws ReflectionException |
|
| 1110 | - */ |
|
| 1111 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1112 | - { |
|
| 1113 | - // let's examine the constructor |
|
| 1114 | - $constructor = $reflector->getConstructor(); |
|
| 1115 | - // whu? huh? nothing? |
|
| 1116 | - if (! $constructor) { |
|
| 1117 | - return $arguments; |
|
| 1118 | - } |
|
| 1119 | - // get constructor parameters |
|
| 1120 | - $params = $constructor->getParameters(); |
|
| 1121 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1122 | - $argument_keys = array_keys($arguments); |
|
| 1123 | - // now loop thru all of the constructors expected parameters |
|
| 1124 | - foreach ($params as $index => $param) { |
|
| 1125 | - // is this a dependency for a specific class ? |
|
| 1126 | - $param_class = $param->getClass() |
|
| 1127 | - ? $param->getClass()->name |
|
| 1128 | - : null; |
|
| 1129 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1130 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1131 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1132 | - : $param_class; |
|
| 1133 | - if ( |
|
| 1134 | - // param is not even a class |
|
| 1135 | - empty($param_class) |
|
| 1136 | - // and something already exists in the incoming arguments for this param |
|
| 1137 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1138 | - ) { |
|
| 1139 | - // so let's skip this argument and move on to the next |
|
| 1140 | - continue; |
|
| 1141 | - } |
|
| 1142 | - if ( |
|
| 1143 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1144 | - ! empty($param_class) |
|
| 1145 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1146 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1147 | - ) { |
|
| 1148 | - // skip this argument and move on to the next |
|
| 1149 | - continue; |
|
| 1150 | - } |
|
| 1151 | - if ( |
|
| 1152 | - // parameter is type hinted as a class, and should be injected |
|
| 1153 | - ! empty($param_class) |
|
| 1154 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1155 | - ) { |
|
| 1156 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
| 1157 | - } else { |
|
| 1158 | - try { |
|
| 1159 | - $arguments[$index] = $param->getDefaultValue(); |
|
| 1160 | - } catch (ReflectionException $e) { |
|
| 1161 | - throw new ReflectionException( |
|
| 1162 | - sprintf( |
|
| 1163 | - esc_html__('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1164 | - $e->getMessage(), |
|
| 1165 | - $param->getName() |
|
| 1166 | - ) |
|
| 1167 | - ); |
|
| 1168 | - } |
|
| 1169 | - } |
|
| 1170 | - } |
|
| 1171 | - return $arguments; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * @param string $class_name |
|
| 1178 | - * @param string $param_class |
|
| 1179 | - * @param array $arguments |
|
| 1180 | - * @param mixed $index |
|
| 1181 | - * @return array |
|
| 1182 | - * @throws EE_Error |
|
| 1183 | - * @throws ReflectionException |
|
| 1184 | - */ |
|
| 1185 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
| 1186 | - { |
|
| 1187 | - $dependency = null; |
|
| 1188 | - // should dependency be loaded from cache ? |
|
| 1189 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
| 1190 | - !== EE_Dependency_Map::load_new_object; |
|
| 1191 | - // we might have a dependency... |
|
| 1192 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1193 | - $cached_class = $cache_on |
|
| 1194 | - ? $this->_get_cached_class($param_class) |
|
| 1195 | - : null; |
|
| 1196 | - // and grab it if it exists |
|
| 1197 | - if ($cached_class instanceof $param_class) { |
|
| 1198 | - $dependency = $cached_class; |
|
| 1199 | - } else if ($param_class !== $class_name) { |
|
| 1200 | - // obtain the loader method from the dependency map |
|
| 1201 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1202 | - // is loader a custom closure ? |
|
| 1203 | - if ($loader instanceof Closure) { |
|
| 1204 | - $dependency = $loader(); |
|
| 1205 | - } else { |
|
| 1206 | - // set the cache on property for the recursive loading call |
|
| 1207 | - $this->_cache_on = $cache_on; |
|
| 1208 | - // if not, then let's try and load it via the registry |
|
| 1209 | - if ($loader && method_exists($this, $loader)) { |
|
| 1210 | - $dependency = $this->{$loader}($param_class); |
|
| 1211 | - } else { |
|
| 1212 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - // did we successfully find the correct dependency ? |
|
| 1217 | - if ($dependency instanceof $param_class) { |
|
| 1218 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1219 | - if (isset($argument_keys[$index])) { |
|
| 1220 | - $arguments[$argument_keys[$index]] = $dependency; |
|
| 1221 | - } else { |
|
| 1222 | - $arguments[$index] = $dependency; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - return $arguments; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * _set_cached_class |
|
| 1232 | - * attempts to cache the instantiated class locally |
|
| 1233 | - * in one of the following places, in the following order: |
|
| 1234 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1235 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1236 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1237 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1238 | - * |
|
| 1239 | - * @param object $class_obj |
|
| 1240 | - * @param string $class_name |
|
| 1241 | - * @param string $class_prefix |
|
| 1242 | - * @param bool $from_db |
|
| 1243 | - * @return void |
|
| 1244 | - */ |
|
| 1245 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1246 | - { |
|
| 1247 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1248 | - return; |
|
| 1249 | - } |
|
| 1250 | - // return newly instantiated class |
|
| 1251 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
| 1252 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 1253 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1254 | - return; |
|
| 1255 | - } |
|
| 1256 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1257 | - if (property_exists($this, $class_name)) { |
|
| 1258 | - $this->{$class_name} = $class_obj; |
|
| 1259 | - return; |
|
| 1260 | - } |
|
| 1261 | - if ($class_prefix === 'addon') { |
|
| 1262 | - $this->addons->{$class_name} = $class_obj; |
|
| 1263 | - return; |
|
| 1264 | - } |
|
| 1265 | - if (! $from_db) { |
|
| 1266 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - |
|
| 1271 | - |
|
| 1272 | - /** |
|
| 1273 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1274 | - * |
|
| 1275 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1276 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1277 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1278 | - * @param array $arguments |
|
| 1279 | - * @return object |
|
| 1280 | - */ |
|
| 1281 | - public static function factory($classname, $arguments = array()) |
|
| 1282 | - { |
|
| 1283 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1284 | - if ($loader instanceof Closure) { |
|
| 1285 | - return $loader($arguments); |
|
| 1286 | - } |
|
| 1287 | - if (method_exists(self::instance(), $loader)) { |
|
| 1288 | - return self::instance()->{$loader}($classname, $arguments); |
|
| 1289 | - } |
|
| 1290 | - return null; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - |
|
| 1295 | - /** |
|
| 1296 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1297 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1298 | - * |
|
| 1299 | - * @param string $name |
|
| 1300 | - * @return EE_Addon |
|
| 1301 | - */ |
|
| 1302 | - public function get_addon_by_name($name) |
|
| 1303 | - { |
|
| 1304 | - foreach ($this->addons as $addon) { |
|
| 1305 | - if ($addon->name() === $name) { |
|
| 1306 | - return $addon; |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - return null; |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - |
|
| 1313 | - |
|
| 1314 | - /** |
|
| 1315 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
|
| 1316 | - * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
|
| 1317 | - * name is the addon's classname. So if you just want to get the addon by classname, use |
|
| 1318 | - * EE_Config::instance()->addons->{classname} |
|
| 1319 | - * |
|
| 1320 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1321 | - */ |
|
| 1322 | - public function get_addons_by_name() |
|
| 1323 | - { |
|
| 1324 | - $addons = array(); |
|
| 1325 | - foreach ($this->addons as $addon) { |
|
| 1326 | - $addons[$addon->name()] = $addon; |
|
| 1327 | - } |
|
| 1328 | - return $addons; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - |
|
| 1333 | - /** |
|
| 1334 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1335 | - * a stale copy of it around |
|
| 1336 | - * |
|
| 1337 | - * @param string $model_name |
|
| 1338 | - * @return \EEM_Base |
|
| 1339 | - * @throws \EE_Error |
|
| 1340 | - */ |
|
| 1341 | - public function reset_model($model_name) |
|
| 1342 | - { |
|
| 1343 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1344 | - ? "EEM_{$model_name}" |
|
| 1345 | - : $model_name; |
|
| 1346 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1347 | - return null; |
|
| 1348 | - } |
|
| 1349 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1350 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1351 | - && is_callable( |
|
| 1352 | - array($model_class_name, 'reset') |
|
| 1353 | - )) { |
|
| 1354 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1355 | - } else { |
|
| 1356 | - throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1357 | - } |
|
| 1358 | - return $this->LIB->{$model_class_name}; |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * Resets the registry. |
|
| 1365 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1366 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1367 | - * - $_dependency_map |
|
| 1368 | - * - $_class_abbreviations |
|
| 1369 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1370 | - * - $REQ: Still on the same request so no need to change. |
|
| 1371 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1372 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1373 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1374 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1375 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1376 | - * switch or on the restore. |
|
| 1377 | - * - $modules |
|
| 1378 | - * - $shortcodes |
|
| 1379 | - * - $widgets |
|
| 1380 | - * |
|
| 1381 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
| 1382 | - * the Registry to its state at the beginning of the request |
|
| 1383 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1384 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1385 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1386 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1387 | - * client |
|
| 1388 | - * code instead can just change the model context to a different blog id if |
|
| 1389 | - * necessary |
|
| 1390 | - * @return EE_Registry |
|
| 1391 | - * @throws EE_Error |
|
| 1392 | - * @throws ReflectionException |
|
| 1393 | - */ |
|
| 1394 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1395 | - { |
|
| 1396 | - $instance = self::instance(); |
|
| 1397 | - $instance->_cache_on = true; |
|
| 1398 | - // reset some "special" classes |
|
| 1399 | - EEH_Activation::reset(); |
|
| 1400 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1401 | - $instance->CART = null; |
|
| 1402 | - $instance->MRM = null; |
|
| 1403 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1404 | - //messages reset |
|
| 1405 | - EED_Messages::reset(); |
|
| 1406 | - //handle of objects cached on LIB |
|
| 1407 | - foreach (array('LIB', 'modules') as $cache) { |
|
| 1408 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1409 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1410 | - unset($instance->{$cache}->{$class_name}); |
|
| 1411 | - } |
|
| 1412 | - } |
|
| 1413 | - } |
|
| 1414 | - return $instance; |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - |
|
| 1418 | - |
|
| 1419 | - /** |
|
| 1420 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1421 | - * if passed object implements InterminableInterface, then return false, |
|
| 1422 | - * to indicate that it should NOT be cleared from the Registry cache |
|
| 1423 | - * |
|
| 1424 | - * @param $object |
|
| 1425 | - * @param bool $reset_models |
|
| 1426 | - * @return bool returns true if cached object should be unset |
|
| 1427 | - */ |
|
| 1428 | - private static function _reset_and_unset_object($object, $reset_models) |
|
| 1429 | - { |
|
| 1430 | - if (! is_object($object)) { |
|
| 1431 | - // don't unset anything that's not an object |
|
| 1432 | - return false; |
|
| 1433 | - } |
|
| 1434 | - if ($object instanceof EED_Module) { |
|
| 1435 | - $object::reset(); |
|
| 1436 | - // don't unset modules |
|
| 1437 | - return false; |
|
| 1438 | - } |
|
| 1439 | - if ($object instanceof ResettableInterface) { |
|
| 1440 | - if ($object instanceof EEM_Base) { |
|
| 1441 | - if ($reset_models) { |
|
| 1442 | - $object->reset(); |
|
| 1443 | - return true; |
|
| 1444 | - } |
|
| 1445 | - return false; |
|
| 1446 | - } |
|
| 1447 | - $object->reset(); |
|
| 1448 | - return true; |
|
| 1449 | - } |
|
| 1450 | - if (! $object instanceof InterminableInterface) { |
|
| 1451 | - return true; |
|
| 1452 | - } |
|
| 1453 | - return false; |
|
| 1454 | - } |
|
| 1455 | - |
|
| 1456 | - |
|
| 1457 | - |
|
| 1458 | - /** |
|
| 1459 | - * Gets all the custom post type models defined |
|
| 1460 | - * |
|
| 1461 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1462 | - */ |
|
| 1463 | - public function cpt_models() |
|
| 1464 | - { |
|
| 1465 | - $cpt_models = array(); |
|
| 1466 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1467 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1468 | - $cpt_models[$short_name] = $classname; |
|
| 1469 | - } |
|
| 1470 | - } |
|
| 1471 | - return $cpt_models; |
|
| 1472 | - } |
|
| 1473 | - |
|
| 1474 | - |
|
| 1475 | - |
|
| 1476 | - /** |
|
| 1477 | - * @return \EE_Config |
|
| 1478 | - */ |
|
| 1479 | - public static function CFG() |
|
| 1480 | - { |
|
| 1481 | - return self::instance()->CFG; |
|
| 1482 | - } |
|
| 23 | + /** |
|
| 24 | + * @var EE_Registry $_instance |
|
| 25 | + */ |
|
| 26 | + private static $_instance; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var EE_Dependency_Map $_dependency_map |
|
| 30 | + */ |
|
| 31 | + protected $_dependency_map; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array $_class_abbreviations |
|
| 35 | + */ |
|
| 36 | + protected $_class_abbreviations = array(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var CommandBusInterface $BUS |
|
| 40 | + */ |
|
| 41 | + public $BUS; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Cart $CART |
|
| 45 | + */ |
|
| 46 | + public $CART; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var EE_Config $CFG |
|
| 50 | + */ |
|
| 51 | + public $CFG; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var EE_Network_Config $NET_CFG |
|
| 55 | + */ |
|
| 56 | + public $NET_CFG; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * StdClass object for storing library classes in |
|
| 60 | + * |
|
| 61 | + * @var StdClass $LIB |
|
| 62 | + */ |
|
| 63 | + public $LIB; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var EE_Request_Handler $REQ |
|
| 67 | + */ |
|
| 68 | + public $REQ; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var EE_Session $SSN |
|
| 72 | + */ |
|
| 73 | + public $SSN; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @since 4.5.0 |
|
| 77 | + * @var EE_Capabilities $CAP |
|
| 78 | + */ |
|
| 79 | + public $CAP; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @since 4.9.0 |
|
| 83 | + * @var EE_Message_Resource_Manager $MRM |
|
| 84 | + */ |
|
| 85 | + public $MRM; |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @var Registry $AssetsRegistry |
|
| 90 | + */ |
|
| 91 | + public $AssetsRegistry; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 95 | + * |
|
| 96 | + * @var EE_Addon[] $addons |
|
| 97 | + */ |
|
| 98 | + public $addons; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 102 | + * |
|
| 103 | + * @var EEM_Base[] $models |
|
| 104 | + */ |
|
| 105 | + public $models = array(); |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @var EED_Module[] $modules |
|
| 109 | + */ |
|
| 110 | + public $modules; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @var EES_Shortcode[] $shortcodes |
|
| 114 | + */ |
|
| 115 | + public $shortcodes; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @var WP_Widget[] $widgets |
|
| 119 | + */ |
|
| 120 | + public $widgets; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 124 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 125 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 126 | + * classnames (eg "EEM_Event") |
|
| 127 | + * |
|
| 128 | + * @var array $non_abstract_db_models |
|
| 129 | + */ |
|
| 130 | + public $non_abstract_db_models = array(); |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * internationalization for JS strings |
|
| 135 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 136 | + * in js file: var translatedString = eei18n.string_key; |
|
| 137 | + * |
|
| 138 | + * @var array $i18n_js_strings |
|
| 139 | + */ |
|
| 140 | + public static $i18n_js_strings = array(); |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * $main_file - path to espresso.php |
|
| 145 | + * |
|
| 146 | + * @var array $main_file |
|
| 147 | + */ |
|
| 148 | + public $main_file; |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * array of ReflectionClass objects where the key is the class name |
|
| 152 | + * |
|
| 153 | + * @var ReflectionClass[] $_reflectors |
|
| 154 | + */ |
|
| 155 | + public $_reflectors; |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 159 | + * |
|
| 160 | + * @var boolean $_cache_on |
|
| 161 | + */ |
|
| 162 | + protected $_cache_on = true; |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @singleton method used to instantiate class object |
|
| 168 | + * @param EE_Dependency_Map $dependency_map |
|
| 169 | + * @return EE_Registry instance |
|
| 170 | + */ |
|
| 171 | + public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 172 | + { |
|
| 173 | + // check if class object is instantiated |
|
| 174 | + if (! self::$_instance instanceof EE_Registry) { |
|
| 175 | + self::$_instance = new self($dependency_map); |
|
| 176 | + } |
|
| 177 | + return self::$_instance; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * protected constructor to prevent direct creation |
|
| 184 | + * |
|
| 185 | + * @Constructor |
|
| 186 | + * @param EE_Dependency_Map $dependency_map |
|
| 187 | + */ |
|
| 188 | + protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 189 | + { |
|
| 190 | + $this->_dependency_map = $dependency_map; |
|
| 191 | + $this->LIB = new stdClass(); |
|
| 192 | + $this->addons = new stdClass(); |
|
| 193 | + $this->modules = new stdClass(); |
|
| 194 | + $this->shortcodes = new stdClass(); |
|
| 195 | + $this->widgets = new stdClass(); |
|
| 196 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * initialize |
|
| 203 | + * |
|
| 204 | + * @throws EE_Error |
|
| 205 | + * @throws ReflectionException |
|
| 206 | + */ |
|
| 207 | + public function initialize() |
|
| 208 | + { |
|
| 209 | + $this->_class_abbreviations = apply_filters( |
|
| 210 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 211 | + array( |
|
| 212 | + 'EE_Config' => 'CFG', |
|
| 213 | + 'EE_Session' => 'SSN', |
|
| 214 | + 'EE_Capabilities' => 'CAP', |
|
| 215 | + 'EE_Cart' => 'CART', |
|
| 216 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 217 | + 'EE_Request_Handler' => 'REQ', |
|
| 218 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 219 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 220 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 221 | + ) |
|
| 222 | + ); |
|
| 223 | + $this->load_core('Base', array(), true); |
|
| 224 | + // add our request and response objects to the cache |
|
| 225 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 226 | + $this->_set_cached_class( |
|
| 227 | + $request_loader(), |
|
| 228 | + 'EE_Request' |
|
| 229 | + ); |
|
| 230 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 231 | + $this->_set_cached_class( |
|
| 232 | + $response_loader(), |
|
| 233 | + 'EE_Response' |
|
| 234 | + ); |
|
| 235 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @return void |
|
| 242 | + */ |
|
| 243 | + public function init() |
|
| 244 | + { |
|
| 245 | + // Get current page protocol |
|
| 246 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 247 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 248 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 249 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * localize_i18n_js_strings |
|
| 256 | + * |
|
| 257 | + * @return string |
|
| 258 | + */ |
|
| 259 | + public static function localize_i18n_js_strings() |
|
| 260 | + { |
|
| 261 | + $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 262 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 263 | + if (is_scalar($value)) { |
|
| 264 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * @param $module |
|
| 274 | + * @throws EE_Error |
|
| 275 | + * @throws ReflectionException |
|
| 276 | + */ |
|
| 277 | + public function add_module($module) |
|
| 278 | + { |
|
| 279 | + if ($module instanceof EED_Module) { |
|
| 280 | + $module_class = get_class($module); |
|
| 281 | + $this->modules->{$module_class} = $module; |
|
| 282 | + } else { |
|
| 283 | + if (! class_exists('EE_Module_Request_Router')) { |
|
| 284 | + $this->load_core('Module_Request_Router'); |
|
| 285 | + } |
|
| 286 | + EE_Module_Request_Router::module_factory($module); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @param string $module_name |
|
| 294 | + * @return mixed EED_Module | NULL |
|
| 295 | + */ |
|
| 296 | + public function get_module($module_name = '') |
|
| 297 | + { |
|
| 298 | + return isset($this->modules->{$module_name}) |
|
| 299 | + ? $this->modules->{$module_name} |
|
| 300 | + : null; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * loads core classes - must be singletons |
|
| 307 | + * |
|
| 308 | + * @param string $class_name - simple class name ie: session |
|
| 309 | + * @param mixed $arguments |
|
| 310 | + * @param bool $load_only |
|
| 311 | + * @return mixed |
|
| 312 | + * @throws EE_Error |
|
| 313 | + * @throws ReflectionException |
|
| 314 | + */ |
|
| 315 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 316 | + { |
|
| 317 | + $core_paths = apply_filters( |
|
| 318 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 319 | + array( |
|
| 320 | + EE_CORE, |
|
| 321 | + EE_ADMIN, |
|
| 322 | + EE_CPTS, |
|
| 323 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 324 | + EE_CORE . 'capabilities' . DS, |
|
| 325 | + EE_CORE . 'request_stack' . DS, |
|
| 326 | + EE_CORE . 'middleware' . DS, |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + // retrieve instantiated class |
|
| 330 | + return $this->_load( |
|
| 331 | + $core_paths, |
|
| 332 | + 'EE_', |
|
| 333 | + $class_name, |
|
| 334 | + 'core', |
|
| 335 | + $arguments, |
|
| 336 | + false, |
|
| 337 | + true, |
|
| 338 | + $load_only |
|
| 339 | + ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * loads service classes |
|
| 346 | + * |
|
| 347 | + * @param string $class_name - simple class name ie: session |
|
| 348 | + * @param mixed $arguments |
|
| 349 | + * @param bool $load_only |
|
| 350 | + * @return mixed |
|
| 351 | + * @throws EE_Error |
|
| 352 | + * @throws ReflectionException |
|
| 353 | + */ |
|
| 354 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 355 | + { |
|
| 356 | + $service_paths = apply_filters( |
|
| 357 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 358 | + array( |
|
| 359 | + EE_CORE . 'services' . DS, |
|
| 360 | + ) |
|
| 361 | + ); |
|
| 362 | + // retrieve instantiated class |
|
| 363 | + return $this->_load( |
|
| 364 | + $service_paths, |
|
| 365 | + 'EE_', |
|
| 366 | + $class_name, |
|
| 367 | + 'class', |
|
| 368 | + $arguments, |
|
| 369 | + false, |
|
| 370 | + true, |
|
| 371 | + $load_only |
|
| 372 | + ); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * loads data_migration_scripts |
|
| 379 | + * |
|
| 380 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 381 | + * @param mixed $arguments |
|
| 382 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 383 | + * @throws EE_Error |
|
| 384 | + * @throws ReflectionException |
|
| 385 | + */ |
|
| 386 | + public function load_dms($class_name, $arguments = array()) |
|
| 387 | + { |
|
| 388 | + // retrieve instantiated class |
|
| 389 | + return $this->_load( |
|
| 390 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 391 | + 'EE_DMS_', |
|
| 392 | + $class_name, |
|
| 393 | + 'dms', |
|
| 394 | + $arguments, |
|
| 395 | + false, |
|
| 396 | + false |
|
| 397 | + ); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * loads object creating classes - must be singletons |
|
| 404 | + * |
|
| 405 | + * @param string $class_name - simple class name ie: attendee |
|
| 406 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 407 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 408 | + * instantiate |
|
| 409 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 410 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 411 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 412 | + * (default) |
|
| 413 | + * @return EE_Base_Class | bool |
|
| 414 | + * @throws EE_Error |
|
| 415 | + * @throws ReflectionException |
|
| 416 | + */ |
|
| 417 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 418 | + { |
|
| 419 | + $paths = apply_filters( |
|
| 420 | + 'FHEE__EE_Registry__load_class__paths', array( |
|
| 421 | + EE_CORE, |
|
| 422 | + EE_CLASSES, |
|
| 423 | + EE_BUSINESS, |
|
| 424 | + ) |
|
| 425 | + ); |
|
| 426 | + // retrieve instantiated class |
|
| 427 | + return $this->_load( |
|
| 428 | + $paths, |
|
| 429 | + 'EE_', |
|
| 430 | + $class_name, |
|
| 431 | + 'class', |
|
| 432 | + $arguments, |
|
| 433 | + $from_db, |
|
| 434 | + $cache, |
|
| 435 | + $load_only |
|
| 436 | + ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * loads helper classes - must be singletons |
|
| 443 | + * |
|
| 444 | + * @param string $class_name - simple class name ie: price |
|
| 445 | + * @param mixed $arguments |
|
| 446 | + * @param bool $load_only |
|
| 447 | + * @return EEH_Base | bool |
|
| 448 | + * @throws EE_Error |
|
| 449 | + * @throws ReflectionException |
|
| 450 | + */ |
|
| 451 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 452 | + { |
|
| 453 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 454 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 455 | + // retrieve instantiated class |
|
| 456 | + return $this->_load( |
|
| 457 | + $helper_paths, |
|
| 458 | + 'EEH_', |
|
| 459 | + $class_name, |
|
| 460 | + 'helper', |
|
| 461 | + $arguments, |
|
| 462 | + false, |
|
| 463 | + true, |
|
| 464 | + $load_only |
|
| 465 | + ); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * loads core classes - must be singletons |
|
| 472 | + * |
|
| 473 | + * @param string $class_name - simple class name ie: session |
|
| 474 | + * @param mixed $arguments |
|
| 475 | + * @param bool $load_only |
|
| 476 | + * @param bool $cache whether to cache the object or not. |
|
| 477 | + * @return mixed |
|
| 478 | + * @throws EE_Error |
|
| 479 | + * @throws ReflectionException |
|
| 480 | + */ |
|
| 481 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 482 | + { |
|
| 483 | + $paths = array( |
|
| 484 | + EE_LIBRARIES, |
|
| 485 | + EE_LIBRARIES . 'messages' . DS, |
|
| 486 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 487 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 488 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 489 | + ); |
|
| 490 | + // retrieve instantiated class |
|
| 491 | + return $this->_load( |
|
| 492 | + $paths, |
|
| 493 | + 'EE_', |
|
| 494 | + $class_name, |
|
| 495 | + 'lib', |
|
| 496 | + $arguments, |
|
| 497 | + false, |
|
| 498 | + $cache, |
|
| 499 | + $load_only |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * loads model classes - must be singletons |
|
| 507 | + * |
|
| 508 | + * @param string $class_name - simple class name ie: price |
|
| 509 | + * @param mixed $arguments |
|
| 510 | + * @param bool $load_only |
|
| 511 | + * @return EEM_Base | bool |
|
| 512 | + * @throws EE_Error |
|
| 513 | + * @throws ReflectionException |
|
| 514 | + */ |
|
| 515 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 516 | + { |
|
| 517 | + $paths = apply_filters( |
|
| 518 | + 'FHEE__EE_Registry__load_model__paths', array( |
|
| 519 | + EE_MODELS, |
|
| 520 | + EE_CORE, |
|
| 521 | + ) |
|
| 522 | + ); |
|
| 523 | + // retrieve instantiated class |
|
| 524 | + return $this->_load( |
|
| 525 | + $paths, |
|
| 526 | + 'EEM_', |
|
| 527 | + $class_name, |
|
| 528 | + 'model', |
|
| 529 | + $arguments, |
|
| 530 | + false, |
|
| 531 | + true, |
|
| 532 | + $load_only |
|
| 533 | + ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * loads model classes - must be singletons |
|
| 540 | + * |
|
| 541 | + * @param string $class_name - simple class name ie: price |
|
| 542 | + * @param mixed $arguments |
|
| 543 | + * @param bool $load_only |
|
| 544 | + * @return mixed | bool |
|
| 545 | + * @throws EE_Error |
|
| 546 | + * @throws ReflectionException |
|
| 547 | + */ |
|
| 548 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 549 | + { |
|
| 550 | + $paths = array( |
|
| 551 | + EE_MODELS . 'fields' . DS, |
|
| 552 | + EE_MODELS . 'helpers' . DS, |
|
| 553 | + EE_MODELS . 'relations' . DS, |
|
| 554 | + EE_MODELS . 'strategies' . DS, |
|
| 555 | + ); |
|
| 556 | + // retrieve instantiated class |
|
| 557 | + return $this->_load( |
|
| 558 | + $paths, |
|
| 559 | + 'EE_', |
|
| 560 | + $class_name, |
|
| 561 | + '', |
|
| 562 | + $arguments, |
|
| 563 | + false, |
|
| 564 | + true, |
|
| 565 | + $load_only |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Determines if $model_name is the name of an actual EE model. |
|
| 573 | + * |
|
| 574 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 575 | + * @return boolean |
|
| 576 | + */ |
|
| 577 | + public function is_model_name($model_name) |
|
| 578 | + { |
|
| 579 | + return isset($this->models[$model_name]); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * generic class loader |
|
| 586 | + * |
|
| 587 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 588 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 589 | + * @param string $type - file type - core? class? helper? model? |
|
| 590 | + * @param mixed $arguments |
|
| 591 | + * @param bool $load_only |
|
| 592 | + * @return mixed |
|
| 593 | + * @throws EE_Error |
|
| 594 | + * @throws ReflectionException |
|
| 595 | + */ |
|
| 596 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 597 | + { |
|
| 598 | + // retrieve instantiated class |
|
| 599 | + return $this->_load( |
|
| 600 | + $path_to_file, |
|
| 601 | + '', |
|
| 602 | + $file_name, |
|
| 603 | + $type, |
|
| 604 | + $arguments, |
|
| 605 | + false, |
|
| 606 | + true, |
|
| 607 | + $load_only |
|
| 608 | + ); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 615 | + * @param string $class_name - full class name ie: My_Class |
|
| 616 | + * @param string $type - file type - core? class? helper? model? |
|
| 617 | + * @param mixed $arguments |
|
| 618 | + * @param bool $load_only |
|
| 619 | + * @return bool|EE_Addon|object |
|
| 620 | + * @throws EE_Error |
|
| 621 | + * @throws ReflectionException |
|
| 622 | + */ |
|
| 623 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 624 | + { |
|
| 625 | + // retrieve instantiated class |
|
| 626 | + return $this->_load( |
|
| 627 | + $path_to_file, |
|
| 628 | + 'addon', |
|
| 629 | + $class_name, |
|
| 630 | + $type, |
|
| 631 | + $arguments, |
|
| 632 | + false, |
|
| 633 | + true, |
|
| 634 | + $load_only |
|
| 635 | + ); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * instantiates, caches, and automatically resolves dependencies |
|
| 642 | + * for classes that use a Fully Qualified Class Name. |
|
| 643 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 644 | + * then you need to use one of the existing load_*() methods |
|
| 645 | + * which can resolve the classname and filepath from the passed arguments |
|
| 646 | + * |
|
| 647 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 648 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 649 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 650 | + * @param bool $from_db some classes are instantiated from the db |
|
| 651 | + * and thus call a different method to instantiate |
|
| 652 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 653 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 654 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
| 655 | + * object = class loaded and instantiated successfully. |
|
| 656 | + * bool = fail or success when $load_only is true |
|
| 657 | + * @throws EE_Error |
|
| 658 | + * @throws ReflectionException |
|
| 659 | + */ |
|
| 660 | + public function create( |
|
| 661 | + $class_name = false, |
|
| 662 | + $arguments = array(), |
|
| 663 | + $cache = false, |
|
| 664 | + $from_db = false, |
|
| 665 | + $load_only = false, |
|
| 666 | + $addon = false |
|
| 667 | + ) { |
|
| 668 | + $class_name = ltrim($class_name, '\\'); |
|
| 669 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 670 | + if (! class_exists($class_name)) { |
|
| 671 | + // maybe the class is registered with a preceding \ |
|
| 672 | + $class_name = strpos($class_name, '\\') !== 0 |
|
| 673 | + ? '\\' . $class_name |
|
| 674 | + : $class_name; |
|
| 675 | + // still doesn't exist ? |
|
| 676 | + if (! class_exists($class_name)) { |
|
| 677 | + return null; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 681 | + if ($load_only) { |
|
| 682 | + return true; |
|
| 683 | + } |
|
| 684 | + $addon = $addon |
|
| 685 | + ? 'addon' |
|
| 686 | + : ''; |
|
| 687 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 688 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 689 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 690 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 691 | + // return object if it's already cached |
|
| 692 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 693 | + if ($cached_class !== null) { |
|
| 694 | + return $cached_class; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + // instantiate the requested object |
|
| 698 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 699 | + if ($this->_cache_on && $cache) { |
|
| 700 | + // save it for later... kinda like gum { : $ |
|
| 701 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 702 | + } |
|
| 703 | + $this->_cache_on = true; |
|
| 704 | + return $class_obj; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * instantiates, caches, and injects dependencies for classes |
|
| 711 | + * |
|
| 712 | + * @param array $file_paths an array of paths to folders to look in |
|
| 713 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 714 | + * @param bool|string $class_name $class name |
|
| 715 | + * @param string $type file type - core? class? helper? model? |
|
| 716 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 717 | + * @param bool $from_db some classes are instantiated from the db |
|
| 718 | + * and thus call a different method to instantiate |
|
| 719 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 720 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 721 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
| 722 | + * object = class loaded and instantiated successfully. |
|
| 723 | + * bool = fail or success when $load_only is true |
|
| 724 | + * @throws EE_Error |
|
| 725 | + * @throws ReflectionException |
|
| 726 | + */ |
|
| 727 | + protected function _load( |
|
| 728 | + $file_paths = array(), |
|
| 729 | + $class_prefix = 'EE_', |
|
| 730 | + $class_name = false, |
|
| 731 | + $type = 'class', |
|
| 732 | + $arguments = array(), |
|
| 733 | + $from_db = false, |
|
| 734 | + $cache = true, |
|
| 735 | + $load_only = false |
|
| 736 | + ) { |
|
| 737 | + $class_name = ltrim($class_name, '\\'); |
|
| 738 | + // strip php file extension |
|
| 739 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 740 | + // does the class have a prefix ? |
|
| 741 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 742 | + // make sure $class_prefix is uppercase |
|
| 743 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 744 | + // add class prefix ONCE!!! |
|
| 745 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 746 | + } |
|
| 747 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 748 | + $class_exists = class_exists($class_name); |
|
| 749 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 750 | + if ($load_only && $class_exists) { |
|
| 751 | + return true; |
|
| 752 | + } |
|
| 753 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 754 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 755 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 756 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 757 | + // return object if it's already cached |
|
| 758 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 759 | + if ($cached_class !== null) { |
|
| 760 | + return $cached_class; |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 764 | + if (! $class_exists) { |
|
| 765 | + // get full path to file |
|
| 766 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 767 | + // load the file |
|
| 768 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 769 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 770 | + if (! $loaded || $load_only) { |
|
| 771 | + // return boolean if only loading, or null if an object was expected |
|
| 772 | + return $load_only |
|
| 773 | + ? $loaded |
|
| 774 | + : null; |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + // instantiate the requested object |
|
| 778 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 779 | + if ($this->_cache_on && $cache) { |
|
| 780 | + // save it for later... kinda like gum { : $ |
|
| 781 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 782 | + } |
|
| 783 | + $this->_cache_on = true; |
|
| 784 | + return $class_obj; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * attempts to find a cached version of the requested class |
|
| 791 | + * by looking in the following places: |
|
| 792 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 793 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 794 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 795 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 796 | + * |
|
| 797 | + * @param string $class_name |
|
| 798 | + * @param string $class_prefix |
|
| 799 | + * @return mixed |
|
| 800 | + */ |
|
| 801 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 802 | + { |
|
| 803 | + if ($class_name === 'EE_Registry') { |
|
| 804 | + return $this; |
|
| 805 | + } |
|
| 806 | + // have to specify something, but not anything that will conflict |
|
| 807 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
| 808 | + ? $this->_class_abbreviations[$class_name] |
|
| 809 | + : 'FANCY_BATMAN_PANTS'; |
|
| 810 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 811 | + // check if class has already been loaded, and return it if it has been |
|
| 812 | + if (isset($this->{$class_abbreviation})) { |
|
| 813 | + return $this->{$class_abbreviation}; |
|
| 814 | + } |
|
| 815 | + if (isset ($this->{$class_name})) { |
|
| 816 | + return $this->{$class_name}; |
|
| 817 | + } |
|
| 818 | + if (isset ($this->LIB->{$class_name})) { |
|
| 819 | + return $this->LIB->{$class_name}; |
|
| 820 | + } |
|
| 821 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 822 | + return $this->addons->{$class_name}; |
|
| 823 | + } |
|
| 824 | + return null; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * removes a cached version of the requested class |
|
| 831 | + * |
|
| 832 | + * @param string $class_name |
|
| 833 | + * @param boolean $addon |
|
| 834 | + * @return boolean |
|
| 835 | + */ |
|
| 836 | + public function clear_cached_class($class_name, $addon = false) |
|
| 837 | + { |
|
| 838 | + // have to specify something, but not anything that will conflict |
|
| 839 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
| 840 | + ? $this->_class_abbreviations[$class_name] |
|
| 841 | + : 'FANCY_BATMAN_PANTS'; |
|
| 842 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 843 | + // check if class has already been loaded, and return it if it has been |
|
| 844 | + if (isset($this->{$class_abbreviation})) { |
|
| 845 | + $this->{$class_abbreviation} = null; |
|
| 846 | + return true; |
|
| 847 | + } |
|
| 848 | + if (isset($this->{$class_name})) { |
|
| 849 | + $this->{$class_name} = null; |
|
| 850 | + return true; |
|
| 851 | + } |
|
| 852 | + if (isset($this->LIB->{$class_name})) { |
|
| 853 | + unset($this->LIB->{$class_name}); |
|
| 854 | + return true; |
|
| 855 | + } |
|
| 856 | + if ($addon && isset($this->addons->{$class_name})) { |
|
| 857 | + unset($this->addons->{$class_name}); |
|
| 858 | + return true; |
|
| 859 | + } |
|
| 860 | + return false; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * attempts to find a full valid filepath for the requested class. |
|
| 867 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 868 | + * then returns that path if the target file has been found and is readable |
|
| 869 | + * |
|
| 870 | + * @param string $class_name |
|
| 871 | + * @param string $type |
|
| 872 | + * @param array $file_paths |
|
| 873 | + * @return string | bool |
|
| 874 | + */ |
|
| 875 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 876 | + { |
|
| 877 | + // make sure $file_paths is an array |
|
| 878 | + $file_paths = is_array($file_paths) |
|
| 879 | + ? $file_paths |
|
| 880 | + : array($file_paths); |
|
| 881 | + // cycle thru paths |
|
| 882 | + foreach ($file_paths as $key => $file_path) { |
|
| 883 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 884 | + $file_path = $file_path |
|
| 885 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 886 | + : EE_CLASSES; |
|
| 887 | + // prep file type |
|
| 888 | + $type = ! empty($type) |
|
| 889 | + ? trim($type, '.') . '.' |
|
| 890 | + : ''; |
|
| 891 | + // build full file path |
|
| 892 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 893 | + //does the file exist and can be read ? |
|
| 894 | + if (is_readable($file_paths[$key])) { |
|
| 895 | + return $file_paths[$key]; |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + return false; |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * basically just performs a require_once() |
|
| 905 | + * but with some error handling |
|
| 906 | + * |
|
| 907 | + * @param string $path |
|
| 908 | + * @param string $class_name |
|
| 909 | + * @param string $type |
|
| 910 | + * @param array $file_paths |
|
| 911 | + * @return bool |
|
| 912 | + * @throws EE_Error |
|
| 913 | + * @throws ReflectionException |
|
| 914 | + */ |
|
| 915 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 916 | + { |
|
| 917 | + // don't give up! you gotta... |
|
| 918 | + try { |
|
| 919 | + //does the file exist and can it be read ? |
|
| 920 | + if (! $path) { |
|
| 921 | + // so sorry, can't find the file |
|
| 922 | + throw new EE_Error ( |
|
| 923 | + sprintf( |
|
| 924 | + esc_html__( |
|
| 925 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 926 | + 'event_espresso' |
|
| 927 | + ), |
|
| 928 | + trim($type, '.'), |
|
| 929 | + $class_name, |
|
| 930 | + '<br />' . implode(',<br />', $file_paths) |
|
| 931 | + ) |
|
| 932 | + ); |
|
| 933 | + } |
|
| 934 | + // get the file |
|
| 935 | + require_once($path); |
|
| 936 | + // if the class isn't already declared somewhere |
|
| 937 | + if (class_exists($class_name, false) === false) { |
|
| 938 | + // so sorry, not a class |
|
| 939 | + throw new EE_Error( |
|
| 940 | + sprintf( |
|
| 941 | + esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 942 | + $type, |
|
| 943 | + $path, |
|
| 944 | + $class_name |
|
| 945 | + ) |
|
| 946 | + ); |
|
| 947 | + } |
|
| 948 | + } catch (EE_Error $e) { |
|
| 949 | + $e->get_error(); |
|
| 950 | + return false; |
|
| 951 | + } |
|
| 952 | + return true; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * _create_object |
|
| 959 | + * Attempts to instantiate the requested class via any of the |
|
| 960 | + * commonly used instantiation methods employed throughout EE. |
|
| 961 | + * The priority for instantiation is as follows: |
|
| 962 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 963 | + * - model objects via their 'new_instance_from_db' method |
|
| 964 | + * - model objects via their 'new_instance' method |
|
| 965 | + * - "singleton" classes" via their 'instance' method |
|
| 966 | + * - standard instantiable classes via their __constructor |
|
| 967 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 968 | + * then the constructor for the requested class will be examined to determine |
|
| 969 | + * if any dependencies exist, and if they can be injected. |
|
| 970 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 971 | + * |
|
| 972 | + * @param string $class_name |
|
| 973 | + * @param array $arguments |
|
| 974 | + * @param string $type |
|
| 975 | + * @param bool $from_db |
|
| 976 | + * @return null|object |
|
| 977 | + * @throws EE_Error |
|
| 978 | + * @throws ReflectionException |
|
| 979 | + */ |
|
| 980 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 981 | + { |
|
| 982 | + $class_obj = null; |
|
| 983 | + $instantiation_mode = '0) none'; |
|
| 984 | + // don't give up! you gotta... |
|
| 985 | + try { |
|
| 986 | + // create reflection |
|
| 987 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 988 | + // make sure arguments are an array |
|
| 989 | + $arguments = is_array($arguments) |
|
| 990 | + ? $arguments |
|
| 991 | + : array($arguments); |
|
| 992 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 993 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 994 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 995 | + ? $arguments |
|
| 996 | + : array($arguments); |
|
| 997 | + // attempt to inject dependencies ? |
|
| 998 | + if ($this->_dependency_map->has($class_name)) { |
|
| 999 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1000 | + } |
|
| 1001 | + // instantiate the class if possible |
|
| 1002 | + if ($reflector->isAbstract()) { |
|
| 1003 | + // nothing to instantiate, loading file was enough |
|
| 1004 | + // does not throw an exception so $instantiation_mode is unused |
|
| 1005 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1006 | + $class_obj = true; |
|
| 1007 | + } else if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1008 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1009 | + $instantiation_mode = '2) no constructor but instantiable'; |
|
| 1010 | + $class_obj = $reflector->newInstance(); |
|
| 1011 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1012 | + $instantiation_mode = '3) new_instance_from_db()'; |
|
| 1013 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1014 | + } else if (method_exists($class_name, 'new_instance')) { |
|
| 1015 | + $instantiation_mode = '4) new_instance()'; |
|
| 1016 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1017 | + } else if (method_exists($class_name, 'instance')) { |
|
| 1018 | + $instantiation_mode = '5) instance()'; |
|
| 1019 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1020 | + } else if ($reflector->isInstantiable()) { |
|
| 1021 | + $instantiation_mode = '6) constructor'; |
|
| 1022 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
| 1023 | + } else { |
|
| 1024 | + // heh ? something's not right ! |
|
| 1025 | + throw new EE_Error( |
|
| 1026 | + sprintf( |
|
| 1027 | + esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1028 | + $type, |
|
| 1029 | + $class_name |
|
| 1030 | + ) |
|
| 1031 | + ); |
|
| 1032 | + } |
|
| 1033 | + } catch (Exception $e) { |
|
| 1034 | + if (! $e instanceof EE_Error) { |
|
| 1035 | + $e = new EE_Error( |
|
| 1036 | + sprintf( |
|
| 1037 | + esc_html__( |
|
| 1038 | + 'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', |
|
| 1039 | + 'event_espresso' |
|
| 1040 | + ), |
|
| 1041 | + $class_name, |
|
| 1042 | + '<br />', |
|
| 1043 | + $e->getMessage(), |
|
| 1044 | + $instantiation_mode |
|
| 1045 | + ) |
|
| 1046 | + ); |
|
| 1047 | + } |
|
| 1048 | + $e->get_error(); |
|
| 1049 | + } |
|
| 1050 | + return $class_obj; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + |
|
| 1055 | + /** |
|
| 1056 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1057 | + * @param array $array |
|
| 1058 | + * @return bool |
|
| 1059 | + */ |
|
| 1060 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1061 | + { |
|
| 1062 | + return ! empty($array) |
|
| 1063 | + ? array_keys($array) === range(0, count($array) - 1) |
|
| 1064 | + : true; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * getReflectionClass |
|
| 1071 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 1072 | + * and returns that instead of creating a new one |
|
| 1073 | + * |
|
| 1074 | + * @param string $class_name |
|
| 1075 | + * @return ReflectionClass |
|
| 1076 | + * @throws ReflectionException |
|
| 1077 | + */ |
|
| 1078 | + public function get_ReflectionClass($class_name) |
|
| 1079 | + { |
|
| 1080 | + if ( |
|
| 1081 | + ! isset($this->_reflectors[$class_name]) |
|
| 1082 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1083 | + ) { |
|
| 1084 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1085 | + } |
|
| 1086 | + return $this->_reflectors[$class_name]; |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + |
|
| 1091 | + /** |
|
| 1092 | + * _resolve_dependencies |
|
| 1093 | + * examines the constructor for the requested class to determine |
|
| 1094 | + * if any dependencies exist, and if they can be injected. |
|
| 1095 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1096 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1097 | + * For example: |
|
| 1098 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 1099 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1100 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1101 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 1102 | + * and the correct classes can be loaded |
|
| 1103 | + * |
|
| 1104 | + * @param ReflectionClass $reflector |
|
| 1105 | + * @param string $class_name |
|
| 1106 | + * @param array $arguments |
|
| 1107 | + * @return array |
|
| 1108 | + * @throws EE_Error |
|
| 1109 | + * @throws ReflectionException |
|
| 1110 | + */ |
|
| 1111 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1112 | + { |
|
| 1113 | + // let's examine the constructor |
|
| 1114 | + $constructor = $reflector->getConstructor(); |
|
| 1115 | + // whu? huh? nothing? |
|
| 1116 | + if (! $constructor) { |
|
| 1117 | + return $arguments; |
|
| 1118 | + } |
|
| 1119 | + // get constructor parameters |
|
| 1120 | + $params = $constructor->getParameters(); |
|
| 1121 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1122 | + $argument_keys = array_keys($arguments); |
|
| 1123 | + // now loop thru all of the constructors expected parameters |
|
| 1124 | + foreach ($params as $index => $param) { |
|
| 1125 | + // is this a dependency for a specific class ? |
|
| 1126 | + $param_class = $param->getClass() |
|
| 1127 | + ? $param->getClass()->name |
|
| 1128 | + : null; |
|
| 1129 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1130 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1131 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1132 | + : $param_class; |
|
| 1133 | + if ( |
|
| 1134 | + // param is not even a class |
|
| 1135 | + empty($param_class) |
|
| 1136 | + // and something already exists in the incoming arguments for this param |
|
| 1137 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1138 | + ) { |
|
| 1139 | + // so let's skip this argument and move on to the next |
|
| 1140 | + continue; |
|
| 1141 | + } |
|
| 1142 | + if ( |
|
| 1143 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1144 | + ! empty($param_class) |
|
| 1145 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1146 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1147 | + ) { |
|
| 1148 | + // skip this argument and move on to the next |
|
| 1149 | + continue; |
|
| 1150 | + } |
|
| 1151 | + if ( |
|
| 1152 | + // parameter is type hinted as a class, and should be injected |
|
| 1153 | + ! empty($param_class) |
|
| 1154 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1155 | + ) { |
|
| 1156 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
| 1157 | + } else { |
|
| 1158 | + try { |
|
| 1159 | + $arguments[$index] = $param->getDefaultValue(); |
|
| 1160 | + } catch (ReflectionException $e) { |
|
| 1161 | + throw new ReflectionException( |
|
| 1162 | + sprintf( |
|
| 1163 | + esc_html__('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
| 1164 | + $e->getMessage(), |
|
| 1165 | + $param->getName() |
|
| 1166 | + ) |
|
| 1167 | + ); |
|
| 1168 | + } |
|
| 1169 | + } |
|
| 1170 | + } |
|
| 1171 | + return $arguments; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * @param string $class_name |
|
| 1178 | + * @param string $param_class |
|
| 1179 | + * @param array $arguments |
|
| 1180 | + * @param mixed $index |
|
| 1181 | + * @return array |
|
| 1182 | + * @throws EE_Error |
|
| 1183 | + * @throws ReflectionException |
|
| 1184 | + */ |
|
| 1185 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
| 1186 | + { |
|
| 1187 | + $dependency = null; |
|
| 1188 | + // should dependency be loaded from cache ? |
|
| 1189 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
| 1190 | + !== EE_Dependency_Map::load_new_object; |
|
| 1191 | + // we might have a dependency... |
|
| 1192 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1193 | + $cached_class = $cache_on |
|
| 1194 | + ? $this->_get_cached_class($param_class) |
|
| 1195 | + : null; |
|
| 1196 | + // and grab it if it exists |
|
| 1197 | + if ($cached_class instanceof $param_class) { |
|
| 1198 | + $dependency = $cached_class; |
|
| 1199 | + } else if ($param_class !== $class_name) { |
|
| 1200 | + // obtain the loader method from the dependency map |
|
| 1201 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1202 | + // is loader a custom closure ? |
|
| 1203 | + if ($loader instanceof Closure) { |
|
| 1204 | + $dependency = $loader(); |
|
| 1205 | + } else { |
|
| 1206 | + // set the cache on property for the recursive loading call |
|
| 1207 | + $this->_cache_on = $cache_on; |
|
| 1208 | + // if not, then let's try and load it via the registry |
|
| 1209 | + if ($loader && method_exists($this, $loader)) { |
|
| 1210 | + $dependency = $this->{$loader}($param_class); |
|
| 1211 | + } else { |
|
| 1212 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + // did we successfully find the correct dependency ? |
|
| 1217 | + if ($dependency instanceof $param_class) { |
|
| 1218 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1219 | + if (isset($argument_keys[$index])) { |
|
| 1220 | + $arguments[$argument_keys[$index]] = $dependency; |
|
| 1221 | + } else { |
|
| 1222 | + $arguments[$index] = $dependency; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + return $arguments; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * _set_cached_class |
|
| 1232 | + * attempts to cache the instantiated class locally |
|
| 1233 | + * in one of the following places, in the following order: |
|
| 1234 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1235 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1236 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1237 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1238 | + * |
|
| 1239 | + * @param object $class_obj |
|
| 1240 | + * @param string $class_name |
|
| 1241 | + * @param string $class_prefix |
|
| 1242 | + * @param bool $from_db |
|
| 1243 | + * @return void |
|
| 1244 | + */ |
|
| 1245 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1246 | + { |
|
| 1247 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1248 | + return; |
|
| 1249 | + } |
|
| 1250 | + // return newly instantiated class |
|
| 1251 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
| 1252 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
| 1253 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1254 | + return; |
|
| 1255 | + } |
|
| 1256 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1257 | + if (property_exists($this, $class_name)) { |
|
| 1258 | + $this->{$class_name} = $class_obj; |
|
| 1259 | + return; |
|
| 1260 | + } |
|
| 1261 | + if ($class_prefix === 'addon') { |
|
| 1262 | + $this->addons->{$class_name} = $class_obj; |
|
| 1263 | + return; |
|
| 1264 | + } |
|
| 1265 | + if (! $from_db) { |
|
| 1266 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + |
|
| 1271 | + |
|
| 1272 | + /** |
|
| 1273 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1274 | + * |
|
| 1275 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1276 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1277 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1278 | + * @param array $arguments |
|
| 1279 | + * @return object |
|
| 1280 | + */ |
|
| 1281 | + public static function factory($classname, $arguments = array()) |
|
| 1282 | + { |
|
| 1283 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1284 | + if ($loader instanceof Closure) { |
|
| 1285 | + return $loader($arguments); |
|
| 1286 | + } |
|
| 1287 | + if (method_exists(self::instance(), $loader)) { |
|
| 1288 | + return self::instance()->{$loader}($classname, $arguments); |
|
| 1289 | + } |
|
| 1290 | + return null; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + |
|
| 1295 | + /** |
|
| 1296 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1297 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
| 1298 | + * |
|
| 1299 | + * @param string $name |
|
| 1300 | + * @return EE_Addon |
|
| 1301 | + */ |
|
| 1302 | + public function get_addon_by_name($name) |
|
| 1303 | + { |
|
| 1304 | + foreach ($this->addons as $addon) { |
|
| 1305 | + if ($addon->name() === $name) { |
|
| 1306 | + return $addon; |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + return null; |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + |
|
| 1313 | + |
|
| 1314 | + /** |
|
| 1315 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
|
| 1316 | + * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
|
| 1317 | + * name is the addon's classname. So if you just want to get the addon by classname, use |
|
| 1318 | + * EE_Config::instance()->addons->{classname} |
|
| 1319 | + * |
|
| 1320 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1321 | + */ |
|
| 1322 | + public function get_addons_by_name() |
|
| 1323 | + { |
|
| 1324 | + $addons = array(); |
|
| 1325 | + foreach ($this->addons as $addon) { |
|
| 1326 | + $addons[$addon->name()] = $addon; |
|
| 1327 | + } |
|
| 1328 | + return $addons; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + |
|
| 1333 | + /** |
|
| 1334 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1335 | + * a stale copy of it around |
|
| 1336 | + * |
|
| 1337 | + * @param string $model_name |
|
| 1338 | + * @return \EEM_Base |
|
| 1339 | + * @throws \EE_Error |
|
| 1340 | + */ |
|
| 1341 | + public function reset_model($model_name) |
|
| 1342 | + { |
|
| 1343 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1344 | + ? "EEM_{$model_name}" |
|
| 1345 | + : $model_name; |
|
| 1346 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1347 | + return null; |
|
| 1348 | + } |
|
| 1349 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1350 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1351 | + && is_callable( |
|
| 1352 | + array($model_class_name, 'reset') |
|
| 1353 | + )) { |
|
| 1354 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1355 | + } else { |
|
| 1356 | + throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1357 | + } |
|
| 1358 | + return $this->LIB->{$model_class_name}; |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * Resets the registry. |
|
| 1365 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1366 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1367 | + * - $_dependency_map |
|
| 1368 | + * - $_class_abbreviations |
|
| 1369 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1370 | + * - $REQ: Still on the same request so no need to change. |
|
| 1371 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1372 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1373 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1374 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1375 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1376 | + * switch or on the restore. |
|
| 1377 | + * - $modules |
|
| 1378 | + * - $shortcodes |
|
| 1379 | + * - $widgets |
|
| 1380 | + * |
|
| 1381 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
| 1382 | + * the Registry to its state at the beginning of the request |
|
| 1383 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1384 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1385 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1386 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1387 | + * client |
|
| 1388 | + * code instead can just change the model context to a different blog id if |
|
| 1389 | + * necessary |
|
| 1390 | + * @return EE_Registry |
|
| 1391 | + * @throws EE_Error |
|
| 1392 | + * @throws ReflectionException |
|
| 1393 | + */ |
|
| 1394 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1395 | + { |
|
| 1396 | + $instance = self::instance(); |
|
| 1397 | + $instance->_cache_on = true; |
|
| 1398 | + // reset some "special" classes |
|
| 1399 | + EEH_Activation::reset(); |
|
| 1400 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1401 | + $instance->CART = null; |
|
| 1402 | + $instance->MRM = null; |
|
| 1403 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1404 | + //messages reset |
|
| 1405 | + EED_Messages::reset(); |
|
| 1406 | + //handle of objects cached on LIB |
|
| 1407 | + foreach (array('LIB', 'modules') as $cache) { |
|
| 1408 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1409 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1410 | + unset($instance->{$cache}->{$class_name}); |
|
| 1411 | + } |
|
| 1412 | + } |
|
| 1413 | + } |
|
| 1414 | + return $instance; |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + |
|
| 1418 | + |
|
| 1419 | + /** |
|
| 1420 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1421 | + * if passed object implements InterminableInterface, then return false, |
|
| 1422 | + * to indicate that it should NOT be cleared from the Registry cache |
|
| 1423 | + * |
|
| 1424 | + * @param $object |
|
| 1425 | + * @param bool $reset_models |
|
| 1426 | + * @return bool returns true if cached object should be unset |
|
| 1427 | + */ |
|
| 1428 | + private static function _reset_and_unset_object($object, $reset_models) |
|
| 1429 | + { |
|
| 1430 | + if (! is_object($object)) { |
|
| 1431 | + // don't unset anything that's not an object |
|
| 1432 | + return false; |
|
| 1433 | + } |
|
| 1434 | + if ($object instanceof EED_Module) { |
|
| 1435 | + $object::reset(); |
|
| 1436 | + // don't unset modules |
|
| 1437 | + return false; |
|
| 1438 | + } |
|
| 1439 | + if ($object instanceof ResettableInterface) { |
|
| 1440 | + if ($object instanceof EEM_Base) { |
|
| 1441 | + if ($reset_models) { |
|
| 1442 | + $object->reset(); |
|
| 1443 | + return true; |
|
| 1444 | + } |
|
| 1445 | + return false; |
|
| 1446 | + } |
|
| 1447 | + $object->reset(); |
|
| 1448 | + return true; |
|
| 1449 | + } |
|
| 1450 | + if (! $object instanceof InterminableInterface) { |
|
| 1451 | + return true; |
|
| 1452 | + } |
|
| 1453 | + return false; |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + |
|
| 1457 | + |
|
| 1458 | + /** |
|
| 1459 | + * Gets all the custom post type models defined |
|
| 1460 | + * |
|
| 1461 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1462 | + */ |
|
| 1463 | + public function cpt_models() |
|
| 1464 | + { |
|
| 1465 | + $cpt_models = array(); |
|
| 1466 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1467 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1468 | + $cpt_models[$short_name] = $classname; |
|
| 1469 | + } |
|
| 1470 | + } |
|
| 1471 | + return $cpt_models; |
|
| 1472 | + } |
|
| 1473 | + |
|
| 1474 | + |
|
| 1475 | + |
|
| 1476 | + /** |
|
| 1477 | + * @return \EE_Config |
|
| 1478 | + */ |
|
| 1479 | + public static function CFG() |
|
| 1480 | + { |
|
| 1481 | + return self::instance()->CFG; |
|
| 1482 | + } |
|
| 1483 | 1483 | |
| 1484 | 1484 | |
| 1485 | 1485 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | public static function instance(EE_Dependency_Map $dependency_map = null) |
| 172 | 172 | { |
| 173 | 173 | // check if class object is instantiated |
| 174 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 174 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
| 175 | 175 | self::$_instance = new self($dependency_map); |
| 176 | 176 | } |
| 177 | 177 | return self::$_instance; |
@@ -258,13 +258,13 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public static function localize_i18n_js_strings() |
| 260 | 260 | { |
| 261 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 261 | + $i18n_js_strings = (array) self::$i18n_js_strings; |
|
| 262 | 262 | foreach ($i18n_js_strings as $key => $value) { |
| 263 | 263 | if (is_scalar($value)) { |
| 264 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 264 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 267 | + return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $module_class = get_class($module); |
| 281 | 281 | $this->modules->{$module_class} = $module; |
| 282 | 282 | } else { |
| 283 | - if (! class_exists('EE_Module_Request_Router')) { |
|
| 283 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
| 284 | 284 | $this->load_core('Module_Request_Router'); |
| 285 | 285 | } |
| 286 | 286 | EE_Module_Request_Router::module_factory($module); |
@@ -320,10 +320,10 @@ discard block |
||
| 320 | 320 | EE_CORE, |
| 321 | 321 | EE_ADMIN, |
| 322 | 322 | EE_CPTS, |
| 323 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 324 | - EE_CORE . 'capabilities' . DS, |
|
| 325 | - EE_CORE . 'request_stack' . DS, |
|
| 326 | - EE_CORE . 'middleware' . DS, |
|
| 323 | + EE_CORE.'data_migration_scripts'.DS, |
|
| 324 | + EE_CORE.'capabilities'.DS, |
|
| 325 | + EE_CORE.'request_stack'.DS, |
|
| 326 | + EE_CORE.'middleware'.DS, |
|
| 327 | 327 | ) |
| 328 | 328 | ); |
| 329 | 329 | // retrieve instantiated class |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | $service_paths = apply_filters( |
| 357 | 357 | 'FHEE__EE_Registry__load_service__service_paths', |
| 358 | 358 | array( |
| 359 | - EE_CORE . 'services' . DS, |
|
| 359 | + EE_CORE.'services'.DS, |
|
| 360 | 360 | ) |
| 361 | 361 | ); |
| 362 | 362 | // retrieve instantiated class |
@@ -482,10 +482,10 @@ discard block |
||
| 482 | 482 | { |
| 483 | 483 | $paths = array( |
| 484 | 484 | EE_LIBRARIES, |
| 485 | - EE_LIBRARIES . 'messages' . DS, |
|
| 486 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 487 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 488 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 485 | + EE_LIBRARIES.'messages'.DS, |
|
| 486 | + EE_LIBRARIES.'shortcodes'.DS, |
|
| 487 | + EE_LIBRARIES.'qtips'.DS, |
|
| 488 | + EE_LIBRARIES.'payment_methods'.DS, |
|
| 489 | 489 | ); |
| 490 | 490 | // retrieve instantiated class |
| 491 | 491 | return $this->_load( |
@@ -548,10 +548,10 @@ discard block |
||
| 548 | 548 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
| 549 | 549 | { |
| 550 | 550 | $paths = array( |
| 551 | - EE_MODELS . 'fields' . DS, |
|
| 552 | - EE_MODELS . 'helpers' . DS, |
|
| 553 | - EE_MODELS . 'relations' . DS, |
|
| 554 | - EE_MODELS . 'strategies' . DS, |
|
| 551 | + EE_MODELS.'fields'.DS, |
|
| 552 | + EE_MODELS.'helpers'.DS, |
|
| 553 | + EE_MODELS.'relations'.DS, |
|
| 554 | + EE_MODELS.'strategies'.DS, |
|
| 555 | 555 | ); |
| 556 | 556 | // retrieve instantiated class |
| 557 | 557 | return $this->_load( |
@@ -667,13 +667,13 @@ discard block |
||
| 667 | 667 | ) { |
| 668 | 668 | $class_name = ltrim($class_name, '\\'); |
| 669 | 669 | $class_name = $this->_dependency_map->get_alias($class_name); |
| 670 | - if (! class_exists($class_name)) { |
|
| 670 | + if ( ! class_exists($class_name)) { |
|
| 671 | 671 | // maybe the class is registered with a preceding \ |
| 672 | 672 | $class_name = strpos($class_name, '\\') !== 0 |
| 673 | - ? '\\' . $class_name |
|
| 673 | + ? '\\'.$class_name |
|
| 674 | 674 | : $class_name; |
| 675 | 675 | // still doesn't exist ? |
| 676 | - if (! class_exists($class_name)) { |
|
| 676 | + if ( ! class_exists($class_name)) { |
|
| 677 | 677 | return null; |
| 678 | 678 | } |
| 679 | 679 | } |
@@ -738,11 +738,11 @@ discard block |
||
| 738 | 738 | // strip php file extension |
| 739 | 739 | $class_name = str_replace('.php', '', trim($class_name)); |
| 740 | 740 | // does the class have a prefix ? |
| 741 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 741 | + if ( ! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 742 | 742 | // make sure $class_prefix is uppercase |
| 743 | 743 | $class_prefix = strtoupper(trim($class_prefix)); |
| 744 | 744 | // add class prefix ONCE!!! |
| 745 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 745 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
| 746 | 746 | } |
| 747 | 747 | $class_name = $this->_dependency_map->get_alias($class_name); |
| 748 | 748 | $class_exists = class_exists($class_name); |
@@ -761,13 +761,13 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | } |
| 763 | 763 | // if the class doesn't already exist.. then we need to try and find the file and load it |
| 764 | - if (! $class_exists) { |
|
| 764 | + if ( ! $class_exists) { |
|
| 765 | 765 | // get full path to file |
| 766 | 766 | $path = $this->_resolve_path($class_name, $type, $file_paths); |
| 767 | 767 | // load the file |
| 768 | 768 | $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
| 769 | 769 | // if loading failed, or we are only loading a file but NOT instantiating an object |
| 770 | - if (! $loaded || $load_only) { |
|
| 770 | + if ( ! $loaded || $load_only) { |
|
| 771 | 771 | // return boolean if only loading, or null if an object was expected |
| 772 | 772 | return $load_only |
| 773 | 773 | ? $loaded |
@@ -886,10 +886,10 @@ discard block |
||
| 886 | 886 | : EE_CLASSES; |
| 887 | 887 | // prep file type |
| 888 | 888 | $type = ! empty($type) |
| 889 | - ? trim($type, '.') . '.' |
|
| 889 | + ? trim($type, '.').'.' |
|
| 890 | 890 | : ''; |
| 891 | 891 | // build full file path |
| 892 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 892 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
| 893 | 893 | //does the file exist and can be read ? |
| 894 | 894 | if (is_readable($file_paths[$key])) { |
| 895 | 895 | return $file_paths[$key]; |
@@ -917,9 +917,9 @@ discard block |
||
| 917 | 917 | // don't give up! you gotta... |
| 918 | 918 | try { |
| 919 | 919 | //does the file exist and can it be read ? |
| 920 | - if (! $path) { |
|
| 920 | + if ( ! $path) { |
|
| 921 | 921 | // so sorry, can't find the file |
| 922 | - throw new EE_Error ( |
|
| 922 | + throw new EE_Error( |
|
| 923 | 923 | sprintf( |
| 924 | 924 | esc_html__( |
| 925 | 925 | 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | ), |
| 928 | 928 | trim($type, '.'), |
| 929 | 929 | $class_name, |
| 930 | - '<br />' . implode(',<br />', $file_paths) |
|
| 930 | + '<br />'.implode(',<br />', $file_paths) |
|
| 931 | 931 | ) |
| 932 | 932 | ); |
| 933 | 933 | } |
@@ -1031,7 +1031,7 @@ discard block |
||
| 1031 | 1031 | ); |
| 1032 | 1032 | } |
| 1033 | 1033 | } catch (Exception $e) { |
| 1034 | - if (! $e instanceof EE_Error) { |
|
| 1034 | + if ( ! $e instanceof EE_Error) { |
|
| 1035 | 1035 | $e = new EE_Error( |
| 1036 | 1036 | sprintf( |
| 1037 | 1037 | esc_html__( |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | // let's examine the constructor |
| 1114 | 1114 | $constructor = $reflector->getConstructor(); |
| 1115 | 1115 | // whu? huh? nothing? |
| 1116 | - if (! $constructor) { |
|
| 1116 | + if ( ! $constructor) { |
|
| 1117 | 1117 | return $arguments; |
| 1118 | 1118 | } |
| 1119 | 1119 | // get constructor parameters |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | $this->addons->{$class_name} = $class_obj; |
| 1263 | 1263 | return; |
| 1264 | 1264 | } |
| 1265 | - if (! $from_db) { |
|
| 1265 | + if ( ! $from_db) { |
|
| 1266 | 1266 | $this->LIB->{$class_name} = $class_obj; |
| 1267 | 1267 | } |
| 1268 | 1268 | } |
@@ -1343,7 +1343,7 @@ discard block |
||
| 1343 | 1343 | $model_class_name = strpos($model_name, 'EEM_') !== 0 |
| 1344 | 1344 | ? "EEM_{$model_name}" |
| 1345 | 1345 | : $model_name; |
| 1346 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1346 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1347 | 1347 | return null; |
| 1348 | 1348 | } |
| 1349 | 1349 | //get that model reset it and make sure we nuke the old reference to it |
@@ -1427,7 +1427,7 @@ discard block |
||
| 1427 | 1427 | */ |
| 1428 | 1428 | private static function _reset_and_unset_object($object, $reset_models) |
| 1429 | 1429 | { |
| 1430 | - if (! is_object($object)) { |
|
| 1430 | + if ( ! is_object($object)) { |
|
| 1431 | 1431 | // don't unset anything that's not an object |
| 1432 | 1432 | return false; |
| 1433 | 1433 | } |
@@ -1447,7 +1447,7 @@ discard block |
||
| 1447 | 1447 | $object->reset(); |
| 1448 | 1448 | return true; |
| 1449 | 1449 | } |
| 1450 | - if (! $object instanceof InterminableInterface) { |
|
| 1450 | + if ( ! $object instanceof InterminableInterface) { |
|
| 1451 | 1451 | return true; |
| 1452 | 1452 | } |
| 1453 | 1453 | return false; |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\interfaces\InterminableInterface; |
| 4 | 4 | |
| 5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 6 | - exit('No direct script access allowed'); |
|
| 6 | + exit('No direct script access allowed'); |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | /** |
@@ -26,336 +26,336 @@ discard block |
||
| 26 | 26 | final class EE_Admin implements InterminableInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @access private |
|
| 31 | - * @var EE_Admin $_instance |
|
| 32 | - */ |
|
| 33 | - private static $_instance; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - *@ singleton method used to instantiate class object |
|
| 38 | - *@ access public |
|
| 39 | - *@ return class instance |
|
| 40 | - * |
|
| 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 | - */ |
|
| 56 | - public static function reset() |
|
| 57 | - { |
|
| 58 | - self::$_instance = null; |
|
| 59 | - return self::instance(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * class constructor |
|
| 65 | - * |
|
| 66 | - * @throws \EE_Error |
|
| 67 | - */ |
|
| 68 | - protected function __construct() |
|
| 69 | - { |
|
| 70 | - // define global EE_Admin constants |
|
| 71 | - $this->_define_all_constants(); |
|
| 72 | - // set autoloaders for our admin page classes based on included path information |
|
| 73 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 74 | - // admin hooks |
|
| 75 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 76 | - // load EE_Request_Handler early |
|
| 77 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 78 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 79 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 80 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 81 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 82 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 83 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 84 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 85 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 86 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 87 | - |
|
| 88 | - //reset Environment config (we only do this on admin page loads); |
|
| 89 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 90 | - |
|
| 91 | - do_action('AHEE__EE_Admin__loaded'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * _define_all_constants |
|
| 97 | - * define constants that are set globally for all admin pages |
|
| 98 | - * |
|
| 99 | - * @access private |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - private function _define_all_constants() |
|
| 103 | - { |
|
| 104 | - if (! defined('EE_ADMIN_URL')) { |
|
| 105 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 106 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 107 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 108 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 109 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
| 116 | - * |
|
| 117 | - * @access public |
|
| 118 | - * @param array $links |
|
| 119 | - * @param string $plugin |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function filter_plugin_actions($links, $plugin) |
|
| 123 | - { |
|
| 124 | - // set $main_file in stone |
|
| 125 | - static $main_file; |
|
| 126 | - // if $main_file is not set yet |
|
| 127 | - if (! $main_file) { |
|
| 128 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 129 | - } |
|
| 130 | - if ($plugin === $main_file) { |
|
| 131 | - // compare current plugin to this one |
|
| 132 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 133 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">' . __('Maintenance Mode Active', |
|
| 134 | - 'event_espresso') . '</a>'; |
|
| 135 | - array_unshift($links, $maintenance_link); |
|
| 136 | - } else { |
|
| 137 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __('Settings', |
|
| 138 | - 'event_espresso') . '</a>'; |
|
| 139 | - $events_link = '<a href="admin.php?page=espresso_events">' . __('Events', |
|
| 140 | - 'event_espresso') . '</a>'; |
|
| 141 | - // add before other links |
|
| 142 | - array_unshift($links, $org_settings_link, $events_link); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - return $links; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * _get_request |
|
| 151 | - * |
|
| 152 | - * @access public |
|
| 153 | - * @return void |
|
| 154 | - */ |
|
| 155 | - public function get_request() |
|
| 156 | - { |
|
| 157 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 158 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * hide_admin_pages_except_maintenance_mode |
|
| 164 | - * |
|
| 165 | - * @access public |
|
| 166 | - * @param array $admin_page_folder_names |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 169 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 170 | - { |
|
| 171 | - return array( |
|
| 172 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 173 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 174 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 175 | - ); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 181 | - * EE_Front_Controller's init phases have run |
|
| 182 | - * |
|
| 183 | - * @access public |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - public function init() |
|
| 187 | - { |
|
| 188 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 189 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 190 | - //ok so we want to enable the entire admin |
|
| 191 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 192 | - add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 193 | - add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 194 | - //at a glance dashboard widget |
|
| 195 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 196 | - //filter for get_edit_post_link used on comments for custom post types |
|
| 197 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 198 | - } |
|
| 199 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 200 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 201 | - try { |
|
| 202 | - //this loads the controller for the admin pages which will setup routing etc |
|
| 203 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 204 | - } catch (EE_Error $e) { |
|
| 205 | - $e->get_error(); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 209 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 210 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 211 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 212 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 213 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 219 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 220 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 221 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 222 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 223 | - * |
|
| 224 | - * @param object $post_type WP post type object |
|
| 225 | - * @return object WP post type object |
|
| 226 | - */ |
|
| 227 | - public function remove_pages_from_nav_menu($post_type) |
|
| 228 | - { |
|
| 229 | - //if this isn't the "pages" post type let's get out |
|
| 230 | - if ($post_type->name !== 'page') { |
|
| 231 | - return $post_type; |
|
| 232 | - } |
|
| 233 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 234 | - |
|
| 235 | - $post_type->_default_query = array( |
|
| 236 | - 'post__not_in' => $critical_pages, |
|
| 237 | - ); |
|
| 238 | - return $post_type; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 244 | - * metaboxes get shown as well |
|
| 245 | - * |
|
| 246 | - * @access public |
|
| 247 | - * @return void |
|
| 248 | - */ |
|
| 249 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 250 | - { |
|
| 251 | - global $wp_meta_boxes, $pagenow; |
|
| 252 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 253 | - return; |
|
| 254 | - } |
|
| 255 | - $user = wp_get_current_user(); |
|
| 256 | - //has this been done yet? |
|
| 257 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 258 | - return; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 262 | - $initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 263 | - array( |
|
| 264 | - 'nav-menu-theme-locations', |
|
| 265 | - 'add-page', |
|
| 266 | - 'add-custom-links', |
|
| 267 | - 'add-category', |
|
| 268 | - 'add-espresso_events', |
|
| 269 | - 'add-espresso_venues', |
|
| 270 | - 'add-espresso_event_categories', |
|
| 271 | - 'add-espresso_venue_categories', |
|
| 272 | - 'add-post-type-post', |
|
| 273 | - 'add-post-type-page', |
|
| 274 | - )); |
|
| 275 | - |
|
| 276 | - if (is_array($hidden_meta_boxes)) { |
|
| 277 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | - if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | - unset($hidden_meta_boxes[$key]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | - * |
|
| 293 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | - * addons etc. |
|
| 295 | - * @access public |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - public function register_custom_nav_menu_boxes() |
|
| 299 | - { |
|
| 300 | - add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), |
|
| 301 | - array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core'); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 307 | - * |
|
| 308 | - * @since 4.3.0 |
|
| 309 | - * @param string $link the original link generated by wp |
|
| 310 | - * @param int $id post id |
|
| 311 | - * @return string the (maybe) modified link |
|
| 312 | - */ |
|
| 313 | - public function modify_edit_post_link($link, $id) |
|
| 314 | - { |
|
| 315 | - if (! $post = get_post($id)) { |
|
| 316 | - return $link; |
|
| 317 | - } |
|
| 318 | - if ($post->post_type === 'espresso_attendees') { |
|
| 319 | - $query_args = array( |
|
| 320 | - 'action' => 'edit_attendee', |
|
| 321 | - 'post' => $id, |
|
| 322 | - ); |
|
| 323 | - return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations')); |
|
| 324 | - } |
|
| 325 | - return $link; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - public function ee_cpt_archive_pages() |
|
| 330 | - { |
|
| 331 | - global $nav_menu_selected_id; |
|
| 332 | - |
|
| 333 | - $db_fields = false; |
|
| 334 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 335 | - $current_tab = 'event-archives'; |
|
| 336 | - |
|
| 337 | - /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 29 | + /** |
|
| 30 | + * @access private |
|
| 31 | + * @var EE_Admin $_instance |
|
| 32 | + */ |
|
| 33 | + private static $_instance; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + *@ singleton method used to instantiate class object |
|
| 38 | + *@ access public |
|
| 39 | + *@ return class instance |
|
| 40 | + * |
|
| 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 | + */ |
|
| 56 | + public static function reset() |
|
| 57 | + { |
|
| 58 | + self::$_instance = null; |
|
| 59 | + return self::instance(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * class constructor |
|
| 65 | + * |
|
| 66 | + * @throws \EE_Error |
|
| 67 | + */ |
|
| 68 | + protected function __construct() |
|
| 69 | + { |
|
| 70 | + // define global EE_Admin constants |
|
| 71 | + $this->_define_all_constants(); |
|
| 72 | + // set autoloaders for our admin page classes based on included path information |
|
| 73 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 74 | + // admin hooks |
|
| 75 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 76 | + // load EE_Request_Handler early |
|
| 77 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 78 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 79 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 80 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 81 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 82 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 83 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 84 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 85 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 86 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 87 | + |
|
| 88 | + //reset Environment config (we only do this on admin page loads); |
|
| 89 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 90 | + |
|
| 91 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * _define_all_constants |
|
| 97 | + * define constants that are set globally for all admin pages |
|
| 98 | + * |
|
| 99 | + * @access private |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + private function _define_all_constants() |
|
| 103 | + { |
|
| 104 | + if (! defined('EE_ADMIN_URL')) { |
|
| 105 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 106 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 107 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 108 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 109 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
| 116 | + * |
|
| 117 | + * @access public |
|
| 118 | + * @param array $links |
|
| 119 | + * @param string $plugin |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function filter_plugin_actions($links, $plugin) |
|
| 123 | + { |
|
| 124 | + // set $main_file in stone |
|
| 125 | + static $main_file; |
|
| 126 | + // if $main_file is not set yet |
|
| 127 | + if (! $main_file) { |
|
| 128 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 129 | + } |
|
| 130 | + if ($plugin === $main_file) { |
|
| 131 | + // compare current plugin to this one |
|
| 132 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 133 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">' . __('Maintenance Mode Active', |
|
| 134 | + 'event_espresso') . '</a>'; |
|
| 135 | + array_unshift($links, $maintenance_link); |
|
| 136 | + } else { |
|
| 137 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __('Settings', |
|
| 138 | + 'event_espresso') . '</a>'; |
|
| 139 | + $events_link = '<a href="admin.php?page=espresso_events">' . __('Events', |
|
| 140 | + 'event_espresso') . '</a>'; |
|
| 141 | + // add before other links |
|
| 142 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + return $links; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * _get_request |
|
| 151 | + * |
|
| 152 | + * @access public |
|
| 153 | + * @return void |
|
| 154 | + */ |
|
| 155 | + public function get_request() |
|
| 156 | + { |
|
| 157 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 158 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * hide_admin_pages_except_maintenance_mode |
|
| 164 | + * |
|
| 165 | + * @access public |
|
| 166 | + * @param array $admin_page_folder_names |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 170 | + { |
|
| 171 | + return array( |
|
| 172 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 173 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 174 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 181 | + * EE_Front_Controller's init phases have run |
|
| 182 | + * |
|
| 183 | + * @access public |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + public function init() |
|
| 187 | + { |
|
| 188 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 189 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 190 | + //ok so we want to enable the entire admin |
|
| 191 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 192 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 193 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 194 | + //at a glance dashboard widget |
|
| 195 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 196 | + //filter for get_edit_post_link used on comments for custom post types |
|
| 197 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 198 | + } |
|
| 199 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 200 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 201 | + try { |
|
| 202 | + //this loads the controller for the admin pages which will setup routing etc |
|
| 203 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 204 | + } catch (EE_Error $e) { |
|
| 205 | + $e->get_error(); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 209 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 210 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 211 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 212 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 213 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 219 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 220 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 221 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 222 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 223 | + * |
|
| 224 | + * @param object $post_type WP post type object |
|
| 225 | + * @return object WP post type object |
|
| 226 | + */ |
|
| 227 | + public function remove_pages_from_nav_menu($post_type) |
|
| 228 | + { |
|
| 229 | + //if this isn't the "pages" post type let's get out |
|
| 230 | + if ($post_type->name !== 'page') { |
|
| 231 | + return $post_type; |
|
| 232 | + } |
|
| 233 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 234 | + |
|
| 235 | + $post_type->_default_query = array( |
|
| 236 | + 'post__not_in' => $critical_pages, |
|
| 237 | + ); |
|
| 238 | + return $post_type; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 244 | + * metaboxes get shown as well |
|
| 245 | + * |
|
| 246 | + * @access public |
|
| 247 | + * @return void |
|
| 248 | + */ |
|
| 249 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 250 | + { |
|
| 251 | + global $wp_meta_boxes, $pagenow; |
|
| 252 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | + $user = wp_get_current_user(); |
|
| 256 | + //has this been done yet? |
|
| 257 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 258 | + return; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 262 | + $initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 263 | + array( |
|
| 264 | + 'nav-menu-theme-locations', |
|
| 265 | + 'add-page', |
|
| 266 | + 'add-custom-links', |
|
| 267 | + 'add-category', |
|
| 268 | + 'add-espresso_events', |
|
| 269 | + 'add-espresso_venues', |
|
| 270 | + 'add-espresso_event_categories', |
|
| 271 | + 'add-espresso_venue_categories', |
|
| 272 | + 'add-post-type-post', |
|
| 273 | + 'add-post-type-page', |
|
| 274 | + )); |
|
| 275 | + |
|
| 276 | + if (is_array($hidden_meta_boxes)) { |
|
| 277 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | + unset($hidden_meta_boxes[$key]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | + * |
|
| 293 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | + * addons etc. |
|
| 295 | + * @access public |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + public function register_custom_nav_menu_boxes() |
|
| 299 | + { |
|
| 300 | + add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), |
|
| 301 | + array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core'); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 307 | + * |
|
| 308 | + * @since 4.3.0 |
|
| 309 | + * @param string $link the original link generated by wp |
|
| 310 | + * @param int $id post id |
|
| 311 | + * @return string the (maybe) modified link |
|
| 312 | + */ |
|
| 313 | + public function modify_edit_post_link($link, $id) |
|
| 314 | + { |
|
| 315 | + if (! $post = get_post($id)) { |
|
| 316 | + return $link; |
|
| 317 | + } |
|
| 318 | + if ($post->post_type === 'espresso_attendees') { |
|
| 319 | + $query_args = array( |
|
| 320 | + 'action' => 'edit_attendee', |
|
| 321 | + 'post' => $id, |
|
| 322 | + ); |
|
| 323 | + return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations')); |
|
| 324 | + } |
|
| 325 | + return $link; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + public function ee_cpt_archive_pages() |
|
| 330 | + { |
|
| 331 | + global $nav_menu_selected_id; |
|
| 332 | + |
|
| 333 | + $db_fields = false; |
|
| 334 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 335 | + $current_tab = 'event-archives'; |
|
| 336 | + |
|
| 337 | + /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 338 | 338 | $current_tab = 'search'; |
| 339 | 339 | }/**/ |
| 340 | 340 | |
| 341 | - $removed_args = array( |
|
| 342 | - 'action', |
|
| 343 | - 'customlink-tab', |
|
| 344 | - 'edit-menu-item', |
|
| 345 | - 'menu-item', |
|
| 346 | - 'page-tab', |
|
| 347 | - '_wpnonce', |
|
| 348 | - ); |
|
| 341 | + $removed_args = array( |
|
| 342 | + 'action', |
|
| 343 | + 'customlink-tab', |
|
| 344 | + 'edit-menu-item', |
|
| 345 | + 'menu-item', |
|
| 346 | + 'page-tab', |
|
| 347 | + '_wpnonce', |
|
| 348 | + ); |
|
| 349 | 349 | |
| 350 | - ?> |
|
| 350 | + ?> |
|
| 351 | 351 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 352 | 352 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 353 | 353 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
| 354 | 354 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
| 355 | 355 | href="<?php if ($nav_menu_selected_id) { |
| 356 | - echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', |
|
| 357 | - remove_query_arg($removed_args))); |
|
| 358 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 356 | + echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', |
|
| 357 | + remove_query_arg($removed_args))); |
|
| 358 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 359 | 359 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
| 360 | 360 | </a> |
| 361 | 361 | </li> |
@@ -374,29 +374,29 @@ discard block |
||
| 374 | 374 | <?php */ ?> |
| 375 | 375 | |
| 376 | 376 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 377 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 378 | - ?>"> |
|
| 377 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 378 | + ?>"> |
|
| 379 | 379 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 380 | 380 | <?php |
| 381 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 382 | - $args['walker'] = $walker; |
|
| 383 | - echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, |
|
| 384 | - (object)$args); |
|
| 385 | - ?> |
|
| 381 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 382 | + $args['walker'] = $walker; |
|
| 383 | + echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, |
|
| 384 | + (object)$args); |
|
| 385 | + ?> |
|
| 386 | 386 | </ul> |
| 387 | 387 | </div><!-- /.tabs-panel --> |
| 388 | 388 | |
| 389 | 389 | <p class="button-controls"> |
| 390 | 390 | <span class="list-controls"> |
| 391 | 391 | <a href="<?php |
| 392 | - echo esc_url(add_query_arg( |
|
| 393 | - array( |
|
| 394 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 395 | - 'selectall' => 1, |
|
| 396 | - ), |
|
| 397 | - remove_query_arg($removed_args) |
|
| 398 | - )); |
|
| 399 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 392 | + echo esc_url(add_query_arg( |
|
| 393 | + array( |
|
| 394 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 395 | + 'selectall' => 1, |
|
| 396 | + ), |
|
| 397 | + remove_query_arg($removed_args) |
|
| 398 | + )); |
|
| 399 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 400 | 400 | </span> |
| 401 | 401 | |
| 402 | 402 | <span class="add-to-menu"> |
@@ -411,402 +411,402 @@ discard block |
||
| 411 | 411 | </div><!-- /.posttypediv --> |
| 412 | 412 | |
| 413 | 413 | <?php |
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Returns an array of event archive nav items. |
|
| 419 | - * |
|
| 420 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 421 | - * method we use for getting the extra nav menu items |
|
| 422 | - * @return array |
|
| 423 | - */ |
|
| 424 | - private function _get_extra_nav_menu_pages_items() |
|
| 425 | - { |
|
| 426 | - $menuitems[] = array( |
|
| 427 | - 'title' => __('Event List', 'event_espresso'), |
|
| 428 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
| 429 | - 'description' => __('Archive page for all events.', 'event_espresso'), |
|
| 430 | - ); |
|
| 431 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 437 | - * the properties and converts it to the menu item object. |
|
| 438 | - * |
|
| 439 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 440 | - * @param $menu_item_values |
|
| 441 | - * @return stdClass |
|
| 442 | - */ |
|
| 443 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 444 | - { |
|
| 445 | - $menu_item = new stdClass(); |
|
| 446 | - $keys = array( |
|
| 447 | - 'ID' => 0, |
|
| 448 | - 'db_id' => 0, |
|
| 449 | - 'menu_item_parent' => 0, |
|
| 450 | - 'object_id' => -1, |
|
| 451 | - 'post_parent' => 0, |
|
| 452 | - 'type' => 'custom', |
|
| 453 | - 'object' => '', |
|
| 454 | - 'type_label' => __('Extra Nav Menu Item', 'event_espresso'), |
|
| 455 | - 'title' => '', |
|
| 456 | - 'url' => '', |
|
| 457 | - 'target' => '', |
|
| 458 | - 'attr_title' => '', |
|
| 459 | - 'description' => '', |
|
| 460 | - 'classes' => array(), |
|
| 461 | - 'xfn' => '', |
|
| 462 | - ); |
|
| 463 | - |
|
| 464 | - foreach ($keys as $key => $value) { |
|
| 465 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 466 | - } |
|
| 467 | - return $menu_item; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 473 | - * EE_Admin_Page route is called. |
|
| 474 | - * |
|
| 475 | - * @return void |
|
| 476 | - */ |
|
| 477 | - public function route_admin_request() |
|
| 478 | - { |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 484 | - * |
|
| 485 | - * @return void |
|
| 486 | - */ |
|
| 487 | - public function wp_loaded() |
|
| 488 | - { |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * admin_init |
|
| 494 | - * |
|
| 495 | - * @access public |
|
| 496 | - * @return void |
|
| 497 | - */ |
|
| 498 | - public function admin_init() |
|
| 499 | - { |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 503 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 504 | - * - check if doing post processing. |
|
| 505 | - * - check if doing post processing of one of EE CPTs |
|
| 506 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 507 | - */ |
|
| 508 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 509 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 510 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 516 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical Pages" |
|
| 517 | - * tab in the EE General Settings Admin page. |
|
| 518 | - * This is for user-proofing. |
|
| 519 | - */ |
|
| 520 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 521 | - |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 527 | - * |
|
| 528 | - * @param string $output Current output. |
|
| 529 | - * @return string |
|
| 530 | - */ |
|
| 531 | - public function modify_dropdown_pages($output) |
|
| 532 | - { |
|
| 533 | - //get critical pages |
|
| 534 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 535 | - |
|
| 536 | - //split current output by line break for easier parsing. |
|
| 537 | - $split_output = explode("\n", $output); |
|
| 538 | - |
|
| 539 | - //loop through to remove any critical pages from the array. |
|
| 540 | - foreach ($critical_pages as $page_id) { |
|
| 541 | - $needle = 'value="' . $page_id . '"'; |
|
| 542 | - foreach ($split_output as $key => $haystack) { |
|
| 543 | - if (strpos($haystack, $needle) !== false) { |
|
| 544 | - unset($split_output[$key]); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - //replace output with the new contents |
|
| 550 | - return implode("\n", $split_output); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * enqueue all admin scripts that need loaded for admin pages |
|
| 556 | - * |
|
| 557 | - * @access public |
|
| 558 | - * @return void |
|
| 559 | - */ |
|
| 560 | - public function enqueue_admin_scripts() |
|
| 561 | - { |
|
| 562 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 563 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script calls. |
|
| 564 | - wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), |
|
| 565 | - EVENT_ESPRESSO_VERSION, true); |
|
| 566 | - // register cookie script for future dependencies |
|
| 567 | - wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', |
|
| 568 | - true); |
|
| 569 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 570 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
| 571 | - //joyride style |
|
| 572 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 573 | - wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 574 | - array('joyride-css'), EVENT_ESPRESSO_VERSION); |
|
| 575 | - wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', |
|
| 576 | - true); |
|
| 577 | - //joyride JS |
|
| 578 | - wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 579 | - array('jquery-cookie', 'joyride-modernizr'), '2.1', true); |
|
| 580 | - // wanna go for a joyride? |
|
| 581 | - wp_enqueue_style('ee-joyride-css'); |
|
| 582 | - wp_enqueue_script('jquery-joyride'); |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * display_admin_notices |
|
| 589 | - * |
|
| 590 | - * @access public |
|
| 591 | - * @return string |
|
| 592 | - */ |
|
| 593 | - public function display_admin_notices() |
|
| 594 | - { |
|
| 595 | - echo EE_Error::get_notices(); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * get_persistent_admin_notices |
|
| 601 | - * |
|
| 602 | - * @access public |
|
| 603 | - * @return void |
|
| 604 | - */ |
|
| 605 | - public function get_persistent_admin_notices() |
|
| 606 | - { |
|
| 607 | - // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 608 | - $args = array( |
|
| 609 | - 'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '', |
|
| 610 | - 'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '', |
|
| 611 | - ); |
|
| 612 | - $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
| 613 | - echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * dismiss_persistent_admin_notice |
|
| 619 | - * |
|
| 620 | - * @access public |
|
| 621 | - * @return void |
|
| 622 | - */ |
|
| 623 | - public function dismiss_ee_nag_notice_callback() |
|
| 624 | - { |
|
| 625 | - EE_Error::dismiss_persistent_admin_notice(); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * @param array $elements |
|
| 631 | - * @return array |
|
| 632 | - * @throws \EE_Error |
|
| 633 | - */ |
|
| 634 | - public function dashboard_glance_items($elements) |
|
| 635 | - { |
|
| 636 | - $elements = is_array($elements) ? $elements : array($elements); |
|
| 637 | - $events = EEM_Event::instance()->count(); |
|
| 638 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), |
|
| 639 | - admin_url('admin.php')); |
|
| 640 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 641 | - $items['events']['title'] = __('Click to view all Events', 'event_espresso'); |
|
| 642 | - $registrations = EEM_Registration::instance()->count( |
|
| 643 | - array( |
|
| 644 | - array( |
|
| 645 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 646 | - ), |
|
| 647 | - ) |
|
| 648 | - ); |
|
| 649 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), |
|
| 650 | - admin_url('admin.php')); |
|
| 651 | - $items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), |
|
| 652 | - number_format_i18n($registrations)); |
|
| 653 | - $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso'); |
|
| 654 | - |
|
| 655 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 656 | - |
|
| 657 | - foreach ($items as $type => $item_properties) { |
|
| 658 | - $elements[] = sprintf('<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 659 | - $item_properties['url'], $item_properties['title'], $item_properties['text']); |
|
| 660 | - } |
|
| 661 | - return $elements; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * check_for_invalid_datetime_formats |
|
| 667 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 668 | - * their selected format can be parsed by PHP |
|
| 669 | - * |
|
| 670 | - * @access public |
|
| 671 | - * @param $value |
|
| 672 | - * @param $option |
|
| 673 | - * @throws EE_Error |
|
| 674 | - * @return string |
|
| 675 | - */ |
|
| 676 | - public function check_for_invalid_datetime_formats($value, $option) |
|
| 677 | - { |
|
| 678 | - // check for date_format or time_format |
|
| 679 | - switch ($option) { |
|
| 680 | - case 'date_format' : |
|
| 681 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 682 | - break; |
|
| 683 | - case 'time_format' : |
|
| 684 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 685 | - break; |
|
| 686 | - default : |
|
| 687 | - $date_time_format = false; |
|
| 688 | - } |
|
| 689 | - // do we have a date_time format to check ? |
|
| 690 | - if ($date_time_format) { |
|
| 691 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 692 | - |
|
| 693 | - if (is_array($error_msg)) { |
|
| 694 | - $msg = '<p>' . sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 695 | - 'event_espresso'), date($date_time_format), $date_time_format) . '</p><p><ul>'; |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - foreach ($error_msg as $error) { |
|
| 699 | - $msg .= '<li>' . $error . '</li>'; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 703 | - 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 704 | - |
|
| 705 | - // trigger WP settings error |
|
| 706 | - add_settings_error( |
|
| 707 | - 'date_format', |
|
| 708 | - 'date_format', |
|
| 709 | - $msg |
|
| 710 | - ); |
|
| 711 | - |
|
| 712 | - // set format to something valid |
|
| 713 | - switch ($option) { |
|
| 714 | - case 'date_format' : |
|
| 715 | - $value = 'F j, Y'; |
|
| 716 | - break; |
|
| 717 | - case 'time_format' : |
|
| 718 | - $value = 'g:i a'; |
|
| 719 | - break; |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - } |
|
| 723 | - return $value; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 729 | - * |
|
| 730 | - * @access public |
|
| 731 | - * @param $content |
|
| 732 | - * @return string |
|
| 733 | - */ |
|
| 734 | - public function its_eSpresso($content) |
|
| 735 | - { |
|
| 736 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * espresso_admin_footer |
|
| 742 | - * |
|
| 743 | - * @access public |
|
| 744 | - * @return string |
|
| 745 | - */ |
|
| 746 | - public function espresso_admin_footer() |
|
| 747 | - { |
|
| 748 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - /** |
|
| 753 | - * static method for registering ee admin page. |
|
| 754 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 755 | - * |
|
| 756 | - * @since 4.3.0 |
|
| 757 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 758 | - * @see EE_Register_Admin_Page::register() |
|
| 759 | - * @param $page_basename |
|
| 760 | - * @param $page_path |
|
| 761 | - * @param array $config |
|
| 762 | - * @return void |
|
| 763 | - */ |
|
| 764 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 765 | - { |
|
| 766 | - EE_Error::doing_it_wrong(__METHOD__, |
|
| 767 | - sprintf(__('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 768 | - 'event_espresso'), $page_basename), '4.3'); |
|
| 769 | - if (class_exists('EE_Register_Admin_Page')) { |
|
| 770 | - $config['page_path'] = $page_path; |
|
| 771 | - } |
|
| 772 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
| 773 | - |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * @deprecated 4.8.41 |
|
| 779 | - * @access public |
|
| 780 | - * @param int $post_ID |
|
| 781 | - * @param \WP_Post $post |
|
| 782 | - * @return void |
|
| 783 | - */ |
|
| 784 | - public static function parse_post_content_on_save($post_ID, $post) |
|
| 785 | - { |
|
| 786 | - EE_Error::doing_it_wrong( |
|
| 787 | - __METHOD__, |
|
| 788 | - __('Usage is deprecated', 'event_espresso'), |
|
| 789 | - '4.8.41' |
|
| 790 | - ); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * @deprecated 4.8.41 |
|
| 796 | - * @access public |
|
| 797 | - * @param $option |
|
| 798 | - * @param $old_value |
|
| 799 | - * @param $value |
|
| 800 | - * @return void |
|
| 801 | - */ |
|
| 802 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 803 | - { |
|
| 804 | - EE_Error::doing_it_wrong( |
|
| 805 | - __METHOD__, |
|
| 806 | - __('Usage is deprecated', 'event_espresso'), |
|
| 807 | - '4.8.41' |
|
| 808 | - ); |
|
| 809 | - } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Returns an array of event archive nav items. |
|
| 419 | + * |
|
| 420 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 421 | + * method we use for getting the extra nav menu items |
|
| 422 | + * @return array |
|
| 423 | + */ |
|
| 424 | + private function _get_extra_nav_menu_pages_items() |
|
| 425 | + { |
|
| 426 | + $menuitems[] = array( |
|
| 427 | + 'title' => __('Event List', 'event_espresso'), |
|
| 428 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 429 | + 'description' => __('Archive page for all events.', 'event_espresso'), |
|
| 430 | + ); |
|
| 431 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 437 | + * the properties and converts it to the menu item object. |
|
| 438 | + * |
|
| 439 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 440 | + * @param $menu_item_values |
|
| 441 | + * @return stdClass |
|
| 442 | + */ |
|
| 443 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 444 | + { |
|
| 445 | + $menu_item = new stdClass(); |
|
| 446 | + $keys = array( |
|
| 447 | + 'ID' => 0, |
|
| 448 | + 'db_id' => 0, |
|
| 449 | + 'menu_item_parent' => 0, |
|
| 450 | + 'object_id' => -1, |
|
| 451 | + 'post_parent' => 0, |
|
| 452 | + 'type' => 'custom', |
|
| 453 | + 'object' => '', |
|
| 454 | + 'type_label' => __('Extra Nav Menu Item', 'event_espresso'), |
|
| 455 | + 'title' => '', |
|
| 456 | + 'url' => '', |
|
| 457 | + 'target' => '', |
|
| 458 | + 'attr_title' => '', |
|
| 459 | + 'description' => '', |
|
| 460 | + 'classes' => array(), |
|
| 461 | + 'xfn' => '', |
|
| 462 | + ); |
|
| 463 | + |
|
| 464 | + foreach ($keys as $key => $value) { |
|
| 465 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 466 | + } |
|
| 467 | + return $menu_item; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 473 | + * EE_Admin_Page route is called. |
|
| 474 | + * |
|
| 475 | + * @return void |
|
| 476 | + */ |
|
| 477 | + public function route_admin_request() |
|
| 478 | + { |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 484 | + * |
|
| 485 | + * @return void |
|
| 486 | + */ |
|
| 487 | + public function wp_loaded() |
|
| 488 | + { |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * admin_init |
|
| 494 | + * |
|
| 495 | + * @access public |
|
| 496 | + * @return void |
|
| 497 | + */ |
|
| 498 | + public function admin_init() |
|
| 499 | + { |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 503 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 504 | + * - check if doing post processing. |
|
| 505 | + * - check if doing post processing of one of EE CPTs |
|
| 506 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 507 | + */ |
|
| 508 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 509 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 510 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 516 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical Pages" |
|
| 517 | + * tab in the EE General Settings Admin page. |
|
| 518 | + * This is for user-proofing. |
|
| 519 | + */ |
|
| 520 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 521 | + |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 527 | + * |
|
| 528 | + * @param string $output Current output. |
|
| 529 | + * @return string |
|
| 530 | + */ |
|
| 531 | + public function modify_dropdown_pages($output) |
|
| 532 | + { |
|
| 533 | + //get critical pages |
|
| 534 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 535 | + |
|
| 536 | + //split current output by line break for easier parsing. |
|
| 537 | + $split_output = explode("\n", $output); |
|
| 538 | + |
|
| 539 | + //loop through to remove any critical pages from the array. |
|
| 540 | + foreach ($critical_pages as $page_id) { |
|
| 541 | + $needle = 'value="' . $page_id . '"'; |
|
| 542 | + foreach ($split_output as $key => $haystack) { |
|
| 543 | + if (strpos($haystack, $needle) !== false) { |
|
| 544 | + unset($split_output[$key]); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + //replace output with the new contents |
|
| 550 | + return implode("\n", $split_output); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * enqueue all admin scripts that need loaded for admin pages |
|
| 556 | + * |
|
| 557 | + * @access public |
|
| 558 | + * @return void |
|
| 559 | + */ |
|
| 560 | + public function enqueue_admin_scripts() |
|
| 561 | + { |
|
| 562 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 563 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script calls. |
|
| 564 | + wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), |
|
| 565 | + EVENT_ESPRESSO_VERSION, true); |
|
| 566 | + // register cookie script for future dependencies |
|
| 567 | + wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', |
|
| 568 | + true); |
|
| 569 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 570 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
| 571 | + //joyride style |
|
| 572 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 573 | + wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 574 | + array('joyride-css'), EVENT_ESPRESSO_VERSION); |
|
| 575 | + wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', |
|
| 576 | + true); |
|
| 577 | + //joyride JS |
|
| 578 | + wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 579 | + array('jquery-cookie', 'joyride-modernizr'), '2.1', true); |
|
| 580 | + // wanna go for a joyride? |
|
| 581 | + wp_enqueue_style('ee-joyride-css'); |
|
| 582 | + wp_enqueue_script('jquery-joyride'); |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * display_admin_notices |
|
| 589 | + * |
|
| 590 | + * @access public |
|
| 591 | + * @return string |
|
| 592 | + */ |
|
| 593 | + public function display_admin_notices() |
|
| 594 | + { |
|
| 595 | + echo EE_Error::get_notices(); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * get_persistent_admin_notices |
|
| 601 | + * |
|
| 602 | + * @access public |
|
| 603 | + * @return void |
|
| 604 | + */ |
|
| 605 | + public function get_persistent_admin_notices() |
|
| 606 | + { |
|
| 607 | + // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 608 | + $args = array( |
|
| 609 | + 'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '', |
|
| 610 | + 'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '', |
|
| 611 | + ); |
|
| 612 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
| 613 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * dismiss_persistent_admin_notice |
|
| 619 | + * |
|
| 620 | + * @access public |
|
| 621 | + * @return void |
|
| 622 | + */ |
|
| 623 | + public function dismiss_ee_nag_notice_callback() |
|
| 624 | + { |
|
| 625 | + EE_Error::dismiss_persistent_admin_notice(); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * @param array $elements |
|
| 631 | + * @return array |
|
| 632 | + * @throws \EE_Error |
|
| 633 | + */ |
|
| 634 | + public function dashboard_glance_items($elements) |
|
| 635 | + { |
|
| 636 | + $elements = is_array($elements) ? $elements : array($elements); |
|
| 637 | + $events = EEM_Event::instance()->count(); |
|
| 638 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), |
|
| 639 | + admin_url('admin.php')); |
|
| 640 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 641 | + $items['events']['title'] = __('Click to view all Events', 'event_espresso'); |
|
| 642 | + $registrations = EEM_Registration::instance()->count( |
|
| 643 | + array( |
|
| 644 | + array( |
|
| 645 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 646 | + ), |
|
| 647 | + ) |
|
| 648 | + ); |
|
| 649 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), |
|
| 650 | + admin_url('admin.php')); |
|
| 651 | + $items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), |
|
| 652 | + number_format_i18n($registrations)); |
|
| 653 | + $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso'); |
|
| 654 | + |
|
| 655 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 656 | + |
|
| 657 | + foreach ($items as $type => $item_properties) { |
|
| 658 | + $elements[] = sprintf('<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 659 | + $item_properties['url'], $item_properties['title'], $item_properties['text']); |
|
| 660 | + } |
|
| 661 | + return $elements; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * check_for_invalid_datetime_formats |
|
| 667 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 668 | + * their selected format can be parsed by PHP |
|
| 669 | + * |
|
| 670 | + * @access public |
|
| 671 | + * @param $value |
|
| 672 | + * @param $option |
|
| 673 | + * @throws EE_Error |
|
| 674 | + * @return string |
|
| 675 | + */ |
|
| 676 | + public function check_for_invalid_datetime_formats($value, $option) |
|
| 677 | + { |
|
| 678 | + // check for date_format or time_format |
|
| 679 | + switch ($option) { |
|
| 680 | + case 'date_format' : |
|
| 681 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 682 | + break; |
|
| 683 | + case 'time_format' : |
|
| 684 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 685 | + break; |
|
| 686 | + default : |
|
| 687 | + $date_time_format = false; |
|
| 688 | + } |
|
| 689 | + // do we have a date_time format to check ? |
|
| 690 | + if ($date_time_format) { |
|
| 691 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 692 | + |
|
| 693 | + if (is_array($error_msg)) { |
|
| 694 | + $msg = '<p>' . sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 695 | + 'event_espresso'), date($date_time_format), $date_time_format) . '</p><p><ul>'; |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + foreach ($error_msg as $error) { |
|
| 699 | + $msg .= '<li>' . $error . '</li>'; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 703 | + 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 704 | + |
|
| 705 | + // trigger WP settings error |
|
| 706 | + add_settings_error( |
|
| 707 | + 'date_format', |
|
| 708 | + 'date_format', |
|
| 709 | + $msg |
|
| 710 | + ); |
|
| 711 | + |
|
| 712 | + // set format to something valid |
|
| 713 | + switch ($option) { |
|
| 714 | + case 'date_format' : |
|
| 715 | + $value = 'F j, Y'; |
|
| 716 | + break; |
|
| 717 | + case 'time_format' : |
|
| 718 | + $value = 'g:i a'; |
|
| 719 | + break; |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + } |
|
| 723 | + return $value; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 729 | + * |
|
| 730 | + * @access public |
|
| 731 | + * @param $content |
|
| 732 | + * @return string |
|
| 733 | + */ |
|
| 734 | + public function its_eSpresso($content) |
|
| 735 | + { |
|
| 736 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * espresso_admin_footer |
|
| 742 | + * |
|
| 743 | + * @access public |
|
| 744 | + * @return string |
|
| 745 | + */ |
|
| 746 | + public function espresso_admin_footer() |
|
| 747 | + { |
|
| 748 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + /** |
|
| 753 | + * static method for registering ee admin page. |
|
| 754 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 755 | + * |
|
| 756 | + * @since 4.3.0 |
|
| 757 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 758 | + * @see EE_Register_Admin_Page::register() |
|
| 759 | + * @param $page_basename |
|
| 760 | + * @param $page_path |
|
| 761 | + * @param array $config |
|
| 762 | + * @return void |
|
| 763 | + */ |
|
| 764 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 765 | + { |
|
| 766 | + EE_Error::doing_it_wrong(__METHOD__, |
|
| 767 | + sprintf(__('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 768 | + 'event_espresso'), $page_basename), '4.3'); |
|
| 769 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 770 | + $config['page_path'] = $page_path; |
|
| 771 | + } |
|
| 772 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 773 | + |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * @deprecated 4.8.41 |
|
| 779 | + * @access public |
|
| 780 | + * @param int $post_ID |
|
| 781 | + * @param \WP_Post $post |
|
| 782 | + * @return void |
|
| 783 | + */ |
|
| 784 | + public static function parse_post_content_on_save($post_ID, $post) |
|
| 785 | + { |
|
| 786 | + EE_Error::doing_it_wrong( |
|
| 787 | + __METHOD__, |
|
| 788 | + __('Usage is deprecated', 'event_espresso'), |
|
| 789 | + '4.8.41' |
|
| 790 | + ); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * @deprecated 4.8.41 |
|
| 796 | + * @access public |
|
| 797 | + * @param $option |
|
| 798 | + * @param $old_value |
|
| 799 | + * @param $value |
|
| 800 | + * @return void |
|
| 801 | + */ |
|
| 802 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 803 | + { |
|
| 804 | + EE_Error::doing_it_wrong( |
|
| 805 | + __METHOD__, |
|
| 806 | + __('Usage is deprecated', 'event_espresso'), |
|
| 807 | + '4.8.41' |
|
| 808 | + ); |
|
| 809 | + } |
|
| 810 | 810 | |
| 811 | 811 | } |
| 812 | 812 | // End of file EE_Admin.core.php |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | use EventEspresso\core\interfaces\InterminableInterface; |
| 4 | 4 | |
| 5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | 6 | exit('No direct script access allowed'); |
| 7 | 7 | } |
| 8 | 8 | |
@@ -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; |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | private function _define_all_constants() |
| 103 | 103 | { |
| 104 | - if (! defined('EE_ADMIN_URL')) { |
|
| 105 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 106 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 107 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 108 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 104 | + if ( ! defined('EE_ADMIN_URL')) { |
|
| 105 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 106 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 107 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
| 108 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 109 | 109 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -124,20 +124,20 @@ discard block |
||
| 124 | 124 | // set $main_file in stone |
| 125 | 125 | static $main_file; |
| 126 | 126 | // if $main_file is not set yet |
| 127 | - if (! $main_file) { |
|
| 127 | + if ( ! $main_file) { |
|
| 128 | 128 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
| 129 | 129 | } |
| 130 | 130 | if ($plugin === $main_file) { |
| 131 | 131 | // compare current plugin to this one |
| 132 | 132 | if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
| 133 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">' . __('Maintenance Mode Active', |
|
| 134 | - 'event_espresso') . '</a>'; |
|
| 133 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">'.__('Maintenance Mode Active', |
|
| 134 | + 'event_espresso').'</a>'; |
|
| 135 | 135 | array_unshift($links, $maintenance_link); |
| 136 | 136 | } else { |
| 137 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __('Settings', |
|
| 138 | - 'event_espresso') . '</a>'; |
|
| 139 | - $events_link = '<a href="admin.php?page=espresso_events">' . __('Events', |
|
| 140 | - 'event_espresso') . '</a>'; |
|
| 137 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', |
|
| 138 | + 'event_espresso').'</a>'; |
|
| 139 | + $events_link = '<a href="admin.php?page=espresso_events">'.__('Events', |
|
| 140 | + 'event_espresso').'</a>'; |
|
| 141 | 141 | // add before other links |
| 142 | 142 | array_unshift($links, $org_settings_link, $events_link); |
| 143 | 143 | } |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
| 170 | 170 | { |
| 171 | 171 | return array( |
| 172 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 173 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 174 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 172 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
| 173 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
| 174 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
| 175 | 175 | ); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
| 198 | 198 | } |
| 199 | 199 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 200 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 200 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 201 | 201 | try { |
| 202 | 202 | //this loads the controller for the admin pages which will setup routing etc |
| 203 | 203 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | public function enable_hidden_ee_nav_menu_metaboxes() |
| 250 | 250 | { |
| 251 | 251 | global $wp_meta_boxes, $pagenow; |
| 252 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 252 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 253 | 253 | return; |
| 254 | 254 | } |
| 255 | 255 | $user = wp_get_current_user(); |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | */ |
| 313 | 313 | public function modify_edit_post_link($link, $id) |
| 314 | 314 | { |
| 315 | - if (! $post = get_post($id)) { |
|
| 315 | + if ( ! $post = get_post($id)) { |
|
| 316 | 316 | return $link; |
| 317 | 317 | } |
| 318 | 318 | if ($post->post_type === 'espresso_attendees') { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | $pages = $this->_get_extra_nav_menu_pages_items(); |
| 382 | 382 | $args['walker'] = $walker; |
| 383 | 383 | echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, |
| 384 | - (object)$args); |
|
| 384 | + (object) $args); |
|
| 385 | 385 | ?> |
| 386 | 386 | </ul> |
| 387 | 387 | </div><!-- /.tabs-panel --> |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | |
| 539 | 539 | //loop through to remove any critical pages from the array. |
| 540 | 540 | foreach ($critical_pages as $page_id) { |
| 541 | - $needle = 'value="' . $page_id . '"'; |
|
| 541 | + $needle = 'value="'.$page_id.'"'; |
|
| 542 | 542 | foreach ($split_output as $key => $haystack) { |
| 543 | 543 | if (strpos($haystack, $needle) !== false) { |
| 544 | 544 | unset($split_output[$key]); |
@@ -561,21 +561,21 @@ discard block |
||
| 561 | 561 | { |
| 562 | 562 | // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
| 563 | 563 | // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script calls. |
| 564 | - wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), |
|
| 564 | + wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), |
|
| 565 | 565 | EVENT_ESPRESSO_VERSION, true); |
| 566 | 566 | // register cookie script for future dependencies |
| 567 | - wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', |
|
| 567 | + wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', |
|
| 568 | 568 | true); |
| 569 | 569 | //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' ); |
| 570 | 570 | if (apply_filters('FHEE_load_joyride', false)) { |
| 571 | 571 | //joyride style |
| 572 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 573 | - wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 572 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 573 | + wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 574 | 574 | array('joyride-css'), EVENT_ESPRESSO_VERSION); |
| 575 | - wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', |
|
| 575 | + wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', |
|
| 576 | 576 | true); |
| 577 | 577 | //joyride JS |
| 578 | - wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 578 | + wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 579 | 579 | array('jquery-cookie', 'joyride-modernizr'), '2.1', true); |
| 580 | 580 | // wanna go for a joyride? |
| 581 | 581 | wp_enqueue_style('ee-joyride-css'); |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | public function get_persistent_admin_notices() |
| 606 | 606 | { |
| 607 | 607 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
| 608 | - $args = array( |
|
| 608 | + $args = array( |
|
| 609 | 609 | 'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '', |
| 610 | 610 | 'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '', |
| 611 | 611 | ); |
@@ -652,10 +652,10 @@ discard block |
||
| 652 | 652 | number_format_i18n($registrations)); |
| 653 | 653 | $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso'); |
| 654 | 654 | |
| 655 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 655 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 656 | 656 | |
| 657 | 657 | foreach ($items as $type => $item_properties) { |
| 658 | - $elements[] = sprintf('<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 658 | + $elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
| 659 | 659 | $item_properties['url'], $item_properties['title'], $item_properties['text']); |
| 660 | 660 | } |
| 661 | 661 | return $elements; |
@@ -678,10 +678,10 @@ discard block |
||
| 678 | 678 | // check for date_format or time_format |
| 679 | 679 | switch ($option) { |
| 680 | 680 | case 'date_format' : |
| 681 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 681 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 682 | 682 | break; |
| 683 | 683 | case 'time_format' : |
| 684 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 684 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 685 | 685 | break; |
| 686 | 686 | default : |
| 687 | 687 | $date_time_format = false; |
@@ -691,16 +691,16 @@ discard block |
||
| 691 | 691 | $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
| 692 | 692 | |
| 693 | 693 | if (is_array($error_msg)) { |
| 694 | - $msg = '<p>' . sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 695 | - 'event_espresso'), date($date_time_format), $date_time_format) . '</p><p><ul>'; |
|
| 694 | + $msg = '<p>'.sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 695 | + 'event_espresso'), date($date_time_format), $date_time_format).'</p><p><ul>'; |
|
| 696 | 696 | |
| 697 | 697 | |
| 698 | 698 | foreach ($error_msg as $error) { |
| 699 | - $msg .= '<li>' . $error . '</li>'; |
|
| 699 | + $msg .= '<li>'.$error.'</li>'; |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 703 | - 'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>'; |
|
| 702 | + $msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 703 | + 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>'; |
|
| 704 | 704 | |
| 705 | 705 | // trigger WP settings error |
| 706 | 706 | add_settings_error( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.015'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.015'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - // for older WP versions |
|
| 197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * espresso_plugin_activation |
|
| 202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | - */ |
|
| 204 | - function espresso_plugin_activation() |
|
| 205 | - { |
|
| 206 | - update_option('ee_espresso_activation', true); |
|
| 207 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + // for older WP versions |
|
| 197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * espresso_plugin_activation |
|
| 202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | + */ |
|
| 204 | + function espresso_plugin_activation() |
|
| 205 | + { |
|
| 206 | + update_option('ee_espresso_activation', true); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | - /** |
|
| 211 | - * espresso_load_error_handling |
|
| 212 | - * this function loads EE's class for handling exceptions and errors |
|
| 213 | - */ |
|
| 214 | - function espresso_load_error_handling() |
|
| 215 | - { |
|
| 216 | - // load debugging tools |
|
| 217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | - EEH_Debug_Tools::instance(); |
|
| 220 | - } |
|
| 221 | - // load error handling |
|
| 222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | - } else { |
|
| 225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | - } |
|
| 227 | - } |
|
| 209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | + /** |
|
| 211 | + * espresso_load_error_handling |
|
| 212 | + * this function loads EE's class for handling exceptions and errors |
|
| 213 | + */ |
|
| 214 | + function espresso_load_error_handling() |
|
| 215 | + { |
|
| 216 | + // load debugging tools |
|
| 217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | + EEH_Debug_Tools::instance(); |
|
| 220 | + } |
|
| 221 | + // load error handling |
|
| 222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | + } else { |
|
| 225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * espresso_load_required |
|
| 231 | - * given a class name and path, this function will load that file or throw an exception |
|
| 232 | - * |
|
| 233 | - * @param string $classname |
|
| 234 | - * @param string $full_path_to_file |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | - { |
|
| 239 | - static $error_handling_loaded = false; |
|
| 240 | - if ( ! $error_handling_loaded) { |
|
| 241 | - espresso_load_error_handling(); |
|
| 242 | - $error_handling_loaded = true; |
|
| 243 | - } |
|
| 244 | - if (is_readable($full_path_to_file)) { |
|
| 245 | - require_once($full_path_to_file); |
|
| 246 | - } else { |
|
| 247 | - throw new EE_Error ( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $classname |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 229 | + /** |
|
| 230 | + * espresso_load_required |
|
| 231 | + * given a class name and path, this function will load that file or throw an exception |
|
| 232 | + * |
|
| 233 | + * @param string $classname |
|
| 234 | + * @param string $full_path_to_file |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | + { |
|
| 239 | + static $error_handling_loaded = false; |
|
| 240 | + if ( ! $error_handling_loaded) { |
|
| 241 | + espresso_load_error_handling(); |
|
| 242 | + $error_handling_loaded = true; |
|
| 243 | + } |
|
| 244 | + if (is_readable($full_path_to_file)) { |
|
| 245 | + require_once($full_path_to_file); |
|
| 246 | + } else { |
|
| 247 | + throw new EE_Error ( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $classname |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | - new EE_Bootstrap(); |
|
| 263 | - } |
|
| 259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | + new EE_Bootstrap(); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 266 | - /** |
|
| 267 | - * deactivate_plugin |
|
| 268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | - * |
|
| 270 | - * @access public |
|
| 271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | - { |
|
| 276 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | - } |
|
| 279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | - deactivate_plugins($plugin_basename); |
|
| 281 | - } |
|
| 266 | + /** |
|
| 267 | + * deactivate_plugin |
|
| 268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | + * |
|
| 270 | + * @access public |
|
| 271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | + { |
|
| 276 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | + } |
|
| 279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | + deactivate_plugins($plugin_basename); |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | \ No newline at end of file |