@@ -11,9 +11,9 @@ discard block |
||
| 11 | 11 | $stages = glob(EE_CORE . 'data_migration_scripts/5_0_0_stages/*'); |
| 12 | 12 | $class_to_filepath = []; |
| 13 | 13 | foreach ($stages as $filepath) { |
| 14 | - $matches = []; |
|
| 15 | - preg_match('~5_0_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 16 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 14 | + $matches = []; |
|
| 15 | + preg_match('~5_0_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 16 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 17 | 17 | } |
| 18 | 18 | // give addons a chance to autoload their stages too |
| 19 | 19 | $class_to_filepath = apply_filters('FHEE__EE_DMS_5_0_0__autoloaded_stages', $class_to_filepath); |
@@ -29,65 +29,65 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | class EE_DMS_Core_5_0_0 extends EE_Data_Migration_Script_Base |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * @param EE_DMS_Core_4_10_0 $dms_4_10 |
|
| 34 | - * @param TableManager|null $table_manager |
|
| 35 | - * @param TableAnalysis|null $table_analysis |
|
| 36 | - */ |
|
| 37 | - public function __construct( |
|
| 38 | - EE_DMS_Core_4_10_0 $dms_4_10, |
|
| 39 | - TableManager $table_manager = null, |
|
| 40 | - TableAnalysis $table_analysis = null |
|
| 41 | - ) { |
|
| 42 | - $this->previous_dms = $dms_4_10; |
|
| 43 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 5.0.0", "event_espresso"); |
|
| 44 | - $this->_priority = 10; |
|
| 45 | - $this->_migration_stages = [ |
|
| 46 | - new EE_DMS_5_0_0_Event_Venues(), |
|
| 47 | - ]; |
|
| 48 | - parent::__construct($table_manager, $table_analysis); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Whether to migrate or not. |
|
| 54 | - * |
|
| 55 | - * @param array $version_array |
|
| 56 | - * @return bool |
|
| 57 | - */ |
|
| 58 | - public function can_migrate_from_version($version_array): bool |
|
| 59 | - { |
|
| 60 | - $version_string = $version_array['Core']; |
|
| 61 | - return $version_string && |
|
| 62 | - version_compare($version_string, '5.0.0.decaf', '<') && |
|
| 63 | - version_compare($version_string, '4.10.0.decaf', '>='); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return bool |
|
| 69 | - * @throws EE_Error |
|
| 70 | - * @throws ReflectionException |
|
| 71 | - */ |
|
| 72 | - public function schema_changes_before_migration(): bool |
|
| 73 | - { |
|
| 74 | - require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
| 75 | - |
|
| 76 | - $this->_table_has_not_changed_since_previous( |
|
| 77 | - 'esp_answer', |
|
| 78 | - ' ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 32 | + /** |
|
| 33 | + * @param EE_DMS_Core_4_10_0 $dms_4_10 |
|
| 34 | + * @param TableManager|null $table_manager |
|
| 35 | + * @param TableAnalysis|null $table_analysis |
|
| 36 | + */ |
|
| 37 | + public function __construct( |
|
| 38 | + EE_DMS_Core_4_10_0 $dms_4_10, |
|
| 39 | + TableManager $table_manager = null, |
|
| 40 | + TableAnalysis $table_analysis = null |
|
| 41 | + ) { |
|
| 42 | + $this->previous_dms = $dms_4_10; |
|
| 43 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 5.0.0", "event_espresso"); |
|
| 44 | + $this->_priority = 10; |
|
| 45 | + $this->_migration_stages = [ |
|
| 46 | + new EE_DMS_5_0_0_Event_Venues(), |
|
| 47 | + ]; |
|
| 48 | + parent::__construct($table_manager, $table_analysis); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Whether to migrate or not. |
|
| 54 | + * |
|
| 55 | + * @param array $version_array |
|
| 56 | + * @return bool |
|
| 57 | + */ |
|
| 58 | + public function can_migrate_from_version($version_array): bool |
|
| 59 | + { |
|
| 60 | + $version_string = $version_array['Core']; |
|
| 61 | + return $version_string && |
|
| 62 | + version_compare($version_string, '5.0.0.decaf', '<') && |
|
| 63 | + version_compare($version_string, '4.10.0.decaf', '>='); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return bool |
|
| 69 | + * @throws EE_Error |
|
| 70 | + * @throws ReflectionException |
|
| 71 | + */ |
|
| 72 | + public function schema_changes_before_migration(): bool |
|
| 73 | + { |
|
| 74 | + require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
| 75 | + |
|
| 76 | + $this->_table_has_not_changed_since_previous( |
|
| 77 | + 'esp_answer', |
|
| 78 | + ' ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 79 | 79 | REG_ID int(10) unsigned NOT NULL, |
| 80 | 80 | QST_ID int(10) unsigned NOT NULL, |
| 81 | 81 | ANS_value text NOT NULL, |
| 82 | 82 | PRIMARY KEY (ANS_ID)' |
| 83 | - ); |
|
| 84 | - $this->_get_table_manager()->addIndex('esp_answer', 'REG_ID', 'REG_ID'); |
|
| 85 | - $this->_get_table_manager()->addIndex('esp_answer', 'QST_ID', 'QST_ID'); |
|
| 83 | + ); |
|
| 84 | + $this->_get_table_manager()->addIndex('esp_answer', 'REG_ID', 'REG_ID'); |
|
| 85 | + $this->_get_table_manager()->addIndex('esp_answer', 'QST_ID', 'QST_ID'); |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - $this->_table_has_not_changed_since_previous( |
|
| 89 | - 'esp_attendee_meta', |
|
| 90 | - "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 88 | + $this->_table_has_not_changed_since_previous( |
|
| 89 | + 'esp_attendee_meta', |
|
| 90 | + "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 91 | 91 | ATT_ID bigint(20) unsigned NOT NULL, |
| 92 | 92 | ATT_fname varchar(45) NOT NULL, |
| 93 | 93 | ATT_lname varchar(45) NOT NULL, |
@@ -100,43 +100,43 @@ discard block |
||
| 100 | 100 | ATT_email varchar(255) NOT NULL, |
| 101 | 101 | ATT_phone varchar(45) DEFAULT NULL, |
| 102 | 102 | PRIMARY KEY (ATTM_ID)" |
| 103 | - ); |
|
| 104 | - $this->_get_table_manager()->addIndex('esp_attendee_meta', 'ATT_ID', 'ATT_ID'); |
|
| 105 | - $this->_get_table_manager()->addIndex( |
|
| 106 | - 'esp_attendee_meta', |
|
| 107 | - 'ATT_email', |
|
| 108 | - 'ATT_email', |
|
| 109 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 110 | - TableAnalysis::INDEX_COLUMN_SIZE |
|
| 111 | - ); |
|
| 112 | - $this->_get_table_manager()->addIndex('esp_attendee_meta', 'ATT_lname', 'ATT_lname'); |
|
| 113 | - $this->_get_table_manager()->addIndex('esp_attendee_meta', 'ATT_fname', 'ATT_fname'); |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - $this->_table_has_not_changed_since_previous( |
|
| 117 | - 'esp_checkin', |
|
| 118 | - "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 103 | + ); |
|
| 104 | + $this->_get_table_manager()->addIndex('esp_attendee_meta', 'ATT_ID', 'ATT_ID'); |
|
| 105 | + $this->_get_table_manager()->addIndex( |
|
| 106 | + 'esp_attendee_meta', |
|
| 107 | + 'ATT_email', |
|
| 108 | + 'ATT_email', |
|
| 109 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 110 | + TableAnalysis::INDEX_COLUMN_SIZE |
|
| 111 | + ); |
|
| 112 | + $this->_get_table_manager()->addIndex('esp_attendee_meta', 'ATT_lname', 'ATT_lname'); |
|
| 113 | + $this->_get_table_manager()->addIndex('esp_attendee_meta', 'ATT_fname', 'ATT_fname'); |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + $this->_table_has_not_changed_since_previous( |
|
| 117 | + 'esp_checkin', |
|
| 118 | + "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 119 | 119 | REG_ID int(10) unsigned NOT NULL, |
| 120 | 120 | DTT_ID int(10) unsigned NOT NULL, |
| 121 | 121 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
| 122 | 122 | CHK_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 123 | 123 | PRIMARY KEY (CHK_ID)" |
| 124 | - ); |
|
| 125 | - $this->_get_table_manager()->addIndex('esp_checkin', 'REG_ID', 'REG_ID'); |
|
| 126 | - $this->_get_table_manager()->addIndex('esp_checkin', 'DTT_ID', 'DTT_ID'); |
|
| 127 | - $this->_get_table_manager()->addIndex( |
|
| 128 | - 'esp_checkin', |
|
| 129 | - 'CHK_timestamp', |
|
| 130 | - 'CHK_timestamp', |
|
| 131 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 132 | - null, |
|
| 133 | - true |
|
| 134 | - ); |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - $this->_table_has_not_changed_since_previous( |
|
| 138 | - 'esp_country', |
|
| 139 | - "CNT_ISO varchar(2) NOT NULL, |
|
| 124 | + ); |
|
| 125 | + $this->_get_table_manager()->addIndex('esp_checkin', 'REG_ID', 'REG_ID'); |
|
| 126 | + $this->_get_table_manager()->addIndex('esp_checkin', 'DTT_ID', 'DTT_ID'); |
|
| 127 | + $this->_get_table_manager()->addIndex( |
|
| 128 | + 'esp_checkin', |
|
| 129 | + 'CHK_timestamp', |
|
| 130 | + 'CHK_timestamp', |
|
| 131 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 132 | + null, |
|
| 133 | + true |
|
| 134 | + ); |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + $this->_table_has_not_changed_since_previous( |
|
| 138 | + 'esp_country', |
|
| 139 | + "CNT_ISO varchar(2) NOT NULL, |
|
| 140 | 140 | CNT_ISO3 varchar(3) NOT NULL, |
| 141 | 141 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
| 142 | 142 | CNT_name varchar(45) NOT NULL, |
@@ -152,38 +152,38 @@ discard block |
||
| 152 | 152 | CNT_is_EU tinyint(1) DEFAULT '0', |
| 153 | 153 | CNT_active tinyint(1) DEFAULT '0', |
| 154 | 154 | PRIMARY KEY (CNT_ISO)" |
| 155 | - ); |
|
| 155 | + ); |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | - $this->_table_has_not_changed_since_previous( |
|
| 159 | - 'esp_currency', |
|
| 160 | - "CUR_code varchar(6) NOT NULL, |
|
| 158 | + $this->_table_has_not_changed_since_previous( |
|
| 159 | + 'esp_currency', |
|
| 160 | + "CUR_code varchar(6) NOT NULL, |
|
| 161 | 161 | CUR_single varchar(45) DEFAULT 'dollar', |
| 162 | 162 | CUR_plural varchar(45) DEFAULT 'dollars', |
| 163 | 163 | CUR_sign varchar(45) DEFAULT '$', |
| 164 | 164 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
| 165 | 165 | CUR_active tinyint(1) DEFAULT '0', |
| 166 | 166 | PRIMARY KEY (CUR_code)" |
| 167 | - ); |
|
| 167 | + ); |
|
| 168 | 168 | |
| 169 | 169 | |
| 170 | - // note: although this table is no longer in use, |
|
| 171 | - // it hasn't been removed because then queries to the model will have errors. |
|
| 172 | - // but you should expect this table and its corresponding model to be removed in |
|
| 173 | - // the next few months |
|
| 174 | - $this->_table_is_new_in_this_version( |
|
| 175 | - 'esp_currency_payment_method', |
|
| 176 | - "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 170 | + // note: although this table is no longer in use, |
|
| 171 | + // it hasn't been removed because then queries to the model will have errors. |
|
| 172 | + // but you should expect this table and its corresponding model to be removed in |
|
| 173 | + // the next few months |
|
| 174 | + $this->_table_is_new_in_this_version( |
|
| 175 | + 'esp_currency_payment_method', |
|
| 176 | + "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 177 | 177 | CUR_code varchar(6) NOT NULL, |
| 178 | 178 | PMD_ID int(11) NOT NULL, |
| 179 | 179 | PRIMARY KEY (CPM_ID)" |
| 180 | - ); |
|
| 181 | - $this->_get_table_manager()->addIndex('esp_currency_payment_method', 'PMD_ID', 'PMD_ID'); |
|
| 180 | + ); |
|
| 181 | + $this->_get_table_manager()->addIndex('esp_currency_payment_method', 'PMD_ID', 'PMD_ID'); |
|
| 182 | 182 | |
| 183 | 183 | |
| 184 | - $this->_table_is_changed_in_this_version( |
|
| 185 | - 'esp_datetime', |
|
| 186 | - "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 184 | + $this->_table_is_changed_in_this_version( |
|
| 185 | + 'esp_datetime', |
|
| 186 | + "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 187 | 187 | EVT_ID bigint(20) unsigned NOT NULL, |
| 188 | 188 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 189 | 189 | DTT_name varchar(255) NOT NULL DEFAULT '', |
@@ -198,39 +198,39 @@ discard block |
||
| 198 | 198 | DTT_parent int(10) unsigned DEFAULT 0, |
| 199 | 199 | DTT_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 200 | 200 | PRIMARY KEY (DTT_ID)" |
| 201 | - ); |
|
| 202 | - $this->_get_table_manager()->addIndex('esp_datetime', 'EVT_ID', 'EVT_ID'); |
|
| 203 | - // $this->_get_table_manager()->addIndex('esp_datetime', 'VNU_ID', 'VNU_ID'); |
|
| 204 | - $this->_get_table_manager()->addIndex('esp_datetime', 'DTT_EVT_start', 'DTT_EVT_start'); |
|
| 205 | - // $this->_get_table_manager()->addIndex('esp_datetime', 'DTT_EVT_end', 'DTT_EVT_end'); |
|
| 206 | - // $this->_get_table_manager()->dropIndex('esp_datetime', 'DTT_is_primary'); |
|
| 201 | + ); |
|
| 202 | + $this->_get_table_manager()->addIndex('esp_datetime', 'EVT_ID', 'EVT_ID'); |
|
| 203 | + // $this->_get_table_manager()->addIndex('esp_datetime', 'VNU_ID', 'VNU_ID'); |
|
| 204 | + $this->_get_table_manager()->addIndex('esp_datetime', 'DTT_EVT_start', 'DTT_EVT_start'); |
|
| 205 | + // $this->_get_table_manager()->addIndex('esp_datetime', 'DTT_EVT_end', 'DTT_EVT_end'); |
|
| 206 | + // $this->_get_table_manager()->dropIndex('esp_datetime', 'DTT_is_primary'); |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - $this->_table_has_not_changed_since_previous( |
|
| 210 | - 'esp_datetime_ticket', |
|
| 211 | - "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 209 | + $this->_table_has_not_changed_since_previous( |
|
| 210 | + 'esp_datetime_ticket', |
|
| 211 | + "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 212 | 212 | DTT_ID int(10) unsigned NOT NULL, |
| 213 | 213 | TKT_ID int(10) unsigned NOT NULL, |
| 214 | 214 | PRIMARY KEY (DTK_ID)" |
| 215 | - ); |
|
| 216 | - $this->_get_table_manager()->addIndex('esp_datetime_ticket', 'DTT_ID', 'DTT_ID'); |
|
| 217 | - $this->_get_table_manager()->addIndex('esp_datetime_ticket', 'TKT_ID', 'TKT_ID'); |
|
| 215 | + ); |
|
| 216 | + $this->_get_table_manager()->addIndex('esp_datetime_ticket', 'DTT_ID', 'DTT_ID'); |
|
| 217 | + $this->_get_table_manager()->addIndex('esp_datetime_ticket', 'TKT_ID', 'TKT_ID'); |
|
| 218 | 218 | |
| 219 | 219 | |
| 220 | - $this->_table_has_not_changed_since_previous( |
|
| 221 | - 'esp_event_message_template', |
|
| 222 | - "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 220 | + $this->_table_has_not_changed_since_previous( |
|
| 221 | + 'esp_event_message_template', |
|
| 222 | + "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 223 | 223 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 224 | 224 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
| 225 | 225 | PRIMARY KEY (EMT_ID)" |
| 226 | - ); |
|
| 227 | - $this->_get_table_manager()->addIndex('esp_event_message_template', 'EVT_ID', 'EVT_ID'); |
|
| 228 | - $this->_get_table_manager()->addIndex('esp_event_message_template', 'GRP_ID', 'GRP_ID'); |
|
| 226 | + ); |
|
| 227 | + $this->_get_table_manager()->addIndex('esp_event_message_template', 'EVT_ID', 'EVT_ID'); |
|
| 228 | + $this->_get_table_manager()->addIndex('esp_event_message_template', 'GRP_ID', 'GRP_ID'); |
|
| 229 | 229 | |
| 230 | 230 | |
| 231 | - $this->_table_is_changed_in_this_version( |
|
| 232 | - 'esp_event_meta', |
|
| 233 | - "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
| 231 | + $this->_table_is_changed_in_this_version( |
|
| 232 | + 'esp_event_meta', |
|
| 233 | + "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
| 234 | 234 | EVT_ID bigint(20) unsigned NOT NULL, |
| 235 | 235 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 236 | 236 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -246,77 +246,77 @@ discard block |
||
| 246 | 246 | EVT_donations tinyint(1) NULL, |
| 247 | 247 | FSC_UUID varchar(25) DEFAULT NULL, |
| 248 | 248 | PRIMARY KEY (EVTM_ID)" |
| 249 | - ); |
|
| 250 | - $this->_get_table_manager()->addIndex( |
|
| 251 | - 'esp_event_meta', |
|
| 252 | - 'EVT_ID', |
|
| 253 | - 'EVT_ID', |
|
| 254 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 255 | - null, |
|
| 256 | - true |
|
| 257 | - ); |
|
| 258 | - // $this->_get_table_manager()->addIndex('esp_event_meta', 'VNU_ID', 'VNU_ID'); |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - $this->_table_has_not_changed_since_previous( |
|
| 262 | - 'esp_event_question_group', |
|
| 263 | - "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 249 | + ); |
|
| 250 | + $this->_get_table_manager()->addIndex( |
|
| 251 | + 'esp_event_meta', |
|
| 252 | + 'EVT_ID', |
|
| 253 | + 'EVT_ID', |
|
| 254 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 255 | + null, |
|
| 256 | + true |
|
| 257 | + ); |
|
| 258 | + // $this->_get_table_manager()->addIndex('esp_event_meta', 'VNU_ID', 'VNU_ID'); |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + $this->_table_has_not_changed_since_previous( |
|
| 262 | + 'esp_event_question_group', |
|
| 263 | + "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 264 | 264 | EVT_ID bigint(20) unsigned NOT NULL, |
| 265 | 265 | QSG_ID int(10) unsigned NOT NULL, |
| 266 | 266 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 267 | 267 | EQG_additional tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 268 | 268 | PRIMARY KEY (EQG_ID)" |
| 269 | - ); |
|
| 270 | - $this->_get_table_manager()->addIndex('esp_event_question_group', 'EVT_ID', 'EVT_ID'); |
|
| 271 | - $this->_get_table_manager()->addIndex('esp_event_question_group', 'QSG_ID', 'QSG_ID'); |
|
| 269 | + ); |
|
| 270 | + $this->_get_table_manager()->addIndex('esp_event_question_group', 'EVT_ID', 'EVT_ID'); |
|
| 271 | + $this->_get_table_manager()->addIndex('esp_event_question_group', 'QSG_ID', 'QSG_ID'); |
|
| 272 | 272 | |
| 273 | 273 | |
| 274 | - $this->_table_has_not_changed_since_previous( |
|
| 275 | - 'esp_event_venue', |
|
| 276 | - "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 274 | + $this->_table_has_not_changed_since_previous( |
|
| 275 | + 'esp_event_venue', |
|
| 276 | + "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 277 | 277 | EVT_ID bigint(20) unsigned NOT NULL, |
| 278 | 278 | VNU_ID bigint(20) unsigned NOT NULL, |
| 279 | 279 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 280 | 280 | PRIMARY KEY (EVV_ID)" |
| 281 | - ); |
|
| 281 | + ); |
|
| 282 | 282 | |
| 283 | 283 | |
| 284 | - $this->_table_has_not_changed_since_previous( |
|
| 285 | - 'esp_extra_meta', |
|
| 286 | - "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 284 | + $this->_table_has_not_changed_since_previous( |
|
| 285 | + 'esp_extra_meta', |
|
| 286 | + "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 287 | 287 | OBJ_ID int(11) DEFAULT NULL, |
| 288 | 288 | EXM_type varchar(45) DEFAULT NULL, |
| 289 | 289 | EXM_key varchar(45) DEFAULT NULL, |
| 290 | 290 | EXM_value text, |
| 291 | 291 | PRIMARY KEY (EXM_ID)" |
| 292 | - ); |
|
| 293 | - $this->_get_table_manager()->addIndex('esp_extra_meta', 'EXM_type', 'EXM_type,OBJ_ID,EXM_key'); |
|
| 292 | + ); |
|
| 293 | + $this->_get_table_manager()->addIndex('esp_extra_meta', 'EXM_type', 'EXM_type,OBJ_ID,EXM_key'); |
|
| 294 | 294 | |
| 295 | 295 | |
| 296 | - $this->_table_has_not_changed_since_previous( |
|
| 297 | - 'esp_extra_join', |
|
| 298 | - "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 296 | + $this->_table_has_not_changed_since_previous( |
|
| 297 | + 'esp_extra_join', |
|
| 298 | + "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 299 | 299 | EXJ_first_model_id varchar(12) NOT NULL, |
| 300 | 300 | EXJ_first_model_name varchar(20) NOT NULL, |
| 301 | 301 | EXJ_second_model_id varchar(12) NOT NULL, |
| 302 | 302 | EXJ_second_model_name varchar(20) NOT NULL, |
| 303 | 303 | PRIMARY KEY (EXJ_ID)" |
| 304 | - ); |
|
| 305 | - $this->_get_table_manager()->addIndex( |
|
| 306 | - 'esp_extra_join', |
|
| 307 | - 'first_model', |
|
| 308 | - 'EXJ_first_model_name,EXJ_first_model_id' |
|
| 309 | - ); |
|
| 310 | - $this->_get_table_manager()->addIndex( |
|
| 311 | - 'esp_extra_join', |
|
| 312 | - 'second_model', |
|
| 313 | - 'EXJ_second_model_name,EXJ_second_model_id' |
|
| 314 | - ); |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - $this->_table_is_new_in_this_version( |
|
| 318 | - 'esp_form_element', |
|
| 319 | - "FIN_UUID varchar(25) NOT NULL, |
|
| 304 | + ); |
|
| 305 | + $this->_get_table_manager()->addIndex( |
|
| 306 | + 'esp_extra_join', |
|
| 307 | + 'first_model', |
|
| 308 | + 'EXJ_first_model_name,EXJ_first_model_id' |
|
| 309 | + ); |
|
| 310 | + $this->_get_table_manager()->addIndex( |
|
| 311 | + 'esp_extra_join', |
|
| 312 | + 'second_model', |
|
| 313 | + 'EXJ_second_model_name,EXJ_second_model_id' |
|
| 314 | + ); |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + $this->_table_is_new_in_this_version( |
|
| 318 | + 'esp_form_element', |
|
| 319 | + "FIN_UUID varchar(25) NOT NULL, |
|
| 320 | 320 | FSC_UUID varchar(25) NOT NULL, |
| 321 | 321 | FIN_adminOnly tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 322 | 322 | FIN_attributes text DEFAULT NULL, |
@@ -330,15 +330,15 @@ discard block |
||
| 330 | 330 | FIN_type tinytext DEFAULT NULL, |
| 331 | 331 | FIN_wpUser bigint(20) unsigned DEFAULT NULL, |
| 332 | 332 | PRIMARY KEY (FIN_UUID)" |
| 333 | - ); |
|
| 334 | - $this->_get_table_manager()->addIndex('esp_form_element', 'FSC_UUID', 'FSC_UUID'); |
|
| 335 | - // $this->_get_table_manager()->dropIndex('esp_form_element', 'FIN_order'); |
|
| 336 | - // $this->_get_table_manager()->dropIndex('esp_form_element', 'FIN_status'); |
|
| 333 | + ); |
|
| 334 | + $this->_get_table_manager()->addIndex('esp_form_element', 'FSC_UUID', 'FSC_UUID'); |
|
| 335 | + // $this->_get_table_manager()->dropIndex('esp_form_element', 'FIN_order'); |
|
| 336 | + // $this->_get_table_manager()->dropIndex('esp_form_element', 'FIN_status'); |
|
| 337 | 337 | |
| 338 | 338 | |
| 339 | - $this->_table_is_new_in_this_version( |
|
| 340 | - 'esp_form_section', |
|
| 341 | - "FSC_UUID varchar(25) NOT NULL, |
|
| 339 | + $this->_table_is_new_in_this_version( |
|
| 340 | + 'esp_form_section', |
|
| 341 | + "FSC_UUID varchar(25) NOT NULL, |
|
| 342 | 342 | FSC_appliesTo tinytext NOT NULL, |
| 343 | 343 | FSC_attributes text DEFAULT NULL, |
| 344 | 344 | FSC_belongsTo varchar(25) DEFAULT NULL, |
@@ -347,36 +347,36 @@ discard block |
||
| 347 | 347 | FSC_status varchar(32) NOT NULL DEFAULT 'active', |
| 348 | 348 | FSC_wpUser bigint(20) unsigned DEFAULT NULL, |
| 349 | 349 | PRIMARY KEY (FSC_UUID)" |
| 350 | - ); |
|
| 351 | - $this->_get_table_manager()->addIndex('esp_form_section', 'FSC_belongsTo', 'FSC_belongsTo'); |
|
| 352 | - // $this->_get_table_manager()->dropIndex('esp_form_section', 'FSC_order'); |
|
| 353 | - // $this->_get_table_manager()->dropIndex('esp_form_section', 'FSC_status'); |
|
| 350 | + ); |
|
| 351 | + $this->_get_table_manager()->addIndex('esp_form_section', 'FSC_belongsTo', 'FSC_belongsTo'); |
|
| 352 | + // $this->_get_table_manager()->dropIndex('esp_form_section', 'FSC_order'); |
|
| 353 | + // $this->_get_table_manager()->dropIndex('esp_form_section', 'FSC_status'); |
|
| 354 | 354 | |
| 355 | 355 | |
| 356 | - $this->_table_is_new_in_this_version( |
|
| 357 | - 'esp_form_submission', |
|
| 358 | - "FSB_UUID varchar(25) NOT NULL, |
|
| 356 | + $this->_table_is_new_in_this_version( |
|
| 357 | + 'esp_form_submission', |
|
| 358 | + "FSB_UUID varchar(25) NOT NULL, |
|
| 359 | 359 | FSC_UUID varchar(25) NOT NULL, |
| 360 | 360 | TXN_ID int(10) DEFAULT NULL, |
| 361 | 361 | FSB_data mediumtext DEFAULT NULL, |
| 362 | 362 | FSB_submitted datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 363 | 363 | PRIMARY KEY (FSB_UUID)" |
| 364 | - ); |
|
| 365 | - $this->_get_table_manager()->addIndex('esp_form_submission', 'FSC_UUID', 'FSC_UUID'); |
|
| 366 | - $this->_get_table_manager()->addIndex('esp_form_submission', 'TXN_ID', 'TXN_ID'); |
|
| 367 | - $this->_get_table_manager()->addIndex( |
|
| 368 | - 'esp_form_submission', |
|
| 369 | - 'FSB_submitted', |
|
| 370 | - 'FSB_submitted', |
|
| 371 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 372 | - null, |
|
| 373 | - true |
|
| 374 | - ); |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - $this->_table_is_changed_in_this_version( |
|
| 378 | - 'esp_line_item', |
|
| 379 | - "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 364 | + ); |
|
| 365 | + $this->_get_table_manager()->addIndex('esp_form_submission', 'FSC_UUID', 'FSC_UUID'); |
|
| 366 | + $this->_get_table_manager()->addIndex('esp_form_submission', 'TXN_ID', 'TXN_ID'); |
|
| 367 | + $this->_get_table_manager()->addIndex( |
|
| 368 | + 'esp_form_submission', |
|
| 369 | + 'FSB_submitted', |
|
| 370 | + 'FSB_submitted', |
|
| 371 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 372 | + null, |
|
| 373 | + true |
|
| 374 | + ); |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + $this->_table_is_changed_in_this_version( |
|
| 378 | + 'esp_line_item', |
|
| 379 | + "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 380 | 380 | LIN_code varchar(245) NOT NULL DEFAULT '', |
| 381 | 381 | TXN_ID int(10) DEFAULT NULL, |
| 382 | 382 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -394,24 +394,24 @@ discard block |
||
| 394 | 394 | OBJ_type varchar(45) DEFAULT NULL, |
| 395 | 395 | LIN_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 396 | 396 | PRIMARY KEY (LIN_ID)" |
| 397 | - ); |
|
| 398 | - $this->_get_table_manager()->addIndex('esp_line_item', 'parent_order', 'LIN_parent,LIN_order'); |
|
| 399 | - $this->_get_table_manager()->addIndex('esp_line_item', 'txn_type_timestamp', 'TXN_ID,LIN_type,LIN_timestamp'); |
|
| 400 | - $this->_get_table_manager()->addIndex('esp_line_item', 'txn_obj_id_obj_type', 'TXN_ID,OBJ_ID,OBJ_type'); |
|
| 401 | - $this->_get_table_manager()->addIndex('esp_line_item', 'obj_id_obj_type', 'OBJ_ID,OBJ_type'); |
|
| 402 | - $this->_get_table_manager()->addIndex( |
|
| 403 | - 'esp_line_item', |
|
| 404 | - 'LIN_timestamp', |
|
| 405 | - 'LIN_timestamp', |
|
| 406 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 407 | - null, |
|
| 408 | - true |
|
| 409 | - ); |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - $this->_table_has_not_changed_since_previous( |
|
| 413 | - 'esp_log', |
|
| 414 | - "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 397 | + ); |
|
| 398 | + $this->_get_table_manager()->addIndex('esp_line_item', 'parent_order', 'LIN_parent,LIN_order'); |
|
| 399 | + $this->_get_table_manager()->addIndex('esp_line_item', 'txn_type_timestamp', 'TXN_ID,LIN_type,LIN_timestamp'); |
|
| 400 | + $this->_get_table_manager()->addIndex('esp_line_item', 'txn_obj_id_obj_type', 'TXN_ID,OBJ_ID,OBJ_type'); |
|
| 401 | + $this->_get_table_manager()->addIndex('esp_line_item', 'obj_id_obj_type', 'OBJ_ID,OBJ_type'); |
|
| 402 | + $this->_get_table_manager()->addIndex( |
|
| 403 | + 'esp_line_item', |
|
| 404 | + 'LIN_timestamp', |
|
| 405 | + 'LIN_timestamp', |
|
| 406 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 407 | + null, |
|
| 408 | + true |
|
| 409 | + ); |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + $this->_table_has_not_changed_since_previous( |
|
| 413 | + 'esp_log', |
|
| 414 | + "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 415 | 415 | LOG_time datetime DEFAULT NULL, |
| 416 | 416 | OBJ_ID varchar(45) DEFAULT NULL, |
| 417 | 417 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -419,15 +419,15 @@ discard block |
||
| 419 | 419 | LOG_message text, |
| 420 | 420 | LOG_wp_user int(11) DEFAULT NULL, |
| 421 | 421 | PRIMARY KEY (LOG_ID)" |
| 422 | - ); |
|
| 423 | - $this->_get_table_manager()->addIndex('esp_log', 'LOG_time', 'LOG_time'); |
|
| 424 | - $this->_get_table_manager()->addIndex('esp_log', 'LOG_type', 'LOG_type'); |
|
| 425 | - $this->_get_table_manager()->addIndex('esp_log', 'OBJ', 'OBJ_type,OBJ_ID'); |
|
| 422 | + ); |
|
| 423 | + $this->_get_table_manager()->addIndex('esp_log', 'LOG_time', 'LOG_time'); |
|
| 424 | + $this->_get_table_manager()->addIndex('esp_log', 'LOG_type', 'LOG_type'); |
|
| 425 | + $this->_get_table_manager()->addIndex('esp_log', 'OBJ', 'OBJ_type,OBJ_ID'); |
|
| 426 | 426 | |
| 427 | 427 | |
| 428 | - $this->_table_has_not_changed_since_previous( |
|
| 429 | - 'esp_message', |
|
| 430 | - "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 428 | + $this->_table_has_not_changed_since_previous( |
|
| 429 | + 'esp_message', |
|
| 430 | + "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
| 431 | 431 | GRP_ID int(10) unsigned NULL, |
| 432 | 432 | MSG_token varchar(255) NULL, |
| 433 | 433 | TXN_ID int(10) unsigned NULL, |
@@ -445,50 +445,50 @@ discard block |
||
| 445 | 445 | MSG_created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 446 | 446 | MSG_modified datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 447 | 447 | PRIMARY KEY (MSG_ID)" |
| 448 | - ); |
|
| 449 | - $this->_get_table_manager()->addIndex('esp_message', 'GRP_ID', 'GRP_ID'); |
|
| 450 | - $this->_get_table_manager()->addIndex('esp_message', 'TXN_ID', 'TXN_ID'); |
|
| 451 | - $this->_get_table_manager()->addIndex('esp_message', 'MSG_recipient_ID', 'MSG_recipient_ID'); |
|
| 452 | - $this->_get_table_manager()->addIndex( |
|
| 453 | - 'esp_message', |
|
| 454 | - 'MSG_to', |
|
| 455 | - 'MSG_to', |
|
| 456 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 457 | - TableAnalysis::INDEX_COLUMN_SIZE |
|
| 458 | - ); |
|
| 459 | - $this->_get_table_manager()->addIndex( |
|
| 460 | - 'esp_message', |
|
| 461 | - 'MSG_from', |
|
| 462 | - 'MSG_from', |
|
| 463 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 464 | - TableAnalysis::INDEX_COLUMN_SIZE |
|
| 465 | - ); |
|
| 466 | - $this->_get_table_manager()->addIndex('esp_message', 'MSG_modified', 'MSG_modified'); |
|
| 467 | - // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_messenger'); |
|
| 468 | - // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_message_type'); |
|
| 469 | - // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_context'); |
|
| 470 | - // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_recipient_type'); |
|
| 471 | - // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_subject'); |
|
| 472 | - // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_created'); |
|
| 473 | - // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_priority'); |
|
| 474 | - // $this->_get_table_manager()->dropIndex('esp_message', 'STS_ID'); |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - $this->_table_has_not_changed_since_previous( |
|
| 478 | - 'esp_message_template', |
|
| 479 | - "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 448 | + ); |
|
| 449 | + $this->_get_table_manager()->addIndex('esp_message', 'GRP_ID', 'GRP_ID'); |
|
| 450 | + $this->_get_table_manager()->addIndex('esp_message', 'TXN_ID', 'TXN_ID'); |
|
| 451 | + $this->_get_table_manager()->addIndex('esp_message', 'MSG_recipient_ID', 'MSG_recipient_ID'); |
|
| 452 | + $this->_get_table_manager()->addIndex( |
|
| 453 | + 'esp_message', |
|
| 454 | + 'MSG_to', |
|
| 455 | + 'MSG_to', |
|
| 456 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 457 | + TableAnalysis::INDEX_COLUMN_SIZE |
|
| 458 | + ); |
|
| 459 | + $this->_get_table_manager()->addIndex( |
|
| 460 | + 'esp_message', |
|
| 461 | + 'MSG_from', |
|
| 462 | + 'MSG_from', |
|
| 463 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 464 | + TableAnalysis::INDEX_COLUMN_SIZE |
|
| 465 | + ); |
|
| 466 | + $this->_get_table_manager()->addIndex('esp_message', 'MSG_modified', 'MSG_modified'); |
|
| 467 | + // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_messenger'); |
|
| 468 | + // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_message_type'); |
|
| 469 | + // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_context'); |
|
| 470 | + // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_recipient_type'); |
|
| 471 | + // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_subject'); |
|
| 472 | + // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_created'); |
|
| 473 | + // $this->_get_table_manager()->dropIndex('esp_message', 'MSG_priority'); |
|
| 474 | + // $this->_get_table_manager()->dropIndex('esp_message', 'STS_ID'); |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + $this->_table_has_not_changed_since_previous( |
|
| 478 | + 'esp_message_template', |
|
| 479 | + "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 480 | 480 | GRP_ID int(10) unsigned NOT NULL, |
| 481 | 481 | MTP_context varchar(50) NOT NULL, |
| 482 | 482 | MTP_template_field varchar(30) NOT NULL, |
| 483 | 483 | MTP_content text NOT NULL, |
| 484 | 484 | PRIMARY KEY (MTP_ID)" |
| 485 | - ); |
|
| 486 | - $this->_get_table_manager()->addIndex('esp_message_template', 'GRP_ID', 'GRP_ID'); |
|
| 485 | + ); |
|
| 486 | + $this->_get_table_manager()->addIndex('esp_message_template', 'GRP_ID', 'GRP_ID'); |
|
| 487 | 487 | |
| 488 | 488 | |
| 489 | - $this->_table_has_not_changed_since_previous( |
|
| 490 | - 'esp_message_template_group', |
|
| 491 | - "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 489 | + $this->_table_has_not_changed_since_previous( |
|
| 490 | + 'esp_message_template_group', |
|
| 491 | + "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 492 | 492 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
| 493 | 493 | MTP_name varchar(245) NOT NULL DEFAULT '', |
| 494 | 494 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -499,13 +499,13 @@ discard block |
||
| 499 | 499 | MTP_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 500 | 500 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
| 501 | 501 | PRIMARY KEY (GRP_ID)" |
| 502 | - ); |
|
| 503 | - $this->_get_table_manager()->addIndex('esp_message_template_group', 'MTP_user_id', 'MTP_user_id'); |
|
| 502 | + ); |
|
| 503 | + $this->_get_table_manager()->addIndex('esp_message_template_group', 'MTP_user_id', 'MTP_user_id'); |
|
| 504 | 504 | |
| 505 | 505 | |
| 506 | - $this->_table_has_not_changed_since_previous( |
|
| 507 | - 'esp_payment', |
|
| 508 | - "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 506 | + $this->_table_has_not_changed_since_previous( |
|
| 507 | + 'esp_payment', |
|
| 508 | + "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 509 | 509 | TXN_ID int(10) unsigned DEFAULT NULL, |
| 510 | 510 | STS_ID varchar(3) DEFAULT NULL, |
| 511 | 511 | PAY_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
@@ -520,21 +520,21 @@ discard block |
||
| 520 | 520 | PAY_redirect_url varchar(300), |
| 521 | 521 | PAY_redirect_args text, |
| 522 | 522 | PRIMARY KEY (PAY_ID)" |
| 523 | - ); |
|
| 524 | - $this->_get_table_manager()->addIndex( |
|
| 525 | - 'esp_payment', |
|
| 526 | - 'PAY_timestamp', |
|
| 527 | - 'PAY_timestamp', |
|
| 528 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 529 | - null, |
|
| 530 | - true |
|
| 531 | - ); |
|
| 532 | - $this->_get_table_manager()->addIndex('esp_payment', 'TXN_ID', 'TXN_ID'); |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - $this->_table_has_not_changed_since_previous( |
|
| 536 | - 'esp_payment_method', |
|
| 537 | - "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 523 | + ); |
|
| 524 | + $this->_get_table_manager()->addIndex( |
|
| 525 | + 'esp_payment', |
|
| 526 | + 'PAY_timestamp', |
|
| 527 | + 'PAY_timestamp', |
|
| 528 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 529 | + null, |
|
| 530 | + true |
|
| 531 | + ); |
|
| 532 | + $this->_get_table_manager()->addIndex('esp_payment', 'TXN_ID', 'TXN_ID'); |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + $this->_table_has_not_changed_since_previous( |
|
| 536 | + 'esp_payment_method', |
|
| 537 | + "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 538 | 538 | PMD_type varchar(124) DEFAULT NULL, |
| 539 | 539 | PMD_name varchar(255) DEFAULT NULL, |
| 540 | 540 | PMD_desc text, |
@@ -548,19 +548,19 @@ discard block |
||
| 548 | 548 | PMD_button_url varchar(1012) DEFAULT NULL, |
| 549 | 549 | PMD_scope varchar(255) NULL DEFAULT 'frontend', |
| 550 | 550 | PRIMARY KEY (PMD_ID)" |
| 551 | - ); |
|
| 552 | - $this->_get_table_manager()->addIndex( |
|
| 553 | - 'esp_payment_method', |
|
| 554 | - 'PMD_slug_UNIQUE', |
|
| 555 | - 'PMD_slug', |
|
| 556 | - TableAnalysis::INDEX_TYPE_UNIQUE |
|
| 557 | - ); |
|
| 558 | - // $this->_get_table_manager()->dropIndex('esp_payment_method', 'PMD_type'); |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - $this->_table_is_changed_in_this_version( |
|
| 562 | - 'esp_price', |
|
| 563 | - "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 551 | + ); |
|
| 552 | + $this->_get_table_manager()->addIndex( |
|
| 553 | + 'esp_payment_method', |
|
| 554 | + 'PMD_slug_UNIQUE', |
|
| 555 | + 'PMD_slug', |
|
| 556 | + TableAnalysis::INDEX_TYPE_UNIQUE |
|
| 557 | + ); |
|
| 558 | + // $this->_get_table_manager()->dropIndex('esp_payment_method', 'PMD_type'); |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + $this->_table_is_changed_in_this_version( |
|
| 562 | + 'esp_price', |
|
| 563 | + "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 564 | 564 | PRT_ID tinyint(3) unsigned NOT NULL, |
| 565 | 565 | PRC_amount decimal(12,6) NOT NULL DEFAULT '0.00', |
| 566 | 566 | PRC_name varchar(245) NOT NULL, |
@@ -572,13 +572,13 @@ discard block |
||
| 572 | 572 | PRC_wp_user bigint(20) unsigned NULL, |
| 573 | 573 | PRC_parent int(10) unsigned DEFAULT 0, |
| 574 | 574 | PRIMARY KEY (PRC_ID)" |
| 575 | - ); |
|
| 576 | - $this->_get_table_manager()->addIndex('esp_price', 'PRT_ID', 'PRT_ID'); |
|
| 575 | + ); |
|
| 576 | + $this->_get_table_manager()->addIndex('esp_price', 'PRT_ID', 'PRT_ID'); |
|
| 577 | 577 | |
| 578 | 578 | |
| 579 | - $this->_table_has_not_changed_since_previous( |
|
| 580 | - 'esp_price_type', |
|
| 581 | - "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 579 | + $this->_table_has_not_changed_since_previous( |
|
| 580 | + 'esp_price_type', |
|
| 581 | + "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
| 582 | 582 | PRT_name varchar(45) NOT NULL, |
| 583 | 583 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
| 584 | 584 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -587,33 +587,33 @@ discard block |
||
| 587 | 587 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 588 | 588 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
| 589 | 589 | PRIMARY KEY (PRT_ID)" |
| 590 | - ); |
|
| 590 | + ); |
|
| 591 | 591 | |
| 592 | 592 | |
| 593 | - $this->_table_has_not_changed_since_previous( |
|
| 594 | - 'esp_ticket_price', |
|
| 595 | - "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 593 | + $this->_table_has_not_changed_since_previous( |
|
| 594 | + 'esp_ticket_price', |
|
| 595 | + "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 596 | 596 | TKT_ID int(10) unsigned NOT NULL, |
| 597 | 597 | PRC_ID int(10) unsigned NOT NULL, |
| 598 | 598 | PRIMARY KEY (TKP_ID)" |
| 599 | - ); |
|
| 600 | - $this->_get_table_manager()->addIndex('esp_ticket_price', 'TKT_ID', 'TKT_ID'); |
|
| 601 | - $this->_get_table_manager()->addIndex('esp_ticket_price', 'PRC_ID', 'PRC_ID'); |
|
| 599 | + ); |
|
| 600 | + $this->_get_table_manager()->addIndex('esp_ticket_price', 'TKT_ID', 'TKT_ID'); |
|
| 601 | + $this->_get_table_manager()->addIndex('esp_ticket_price', 'PRC_ID', 'PRC_ID'); |
|
| 602 | 602 | |
| 603 | 603 | |
| 604 | - $this->_table_has_not_changed_since_previous( |
|
| 605 | - 'esp_ticket_template', |
|
| 606 | - "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 604 | + $this->_table_has_not_changed_since_previous( |
|
| 605 | + 'esp_ticket_template', |
|
| 606 | + "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 607 | 607 | TTM_name varchar(45) NOT NULL, |
| 608 | 608 | TTM_description text, |
| 609 | 609 | TTM_file varchar(45), |
| 610 | 610 | PRIMARY KEY (TTM_ID)" |
| 611 | - ); |
|
| 611 | + ); |
|
| 612 | 612 | |
| 613 | 613 | |
| 614 | - $this->_table_has_not_changed_since_previous( |
|
| 615 | - 'esp_question', |
|
| 616 | - "QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 614 | + $this->_table_has_not_changed_since_previous( |
|
| 615 | + 'esp_question', |
|
| 616 | + "QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 617 | 617 | QST_display_text text NOT NULL, |
| 618 | 618 | QST_admin_label varchar(255) NOT NULL, |
| 619 | 619 | QST_system varchar(25) DEFAULT NULL, |
@@ -626,13 +626,13 @@ discard block |
||
| 626 | 626 | QST_wp_user bigint(20) unsigned NULL, |
| 627 | 627 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
| 628 | 628 | PRIMARY KEY (QST_ID)" |
| 629 | - ); |
|
| 630 | - // $this->_get_table_manager()->dropIndex('esp_question', 'QST_order'); |
|
| 629 | + ); |
|
| 630 | + // $this->_get_table_manager()->dropIndex('esp_question', 'QST_order'); |
|
| 631 | 631 | |
| 632 | 632 | |
| 633 | - $this->_table_has_not_changed_since_previous( |
|
| 634 | - 'esp_question_group', |
|
| 635 | - "QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 633 | + $this->_table_has_not_changed_since_previous( |
|
| 634 | + 'esp_question_group', |
|
| 635 | + "QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 636 | 636 | QSG_name varchar(255) NOT NULL, |
| 637 | 637 | QSG_identifier varchar(100) NOT NULL, |
| 638 | 638 | QSG_desc text NULL, |
@@ -643,31 +643,31 @@ discard block |
||
| 643 | 643 | QSG_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 644 | 644 | QSG_wp_user bigint(20) unsigned NULL, |
| 645 | 645 | PRIMARY KEY (QSG_ID)" |
| 646 | - ); |
|
| 647 | - $this->_get_table_manager()->addIndex( |
|
| 648 | - 'esp_question_group', |
|
| 649 | - 'QSG_identifier_UNIQUE', |
|
| 650 | - 'QSG_identifier', |
|
| 651 | - TableAnalysis::INDEX_TYPE_UNIQUE |
|
| 652 | - ); |
|
| 653 | - // $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_order'); |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - $this->_table_has_not_changed_since_previous( |
|
| 657 | - 'esp_question_group_question', |
|
| 658 | - "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 646 | + ); |
|
| 647 | + $this->_get_table_manager()->addIndex( |
|
| 648 | + 'esp_question_group', |
|
| 649 | + 'QSG_identifier_UNIQUE', |
|
| 650 | + 'QSG_identifier', |
|
| 651 | + TableAnalysis::INDEX_TYPE_UNIQUE |
|
| 652 | + ); |
|
| 653 | + // $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_order'); |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + $this->_table_has_not_changed_since_previous( |
|
| 657 | + 'esp_question_group_question', |
|
| 658 | + "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 659 | 659 | QSG_ID int(10) unsigned NOT NULL, |
| 660 | 660 | QST_ID int(10) unsigned NOT NULL, |
| 661 | 661 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
| 662 | 662 | PRIMARY KEY (QGQ_ID)" |
| 663 | - ); |
|
| 664 | - $this->_get_table_manager()->addIndex('esp_question_group_question', 'QST_ID', 'QST_ID'); |
|
| 665 | - // $this->_get_table_manager()->dropIndex('esp_question_group_question', 'QSG_ID_order'); |
|
| 663 | + ); |
|
| 664 | + $this->_get_table_manager()->addIndex('esp_question_group_question', 'QST_ID', 'QST_ID'); |
|
| 665 | + // $this->_get_table_manager()->dropIndex('esp_question_group_question', 'QSG_ID_order'); |
|
| 666 | 666 | |
| 667 | 667 | |
| 668 | - $this->_table_has_not_changed_since_previous( |
|
| 669 | - 'esp_question_option', |
|
| 670 | - "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 668 | + $this->_table_has_not_changed_since_previous( |
|
| 669 | + 'esp_question_option', |
|
| 670 | + "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 671 | 671 | QSO_value varchar(255) NOT NULL, |
| 672 | 672 | QSO_desc text NOT NULL, |
| 673 | 673 | QST_ID int(10) unsigned NOT NULL, |
@@ -675,14 +675,14 @@ discard block |
||
| 675 | 675 | QSO_system varchar(25) DEFAULT NULL, |
| 676 | 676 | QSO_deleted tinyint(1) unsigned NOT NULL DEFAULT 0, |
| 677 | 677 | PRIMARY KEY (QSO_ID)" |
| 678 | - ); |
|
| 679 | - $this->_get_table_manager()->addIndex('esp_question_option', 'QST_ID', 'QST_ID'); |
|
| 680 | - $this->_get_table_manager()->dropIndex('esp_question_option', 'QSO_order'); |
|
| 678 | + ); |
|
| 679 | + $this->_get_table_manager()->addIndex('esp_question_option', 'QST_ID', 'QST_ID'); |
|
| 680 | + $this->_get_table_manager()->dropIndex('esp_question_option', 'QSO_order'); |
|
| 681 | 681 | |
| 682 | 682 | |
| 683 | - $this->_table_has_not_changed_since_previous( |
|
| 684 | - 'esp_registration', |
|
| 685 | - "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 683 | + $this->_table_has_not_changed_since_previous( |
|
| 684 | + 'esp_registration', |
|
| 685 | + "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 686 | 686 | EVT_ID bigint(20) unsigned NOT NULL, |
| 687 | 687 | ATT_ID bigint(20) unsigned NOT NULL, |
| 688 | 688 | TXN_ID int(10) unsigned NOT NULL, |
@@ -699,67 +699,67 @@ discard block |
||
| 699 | 699 | REG_att_is_going tinyint(1) DEFAULT '0', |
| 700 | 700 | REG_deleted tinyint(1) DEFAULT '0', |
| 701 | 701 | PRIMARY KEY (REG_ID)" |
| 702 | - ); |
|
| 703 | - $this->_get_table_manager()->addIndex('esp_registration', 'REG_url_link', 'REG_url_link'); |
|
| 704 | - $this->_get_table_manager()->addIndex('esp_registration', 'REG_code', 'REG_code'); |
|
| 705 | - // $this->_get_table_manager()->addIndex( |
|
| 706 | - // 'esp_registration', |
|
| 707 | - // 'REG_date', |
|
| 708 | - // 'REG_date', |
|
| 709 | - // TableAnalysis::INDEX_TYPE_INDEX, |
|
| 710 | - // null, |
|
| 711 | - // true |
|
| 712 | - // ); |
|
| 713 | - $this->_get_table_manager()->addIndex('esp_registration', 'TXN_ID', 'TXN_ID'); |
|
| 714 | - $this->_get_table_manager()->addIndex('esp_registration', 'ATT_ID', 'ATT_ID'); |
|
| 715 | - $this->_get_table_manager()->addIndex('esp_registration', 'TKT_ID', 'TKT_ID'); |
|
| 716 | - $this->_get_table_manager()->addIndex('esp_registration', 'EVT_ID', 'EVT_ID'); |
|
| 717 | - $this->_get_table_manager()->dropIndex('esp_registration', 'REG_deleted'); |
|
| 718 | - // $this->_get_table_manager()->dropIndex('esp_registration', 'STS_ID'); |
|
| 719 | - |
|
| 720 | - |
|
| 721 | - $this->_table_has_not_changed_since_previous( |
|
| 722 | - 'esp_registration_payment', |
|
| 723 | - "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 702 | + ); |
|
| 703 | + $this->_get_table_manager()->addIndex('esp_registration', 'REG_url_link', 'REG_url_link'); |
|
| 704 | + $this->_get_table_manager()->addIndex('esp_registration', 'REG_code', 'REG_code'); |
|
| 705 | + // $this->_get_table_manager()->addIndex( |
|
| 706 | + // 'esp_registration', |
|
| 707 | + // 'REG_date', |
|
| 708 | + // 'REG_date', |
|
| 709 | + // TableAnalysis::INDEX_TYPE_INDEX, |
|
| 710 | + // null, |
|
| 711 | + // true |
|
| 712 | + // ); |
|
| 713 | + $this->_get_table_manager()->addIndex('esp_registration', 'TXN_ID', 'TXN_ID'); |
|
| 714 | + $this->_get_table_manager()->addIndex('esp_registration', 'ATT_ID', 'ATT_ID'); |
|
| 715 | + $this->_get_table_manager()->addIndex('esp_registration', 'TKT_ID', 'TKT_ID'); |
|
| 716 | + $this->_get_table_manager()->addIndex('esp_registration', 'EVT_ID', 'EVT_ID'); |
|
| 717 | + $this->_get_table_manager()->dropIndex('esp_registration', 'REG_deleted'); |
|
| 718 | + // $this->_get_table_manager()->dropIndex('esp_registration', 'STS_ID'); |
|
| 719 | + |
|
| 720 | + |
|
| 721 | + $this->_table_has_not_changed_since_previous( |
|
| 722 | + 'esp_registration_payment', |
|
| 723 | + "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 724 | 724 | REG_ID int(10) unsigned NOT NULL, |
| 725 | 725 | PAY_ID int(10) unsigned NULL, |
| 726 | 726 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
| 727 | 727 | PRIMARY KEY (RPY_ID)" |
| 728 | - ); |
|
| 729 | - $this->_get_table_manager()->addIndex('esp_registration_payment', 'REG_ID', 'REG_ID'); |
|
| 730 | - $this->_get_table_manager()->addIndex('esp_registration_payment', 'PAY_ID', 'PAY_ID'); |
|
| 728 | + ); |
|
| 729 | + $this->_get_table_manager()->addIndex('esp_registration_payment', 'REG_ID', 'REG_ID'); |
|
| 730 | + $this->_get_table_manager()->addIndex('esp_registration_payment', 'PAY_ID', 'PAY_ID'); |
|
| 731 | 731 | |
| 732 | 732 | |
| 733 | - $this->_table_has_not_changed_since_previous( |
|
| 734 | - 'esp_state', |
|
| 735 | - "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 733 | + $this->_table_has_not_changed_since_previous( |
|
| 734 | + 'esp_state', |
|
| 735 | + "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
| 736 | 736 | CNT_ISO varchar(2) NOT NULL, |
| 737 | 737 | STA_abbrev varchar(24) NOT NULL, |
| 738 | 738 | STA_name varchar(100) NOT NULL, |
| 739 | 739 | STA_active tinyint(1) DEFAULT '1', |
| 740 | 740 | PRIMARY KEY (STA_ID)" |
| 741 | - ); |
|
| 742 | - $this->_get_table_manager()->addIndex('esp_state', 'STA_abbrev', 'STA_abbrev'); |
|
| 743 | - $this->_get_table_manager()->addIndex('esp_state', 'CNT_ISO', 'CNT_ISO'); |
|
| 741 | + ); |
|
| 742 | + $this->_get_table_manager()->addIndex('esp_state', 'STA_abbrev', 'STA_abbrev'); |
|
| 743 | + $this->_get_table_manager()->addIndex('esp_state', 'CNT_ISO', 'CNT_ISO'); |
|
| 744 | 744 | |
| 745 | 745 | |
| 746 | - $this->_table_has_not_changed_since_previous( |
|
| 747 | - 'esp_status', |
|
| 748 | - "STS_ID varchar(3) NOT NULL, |
|
| 746 | + $this->_table_has_not_changed_since_previous( |
|
| 747 | + 'esp_status', |
|
| 748 | + "STS_ID varchar(3) NOT NULL, |
|
| 749 | 749 | STS_code varchar(45) NOT NULL, |
| 750 | 750 | STS_type varchar(45) NOT NULL, |
| 751 | 751 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
| 752 | 752 | STS_desc tinytext, |
| 753 | 753 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
| 754 | 754 | PRIMARY KEY (STS_ID)" |
| 755 | - ); |
|
| 756 | - $this->_get_table_manager()->addIndex('esp_status', 'STS_type', 'STS_type'); |
|
| 757 | - $this->_get_table_manager()->dropIndex('esp_status', 'STS_ID_UNIQUE'); |
|
| 755 | + ); |
|
| 756 | + $this->_get_table_manager()->addIndex('esp_status', 'STS_type', 'STS_type'); |
|
| 757 | + $this->_get_table_manager()->dropIndex('esp_status', 'STS_ID_UNIQUE'); |
|
| 758 | 758 | |
| 759 | 759 | |
| 760 | - $this->_table_is_changed_in_this_version( |
|
| 761 | - 'esp_ticket', |
|
| 762 | - "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 760 | + $this->_table_is_changed_in_this_version( |
|
| 761 | + 'esp_ticket', |
|
| 762 | + "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 763 | 763 | TTM_ID int(10) unsigned NOT NULL, |
| 764 | 764 | TKT_name varchar(245) NOT NULL DEFAULT '', |
| 765 | 765 | TKT_description text NOT NULL, |
@@ -783,14 +783,14 @@ discard block |
||
| 783 | 783 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
| 784 | 784 | TKT_visibility smallint(6) unsigned NOT NULL DEFAULT 100, |
| 785 | 785 | PRIMARY KEY (TKT_ID)" |
| 786 | - ); |
|
| 787 | - $this->_get_table_manager()->addIndex('esp_ticket', 'TKT_start_date', 'TKT_start_date'); |
|
| 788 | - // $this->_get_table_manager()->addIndex('esp_ticket', 'TKT_end_date', 'TKT_end_date'); |
|
| 786 | + ); |
|
| 787 | + $this->_get_table_manager()->addIndex('esp_ticket', 'TKT_start_date', 'TKT_start_date'); |
|
| 788 | + // $this->_get_table_manager()->addIndex('esp_ticket', 'TKT_end_date', 'TKT_end_date'); |
|
| 789 | 789 | |
| 790 | 790 | |
| 791 | - $this->_table_has_not_changed_since_previous( |
|
| 792 | - 'esp_transaction', |
|
| 793 | - "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 791 | + $this->_table_has_not_changed_since_previous( |
|
| 792 | + 'esp_transaction', |
|
| 793 | + "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
| 794 | 794 | TXN_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 795 | 795 | TXN_total decimal(12,3) DEFAULT '0.00', |
| 796 | 796 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -800,21 +800,21 @@ discard block |
||
| 800 | 800 | PMD_ID int(11) DEFAULT NULL, |
| 801 | 801 | TXN_reg_steps text, |
| 802 | 802 | PRIMARY KEY (TXN_ID)" |
| 803 | - ); |
|
| 804 | - $this->_get_table_manager()->addIndex( |
|
| 805 | - 'esp_transaction', |
|
| 806 | - 'TXN_timestamp', |
|
| 807 | - 'TXN_timestamp', |
|
| 808 | - TableAnalysis::INDEX_TYPE_INDEX, |
|
| 809 | - null, |
|
| 810 | - true |
|
| 811 | - ); |
|
| 812 | - // $this->_get_table_manager()->dropIndex('esp_transaction', 'STS_ID'); |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - $this->_table_has_not_changed_since_previous( |
|
| 816 | - 'esp_venue_meta', |
|
| 817 | - 'VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 803 | + ); |
|
| 804 | + $this->_get_table_manager()->addIndex( |
|
| 805 | + 'esp_transaction', |
|
| 806 | + 'TXN_timestamp', |
|
| 807 | + 'TXN_timestamp', |
|
| 808 | + TableAnalysis::INDEX_TYPE_INDEX, |
|
| 809 | + null, |
|
| 810 | + true |
|
| 811 | + ); |
|
| 812 | + // $this->_get_table_manager()->dropIndex('esp_transaction', 'STS_ID'); |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + $this->_table_has_not_changed_since_previous( |
|
| 816 | + 'esp_venue_meta', |
|
| 817 | + 'VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
| 818 | 818 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
| 819 | 819 | VNU_address varchar(255) DEFAULT NULL, |
| 820 | 820 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -830,29 +830,29 @@ discard block |
||
| 830 | 830 | VNU_enable_for_gmap tinyint(1) DEFAULT 0, |
| 831 | 831 | VNU_google_map_link varchar(255) DEFAULT NULL, |
| 832 | 832 | PRIMARY KEY (VNUM_ID)' |
| 833 | - ); |
|
| 834 | - $this->_get_table_manager()->addIndex('esp_venue_meta', 'VNU_ID', 'VNU_ID'); |
|
| 835 | - $this->_get_table_manager()->addIndex('esp_venue_meta', 'STA_ID', 'STA_ID'); |
|
| 836 | - $this->_get_table_manager()->addIndex('esp_venue_meta', 'CNT_ISO', 'CNT_ISO'); |
|
| 833 | + ); |
|
| 834 | + $this->_get_table_manager()->addIndex('esp_venue_meta', 'VNU_ID', 'VNU_ID'); |
|
| 835 | + $this->_get_table_manager()->addIndex('esp_venue_meta', 'STA_ID', 'STA_ID'); |
|
| 836 | + $this->_get_table_manager()->addIndex('esp_venue_meta', 'CNT_ISO', 'CNT_ISO'); |
|
| 837 | 837 | |
| 838 | 838 | |
| 839 | - $this->previous_dms->insert_default_data(); |
|
| 840 | - $LegacyTextDomainOptions = new LegacyTextDomainOptions(); |
|
| 841 | - $LegacyTextDomainOptions->convertToConsolidatedFormat(); |
|
| 842 | - return true; |
|
| 843 | - } |
|
| 839 | + $this->previous_dms->insert_default_data(); |
|
| 840 | + $LegacyTextDomainOptions = new LegacyTextDomainOptions(); |
|
| 841 | + $LegacyTextDomainOptions->convertToConsolidatedFormat(); |
|
| 842 | + return true; |
|
| 843 | + } |
|
| 844 | 844 | |
| 845 | 845 | |
| 846 | - /** |
|
| 847 | - * @return bool |
|
| 848 | - */ |
|
| 849 | - public function schema_changes_after_migration(): bool |
|
| 850 | - { |
|
| 851 | - return true; |
|
| 852 | - } |
|
| 846 | + /** |
|
| 847 | + * @return bool |
|
| 848 | + */ |
|
| 849 | + public function schema_changes_after_migration(): bool |
|
| 850 | + { |
|
| 851 | + return true; |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | 854 | |
| 855 | - public function migration_page_hooks() |
|
| 856 | - { |
|
| 857 | - } |
|
| 855 | + public function migration_page_hooks() |
|
| 856 | + { |
|
| 857 | + } |
|
| 858 | 858 | } |
@@ -15,86 +15,86 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | abstract class EE_Data_Migration_Script_Stage_Table extends EE_Data_Migration_Script_Stage |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var string The columns to select. May be overridden for children. |
|
| 20 | - */ |
|
| 21 | - protected string $select_expression = '*'; |
|
| 18 | + /** |
|
| 19 | + * @var string The columns to select. May be overridden for children. |
|
| 20 | + */ |
|
| 21 | + protected string $select_expression = '*'; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Set in the constructor to add this sql to both the counting query in |
|
| 25 | - * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and |
|
| 26 | - * EE_Data_Migration_Script_Stage_Table::_get_rows(). |
|
| 27 | - * Eg "where column_name like '%some_value%'" |
|
| 28 | - * |
|
| 29 | - * @var string|null |
|
| 30 | - */ |
|
| 31 | - protected ?string $_extra_where_sql = ''; |
|
| 23 | + /** |
|
| 24 | + * Set in the constructor to add this sql to both the counting query in |
|
| 25 | + * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and |
|
| 26 | + * EE_Data_Migration_Script_Stage_Table::_get_rows(). |
|
| 27 | + * Eg "where column_name like '%some_value%'" |
|
| 28 | + * |
|
| 29 | + * @var string|null |
|
| 30 | + */ |
|
| 31 | + protected ?string $_extra_where_sql = ''; |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property |
|
| 36 | - * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that |
|
| 37 | - * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the |
|
| 38 | - * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees |
|
| 39 | - * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at |
|
| 40 | - * very least we MUST report/return 50 items migrated) |
|
| 41 | - * |
|
| 42 | - * @param int $num_items_to_migrate |
|
| 43 | - * @return int number of items ACTUALLY migrated |
|
| 44 | - */ |
|
| 45 | - public function _migration_step($num_items_to_migrate = 50) |
|
| 46 | - { |
|
| 47 | - $rows = $this->_get_rows($num_items_to_migrate); |
|
| 48 | - $items_actually_migrated = 0; |
|
| 49 | - foreach ($rows as $old_row) { |
|
| 50 | - $this->_migrate_old_row($old_row); |
|
| 51 | - $items_actually_migrated++; |
|
| 52 | - } |
|
| 53 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 54 | - $this->set_completed(); |
|
| 55 | - } |
|
| 56 | - return $items_actually_migrated; |
|
| 57 | - } |
|
| 34 | + /** |
|
| 35 | + * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property |
|
| 36 | + * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that |
|
| 37 | + * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the |
|
| 38 | + * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees |
|
| 39 | + * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at |
|
| 40 | + * very least we MUST report/return 50 items migrated) |
|
| 41 | + * |
|
| 42 | + * @param int $num_items_to_migrate |
|
| 43 | + * @return int number of items ACTUALLY migrated |
|
| 44 | + */ |
|
| 45 | + public function _migration_step($num_items_to_migrate = 50) |
|
| 46 | + { |
|
| 47 | + $rows = $this->_get_rows($num_items_to_migrate); |
|
| 48 | + $items_actually_migrated = 0; |
|
| 49 | + foreach ($rows as $old_row) { |
|
| 50 | + $this->_migrate_old_row($old_row); |
|
| 51 | + $items_actually_migrated++; |
|
| 52 | + } |
|
| 53 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 54 | + $this->set_completed(); |
|
| 55 | + } |
|
| 56 | + return $items_actually_migrated; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Gets the rows for each migration stage from the old table |
|
| 61 | - * |
|
| 62 | - * @global wpdb $wpdb |
|
| 63 | - * @param int $limit |
|
| 64 | - * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
| 65 | - */ |
|
| 66 | - protected function _get_rows($limit) |
|
| 67 | - { |
|
| 68 | - global $wpdb; |
|
| 69 | - $start_at_record = $this->count_records_migrated(); |
|
| 70 | - $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare( |
|
| 71 | - "LIMIT %d, %d", |
|
| 72 | - $start_at_record, |
|
| 73 | - $limit |
|
| 74 | - ); |
|
| 75 | - return $wpdb->get_results($query, ARRAY_A); |
|
| 76 | - } |
|
| 59 | + /** |
|
| 60 | + * Gets the rows for each migration stage from the old table |
|
| 61 | + * |
|
| 62 | + * @global wpdb $wpdb |
|
| 63 | + * @param int $limit |
|
| 64 | + * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
| 65 | + */ |
|
| 66 | + protected function _get_rows($limit) |
|
| 67 | + { |
|
| 68 | + global $wpdb; |
|
| 69 | + $start_at_record = $this->count_records_migrated(); |
|
| 70 | + $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare( |
|
| 71 | + "LIMIT %d, %d", |
|
| 72 | + $start_at_record, |
|
| 73 | + $limit |
|
| 74 | + ); |
|
| 75 | + return $wpdb->get_results($query, ARRAY_A); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Counts the records to migrate; the public version may cache it |
|
| 81 | - * |
|
| 82 | - * @return int |
|
| 83 | - */ |
|
| 84 | - public function _count_records_to_migrate() |
|
| 85 | - { |
|
| 86 | - global $wpdb; |
|
| 87 | - $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}"; |
|
| 88 | - return (int) $wpdb->get_var($query); |
|
| 89 | - } |
|
| 79 | + /** |
|
| 80 | + * Counts the records to migrate; the public version may cache it |
|
| 81 | + * |
|
| 82 | + * @return int |
|
| 83 | + */ |
|
| 84 | + public function _count_records_to_migrate() |
|
| 85 | + { |
|
| 86 | + global $wpdb; |
|
| 87 | + $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}"; |
|
| 88 | + return (int) $wpdb->get_var($query); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * takes care of migrating this particular row from the OLD table to whatever its |
|
| 93 | - * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a |
|
| 94 | - * fatal error which prevents all future migrations, throw an exception describing it |
|
| 95 | - * |
|
| 96 | - * @param array $old_row an associative array where keys are column names and values are their values. |
|
| 97 | - * @return void |
|
| 98 | - */ |
|
| 99 | - abstract protected function _migrate_old_row($old_row); |
|
| 91 | + /** |
|
| 92 | + * takes care of migrating this particular row from the OLD table to whatever its |
|
| 93 | + * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a |
|
| 94 | + * fatal error which prevents all future migrations, throw an exception describing it |
|
| 95 | + * |
|
| 96 | + * @param array $old_row an associative array where keys are column names and values are their values. |
|
| 97 | + * @return void |
|
| 98 | + */ |
|
| 99 | + abstract protected function _migrate_old_row($old_row); |
|
| 100 | 100 | } |
@@ -13,67 +13,67 @@ |
||
| 13 | 13 | class EE_DMS_4_6_0_invoice_settings extends EE_Data_Migration_Script_Stage |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Just initializes the status of the migration |
|
| 18 | - */ |
|
| 19 | - public function __construct() |
|
| 20 | - { |
|
| 21 | - $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
| 22 | - parent::__construct(); |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * Just initializes the status of the migration |
|
| 18 | + */ |
|
| 19 | + public function __construct() |
|
| 20 | + { |
|
| 21 | + $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
| 22 | + parent::__construct(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * _count_records_to_migrate |
|
| 28 | - * Counts the records to migrate; the public version may cache it |
|
| 29 | - * |
|
| 30 | - * @access protected |
|
| 31 | - * @return int |
|
| 32 | - */ |
|
| 33 | - protected function _count_records_to_migrate(): int |
|
| 34 | - { |
|
| 35 | - return 1; |
|
| 36 | - } |
|
| 26 | + /** |
|
| 27 | + * _count_records_to_migrate |
|
| 28 | + * Counts the records to migrate; the public version may cache it |
|
| 29 | + * |
|
| 30 | + * @access protected |
|
| 31 | + * @return int |
|
| 32 | + */ |
|
| 33 | + protected function _count_records_to_migrate(): int |
|
| 34 | + { |
|
| 35 | + return 1; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * _migration_step |
|
| 41 | - * |
|
| 42 | - * @access protected |
|
| 43 | - * @param int $num_items_to_migrate |
|
| 44 | - * @return int number of items ACTUALLY migrated |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - protected function _migration_step($num_items_to_migrate = 1) |
|
| 48 | - { |
|
| 49 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
| 50 | - $overridden_invoice_body = EEH_Template::locate_template( |
|
| 51 | - $templates_relative_path . 'invoice_body.template.php', |
|
| 52 | - [], |
|
| 53 | - false, |
|
| 54 | - false, |
|
| 55 | - true |
|
| 56 | - ); |
|
| 57 | - $overridden_receipt_body = EEH_Template::locate_template( |
|
| 58 | - $templates_relative_path . 'receipt_body.template.php', |
|
| 59 | - [], |
|
| 60 | - false, |
|
| 61 | - false, |
|
| 62 | - true |
|
| 63 | - ); |
|
| 64 | - if ($overridden_invoice_body || $overridden_receipt_body) { |
|
| 65 | - new PersistentAdminNotice( |
|
| 66 | - 'invoice_overriding_templates', |
|
| 67 | - esc_html__( |
|
| 68 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
| 69 | - 'event_espresso' |
|
| 70 | - ), |
|
| 71 | - true |
|
| 72 | - ); |
|
| 73 | - } |
|
| 39 | + /** |
|
| 40 | + * _migration_step |
|
| 41 | + * |
|
| 42 | + * @access protected |
|
| 43 | + * @param int $num_items_to_migrate |
|
| 44 | + * @return int number of items ACTUALLY migrated |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + protected function _migration_step($num_items_to_migrate = 1) |
|
| 48 | + { |
|
| 49 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
| 50 | + $overridden_invoice_body = EEH_Template::locate_template( |
|
| 51 | + $templates_relative_path . 'invoice_body.template.php', |
|
| 52 | + [], |
|
| 53 | + false, |
|
| 54 | + false, |
|
| 55 | + true |
|
| 56 | + ); |
|
| 57 | + $overridden_receipt_body = EEH_Template::locate_template( |
|
| 58 | + $templates_relative_path . 'receipt_body.template.php', |
|
| 59 | + [], |
|
| 60 | + false, |
|
| 61 | + false, |
|
| 62 | + true |
|
| 63 | + ); |
|
| 64 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
| 65 | + new PersistentAdminNotice( |
|
| 66 | + 'invoice_overriding_templates', |
|
| 67 | + esc_html__( |
|
| 68 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
| 69 | + 'event_espresso' |
|
| 70 | + ), |
|
| 71 | + true |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - // regardless of whether it worked or not, we ought to continue the migration |
|
| 76 | - $this->set_completed(); |
|
| 77 | - return 1; |
|
| 78 | - } |
|
| 75 | + // regardless of whether it worked or not, we ought to continue the migration |
|
| 76 | + $this->set_completed(); |
|
| 77 | + return 1; |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -48,14 +48,14 @@ |
||
| 48 | 48 | { |
| 49 | 49 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
| 50 | 50 | $overridden_invoice_body = EEH_Template::locate_template( |
| 51 | - $templates_relative_path . 'invoice_body.template.php', |
|
| 51 | + $templates_relative_path.'invoice_body.template.php', |
|
| 52 | 52 | [], |
| 53 | 53 | false, |
| 54 | 54 | false, |
| 55 | 55 | true |
| 56 | 56 | ); |
| 57 | 57 | $overridden_receipt_body = EEH_Template::locate_template( |
| 58 | - $templates_relative_path . 'receipt_body.template.php', |
|
| 58 | + $templates_relative_path.'receipt_body.template.php', |
|
| 59 | 59 | [], |
| 60 | 60 | false, |
| 61 | 61 | false, |
@@ -27,659 +27,659 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class EEM_Line_Item extends EEM_Base |
| 29 | 29 | { |
| 30 | - /** |
|
| 31 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
| 32 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
| 33 | - * be a direct child of the grand total. Its quantity and LIN_unit_price = 1. |
|
| 34 | - */ |
|
| 35 | - const type_tax_sub_total = 'tax-sub-total'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
| 39 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
| 40 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
| 41 | - */ |
|
| 42 | - const type_tax = 'tax'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Indicating individual items purchased, or discounts or surcharges. |
|
| 46 | - * The sum of all the regular line items plus the tax items should equal the grand total. |
|
| 47 | - * Possible children are sub-line-items and cancellations. |
|
| 48 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
| 49 | - * LIN_totals. Its LIN_percent = 0. |
|
| 50 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
| 51 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
| 52 | - */ |
|
| 53 | - const type_line_item = 'line-item'; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Line item indicating all the factors that make a single line item. |
|
| 57 | - * Sub-line items should have NO children line items. |
|
| 58 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
| 59 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
| 60 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
| 61 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
| 62 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
| 63 | - */ |
|
| 64 | - const type_sub_line_item = 'sub-item'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
| 68 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
| 69 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
| 70 | - */ |
|
| 71 | - const type_sub_tax = 'sub-tax'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
| 75 | - * Direct children should be event subtotals. |
|
| 76 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
| 77 | - */ |
|
| 78 | - const type_sub_total = 'sub-total'; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Line item for the grand total of an order. |
|
| 82 | - * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
| 83 | - * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
| 84 | - * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
| 85 | - */ |
|
| 86 | - const type_total = 'total'; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
| 90 | - * should be created, indicating the quantity that were cancelled |
|
| 91 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
| 92 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
| 93 | - * cancelled, and only one remains). |
|
| 94 | - * When items are refunded, a cancellation line item should be made, which points |
|
| 95 | - * to teh payment model object which actually refunded the payment. |
|
| 96 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
| 97 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
| 98 | - * Their LIN_percent should be 0. |
|
| 99 | - */ |
|
| 100 | - const type_cancellation = 'cancellation'; |
|
| 101 | - |
|
| 102 | - // various line item object types |
|
| 103 | - const OBJ_TYPE_EVENT = 'Event'; |
|
| 104 | - |
|
| 105 | - const OBJ_TYPE_PRICE = 'Price'; |
|
| 106 | - |
|
| 107 | - const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
| 108 | - |
|
| 109 | - const OBJ_TYPE_TICKET = 'Ticket'; |
|
| 110 | - |
|
| 111 | - const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @var EEM_Line_Item $_instance |
|
| 115 | - */ |
|
| 116 | - protected static $_instance; |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * private constructor to prevent direct creation |
|
| 121 | - * |
|
| 122 | - * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings |
|
| 123 | - * (and any incoming timezone data that gets saved). |
|
| 124 | - * Note this just sends the timezone info to the date time model field objects. |
|
| 125 | - * Default is NULL |
|
| 126 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 127 | - * @throws EE_Error |
|
| 128 | - * @throws ReflectionException |
|
| 129 | - */ |
|
| 130 | - protected function __construct(?string $timezone = '') |
|
| 131 | - { |
|
| 132 | - $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
| 133 | - $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
| 134 | - |
|
| 135 | - $this->_tables = [ |
|
| 136 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
| 137 | - ]; |
|
| 138 | - $line_items_can_be_for = apply_filters( |
|
| 139 | - 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
| 140 | - ['Ticket', 'Price', 'Event'] |
|
| 141 | - ); |
|
| 142 | - $this->_fields = [ |
|
| 143 | - 'Line_Item' => [ |
|
| 144 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
| 145 | - 'LIN_ID', |
|
| 146 | - esc_html__('ID', 'event_espresso') |
|
| 147 | - ), |
|
| 148 | - 'LIN_code' => new EE_Slug_Field( |
|
| 149 | - 'LIN_code', |
|
| 150 | - esc_html__('Code for index into Cart', 'event_espresso'), |
|
| 151 | - true |
|
| 152 | - ), |
|
| 153 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
| 154 | - 'TXN_ID', |
|
| 155 | - esc_html__('Transaction ID', 'event_espresso'), |
|
| 156 | - true, |
|
| 157 | - null, |
|
| 158 | - 'Transaction' |
|
| 159 | - ), |
|
| 160 | - 'LIN_name' => new EE_Full_HTML_Field( |
|
| 161 | - 'LIN_name', |
|
| 162 | - esc_html__('Line Item Name', 'event_espresso'), |
|
| 163 | - false, |
|
| 164 | - '' |
|
| 165 | - ), |
|
| 166 | - 'LIN_desc' => new EE_Full_HTML_Field( |
|
| 167 | - 'LIN_desc', |
|
| 168 | - esc_html__('Line Item Description', 'event_espresso'), |
|
| 169 | - true |
|
| 170 | - ), |
|
| 171 | - 'LIN_unit_price' => new EE_Money_Field( |
|
| 172 | - 'LIN_unit_price', |
|
| 173 | - esc_html__('Unit Price', 'event_espresso'), |
|
| 174 | - false, |
|
| 175 | - 0 |
|
| 176 | - ), |
|
| 177 | - 'LIN_percent' => new EE_Float_Field( |
|
| 178 | - 'LIN_percent', |
|
| 179 | - esc_html__('Percent', 'event_espresso'), |
|
| 180 | - false, |
|
| 181 | - 0 |
|
| 182 | - ), |
|
| 183 | - 'LIN_is_taxable' => new EE_Boolean_Field( |
|
| 184 | - 'LIN_is_taxable', |
|
| 185 | - esc_html__('Taxable', 'event_espresso'), |
|
| 186 | - false, |
|
| 187 | - false |
|
| 188 | - ), |
|
| 189 | - 'LIN_order' => new EE_Integer_Field( |
|
| 190 | - 'LIN_order', |
|
| 191 | - esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
| 192 | - false, |
|
| 193 | - 1 |
|
| 194 | - ), |
|
| 195 | - 'LIN_total' => new EE_Money_Field( |
|
| 196 | - 'LIN_total', |
|
| 197 | - esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
| 198 | - false, |
|
| 199 | - 0 |
|
| 200 | - ), |
|
| 201 | - 'LIN_pretax' => new EE_Money_Field( |
|
| 202 | - 'LIN_pretax', |
|
| 203 | - esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
| 204 | - false, |
|
| 205 | - 0 |
|
| 206 | - ), |
|
| 207 | - 'LIN_quantity' => new EE_Integer_Field( |
|
| 208 | - 'LIN_quantity', |
|
| 209 | - esc_html__('Quantity', 'event_espresso'), |
|
| 210 | - false, |
|
| 211 | - 1 |
|
| 212 | - ), |
|
| 213 | - 'LIN_parent' => new EE_Integer_Field( |
|
| 214 | - 'LIN_parent', |
|
| 215 | - esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
| 216 | - true, |
|
| 217 | - null |
|
| 218 | - ), |
|
| 219 | - 'LIN_type' => new EE_Enum_Text_Field( |
|
| 220 | - 'LIN_type', |
|
| 221 | - esc_html__('Type', 'event_espresso'), |
|
| 222 | - false, |
|
| 223 | - 'line-item', |
|
| 224 | - [ |
|
| 225 | - self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
| 226 | - self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
| 227 | - self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
| 228 | - self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
| 229 | - self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
| 230 | - self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
| 231 | - self::type_total => esc_html__('Total', 'event_espresso'), |
|
| 232 | - self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
| 233 | - ] |
|
| 234 | - ), |
|
| 235 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
| 236 | - 'OBJ_ID', |
|
| 237 | - esc_html__('ID of Item purchased.', 'event_espresso'), |
|
| 238 | - true, |
|
| 239 | - null, |
|
| 240 | - $line_items_can_be_for |
|
| 241 | - ), |
|
| 242 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
| 243 | - 'OBJ_type', |
|
| 244 | - esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
| 245 | - true, |
|
| 246 | - null, |
|
| 247 | - $line_items_can_be_for |
|
| 248 | - ), |
|
| 249 | - 'LIN_timestamp' => new EE_Datetime_Field( |
|
| 250 | - 'LIN_timestamp', |
|
| 251 | - esc_html__('When the line item was created', 'event_espresso'), |
|
| 252 | - false, |
|
| 253 | - EE_Datetime_Field::now, |
|
| 254 | - $timezone |
|
| 255 | - ), |
|
| 256 | - ], |
|
| 257 | - ]; |
|
| 258 | - $this->_model_relations = [ |
|
| 259 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
| 260 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
| 261 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
| 262 | - 'Event' => new EE_Belongs_To_Any_Relation(), |
|
| 263 | - ]; |
|
| 264 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
| 265 | - $this->_caps_slug = 'transactions'; |
|
| 266 | - parent::__construct($timezone); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Gets all the line items for this transaction of the given type |
|
| 272 | - * |
|
| 273 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
| 274 | - * @param EE_Transaction|int $transaction |
|
| 275 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 276 | - * @throws EE_Error |
|
| 277 | - * @throws InvalidArgumentException |
|
| 278 | - * @throws InvalidDataTypeException |
|
| 279 | - * @throws InvalidInterfaceException |
|
| 280 | - */ |
|
| 281 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
| 282 | - { |
|
| 283 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 284 | - return $this->get_all( |
|
| 285 | - [ |
|
| 286 | - [ |
|
| 287 | - 'LIN_type' => $line_item_type, |
|
| 288 | - 'TXN_ID' => $transaction, |
|
| 289 | - ], |
|
| 290 | - ] |
|
| 291 | - ); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Gets all line items unrelated to tickets that are normal line items |
|
| 297 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
| 298 | - * |
|
| 299 | - * @param EE_Transaction|int $transaction |
|
| 300 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 301 | - * @throws EE_Error |
|
| 302 | - * @throws InvalidArgumentException |
|
| 303 | - * @throws InvalidDataTypeException |
|
| 304 | - * @throws InvalidInterfaceException |
|
| 305 | - */ |
|
| 306 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
| 307 | - { |
|
| 308 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 309 | - return $this->get_all( |
|
| 310 | - [ |
|
| 311 | - [ |
|
| 312 | - 'LIN_type' => self::type_line_item, |
|
| 313 | - 'TXN_ID' => $transaction, |
|
| 314 | - 'OR' => [ |
|
| 315 | - 'OBJ_type*notticket' => ['!=', EEM_Line_Item::OBJ_TYPE_TICKET], |
|
| 316 | - 'OBJ_type*null' => ['IS_NULL'], |
|
| 317 | - ], |
|
| 318 | - ], |
|
| 319 | - ] |
|
| 320 | - ); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
| 326 | - * This needs to be very efficient |
|
| 327 | - * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
| 328 | - * deleting and joining tables like this. |
|
| 329 | - * |
|
| 330 | - * @return int count of how many deleted |
|
| 331 | - * @throws EE_Error |
|
| 332 | - * @throws InvalidArgumentException |
|
| 333 | - * @throws InvalidDataTypeException |
|
| 334 | - * @throws InvalidInterfaceException |
|
| 335 | - */ |
|
| 336 | - public function delete_line_items_with_no_transaction() |
|
| 337 | - { |
|
| 338 | - /** @type WPDB $wpdb */ |
|
| 339 | - global $wpdb; |
|
| 340 | - $time_to_leave_alone = apply_filters( |
|
| 341 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
| 342 | - WEEK_IN_SECONDS |
|
| 343 | - ); |
|
| 344 | - $query = $wpdb->prepare( |
|
| 345 | - 'DELETE li |
|
| 30 | + /** |
|
| 31 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
| 32 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
| 33 | + * be a direct child of the grand total. Its quantity and LIN_unit_price = 1. |
|
| 34 | + */ |
|
| 35 | + const type_tax_sub_total = 'tax-sub-total'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
| 39 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
| 40 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
| 41 | + */ |
|
| 42 | + const type_tax = 'tax'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Indicating individual items purchased, or discounts or surcharges. |
|
| 46 | + * The sum of all the regular line items plus the tax items should equal the grand total. |
|
| 47 | + * Possible children are sub-line-items and cancellations. |
|
| 48 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
| 49 | + * LIN_totals. Its LIN_percent = 0. |
|
| 50 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
| 51 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
| 52 | + */ |
|
| 53 | + const type_line_item = 'line-item'; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Line item indicating all the factors that make a single line item. |
|
| 57 | + * Sub-line items should have NO children line items. |
|
| 58 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
| 59 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
| 60 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
| 61 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
| 62 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
| 63 | + */ |
|
| 64 | + const type_sub_line_item = 'sub-item'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
| 68 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
| 69 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
| 70 | + */ |
|
| 71 | + const type_sub_tax = 'sub-tax'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
| 75 | + * Direct children should be event subtotals. |
|
| 76 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
| 77 | + */ |
|
| 78 | + const type_sub_total = 'sub-total'; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Line item for the grand total of an order. |
|
| 82 | + * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
| 83 | + * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
| 84 | + * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
| 85 | + */ |
|
| 86 | + const type_total = 'total'; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
| 90 | + * should be created, indicating the quantity that were cancelled |
|
| 91 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
| 92 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
| 93 | + * cancelled, and only one remains). |
|
| 94 | + * When items are refunded, a cancellation line item should be made, which points |
|
| 95 | + * to teh payment model object which actually refunded the payment. |
|
| 96 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
| 97 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
| 98 | + * Their LIN_percent should be 0. |
|
| 99 | + */ |
|
| 100 | + const type_cancellation = 'cancellation'; |
|
| 101 | + |
|
| 102 | + // various line item object types |
|
| 103 | + const OBJ_TYPE_EVENT = 'Event'; |
|
| 104 | + |
|
| 105 | + const OBJ_TYPE_PRICE = 'Price'; |
|
| 106 | + |
|
| 107 | + const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
| 108 | + |
|
| 109 | + const OBJ_TYPE_TICKET = 'Ticket'; |
|
| 110 | + |
|
| 111 | + const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @var EEM_Line_Item $_instance |
|
| 115 | + */ |
|
| 116 | + protected static $_instance; |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * private constructor to prevent direct creation |
|
| 121 | + * |
|
| 122 | + * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings |
|
| 123 | + * (and any incoming timezone data that gets saved). |
|
| 124 | + * Note this just sends the timezone info to the date time model field objects. |
|
| 125 | + * Default is NULL |
|
| 126 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 127 | + * @throws EE_Error |
|
| 128 | + * @throws ReflectionException |
|
| 129 | + */ |
|
| 130 | + protected function __construct(?string $timezone = '') |
|
| 131 | + { |
|
| 132 | + $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
| 133 | + $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
| 134 | + |
|
| 135 | + $this->_tables = [ |
|
| 136 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
| 137 | + ]; |
|
| 138 | + $line_items_can_be_for = apply_filters( |
|
| 139 | + 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
| 140 | + ['Ticket', 'Price', 'Event'] |
|
| 141 | + ); |
|
| 142 | + $this->_fields = [ |
|
| 143 | + 'Line_Item' => [ |
|
| 144 | + 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
| 145 | + 'LIN_ID', |
|
| 146 | + esc_html__('ID', 'event_espresso') |
|
| 147 | + ), |
|
| 148 | + 'LIN_code' => new EE_Slug_Field( |
|
| 149 | + 'LIN_code', |
|
| 150 | + esc_html__('Code for index into Cart', 'event_espresso'), |
|
| 151 | + true |
|
| 152 | + ), |
|
| 153 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
| 154 | + 'TXN_ID', |
|
| 155 | + esc_html__('Transaction ID', 'event_espresso'), |
|
| 156 | + true, |
|
| 157 | + null, |
|
| 158 | + 'Transaction' |
|
| 159 | + ), |
|
| 160 | + 'LIN_name' => new EE_Full_HTML_Field( |
|
| 161 | + 'LIN_name', |
|
| 162 | + esc_html__('Line Item Name', 'event_espresso'), |
|
| 163 | + false, |
|
| 164 | + '' |
|
| 165 | + ), |
|
| 166 | + 'LIN_desc' => new EE_Full_HTML_Field( |
|
| 167 | + 'LIN_desc', |
|
| 168 | + esc_html__('Line Item Description', 'event_espresso'), |
|
| 169 | + true |
|
| 170 | + ), |
|
| 171 | + 'LIN_unit_price' => new EE_Money_Field( |
|
| 172 | + 'LIN_unit_price', |
|
| 173 | + esc_html__('Unit Price', 'event_espresso'), |
|
| 174 | + false, |
|
| 175 | + 0 |
|
| 176 | + ), |
|
| 177 | + 'LIN_percent' => new EE_Float_Field( |
|
| 178 | + 'LIN_percent', |
|
| 179 | + esc_html__('Percent', 'event_espresso'), |
|
| 180 | + false, |
|
| 181 | + 0 |
|
| 182 | + ), |
|
| 183 | + 'LIN_is_taxable' => new EE_Boolean_Field( |
|
| 184 | + 'LIN_is_taxable', |
|
| 185 | + esc_html__('Taxable', 'event_espresso'), |
|
| 186 | + false, |
|
| 187 | + false |
|
| 188 | + ), |
|
| 189 | + 'LIN_order' => new EE_Integer_Field( |
|
| 190 | + 'LIN_order', |
|
| 191 | + esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
| 192 | + false, |
|
| 193 | + 1 |
|
| 194 | + ), |
|
| 195 | + 'LIN_total' => new EE_Money_Field( |
|
| 196 | + 'LIN_total', |
|
| 197 | + esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
| 198 | + false, |
|
| 199 | + 0 |
|
| 200 | + ), |
|
| 201 | + 'LIN_pretax' => new EE_Money_Field( |
|
| 202 | + 'LIN_pretax', |
|
| 203 | + esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
| 204 | + false, |
|
| 205 | + 0 |
|
| 206 | + ), |
|
| 207 | + 'LIN_quantity' => new EE_Integer_Field( |
|
| 208 | + 'LIN_quantity', |
|
| 209 | + esc_html__('Quantity', 'event_espresso'), |
|
| 210 | + false, |
|
| 211 | + 1 |
|
| 212 | + ), |
|
| 213 | + 'LIN_parent' => new EE_Integer_Field( |
|
| 214 | + 'LIN_parent', |
|
| 215 | + esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
| 216 | + true, |
|
| 217 | + null |
|
| 218 | + ), |
|
| 219 | + 'LIN_type' => new EE_Enum_Text_Field( |
|
| 220 | + 'LIN_type', |
|
| 221 | + esc_html__('Type', 'event_espresso'), |
|
| 222 | + false, |
|
| 223 | + 'line-item', |
|
| 224 | + [ |
|
| 225 | + self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
| 226 | + self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
| 227 | + self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
| 228 | + self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
| 229 | + self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
| 230 | + self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
| 231 | + self::type_total => esc_html__('Total', 'event_espresso'), |
|
| 232 | + self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
| 233 | + ] |
|
| 234 | + ), |
|
| 235 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
| 236 | + 'OBJ_ID', |
|
| 237 | + esc_html__('ID of Item purchased.', 'event_espresso'), |
|
| 238 | + true, |
|
| 239 | + null, |
|
| 240 | + $line_items_can_be_for |
|
| 241 | + ), |
|
| 242 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
| 243 | + 'OBJ_type', |
|
| 244 | + esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
| 245 | + true, |
|
| 246 | + null, |
|
| 247 | + $line_items_can_be_for |
|
| 248 | + ), |
|
| 249 | + 'LIN_timestamp' => new EE_Datetime_Field( |
|
| 250 | + 'LIN_timestamp', |
|
| 251 | + esc_html__('When the line item was created', 'event_espresso'), |
|
| 252 | + false, |
|
| 253 | + EE_Datetime_Field::now, |
|
| 254 | + $timezone |
|
| 255 | + ), |
|
| 256 | + ], |
|
| 257 | + ]; |
|
| 258 | + $this->_model_relations = [ |
|
| 259 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
| 260 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
| 261 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
| 262 | + 'Event' => new EE_Belongs_To_Any_Relation(), |
|
| 263 | + ]; |
|
| 264 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
| 265 | + $this->_caps_slug = 'transactions'; |
|
| 266 | + parent::__construct($timezone); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Gets all the line items for this transaction of the given type |
|
| 272 | + * |
|
| 273 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
| 274 | + * @param EE_Transaction|int $transaction |
|
| 275 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 276 | + * @throws EE_Error |
|
| 277 | + * @throws InvalidArgumentException |
|
| 278 | + * @throws InvalidDataTypeException |
|
| 279 | + * @throws InvalidInterfaceException |
|
| 280 | + */ |
|
| 281 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
| 282 | + { |
|
| 283 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 284 | + return $this->get_all( |
|
| 285 | + [ |
|
| 286 | + [ |
|
| 287 | + 'LIN_type' => $line_item_type, |
|
| 288 | + 'TXN_ID' => $transaction, |
|
| 289 | + ], |
|
| 290 | + ] |
|
| 291 | + ); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Gets all line items unrelated to tickets that are normal line items |
|
| 297 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
| 298 | + * |
|
| 299 | + * @param EE_Transaction|int $transaction |
|
| 300 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 301 | + * @throws EE_Error |
|
| 302 | + * @throws InvalidArgumentException |
|
| 303 | + * @throws InvalidDataTypeException |
|
| 304 | + * @throws InvalidInterfaceException |
|
| 305 | + */ |
|
| 306 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
| 307 | + { |
|
| 308 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
| 309 | + return $this->get_all( |
|
| 310 | + [ |
|
| 311 | + [ |
|
| 312 | + 'LIN_type' => self::type_line_item, |
|
| 313 | + 'TXN_ID' => $transaction, |
|
| 314 | + 'OR' => [ |
|
| 315 | + 'OBJ_type*notticket' => ['!=', EEM_Line_Item::OBJ_TYPE_TICKET], |
|
| 316 | + 'OBJ_type*null' => ['IS_NULL'], |
|
| 317 | + ], |
|
| 318 | + ], |
|
| 319 | + ] |
|
| 320 | + ); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
| 326 | + * This needs to be very efficient |
|
| 327 | + * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
| 328 | + * deleting and joining tables like this. |
|
| 329 | + * |
|
| 330 | + * @return int count of how many deleted |
|
| 331 | + * @throws EE_Error |
|
| 332 | + * @throws InvalidArgumentException |
|
| 333 | + * @throws InvalidDataTypeException |
|
| 334 | + * @throws InvalidInterfaceException |
|
| 335 | + */ |
|
| 336 | + public function delete_line_items_with_no_transaction() |
|
| 337 | + { |
|
| 338 | + /** @type WPDB $wpdb */ |
|
| 339 | + global $wpdb; |
|
| 340 | + $time_to_leave_alone = apply_filters( |
|
| 341 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
| 342 | + WEEK_IN_SECONDS |
|
| 343 | + ); |
|
| 344 | + $query = $wpdb->prepare( |
|
| 345 | + 'DELETE li |
|
| 346 | 346 | FROM ' . $this->table() . ' li |
| 347 | 347 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
| 348 | 348 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
| 349 | - // use GMT time because that's what TXN_timestamps are in |
|
| 350 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
| 351 | - ); |
|
| 352 | - return $wpdb->query($query); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * get_line_item_for_transaction_object |
|
| 358 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
| 359 | - * |
|
| 360 | - * @param int $TXN_ID |
|
| 361 | - * @param EE_Base_Class $object |
|
| 362 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 363 | - * @throws EE_Error |
|
| 364 | - * @throws InvalidArgumentException |
|
| 365 | - * @throws InvalidDataTypeException |
|
| 366 | - * @throws InvalidInterfaceException |
|
| 367 | - * @throws ReflectionException |
|
| 368 | - */ |
|
| 369 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
| 370 | - { |
|
| 371 | - return $this->get_all( |
|
| 372 | - [ |
|
| 373 | - [ |
|
| 374 | - 'TXN_ID' => $TXN_ID, |
|
| 375 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
| 376 | - 'OBJ_ID' => $object->ID(), |
|
| 377 | - ], |
|
| 378 | - ] |
|
| 379 | - ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * get_object_line_items_for_transaction |
|
| 385 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
| 386 | - * |
|
| 387 | - * @param int $TXN_ID |
|
| 388 | - * @param string $OBJ_type |
|
| 389 | - * @param array $OBJ_IDs |
|
| 390 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 391 | - * @throws EE_Error |
|
| 392 | - */ |
|
| 393 | - public function get_object_line_items_for_transaction( |
|
| 394 | - $TXN_ID, |
|
| 395 | - $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
| 396 | - $OBJ_IDs = [] |
|
| 397 | - ) { |
|
| 398 | - $query_params = [ |
|
| 399 | - 'OBJ_type' => $OBJ_type, |
|
| 400 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
| 401 | - 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? ['IN', $OBJ_IDs] : $OBJ_IDs, |
|
| 402 | - ]; |
|
| 403 | - if ($TXN_ID) { |
|
| 404 | - $query_params['TXN_ID'] = $TXN_ID; |
|
| 405 | - } |
|
| 406 | - return $this->get_all([$query_params]); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * get_all_ticket_line_items_for_transaction |
|
| 412 | - * |
|
| 413 | - * @param EE_Transaction $transaction |
|
| 414 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 415 | - * @throws EE_Error |
|
| 416 | - * @throws InvalidArgumentException |
|
| 417 | - * @throws InvalidDataTypeException |
|
| 418 | - * @throws InvalidInterfaceException |
|
| 419 | - * @throws ReflectionException |
|
| 420 | - */ |
|
| 421 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
| 422 | - { |
|
| 423 | - return $this->get_all( |
|
| 424 | - [ |
|
| 425 | - [ |
|
| 426 | - 'TXN_ID' => $transaction->ID(), |
|
| 427 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 428 | - ], |
|
| 429 | - ] |
|
| 430 | - ); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * get_ticket_line_item_for_transaction |
|
| 436 | - * |
|
| 437 | - * @param int $TXN_ID |
|
| 438 | - * @param int $TKT_ID |
|
| 439 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
| 440 | - * @throws EE_Error |
|
| 441 | - * @throws InvalidArgumentException |
|
| 442 | - * @throws InvalidDataTypeException |
|
| 443 | - * @throws InvalidInterfaceException |
|
| 444 | - */ |
|
| 445 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
| 446 | - { |
|
| 447 | - return $this->get_one( |
|
| 448 | - [ |
|
| 449 | - [ |
|
| 450 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
| 451 | - 'OBJ_ID' => $TKT_ID, |
|
| 452 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 453 | - ], |
|
| 454 | - ] |
|
| 455 | - ); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * get_existing_promotion_line_item |
|
| 461 | - * searches the cart for existing line items for the specified promotion |
|
| 462 | - * |
|
| 463 | - * @param EE_Line_Item $parent_line_item |
|
| 464 | - * @param EE_Promotion $promotion |
|
| 465 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
| 466 | - * @throws EE_Error |
|
| 467 | - * @throws InvalidArgumentException |
|
| 468 | - * @throws InvalidDataTypeException |
|
| 469 | - * @throws InvalidInterfaceException |
|
| 470 | - * @throws ReflectionException |
|
| 471 | - * @since 1.0.0 |
|
| 472 | - */ |
|
| 473 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
| 474 | - { |
|
| 475 | - return $this->get_one( |
|
| 476 | - [ |
|
| 477 | - [ |
|
| 478 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 479 | - 'LIN_parent' => $parent_line_item->ID(), |
|
| 480 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
| 481 | - 'OBJ_ID' => $promotion->ID(), |
|
| 482 | - ], |
|
| 483 | - ] |
|
| 484 | - ); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * searches the cart for existing line items for the specified transaction and promotion |
|
| 490 | - * |
|
| 491 | - * @param int $TXN_ID |
|
| 492 | - * @param string $promo_code |
|
| 493 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|null |
|
| 494 | - * @throws EE_Error |
|
| 495 | - * @throws InvalidArgumentException |
|
| 496 | - * @throws InvalidDataTypeException |
|
| 497 | - * @throws InvalidInterfaceException |
|
| 498 | - * @throws ReflectionException |
|
| 499 | - * @since 1.0.0 |
|
| 500 | - */ |
|
| 501 | - public function getExistingPromotionLineItemForTransactionByCode(int $TXN_ID, string $promo_code) |
|
| 502 | - { |
|
| 503 | - return $this->get_one( |
|
| 504 | - [ |
|
| 505 | - [ |
|
| 506 | - 'TXN_ID' => $TXN_ID, |
|
| 507 | - 'LIN_name' => $promo_code, |
|
| 508 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
| 509 | - ], |
|
| 510 | - ] |
|
| 511 | - ); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * get_all_promotion_line_items |
|
| 517 | - * searches the cart for any and all existing promotion line items |
|
| 518 | - * |
|
| 519 | - * @param EE_Line_Item $parent_line_item |
|
| 520 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 521 | - * @throws EE_Error |
|
| 522 | - * @throws InvalidArgumentException |
|
| 523 | - * @throws InvalidDataTypeException |
|
| 524 | - * @throws InvalidInterfaceException |
|
| 525 | - * @throws ReflectionException |
|
| 526 | - * @since 1.0.0 |
|
| 527 | - */ |
|
| 528 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
| 529 | - { |
|
| 530 | - return $this->get_all( |
|
| 531 | - [ |
|
| 532 | - [ |
|
| 533 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 534 | - 'LIN_parent' => $parent_line_item->ID(), |
|
| 535 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
| 536 | - ], |
|
| 537 | - ] |
|
| 538 | - ); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Gets the registration's corresponding line item. |
|
| 544 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
| 545 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
| 546 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
| 547 | - * |
|
| 548 | - * @param EE_Registration $registration |
|
| 549 | - * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
| 550 | - * @throws EE_Error |
|
| 551 | - */ |
|
| 552 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
| 553 | - { |
|
| 554 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
| 560 | - * |
|
| 561 | - * @param EE_Registration $registration |
|
| 562 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
| 563 | - * @return array @see |
|
| 564 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 565 | - * @throws EE_Error |
|
| 566 | - */ |
|
| 567 | - public function line_item_for_registration_query_params( |
|
| 568 | - EE_Registration $registration, |
|
| 569 | - $original_query_params = [] |
|
| 570 | - ) { |
|
| 571 | - return array_replace_recursive( |
|
| 572 | - $original_query_params, |
|
| 573 | - [ |
|
| 574 | - [ |
|
| 575 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
| 576 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 577 | - 'TXN_ID' => $registration->transaction_ID(), |
|
| 578 | - ], |
|
| 579 | - ] |
|
| 580 | - ); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 586 | - * @throws InvalidInterfaceException |
|
| 587 | - * @throws InvalidDataTypeException |
|
| 588 | - * @throws EE_Error |
|
| 589 | - * @throws InvalidArgumentException |
|
| 590 | - */ |
|
| 591 | - public function get_total_line_items_with_no_transaction() |
|
| 592 | - { |
|
| 593 | - return $this->get_total_line_items_for_carts(); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 599 | - * @throws InvalidInterfaceException |
|
| 600 | - * @throws InvalidDataTypeException |
|
| 601 | - * @throws EE_Error |
|
| 602 | - * @throws InvalidArgumentException |
|
| 603 | - */ |
|
| 604 | - public function get_total_line_items_for_active_carts() |
|
| 605 | - { |
|
| 606 | - return $this->get_total_line_items_for_carts(false); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 612 | - * @throws InvalidInterfaceException |
|
| 613 | - * @throws InvalidDataTypeException |
|
| 614 | - * @throws EE_Error |
|
| 615 | - * @throws InvalidArgumentException |
|
| 616 | - */ |
|
| 617 | - public function get_total_line_items_for_expired_carts() |
|
| 618 | - { |
|
| 619 | - return $this->get_total_line_items_for_carts(true); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
| 625 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
| 626 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
| 627 | - * |
|
| 628 | - * @param null $expired |
|
| 629 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 630 | - * @throws EE_Error |
|
| 631 | - * @throws InvalidArgumentException |
|
| 632 | - * @throws InvalidDataTypeException |
|
| 633 | - * @throws InvalidInterfaceException |
|
| 634 | - */ |
|
| 635 | - private function get_total_line_items_for_carts($expired = null) |
|
| 636 | - { |
|
| 637 | - $where_params = [ |
|
| 638 | - 'TXN_ID' => 0, |
|
| 639 | - 'LIN_type' => 'total', |
|
| 640 | - ]; |
|
| 641 | - if ($expired !== null) { |
|
| 642 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 643 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 644 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 645 | - ); |
|
| 646 | - $where_params['LIN_timestamp'] = [ |
|
| 647 | - $expired ? '<=' : '>', |
|
| 648 | - $session_lifespan->expiration(), |
|
| 649 | - ]; |
|
| 650 | - } |
|
| 651 | - return $this->get_all([$where_params]); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
| 657 | - * AND the timestamp is older than the session lifespan. |
|
| 658 | - * |
|
| 659 | - * @param int $timestamp |
|
| 660 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 661 | - * @throws EE_Error |
|
| 662 | - * @throws InvalidArgumentException |
|
| 663 | - * @throws InvalidDataTypeException |
|
| 664 | - * @throws InvalidInterfaceException |
|
| 665 | - */ |
|
| 666 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
| 667 | - { |
|
| 668 | - if (! absint($timestamp)) { |
|
| 669 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 670 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 671 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 672 | - ); |
|
| 673 | - $timestamp = $session_lifespan->expiration(); |
|
| 674 | - } |
|
| 675 | - return $this->get_all( |
|
| 676 | - [ |
|
| 677 | - [ |
|
| 678 | - 'TXN_ID' => 0, |
|
| 679 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 680 | - 'LIN_timestamp' => ['<=', $timestamp], |
|
| 681 | - ], |
|
| 682 | - ] |
|
| 683 | - ); |
|
| 684 | - } |
|
| 349 | + // use GMT time because that's what TXN_timestamps are in |
|
| 350 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
| 351 | + ); |
|
| 352 | + return $wpdb->query($query); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * get_line_item_for_transaction_object |
|
| 358 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
| 359 | + * |
|
| 360 | + * @param int $TXN_ID |
|
| 361 | + * @param EE_Base_Class $object |
|
| 362 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 363 | + * @throws EE_Error |
|
| 364 | + * @throws InvalidArgumentException |
|
| 365 | + * @throws InvalidDataTypeException |
|
| 366 | + * @throws InvalidInterfaceException |
|
| 367 | + * @throws ReflectionException |
|
| 368 | + */ |
|
| 369 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
| 370 | + { |
|
| 371 | + return $this->get_all( |
|
| 372 | + [ |
|
| 373 | + [ |
|
| 374 | + 'TXN_ID' => $TXN_ID, |
|
| 375 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
| 376 | + 'OBJ_ID' => $object->ID(), |
|
| 377 | + ], |
|
| 378 | + ] |
|
| 379 | + ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * get_object_line_items_for_transaction |
|
| 385 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
| 386 | + * |
|
| 387 | + * @param int $TXN_ID |
|
| 388 | + * @param string $OBJ_type |
|
| 389 | + * @param array $OBJ_IDs |
|
| 390 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 391 | + * @throws EE_Error |
|
| 392 | + */ |
|
| 393 | + public function get_object_line_items_for_transaction( |
|
| 394 | + $TXN_ID, |
|
| 395 | + $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
| 396 | + $OBJ_IDs = [] |
|
| 397 | + ) { |
|
| 398 | + $query_params = [ |
|
| 399 | + 'OBJ_type' => $OBJ_type, |
|
| 400 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
| 401 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? ['IN', $OBJ_IDs] : $OBJ_IDs, |
|
| 402 | + ]; |
|
| 403 | + if ($TXN_ID) { |
|
| 404 | + $query_params['TXN_ID'] = $TXN_ID; |
|
| 405 | + } |
|
| 406 | + return $this->get_all([$query_params]); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * get_all_ticket_line_items_for_transaction |
|
| 412 | + * |
|
| 413 | + * @param EE_Transaction $transaction |
|
| 414 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 415 | + * @throws EE_Error |
|
| 416 | + * @throws InvalidArgumentException |
|
| 417 | + * @throws InvalidDataTypeException |
|
| 418 | + * @throws InvalidInterfaceException |
|
| 419 | + * @throws ReflectionException |
|
| 420 | + */ |
|
| 421 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
| 422 | + { |
|
| 423 | + return $this->get_all( |
|
| 424 | + [ |
|
| 425 | + [ |
|
| 426 | + 'TXN_ID' => $transaction->ID(), |
|
| 427 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 428 | + ], |
|
| 429 | + ] |
|
| 430 | + ); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * get_ticket_line_item_for_transaction |
|
| 436 | + * |
|
| 437 | + * @param int $TXN_ID |
|
| 438 | + * @param int $TKT_ID |
|
| 439 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
| 440 | + * @throws EE_Error |
|
| 441 | + * @throws InvalidArgumentException |
|
| 442 | + * @throws InvalidDataTypeException |
|
| 443 | + * @throws InvalidInterfaceException |
|
| 444 | + */ |
|
| 445 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
| 446 | + { |
|
| 447 | + return $this->get_one( |
|
| 448 | + [ |
|
| 449 | + [ |
|
| 450 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
| 451 | + 'OBJ_ID' => $TKT_ID, |
|
| 452 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 453 | + ], |
|
| 454 | + ] |
|
| 455 | + ); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * get_existing_promotion_line_item |
|
| 461 | + * searches the cart for existing line items for the specified promotion |
|
| 462 | + * |
|
| 463 | + * @param EE_Line_Item $parent_line_item |
|
| 464 | + * @param EE_Promotion $promotion |
|
| 465 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
| 466 | + * @throws EE_Error |
|
| 467 | + * @throws InvalidArgumentException |
|
| 468 | + * @throws InvalidDataTypeException |
|
| 469 | + * @throws InvalidInterfaceException |
|
| 470 | + * @throws ReflectionException |
|
| 471 | + * @since 1.0.0 |
|
| 472 | + */ |
|
| 473 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
| 474 | + { |
|
| 475 | + return $this->get_one( |
|
| 476 | + [ |
|
| 477 | + [ |
|
| 478 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 479 | + 'LIN_parent' => $parent_line_item->ID(), |
|
| 480 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
| 481 | + 'OBJ_ID' => $promotion->ID(), |
|
| 482 | + ], |
|
| 483 | + ] |
|
| 484 | + ); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * searches the cart for existing line items for the specified transaction and promotion |
|
| 490 | + * |
|
| 491 | + * @param int $TXN_ID |
|
| 492 | + * @param string $promo_code |
|
| 493 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|null |
|
| 494 | + * @throws EE_Error |
|
| 495 | + * @throws InvalidArgumentException |
|
| 496 | + * @throws InvalidDataTypeException |
|
| 497 | + * @throws InvalidInterfaceException |
|
| 498 | + * @throws ReflectionException |
|
| 499 | + * @since 1.0.0 |
|
| 500 | + */ |
|
| 501 | + public function getExistingPromotionLineItemForTransactionByCode(int $TXN_ID, string $promo_code) |
|
| 502 | + { |
|
| 503 | + return $this->get_one( |
|
| 504 | + [ |
|
| 505 | + [ |
|
| 506 | + 'TXN_ID' => $TXN_ID, |
|
| 507 | + 'LIN_name' => $promo_code, |
|
| 508 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
| 509 | + ], |
|
| 510 | + ] |
|
| 511 | + ); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * get_all_promotion_line_items |
|
| 517 | + * searches the cart for any and all existing promotion line items |
|
| 518 | + * |
|
| 519 | + * @param EE_Line_Item $parent_line_item |
|
| 520 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 521 | + * @throws EE_Error |
|
| 522 | + * @throws InvalidArgumentException |
|
| 523 | + * @throws InvalidDataTypeException |
|
| 524 | + * @throws InvalidInterfaceException |
|
| 525 | + * @throws ReflectionException |
|
| 526 | + * @since 1.0.0 |
|
| 527 | + */ |
|
| 528 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
| 529 | + { |
|
| 530 | + return $this->get_all( |
|
| 531 | + [ |
|
| 532 | + [ |
|
| 533 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
| 534 | + 'LIN_parent' => $parent_line_item->ID(), |
|
| 535 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
| 536 | + ], |
|
| 537 | + ] |
|
| 538 | + ); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Gets the registration's corresponding line item. |
|
| 544 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
| 545 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
| 546 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
| 547 | + * |
|
| 548 | + * @param EE_Registration $registration |
|
| 549 | + * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
| 550 | + * @throws EE_Error |
|
| 551 | + */ |
|
| 552 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
| 553 | + { |
|
| 554 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
| 560 | + * |
|
| 561 | + * @param EE_Registration $registration |
|
| 562 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
| 563 | + * @return array @see |
|
| 564 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 565 | + * @throws EE_Error |
|
| 566 | + */ |
|
| 567 | + public function line_item_for_registration_query_params( |
|
| 568 | + EE_Registration $registration, |
|
| 569 | + $original_query_params = [] |
|
| 570 | + ) { |
|
| 571 | + return array_replace_recursive( |
|
| 572 | + $original_query_params, |
|
| 573 | + [ |
|
| 574 | + [ |
|
| 575 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
| 576 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 577 | + 'TXN_ID' => $registration->transaction_ID(), |
|
| 578 | + ], |
|
| 579 | + ] |
|
| 580 | + ); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 586 | + * @throws InvalidInterfaceException |
|
| 587 | + * @throws InvalidDataTypeException |
|
| 588 | + * @throws EE_Error |
|
| 589 | + * @throws InvalidArgumentException |
|
| 590 | + */ |
|
| 591 | + public function get_total_line_items_with_no_transaction() |
|
| 592 | + { |
|
| 593 | + return $this->get_total_line_items_for_carts(); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 599 | + * @throws InvalidInterfaceException |
|
| 600 | + * @throws InvalidDataTypeException |
|
| 601 | + * @throws EE_Error |
|
| 602 | + * @throws InvalidArgumentException |
|
| 603 | + */ |
|
| 604 | + public function get_total_line_items_for_active_carts() |
|
| 605 | + { |
|
| 606 | + return $this->get_total_line_items_for_carts(false); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 612 | + * @throws InvalidInterfaceException |
|
| 613 | + * @throws InvalidDataTypeException |
|
| 614 | + * @throws EE_Error |
|
| 615 | + * @throws InvalidArgumentException |
|
| 616 | + */ |
|
| 617 | + public function get_total_line_items_for_expired_carts() |
|
| 618 | + { |
|
| 619 | + return $this->get_total_line_items_for_carts(true); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
| 625 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
| 626 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
| 627 | + * |
|
| 628 | + * @param null $expired |
|
| 629 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 630 | + * @throws EE_Error |
|
| 631 | + * @throws InvalidArgumentException |
|
| 632 | + * @throws InvalidDataTypeException |
|
| 633 | + * @throws InvalidInterfaceException |
|
| 634 | + */ |
|
| 635 | + private function get_total_line_items_for_carts($expired = null) |
|
| 636 | + { |
|
| 637 | + $where_params = [ |
|
| 638 | + 'TXN_ID' => 0, |
|
| 639 | + 'LIN_type' => 'total', |
|
| 640 | + ]; |
|
| 641 | + if ($expired !== null) { |
|
| 642 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 643 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 644 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 645 | + ); |
|
| 646 | + $where_params['LIN_timestamp'] = [ |
|
| 647 | + $expired ? '<=' : '>', |
|
| 648 | + $session_lifespan->expiration(), |
|
| 649 | + ]; |
|
| 650 | + } |
|
| 651 | + return $this->get_all([$where_params]); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
| 657 | + * AND the timestamp is older than the session lifespan. |
|
| 658 | + * |
|
| 659 | + * @param int $timestamp |
|
| 660 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 661 | + * @throws EE_Error |
|
| 662 | + * @throws InvalidArgumentException |
|
| 663 | + * @throws InvalidDataTypeException |
|
| 664 | + * @throws InvalidInterfaceException |
|
| 665 | + */ |
|
| 666 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
| 667 | + { |
|
| 668 | + if (! absint($timestamp)) { |
|
| 669 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 670 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 671 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 672 | + ); |
|
| 673 | + $timestamp = $session_lifespan->expiration(); |
|
| 674 | + } |
|
| 675 | + return $this->get_all( |
|
| 676 | + [ |
|
| 677 | + [ |
|
| 678 | + 'TXN_ID' => 0, |
|
| 679 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
| 680 | + 'LIN_timestamp' => ['<=', $timestamp], |
|
| 681 | + ], |
|
| 682 | + ] |
|
| 683 | + ); |
|
| 684 | + } |
|
| 685 | 685 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 7 | 7 | |
| 8 | 8 | if (! class_exists('WP_List_Table')) { |
| 9 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 9 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | |
@@ -24,933 +24,933 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | abstract class EE_Admin_List_Table extends WP_List_Table |
| 26 | 26 | { |
| 27 | - const ACTION_COPY = 'duplicate'; |
|
| 28 | - |
|
| 29 | - const ACTION_DELETE = 'delete'; |
|
| 30 | - |
|
| 31 | - const ACTION_EDIT = 'edit'; |
|
| 32 | - |
|
| 33 | - const ACTION_RESTORE = 'restore'; |
|
| 34 | - |
|
| 35 | - const ACTION_TRASH = 'trash'; |
|
| 36 | - |
|
| 37 | - protected static array $actions = [ |
|
| 38 | - self::ACTION_COPY, |
|
| 39 | - self::ACTION_DELETE, |
|
| 40 | - self::ACTION_EDIT, |
|
| 41 | - self::ACTION_RESTORE, |
|
| 42 | - self::ACTION_TRASH, |
|
| 43 | - ]; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * holds the data that will be processed for the table |
|
| 47 | - * |
|
| 48 | - * @var array $_data |
|
| 49 | - */ |
|
| 50 | - protected array $_data; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * This holds the value of all the data available for the given view (for all pages). |
|
| 55 | - * |
|
| 56 | - * @var int $_all_data_count |
|
| 57 | - */ |
|
| 58 | - protected int $_all_data_count; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Will contain the count of trashed items for the view label. |
|
| 63 | - * |
|
| 64 | - * @var int $_trashed_count |
|
| 65 | - */ |
|
| 66 | - protected int $_trashed_count; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * This is what will be referenced as the slug for the current screen |
|
| 71 | - * |
|
| 72 | - * @var string $_screen |
|
| 73 | - */ |
|
| 74 | - protected string $_screen; |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * this is the EE_Admin_Page object |
|
| 79 | - * |
|
| 80 | - * @var EE_Admin_Page $_admin_page |
|
| 81 | - */ |
|
| 82 | - protected EE_Admin_Page $_admin_page; |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * The current view |
|
| 87 | - * |
|
| 88 | - * @var string $_view |
|
| 89 | - */ |
|
| 90 | - protected string $_view; |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * array of possible views for this table |
|
| 95 | - * |
|
| 96 | - * @var array $_views |
|
| 97 | - */ |
|
| 98 | - protected array $_views; |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * An array of key => value pairs containing information about the current table |
|
| 103 | - * array( |
|
| 104 | - * 'plural' => 'plural label', |
|
| 105 | - * 'singular' => 'singular label', |
|
| 106 | - * 'ajax' => false, //whether to use ajax or not |
|
| 107 | - * 'screen' => null, //string used to reference what screen this is |
|
| 108 | - * (WP_List_table converts to screen object) |
|
| 109 | - * ) |
|
| 110 | - * |
|
| 111 | - * @var array $_wp_list_args |
|
| 112 | - */ |
|
| 113 | - protected array $_wp_list_args; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * an array of column names |
|
| 117 | - * array( |
|
| 118 | - * 'internal-name' => 'Title' |
|
| 119 | - * ) |
|
| 120 | - * |
|
| 121 | - * @var array $_columns |
|
| 122 | - */ |
|
| 123 | - protected array $_columns; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * An array of sortable columns |
|
| 127 | - * array( |
|
| 128 | - * 'internal-name' => 'orderby' //or |
|
| 129 | - * 'internal-name' => array( 'orderby', true ) |
|
| 130 | - * ) |
|
| 131 | - * |
|
| 132 | - * @var array $_sortable_columns |
|
| 133 | - */ |
|
| 134 | - protected array $_sortable_columns; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * callback method used to perform AJAX row reordering |
|
| 138 | - * |
|
| 139 | - * @var string|null $_ajax_sorting_callback |
|
| 140 | - */ |
|
| 141 | - protected ?string $_ajax_sorting_callback = null; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * An array of hidden columns (if needed) |
|
| 145 | - * array('internal-name', 'internal-name') |
|
| 146 | - * |
|
| 147 | - * @var array $_hidden_columns |
|
| 148 | - */ |
|
| 149 | - protected array $_hidden_columns; |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * holds the per_page value |
|
| 153 | - * |
|
| 154 | - * @var int $_per_page |
|
| 155 | - */ |
|
| 156 | - protected int $_per_page; |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * holds what page number is currently being viewed |
|
| 160 | - * |
|
| 161 | - * @var int $_current_page |
|
| 162 | - */ |
|
| 163 | - protected int $_current_page; |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * the reference string for the nonce_action |
|
| 167 | - * |
|
| 168 | - * @var string $_nonce_action_ref |
|
| 169 | - */ |
|
| 170 | - protected string $_nonce_action_ref; |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * property to hold incoming request data (as set by the admin_page_core) |
|
| 174 | - * |
|
| 175 | - * @var array $_req_data |
|
| 176 | - */ |
|
| 177 | - protected array $_req_data; |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * yes / no array for admin form fields |
|
| 182 | - * |
|
| 183 | - * @var array $_yes_no |
|
| 184 | - */ |
|
| 185 | - protected array $_yes_no = []; |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Array describing buttons that should appear at the bottom of the page |
|
| 189 | - * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 190 | - * and the values are another array with the following keys |
|
| 191 | - * array( |
|
| 192 | - * 'route' => 'page_route', |
|
| 193 | - * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 194 | - * ) |
|
| 195 | - * |
|
| 196 | - * @var array $_bottom_buttons |
|
| 197 | - */ |
|
| 198 | - protected array $_bottom_buttons = []; |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Used to indicate what should be the primary column for the list table. |
|
| 203 | - * If not present then falls back to what WP calculates |
|
| 204 | - * as the primary column. |
|
| 205 | - * |
|
| 206 | - * @type string $_primary_column |
|
| 207 | - */ |
|
| 208 | - protected string $_primary_column = ''; |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Used to indicate whether the table has a checkbox column or not. |
|
| 213 | - * |
|
| 214 | - * @type bool $_has_checkbox_column |
|
| 215 | - */ |
|
| 216 | - protected bool $_has_checkbox_column = false; |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @var AdminListTableFilters|null |
|
| 220 | - */ |
|
| 221 | - protected ?AdminListTableFilters $admin_list_table_filters = null; |
|
| 222 | - |
|
| 223 | - protected ?RequestInterface $request = null; |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 228 | - * @param AdminListTableFilters|null $filters to display list table filters |
|
| 229 | - */ |
|
| 230 | - public function __construct(EE_Admin_Page $admin_page, ?AdminListTableFilters $filters = null) |
|
| 231 | - { |
|
| 232 | - $this->request = $this->request ?? LoaderFactory::getShared(RequestInterface::class); |
|
| 233 | - $this->_admin_page = $admin_page; |
|
| 234 | - $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 235 | - $this->_view = $this->_admin_page->get_view(); |
|
| 236 | - $this->_views = $this->_admin_page->get_list_table_view_RLs(); |
|
| 237 | - $this->_current_page = $this->get_pagenum(); |
|
| 238 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 239 | - $this->_yes_no = [ |
|
| 240 | - esc_html__('No', 'event_espresso'), |
|
| 241 | - esc_html__('Yes', 'event_espresso') |
|
| 242 | - ]; |
|
| 243 | - |
|
| 244 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 245 | - |
|
| 246 | - $this->admin_list_table_filters = $filters instanceof AdminListTableFilters |
|
| 247 | - ? $filters |
|
| 248 | - : LoaderFactory::getShared(AdminListTableFilters::class); |
|
| 249 | - |
|
| 250 | - $this->_setup_data(); |
|
| 251 | - $this->_add_view_counts(); |
|
| 252 | - // ensure changes made to views in child classes get ported back to the admin page |
|
| 253 | - $this->_admin_page->updateViews($this->_views); |
|
| 254 | - |
|
| 255 | - $this->_nonce_action_ref = $this->_view; |
|
| 256 | - |
|
| 257 | - $this->_set_properties(); |
|
| 258 | - |
|
| 259 | - // set primary column |
|
| 260 | - add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 261 | - |
|
| 262 | - // set parent defaults |
|
| 263 | - parent::__construct($this->_wp_list_args); |
|
| 264 | - |
|
| 265 | - $this->prepare_items(); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * _setup_data |
|
| 271 | - * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 272 | - * |
|
| 273 | - * @return void |
|
| 274 | - * @uses $this->_admin_page |
|
| 275 | - */ |
|
| 276 | - abstract protected function _setup_data(); |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 281 | - * properties set: |
|
| 282 | - * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 283 | - * _columns = set the columns in an array. |
|
| 284 | - * _sortable_columns = columns that are sortable (array). |
|
| 285 | - * _hidden_columns = columns that are hidden (array) |
|
| 286 | - * _default_orderby = the default orderby for sorting. |
|
| 287 | - * |
|
| 288 | - * @abstract |
|
| 289 | - * @access protected |
|
| 290 | - * @return void |
|
| 291 | - */ |
|
| 292 | - abstract protected function _set_properties(); |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * _get_table_filters |
|
| 297 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 298 | - * gets shown in the table. |
|
| 299 | - * |
|
| 300 | - * @abstract |
|
| 301 | - * @access protected |
|
| 302 | - * @return string[] |
|
| 303 | - */ |
|
| 304 | - abstract protected function _get_table_filters(); |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 309 | - * counts of the views is accurate. |
|
| 310 | - * |
|
| 311 | - * @abstract |
|
| 312 | - * @access protected |
|
| 313 | - * @return void |
|
| 314 | - */ |
|
| 315 | - abstract protected function _add_view_counts(); |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * _get_hidden_fields |
|
| 320 | - * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 321 | - * |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 324 | - protected function _get_hidden_fields() |
|
| 325 | - { |
|
| 326 | - $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 327 | - $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 328 | - // if action is STILL empty, then we set it to default |
|
| 329 | - $action = empty($action) ? 'default' : $action; |
|
| 330 | - $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 331 | - $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 332 | - $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 333 | - |
|
| 334 | - $bulk_actions = $this->_get_bulk_actions(); |
|
| 335 | - foreach ($bulk_actions as $bulk_action => $label) { |
|
| 336 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 337 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - return $field; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * _set_column_info |
|
| 346 | - * we're using this to set the column headers property. |
|
| 347 | - * |
|
| 348 | - * @access protected |
|
| 349 | - * @return void |
|
| 350 | - */ |
|
| 351 | - protected function _set_column_info() |
|
| 352 | - { |
|
| 353 | - $columns = $this->get_columns(); |
|
| 354 | - $hidden = $this->get_hidden_columns(); |
|
| 355 | - $_sortable = $this->get_sortable_columns(); |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 359 | - * Note that $this->screen->id is in the format |
|
| 360 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 361 | - * table it is: event-espresso_page_espresso_messages. |
|
| 362 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 363 | - * hook prefix ("event-espresso") will be different. |
|
| 364 | - * |
|
| 365 | - * @var array |
|
| 366 | - */ |
|
| 367 | - $_sortable = apply_filters( |
|
| 368 | - "FHEE_manage_{$this->screen->id}_sortable_columns", |
|
| 369 | - $_sortable, |
|
| 370 | - $this->_screen, |
|
| 371 | - $this |
|
| 372 | - ); |
|
| 373 | - |
|
| 374 | - $sortable = []; |
|
| 375 | - foreach ($_sortable as $id => $data) { |
|
| 376 | - if (empty($data)) { |
|
| 377 | - continue; |
|
| 378 | - } |
|
| 379 | - // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 380 | - if (is_array($data)) { |
|
| 381 | - $_data[0] = key($data); |
|
| 382 | - $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 383 | - } else { |
|
| 384 | - $_data[0] = $data; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $data = (array) $data; |
|
| 388 | - |
|
| 389 | - if (! isset($data[1])) { |
|
| 390 | - $_data[1] = false; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - $sortable[ $id ] = $_data; |
|
| 394 | - } |
|
| 395 | - $primary = $this->get_primary_column_name(); |
|
| 396 | - $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 402 | - * |
|
| 403 | - * @return string |
|
| 404 | - */ |
|
| 405 | - protected function get_primary_column_name() |
|
| 406 | - { |
|
| 407 | - foreach (class_parents($this) as $parent) { |
|
| 408 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 409 | - return parent::get_primary_column_name(); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - return $this->_primary_column; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 418 | - * |
|
| 419 | - * @param EE_Base_Class $item |
|
| 420 | - * @param string $column_name |
|
| 421 | - * @param string $primary |
|
| 422 | - * @return string |
|
| 423 | - */ |
|
| 424 | - protected function handle_row_actions($item, $column_name, $primary) |
|
| 425 | - { |
|
| 426 | - foreach (class_parents($this) as $parent) { |
|
| 427 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 428 | - return parent::handle_row_actions($item, $column_name, $primary); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - return ''; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * _get_bulk_actions |
|
| 437 | - * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 438 | - * |
|
| 439 | - * @access protected |
|
| 440 | - * @return array bulk_actions |
|
| 441 | - */ |
|
| 442 | - protected function _get_bulk_actions(): array |
|
| 443 | - { |
|
| 444 | - $actions = []; |
|
| 445 | - // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 446 | - // formatted array for the wp_list_table(); |
|
| 447 | - foreach ($this->_views as $view => $args) { |
|
| 448 | - if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 449 | - // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 450 | - // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 451 | - foreach ($args['bulk_action'] as $route => $label) { |
|
| 452 | - if ($this->_admin_page->check_user_access($route, true)) { |
|
| 453 | - $actions[ $route ] = $label; |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - return $actions; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Generate the table navigation above or below the table. |
|
| 464 | - * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 465 | - * |
|
| 466 | - * @throws EE_Error |
|
| 467 | - * @since 4.9.44.rc.001 |
|
| 468 | - */ |
|
| 469 | - public function display_tablenav($which) |
|
| 470 | - { |
|
| 471 | - if ('top' === $which) { |
|
| 472 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 473 | - } |
|
| 474 | - ?> |
|
| 27 | + const ACTION_COPY = 'duplicate'; |
|
| 28 | + |
|
| 29 | + const ACTION_DELETE = 'delete'; |
|
| 30 | + |
|
| 31 | + const ACTION_EDIT = 'edit'; |
|
| 32 | + |
|
| 33 | + const ACTION_RESTORE = 'restore'; |
|
| 34 | + |
|
| 35 | + const ACTION_TRASH = 'trash'; |
|
| 36 | + |
|
| 37 | + protected static array $actions = [ |
|
| 38 | + self::ACTION_COPY, |
|
| 39 | + self::ACTION_DELETE, |
|
| 40 | + self::ACTION_EDIT, |
|
| 41 | + self::ACTION_RESTORE, |
|
| 42 | + self::ACTION_TRASH, |
|
| 43 | + ]; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * holds the data that will be processed for the table |
|
| 47 | + * |
|
| 48 | + * @var array $_data |
|
| 49 | + */ |
|
| 50 | + protected array $_data; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * This holds the value of all the data available for the given view (for all pages). |
|
| 55 | + * |
|
| 56 | + * @var int $_all_data_count |
|
| 57 | + */ |
|
| 58 | + protected int $_all_data_count; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Will contain the count of trashed items for the view label. |
|
| 63 | + * |
|
| 64 | + * @var int $_trashed_count |
|
| 65 | + */ |
|
| 66 | + protected int $_trashed_count; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * This is what will be referenced as the slug for the current screen |
|
| 71 | + * |
|
| 72 | + * @var string $_screen |
|
| 73 | + */ |
|
| 74 | + protected string $_screen; |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * this is the EE_Admin_Page object |
|
| 79 | + * |
|
| 80 | + * @var EE_Admin_Page $_admin_page |
|
| 81 | + */ |
|
| 82 | + protected EE_Admin_Page $_admin_page; |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * The current view |
|
| 87 | + * |
|
| 88 | + * @var string $_view |
|
| 89 | + */ |
|
| 90 | + protected string $_view; |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * array of possible views for this table |
|
| 95 | + * |
|
| 96 | + * @var array $_views |
|
| 97 | + */ |
|
| 98 | + protected array $_views; |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * An array of key => value pairs containing information about the current table |
|
| 103 | + * array( |
|
| 104 | + * 'plural' => 'plural label', |
|
| 105 | + * 'singular' => 'singular label', |
|
| 106 | + * 'ajax' => false, //whether to use ajax or not |
|
| 107 | + * 'screen' => null, //string used to reference what screen this is |
|
| 108 | + * (WP_List_table converts to screen object) |
|
| 109 | + * ) |
|
| 110 | + * |
|
| 111 | + * @var array $_wp_list_args |
|
| 112 | + */ |
|
| 113 | + protected array $_wp_list_args; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * an array of column names |
|
| 117 | + * array( |
|
| 118 | + * 'internal-name' => 'Title' |
|
| 119 | + * ) |
|
| 120 | + * |
|
| 121 | + * @var array $_columns |
|
| 122 | + */ |
|
| 123 | + protected array $_columns; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * An array of sortable columns |
|
| 127 | + * array( |
|
| 128 | + * 'internal-name' => 'orderby' //or |
|
| 129 | + * 'internal-name' => array( 'orderby', true ) |
|
| 130 | + * ) |
|
| 131 | + * |
|
| 132 | + * @var array $_sortable_columns |
|
| 133 | + */ |
|
| 134 | + protected array $_sortable_columns; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * callback method used to perform AJAX row reordering |
|
| 138 | + * |
|
| 139 | + * @var string|null $_ajax_sorting_callback |
|
| 140 | + */ |
|
| 141 | + protected ?string $_ajax_sorting_callback = null; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * An array of hidden columns (if needed) |
|
| 145 | + * array('internal-name', 'internal-name') |
|
| 146 | + * |
|
| 147 | + * @var array $_hidden_columns |
|
| 148 | + */ |
|
| 149 | + protected array $_hidden_columns; |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * holds the per_page value |
|
| 153 | + * |
|
| 154 | + * @var int $_per_page |
|
| 155 | + */ |
|
| 156 | + protected int $_per_page; |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * holds what page number is currently being viewed |
|
| 160 | + * |
|
| 161 | + * @var int $_current_page |
|
| 162 | + */ |
|
| 163 | + protected int $_current_page; |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * the reference string for the nonce_action |
|
| 167 | + * |
|
| 168 | + * @var string $_nonce_action_ref |
|
| 169 | + */ |
|
| 170 | + protected string $_nonce_action_ref; |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * property to hold incoming request data (as set by the admin_page_core) |
|
| 174 | + * |
|
| 175 | + * @var array $_req_data |
|
| 176 | + */ |
|
| 177 | + protected array $_req_data; |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * yes / no array for admin form fields |
|
| 182 | + * |
|
| 183 | + * @var array $_yes_no |
|
| 184 | + */ |
|
| 185 | + protected array $_yes_no = []; |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Array describing buttons that should appear at the bottom of the page |
|
| 189 | + * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 190 | + * and the values are another array with the following keys |
|
| 191 | + * array( |
|
| 192 | + * 'route' => 'page_route', |
|
| 193 | + * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 194 | + * ) |
|
| 195 | + * |
|
| 196 | + * @var array $_bottom_buttons |
|
| 197 | + */ |
|
| 198 | + protected array $_bottom_buttons = []; |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Used to indicate what should be the primary column for the list table. |
|
| 203 | + * If not present then falls back to what WP calculates |
|
| 204 | + * as the primary column. |
|
| 205 | + * |
|
| 206 | + * @type string $_primary_column |
|
| 207 | + */ |
|
| 208 | + protected string $_primary_column = ''; |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Used to indicate whether the table has a checkbox column or not. |
|
| 213 | + * |
|
| 214 | + * @type bool $_has_checkbox_column |
|
| 215 | + */ |
|
| 216 | + protected bool $_has_checkbox_column = false; |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @var AdminListTableFilters|null |
|
| 220 | + */ |
|
| 221 | + protected ?AdminListTableFilters $admin_list_table_filters = null; |
|
| 222 | + |
|
| 223 | + protected ?RequestInterface $request = null; |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 228 | + * @param AdminListTableFilters|null $filters to display list table filters |
|
| 229 | + */ |
|
| 230 | + public function __construct(EE_Admin_Page $admin_page, ?AdminListTableFilters $filters = null) |
|
| 231 | + { |
|
| 232 | + $this->request = $this->request ?? LoaderFactory::getShared(RequestInterface::class); |
|
| 233 | + $this->_admin_page = $admin_page; |
|
| 234 | + $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 235 | + $this->_view = $this->_admin_page->get_view(); |
|
| 236 | + $this->_views = $this->_admin_page->get_list_table_view_RLs(); |
|
| 237 | + $this->_current_page = $this->get_pagenum(); |
|
| 238 | + $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 239 | + $this->_yes_no = [ |
|
| 240 | + esc_html__('No', 'event_espresso'), |
|
| 241 | + esc_html__('Yes', 'event_espresso') |
|
| 242 | + ]; |
|
| 243 | + |
|
| 244 | + $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 245 | + |
|
| 246 | + $this->admin_list_table_filters = $filters instanceof AdminListTableFilters |
|
| 247 | + ? $filters |
|
| 248 | + : LoaderFactory::getShared(AdminListTableFilters::class); |
|
| 249 | + |
|
| 250 | + $this->_setup_data(); |
|
| 251 | + $this->_add_view_counts(); |
|
| 252 | + // ensure changes made to views in child classes get ported back to the admin page |
|
| 253 | + $this->_admin_page->updateViews($this->_views); |
|
| 254 | + |
|
| 255 | + $this->_nonce_action_ref = $this->_view; |
|
| 256 | + |
|
| 257 | + $this->_set_properties(); |
|
| 258 | + |
|
| 259 | + // set primary column |
|
| 260 | + add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 261 | + |
|
| 262 | + // set parent defaults |
|
| 263 | + parent::__construct($this->_wp_list_args); |
|
| 264 | + |
|
| 265 | + $this->prepare_items(); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * _setup_data |
|
| 271 | + * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 272 | + * |
|
| 273 | + * @return void |
|
| 274 | + * @uses $this->_admin_page |
|
| 275 | + */ |
|
| 276 | + abstract protected function _setup_data(); |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 281 | + * properties set: |
|
| 282 | + * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 283 | + * _columns = set the columns in an array. |
|
| 284 | + * _sortable_columns = columns that are sortable (array). |
|
| 285 | + * _hidden_columns = columns that are hidden (array) |
|
| 286 | + * _default_orderby = the default orderby for sorting. |
|
| 287 | + * |
|
| 288 | + * @abstract |
|
| 289 | + * @access protected |
|
| 290 | + * @return void |
|
| 291 | + */ |
|
| 292 | + abstract protected function _set_properties(); |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * _get_table_filters |
|
| 297 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 298 | + * gets shown in the table. |
|
| 299 | + * |
|
| 300 | + * @abstract |
|
| 301 | + * @access protected |
|
| 302 | + * @return string[] |
|
| 303 | + */ |
|
| 304 | + abstract protected function _get_table_filters(); |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 309 | + * counts of the views is accurate. |
|
| 310 | + * |
|
| 311 | + * @abstract |
|
| 312 | + * @access protected |
|
| 313 | + * @return void |
|
| 314 | + */ |
|
| 315 | + abstract protected function _add_view_counts(); |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * _get_hidden_fields |
|
| 320 | + * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 321 | + * |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | + protected function _get_hidden_fields() |
|
| 325 | + { |
|
| 326 | + $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 327 | + $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 328 | + // if action is STILL empty, then we set it to default |
|
| 329 | + $action = empty($action) ? 'default' : $action; |
|
| 330 | + $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 331 | + $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 332 | + $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 333 | + |
|
| 334 | + $bulk_actions = $this->_get_bulk_actions(); |
|
| 335 | + foreach ($bulk_actions as $bulk_action => $label) { |
|
| 336 | + $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 337 | + . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + return $field; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * _set_column_info |
|
| 346 | + * we're using this to set the column headers property. |
|
| 347 | + * |
|
| 348 | + * @access protected |
|
| 349 | + * @return void |
|
| 350 | + */ |
|
| 351 | + protected function _set_column_info() |
|
| 352 | + { |
|
| 353 | + $columns = $this->get_columns(); |
|
| 354 | + $hidden = $this->get_hidden_columns(); |
|
| 355 | + $_sortable = $this->get_sortable_columns(); |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 359 | + * Note that $this->screen->id is in the format |
|
| 360 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 361 | + * table it is: event-espresso_page_espresso_messages. |
|
| 362 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 363 | + * hook prefix ("event-espresso") will be different. |
|
| 364 | + * |
|
| 365 | + * @var array |
|
| 366 | + */ |
|
| 367 | + $_sortable = apply_filters( |
|
| 368 | + "FHEE_manage_{$this->screen->id}_sortable_columns", |
|
| 369 | + $_sortable, |
|
| 370 | + $this->_screen, |
|
| 371 | + $this |
|
| 372 | + ); |
|
| 373 | + |
|
| 374 | + $sortable = []; |
|
| 375 | + foreach ($_sortable as $id => $data) { |
|
| 376 | + if (empty($data)) { |
|
| 377 | + continue; |
|
| 378 | + } |
|
| 379 | + // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 380 | + if (is_array($data)) { |
|
| 381 | + $_data[0] = key($data); |
|
| 382 | + $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 383 | + } else { |
|
| 384 | + $_data[0] = $data; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $data = (array) $data; |
|
| 388 | + |
|
| 389 | + if (! isset($data[1])) { |
|
| 390 | + $_data[1] = false; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + $sortable[ $id ] = $_data; |
|
| 394 | + } |
|
| 395 | + $primary = $this->get_primary_column_name(); |
|
| 396 | + $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 402 | + * |
|
| 403 | + * @return string |
|
| 404 | + */ |
|
| 405 | + protected function get_primary_column_name() |
|
| 406 | + { |
|
| 407 | + foreach (class_parents($this) as $parent) { |
|
| 408 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 409 | + return parent::get_primary_column_name(); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + return $this->_primary_column; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 418 | + * |
|
| 419 | + * @param EE_Base_Class $item |
|
| 420 | + * @param string $column_name |
|
| 421 | + * @param string $primary |
|
| 422 | + * @return string |
|
| 423 | + */ |
|
| 424 | + protected function handle_row_actions($item, $column_name, $primary) |
|
| 425 | + { |
|
| 426 | + foreach (class_parents($this) as $parent) { |
|
| 427 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 428 | + return parent::handle_row_actions($item, $column_name, $primary); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + return ''; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * _get_bulk_actions |
|
| 437 | + * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 438 | + * |
|
| 439 | + * @access protected |
|
| 440 | + * @return array bulk_actions |
|
| 441 | + */ |
|
| 442 | + protected function _get_bulk_actions(): array |
|
| 443 | + { |
|
| 444 | + $actions = []; |
|
| 445 | + // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 446 | + // formatted array for the wp_list_table(); |
|
| 447 | + foreach ($this->_views as $view => $args) { |
|
| 448 | + if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 449 | + // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 450 | + // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 451 | + foreach ($args['bulk_action'] as $route => $label) { |
|
| 452 | + if ($this->_admin_page->check_user_access($route, true)) { |
|
| 453 | + $actions[ $route ] = $label; |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + return $actions; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Generate the table navigation above or below the table. |
|
| 464 | + * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 465 | + * |
|
| 466 | + * @throws EE_Error |
|
| 467 | + * @since 4.9.44.rc.001 |
|
| 468 | + */ |
|
| 469 | + public function display_tablenav($which) |
|
| 470 | + { |
|
| 471 | + if ('top' === $which) { |
|
| 472 | + wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 473 | + } |
|
| 474 | + ?> |
|
| 475 | 475 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
| 476 | 476 | <?php if ($this->_get_bulk_actions()) { ?> |
| 477 | 477 | <div class="alignleft actions bulkactions"> |
| 478 | 478 | <?php $this->bulk_actions(); ?> |
| 479 | 479 | </div> |
| 480 | 480 | <?php } |
| 481 | - $this->extra_tablenav($which); |
|
| 482 | - $this->pagination($which); |
|
| 483 | - ?> |
|
| 481 | + $this->extra_tablenav($which); |
|
| 482 | + $this->pagination($which); |
|
| 483 | + ?> |
|
| 484 | 484 | |
| 485 | 485 | <br class="clear" /> |
| 486 | 486 | </div> |
| 487 | 487 | <?php |
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * _filters |
|
| 493 | - * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 494 | - * button. |
|
| 495 | - * |
|
| 496 | - * @access private |
|
| 497 | - * @return void echos html showing filters |
|
| 498 | - */ |
|
| 499 | - private function _filters(): void |
|
| 500 | - { |
|
| 501 | - $classname = get_class($this); |
|
| 502 | - $filters = apply_filters( |
|
| 503 | - "FHEE__{$classname}__filters", |
|
| 504 | - $this->_get_table_filters(), |
|
| 505 | - $this, |
|
| 506 | - $this->_screen |
|
| 507 | - ); |
|
| 508 | - |
|
| 509 | - if (empty($filters)) { |
|
| 510 | - return; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - $this->admin_list_table_filters->filters( |
|
| 514 | - $filters, |
|
| 515 | - $this->get_admin_page()->get_current_page_view_url() |
|
| 516 | - ); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Callback for 'list_table_primary_column' WordPress filter |
|
| 522 | - * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 523 | - * column when class is instantiated. |
|
| 524 | - * |
|
| 525 | - * @param string $column_name |
|
| 526 | - * @return string |
|
| 527 | - * @see WP_List_Table::get_primary_column_name |
|
| 528 | - */ |
|
| 529 | - public function set_primary_column($column_name) |
|
| 530 | - { |
|
| 531 | - return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * |
|
| 537 | - */ |
|
| 538 | - public function prepare_items() |
|
| 539 | - { |
|
| 540 | - $this->_set_column_info(); |
|
| 541 | - $this->process_bulk_action(); |
|
| 542 | - |
|
| 543 | - $this->items = $this->_data; |
|
| 544 | - $this->set_pagination_args( |
|
| 545 | - [ |
|
| 546 | - 'total_items' => $this->_all_data_count, |
|
| 547 | - 'per_page' => $this->_per_page, |
|
| 548 | - 'total_pages' => (int) ceil($this->_all_data_count / $this->_per_page), |
|
| 549 | - ] |
|
| 550 | - ); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * @param object|array $item |
|
| 556 | - * @return string html content for the column |
|
| 557 | - */ |
|
| 558 | - protected function column_cb($item) |
|
| 559 | - { |
|
| 560 | - return ''; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * This column is the default for when there is no defined column method for a registered column. |
|
| 566 | - * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 567 | - * |
|
| 568 | - * @param EE_Base_Class $item |
|
| 569 | - * @param string $column_name The column being called. |
|
| 570 | - * @return string html content for the column |
|
| 571 | - */ |
|
| 572 | - public function column_default($item, $column_name) |
|
| 573 | - { |
|
| 574 | - /** |
|
| 575 | - * Dynamic hook allowing for adding additional column content in this list table. |
|
| 576 | - * Note that $this->screen->id is in the format |
|
| 577 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 578 | - * table it is: event-espresso_page_espresso_messages. |
|
| 579 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 580 | - * hook prefix ("event-espresso") will be different. |
|
| 581 | - */ |
|
| 582 | - ob_start(); |
|
| 583 | - do_action( |
|
| 584 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 585 | - $item, |
|
| 586 | - $this->_screen |
|
| 587 | - ); |
|
| 588 | - $content = ob_get_clean(); |
|
| 589 | - return $column_name === 'actions' ? $this->actionsModalMenu($content) : $content; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Get a list of columns. The format is: |
|
| 595 | - * 'internal-name' => 'Title' |
|
| 596 | - * |
|
| 597 | - * @return array |
|
| 598 | - * @since 3.1.0 |
|
| 599 | - * @access public |
|
| 600 | - * @abstract |
|
| 601 | - */ |
|
| 602 | - public function get_columns() |
|
| 603 | - { |
|
| 604 | - /** |
|
| 605 | - * Dynamic hook allowing for adding additional columns in this list table. |
|
| 606 | - * Note that $this->screen->id is in the format |
|
| 607 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 608 | - * table it is: event-espresso_page_espresso_messages. |
|
| 609 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 610 | - * hook prefix ("event-espresso") will be different. |
|
| 611 | - * |
|
| 612 | - * @var array |
|
| 613 | - */ |
|
| 614 | - return apply_filters("FHEE_manage_{$this->screen->id}_columns", $this->_columns, $this->_screen, $this); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Get an associative array ( id => link ) with the list |
|
| 620 | - * of views available on this table. |
|
| 621 | - * |
|
| 622 | - * @return array |
|
| 623 | - * @since 3.1.0 |
|
| 624 | - * @access protected |
|
| 625 | - */ |
|
| 626 | - public function get_views() |
|
| 627 | - { |
|
| 628 | - return $this->_views; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Generate the views html. |
|
| 634 | - */ |
|
| 635 | - public function display_views() |
|
| 636 | - { |
|
| 637 | - $views = $this->get_views(); |
|
| 638 | - $assembled_views = []; |
|
| 639 | - |
|
| 640 | - if (empty($views)) { |
|
| 641 | - return; |
|
| 642 | - } |
|
| 643 | - echo "<ul class='subsubsub'>\n"; |
|
| 644 | - foreach ($views as $view) { |
|
| 645 | - $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 646 | - if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 647 | - $filter = "<li"; |
|
| 648 | - $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 649 | - $filter .= ">"; |
|
| 650 | - $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 651 | - $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 652 | - $filter .= '</li>'; |
|
| 653 | - $assembled_views[ $view['slug'] ] = $filter; |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - echo ! empty($assembled_views) |
|
| 658 | - ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 659 | - : ''; |
|
| 660 | - echo "</ul>"; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Generates content for a single row of the table |
|
| 666 | - * |
|
| 667 | - * @param EE_Base_Class $item The current item |
|
| 668 | - * @since 4.1 |
|
| 669 | - * @access public |
|
| 670 | - */ |
|
| 671 | - public function single_row($item) |
|
| 672 | - { |
|
| 673 | - $row_class = $this->_get_row_class($item); |
|
| 674 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 675 | - $this->single_row_columns($item); // already escaped |
|
| 676 | - echo '</tr>'; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * This simply sets up the row class for the table rows. |
|
| 682 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 683 | - * |
|
| 684 | - * @param EE_Base_Class $item the current item |
|
| 685 | - * @return string |
|
| 686 | - */ |
|
| 687 | - protected function _get_row_class($item) |
|
| 688 | - { |
|
| 689 | - static $row_class = ''; |
|
| 690 | - $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 691 | - |
|
| 692 | - $new_row_class = $row_class; |
|
| 693 | - |
|
| 694 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 695 | - $new_row_class .= ' rowsortable'; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - return $new_row_class; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * @return array |
|
| 704 | - */ |
|
| 705 | - public function get_sortable_columns() |
|
| 706 | - { |
|
| 707 | - return (array) $this->_sortable_columns; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * @return string |
|
| 713 | - */ |
|
| 714 | - public function get_ajax_sorting_callback() |
|
| 715 | - { |
|
| 716 | - return $this->_ajax_sorting_callback; |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * @return array |
|
| 722 | - */ |
|
| 723 | - public function get_hidden_columns() |
|
| 724 | - { |
|
| 725 | - $user_id = get_current_user_id(); |
|
| 726 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 727 | - if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 728 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 729 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 730 | - } |
|
| 731 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 732 | - return (array) get_user_option($ref, $user_id); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Generates the columns for a single row of the table. |
|
| 738 | - * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 739 | - * column. |
|
| 740 | - * |
|
| 741 | - * @param EE_Base_Class $item The current item |
|
| 742 | - * @since 3.1.0 |
|
| 743 | - */ |
|
| 744 | - public function single_row_columns($item) |
|
| 745 | - { |
|
| 746 | - [$columns, $hidden, $sortable, $primary] = $this->get_column_info(); |
|
| 747 | - |
|
| 748 | - foreach ($columns as $column_name => $column_display_name) { |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 752 | - * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 753 | - */ |
|
| 754 | - $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 755 | - |
|
| 756 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 757 | - if ($primary === $column_name) { |
|
| 758 | - $classes .= ' has-row-actions column-primary'; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 762 | - |
|
| 763 | - $class = 'class="' . esc_attr($classes) . '"'; |
|
| 764 | - |
|
| 765 | - $attributes = "{$class}{$data}"; |
|
| 766 | - |
|
| 767 | - if ($column_name === 'cb') { |
|
| 768 | - echo '<th scope="row" class="check-column">'; |
|
| 769 | - echo apply_filters( |
|
| 770 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 771 | - $this->column_cb($item), // already escaped |
|
| 772 | - $item, |
|
| 773 | - $this |
|
| 774 | - ); |
|
| 775 | - echo '</th>'; |
|
| 776 | - } elseif (method_exists($this, "column_$column_name")) { |
|
| 777 | - echo "<td $attributes>"; // already escaped |
|
| 778 | - echo apply_filters( |
|
| 779 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 780 | - call_user_func([$this, "column_$column_name"], $item), |
|
| 781 | - $item, |
|
| 782 | - $this |
|
| 783 | - ); |
|
| 784 | - echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 785 | - echo "</td>"; |
|
| 786 | - } else { |
|
| 787 | - echo "<td $attributes>"; // already escaped |
|
| 788 | - echo apply_filters( |
|
| 789 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 790 | - $this->column_default($item, $column_name), |
|
| 791 | - $item, |
|
| 792 | - $column_name, |
|
| 793 | - $this |
|
| 794 | - ); |
|
| 795 | - echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 796 | - echo "</td>"; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Extra controls to be displayed between bulk actions and pagination |
|
| 804 | - * |
|
| 805 | - * @access public |
|
| 806 | - * @param string $which |
|
| 807 | - * @throws EE_Error |
|
| 808 | - */ |
|
| 809 | - public function extra_tablenav($which) |
|
| 810 | - { |
|
| 811 | - if ($which === 'top') { |
|
| 812 | - $this->_filters(); |
|
| 813 | - echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags()); |
|
| 814 | - } else { |
|
| 815 | - echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 816 | - foreach ($this->_bottom_buttons as $type => $action) { |
|
| 817 | - $route = $action['route'] ?? ''; |
|
| 818 | - $extra_request = $action['extra_request'] ?? []; |
|
| 819 | - $btn_class = $action['btn_class'] ?? 'button button--secondary'; |
|
| 820 | - // already escaped |
|
| 821 | - echo wp_kses($this->_admin_page->get_action_link_or_button( |
|
| 822 | - $route, |
|
| 823 | - $type, |
|
| 824 | - $extra_request, |
|
| 825 | - $btn_class |
|
| 826 | - ), AllowedTags::getWithFormTags()); |
|
| 827 | - } |
|
| 828 | - do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 829 | - echo '</div>'; |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * Get an associative array ( option_name => option_title ) with the list |
|
| 836 | - * of bulk actions available on this table. |
|
| 837 | - * |
|
| 838 | - * @return array |
|
| 839 | - * @since 3.1.0 |
|
| 840 | - * @access protected |
|
| 841 | - */ |
|
| 842 | - public function get_bulk_actions() |
|
| 843 | - { |
|
| 844 | - return (array) $this->_get_bulk_actions(); |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Processing bulk actions. |
|
| 850 | - */ |
|
| 851 | - public function process_bulk_action() |
|
| 852 | - { |
|
| 853 | - // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 854 | - // reference in case there is a case where it gets used. |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * returns the EE admin page this list table is associated with |
|
| 860 | - * |
|
| 861 | - * @return EE_Admin_Page |
|
| 862 | - */ |
|
| 863 | - public function get_admin_page() |
|
| 864 | - { |
|
| 865 | - return $this->_admin_page; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * A "helper" function for all children to provide an html string of |
|
| 871 | - * actions to output in their content. It is preferable for child classes |
|
| 872 | - * to use this method for generating their actions content so that it's |
|
| 873 | - * filterable by plugins |
|
| 874 | - * |
|
| 875 | - * @param string $action_container what are the html container |
|
| 876 | - * elements for this actions string? |
|
| 877 | - * @param string $action_class What class is for the container |
|
| 878 | - * element. |
|
| 879 | - * @param string $action_items The contents for the action items |
|
| 880 | - * container. This is filtered before |
|
| 881 | - * returned. |
|
| 882 | - * @param string $action_id What id (optional) is used for the |
|
| 883 | - * container element. |
|
| 884 | - * @param EE_Base_Class $item The object for the column displaying |
|
| 885 | - * the actions. |
|
| 886 | - * @return string The assembled action elements container. |
|
| 887 | - */ |
|
| 888 | - protected function _action_string( |
|
| 889 | - $action_items, |
|
| 890 | - $item, |
|
| 891 | - $action_container = 'ul', |
|
| 892 | - $action_class = '', |
|
| 893 | - $action_id = '' |
|
| 894 | - ) { |
|
| 895 | - $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 896 | - $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 897 | - $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 898 | - $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 899 | - try { |
|
| 900 | - $content = apply_filters( |
|
| 901 | - 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 902 | - $action_items, |
|
| 903 | - $item, |
|
| 904 | - $this |
|
| 905 | - ); |
|
| 906 | - } catch (Exception $e) { |
|
| 907 | - if (WP_DEBUG) { |
|
| 908 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 909 | - } |
|
| 910 | - $content = $action_items; |
|
| 911 | - } |
|
| 912 | - return "{$open_tag}{$content}{$close_tag}"; |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * @return string |
|
| 918 | - */ |
|
| 919 | - protected function getReturnUrl() |
|
| 920 | - { |
|
| 921 | - $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 922 | - $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 923 | - return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * @param string $id |
|
| 929 | - * @param string $content |
|
| 930 | - * @param string $align start (default), center, end |
|
| 931 | - * @return string |
|
| 932 | - * @since 5.0.0.p |
|
| 933 | - */ |
|
| 934 | - protected function columnContent($id, $content, $align = 'start') |
|
| 935 | - { |
|
| 936 | - if (! isset($this->_columns[ $id ])) { |
|
| 937 | - throw new DomainException('missing column id'); |
|
| 938 | - } |
|
| 939 | - $heading = $id !== 'cb' ? $this->_columns[ $id ] : ''; |
|
| 940 | - $align = in_array($align, ['start', 'center', 'end']) ? $align : 'start'; |
|
| 941 | - $align = "ee-responsive-table-cell--{$align}"; |
|
| 942 | - |
|
| 943 | - $html = "<div class='ee-responsive-table-cell ee-responsive-table-cell--column-{$id} {$align} ee-layout-row'>"; |
|
| 944 | - $html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>"; |
|
| 945 | - $html .= "<div class='ee-responsive-table-cell__content ee-layout-row'>{$content}</div>"; |
|
| 946 | - $html .= "</div>"; |
|
| 947 | - return $html; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - protected function actionsModalMenu($actions): string |
|
| 952 | - { |
|
| 953 | - return ' |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * _filters |
|
| 493 | + * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 494 | + * button. |
|
| 495 | + * |
|
| 496 | + * @access private |
|
| 497 | + * @return void echos html showing filters |
|
| 498 | + */ |
|
| 499 | + private function _filters(): void |
|
| 500 | + { |
|
| 501 | + $classname = get_class($this); |
|
| 502 | + $filters = apply_filters( |
|
| 503 | + "FHEE__{$classname}__filters", |
|
| 504 | + $this->_get_table_filters(), |
|
| 505 | + $this, |
|
| 506 | + $this->_screen |
|
| 507 | + ); |
|
| 508 | + |
|
| 509 | + if (empty($filters)) { |
|
| 510 | + return; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + $this->admin_list_table_filters->filters( |
|
| 514 | + $filters, |
|
| 515 | + $this->get_admin_page()->get_current_page_view_url() |
|
| 516 | + ); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Callback for 'list_table_primary_column' WordPress filter |
|
| 522 | + * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 523 | + * column when class is instantiated. |
|
| 524 | + * |
|
| 525 | + * @param string $column_name |
|
| 526 | + * @return string |
|
| 527 | + * @see WP_List_Table::get_primary_column_name |
|
| 528 | + */ |
|
| 529 | + public function set_primary_column($column_name) |
|
| 530 | + { |
|
| 531 | + return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * |
|
| 537 | + */ |
|
| 538 | + public function prepare_items() |
|
| 539 | + { |
|
| 540 | + $this->_set_column_info(); |
|
| 541 | + $this->process_bulk_action(); |
|
| 542 | + |
|
| 543 | + $this->items = $this->_data; |
|
| 544 | + $this->set_pagination_args( |
|
| 545 | + [ |
|
| 546 | + 'total_items' => $this->_all_data_count, |
|
| 547 | + 'per_page' => $this->_per_page, |
|
| 548 | + 'total_pages' => (int) ceil($this->_all_data_count / $this->_per_page), |
|
| 549 | + ] |
|
| 550 | + ); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * @param object|array $item |
|
| 556 | + * @return string html content for the column |
|
| 557 | + */ |
|
| 558 | + protected function column_cb($item) |
|
| 559 | + { |
|
| 560 | + return ''; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * This column is the default for when there is no defined column method for a registered column. |
|
| 566 | + * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 567 | + * |
|
| 568 | + * @param EE_Base_Class $item |
|
| 569 | + * @param string $column_name The column being called. |
|
| 570 | + * @return string html content for the column |
|
| 571 | + */ |
|
| 572 | + public function column_default($item, $column_name) |
|
| 573 | + { |
|
| 574 | + /** |
|
| 575 | + * Dynamic hook allowing for adding additional column content in this list table. |
|
| 576 | + * Note that $this->screen->id is in the format |
|
| 577 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 578 | + * table it is: event-espresso_page_espresso_messages. |
|
| 579 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 580 | + * hook prefix ("event-espresso") will be different. |
|
| 581 | + */ |
|
| 582 | + ob_start(); |
|
| 583 | + do_action( |
|
| 584 | + 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 585 | + $item, |
|
| 586 | + $this->_screen |
|
| 587 | + ); |
|
| 588 | + $content = ob_get_clean(); |
|
| 589 | + return $column_name === 'actions' ? $this->actionsModalMenu($content) : $content; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Get a list of columns. The format is: |
|
| 595 | + * 'internal-name' => 'Title' |
|
| 596 | + * |
|
| 597 | + * @return array |
|
| 598 | + * @since 3.1.0 |
|
| 599 | + * @access public |
|
| 600 | + * @abstract |
|
| 601 | + */ |
|
| 602 | + public function get_columns() |
|
| 603 | + { |
|
| 604 | + /** |
|
| 605 | + * Dynamic hook allowing for adding additional columns in this list table. |
|
| 606 | + * Note that $this->screen->id is in the format |
|
| 607 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 608 | + * table it is: event-espresso_page_espresso_messages. |
|
| 609 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 610 | + * hook prefix ("event-espresso") will be different. |
|
| 611 | + * |
|
| 612 | + * @var array |
|
| 613 | + */ |
|
| 614 | + return apply_filters("FHEE_manage_{$this->screen->id}_columns", $this->_columns, $this->_screen, $this); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Get an associative array ( id => link ) with the list |
|
| 620 | + * of views available on this table. |
|
| 621 | + * |
|
| 622 | + * @return array |
|
| 623 | + * @since 3.1.0 |
|
| 624 | + * @access protected |
|
| 625 | + */ |
|
| 626 | + public function get_views() |
|
| 627 | + { |
|
| 628 | + return $this->_views; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Generate the views html. |
|
| 634 | + */ |
|
| 635 | + public function display_views() |
|
| 636 | + { |
|
| 637 | + $views = $this->get_views(); |
|
| 638 | + $assembled_views = []; |
|
| 639 | + |
|
| 640 | + if (empty($views)) { |
|
| 641 | + return; |
|
| 642 | + } |
|
| 643 | + echo "<ul class='subsubsub'>\n"; |
|
| 644 | + foreach ($views as $view) { |
|
| 645 | + $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 646 | + if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 647 | + $filter = "<li"; |
|
| 648 | + $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 649 | + $filter .= ">"; |
|
| 650 | + $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 651 | + $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 652 | + $filter .= '</li>'; |
|
| 653 | + $assembled_views[ $view['slug'] ] = $filter; |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + echo ! empty($assembled_views) |
|
| 658 | + ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 659 | + : ''; |
|
| 660 | + echo "</ul>"; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Generates content for a single row of the table |
|
| 666 | + * |
|
| 667 | + * @param EE_Base_Class $item The current item |
|
| 668 | + * @since 4.1 |
|
| 669 | + * @access public |
|
| 670 | + */ |
|
| 671 | + public function single_row($item) |
|
| 672 | + { |
|
| 673 | + $row_class = $this->_get_row_class($item); |
|
| 674 | + echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 675 | + $this->single_row_columns($item); // already escaped |
|
| 676 | + echo '</tr>'; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * This simply sets up the row class for the table rows. |
|
| 682 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 683 | + * |
|
| 684 | + * @param EE_Base_Class $item the current item |
|
| 685 | + * @return string |
|
| 686 | + */ |
|
| 687 | + protected function _get_row_class($item) |
|
| 688 | + { |
|
| 689 | + static $row_class = ''; |
|
| 690 | + $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 691 | + |
|
| 692 | + $new_row_class = $row_class; |
|
| 693 | + |
|
| 694 | + if (! empty($this->_ajax_sorting_callback)) { |
|
| 695 | + $new_row_class .= ' rowsortable'; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + return $new_row_class; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * @return array |
|
| 704 | + */ |
|
| 705 | + public function get_sortable_columns() |
|
| 706 | + { |
|
| 707 | + return (array) $this->_sortable_columns; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * @return string |
|
| 713 | + */ |
|
| 714 | + public function get_ajax_sorting_callback() |
|
| 715 | + { |
|
| 716 | + return $this->_ajax_sorting_callback; |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * @return array |
|
| 722 | + */ |
|
| 723 | + public function get_hidden_columns() |
|
| 724 | + { |
|
| 725 | + $user_id = get_current_user_id(); |
|
| 726 | + $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 727 | + if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 728 | + update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 729 | + update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 730 | + } |
|
| 731 | + $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 732 | + return (array) get_user_option($ref, $user_id); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Generates the columns for a single row of the table. |
|
| 738 | + * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 739 | + * column. |
|
| 740 | + * |
|
| 741 | + * @param EE_Base_Class $item The current item |
|
| 742 | + * @since 3.1.0 |
|
| 743 | + */ |
|
| 744 | + public function single_row_columns($item) |
|
| 745 | + { |
|
| 746 | + [$columns, $hidden, $sortable, $primary] = $this->get_column_info(); |
|
| 747 | + |
|
| 748 | + foreach ($columns as $column_name => $column_display_name) { |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 752 | + * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 753 | + */ |
|
| 754 | + $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 755 | + |
|
| 756 | + $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 757 | + if ($primary === $column_name) { |
|
| 758 | + $classes .= ' has-row-actions column-primary'; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 762 | + |
|
| 763 | + $class = 'class="' . esc_attr($classes) . '"'; |
|
| 764 | + |
|
| 765 | + $attributes = "{$class}{$data}"; |
|
| 766 | + |
|
| 767 | + if ($column_name === 'cb') { |
|
| 768 | + echo '<th scope="row" class="check-column">'; |
|
| 769 | + echo apply_filters( |
|
| 770 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 771 | + $this->column_cb($item), // already escaped |
|
| 772 | + $item, |
|
| 773 | + $this |
|
| 774 | + ); |
|
| 775 | + echo '</th>'; |
|
| 776 | + } elseif (method_exists($this, "column_$column_name")) { |
|
| 777 | + echo "<td $attributes>"; // already escaped |
|
| 778 | + echo apply_filters( |
|
| 779 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 780 | + call_user_func([$this, "column_$column_name"], $item), |
|
| 781 | + $item, |
|
| 782 | + $this |
|
| 783 | + ); |
|
| 784 | + echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 785 | + echo "</td>"; |
|
| 786 | + } else { |
|
| 787 | + echo "<td $attributes>"; // already escaped |
|
| 788 | + echo apply_filters( |
|
| 789 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 790 | + $this->column_default($item, $column_name), |
|
| 791 | + $item, |
|
| 792 | + $column_name, |
|
| 793 | + $this |
|
| 794 | + ); |
|
| 795 | + echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 796 | + echo "</td>"; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Extra controls to be displayed between bulk actions and pagination |
|
| 804 | + * |
|
| 805 | + * @access public |
|
| 806 | + * @param string $which |
|
| 807 | + * @throws EE_Error |
|
| 808 | + */ |
|
| 809 | + public function extra_tablenav($which) |
|
| 810 | + { |
|
| 811 | + if ($which === 'top') { |
|
| 812 | + $this->_filters(); |
|
| 813 | + echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags()); |
|
| 814 | + } else { |
|
| 815 | + echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 816 | + foreach ($this->_bottom_buttons as $type => $action) { |
|
| 817 | + $route = $action['route'] ?? ''; |
|
| 818 | + $extra_request = $action['extra_request'] ?? []; |
|
| 819 | + $btn_class = $action['btn_class'] ?? 'button button--secondary'; |
|
| 820 | + // already escaped |
|
| 821 | + echo wp_kses($this->_admin_page->get_action_link_or_button( |
|
| 822 | + $route, |
|
| 823 | + $type, |
|
| 824 | + $extra_request, |
|
| 825 | + $btn_class |
|
| 826 | + ), AllowedTags::getWithFormTags()); |
|
| 827 | + } |
|
| 828 | + do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 829 | + echo '</div>'; |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * Get an associative array ( option_name => option_title ) with the list |
|
| 836 | + * of bulk actions available on this table. |
|
| 837 | + * |
|
| 838 | + * @return array |
|
| 839 | + * @since 3.1.0 |
|
| 840 | + * @access protected |
|
| 841 | + */ |
|
| 842 | + public function get_bulk_actions() |
|
| 843 | + { |
|
| 844 | + return (array) $this->_get_bulk_actions(); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Processing bulk actions. |
|
| 850 | + */ |
|
| 851 | + public function process_bulk_action() |
|
| 852 | + { |
|
| 853 | + // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 854 | + // reference in case there is a case where it gets used. |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * returns the EE admin page this list table is associated with |
|
| 860 | + * |
|
| 861 | + * @return EE_Admin_Page |
|
| 862 | + */ |
|
| 863 | + public function get_admin_page() |
|
| 864 | + { |
|
| 865 | + return $this->_admin_page; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * A "helper" function for all children to provide an html string of |
|
| 871 | + * actions to output in their content. It is preferable for child classes |
|
| 872 | + * to use this method for generating their actions content so that it's |
|
| 873 | + * filterable by plugins |
|
| 874 | + * |
|
| 875 | + * @param string $action_container what are the html container |
|
| 876 | + * elements for this actions string? |
|
| 877 | + * @param string $action_class What class is for the container |
|
| 878 | + * element. |
|
| 879 | + * @param string $action_items The contents for the action items |
|
| 880 | + * container. This is filtered before |
|
| 881 | + * returned. |
|
| 882 | + * @param string $action_id What id (optional) is used for the |
|
| 883 | + * container element. |
|
| 884 | + * @param EE_Base_Class $item The object for the column displaying |
|
| 885 | + * the actions. |
|
| 886 | + * @return string The assembled action elements container. |
|
| 887 | + */ |
|
| 888 | + protected function _action_string( |
|
| 889 | + $action_items, |
|
| 890 | + $item, |
|
| 891 | + $action_container = 'ul', |
|
| 892 | + $action_class = '', |
|
| 893 | + $action_id = '' |
|
| 894 | + ) { |
|
| 895 | + $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 896 | + $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 897 | + $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 898 | + $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 899 | + try { |
|
| 900 | + $content = apply_filters( |
|
| 901 | + 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 902 | + $action_items, |
|
| 903 | + $item, |
|
| 904 | + $this |
|
| 905 | + ); |
|
| 906 | + } catch (Exception $e) { |
|
| 907 | + if (WP_DEBUG) { |
|
| 908 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 909 | + } |
|
| 910 | + $content = $action_items; |
|
| 911 | + } |
|
| 912 | + return "{$open_tag}{$content}{$close_tag}"; |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * @return string |
|
| 918 | + */ |
|
| 919 | + protected function getReturnUrl() |
|
| 920 | + { |
|
| 921 | + $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 922 | + $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 923 | + return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * @param string $id |
|
| 929 | + * @param string $content |
|
| 930 | + * @param string $align start (default), center, end |
|
| 931 | + * @return string |
|
| 932 | + * @since 5.0.0.p |
|
| 933 | + */ |
|
| 934 | + protected function columnContent($id, $content, $align = 'start') |
|
| 935 | + { |
|
| 936 | + if (! isset($this->_columns[ $id ])) { |
|
| 937 | + throw new DomainException('missing column id'); |
|
| 938 | + } |
|
| 939 | + $heading = $id !== 'cb' ? $this->_columns[ $id ] : ''; |
|
| 940 | + $align = in_array($align, ['start', 'center', 'end']) ? $align : 'start'; |
|
| 941 | + $align = "ee-responsive-table-cell--{$align}"; |
|
| 942 | + |
|
| 943 | + $html = "<div class='ee-responsive-table-cell ee-responsive-table-cell--column-{$id} {$align} ee-layout-row'>"; |
|
| 944 | + $html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>"; |
|
| 945 | + $html .= "<div class='ee-responsive-table-cell__content ee-layout-row'>{$content}</div>"; |
|
| 946 | + $html .= "</div>"; |
|
| 947 | + return $html; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + protected function actionsModalMenu($actions): string |
|
| 952 | + { |
|
| 953 | + return ' |
|
| 954 | 954 | <div class="ee-modal-menu"> |
| 955 | 955 | <button class="ee-modal-menu__button button button--secondary button--icon-only ee-aria-tooltip" |
| 956 | 956 | aria-label="' . esc_attr__('list table actions menu', 'event_espresso') . '" |
@@ -962,43 +962,43 @@ discard block |
||
| 962 | 962 | ' . $actions . ' |
| 963 | 963 | </div> |
| 964 | 964 | </div>'; |
| 965 | - } |
|
| 965 | + } |
|
| 966 | 966 | |
| 967 | 967 | |
| 968 | - public function actionsColumnHeader(): string |
|
| 969 | - { |
|
| 970 | - return ' |
|
| 968 | + public function actionsColumnHeader(): string |
|
| 969 | + { |
|
| 970 | + return ' |
|
| 971 | 971 | <span class="ee-actions-column-header-wrap"> |
| 972 | 972 | <span class="dashicons dashicons-screenoptions"></span> |
| 973 | 973 | <span class="ee-actions-column-header">' . esc_html__('Actions', 'event_espresso') . '</span> |
| 974 | 974 | </span>'; |
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - protected function getActionLink(string $url, string $display_text, string $label, $class = ''): string |
|
| 979 | - { |
|
| 980 | - $class = ! empty($class) ? "{$class} ee-list-table-action" : 'ee-list-table-action'; |
|
| 981 | - $class = ! empty($label) ? "{$class} ee-aria-tooltip" : $class; |
|
| 982 | - $label = ! empty($label) ? " aria-label='{$label}'" : ''; |
|
| 983 | - return "<a href='{$url}' class='{$class}'{$label}>{$display_text}</a>"; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - /** |
|
| 987 | - * Override the search box method of WP List Table to include a reset button |
|
| 988 | - * |
|
| 989 | - * @param string $text The 'submit' button label. |
|
| 990 | - * @param string $input_id ID attribute value for the search input field. |
|
| 991 | - */ |
|
| 992 | - public function search_box($text, $input_id) |
|
| 993 | - { |
|
| 994 | - if (empty($_REQUEST['s']) && ! $this->has_items()) { |
|
| 995 | - return; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - $this->admin_list_table_filters->searchBox( |
|
| 999 | - $text, |
|
| 1000 | - $input_id, |
|
| 1001 | - $this->get_admin_page()->get_current_page_view_url() |
|
| 1002 | - ); |
|
| 1003 | - } |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + protected function getActionLink(string $url, string $display_text, string $label, $class = ''): string |
|
| 979 | + { |
|
| 980 | + $class = ! empty($class) ? "{$class} ee-list-table-action" : 'ee-list-table-action'; |
|
| 981 | + $class = ! empty($label) ? "{$class} ee-aria-tooltip" : $class; |
|
| 982 | + $label = ! empty($label) ? " aria-label='{$label}'" : ''; |
|
| 983 | + return "<a href='{$url}' class='{$class}'{$label}>{$display_text}</a>"; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + /** |
|
| 987 | + * Override the search box method of WP List Table to include a reset button |
|
| 988 | + * |
|
| 989 | + * @param string $text The 'submit' button label. |
|
| 990 | + * @param string $input_id ID attribute value for the search input field. |
|
| 991 | + */ |
|
| 992 | + public function search_box($text, $input_id) |
|
| 993 | + { |
|
| 994 | + if (empty($_REQUEST['s']) && ! $this->has_items()) { |
|
| 995 | + return; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + $this->admin_list_table_filters->searchBox( |
|
| 999 | + $text, |
|
| 1000 | + $input_id, |
|
| 1001 | + $this->get_admin_page()->get_current_page_view_url() |
|
| 1002 | + ); |
|
| 1003 | + } |
|
| 1004 | 1004 | } |
@@ -31,452 +31,452 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | abstract class EE_Admin_Page_CPT extends EE_Admin_Page |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * @var EE_CPT_Base|null |
|
| 36 | - */ |
|
| 37 | - protected $_cpt_model_obj; |
|
| 38 | - |
|
| 39 | - protected ?WP_Post_Type $_cpt_object = null; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
| 44 | - * //in this array we define what the custom post type for this route is. |
|
| 45 | - * array( |
|
| 46 | - * 'route_name' => 'custom_post_type_slug' |
|
| 47 | - * ) |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - protected array $_cpt_routes = []; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
| 56 | - * in this format: |
|
| 57 | - * array( |
|
| 58 | - * 'post_type_slug' => 'edit_route' |
|
| 59 | - * ) |
|
| 60 | - * |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - protected array $_cpt_edit_routes = []; |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
| 68 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
| 69 | - * _cpt_model_names property should be in the following format: array( |
|
| 70 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
| 71 | - * |
|
| 72 | - * @var array $_cpt_model_names |
|
| 73 | - */ |
|
| 74 | - protected array $_cpt_model_names = []; |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
| 79 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
| 80 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
| 81 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
| 82 | - * |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - protected array $_autosave_containers = []; |
|
| 86 | - |
|
| 87 | - protected array $_autosave_fields = []; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
| 91 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
| 92 | - * |
|
| 93 | - * @var array |
|
| 94 | - */ |
|
| 95 | - protected array $_pagenow_map= []; |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * This is the route that will be used for the edit post route. |
|
| 100 | - * |
|
| 101 | - * @var string |
|
| 102 | - */ |
|
| 103 | - protected string $cpt_editpost_route = 'edit'; |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 108 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 109 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
| 110 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
| 111 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
| 112 | - * |
|
| 113 | - * @abstract |
|
| 114 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 115 | - * @param WP_Post $post The post object of the cpt that was saved. |
|
| 116 | - * @return void |
|
| 117 | - */ |
|
| 118 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
| 123 | - * |
|
| 124 | - * @abstract |
|
| 125 | - * @param string $post_id The ID of the cpt that was trashed |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - abstract public function trash_cpt_item($post_id); |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
| 133 | - * |
|
| 134 | - * @param string $post_id theID of the cpt that was untrashed |
|
| 135 | - * @return void |
|
| 136 | - */ |
|
| 137 | - abstract public function restore_cpt_item($post_id); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
| 142 | - * from the db |
|
| 143 | - * |
|
| 144 | - * @param string $post_id the ID of the cpt that was deleted |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - abstract public function delete_cpt_item($post_id); |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @return LoaderInterface |
|
| 152 | - * @throws InvalidArgumentException |
|
| 153 | - * @throws InvalidDataTypeException |
|
| 154 | - * @throws InvalidInterfaceException |
|
| 155 | - */ |
|
| 156 | - protected function getLoader(): LoaderInterface |
|
| 157 | - { |
|
| 158 | - if (! $this->loader instanceof LoaderInterface) { |
|
| 159 | - $this->loader = LoaderFactory::getLoader(); |
|
| 160 | - } |
|
| 161 | - return $this->loader; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
| 167 | - * |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - protected function _before_page_setup() |
|
| 171 | - { |
|
| 172 | - $this->raw_req_action = $this->request->getRequestParam('action'); |
|
| 173 | - $this->raw_req_page = $this->request->getRequestParam('page'); |
|
| 174 | - $this->_cpt_routes = array_merge( |
|
| 175 | - [ |
|
| 176 | - 'create_new' => $this->page_slug, |
|
| 177 | - 'edit' => $this->page_slug, |
|
| 178 | - 'trash' => $this->page_slug, |
|
| 179 | - ], |
|
| 180 | - $this->_cpt_routes |
|
| 181 | - ); |
|
| 182 | - $cpt_route_action = $this->_cpt_routes[ $this->raw_req_action ] ?? null; |
|
| 183 | - // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page |
|
| 184 | - $page = $this->raw_req_page ?: $this->page_slug; |
|
| 185 | - $page = $cpt_route_action ?: $page; |
|
| 186 | - $this->_cpt_object = get_post_type_object($page); |
|
| 187 | - // tweak pagenow for page loading. |
|
| 188 | - if (empty($this->_pagenow_map)) { |
|
| 189 | - $this->_pagenow_map = [ |
|
| 190 | - 'create_new' => 'post-new.php', |
|
| 191 | - 'edit' => 'post.php', |
|
| 192 | - 'trash' => 'post.php', |
|
| 193 | - ]; |
|
| 194 | - } |
|
| 195 | - add_action('current_screen', [$this, 'modify_pagenow']); |
|
| 196 | - // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
| 197 | - // get current page from autosave |
|
| 198 | - $current_page = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]'); |
|
| 199 | - $this->_current_page = $this->request->getRequestParam('current_page', $current_page); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
| 205 | - * |
|
| 206 | - * @param WP_Screen|null $current_screen |
|
| 207 | - * @return void |
|
| 208 | - */ |
|
| 209 | - public function modify_pagenow(?WP_Screen $current_screen) |
|
| 210 | - { |
|
| 211 | - // possibly reset pagenow. |
|
| 212 | - if ( |
|
| 213 | - $this->page_slug === $this->raw_req_page |
|
| 214 | - && isset($this->_pagenow_map[ $this->raw_req_action ]) |
|
| 215 | - ) { |
|
| 216 | - global $pagenow, $hook_suffix; |
|
| 217 | - $pagenow = $this->_pagenow_map[ $this->raw_req_action ]; |
|
| 218 | - $hook_suffix = $pagenow; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
| 225 | - * |
|
| 226 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
| 227 | - * you would send along the id of a metabox container. |
|
| 228 | - * @return void |
|
| 229 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
| 230 | - * automatically register the id for the post metabox as a container. |
|
| 231 | - */ |
|
| 232 | - protected function _register_autosave_containers($ids) |
|
| 233 | - { |
|
| 234 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
| 240 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
| 241 | - */ |
|
| 242 | - protected function _set_autosave_containers() |
|
| 243 | - { |
|
| 244 | - global $wp_meta_boxes; |
|
| 245 | - $containers = []; |
|
| 246 | - if (empty($wp_meta_boxes)) { |
|
| 247 | - return; |
|
| 248 | - } |
|
| 249 | - $current_metaboxes = $wp_meta_boxes[ $this->page_slug ] ?? []; |
|
| 250 | - foreach ($current_metaboxes as $box_context) { |
|
| 251 | - foreach ($box_context as $box_details) { |
|
| 252 | - foreach ($box_details as $box) { |
|
| 253 | - if ( |
|
| 254 | - is_array($box) && is_array($box['callback']) |
|
| 255 | - && ( |
|
| 256 | - $box['callback'][0] instanceof EE_Admin_Page |
|
| 257 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
| 258 | - ) |
|
| 259 | - ) { |
|
| 260 | - $containers[] = $box['id']; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
| 266 | - // add hidden inputs container |
|
| 267 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - protected function _load_autosave_scripts_styles() |
|
| 272 | - { |
|
| 273 | - /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 34 | + /** |
|
| 35 | + * @var EE_CPT_Base|null |
|
| 36 | + */ |
|
| 37 | + protected $_cpt_model_obj; |
|
| 38 | + |
|
| 39 | + protected ?WP_Post_Type $_cpt_object = null; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
| 44 | + * //in this array we define what the custom post type for this route is. |
|
| 45 | + * array( |
|
| 46 | + * 'route_name' => 'custom_post_type_slug' |
|
| 47 | + * ) |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + protected array $_cpt_routes = []; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
| 56 | + * in this format: |
|
| 57 | + * array( |
|
| 58 | + * 'post_type_slug' => 'edit_route' |
|
| 59 | + * ) |
|
| 60 | + * |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + protected array $_cpt_edit_routes = []; |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
| 68 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
| 69 | + * _cpt_model_names property should be in the following format: array( |
|
| 70 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
| 71 | + * |
|
| 72 | + * @var array $_cpt_model_names |
|
| 73 | + */ |
|
| 74 | + protected array $_cpt_model_names = []; |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
| 79 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
| 80 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
| 81 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
| 82 | + * |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + protected array $_autosave_containers = []; |
|
| 86 | + |
|
| 87 | + protected array $_autosave_fields = []; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
| 91 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
| 92 | + * |
|
| 93 | + * @var array |
|
| 94 | + */ |
|
| 95 | + protected array $_pagenow_map= []; |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * This is the route that will be used for the edit post route. |
|
| 100 | + * |
|
| 101 | + * @var string |
|
| 102 | + */ |
|
| 103 | + protected string $cpt_editpost_route = 'edit'; |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 108 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 109 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
| 110 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
| 111 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
| 112 | + * |
|
| 113 | + * @abstract |
|
| 114 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 115 | + * @param WP_Post $post The post object of the cpt that was saved. |
|
| 116 | + * @return void |
|
| 117 | + */ |
|
| 118 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
| 123 | + * |
|
| 124 | + * @abstract |
|
| 125 | + * @param string $post_id The ID of the cpt that was trashed |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + abstract public function trash_cpt_item($post_id); |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
| 133 | + * |
|
| 134 | + * @param string $post_id theID of the cpt that was untrashed |
|
| 135 | + * @return void |
|
| 136 | + */ |
|
| 137 | + abstract public function restore_cpt_item($post_id); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
| 142 | + * from the db |
|
| 143 | + * |
|
| 144 | + * @param string $post_id the ID of the cpt that was deleted |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + abstract public function delete_cpt_item($post_id); |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @return LoaderInterface |
|
| 152 | + * @throws InvalidArgumentException |
|
| 153 | + * @throws InvalidDataTypeException |
|
| 154 | + * @throws InvalidInterfaceException |
|
| 155 | + */ |
|
| 156 | + protected function getLoader(): LoaderInterface |
|
| 157 | + { |
|
| 158 | + if (! $this->loader instanceof LoaderInterface) { |
|
| 159 | + $this->loader = LoaderFactory::getLoader(); |
|
| 160 | + } |
|
| 161 | + return $this->loader; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
| 167 | + * |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + protected function _before_page_setup() |
|
| 171 | + { |
|
| 172 | + $this->raw_req_action = $this->request->getRequestParam('action'); |
|
| 173 | + $this->raw_req_page = $this->request->getRequestParam('page'); |
|
| 174 | + $this->_cpt_routes = array_merge( |
|
| 175 | + [ |
|
| 176 | + 'create_new' => $this->page_slug, |
|
| 177 | + 'edit' => $this->page_slug, |
|
| 178 | + 'trash' => $this->page_slug, |
|
| 179 | + ], |
|
| 180 | + $this->_cpt_routes |
|
| 181 | + ); |
|
| 182 | + $cpt_route_action = $this->_cpt_routes[ $this->raw_req_action ] ?? null; |
|
| 183 | + // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page |
|
| 184 | + $page = $this->raw_req_page ?: $this->page_slug; |
|
| 185 | + $page = $cpt_route_action ?: $page; |
|
| 186 | + $this->_cpt_object = get_post_type_object($page); |
|
| 187 | + // tweak pagenow for page loading. |
|
| 188 | + if (empty($this->_pagenow_map)) { |
|
| 189 | + $this->_pagenow_map = [ |
|
| 190 | + 'create_new' => 'post-new.php', |
|
| 191 | + 'edit' => 'post.php', |
|
| 192 | + 'trash' => 'post.php', |
|
| 193 | + ]; |
|
| 194 | + } |
|
| 195 | + add_action('current_screen', [$this, 'modify_pagenow']); |
|
| 196 | + // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
| 197 | + // get current page from autosave |
|
| 198 | + $current_page = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]'); |
|
| 199 | + $this->_current_page = $this->request->getRequestParam('current_page', $current_page); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
| 205 | + * |
|
| 206 | + * @param WP_Screen|null $current_screen |
|
| 207 | + * @return void |
|
| 208 | + */ |
|
| 209 | + public function modify_pagenow(?WP_Screen $current_screen) |
|
| 210 | + { |
|
| 211 | + // possibly reset pagenow. |
|
| 212 | + if ( |
|
| 213 | + $this->page_slug === $this->raw_req_page |
|
| 214 | + && isset($this->_pagenow_map[ $this->raw_req_action ]) |
|
| 215 | + ) { |
|
| 216 | + global $pagenow, $hook_suffix; |
|
| 217 | + $pagenow = $this->_pagenow_map[ $this->raw_req_action ]; |
|
| 218 | + $hook_suffix = $pagenow; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
| 225 | + * |
|
| 226 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
| 227 | + * you would send along the id of a metabox container. |
|
| 228 | + * @return void |
|
| 229 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
| 230 | + * automatically register the id for the post metabox as a container. |
|
| 231 | + */ |
|
| 232 | + protected function _register_autosave_containers($ids) |
|
| 233 | + { |
|
| 234 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
| 240 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
| 241 | + */ |
|
| 242 | + protected function _set_autosave_containers() |
|
| 243 | + { |
|
| 244 | + global $wp_meta_boxes; |
|
| 245 | + $containers = []; |
|
| 246 | + if (empty($wp_meta_boxes)) { |
|
| 247 | + return; |
|
| 248 | + } |
|
| 249 | + $current_metaboxes = $wp_meta_boxes[ $this->page_slug ] ?? []; |
|
| 250 | + foreach ($current_metaboxes as $box_context) { |
|
| 251 | + foreach ($box_context as $box_details) { |
|
| 252 | + foreach ($box_details as $box) { |
|
| 253 | + if ( |
|
| 254 | + is_array($box) && is_array($box['callback']) |
|
| 255 | + && ( |
|
| 256 | + $box['callback'][0] instanceof EE_Admin_Page |
|
| 257 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
| 258 | + ) |
|
| 259 | + ) { |
|
| 260 | + $containers[] = $box['id']; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
| 266 | + // add hidden inputs container |
|
| 267 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + protected function _load_autosave_scripts_styles() |
|
| 272 | + { |
|
| 273 | + /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 274 | 274 | wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2 |
| 275 | 275 | |
| 276 | - // filter _autosave_containers |
|
| 277 | - $containers = apply_filters( |
|
| 278 | - 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
| 279 | - $this->_autosave_containers, |
|
| 280 | - $this |
|
| 281 | - ); |
|
| 282 | - $containers = apply_filters( |
|
| 283 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 284 | - $containers, |
|
| 285 | - $this |
|
| 286 | - ); |
|
| 287 | - |
|
| 288 | - wp_localize_script( |
|
| 289 | - 'event_editor_js', |
|
| 290 | - 'EE_AUTOSAVE_IDS', |
|
| 291 | - $containers |
|
| 292 | - ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
| 293 | - |
|
| 294 | - $unsaved_data_msg = [ |
|
| 295 | - 'eventmsg' => sprintf( |
|
| 296 | - wp_strip_all_tags( |
|
| 297 | - __( |
|
| 298 | - "The changes you made to this %s will be lost if you navigate away from this page.", |
|
| 299 | - 'event_espresso' |
|
| 300 | - ) |
|
| 301 | - ), |
|
| 302 | - $this->_cpt_object->labels->singular_name |
|
| 303 | - ), |
|
| 304 | - 'inputChanged' => 0, |
|
| 305 | - ]; |
|
| 306 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
| 312 | - * |
|
| 313 | - * @return void |
|
| 314 | - * @throws EE_Error |
|
| 315 | - * @throws ReflectionException |
|
| 316 | - * @throws Throwable |
|
| 317 | - */ |
|
| 318 | - protected function _load_page_dependencies() |
|
| 319 | - { |
|
| 320 | - // we only add stuff if this is a cpt_route! |
|
| 321 | - if (! $this->_cpt_route) { |
|
| 322 | - parent::_load_page_dependencies(); |
|
| 323 | - return; |
|
| 324 | - } |
|
| 325 | - // now let's do some automatic filters into the wp_system |
|
| 326 | - // and we'll check to make sure the CHILD class |
|
| 327 | - // automatically has the required methods in place. |
|
| 328 | - // the following filters are for setting all the redirects |
|
| 329 | - // on DEFAULT WP custom post type actions |
|
| 330 | - // let's add a hidden input to the post-edit form |
|
| 331 | - // so we know when we have to trigger our custom redirects! |
|
| 332 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
| 333 | - add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']); |
|
| 334 | - // inject our Admin page nav tabs... |
|
| 335 | - // let's make sure the nav tabs are set if they aren't already |
|
| 336 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
| 337 | - add_action('edit_form_top', [$this, 'inject_nav_tabs']); |
|
| 338 | - // modify the post_updated messages array |
|
| 339 | - add_action('post_updated_messages', [$this, 'post_update_messages']); |
|
| 340 | - // This basically allows us to change the title of the "publish" metabox area |
|
| 341 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
| 342 | - $screen = $this->_cpt_routes[ $this->_req_action ]; |
|
| 343 | - if (! empty($this->_labels['publishbox'])) { |
|
| 344 | - $this->addMetaBox( |
|
| 345 | - 'submitdiv', |
|
| 346 | - $this->getPublishBoxTitle(), |
|
| 347 | - 'post_submit_meta_box', |
|
| 348 | - $screen, |
|
| 349 | - 'side', |
|
| 350 | - 'core' |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - // let's add page_templates metabox if this cpt added support for it. |
|
| 354 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
| 355 | - $this->addMetaBox( |
|
| 356 | - 'page_templates', |
|
| 357 | - esc_html__('Page Template', 'event_espresso'), |
|
| 358 | - [$this, 'page_template_meta_box'], |
|
| 359 | - $screen, |
|
| 360 | - 'side' |
|
| 361 | - ); |
|
| 362 | - } |
|
| 363 | - // add preview button |
|
| 364 | - // add_filter('get_sample_permalink_html', [PreviewButton::class, 'addButton'], 5, 2); |
|
| 365 | - PreviewButton::addEventEditorPermalinkButton(5); |
|
| 366 | - // add shortlink button to cpt edit screens. |
|
| 367 | - // We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts! |
|
| 368 | - // add_filter('get_sample_permalink_html', [EventShortlinkButton::class, 'addButton'], 10, 2); |
|
| 369 | - EventShortlinkButton::addEventEditorPermalinkButton(); |
|
| 370 | - // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 371 | - // add_filter('get_sample_permalink_html', [TicketSelectorShortcodeButton::class, 'addButton'], 12, 2); |
|
| 372 | - TicketSelectorShortcodeButton::addEventEditorPermalinkButton(12); |
|
| 373 | - // insert our own post_stati dropdown |
|
| 374 | - add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown']); |
|
| 375 | - // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
| 376 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
| 377 | - add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box']); |
|
| 378 | - } |
|
| 379 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
| 380 | - // This is also before the wp_editor for post description field. |
|
| 381 | - if (method_exists($this, 'edit_form_after_title')) { |
|
| 382 | - add_action('edit_form_after_title', [$this, 'edit_form_after_title']); |
|
| 383 | - } |
|
| 384 | - /** |
|
| 385 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
| 386 | - */ |
|
| 387 | - add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours']); |
|
| 388 | - parent::_load_page_dependencies(); |
|
| 389 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
| 390 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
| 391 | - // This is for any plugins that are doing things properly |
|
| 392 | - // and hooking into the load page hook for core wp cpt routes. |
|
| 393 | - global $pagenow; |
|
| 394 | - add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20); |
|
| 395 | - do_action('load-' . $pagenow); |
|
| 396 | - add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30); |
|
| 397 | - // we route REALLY early. |
|
| 398 | - try { |
|
| 399 | - $this->_route_admin_request(); |
|
| 400 | - } catch (EE_Error $e) { |
|
| 401 | - $e->get_error(); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
| 408 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
| 409 | - * route instead. |
|
| 410 | - * |
|
| 411 | - * @param string $good_protocol_url The escaped url. |
|
| 412 | - * @return string possibly a new url for our route. |
|
| 413 | - */ |
|
| 414 | - public function switch_core_wp_urls_with_ours(string $good_protocol_url): string |
|
| 415 | - { |
|
| 416 | - $routes_to_match = [ |
|
| 417 | - 0 => [ |
|
| 418 | - 'edit.php?post_type=espresso_attendees', |
|
| 419 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
| 420 | - ], |
|
| 421 | - 1 => [ |
|
| 422 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 423 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
| 424 | - ], |
|
| 425 | - ]; |
|
| 426 | - foreach ($routes_to_match as $route_matches) { |
|
| 427 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
| 428 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - return $good_protocol_url; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Determine whether the current cpt supports page templates or not. |
|
| 437 | - * |
|
| 438 | - * @param string $cpt_name The cpt slug we're checking on. |
|
| 439 | - * @return bool True supported, false not. |
|
| 440 | - * @throws InvalidArgumentException |
|
| 441 | - * @throws InvalidDataTypeException |
|
| 442 | - * @throws InvalidInterfaceException |
|
| 443 | - * @since %VER% |
|
| 444 | - */ |
|
| 445 | - private function _supports_page_templates(string $cpt_name): bool |
|
| 446 | - { |
|
| 447 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 448 | - $custom_post_types = $this->loader->getShared( |
|
| 449 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 450 | - ); |
|
| 451 | - $cpt_args = $custom_post_types->getDefinitions(); |
|
| 452 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : []; |
|
| 453 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
| 454 | - |
|
| 455 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
| 456 | - // if there are $post_templates for this cpt, then we return false for this method because |
|
| 457 | - // that means we aren't going to load our page template manager and leave that up to the native |
|
| 458 | - // cpt template manager. |
|
| 459 | - return ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Callback for the page_templates metabox selector. |
|
| 465 | - * |
|
| 466 | - * @return void |
|
| 467 | - * @since %VER% |
|
| 468 | - */ |
|
| 469 | - public function page_template_meta_box() |
|
| 470 | - { |
|
| 471 | - global $post; |
|
| 472 | - $template = ''; |
|
| 473 | - |
|
| 474 | - $page_template_count = count(get_page_templates()); |
|
| 475 | - if ($page_template_count) { |
|
| 476 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
| 477 | - $template = ! empty($page_template) ? $page_template : ''; |
|
| 478 | - } |
|
| 479 | - ?> |
|
| 276 | + // filter _autosave_containers |
|
| 277 | + $containers = apply_filters( |
|
| 278 | + 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
| 279 | + $this->_autosave_containers, |
|
| 280 | + $this |
|
| 281 | + ); |
|
| 282 | + $containers = apply_filters( |
|
| 283 | + 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 284 | + $containers, |
|
| 285 | + $this |
|
| 286 | + ); |
|
| 287 | + |
|
| 288 | + wp_localize_script( |
|
| 289 | + 'event_editor_js', |
|
| 290 | + 'EE_AUTOSAVE_IDS', |
|
| 291 | + $containers |
|
| 292 | + ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
| 293 | + |
|
| 294 | + $unsaved_data_msg = [ |
|
| 295 | + 'eventmsg' => sprintf( |
|
| 296 | + wp_strip_all_tags( |
|
| 297 | + __( |
|
| 298 | + "The changes you made to this %s will be lost if you navigate away from this page.", |
|
| 299 | + 'event_espresso' |
|
| 300 | + ) |
|
| 301 | + ), |
|
| 302 | + $this->_cpt_object->labels->singular_name |
|
| 303 | + ), |
|
| 304 | + 'inputChanged' => 0, |
|
| 305 | + ]; |
|
| 306 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
| 312 | + * |
|
| 313 | + * @return void |
|
| 314 | + * @throws EE_Error |
|
| 315 | + * @throws ReflectionException |
|
| 316 | + * @throws Throwable |
|
| 317 | + */ |
|
| 318 | + protected function _load_page_dependencies() |
|
| 319 | + { |
|
| 320 | + // we only add stuff if this is a cpt_route! |
|
| 321 | + if (! $this->_cpt_route) { |
|
| 322 | + parent::_load_page_dependencies(); |
|
| 323 | + return; |
|
| 324 | + } |
|
| 325 | + // now let's do some automatic filters into the wp_system |
|
| 326 | + // and we'll check to make sure the CHILD class |
|
| 327 | + // automatically has the required methods in place. |
|
| 328 | + // the following filters are for setting all the redirects |
|
| 329 | + // on DEFAULT WP custom post type actions |
|
| 330 | + // let's add a hidden input to the post-edit form |
|
| 331 | + // so we know when we have to trigger our custom redirects! |
|
| 332 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
| 333 | + add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']); |
|
| 334 | + // inject our Admin page nav tabs... |
|
| 335 | + // let's make sure the nav tabs are set if they aren't already |
|
| 336 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
| 337 | + add_action('edit_form_top', [$this, 'inject_nav_tabs']); |
|
| 338 | + // modify the post_updated messages array |
|
| 339 | + add_action('post_updated_messages', [$this, 'post_update_messages']); |
|
| 340 | + // This basically allows us to change the title of the "publish" metabox area |
|
| 341 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
| 342 | + $screen = $this->_cpt_routes[ $this->_req_action ]; |
|
| 343 | + if (! empty($this->_labels['publishbox'])) { |
|
| 344 | + $this->addMetaBox( |
|
| 345 | + 'submitdiv', |
|
| 346 | + $this->getPublishBoxTitle(), |
|
| 347 | + 'post_submit_meta_box', |
|
| 348 | + $screen, |
|
| 349 | + 'side', |
|
| 350 | + 'core' |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + // let's add page_templates metabox if this cpt added support for it. |
|
| 354 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
| 355 | + $this->addMetaBox( |
|
| 356 | + 'page_templates', |
|
| 357 | + esc_html__('Page Template', 'event_espresso'), |
|
| 358 | + [$this, 'page_template_meta_box'], |
|
| 359 | + $screen, |
|
| 360 | + 'side' |
|
| 361 | + ); |
|
| 362 | + } |
|
| 363 | + // add preview button |
|
| 364 | + // add_filter('get_sample_permalink_html', [PreviewButton::class, 'addButton'], 5, 2); |
|
| 365 | + PreviewButton::addEventEditorPermalinkButton(5); |
|
| 366 | + // add shortlink button to cpt edit screens. |
|
| 367 | + // We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts! |
|
| 368 | + // add_filter('get_sample_permalink_html', [EventShortlinkButton::class, 'addButton'], 10, 2); |
|
| 369 | + EventShortlinkButton::addEventEditorPermalinkButton(); |
|
| 370 | + // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 371 | + // add_filter('get_sample_permalink_html', [TicketSelectorShortcodeButton::class, 'addButton'], 12, 2); |
|
| 372 | + TicketSelectorShortcodeButton::addEventEditorPermalinkButton(12); |
|
| 373 | + // insert our own post_stati dropdown |
|
| 374 | + add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown']); |
|
| 375 | + // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
| 376 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
| 377 | + add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box']); |
|
| 378 | + } |
|
| 379 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
| 380 | + // This is also before the wp_editor for post description field. |
|
| 381 | + if (method_exists($this, 'edit_form_after_title')) { |
|
| 382 | + add_action('edit_form_after_title', [$this, 'edit_form_after_title']); |
|
| 383 | + } |
|
| 384 | + /** |
|
| 385 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
| 386 | + */ |
|
| 387 | + add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours']); |
|
| 388 | + parent::_load_page_dependencies(); |
|
| 389 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
| 390 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
| 391 | + // This is for any plugins that are doing things properly |
|
| 392 | + // and hooking into the load page hook for core wp cpt routes. |
|
| 393 | + global $pagenow; |
|
| 394 | + add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20); |
|
| 395 | + do_action('load-' . $pagenow); |
|
| 396 | + add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30); |
|
| 397 | + // we route REALLY early. |
|
| 398 | + try { |
|
| 399 | + $this->_route_admin_request(); |
|
| 400 | + } catch (EE_Error $e) { |
|
| 401 | + $e->get_error(); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
| 408 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
| 409 | + * route instead. |
|
| 410 | + * |
|
| 411 | + * @param string $good_protocol_url The escaped url. |
|
| 412 | + * @return string possibly a new url for our route. |
|
| 413 | + */ |
|
| 414 | + public function switch_core_wp_urls_with_ours(string $good_protocol_url): string |
|
| 415 | + { |
|
| 416 | + $routes_to_match = [ |
|
| 417 | + 0 => [ |
|
| 418 | + 'edit.php?post_type=espresso_attendees', |
|
| 419 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
| 420 | + ], |
|
| 421 | + 1 => [ |
|
| 422 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 423 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
| 424 | + ], |
|
| 425 | + ]; |
|
| 426 | + foreach ($routes_to_match as $route_matches) { |
|
| 427 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
| 428 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + return $good_protocol_url; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Determine whether the current cpt supports page templates or not. |
|
| 437 | + * |
|
| 438 | + * @param string $cpt_name The cpt slug we're checking on. |
|
| 439 | + * @return bool True supported, false not. |
|
| 440 | + * @throws InvalidArgumentException |
|
| 441 | + * @throws InvalidDataTypeException |
|
| 442 | + * @throws InvalidInterfaceException |
|
| 443 | + * @since %VER% |
|
| 444 | + */ |
|
| 445 | + private function _supports_page_templates(string $cpt_name): bool |
|
| 446 | + { |
|
| 447 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 448 | + $custom_post_types = $this->loader->getShared( |
|
| 449 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 450 | + ); |
|
| 451 | + $cpt_args = $custom_post_types->getDefinitions(); |
|
| 452 | + $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : []; |
|
| 453 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
| 454 | + |
|
| 455 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
| 456 | + // if there are $post_templates for this cpt, then we return false for this method because |
|
| 457 | + // that means we aren't going to load our page template manager and leave that up to the native |
|
| 458 | + // cpt template manager. |
|
| 459 | + return ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Callback for the page_templates metabox selector. |
|
| 465 | + * |
|
| 466 | + * @return void |
|
| 467 | + * @since %VER% |
|
| 468 | + */ |
|
| 469 | + public function page_template_meta_box() |
|
| 470 | + { |
|
| 471 | + global $post; |
|
| 472 | + $template = ''; |
|
| 473 | + |
|
| 474 | + $page_template_count = count(get_page_templates()); |
|
| 475 | + if ($page_template_count) { |
|
| 476 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
| 477 | + $template = ! empty($page_template) ? $page_template : ''; |
|
| 478 | + } |
|
| 479 | + ?> |
|
| 480 | 480 | <p><strong><?php esc_html_e('Template', 'event_espresso') ?></strong></p> |
| 481 | 481 | <label class="screen-reader-text" for="page_template"> |
| 482 | 482 | <?php esc_html_e('Page Template', 'event_espresso') ?> |
@@ -486,457 +486,457 @@ discard block |
||
| 486 | 486 | <?php page_template_dropdown($template); ?> |
| 487 | 487 | </select> |
| 488 | 488 | <?php |
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
| 494 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 495 | - * |
|
| 496 | - * @param string $return the current html |
|
| 497 | - * @param int $id the post id for the page |
|
| 498 | - * @return string The new html string for the permalink area |
|
| 499 | - * @deprecated 5.0.0.p |
|
| 500 | - * @see PreviewButton::addButton() |
|
| 501 | - */ |
|
| 502 | - public function preview_button_html(string $return, int $id): string |
|
| 503 | - { |
|
| 504 | - return PreviewButton::addButton($return, $id); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * add our custom post status dropdown on the wp post page for this cpt |
|
| 510 | - * |
|
| 511 | - * @return void |
|
| 512 | - */ |
|
| 513 | - public function custom_post_stati_dropdown() |
|
| 514 | - { |
|
| 515 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 516 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
| 517 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
| 518 | - : ''; |
|
| 519 | - $template_args = [ |
|
| 520 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
| 521 | - 'statuses' => $statuses, |
|
| 522 | - 'cur_status_label' => $cur_status_label, |
|
| 523 | - 'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label), |
|
| 524 | - ]; |
|
| 525 | - // we'll add a trash post status (WP doesn't add one for some reason) |
|
| 526 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
| 527 | - $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso'); |
|
| 528 | - $statuses['trash'] = esc_html__('Trashed', 'event_espresso'); |
|
| 529 | - $template_args['statuses'] = $statuses; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 533 | - EEH_Template::display_template($template, $template_args); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - public function setup_autosave_hooks() |
|
| 538 | - { |
|
| 539 | - $this->_set_autosave_containers(); |
|
| 540 | - $this->_load_autosave_scripts_styles(); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available |
|
| 546 | - * in request data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
| 547 | - * for the nonce in here, but then this method looks for two things: |
|
| 548 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
| 549 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
| 550 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
| 551 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
| 552 | - * template args. |
|
| 553 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
| 554 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
| 555 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
| 556 | - * $this->_template_args['data']['items'] = array( |
|
| 557 | - * 'event-datetime-ids' => '1,2,3'; |
|
| 558 | - * ); |
|
| 559 | - * Keep in mind the following things: |
|
| 560 | - * - "where" index is for the input with the id as that string. |
|
| 561 | - * - "what" index is what will be used for the value of that input. |
|
| 562 | - * |
|
| 563 | - * @return void |
|
| 564 | - * @throws EE_Error |
|
| 565 | - */ |
|
| 566 | - public function do_extra_autosave_stuff() |
|
| 567 | - { |
|
| 568 | - // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
| 569 | - $nonce = $this->request->getRequestParam('autosavenonce'); |
|
| 570 | - $this->_verify_nonce($nonce, 'autosave'); |
|
| 571 | - // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
| 572 | - if (! defined('DOING_AUTOSAVE')) { |
|
| 573 | - define('DOING_AUTOSAVE', true); |
|
| 574 | - } |
|
| 575 | - // if we made it here then the nonce checked out. Let's run our methods and actions |
|
| 576 | - $autosave = "_ee_autosave_$this->_current_view"; |
|
| 577 | - if (method_exists($this, $autosave)) { |
|
| 578 | - $this->$autosave(); |
|
| 579 | - } else { |
|
| 580 | - $this->_template_args['success'] = true; |
|
| 581 | - } |
|
| 582 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
| 583 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 584 | - // now let's return json |
|
| 585 | - $this->_return_json(); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
| 591 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
| 592 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
| 593 | - * |
|
| 594 | - * @return void |
|
| 595 | - * @throws EE_Error |
|
| 596 | - * @throws ReflectionException |
|
| 597 | - */ |
|
| 598 | - protected function _extend_page_config_for_cpt() |
|
| 599 | - { |
|
| 600 | - // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
| 601 | - if ($this->raw_req_page !== $this->page_slug) { |
|
| 602 | - return; |
|
| 603 | - } |
|
| 604 | - // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
| 605 | - if (! empty($this->_cpt_object)) { |
|
| 606 | - $this->_page_routes = array_merge( |
|
| 607 | - [ |
|
| 608 | - 'create_new' => [$this, '_create_new_cpt_item'], |
|
| 609 | - 'edit' => [$this, '_edit_cpt_item'], |
|
| 610 | - ], |
|
| 611 | - $this->_page_routes |
|
| 612 | - ); |
|
| 613 | - $this->_page_config = array_merge( |
|
| 614 | - [ |
|
| 615 | - 'create_new' => [ |
|
| 616 | - 'nav' => [ |
|
| 617 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
| 618 | - 'order' => 5, |
|
| 619 | - ], |
|
| 620 | - 'require_nonce' => false, |
|
| 621 | - ], |
|
| 622 | - 'edit' => [ |
|
| 623 | - 'nav' => [ |
|
| 624 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
| 625 | - 'order' => 5, |
|
| 626 | - 'persistent' => false, |
|
| 627 | - 'url' => '', |
|
| 628 | - ], |
|
| 629 | - 'require_nonce' => false, |
|
| 630 | - ], |
|
| 631 | - ], |
|
| 632 | - $this->_page_config |
|
| 633 | - ); |
|
| 634 | - } |
|
| 635 | - // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
| 636 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
| 637 | - return; |
|
| 638 | - } |
|
| 639 | - $this->_cpt_route = true; |
|
| 640 | - // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]); |
|
| 641 | - // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
| 642 | - if (empty($this->_cpt_object)) { |
|
| 643 | - $msg = sprintf( |
|
| 644 | - esc_html__( |
|
| 645 | - 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
| 646 | - 'event_espresso' |
|
| 647 | - ), |
|
| 648 | - $this->page_slug, |
|
| 649 | - $this->_req_action, |
|
| 650 | - get_class($this) |
|
| 651 | - ); |
|
| 652 | - throw new EE_Error($msg); |
|
| 653 | - } |
|
| 654 | - $this->_set_model_object($this->request->getRequestParam('post', 0, DataType::INT)); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
| 660 | - * |
|
| 661 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
| 662 | - * @param bool $ignore_route_check |
|
| 663 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
| 664 | - * @throws EE_Error |
|
| 665 | - * @throws InvalidArgumentException |
|
| 666 | - * @throws InvalidDataTypeException |
|
| 667 | - * @throws InvalidInterfaceException |
|
| 668 | - * @throws ReflectionException |
|
| 669 | - */ |
|
| 670 | - protected function _set_model_object(int $id = 0, bool $ignore_route_check = false, string $req_type = '') |
|
| 671 | - { |
|
| 672 | - $model = null; |
|
| 673 | - if ( |
|
| 674 | - empty($this->_cpt_model_names) |
|
| 675 | - || ( |
|
| 676 | - ! $ignore_route_check |
|
| 677 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
| 678 | - ) |
|
| 679 | - || ( |
|
| 680 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 681 | - && $this->_cpt_model_obj->ID() === $id |
|
| 682 | - ) |
|
| 683 | - ) { |
|
| 684 | - // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
| 685 | - return; |
|
| 686 | - } |
|
| 687 | - // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
| 688 | - if ($ignore_route_check) { |
|
| 689 | - $post_type = get_post_type($id); |
|
| 690 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 691 | - $custom_post_types = $this->loader->getShared( |
|
| 692 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 693 | - ); |
|
| 694 | - $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
| 695 | - if (isset($model_names[ $post_type ])) { |
|
| 696 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
| 697 | - } |
|
| 698 | - } else { |
|
| 699 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
| 700 | - } |
|
| 701 | - if ($model instanceof EEM_Base) { |
|
| 702 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
| 703 | - } |
|
| 704 | - do_action( |
|
| 705 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 706 | - $this->_cpt_model_obj, |
|
| 707 | - $req_type |
|
| 708 | - ); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * admin_init_global |
|
| 714 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 715 | - * This method executes for ALL EE Admin pages. |
|
| 716 | - * |
|
| 717 | - * @return void |
|
| 718 | - */ |
|
| 719 | - public function admin_init_global() |
|
| 720 | - { |
|
| 721 | - $post_ID = $this->request->getRequestParam('post', 0, DataType::INT); |
|
| 722 | - // its possible this is a new save so let's catch that instead |
|
| 723 | - $post_ID = $this->request->getRequestParam('post_ID', $post_ID, DataType::INT); |
|
| 724 | - $post = get_post($post_ID); |
|
| 725 | - $post_type = $post instanceof WP_Post ? $post->post_type : false; |
|
| 726 | - $current_route = $this->request->getRequestParam('current_route', 'shouldneverwork'); |
|
| 727 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
| 728 | - ? $this->_cpt_routes[ $current_route ] |
|
| 729 | - : ''; |
|
| 730 | - add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 2); |
|
| 731 | - add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2); |
|
| 732 | - if ($post_type === $route_to_check) { |
|
| 733 | - add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2); |
|
| 734 | - } |
|
| 735 | - // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
| 736 | - $revision = $this->request->getRequestParam('revision'); |
|
| 737 | - if (! empty($revision)) { |
|
| 738 | - $action = $this->request->getRequestParam('action'); |
|
| 739 | - // doing a restore? |
|
| 740 | - if (! empty($action) && $action === 'restore') { |
|
| 741 | - // get post for revision |
|
| 742 | - $rev_post = get_post($revision); |
|
| 743 | - $rev_parent = get_post($rev_post->post_parent); |
|
| 744 | - // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
| 745 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
| 746 | - add_filter('wp_redirect', [$this, 'revision_redirect']); |
|
| 747 | - // restores of revisions |
|
| 748 | - add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2); |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - } |
|
| 752 | - // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
| 753 | - if ($post_type && $post_type === $route_to_check) { |
|
| 754 | - // $post_id, $post |
|
| 755 | - add_action('save_post', [$this, 'insert_update'], 10, 3); |
|
| 756 | - // $post_id |
|
| 757 | - add_action('trashed_post', [$this, 'before_trash_cpt_item']); |
|
| 758 | - add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts']); |
|
| 759 | - add_action('untrashed_post', [$this, 'before_restore_cpt_item']); |
|
| 760 | - add_action('after_delete_post', [$this, 'before_delete_cpt_item']); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Callback for the WordPress trashed_post hook. |
|
| 767 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
| 768 | - * |
|
| 769 | - * @param int $post_id |
|
| 770 | - * @throws EE_Error |
|
| 771 | - * @throws ReflectionException |
|
| 772 | - */ |
|
| 773 | - public function before_trash_cpt_item(int $post_id) |
|
| 774 | - { |
|
| 775 | - $this->_set_model_object($post_id, true, 'trash'); |
|
| 776 | - // if our cpt object isn't existent then get out immediately. |
|
| 777 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 778 | - return; |
|
| 779 | - } |
|
| 780 | - $this->trash_cpt_item($post_id); |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * Callback for the WordPress untrashed_post hook. |
|
| 786 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
| 787 | - * |
|
| 788 | - * @param $post_id |
|
| 789 | - * @throws EE_Error |
|
| 790 | - * @throws ReflectionException |
|
| 791 | - */ |
|
| 792 | - public function before_restore_cpt_item($post_id) |
|
| 793 | - { |
|
| 794 | - $this->_set_model_object($post_id, true, 'restore'); |
|
| 795 | - // if our cpt object isn't existent then get out immediately. |
|
| 796 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 797 | - return; |
|
| 798 | - } |
|
| 799 | - $this->restore_cpt_item($post_id); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * Callback for the WordPress after_delete_post hook. |
|
| 805 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
| 806 | - * |
|
| 807 | - * @param $post_id |
|
| 808 | - * @throws EE_Error |
|
| 809 | - * @throws ReflectionException |
|
| 810 | - */ |
|
| 811 | - public function before_delete_cpt_item($post_id) |
|
| 812 | - { |
|
| 813 | - $this->_set_model_object($post_id, true, 'delete'); |
|
| 814 | - // if our cpt object isn't existent then get out immediately. |
|
| 815 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 816 | - return; |
|
| 817 | - } |
|
| 818 | - $this->delete_cpt_item($post_id); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
| 824 | - * accordingly. |
|
| 825 | - * |
|
| 826 | - * @return void |
|
| 827 | - * @throws EE_Error |
|
| 828 | - * @throws ReflectionException |
|
| 829 | - */ |
|
| 830 | - public function verify_cpt_object() |
|
| 831 | - { |
|
| 832 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
| 833 | - // verify event object |
|
| 834 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 835 | - throw new EE_Error( |
|
| 836 | - sprintf( |
|
| 837 | - esc_html__( |
|
| 838 | - 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
| 839 | - 'event_espresso' |
|
| 840 | - ), |
|
| 841 | - $label |
|
| 842 | - ) |
|
| 843 | - ); |
|
| 844 | - } |
|
| 845 | - // if auto-draft then throw an error |
|
| 846 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
| 847 | - EE_Error::overwrite_errors(); |
|
| 848 | - EE_Error::add_error( |
|
| 849 | - sprintf( |
|
| 850 | - esc_html__( |
|
| 851 | - 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
| 852 | - 'event_espresso' |
|
| 853 | - ), |
|
| 854 | - $label |
|
| 855 | - ), |
|
| 856 | - __FILE__, |
|
| 857 | - __FUNCTION__, |
|
| 858 | - __LINE__ |
|
| 859 | - ); |
|
| 860 | - } |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - |
|
| 864 | - /** |
|
| 865 | - * admin_footer_scripts_global |
|
| 866 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 867 | - * will apply on ALL EE_Admin pages. |
|
| 868 | - * |
|
| 869 | - * @return void |
|
| 870 | - */ |
|
| 871 | - public function admin_footer_scripts_global() |
|
| 872 | - { |
|
| 873 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 874 | - $this->_add_admin_page_overlay(); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * add in any global scripts for cpt routes |
|
| 880 | - * |
|
| 881 | - * @return void |
|
| 882 | - */ |
|
| 883 | - public function load_global_scripts_styles() |
|
| 884 | - { |
|
| 885 | - parent::load_global_scripts_styles(); |
|
| 886 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 887 | - // setup custom post status object for localize script but only if we've got a cpt object |
|
| 888 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 889 | - if (! empty($statuses)) { |
|
| 890 | - // get ALL statuses! |
|
| 891 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
| 892 | - // setup object |
|
| 893 | - $ee_cpt_statuses = []; |
|
| 894 | - foreach ($statuses as $status => $label) { |
|
| 895 | - $ee_cpt_statuses[ $status ] = [ |
|
| 896 | - 'label' => $label, |
|
| 897 | - 'save_label' => sprintf( |
|
| 898 | - wp_strip_all_tags(__('Save as %s', 'event_espresso')), |
|
| 899 | - $label |
|
| 900 | - ), |
|
| 901 | - ]; |
|
| 902 | - } |
|
| 903 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
| 911 | - * insert/updates |
|
| 912 | - * |
|
| 913 | - * @param int $post_id ID of post being updated |
|
| 914 | - * @param WP_Post $post Post object from WP |
|
| 915 | - * @param bool $update Whether this is an update or a new save. |
|
| 916 | - * @return void |
|
| 917 | - * @throws EE_Error |
|
| 918 | - * @throws ReflectionException |
|
| 919 | - */ |
|
| 920 | - public function insert_update(int $post_id, WP_Post $post, bool $update) |
|
| 921 | - { |
|
| 922 | - // make sure that if this is a revision OR trash action that we don't do any updates! |
|
| 923 | - $action = $this->request->getRequestParam('action'); |
|
| 924 | - if ($action === 'restore' || $action === 'trash') { |
|
| 925 | - return; |
|
| 926 | - } |
|
| 927 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
| 928 | - // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
| 929 | - if ( |
|
| 930 | - $update |
|
| 931 | - && ( |
|
| 932 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 933 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
| 934 | - ) |
|
| 935 | - ) { |
|
| 936 | - return; |
|
| 937 | - } |
|
| 938 | - // check for autosave and update our req_data property accordingly. |
|
| 939 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
| 494 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 495 | + * |
|
| 496 | + * @param string $return the current html |
|
| 497 | + * @param int $id the post id for the page |
|
| 498 | + * @return string The new html string for the permalink area |
|
| 499 | + * @deprecated 5.0.0.p |
|
| 500 | + * @see PreviewButton::addButton() |
|
| 501 | + */ |
|
| 502 | + public function preview_button_html(string $return, int $id): string |
|
| 503 | + { |
|
| 504 | + return PreviewButton::addButton($return, $id); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * add our custom post status dropdown on the wp post page for this cpt |
|
| 510 | + * |
|
| 511 | + * @return void |
|
| 512 | + */ |
|
| 513 | + public function custom_post_stati_dropdown() |
|
| 514 | + { |
|
| 515 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 516 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
| 517 | + ? $statuses[ $this->_cpt_model_obj->status() ] |
|
| 518 | + : ''; |
|
| 519 | + $template_args = [ |
|
| 520 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
| 521 | + 'statuses' => $statuses, |
|
| 522 | + 'cur_status_label' => $cur_status_label, |
|
| 523 | + 'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label), |
|
| 524 | + ]; |
|
| 525 | + // we'll add a trash post status (WP doesn't add one for some reason) |
|
| 526 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
| 527 | + $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso'); |
|
| 528 | + $statuses['trash'] = esc_html__('Trashed', 'event_espresso'); |
|
| 529 | + $template_args['statuses'] = $statuses; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 533 | + EEH_Template::display_template($template, $template_args); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + public function setup_autosave_hooks() |
|
| 538 | + { |
|
| 539 | + $this->_set_autosave_containers(); |
|
| 540 | + $this->_load_autosave_scripts_styles(); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available |
|
| 546 | + * in request data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
| 547 | + * for the nonce in here, but then this method looks for two things: |
|
| 548 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
| 549 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
| 550 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
| 551 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
| 552 | + * template args. |
|
| 553 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
| 554 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
| 555 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
| 556 | + * $this->_template_args['data']['items'] = array( |
|
| 557 | + * 'event-datetime-ids' => '1,2,3'; |
|
| 558 | + * ); |
|
| 559 | + * Keep in mind the following things: |
|
| 560 | + * - "where" index is for the input with the id as that string. |
|
| 561 | + * - "what" index is what will be used for the value of that input. |
|
| 562 | + * |
|
| 563 | + * @return void |
|
| 564 | + * @throws EE_Error |
|
| 565 | + */ |
|
| 566 | + public function do_extra_autosave_stuff() |
|
| 567 | + { |
|
| 568 | + // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
| 569 | + $nonce = $this->request->getRequestParam('autosavenonce'); |
|
| 570 | + $this->_verify_nonce($nonce, 'autosave'); |
|
| 571 | + // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
| 572 | + if (! defined('DOING_AUTOSAVE')) { |
|
| 573 | + define('DOING_AUTOSAVE', true); |
|
| 574 | + } |
|
| 575 | + // if we made it here then the nonce checked out. Let's run our methods and actions |
|
| 576 | + $autosave = "_ee_autosave_$this->_current_view"; |
|
| 577 | + if (method_exists($this, $autosave)) { |
|
| 578 | + $this->$autosave(); |
|
| 579 | + } else { |
|
| 580 | + $this->_template_args['success'] = true; |
|
| 581 | + } |
|
| 582 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
| 583 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 584 | + // now let's return json |
|
| 585 | + $this->_return_json(); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
| 591 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
| 592 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
| 593 | + * |
|
| 594 | + * @return void |
|
| 595 | + * @throws EE_Error |
|
| 596 | + * @throws ReflectionException |
|
| 597 | + */ |
|
| 598 | + protected function _extend_page_config_for_cpt() |
|
| 599 | + { |
|
| 600 | + // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
| 601 | + if ($this->raw_req_page !== $this->page_slug) { |
|
| 602 | + return; |
|
| 603 | + } |
|
| 604 | + // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
| 605 | + if (! empty($this->_cpt_object)) { |
|
| 606 | + $this->_page_routes = array_merge( |
|
| 607 | + [ |
|
| 608 | + 'create_new' => [$this, '_create_new_cpt_item'], |
|
| 609 | + 'edit' => [$this, '_edit_cpt_item'], |
|
| 610 | + ], |
|
| 611 | + $this->_page_routes |
|
| 612 | + ); |
|
| 613 | + $this->_page_config = array_merge( |
|
| 614 | + [ |
|
| 615 | + 'create_new' => [ |
|
| 616 | + 'nav' => [ |
|
| 617 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
| 618 | + 'order' => 5, |
|
| 619 | + ], |
|
| 620 | + 'require_nonce' => false, |
|
| 621 | + ], |
|
| 622 | + 'edit' => [ |
|
| 623 | + 'nav' => [ |
|
| 624 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
| 625 | + 'order' => 5, |
|
| 626 | + 'persistent' => false, |
|
| 627 | + 'url' => '', |
|
| 628 | + ], |
|
| 629 | + 'require_nonce' => false, |
|
| 630 | + ], |
|
| 631 | + ], |
|
| 632 | + $this->_page_config |
|
| 633 | + ); |
|
| 634 | + } |
|
| 635 | + // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
| 636 | + if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
| 637 | + return; |
|
| 638 | + } |
|
| 639 | + $this->_cpt_route = true; |
|
| 640 | + // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]); |
|
| 641 | + // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
| 642 | + if (empty($this->_cpt_object)) { |
|
| 643 | + $msg = sprintf( |
|
| 644 | + esc_html__( |
|
| 645 | + 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
| 646 | + 'event_espresso' |
|
| 647 | + ), |
|
| 648 | + $this->page_slug, |
|
| 649 | + $this->_req_action, |
|
| 650 | + get_class($this) |
|
| 651 | + ); |
|
| 652 | + throw new EE_Error($msg); |
|
| 653 | + } |
|
| 654 | + $this->_set_model_object($this->request->getRequestParam('post', 0, DataType::INT)); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
| 660 | + * |
|
| 661 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
| 662 | + * @param bool $ignore_route_check |
|
| 663 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
| 664 | + * @throws EE_Error |
|
| 665 | + * @throws InvalidArgumentException |
|
| 666 | + * @throws InvalidDataTypeException |
|
| 667 | + * @throws InvalidInterfaceException |
|
| 668 | + * @throws ReflectionException |
|
| 669 | + */ |
|
| 670 | + protected function _set_model_object(int $id = 0, bool $ignore_route_check = false, string $req_type = '') |
|
| 671 | + { |
|
| 672 | + $model = null; |
|
| 673 | + if ( |
|
| 674 | + empty($this->_cpt_model_names) |
|
| 675 | + || ( |
|
| 676 | + ! $ignore_route_check |
|
| 677 | + && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
| 678 | + ) |
|
| 679 | + || ( |
|
| 680 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 681 | + && $this->_cpt_model_obj->ID() === $id |
|
| 682 | + ) |
|
| 683 | + ) { |
|
| 684 | + // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
| 685 | + return; |
|
| 686 | + } |
|
| 687 | + // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
| 688 | + if ($ignore_route_check) { |
|
| 689 | + $post_type = get_post_type($id); |
|
| 690 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 691 | + $custom_post_types = $this->loader->getShared( |
|
| 692 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 693 | + ); |
|
| 694 | + $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
| 695 | + if (isset($model_names[ $post_type ])) { |
|
| 696 | + $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
| 697 | + } |
|
| 698 | + } else { |
|
| 699 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
| 700 | + } |
|
| 701 | + if ($model instanceof EEM_Base) { |
|
| 702 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
| 703 | + } |
|
| 704 | + do_action( |
|
| 705 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 706 | + $this->_cpt_model_obj, |
|
| 707 | + $req_type |
|
| 708 | + ); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * admin_init_global |
|
| 714 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 715 | + * This method executes for ALL EE Admin pages. |
|
| 716 | + * |
|
| 717 | + * @return void |
|
| 718 | + */ |
|
| 719 | + public function admin_init_global() |
|
| 720 | + { |
|
| 721 | + $post_ID = $this->request->getRequestParam('post', 0, DataType::INT); |
|
| 722 | + // its possible this is a new save so let's catch that instead |
|
| 723 | + $post_ID = $this->request->getRequestParam('post_ID', $post_ID, DataType::INT); |
|
| 724 | + $post = get_post($post_ID); |
|
| 725 | + $post_type = $post instanceof WP_Post ? $post->post_type : false; |
|
| 726 | + $current_route = $this->request->getRequestParam('current_route', 'shouldneverwork'); |
|
| 727 | + $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
| 728 | + ? $this->_cpt_routes[ $current_route ] |
|
| 729 | + : ''; |
|
| 730 | + add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 2); |
|
| 731 | + add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2); |
|
| 732 | + if ($post_type === $route_to_check) { |
|
| 733 | + add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2); |
|
| 734 | + } |
|
| 735 | + // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
| 736 | + $revision = $this->request->getRequestParam('revision'); |
|
| 737 | + if (! empty($revision)) { |
|
| 738 | + $action = $this->request->getRequestParam('action'); |
|
| 739 | + // doing a restore? |
|
| 740 | + if (! empty($action) && $action === 'restore') { |
|
| 741 | + // get post for revision |
|
| 742 | + $rev_post = get_post($revision); |
|
| 743 | + $rev_parent = get_post($rev_post->post_parent); |
|
| 744 | + // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
| 745 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
| 746 | + add_filter('wp_redirect', [$this, 'revision_redirect']); |
|
| 747 | + // restores of revisions |
|
| 748 | + add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2); |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + } |
|
| 752 | + // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
| 753 | + if ($post_type && $post_type === $route_to_check) { |
|
| 754 | + // $post_id, $post |
|
| 755 | + add_action('save_post', [$this, 'insert_update'], 10, 3); |
|
| 756 | + // $post_id |
|
| 757 | + add_action('trashed_post', [$this, 'before_trash_cpt_item']); |
|
| 758 | + add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts']); |
|
| 759 | + add_action('untrashed_post', [$this, 'before_restore_cpt_item']); |
|
| 760 | + add_action('after_delete_post', [$this, 'before_delete_cpt_item']); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Callback for the WordPress trashed_post hook. |
|
| 767 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
| 768 | + * |
|
| 769 | + * @param int $post_id |
|
| 770 | + * @throws EE_Error |
|
| 771 | + * @throws ReflectionException |
|
| 772 | + */ |
|
| 773 | + public function before_trash_cpt_item(int $post_id) |
|
| 774 | + { |
|
| 775 | + $this->_set_model_object($post_id, true, 'trash'); |
|
| 776 | + // if our cpt object isn't existent then get out immediately. |
|
| 777 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 778 | + return; |
|
| 779 | + } |
|
| 780 | + $this->trash_cpt_item($post_id); |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + |
|
| 784 | + /** |
|
| 785 | + * Callback for the WordPress untrashed_post hook. |
|
| 786 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
| 787 | + * |
|
| 788 | + * @param $post_id |
|
| 789 | + * @throws EE_Error |
|
| 790 | + * @throws ReflectionException |
|
| 791 | + */ |
|
| 792 | + public function before_restore_cpt_item($post_id) |
|
| 793 | + { |
|
| 794 | + $this->_set_model_object($post_id, true, 'restore'); |
|
| 795 | + // if our cpt object isn't existent then get out immediately. |
|
| 796 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 797 | + return; |
|
| 798 | + } |
|
| 799 | + $this->restore_cpt_item($post_id); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * Callback for the WordPress after_delete_post hook. |
|
| 805 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
| 806 | + * |
|
| 807 | + * @param $post_id |
|
| 808 | + * @throws EE_Error |
|
| 809 | + * @throws ReflectionException |
|
| 810 | + */ |
|
| 811 | + public function before_delete_cpt_item($post_id) |
|
| 812 | + { |
|
| 813 | + $this->_set_model_object($post_id, true, 'delete'); |
|
| 814 | + // if our cpt object isn't existent then get out immediately. |
|
| 815 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 816 | + return; |
|
| 817 | + } |
|
| 818 | + $this->delete_cpt_item($post_id); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
| 824 | + * accordingly. |
|
| 825 | + * |
|
| 826 | + * @return void |
|
| 827 | + * @throws EE_Error |
|
| 828 | + * @throws ReflectionException |
|
| 829 | + */ |
|
| 830 | + public function verify_cpt_object() |
|
| 831 | + { |
|
| 832 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
| 833 | + // verify event object |
|
| 834 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 835 | + throw new EE_Error( |
|
| 836 | + sprintf( |
|
| 837 | + esc_html__( |
|
| 838 | + 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
| 839 | + 'event_espresso' |
|
| 840 | + ), |
|
| 841 | + $label |
|
| 842 | + ) |
|
| 843 | + ); |
|
| 844 | + } |
|
| 845 | + // if auto-draft then throw an error |
|
| 846 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
| 847 | + EE_Error::overwrite_errors(); |
|
| 848 | + EE_Error::add_error( |
|
| 849 | + sprintf( |
|
| 850 | + esc_html__( |
|
| 851 | + 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
| 852 | + 'event_espresso' |
|
| 853 | + ), |
|
| 854 | + $label |
|
| 855 | + ), |
|
| 856 | + __FILE__, |
|
| 857 | + __FUNCTION__, |
|
| 858 | + __LINE__ |
|
| 859 | + ); |
|
| 860 | + } |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + |
|
| 864 | + /** |
|
| 865 | + * admin_footer_scripts_global |
|
| 866 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 867 | + * will apply on ALL EE_Admin pages. |
|
| 868 | + * |
|
| 869 | + * @return void |
|
| 870 | + */ |
|
| 871 | + public function admin_footer_scripts_global() |
|
| 872 | + { |
|
| 873 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 874 | + $this->_add_admin_page_overlay(); |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * add in any global scripts for cpt routes |
|
| 880 | + * |
|
| 881 | + * @return void |
|
| 882 | + */ |
|
| 883 | + public function load_global_scripts_styles() |
|
| 884 | + { |
|
| 885 | + parent::load_global_scripts_styles(); |
|
| 886 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 887 | + // setup custom post status object for localize script but only if we've got a cpt object |
|
| 888 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 889 | + if (! empty($statuses)) { |
|
| 890 | + // get ALL statuses! |
|
| 891 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
| 892 | + // setup object |
|
| 893 | + $ee_cpt_statuses = []; |
|
| 894 | + foreach ($statuses as $status => $label) { |
|
| 895 | + $ee_cpt_statuses[ $status ] = [ |
|
| 896 | + 'label' => $label, |
|
| 897 | + 'save_label' => sprintf( |
|
| 898 | + wp_strip_all_tags(__('Save as %s', 'event_espresso')), |
|
| 899 | + $label |
|
| 900 | + ), |
|
| 901 | + ]; |
|
| 902 | + } |
|
| 903 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
| 911 | + * insert/updates |
|
| 912 | + * |
|
| 913 | + * @param int $post_id ID of post being updated |
|
| 914 | + * @param WP_Post $post Post object from WP |
|
| 915 | + * @param bool $update Whether this is an update or a new save. |
|
| 916 | + * @return void |
|
| 917 | + * @throws EE_Error |
|
| 918 | + * @throws ReflectionException |
|
| 919 | + */ |
|
| 920 | + public function insert_update(int $post_id, WP_Post $post, bool $update) |
|
| 921 | + { |
|
| 922 | + // make sure that if this is a revision OR trash action that we don't do any updates! |
|
| 923 | + $action = $this->request->getRequestParam('action'); |
|
| 924 | + if ($action === 'restore' || $action === 'trash') { |
|
| 925 | + return; |
|
| 926 | + } |
|
| 927 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
| 928 | + // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
| 929 | + if ( |
|
| 930 | + $update |
|
| 931 | + && ( |
|
| 932 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 933 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
| 934 | + ) |
|
| 935 | + ) { |
|
| 936 | + return; |
|
| 937 | + } |
|
| 938 | + // check for autosave and update our req_data property accordingly. |
|
| 939 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
| 940 | 940 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
| 941 | 941 | |
| 942 | 942 | foreach ( (array) $values as $key => $value ) { |
@@ -946,549 +946,549 @@ discard block |
||
| 946 | 946 | |
| 947 | 947 | }/**/ // TODO reactivate after autosave is implemented in 4.2 |
| 948 | 948 | |
| 949 | - // take care of updating any selected page_template IF this cpt supports it. |
|
| 950 | - |
|
| 951 | - $page_template = $this->request->getRequestParam('page_template'); |
|
| 952 | - if ($this->_supports_page_templates($post->post_type) && ! empty($page_template)) { |
|
| 953 | - // wp version aware. |
|
| 954 | - if (RecommendedVersions::compareWordPressVersion('4.7')) { |
|
| 955 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
| 956 | - } else { |
|
| 957 | - $post->page_template = $page_template; |
|
| 958 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
| 959 | - } |
|
| 960 | - if ($page_template !== 'default' && ! isset($page_templates[ $page_template ])) { |
|
| 961 | - EE_Error::add_error( |
|
| 962 | - esc_html__('Invalid Page Template.', 'event_espresso'), |
|
| 963 | - __FILE__, |
|
| 964 | - __FUNCTION__, |
|
| 965 | - __LINE__ |
|
| 966 | - ); |
|
| 967 | - } else { |
|
| 968 | - update_post_meta($post_id, '_wp_page_template', $page_template); |
|
| 969 | - } |
|
| 970 | - } |
|
| 971 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 972 | - return; |
|
| 973 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
| 974 | - $this->_insert_update_cpt_item($post_id, $post); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
| 980 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
| 981 | - * so we don't have to check for our CPT. |
|
| 982 | - * |
|
| 983 | - * @param int $post_id ID of the post |
|
| 984 | - * @return void |
|
| 985 | - */ |
|
| 986 | - public function dont_permanently_delete_ee_cpts(int $post_id) |
|
| 987 | - { |
|
| 988 | - // only do this if we're actually processing one of our CPTs |
|
| 989 | - // if our cpt object isn't existent then get out immediately. |
|
| 990 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 991 | - return; |
|
| 992 | - } |
|
| 993 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
| 994 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
| 995 | - // our cpts may have comments so let's take care of that too |
|
| 996 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
| 1002 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
| 1003 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
| 1004 | - * |
|
| 1005 | - * @param int $post_id ID of cpt item |
|
| 1006 | - * @param int $revision_id ID of revision being restored |
|
| 1007 | - * @return void |
|
| 1008 | - */ |
|
| 1009 | - public function restore_revision(int $post_id, int $revision_id) |
|
| 1010 | - { |
|
| 1011 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
| 1012 | - // global action |
|
| 1013 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
| 1014 | - // class specific action so you can limit hooking into a specific page. |
|
| 1015 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * @param int $post_id ID of cpt item |
|
| 1021 | - * @param int $revision_id ID of revision for item |
|
| 1022 | - * @return void |
|
| 1023 | - * @see restore_revision() for details |
|
| 1024 | - */ |
|
| 1025 | - abstract protected function _restore_cpt_item(int $post_id, int $revision_id); |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
| 1030 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
| 1031 | - * To fix we have to reset the current_screen using the page_slug |
|
| 1032 | - * (which is identical - or should be - to our registered_post_type id.) |
|
| 1033 | - * Also, since the core WP file loads the admin_header.php for WP |
|
| 1034 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
| 1035 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
| 1036 | - * |
|
| 1037 | - * @return void |
|
| 1038 | - * @throws EE_Error |
|
| 1039 | - * @throws ReflectionException |
|
| 1040 | - */ |
|
| 1041 | - public function modify_current_screen() |
|
| 1042 | - { |
|
| 1043 | - // ONLY do this if the current page_route IS a cpt route |
|
| 1044 | - if (! $this->_cpt_route) { |
|
| 1045 | - return; |
|
| 1046 | - } |
|
| 1047 | - // routing things REALLY early b/c this is a cpt admin page |
|
| 1048 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
| 1049 | - $this->_current_screen = get_current_screen(); |
|
| 1050 | - $this->_current_screen->base = 'event-espresso'; |
|
| 1051 | - $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
| 1052 | - /*try { |
|
| 949 | + // take care of updating any selected page_template IF this cpt supports it. |
|
| 950 | + |
|
| 951 | + $page_template = $this->request->getRequestParam('page_template'); |
|
| 952 | + if ($this->_supports_page_templates($post->post_type) && ! empty($page_template)) { |
|
| 953 | + // wp version aware. |
|
| 954 | + if (RecommendedVersions::compareWordPressVersion('4.7')) { |
|
| 955 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
| 956 | + } else { |
|
| 957 | + $post->page_template = $page_template; |
|
| 958 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
| 959 | + } |
|
| 960 | + if ($page_template !== 'default' && ! isset($page_templates[ $page_template ])) { |
|
| 961 | + EE_Error::add_error( |
|
| 962 | + esc_html__('Invalid Page Template.', 'event_espresso'), |
|
| 963 | + __FILE__, |
|
| 964 | + __FUNCTION__, |
|
| 965 | + __LINE__ |
|
| 966 | + ); |
|
| 967 | + } else { |
|
| 968 | + update_post_meta($post_id, '_wp_page_template', $page_template); |
|
| 969 | + } |
|
| 970 | + } |
|
| 971 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 972 | + return; |
|
| 973 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
| 974 | + $this->_insert_update_cpt_item($post_id, $post); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
| 980 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
| 981 | + * so we don't have to check for our CPT. |
|
| 982 | + * |
|
| 983 | + * @param int $post_id ID of the post |
|
| 984 | + * @return void |
|
| 985 | + */ |
|
| 986 | + public function dont_permanently_delete_ee_cpts(int $post_id) |
|
| 987 | + { |
|
| 988 | + // only do this if we're actually processing one of our CPTs |
|
| 989 | + // if our cpt object isn't existent then get out immediately. |
|
| 990 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 991 | + return; |
|
| 992 | + } |
|
| 993 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
| 994 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
| 995 | + // our cpts may have comments so let's take care of that too |
|
| 996 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
| 1002 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
| 1003 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
| 1004 | + * |
|
| 1005 | + * @param int $post_id ID of cpt item |
|
| 1006 | + * @param int $revision_id ID of revision being restored |
|
| 1007 | + * @return void |
|
| 1008 | + */ |
|
| 1009 | + public function restore_revision(int $post_id, int $revision_id) |
|
| 1010 | + { |
|
| 1011 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
| 1012 | + // global action |
|
| 1013 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
| 1014 | + // class specific action so you can limit hooking into a specific page. |
|
| 1015 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * @param int $post_id ID of cpt item |
|
| 1021 | + * @param int $revision_id ID of revision for item |
|
| 1022 | + * @return void |
|
| 1023 | + * @see restore_revision() for details |
|
| 1024 | + */ |
|
| 1025 | + abstract protected function _restore_cpt_item(int $post_id, int $revision_id); |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
| 1030 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
| 1031 | + * To fix we have to reset the current_screen using the page_slug |
|
| 1032 | + * (which is identical - or should be - to our registered_post_type id.) |
|
| 1033 | + * Also, since the core WP file loads the admin_header.php for WP |
|
| 1034 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
| 1035 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
| 1036 | + * |
|
| 1037 | + * @return void |
|
| 1038 | + * @throws EE_Error |
|
| 1039 | + * @throws ReflectionException |
|
| 1040 | + */ |
|
| 1041 | + public function modify_current_screen() |
|
| 1042 | + { |
|
| 1043 | + // ONLY do this if the current page_route IS a cpt route |
|
| 1044 | + if (! $this->_cpt_route) { |
|
| 1045 | + return; |
|
| 1046 | + } |
|
| 1047 | + // routing things REALLY early b/c this is a cpt admin page |
|
| 1048 | + set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
| 1049 | + $this->_current_screen = get_current_screen(); |
|
| 1050 | + $this->_current_screen->base = 'event-espresso'; |
|
| 1051 | + $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
| 1052 | + /*try { |
|
| 1053 | 1053 | $this->_route_admin_request(); |
| 1054 | 1054 | } catch ( EE_Error $e ) { |
| 1055 | 1055 | $e->get_error(); |
| 1056 | 1056 | }/**/ |
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
| 1062 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
| 1063 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
| 1064 | - * default to be. |
|
| 1065 | - * |
|
| 1066 | - * @param string|null $title The new title (or existing if there is no editor_title defined) |
|
| 1067 | - * @return string|null |
|
| 1068 | - */ |
|
| 1069 | - public function add_custom_editor_default_title(?string $title): ?string |
|
| 1070 | - { |
|
| 1071 | - return $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] ?? $title; |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
| 1077 | - * |
|
| 1078 | - * @param string $shortlink The already generated shortlink |
|
| 1079 | - * @param int $id Post ID for this item |
|
| 1080 | - * @return string |
|
| 1081 | - * @deprecated 5.0.0.p |
|
| 1082 | - * @see EventShortlinkButton::addButton() |
|
| 1083 | - */ |
|
| 1084 | - public function add_shortlink_button_to_editor(string $shortlink, int $id): string |
|
| 1085 | - { |
|
| 1086 | - return EventShortlinkButton::addButton($shortlink, $id); |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - /** |
|
| 1091 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
| 1092 | - * already run in modify_current_screen()) |
|
| 1093 | - * |
|
| 1094 | - * @return void |
|
| 1095 | - * @throws EE_Error |
|
| 1096 | - * @throws ReflectionException |
|
| 1097 | - * @throws Throwable |
|
| 1098 | - */ |
|
| 1099 | - public function route_admin_request() |
|
| 1100 | - { |
|
| 1101 | - if ($this->_cpt_route) { |
|
| 1102 | - return; |
|
| 1103 | - } |
|
| 1104 | - try { |
|
| 1105 | - $this->_route_admin_request(); |
|
| 1106 | - } catch (EE_Error $e) { |
|
| 1107 | - $e->get_error(); |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - |
|
| 1112 | - /** |
|
| 1113 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
| 1114 | - * |
|
| 1115 | - * @return void |
|
| 1116 | - */ |
|
| 1117 | - public function cpt_post_form_hidden_input() |
|
| 1118 | - { |
|
| 1119 | - // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
| 1120 | - echo ' |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
| 1062 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
| 1063 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
| 1064 | + * default to be. |
|
| 1065 | + * |
|
| 1066 | + * @param string|null $title The new title (or existing if there is no editor_title defined) |
|
| 1067 | + * @return string|null |
|
| 1068 | + */ |
|
| 1069 | + public function add_custom_editor_default_title(?string $title): ?string |
|
| 1070 | + { |
|
| 1071 | + return $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] ?? $title; |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
| 1077 | + * |
|
| 1078 | + * @param string $shortlink The already generated shortlink |
|
| 1079 | + * @param int $id Post ID for this item |
|
| 1080 | + * @return string |
|
| 1081 | + * @deprecated 5.0.0.p |
|
| 1082 | + * @see EventShortlinkButton::addButton() |
|
| 1083 | + */ |
|
| 1084 | + public function add_shortlink_button_to_editor(string $shortlink, int $id): string |
|
| 1085 | + { |
|
| 1086 | + return EventShortlinkButton::addButton($shortlink, $id); |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + /** |
|
| 1091 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
| 1092 | + * already run in modify_current_screen()) |
|
| 1093 | + * |
|
| 1094 | + * @return void |
|
| 1095 | + * @throws EE_Error |
|
| 1096 | + * @throws ReflectionException |
|
| 1097 | + * @throws Throwable |
|
| 1098 | + */ |
|
| 1099 | + public function route_admin_request() |
|
| 1100 | + { |
|
| 1101 | + if ($this->_cpt_route) { |
|
| 1102 | + return; |
|
| 1103 | + } |
|
| 1104 | + try { |
|
| 1105 | + $this->_route_admin_request(); |
|
| 1106 | + } catch (EE_Error $e) { |
|
| 1107 | + $e->get_error(); |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + |
|
| 1112 | + /** |
|
| 1113 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
| 1114 | + * |
|
| 1115 | + * @return void |
|
| 1116 | + */ |
|
| 1117 | + public function cpt_post_form_hidden_input() |
|
| 1118 | + { |
|
| 1119 | + // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
| 1120 | + echo ' |
|
| 1121 | 1121 | <input type="hidden" name="ee_cpt_item_redirect_url" value="' . esc_url_raw($this->_admin_base_url) . '"/> |
| 1122 | 1122 | <div id="ee-cpt-hidden-inputs"> |
| 1123 | 1123 | <input type="hidden" id="current_route" name="current_route" value="' . esc_attr($this->_current_view) . '"/> |
| 1124 | 1124 | <input type="hidden" id="current_page" name="current_page" value="' . esc_attr($this->page_slug) . '"/> |
| 1125 | 1125 | </div>'; |
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
| 1131 | - * |
|
| 1132 | - * @param string $location Original location url |
|
| 1133 | - * @return string new (or original) url to redirect to. |
|
| 1134 | - * @throws EE_Error |
|
| 1135 | - */ |
|
| 1136 | - public function revision_redirect(string $location): string |
|
| 1137 | - { |
|
| 1138 | - // get revision |
|
| 1139 | - $revision = $this->request->getRequestParam('revision'); |
|
| 1140 | - // can't do anything without revision so let's get out if not present |
|
| 1141 | - if (empty($revision)) { |
|
| 1142 | - return $location; |
|
| 1143 | - } |
|
| 1144 | - // get rev_post_data |
|
| 1145 | - $rev = get_post($revision); |
|
| 1146 | - $admin_url = $this->_admin_base_url; |
|
| 1147 | - $query_args = [ |
|
| 1148 | - 'action' => 'edit', |
|
| 1149 | - 'post' => $rev->post_parent, |
|
| 1150 | - 'revision' => $revision, |
|
| 1151 | - 'message' => 5, |
|
| 1152 | - ]; |
|
| 1153 | - $this->_process_notices($query_args, true); |
|
| 1154 | - return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
| 1160 | - * |
|
| 1161 | - * @param string $link the original generated link |
|
| 1162 | - * @param int $id post id |
|
| 1163 | - * @return string the link |
|
| 1164 | - */ |
|
| 1165 | - public function modify_edit_post_link(string $link, int $id): string |
|
| 1166 | - { |
|
| 1167 | - $post = get_post($id); |
|
| 1168 | - $action = $this->request->getRequestParam('action'); |
|
| 1169 | - if ( |
|
| 1170 | - empty($action) |
|
| 1171 | - || ! isset($this->_cpt_routes[ $action ]) |
|
| 1172 | - || $post->post_type !== $this->_cpt_routes[ $action ] |
|
| 1173 | - ) { |
|
| 1174 | - return $link; |
|
| 1175 | - } |
|
| 1176 | - $query_args = [ |
|
| 1177 | - 'action' => $this->_cpt_edit_routes[ $post->post_type ] ?? 'edit', |
|
| 1178 | - 'post' => $id, |
|
| 1179 | - ]; |
|
| 1180 | - return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1181 | - } |
|
| 1182 | - |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
| 1186 | - * our routes. |
|
| 1187 | - * |
|
| 1188 | - * @param string $delete_link original delete link |
|
| 1189 | - * @param int $post_id id of cpt object |
|
| 1190 | - * @return string new delete link |
|
| 1191 | - * @throws EE_Error |
|
| 1192 | - * @throws ReflectionException |
|
| 1193 | - */ |
|
| 1194 | - public function modify_delete_post_link(string $delete_link, int $post_id): string |
|
| 1195 | - { |
|
| 1196 | - $post = get_post($post_id); |
|
| 1197 | - $action = $this->request->getRequestParam('action'); |
|
| 1198 | - if ( |
|
| 1199 | - ! $post instanceof WP_Post |
|
| 1200 | - || empty($action) |
|
| 1201 | - || ! isset($this->_cpt_routes[ $action ]) |
|
| 1202 | - || $post->post_type !== $this->_cpt_routes[ $action ] |
|
| 1203 | - ) { |
|
| 1204 | - return $delete_link; |
|
| 1205 | - } |
|
| 1206 | - $this->_set_model_object($post->ID, true); |
|
| 1207 | - |
|
| 1208 | - // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
| 1209 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1210 | - |
|
| 1211 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
| 1212 | - [ |
|
| 1213 | - 'page' => $this->request->getRequestParam('page'), |
|
| 1214 | - 'action' => $action, |
|
| 1215 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() => $post->ID, |
|
| 1216 | - ], |
|
| 1217 | - admin_url() |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
| 1224 | - * so that we can hijack the default redirect locations for wp custom post types |
|
| 1225 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
| 1226 | - * |
|
| 1227 | - * @param string $location This is the incoming currently set redirect location |
|
| 1228 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
| 1229 | - * @return string the new location to redirect to |
|
| 1230 | - * @throws EE_Error |
|
| 1231 | - */ |
|
| 1232 | - public function cpt_post_location_redirect(string $location, string $post_id): string |
|
| 1233 | - { |
|
| 1234 | - // we DO have a match so let's setup the url |
|
| 1235 | - // we have to get the post to determine our route |
|
| 1236 | - $post = get_post($post_id); |
|
| 1237 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
| 1238 | - // shared query_args |
|
| 1239 | - $query_args = ['action' => $edit_route, 'post' => $post_id]; |
|
| 1240 | - |
|
| 1241 | - $save = $this->request->getRequestParam('save'); |
|
| 1242 | - $publish = $this->request->getRequestParam('publish'); |
|
| 1243 | - $add_meta = $this->request->getRequestParam('addmeta'); |
|
| 1244 | - $delete_meta = $this->request->getRequestParam('deletemeta'); |
|
| 1245 | - if ($save || $publish) { |
|
| 1246 | - $status = get_post_status($post_id); |
|
| 1247 | - if ($publish) { |
|
| 1248 | - switch ($status) { |
|
| 1249 | - case 'pending': |
|
| 1250 | - $message = 8; |
|
| 1251 | - break; |
|
| 1252 | - case 'future': |
|
| 1253 | - $message = 9; |
|
| 1254 | - break; |
|
| 1255 | - default: |
|
| 1256 | - $message = 6; |
|
| 1257 | - } |
|
| 1258 | - } else { |
|
| 1259 | - $message = 'draft' === $status ? 10 : 1; |
|
| 1260 | - } |
|
| 1261 | - } elseif ($add_meta) { |
|
| 1262 | - $message = 2; |
|
| 1263 | - } elseif ($delete_meta) { |
|
| 1264 | - $message = 3; |
|
| 1265 | - } elseif ($this->request->getRequestParam('action') === 'post-quickpress-save-cont') { |
|
| 1266 | - $message = 7; |
|
| 1267 | - } else { |
|
| 1268 | - $message = 4; |
|
| 1269 | - } |
|
| 1270 | - // change the message if the post type is not viewable on the frontend |
|
| 1271 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
| 1272 | - |
|
| 1273 | - $query_args['message'] = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
| 1274 | - $this->_process_notices($query_args, true); |
|
| 1275 | - return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * This method is called to inject nav tabs on core WP cpt pages |
|
| 1281 | - * |
|
| 1282 | - * @return void |
|
| 1283 | - * @throws EE_Error |
|
| 1284 | - */ |
|
| 1285 | - public function inject_nav_tabs() |
|
| 1286 | - { |
|
| 1287 | - echo wp_kses($this->_get_main_nav_tabs(), AllowedTags::getWithFormTags()); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - |
|
| 1291 | - /** |
|
| 1292 | - * This just sets up the post update messages when an update form is loaded |
|
| 1293 | - * |
|
| 1294 | - * @param array $messages the original messages array |
|
| 1295 | - * @return array the new messages array |
|
| 1296 | - */ |
|
| 1297 | - public function post_update_messages(array $messages): array |
|
| 1298 | - { |
|
| 1299 | - global $post; |
|
| 1300 | - $id = $this->request->getRequestParam('post'); |
|
| 1301 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
| 1302 | - $revision = $this->request->getRequestParam('revision', 0, 'int'); |
|
| 1303 | - |
|
| 1304 | - $messages[ $post->post_type ] = [ |
|
| 1305 | - 0 => '', // Unused. Messages start at index 1. |
|
| 1306 | - 1 => sprintf( |
|
| 1307 | - esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1308 | - $this->_cpt_object->labels->singular_name, |
|
| 1309 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1310 | - '</a>' |
|
| 1311 | - ), |
|
| 1312 | - 2 => esc_html__('Custom field updated', 'event_espresso'), |
|
| 1313 | - 3 => esc_html__('Custom field deleted.', 'event_espresso'), |
|
| 1314 | - 4 => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1315 | - 5 => $revision |
|
| 1316 | - ? sprintf( |
|
| 1317 | - esc_html__('%s restored to revision from %s', 'event_espresso'), |
|
| 1318 | - $this->_cpt_object->labels->singular_name, |
|
| 1319 | - wp_post_revision_title($revision, false) |
|
| 1320 | - ) |
|
| 1321 | - : false, |
|
| 1322 | - 6 => sprintf( |
|
| 1323 | - esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1324 | - $this->_cpt_object->labels->singular_name, |
|
| 1325 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1326 | - '</a>' |
|
| 1327 | - ), |
|
| 1328 | - 7 => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1329 | - 8 => sprintf( |
|
| 1330 | - esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
| 1331 | - $this->_cpt_object->labels->singular_name, |
|
| 1332 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1333 | - '</a>' |
|
| 1334 | - ), |
|
| 1335 | - 9 => sprintf( |
|
| 1336 | - esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
| 1337 | - $this->_cpt_object->labels->singular_name, |
|
| 1338 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
| 1339 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1340 | - '</a>' |
|
| 1341 | - ), |
|
| 1342 | - 10 => sprintf( |
|
| 1343 | - esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
| 1344 | - $this->_cpt_object->labels->singular_name, |
|
| 1345 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1346 | - '</a>' |
|
| 1347 | - ), |
|
| 1348 | - ]; |
|
| 1349 | - return $messages; |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * default method for the 'create_new' route for cpt admin pages. |
|
| 1355 | - * For reference what to include in here, see wp-admin/post-new.php |
|
| 1356 | - * |
|
| 1357 | - * @return void |
|
| 1358 | - */ |
|
| 1359 | - protected function _create_new_cpt_item() |
|
| 1360 | - { |
|
| 1361 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1362 | - global $post, $title, $post_type, $post_type_object; |
|
| 1363 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1364 | - $post_type_object = $this->_cpt_object; |
|
| 1365 | - $title = $post_type_object->labels->add_new_item; |
|
| 1366 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
| 1367 | - add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1368 | - // modify the default editor title field with default title. |
|
| 1369 | - add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
| 1370 | - $this->loadEditorTemplate(); |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - /** |
|
| 1375 | - * Enqueues auto-save and loads the editor template |
|
| 1376 | - * |
|
| 1377 | - * @param bool $creating |
|
| 1378 | - */ |
|
| 1379 | - private function loadEditorTemplate(bool $creating = true) |
|
| 1380 | - { |
|
| 1381 | - if ($this->admin_config && ! $this->admin_config->useAdvancedEditor()) { |
|
| 1382 | - add_filter('admin_body_class', function($classes) |
|
| 1383 | - { |
|
| 1384 | - $classes .= ' espresso-legacy-editor'; |
|
| 1385 | - return $classes; |
|
| 1386 | - }); |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1390 | - // these vars are used by the template |
|
| 1391 | - $editing = true; |
|
| 1392 | - $post_ID = $post->ID; |
|
| 1393 | - if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
| 1394 | - // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
| 1395 | - // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
| 1396 | - $action = $this->request->getRequestParam('action'); |
|
| 1397 | - if ($creating) { |
|
| 1398 | - wp_enqueue_script('autosave'); |
|
| 1399 | - } elseif ( |
|
| 1400 | - isset($this->_cpt_routes[ $action ]) |
|
| 1401 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $action ]) |
|
| 1402 | - ) { |
|
| 1403 | - $create_new_action = apply_filters( |
|
| 1404 | - 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
| 1405 | - 'create_new', |
|
| 1406 | - $this |
|
| 1407 | - ); |
|
| 1408 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1409 | - [ |
|
| 1410 | - 'action' => $create_new_action, |
|
| 1411 | - 'page' => $this->page_slug, |
|
| 1412 | - ], |
|
| 1413 | - 'admin.php' |
|
| 1414 | - ); |
|
| 1415 | - } |
|
| 1416 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - |
|
| 1421 | - public function add_new_admin_page_global() |
|
| 1422 | - { |
|
| 1423 | - $admin_page = $this->request->getRequestParam('post', 0, DataType::INT) !== 0 |
|
| 1424 | - ? 'post-php' |
|
| 1425 | - : 'post-new-php'; |
|
| 1426 | - ?> |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
| 1131 | + * |
|
| 1132 | + * @param string $location Original location url |
|
| 1133 | + * @return string new (or original) url to redirect to. |
|
| 1134 | + * @throws EE_Error |
|
| 1135 | + */ |
|
| 1136 | + public function revision_redirect(string $location): string |
|
| 1137 | + { |
|
| 1138 | + // get revision |
|
| 1139 | + $revision = $this->request->getRequestParam('revision'); |
|
| 1140 | + // can't do anything without revision so let's get out if not present |
|
| 1141 | + if (empty($revision)) { |
|
| 1142 | + return $location; |
|
| 1143 | + } |
|
| 1144 | + // get rev_post_data |
|
| 1145 | + $rev = get_post($revision); |
|
| 1146 | + $admin_url = $this->_admin_base_url; |
|
| 1147 | + $query_args = [ |
|
| 1148 | + 'action' => 'edit', |
|
| 1149 | + 'post' => $rev->post_parent, |
|
| 1150 | + 'revision' => $revision, |
|
| 1151 | + 'message' => 5, |
|
| 1152 | + ]; |
|
| 1153 | + $this->_process_notices($query_args, true); |
|
| 1154 | + return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
| 1160 | + * |
|
| 1161 | + * @param string $link the original generated link |
|
| 1162 | + * @param int $id post id |
|
| 1163 | + * @return string the link |
|
| 1164 | + */ |
|
| 1165 | + public function modify_edit_post_link(string $link, int $id): string |
|
| 1166 | + { |
|
| 1167 | + $post = get_post($id); |
|
| 1168 | + $action = $this->request->getRequestParam('action'); |
|
| 1169 | + if ( |
|
| 1170 | + empty($action) |
|
| 1171 | + || ! isset($this->_cpt_routes[ $action ]) |
|
| 1172 | + || $post->post_type !== $this->_cpt_routes[ $action ] |
|
| 1173 | + ) { |
|
| 1174 | + return $link; |
|
| 1175 | + } |
|
| 1176 | + $query_args = [ |
|
| 1177 | + 'action' => $this->_cpt_edit_routes[ $post->post_type ] ?? 'edit', |
|
| 1178 | + 'post' => $id, |
|
| 1179 | + ]; |
|
| 1180 | + return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1181 | + } |
|
| 1182 | + |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
| 1186 | + * our routes. |
|
| 1187 | + * |
|
| 1188 | + * @param string $delete_link original delete link |
|
| 1189 | + * @param int $post_id id of cpt object |
|
| 1190 | + * @return string new delete link |
|
| 1191 | + * @throws EE_Error |
|
| 1192 | + * @throws ReflectionException |
|
| 1193 | + */ |
|
| 1194 | + public function modify_delete_post_link(string $delete_link, int $post_id): string |
|
| 1195 | + { |
|
| 1196 | + $post = get_post($post_id); |
|
| 1197 | + $action = $this->request->getRequestParam('action'); |
|
| 1198 | + if ( |
|
| 1199 | + ! $post instanceof WP_Post |
|
| 1200 | + || empty($action) |
|
| 1201 | + || ! isset($this->_cpt_routes[ $action ]) |
|
| 1202 | + || $post->post_type !== $this->_cpt_routes[ $action ] |
|
| 1203 | + ) { |
|
| 1204 | + return $delete_link; |
|
| 1205 | + } |
|
| 1206 | + $this->_set_model_object($post->ID, true); |
|
| 1207 | + |
|
| 1208 | + // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
| 1209 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1210 | + |
|
| 1211 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
| 1212 | + [ |
|
| 1213 | + 'page' => $this->request->getRequestParam('page'), |
|
| 1214 | + 'action' => $action, |
|
| 1215 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() => $post->ID, |
|
| 1216 | + ], |
|
| 1217 | + admin_url() |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
| 1224 | + * so that we can hijack the default redirect locations for wp custom post types |
|
| 1225 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
| 1226 | + * |
|
| 1227 | + * @param string $location This is the incoming currently set redirect location |
|
| 1228 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
| 1229 | + * @return string the new location to redirect to |
|
| 1230 | + * @throws EE_Error |
|
| 1231 | + */ |
|
| 1232 | + public function cpt_post_location_redirect(string $location, string $post_id): string |
|
| 1233 | + { |
|
| 1234 | + // we DO have a match so let's setup the url |
|
| 1235 | + // we have to get the post to determine our route |
|
| 1236 | + $post = get_post($post_id); |
|
| 1237 | + $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
| 1238 | + // shared query_args |
|
| 1239 | + $query_args = ['action' => $edit_route, 'post' => $post_id]; |
|
| 1240 | + |
|
| 1241 | + $save = $this->request->getRequestParam('save'); |
|
| 1242 | + $publish = $this->request->getRequestParam('publish'); |
|
| 1243 | + $add_meta = $this->request->getRequestParam('addmeta'); |
|
| 1244 | + $delete_meta = $this->request->getRequestParam('deletemeta'); |
|
| 1245 | + if ($save || $publish) { |
|
| 1246 | + $status = get_post_status($post_id); |
|
| 1247 | + if ($publish) { |
|
| 1248 | + switch ($status) { |
|
| 1249 | + case 'pending': |
|
| 1250 | + $message = 8; |
|
| 1251 | + break; |
|
| 1252 | + case 'future': |
|
| 1253 | + $message = 9; |
|
| 1254 | + break; |
|
| 1255 | + default: |
|
| 1256 | + $message = 6; |
|
| 1257 | + } |
|
| 1258 | + } else { |
|
| 1259 | + $message = 'draft' === $status ? 10 : 1; |
|
| 1260 | + } |
|
| 1261 | + } elseif ($add_meta) { |
|
| 1262 | + $message = 2; |
|
| 1263 | + } elseif ($delete_meta) { |
|
| 1264 | + $message = 3; |
|
| 1265 | + } elseif ($this->request->getRequestParam('action') === 'post-quickpress-save-cont') { |
|
| 1266 | + $message = 7; |
|
| 1267 | + } else { |
|
| 1268 | + $message = 4; |
|
| 1269 | + } |
|
| 1270 | + // change the message if the post type is not viewable on the frontend |
|
| 1271 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
| 1272 | + |
|
| 1273 | + $query_args['message'] = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
| 1274 | + $this->_process_notices($query_args, true); |
|
| 1275 | + return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * This method is called to inject nav tabs on core WP cpt pages |
|
| 1281 | + * |
|
| 1282 | + * @return void |
|
| 1283 | + * @throws EE_Error |
|
| 1284 | + */ |
|
| 1285 | + public function inject_nav_tabs() |
|
| 1286 | + { |
|
| 1287 | + echo wp_kses($this->_get_main_nav_tabs(), AllowedTags::getWithFormTags()); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + |
|
| 1291 | + /** |
|
| 1292 | + * This just sets up the post update messages when an update form is loaded |
|
| 1293 | + * |
|
| 1294 | + * @param array $messages the original messages array |
|
| 1295 | + * @return array the new messages array |
|
| 1296 | + */ |
|
| 1297 | + public function post_update_messages(array $messages): array |
|
| 1298 | + { |
|
| 1299 | + global $post; |
|
| 1300 | + $id = $this->request->getRequestParam('post'); |
|
| 1301 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
| 1302 | + $revision = $this->request->getRequestParam('revision', 0, 'int'); |
|
| 1303 | + |
|
| 1304 | + $messages[ $post->post_type ] = [ |
|
| 1305 | + 0 => '', // Unused. Messages start at index 1. |
|
| 1306 | + 1 => sprintf( |
|
| 1307 | + esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1308 | + $this->_cpt_object->labels->singular_name, |
|
| 1309 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1310 | + '</a>' |
|
| 1311 | + ), |
|
| 1312 | + 2 => esc_html__('Custom field updated', 'event_espresso'), |
|
| 1313 | + 3 => esc_html__('Custom field deleted.', 'event_espresso'), |
|
| 1314 | + 4 => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1315 | + 5 => $revision |
|
| 1316 | + ? sprintf( |
|
| 1317 | + esc_html__('%s restored to revision from %s', 'event_espresso'), |
|
| 1318 | + $this->_cpt_object->labels->singular_name, |
|
| 1319 | + wp_post_revision_title($revision, false) |
|
| 1320 | + ) |
|
| 1321 | + : false, |
|
| 1322 | + 6 => sprintf( |
|
| 1323 | + esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1324 | + $this->_cpt_object->labels->singular_name, |
|
| 1325 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1326 | + '</a>' |
|
| 1327 | + ), |
|
| 1328 | + 7 => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1329 | + 8 => sprintf( |
|
| 1330 | + esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
| 1331 | + $this->_cpt_object->labels->singular_name, |
|
| 1332 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1333 | + '</a>' |
|
| 1334 | + ), |
|
| 1335 | + 9 => sprintf( |
|
| 1336 | + esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
| 1337 | + $this->_cpt_object->labels->singular_name, |
|
| 1338 | + '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
| 1339 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1340 | + '</a>' |
|
| 1341 | + ), |
|
| 1342 | + 10 => sprintf( |
|
| 1343 | + esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
| 1344 | + $this->_cpt_object->labels->singular_name, |
|
| 1345 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1346 | + '</a>' |
|
| 1347 | + ), |
|
| 1348 | + ]; |
|
| 1349 | + return $messages; |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * default method for the 'create_new' route for cpt admin pages. |
|
| 1355 | + * For reference what to include in here, see wp-admin/post-new.php |
|
| 1356 | + * |
|
| 1357 | + * @return void |
|
| 1358 | + */ |
|
| 1359 | + protected function _create_new_cpt_item() |
|
| 1360 | + { |
|
| 1361 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1362 | + global $post, $title, $post_type, $post_type_object; |
|
| 1363 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1364 | + $post_type_object = $this->_cpt_object; |
|
| 1365 | + $title = $post_type_object->labels->add_new_item; |
|
| 1366 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
| 1367 | + add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1368 | + // modify the default editor title field with default title. |
|
| 1369 | + add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
| 1370 | + $this->loadEditorTemplate(); |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + /** |
|
| 1375 | + * Enqueues auto-save and loads the editor template |
|
| 1376 | + * |
|
| 1377 | + * @param bool $creating |
|
| 1378 | + */ |
|
| 1379 | + private function loadEditorTemplate(bool $creating = true) |
|
| 1380 | + { |
|
| 1381 | + if ($this->admin_config && ! $this->admin_config->useAdvancedEditor()) { |
|
| 1382 | + add_filter('admin_body_class', function($classes) |
|
| 1383 | + { |
|
| 1384 | + $classes .= ' espresso-legacy-editor'; |
|
| 1385 | + return $classes; |
|
| 1386 | + }); |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1390 | + // these vars are used by the template |
|
| 1391 | + $editing = true; |
|
| 1392 | + $post_ID = $post->ID; |
|
| 1393 | + if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
| 1394 | + // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
| 1395 | + // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
| 1396 | + $action = $this->request->getRequestParam('action'); |
|
| 1397 | + if ($creating) { |
|
| 1398 | + wp_enqueue_script('autosave'); |
|
| 1399 | + } elseif ( |
|
| 1400 | + isset($this->_cpt_routes[ $action ]) |
|
| 1401 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $action ]) |
|
| 1402 | + ) { |
|
| 1403 | + $create_new_action = apply_filters( |
|
| 1404 | + 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
| 1405 | + 'create_new', |
|
| 1406 | + $this |
|
| 1407 | + ); |
|
| 1408 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1409 | + [ |
|
| 1410 | + 'action' => $create_new_action, |
|
| 1411 | + 'page' => $this->page_slug, |
|
| 1412 | + ], |
|
| 1413 | + 'admin.php' |
|
| 1414 | + ); |
|
| 1415 | + } |
|
| 1416 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + |
|
| 1421 | + public function add_new_admin_page_global() |
|
| 1422 | + { |
|
| 1423 | + $admin_page = $this->request->getRequestParam('post', 0, DataType::INT) !== 0 |
|
| 1424 | + ? 'post-php' |
|
| 1425 | + : 'post-new-php'; |
|
| 1426 | + ?> |
|
| 1427 | 1427 | <script type="text/javascript"> |
| 1428 | 1428 | adminpage = '<?php echo esc_js($admin_page); ?>'; |
| 1429 | 1429 | </script> |
| 1430 | 1430 | <?php |
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * default method for the 'edit' route for cpt admin pages |
|
| 1436 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
| 1437 | - * |
|
| 1438 | - * @return void |
|
| 1439 | - */ |
|
| 1440 | - protected function _edit_cpt_item() |
|
| 1441 | - { |
|
| 1442 | - global $post, $post_type, $post_type_object, $title; |
|
| 1443 | - $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
| 1444 | - $post = $post_id ? get_post($post_id, OBJECT, 'edit') : null; |
|
| 1445 | - if (empty($post)) { |
|
| 1446 | - wp_die( |
|
| 1447 | - esc_html__( |
|
| 1448 | - "You attempted to edit an item that doesn't exist. Perhaps it was deleted?", |
|
| 1449 | - 'event_espresso' |
|
| 1450 | - ) |
|
| 1451 | - ); |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - $post_lock = $this->request->getRequestParam('get-post-lock'); |
|
| 1455 | - if ($post_lock) { |
|
| 1456 | - wp_set_post_lock($post_id); |
|
| 1457 | - EEH_URL::safeRedirectAndExit(get_edit_post_link($post_id, 'url')); |
|
| 1458 | - } |
|
| 1459 | - |
|
| 1460 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1461 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1462 | - $post_type_object = $this->_cpt_object; |
|
| 1463 | - $title = $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
| 1464 | - ?? $post_type_object->labels->edit_item; |
|
| 1465 | - |
|
| 1466 | - if (! wp_check_post_lock($post->ID)) { |
|
| 1467 | - wp_set_post_lock($post->ID); |
|
| 1468 | - } |
|
| 1469 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
| 1470 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
| 1471 | - wp_enqueue_script('admin-comments'); |
|
| 1472 | - enqueue_comment_hotkeys_js(); |
|
| 1473 | - } |
|
| 1474 | - add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1475 | - // modify the default editor title field with default title. |
|
| 1476 | - add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
| 1477 | - $this->loadEditorTemplate(false); |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - |
|
| 1482 | - /** |
|
| 1483 | - * some getters |
|
| 1484 | - */ |
|
| 1485 | - /** |
|
| 1486 | - * This returns the protected _cpt_model_obj property |
|
| 1487 | - * |
|
| 1488 | - * @return EE_CPT_Base|null |
|
| 1489 | - */ |
|
| 1490 | - public function get_cpt_model_obj(): ?EE_CPT_Base |
|
| 1491 | - { |
|
| 1492 | - return $this->_cpt_model_obj; |
|
| 1493 | - } |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * default method for the 'edit' route for cpt admin pages |
|
| 1436 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
| 1437 | + * |
|
| 1438 | + * @return void |
|
| 1439 | + */ |
|
| 1440 | + protected function _edit_cpt_item() |
|
| 1441 | + { |
|
| 1442 | + global $post, $post_type, $post_type_object, $title; |
|
| 1443 | + $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
| 1444 | + $post = $post_id ? get_post($post_id, OBJECT, 'edit') : null; |
|
| 1445 | + if (empty($post)) { |
|
| 1446 | + wp_die( |
|
| 1447 | + esc_html__( |
|
| 1448 | + "You attempted to edit an item that doesn't exist. Perhaps it was deleted?", |
|
| 1449 | + 'event_espresso' |
|
| 1450 | + ) |
|
| 1451 | + ); |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + $post_lock = $this->request->getRequestParam('get-post-lock'); |
|
| 1455 | + if ($post_lock) { |
|
| 1456 | + wp_set_post_lock($post_id); |
|
| 1457 | + EEH_URL::safeRedirectAndExit(get_edit_post_link($post_id, 'url')); |
|
| 1458 | + } |
|
| 1459 | + |
|
| 1460 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
| 1461 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
| 1462 | + $post_type_object = $this->_cpt_object; |
|
| 1463 | + $title = $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
| 1464 | + ?? $post_type_object->labels->edit_item; |
|
| 1465 | + |
|
| 1466 | + if (! wp_check_post_lock($post->ID)) { |
|
| 1467 | + wp_set_post_lock($post->ID); |
|
| 1468 | + } |
|
| 1469 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
| 1470 | + if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
| 1471 | + wp_enqueue_script('admin-comments'); |
|
| 1472 | + enqueue_comment_hotkeys_js(); |
|
| 1473 | + } |
|
| 1474 | + add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
| 1475 | + // modify the default editor title field with default title. |
|
| 1476 | + add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
| 1477 | + $this->loadEditorTemplate(false); |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + |
|
| 1482 | + /** |
|
| 1483 | + * some getters |
|
| 1484 | + */ |
|
| 1485 | + /** |
|
| 1486 | + * This returns the protected _cpt_model_obj property |
|
| 1487 | + * |
|
| 1488 | + * @return EE_CPT_Base|null |
|
| 1489 | + */ |
|
| 1490 | + public function get_cpt_model_obj(): ?EE_CPT_Base |
|
| 1491 | + { |
|
| 1492 | + return $this->_cpt_model_obj; |
|
| 1493 | + } |
|
| 1494 | 1494 | } |
@@ -25,4332 +25,4332 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 27 | 27 | { |
| 28 | - protected ?EE_Admin_Config $admin_config = null; |
|
| 28 | + protected ?EE_Admin_Config $admin_config = null; |
|
| 29 | 29 | |
| 30 | - protected ?EE_Admin_Hooks $_hook_obj = null; |
|
| 30 | + protected ?EE_Admin_Hooks $_hook_obj = null; |
|
| 31 | 31 | |
| 32 | - protected ?EE_Admin_List_Table $_list_table_object = null; |
|
| 32 | + protected ?EE_Admin_List_Table $_list_table_object = null; |
|
| 33 | 33 | |
| 34 | - protected ?EE_Capabilities $capabilities = null; |
|
| 34 | + protected ?EE_Capabilities $capabilities = null; |
|
| 35 | 35 | |
| 36 | - protected ?EE_Registry $EE = null; |
|
| 36 | + protected ?EE_Registry $EE = null; |
|
| 37 | 37 | |
| 38 | - protected ?FeatureFlags $feature = null; |
|
| 38 | + protected ?FeatureFlags $feature = null; |
|
| 39 | 39 | |
| 40 | - protected ?LoaderInterface $loader = null; |
|
| 40 | + protected ?LoaderInterface $loader = null; |
|
| 41 | 41 | |
| 42 | - protected ?RequestInterface $request = null; |
|
| 42 | + protected ?RequestInterface $request = null; |
|
| 43 | 43 | |
| 44 | - protected ?WP_Screen $_current_screen = null; |
|
| 44 | + protected ?WP_Screen $_current_screen = null; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var array |
|
| 48 | - * @since 5.0.0.p |
|
| 49 | - */ |
|
| 50 | - private array $publish_post_meta_box_hidden_fields = []; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * some default things shared by all child classes |
|
| 54 | - * |
|
| 55 | - * @var string[] |
|
| 56 | - */ |
|
| 57 | - protected array $_default_espresso_metaboxes = [ |
|
| 58 | - '_espresso_news_post_box', |
|
| 59 | - '_espresso_links_post_box', |
|
| 60 | - '_espresso_ratings_request', |
|
| 61 | - '_espresso_sponsors_post_box', |
|
| 62 | - ]; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 66 | - * actions. |
|
| 67 | - * |
|
| 68 | - * @since 4.6.x |
|
| 69 | - */ |
|
| 70 | - protected array $_default_route_query_args = []; |
|
| 71 | - |
|
| 72 | - protected array $_labels = []; |
|
| 73 | - |
|
| 74 | - protected array $_nav_tabs = []; |
|
| 75 | - |
|
| 76 | - protected array $_page_config = []; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * action => method pairs used for routing incoming requests |
|
| 80 | - * |
|
| 81 | - * @var array |
|
| 82 | - */ |
|
| 83 | - protected array $_page_routes = []; |
|
| 84 | - |
|
| 85 | - protected array $_req_data = []; |
|
| 86 | - |
|
| 87 | - protected array $_route_config = []; |
|
| 88 | - |
|
| 89 | - protected array $_template_args = []; |
|
| 90 | - |
|
| 91 | - protected array $_views = []; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * yes / no array for admin form fields |
|
| 95 | - * |
|
| 96 | - * @var array|array[] |
|
| 97 | - */ |
|
| 98 | - protected array $_yes_no_values = []; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * this starts at null so we can have no header routes progress through two states. |
|
| 102 | - */ |
|
| 103 | - protected ?bool $_is_UI_request = null; |
|
| 104 | - |
|
| 105 | - protected bool $_is_caf = false; // This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 106 | - |
|
| 107 | - protected bool $_routing = false; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * whether initializePage() has run |
|
| 111 | - * |
|
| 112 | - * @var bool |
|
| 113 | - */ |
|
| 114 | - protected bool $initialized = false; |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - protected string $_admin_base_path = ''; |
|
| 118 | - |
|
| 119 | - protected string $_admin_base_url = ''; |
|
| 120 | - |
|
| 121 | - protected string $_admin_page_title = ''; |
|
| 122 | - |
|
| 123 | - protected string $_column_template_path = ''; |
|
| 124 | - |
|
| 125 | - protected bool $_cpt_route = false; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * set via request page and action args. |
|
| 129 | - */ |
|
| 130 | - protected string $_current_page = ''; |
|
| 131 | - |
|
| 132 | - protected string $_current_page_view_url = ''; |
|
| 133 | - |
|
| 134 | - protected string $_current_view = ''; |
|
| 135 | - |
|
| 136 | - protected string $_default_nav_tab_name = 'overview'; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * sanitized request action |
|
| 140 | - */ |
|
| 141 | - protected string $_req_action = ''; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * sanitized request action nonce |
|
| 145 | - */ |
|
| 146 | - protected string $_req_nonce = ''; |
|
| 147 | - |
|
| 148 | - protected string $_search_btn_label = ''; |
|
| 149 | - |
|
| 150 | - protected string $_template_path = ''; |
|
| 151 | - |
|
| 152 | - protected string $_view = ''; |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * set early within EE_Admin_Init |
|
| 156 | - * |
|
| 157 | - * @var string |
|
| 158 | - */ |
|
| 159 | - protected string $_wp_page_slug = ''; |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * if the current class is an admin page extension, like: Extend_Events_Admin_Page, |
|
| 163 | - * then this would be the parent classname: Events_Admin_Page |
|
| 164 | - * |
|
| 165 | - * @var string |
|
| 166 | - */ |
|
| 167 | - public string $base_class_name = ''; |
|
| 168 | - |
|
| 169 | - public string $class_name = ''; |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * unprocessed value for the 'action' request param (default '') |
|
| 173 | - * |
|
| 174 | - * @var string |
|
| 175 | - */ |
|
| 176 | - protected string $raw_req_action = ''; |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * unprocessed value for the 'page' request param (default '') |
|
| 180 | - * |
|
| 181 | - * @var string |
|
| 182 | - */ |
|
| 183 | - protected string $raw_req_page = ''; |
|
| 184 | - |
|
| 185 | - public string $page_folder = ''; |
|
| 186 | - |
|
| 187 | - public string $page_label = ''; |
|
| 188 | - |
|
| 189 | - public string $page_slug = ''; |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * the current page route and route config |
|
| 194 | - * |
|
| 195 | - * @var array|callable|string|null |
|
| 196 | - */ |
|
| 197 | - protected $_route = null; |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @Constructor |
|
| 202 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 203 | - * @throws InvalidArgumentException |
|
| 204 | - * @throws InvalidDataTypeException |
|
| 205 | - * @throws InvalidInterfaceException |
|
| 206 | - * @throws ReflectionException |
|
| 207 | - */ |
|
| 208 | - public function __construct($routing = true) |
|
| 209 | - { |
|
| 210 | - $this->loader = LoaderFactory::getLoader(); |
|
| 211 | - $this->admin_config = $this->loader->getShared(EE_Admin_Config::class); |
|
| 212 | - $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 213 | - $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 214 | - $this->capabilities = $this->loader->getShared(EE_Capabilities::class); |
|
| 215 | - // routing enabled? |
|
| 216 | - $this->_routing = $routing; |
|
| 217 | - |
|
| 218 | - $this->class_name = get_class($this); |
|
| 219 | - $this->base_class_name = strpos($this->class_name, 'Extend_') === 0 |
|
| 220 | - ? str_replace('Extend_', '', $this->class_name) |
|
| 221 | - : ''; |
|
| 222 | - |
|
| 223 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 224 | - $this->_is_caf = true; |
|
| 225 | - } |
|
| 226 | - $this->_yes_no_values = [ |
|
| 227 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 228 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 229 | - ]; |
|
| 230 | - // set the _req_data property. |
|
| 231 | - $this->_req_data = $this->request->requestParams(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @return EE_Admin_Config |
|
| 237 | - */ |
|
| 238 | - public function adminConfig(): EE_Admin_Config |
|
| 239 | - { |
|
| 240 | - return $this->admin_config; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @return FeatureFlags |
|
| 246 | - */ |
|
| 247 | - public function feature(): FeatureFlags |
|
| 248 | - { |
|
| 249 | - return $this->feature; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 255 | - * for child classes that needed to set properties prior to these methods getting called, |
|
| 256 | - * but also needed the parent class to have its construction completed as well. |
|
| 257 | - * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 258 | - * and any complex initialization logic should only run after instantiation is complete. |
|
| 259 | - * This method gets called immediately after construction from within |
|
| 260 | - * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 261 | - * |
|
| 262 | - * @throws EE_Error |
|
| 263 | - * @throws InvalidArgumentException |
|
| 264 | - * @throws InvalidDataTypeException |
|
| 265 | - * @throws InvalidInterfaceException |
|
| 266 | - * @throws ReflectionException |
|
| 267 | - * @throws Throwable |
|
| 268 | - * @since 5.0.0.p |
|
| 269 | - */ |
|
| 270 | - public function initializePage() |
|
| 271 | - { |
|
| 272 | - if ($this->initialized) { |
|
| 273 | - return; |
|
| 274 | - } |
|
| 275 | - // set initial page props (child method) |
|
| 276 | - $this->_init_page_props(); |
|
| 277 | - // set global defaults |
|
| 278 | - $this->_set_defaults(); |
|
| 279 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 280 | - $this->_global_ajax_hooks(); |
|
| 281 | - $this->_ajax_hooks(); |
|
| 282 | - // other_page_hooks have to be early too. |
|
| 283 | - $this->_do_other_page_hooks(); |
|
| 284 | - // set up page dependencies |
|
| 285 | - $this->_before_page_setup(); |
|
| 286 | - $this->_page_setup(); |
|
| 287 | - $this->initialized = true; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * _init_page_props |
|
| 293 | - * Child classes use to set at least the following properties: |
|
| 294 | - * $page_slug. |
|
| 295 | - * $page_label. |
|
| 296 | - * |
|
| 297 | - * @abstract |
|
| 298 | - * @return void |
|
| 299 | - */ |
|
| 300 | - abstract protected function _init_page_props(); |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * _ajax_hooks |
|
| 305 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 306 | - * Note: within the ajax callback methods. |
|
| 307 | - * |
|
| 308 | - * @abstract |
|
| 309 | - * @return void |
|
| 310 | - */ |
|
| 311 | - abstract protected function _ajax_hooks(); |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * _define_page_props |
|
| 316 | - * child classes define page properties in here. Must include at least: |
|
| 317 | - * $_admin_base_url = base_url for all admin pages |
|
| 318 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 319 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 320 | - * array( |
|
| 321 | - * 'buttons' => array( |
|
| 322 | - * 'add' => esc_html__('label for add new button'), |
|
| 323 | - * 'edit' => esc_html__('label for edit button'), |
|
| 324 | - * 'delete' => esc_html__('label for delete button') |
|
| 325 | - * ) |
|
| 326 | - * ) |
|
| 327 | - * |
|
| 328 | - * @abstract |
|
| 329 | - * @return void |
|
| 330 | - */ |
|
| 331 | - abstract protected function _define_page_props(); |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * _set_page_routes |
|
| 336 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 337 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 338 | - * have a 'default' route. Here's the format |
|
| 339 | - * $this->_page_routes = array( |
|
| 340 | - * 'default' => array( |
|
| 341 | - * 'func' => '_default_method_handling_route', |
|
| 342 | - * 'args' => array('array','of','args'), |
|
| 343 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 344 | - * ajax request, backend processing) |
|
| 345 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 346 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 347 | - * headers sent route. |
|
| 348 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 349 | - * this route. |
|
| 350 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 351 | - * checks). |
|
| 352 | - * ), |
|
| 353 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 354 | - * handling method. |
|
| 355 | - * ) |
|
| 356 | - * ) |
|
| 357 | - * |
|
| 358 | - * @abstract |
|
| 359 | - * @return void |
|
| 360 | - */ |
|
| 361 | - abstract protected function _set_page_routes(); |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * _set_page_config |
|
| 366 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 367 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 368 | - * $this->_page_config = array( |
|
| 369 | - * 'default' => array( |
|
| 370 | - * 'labels' => array( |
|
| 371 | - * 'buttons' => array( |
|
| 372 | - * 'add' => esc_html__('label for adding item'), |
|
| 373 | - * 'edit' => esc_html__('label for editing item'), |
|
| 374 | - * 'delete' => esc_html__('label for deleting item') |
|
| 375 | - * ), |
|
| 376 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 377 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 378 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 379 | - * _define_page_props() method |
|
| 380 | - * 'nav' => array( |
|
| 381 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 382 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 383 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 384 | - * 'order' => 10, //required to indicate tab position. |
|
| 385 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 386 | - * displayed then add this parameter. |
|
| 387 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 388 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 389 | - * metaboxes set for eventespresso admin pages. |
|
| 390 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 391 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 392 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 393 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 394 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 395 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 396 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 397 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 398 | - * want to display. |
|
| 399 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 400 | - * 'tab_id' => array( |
|
| 401 | - * 'title' => 'tab_title', |
|
| 402 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 403 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 404 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 405 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 406 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 407 | - * attempt to use the callback which should match the name of a method in the class |
|
| 408 | - * ), |
|
| 409 | - * 'tab2_id' => array( |
|
| 410 | - * 'title' => 'tab2 title', |
|
| 411 | - * 'filename' => 'file_name_2' |
|
| 412 | - * 'callback' => 'callback_method_for_content', |
|
| 413 | - * ), |
|
| 414 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 415 | - * help tab area on an admin page. @return void |
|
| 416 | - * |
|
| 417 | - * @abstract |
|
| 418 | - */ |
|
| 419 | - abstract protected function _set_page_config(); |
|
| 46 | + /** |
|
| 47 | + * @var array |
|
| 48 | + * @since 5.0.0.p |
|
| 49 | + */ |
|
| 50 | + private array $publish_post_meta_box_hidden_fields = []; |
|
| 420 | 51 | |
| 52 | + /** |
|
| 53 | + * some default things shared by all child classes |
|
| 54 | + * |
|
| 55 | + * @var string[] |
|
| 56 | + */ |
|
| 57 | + protected array $_default_espresso_metaboxes = [ |
|
| 58 | + '_espresso_news_post_box', |
|
| 59 | + '_espresso_links_post_box', |
|
| 60 | + '_espresso_ratings_request', |
|
| 61 | + '_espresso_sponsors_post_box', |
|
| 62 | + ]; |
|
| 421 | 63 | |
| 422 | - /** |
|
| 423 | - * _add_screen_options |
|
| 424 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 425 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 426 | - * to a particular view. |
|
| 427 | - * |
|
| 428 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 429 | - * see also WP_Screen object documents... |
|
| 430 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 431 | - * @abstract |
|
| 432 | - * @return void |
|
| 433 | - */ |
|
| 434 | - abstract protected function _add_screen_options(); |
|
| 64 | + /** |
|
| 65 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 66 | + * actions. |
|
| 67 | + * |
|
| 68 | + * @since 4.6.x |
|
| 69 | + */ |
|
| 70 | + protected array $_default_route_query_args = []; |
|
| 435 | 71 | |
| 72 | + protected array $_labels = []; |
|
| 436 | 73 | |
| 437 | - /** |
|
| 438 | - * _add_feature_pointers |
|
| 439 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 440 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 441 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 442 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 443 | - * extended) also see: |
|
| 444 | - * |
|
| 445 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 446 | - * @abstract |
|
| 447 | - * @return void |
|
| 448 | - */ |
|
| 449 | - abstract protected function _add_feature_pointers(); |
|
| 74 | + protected array $_nav_tabs = []; |
|
| 450 | 75 | |
| 76 | + protected array $_page_config = []; |
|
| 451 | 77 | |
| 452 | - /** |
|
| 453 | - * load_scripts_styles |
|
| 454 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 455 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 456 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 457 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 458 | - * |
|
| 459 | - * @abstract |
|
| 460 | - * @return void |
|
| 461 | - */ |
|
| 462 | - abstract public function load_scripts_styles(); |
|
| 78 | + /** |
|
| 79 | + * action => method pairs used for routing incoming requests |
|
| 80 | + * |
|
| 81 | + * @var array |
|
| 82 | + */ |
|
| 83 | + protected array $_page_routes = []; |
|
| 463 | 84 | |
| 85 | + protected array $_req_data = []; |
|
| 464 | 86 | |
| 465 | - /** |
|
| 466 | - * admin_init |
|
| 467 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 468 | - * all pages/views loaded by child class. |
|
| 469 | - * |
|
| 470 | - * @abstract |
|
| 471 | - * @return void |
|
| 472 | - */ |
|
| 473 | - abstract public function admin_init(); |
|
| 474 | - |
|
| 87 | + protected array $_route_config = []; |
|
| 475 | 88 | |
| 476 | - /** |
|
| 477 | - * admin_notices |
|
| 478 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 479 | - * all pages/views loaded by child class. |
|
| 480 | - * |
|
| 481 | - * @abstract |
|
| 482 | - * @return void |
|
| 483 | - */ |
|
| 484 | - abstract public function admin_notices(); |
|
| 89 | + protected array $_template_args = []; |
|
| 485 | 90 | |
| 91 | + protected array $_views = []; |
|
| 486 | 92 | |
| 487 | - /** |
|
| 488 | - * admin_footer_scripts |
|
| 489 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 490 | - * will apply to all pages/views loaded by child class. |
|
| 491 | - * |
|
| 492 | - * @return void |
|
| 493 | - */ |
|
| 494 | - abstract public function admin_footer_scripts(); |
|
| 93 | + /** |
|
| 94 | + * yes / no array for admin form fields |
|
| 95 | + * |
|
| 96 | + * @var array|array[] |
|
| 97 | + */ |
|
| 98 | + protected array $_yes_no_values = []; |
|
| 495 | 99 | |
| 100 | + /** |
|
| 101 | + * this starts at null so we can have no header routes progress through two states. |
|
| 102 | + */ |
|
| 103 | + protected ?bool $_is_UI_request = null; |
|
| 496 | 104 | |
| 497 | - /** |
|
| 498 | - * admin_footer |
|
| 499 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 500 | - * apply to all pages/views loaded by child class. |
|
| 501 | - * |
|
| 502 | - * @return void |
|
| 503 | - */ |
|
| 504 | - public function admin_footer() |
|
| 505 | - { |
|
| 506 | - } |
|
| 105 | + protected bool $_is_caf = false; // This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 507 | 106 | |
| 107 | + protected bool $_routing = false; |
|
| 508 | 108 | |
| 509 | - /** |
|
| 510 | - * _global_ajax_hooks |
|
| 511 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 512 | - * Note: within the ajax callback methods. |
|
| 513 | - * |
|
| 514 | - * @abstract |
|
| 515 | - * @return void |
|
| 516 | - */ |
|
| 517 | - protected function _global_ajax_hooks() |
|
| 518 | - { |
|
| 519 | - // for lazy loading of metabox content |
|
| 520 | - add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content']); |
|
| 521 | - |
|
| 522 | - add_action( |
|
| 523 | - 'wp_ajax_espresso_hide_status_change_notice', |
|
| 524 | - [$this, 'hideStatusChangeNotice'] |
|
| 525 | - ); |
|
| 526 | - add_action( |
|
| 527 | - 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 528 | - [$this, 'hideStatusChangeNotice'] |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - public function ajax_metabox_content() |
|
| 534 | - { |
|
| 535 | - $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 536 | - $content_url = $this->request->getRequestParam('contenturl', '', DataType::URL); |
|
| 537 | - EE_Admin_Page::cached_rss_display($content_id, $content_url); |
|
| 538 | - wp_die(); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - public function hideStatusChangeNotice() |
|
| 543 | - { |
|
| 544 | - $response = []; |
|
| 545 | - try { |
|
| 546 | - /** @var StatusChangeNotice $status_change_notice */ |
|
| 547 | - $status_change_notice = $this->loader->getShared( |
|
| 548 | - 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 549 | - ); |
|
| 550 | - $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 551 | - } catch (Exception $exception) { |
|
| 552 | - $response['errors'] = $exception->getMessage(); |
|
| 553 | - } |
|
| 554 | - echo wp_json_encode($response); |
|
| 555 | - exit(); |
|
| 556 | - } |
|
| 109 | + /** |
|
| 110 | + * whether initializePage() has run |
|
| 111 | + * |
|
| 112 | + * @var bool |
|
| 113 | + */ |
|
| 114 | + protected bool $initialized = false; |
|
| 557 | 115 | |
| 558 | 116 | |
| 559 | - /** |
|
| 560 | - * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 561 | - * |
|
| 562 | - * @return void |
|
| 563 | - */ |
|
| 564 | - protected function _before_page_setup() |
|
| 565 | - { |
|
| 566 | - // default is to do nothing |
|
| 567 | - } |
|
| 117 | + protected string $_admin_base_path = ''; |
|
| 568 | 118 | |
| 119 | + protected string $_admin_base_url = ''; |
|
| 569 | 120 | |
| 570 | - /** |
|
| 571 | - * Makes sure any things that need to be loaded early get handled. |
|
| 572 | - * We also escape early here if the page requested doesn't match the object. |
|
| 573 | - * |
|
| 574 | - * @final |
|
| 575 | - * @return void |
|
| 576 | - * @throws EE_Error |
|
| 577 | - * @throws InvalidArgumentException |
|
| 578 | - * @throws ReflectionException |
|
| 579 | - * @throws InvalidDataTypeException |
|
| 580 | - * @throws InvalidInterfaceException |
|
| 581 | - * @throws Throwable |
|
| 582 | - */ |
|
| 583 | - final protected function _page_setup() |
|
| 584 | - { |
|
| 585 | - // requires? |
|
| 586 | - // admin_init stuff - global - we're setting this REALLY early |
|
| 587 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 588 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 589 | - add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 590 | - // next verify if we need to load anything... |
|
| 591 | - $this->_current_page = $this->request->getRequestParam('page', '', DataType::KEY); |
|
| 592 | - $this->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, DataType::KEY); |
|
| 593 | - $this->page_folder = strtolower( |
|
| 594 | - str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name) |
|
| 595 | - ); |
|
| 596 | - global $ee_menu_slugs; |
|
| 597 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 598 | - if ( |
|
| 599 | - ! $this->request->isAjax() |
|
| 600 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 601 | - ) { |
|
| 602 | - return; |
|
| 603 | - } |
|
| 604 | - // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 605 | - // we need to copy the action from the second to the first |
|
| 606 | - $action = $this->request->getRequestParam('action', '-1', DataType::KEY); |
|
| 607 | - $action2 = $this->request->getRequestParam('action2', '-1', DataType::KEY); |
|
| 608 | - $action = $action !== '-1' ? $action : $action2; |
|
| 609 | - $req_action = $action !== '-1' ? $action : 'default'; |
|
| 610 | - |
|
| 611 | - // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 612 | - // then let's use the route as the action. |
|
| 613 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 614 | - $route = $this->request->getRequestParam('route'); |
|
| 615 | - $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 616 | - ? $route |
|
| 617 | - : $req_action; |
|
| 618 | - $this->_current_view = $this->_req_action; |
|
| 619 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 620 | - $this->_define_page_props(); |
|
| 621 | - $this->_current_page_view_url = add_query_arg( |
|
| 622 | - ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 623 | - $this->_admin_base_url |
|
| 624 | - ); |
|
| 625 | - // set page configs |
|
| 626 | - $this->_set_page_routes(); |
|
| 627 | - $this->_set_page_config(); |
|
| 628 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 629 | - if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 630 | - $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 631 | - if ($wp_referer) { |
|
| 632 | - $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - // for CPT and other extended functionality. |
|
| 636 | - // If there is an _extend_page_config_for_cpt |
|
| 637 | - // then let's run that to modify all the various page configuration arrays. |
|
| 638 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 639 | - $this->_extend_page_config_for_cpt(); |
|
| 640 | - } |
|
| 641 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 642 | - $this->_page_routes = apply_filters( |
|
| 643 | - 'FHEE__' . $this->class_name . '__page_setup__page_routes', |
|
| 644 | - $this->_page_routes, |
|
| 645 | - $this |
|
| 646 | - ); |
|
| 647 | - $this->_page_config = apply_filters( |
|
| 648 | - 'FHEE__' . $this->class_name . '__page_setup__page_config', |
|
| 649 | - $this->_page_config, |
|
| 650 | - $this |
|
| 651 | - ); |
|
| 652 | - if ($this->base_class_name !== '') { |
|
| 653 | - $this->_page_routes = apply_filters( |
|
| 654 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_routes', |
|
| 655 | - $this->_page_routes, |
|
| 656 | - $this |
|
| 657 | - ); |
|
| 658 | - $this->_page_config = apply_filters( |
|
| 659 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_config', |
|
| 660 | - $this->_page_config, |
|
| 661 | - $this |
|
| 662 | - ); |
|
| 663 | - } |
|
| 664 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 665 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 666 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 667 | - add_action( |
|
| 668 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 669 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 670 | - 10, |
|
| 671 | - 2 |
|
| 672 | - ); |
|
| 673 | - } |
|
| 674 | - // next route only if routing enabled |
|
| 675 | - if ($this->_routing && ! $this->request->isAjax()) { |
|
| 676 | - $this->_verify_routes(); |
|
| 677 | - // next let's just check user_access and kill if no access |
|
| 678 | - $this->check_user_access(); |
|
| 679 | - if ($this->_is_UI_request) { |
|
| 680 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 681 | - add_action('admin_init', [$this, 'admin_init']); |
|
| 682 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 683 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 684 | - } |
|
| 685 | - } else { |
|
| 686 | - // hijack regular WP loading and route admin request immediately |
|
| 687 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 688 | - $this->route_admin_request(); |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - } |
|
| 121 | + protected string $_admin_page_title = ''; |
|
| 692 | 122 | |
| 123 | + protected string $_column_template_path = ''; |
|
| 693 | 124 | |
| 694 | - /** |
|
| 695 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 696 | - * |
|
| 697 | - * @return void |
|
| 698 | - * @throws EE_Error |
|
| 699 | - */ |
|
| 700 | - private function _do_other_page_hooks() |
|
| 701 | - { |
|
| 702 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 703 | - foreach ($registered_pages as $page) { |
|
| 704 | - // now let's setup the file name and class that should be present |
|
| 705 | - $classname = str_replace('.class.php', '', $page); |
|
| 706 | - // autoloaders should take care of loading file |
|
| 707 | - if (! class_exists($classname)) { |
|
| 708 | - $error_msg[] = sprintf( |
|
| 709 | - esc_html__( |
|
| 710 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 711 | - 'event_espresso' |
|
| 712 | - ), |
|
| 713 | - $page |
|
| 714 | - ); |
|
| 715 | - $error_msg[] = $error_msg[0] |
|
| 716 | - . "\r\n" |
|
| 717 | - . sprintf( |
|
| 718 | - esc_html__( |
|
| 719 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 720 | - 'event_espresso' |
|
| 721 | - ), |
|
| 722 | - $page, |
|
| 723 | - '<br />', |
|
| 724 | - '<strong>' . $classname . '</strong>' |
|
| 725 | - ); |
|
| 726 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 727 | - } |
|
| 728 | - // don't load the same class twice |
|
| 729 | - static $loaded = []; |
|
| 730 | - if (in_array($classname, $loaded, true)) { |
|
| 731 | - continue; |
|
| 732 | - } |
|
| 733 | - $loaded[] = $classname; |
|
| 734 | - // notice we are passing the instance of this class to the hook object. |
|
| 735 | - $this->loader->getShared($classname, [$this]); |
|
| 736 | - } |
|
| 737 | - } |
|
| 125 | + protected bool $_cpt_route = false; |
|
| 738 | 126 | |
| 127 | + /** |
|
| 128 | + * set via request page and action args. |
|
| 129 | + */ |
|
| 130 | + protected string $_current_page = ''; |
|
| 739 | 131 | |
| 740 | - /** |
|
| 741 | - * @throws ReflectionException |
|
| 742 | - * @throws EE_Error |
|
| 743 | - */ |
|
| 744 | - public function load_page_dependencies() |
|
| 745 | - { |
|
| 746 | - try { |
|
| 747 | - $this->_load_page_dependencies(); |
|
| 748 | - } catch (EE_Error $e) { |
|
| 749 | - $e->get_error(); |
|
| 750 | - } |
|
| 751 | - } |
|
| 132 | + protected string $_current_page_view_url = ''; |
|
| 752 | 133 | |
| 134 | + protected string $_current_view = ''; |
|
| 753 | 135 | |
| 754 | - /** |
|
| 755 | - * load_page_dependencies |
|
| 756 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 757 | - * |
|
| 758 | - * @return void |
|
| 759 | - * @throws DomainException |
|
| 760 | - * @throws EE_Error |
|
| 761 | - * @throws InvalidArgumentException |
|
| 762 | - * @throws InvalidDataTypeException |
|
| 763 | - * @throws InvalidInterfaceException |
|
| 764 | - * @throws ReflectionException |
|
| 765 | - */ |
|
| 766 | - protected function _load_page_dependencies() |
|
| 767 | - { |
|
| 768 | - // let's set the current_screen and screen options to override what WP set |
|
| 769 | - $this->_current_screen = get_current_screen(); |
|
| 770 | - // load admin_notices - global, page class, and view specific |
|
| 771 | - add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 772 | - add_action('admin_notices', [$this, 'admin_notices']); |
|
| 773 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 774 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 775 | - } |
|
| 776 | - // load network admin_notices - global, page class, and view specific |
|
| 777 | - add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 778 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 779 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 780 | - } |
|
| 781 | - // this will save any per_page screen options if they are present |
|
| 782 | - $this->_set_per_page_screen_options(); |
|
| 783 | - // setup list table properties |
|
| 784 | - $this->_set_list_table(); |
|
| 785 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 786 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 787 | - add_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99); |
|
| 788 | - // hack because promos admin was loading the edited promotion object in the metaboxes callback |
|
| 789 | - // which should NOT be generated on non-UI requests like POST updates/inserts |
|
| 790 | - if ( |
|
| 791 | - $this->class_name === 'Promotions_Admin_Page' |
|
| 792 | - && ($this->_req_action === 'edit' || $this->_req_action === 'create_new') |
|
| 793 | - ) { |
|
| 794 | - $this->addRegisteredMetaBoxes(); |
|
| 795 | - } |
|
| 796 | - $this->_add_screen_columns(); |
|
| 797 | - // add screen options - global, page child class, and view specific |
|
| 798 | - $this->_add_global_screen_options(); |
|
| 799 | - $this->_add_screen_options(); |
|
| 800 | - $add_screen_options = "_add_screen_options_$this->_current_view"; |
|
| 801 | - if (method_exists($this, $add_screen_options)) { |
|
| 802 | - $this->{$add_screen_options}(); |
|
| 803 | - } |
|
| 804 | - // add help tab(s) - set via page_config and qtips. |
|
| 805 | - $this->_add_help_tabs(); |
|
| 806 | - $this->_add_qtips(); |
|
| 807 | - // add feature_pointers - global, page child class, and view specific |
|
| 808 | - $this->_add_feature_pointers(); |
|
| 809 | - $this->_add_global_feature_pointers(); |
|
| 810 | - $add_feature_pointer = "_add_feature_pointer_$this->_current_view"; |
|
| 811 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 812 | - $this->{$add_feature_pointer}(); |
|
| 813 | - } |
|
| 814 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 815 | - add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 816 | - add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles']); |
|
| 817 | - if (method_exists($this, "load_scripts_styles_$this->_current_view")) { |
|
| 818 | - add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_$this->_current_view"], 15); |
|
| 819 | - } |
|
| 820 | - add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 821 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 822 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 823 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 824 | - // is a good use case. Notice the late priority we're giving these |
|
| 825 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 826 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 827 | - if (method_exists($this, "admin_footer_scripts_$this->_current_view")) { |
|
| 828 | - add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_$this->_current_view"], 101); |
|
| 829 | - } |
|
| 830 | - // admin footer scripts |
|
| 831 | - add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 832 | - add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 833 | - if (method_exists($this, "admin_footer_$this->_current_view")) { |
|
| 834 | - add_action('admin_footer', [$this, "admin_footer_$this->_current_view"], 101); |
|
| 835 | - } |
|
| 836 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 837 | - // targeted hook |
|
| 838 | - do_action( |
|
| 839 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__$this->_req_action" |
|
| 840 | - ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * _set_defaults |
|
| 846 | - * This sets some global defaults for class properties. |
|
| 847 | - */ |
|
| 848 | - private function _set_defaults() |
|
| 849 | - { |
|
| 850 | - // init template args |
|
| 851 | - $this->set_template_args( |
|
| 852 | - [ |
|
| 853 | - 'admin_page_header' => '', |
|
| 854 | - 'admin_page_content' => '', |
|
| 855 | - 'post_body_content' => '', |
|
| 856 | - 'before_list_table' => '', |
|
| 857 | - 'after_list_table' => '', |
|
| 858 | - ] |
|
| 859 | - ); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * route_admin_request |
|
| 865 | - * |
|
| 866 | - * @return void |
|
| 867 | - * @throws InvalidArgumentException |
|
| 868 | - * @throws InvalidInterfaceException |
|
| 869 | - * @throws InvalidDataTypeException |
|
| 870 | - * @throws EE_Error |
|
| 871 | - * @throws ReflectionException |
|
| 872 | - * @throws Throwable |
|
| 873 | - * @see _route_admin_request() |
|
| 874 | - */ |
|
| 875 | - public function route_admin_request() |
|
| 876 | - { |
|
| 877 | - try { |
|
| 878 | - $this->_route_admin_request(); |
|
| 879 | - } catch (EE_Error $e) { |
|
| 880 | - $e->get_error(); |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - public function set_wp_page_slug($wp_page_slug) |
|
| 886 | - { |
|
| 887 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 888 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 889 | - if (is_network_admin()) { |
|
| 890 | - $this->_wp_page_slug .= '-network'; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * _verify_routes |
|
| 897 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 898 | - * we know if we need to drop out. |
|
| 899 | - * |
|
| 900 | - * @return bool |
|
| 901 | - * @throws EE_Error |
|
| 902 | - */ |
|
| 903 | - protected function _verify_routes(): bool |
|
| 904 | - { |
|
| 905 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 906 | - return false; |
|
| 907 | - } |
|
| 908 | - // check that the page_routes array is not empty |
|
| 909 | - if (empty($this->_page_routes)) { |
|
| 910 | - // user error msg |
|
| 911 | - $error_msg = sprintf( |
|
| 912 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 913 | - $this->_admin_page_title |
|
| 914 | - ); |
|
| 915 | - // developer error msg |
|
| 916 | - $error_msg .= '||' . $error_msg |
|
| 917 | - . esc_html__( |
|
| 918 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 919 | - 'event_espresso' |
|
| 920 | - ); |
|
| 921 | - throw new EE_Error($error_msg); |
|
| 922 | - } |
|
| 923 | - // route 'editpost' routes to CPT 'edit' routes |
|
| 924 | - $alt_edit_route = $this instanceof EE_Admin_Page_CPT ? $this->cpt_editpost_route : 'edit'; |
|
| 925 | - if ( |
|
| 926 | - $this->_req_action === 'editpost' |
|
| 927 | - && ! isset($this->_page_routes['editpost']) |
|
| 928 | - && isset($this->_page_routes[$alt_edit_route]) |
|
| 929 | - ) { |
|
| 930 | - $this->_req_action = $alt_edit_route; |
|
| 931 | - } |
|
| 932 | - // and that the requested page route exists |
|
| 933 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 934 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 935 | - $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 936 | - } else { |
|
| 937 | - // user error msg |
|
| 938 | - $error_msg = sprintf( |
|
| 939 | - esc_html__( |
|
| 940 | - 'The requested page route does not exist for the %s admin page.', |
|
| 941 | - 'event_espresso' |
|
| 942 | - ), |
|
| 943 | - $this->_admin_page_title |
|
| 944 | - ); |
|
| 945 | - // developer error msg |
|
| 946 | - $error_msg .= '||' . $error_msg |
|
| 947 | - . sprintf( |
|
| 948 | - esc_html__( |
|
| 949 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 950 | - 'event_espresso' |
|
| 951 | - ), |
|
| 952 | - $this->_req_action |
|
| 953 | - ); |
|
| 954 | - throw new EE_Error($error_msg); |
|
| 955 | - } |
|
| 956 | - // and that a default route exists |
|
| 957 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 958 | - // user error msg |
|
| 959 | - $error_msg = sprintf( |
|
| 960 | - esc_html__( |
|
| 961 | - 'A default page route has not been set for the % admin page.', |
|
| 962 | - 'event_espresso' |
|
| 963 | - ), |
|
| 964 | - $this->_admin_page_title |
|
| 965 | - ); |
|
| 966 | - // developer error msg |
|
| 967 | - $error_msg .= '||' . $error_msg |
|
| 968 | - . esc_html__( |
|
| 969 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 970 | - 'event_espresso' |
|
| 971 | - ); |
|
| 972 | - throw new EE_Error($error_msg); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - // first lets' catch if the UI request has EVER been set. |
|
| 976 | - if ($this->_is_UI_request === null) { |
|
| 977 | - // lets set if this is a UI request or not. |
|
| 978 | - $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, DataType::BOOL); |
|
| 979 | - // wait a minute... we might have a noheader in the route array |
|
| 980 | - $this->_is_UI_request = ! (isset($this->_route['noheader']) && $this->_route['noheader']) |
|
| 981 | - ? $this->_is_UI_request |
|
| 982 | - : false; |
|
| 983 | - } |
|
| 984 | - $this->_set_current_labels(); |
|
| 985 | - return true; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 991 | - * |
|
| 992 | - * @param string $route the route name we're verifying |
|
| 993 | - * @return bool we'll throw an exception if this isn't a valid route. |
|
| 994 | - * @throws EE_Error |
|
| 995 | - */ |
|
| 996 | - protected function _verify_route(string $route): bool |
|
| 997 | - { |
|
| 998 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 999 | - return true; |
|
| 1000 | - } |
|
| 1001 | - // user error msg |
|
| 1002 | - $error_msg = sprintf( |
|
| 1003 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 1004 | - $this->_admin_page_title |
|
| 1005 | - ); |
|
| 1006 | - // developer error msg |
|
| 1007 | - $error_msg .= '||' . $error_msg |
|
| 1008 | - . sprintf( |
|
| 1009 | - esc_html__( |
|
| 1010 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 1011 | - 'event_espresso' |
|
| 1012 | - ), |
|
| 1013 | - $route |
|
| 1014 | - ); |
|
| 1015 | - throw new EE_Error($error_msg); |
|
| 1016 | - } |
|
| 136 | + protected string $_default_nav_tab_name = 'overview'; |
|
| 1017 | 137 | |
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * perform nonce verification |
|
| 1021 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 1022 | - * using this method (and save retyping!) |
|
| 1023 | - * |
|
| 1024 | - * @param string $nonce The nonce sent |
|
| 1025 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 1026 | - * @return void |
|
| 1027 | - * @throws EE_Error |
|
| 1028 | - * @throws InvalidArgumentException |
|
| 1029 | - * @throws InvalidDataTypeException |
|
| 1030 | - * @throws InvalidInterfaceException |
|
| 1031 | - */ |
|
| 1032 | - protected function _verify_nonce(string $nonce, string $nonce_ref) |
|
| 1033 | - { |
|
| 1034 | - // verify nonce against expected value |
|
| 1035 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1036 | - // these are not the droids you are looking for !!! |
|
| 1037 | - $msg = sprintf( |
|
| 1038 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1039 | - '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1040 | - '</a>' |
|
| 1041 | - ); |
|
| 1042 | - if (WP_DEBUG) { |
|
| 1043 | - $msg .= "\n "; |
|
| 1044 | - $msg .= sprintf( |
|
| 1045 | - esc_html__( |
|
| 1046 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1047 | - 'event_espresso' |
|
| 1048 | - ), |
|
| 1049 | - __CLASS__ |
|
| 1050 | - ); |
|
| 1051 | - } |
|
| 1052 | - if (! $this->request->isAjax()) { |
|
| 1053 | - wp_die($msg); |
|
| 1054 | - } |
|
| 1055 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1056 | - $this->_return_json(); |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * _route_admin_request() |
|
| 1063 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1064 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1065 | - * in the page routes and then will try to load the corresponding method. |
|
| 1066 | - * |
|
| 1067 | - * @return void |
|
| 1068 | - * @throws EE_Error |
|
| 1069 | - * @throws InvalidArgumentException |
|
| 1070 | - * @throws InvalidDataTypeException |
|
| 1071 | - * @throws InvalidInterfaceException |
|
| 1072 | - * @throws ReflectionException |
|
| 1073 | - * @throws Throwable |
|
| 1074 | - */ |
|
| 1075 | - protected function _route_admin_request() |
|
| 1076 | - { |
|
| 1077 | - if (! $this->_is_UI_request) { |
|
| 1078 | - $this->_verify_routes(); |
|
| 1079 | - } |
|
| 1080 | - $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1081 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1082 | - // set nonce from post data |
|
| 1083 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1084 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1085 | - } |
|
| 1086 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 1087 | - if ($this->_is_UI_request) { |
|
| 1088 | - $this->_set_nav_tabs(); |
|
| 1089 | - } |
|
| 1090 | - // grab callback function |
|
| 1091 | - $func = $this->_route['func'] ?? $this->_route; |
|
| 1092 | - // check if callback has args |
|
| 1093 | - $args = $this->_route['args'] ?? []; |
|
| 1094 | - |
|
| 1095 | - // action right before calling route |
|
| 1096 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1097 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1098 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1099 | - } |
|
| 1100 | - // strip _wp_http_referer from the server REQUEST_URI |
|
| 1101 | - // else it grows in length on every submission due to recursion, |
|
| 1102 | - // ultimately causing a "Request-URI Too Large" error |
|
| 1103 | - $this->request->unSetRequestParam('_wp_http_referer'); |
|
| 1104 | - $this->request->unSetServerParam('_wp_http_referer'); |
|
| 1105 | - $cleaner_request_uri = remove_query_arg( |
|
| 1106 | - '_wp_http_referer', |
|
| 1107 | - wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1108 | - ); |
|
| 1109 | - $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri, true); |
|
| 1110 | - $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri, true); |
|
| 1111 | - $route_callback = []; |
|
| 1112 | - if (! empty($func)) { |
|
| 1113 | - if (is_array($func) && is_callable($func)) { |
|
| 1114 | - $route_callback = $func; |
|
| 1115 | - } elseif (is_string($func)) { |
|
| 1116 | - if (strpos($func, '::') !== false) { |
|
| 1117 | - $route_callback = explode('::', $func); |
|
| 1118 | - } elseif (method_exists($this, $func)) { |
|
| 1119 | - $route_callback = [$this, $func]; |
|
| 1120 | - } else { |
|
| 1121 | - $route_callback = $func; |
|
| 1122 | - } |
|
| 1123 | - } |
|
| 1124 | - [$class, $method] = $route_callback; |
|
| 1125 | - // is it neither a class method NOR a standalone function? |
|
| 1126 | - if (! is_callable($route_callback)) { |
|
| 1127 | - // user error msg |
|
| 1128 | - $error_msg = esc_html__( |
|
| 1129 | - 'An error occurred. The requested page route could not be found.', |
|
| 1130 | - 'event_espresso' |
|
| 1131 | - ); |
|
| 1132 | - // developer error msg |
|
| 1133 | - $error_msg .= '||'; |
|
| 1134 | - $error_msg .= sprintf( |
|
| 1135 | - esc_html__( |
|
| 1136 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1137 | - 'event_espresso' |
|
| 1138 | - ), |
|
| 1139 | - $method |
|
| 1140 | - ); |
|
| 1141 | - throw new DomainException($error_msg); |
|
| 1142 | - } |
|
| 1143 | - if ($class !== $this && ! in_array($this, $args)) { |
|
| 1144 | - // send along this admin page object for access by addons. |
|
| 1145 | - $args['admin_page'] = $this; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - try { |
|
| 1149 | - call_user_func_array($route_callback, $args); |
|
| 1150 | - } catch (Throwable $throwable) { |
|
| 1151 | - $nice_args = []; |
|
| 1152 | - foreach ($args as $key => $arg) { |
|
| 1153 | - $nice_args[ $key ] = is_object($arg) ? get_class($arg) : $key; |
|
| 1154 | - } |
|
| 1155 | - new ExceptionStackTraceDisplay( |
|
| 1156 | - new RuntimeException( |
|
| 1157 | - sprintf( |
|
| 1158 | - esc_html__( |
|
| 1159 | - 'Page route "%1$s" with the supplied arguments (%2$s) threw the following exception: %3$s', |
|
| 1160 | - 'event_espresso' |
|
| 1161 | - ), |
|
| 1162 | - $method, |
|
| 1163 | - implode(', ', $nice_args), |
|
| 1164 | - $throwable->getMessage() |
|
| 1165 | - ), |
|
| 1166 | - $throwable->getCode(), |
|
| 1167 | - $throwable |
|
| 1168 | - ) |
|
| 1169 | - ); |
|
| 1170 | - } |
|
| 1171 | - } |
|
| 1172 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1173 | - // then we need to reset the routing properties to the new route. |
|
| 1174 | - // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1175 | - if ( |
|
| 1176 | - $this->_is_UI_request === false |
|
| 1177 | - && is_array($this->_route) |
|
| 1178 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1179 | - ) { |
|
| 1180 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1181 | - } |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1187 | - * route redirects to a headers route in its route config. |
|
| 1188 | - * |
|
| 1189 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1190 | - * @return void |
|
| 1191 | - * @throws ReflectionException |
|
| 1192 | - * @throws InvalidArgumentException |
|
| 1193 | - * @throws InvalidInterfaceException |
|
| 1194 | - * @throws InvalidDataTypeException |
|
| 1195 | - * @throws EE_Error |
|
| 1196 | - * @throws Throwable |
|
| 1197 | - * @since 4.3.0 |
|
| 1198 | - */ |
|
| 1199 | - protected function _reset_routing_properties(string $new_route) |
|
| 1200 | - { |
|
| 1201 | - $this->_is_UI_request = true; |
|
| 1202 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1203 | - $this->request->setRequestParam('action', $new_route); |
|
| 1204 | - // rerun page setup |
|
| 1205 | - $this->_page_setup(); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - |
|
| 1209 | - /** |
|
| 1210 | - * _add_query_arg |
|
| 1211 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1212 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1213 | - * |
|
| 1214 | - * @param array $args |
|
| 1215 | - * @param string $url |
|
| 1216 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1217 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1218 | - * Example usage: If the current page is: |
|
| 1219 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1220 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1221 | - * &_wpnonce=5467821 |
|
| 1222 | - * and you call: |
|
| 1223 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1224 | - * array( |
|
| 1225 | - * 'action' => 'resend_something', |
|
| 1226 | - * 'page=>espresso_registrations' |
|
| 1227 | - * ), |
|
| 1228 | - * $some_url, |
|
| 1229 | - * true |
|
| 1230 | - * ); |
|
| 1231 | - * It will produce a url in this structure: |
|
| 1232 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1233 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1234 | - * month_range]=March%202015 |
|
| 1235 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1236 | - * @param int $context |
|
| 1237 | - * @return string |
|
| 1238 | - */ |
|
| 1239 | - public static function add_query_args_and_nonce( |
|
| 1240 | - array $args = [], |
|
| 1241 | - string $url = '', |
|
| 1242 | - bool $sticky = false, |
|
| 1243 | - bool $exclude_nonce = false, |
|
| 1244 | - int $context = EEH_URL::CONTEXT_NONE |
|
| 1245 | - ): string { |
|
| 1246 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1247 | - if ($sticky) { |
|
| 1248 | - /** @var RequestInterface $request */ |
|
| 1249 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1250 | - $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true); |
|
| 1251 | - $request->unSetServerParam('_wp_http_referer', true); |
|
| 1252 | - foreach ($request->requestParams() as $key => $value) { |
|
| 1253 | - // do not add nonces |
|
| 1254 | - if (strpos($key, 'nonce') !== false) { |
|
| 1255 | - continue; |
|
| 1256 | - } |
|
| 1257 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1258 | - } |
|
| 1259 | - } |
|
| 1260 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce, $context); |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * This returns a generated link that will load the related help tab. |
|
| 1266 | - * |
|
| 1267 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1268 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1269 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1270 | - * @return string generated link |
|
| 1271 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1272 | - */ |
|
| 1273 | - protected function _get_help_tab_link(string $help_tab_id, string $icon_style = '', string $help_text = ''): string |
|
| 1274 | - { |
|
| 1275 | - return EEH_Template::get_help_tab_link( |
|
| 1276 | - $help_tab_id, |
|
| 1277 | - $this->page_slug, |
|
| 1278 | - $this->_req_action, |
|
| 1279 | - $icon_style, |
|
| 1280 | - $help_text |
|
| 1281 | - ); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * _add_help_tabs |
|
| 1287 | - * Note child classes define their help tabs within the page_config array. |
|
| 1288 | - * |
|
| 1289 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1290 | - * @return void |
|
| 1291 | - * @throws DomainException |
|
| 1292 | - * @throws EE_Error |
|
| 1293 | - * @throws ReflectionException |
|
| 1294 | - */ |
|
| 1295 | - protected function _add_help_tabs() |
|
| 1296 | - { |
|
| 1297 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1298 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1299 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1300 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1301 | - // check that the callback given is valid |
|
| 1302 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1303 | - throw new EE_Error( |
|
| 1304 | - sprintf( |
|
| 1305 | - esc_html__( |
|
| 1306 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1307 | - 'event_espresso' |
|
| 1308 | - ), |
|
| 1309 | - $config['help_sidebar'], |
|
| 1310 | - $this->class_name |
|
| 1311 | - ) |
|
| 1312 | - ); |
|
| 1313 | - } |
|
| 1314 | - $content = apply_filters( |
|
| 1315 | - 'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar', |
|
| 1316 | - $this->{$config['help_sidebar']}() |
|
| 1317 | - ); |
|
| 1318 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1319 | - } |
|
| 1320 | - if (! isset($config['help_tabs'])) { |
|
| 1321 | - return; |
|
| 1322 | - } //no help tabs for this route |
|
| 1323 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1324 | - // we're here so there ARE help tabs! |
|
| 1325 | - // make sure we've got what we need |
|
| 1326 | - if (! isset($cfg['title'])) { |
|
| 1327 | - throw new EE_Error( |
|
| 1328 | - esc_html__( |
|
| 1329 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1330 | - 'event_espresso' |
|
| 1331 | - ) |
|
| 1332 | - ); |
|
| 1333 | - } |
|
| 1334 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1335 | - throw new EE_Error( |
|
| 1336 | - esc_html__( |
|
| 1337 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1338 | - 'event_espresso' |
|
| 1339 | - ) |
|
| 1340 | - ); |
|
| 1341 | - } |
|
| 1342 | - // first priority goes to content. |
|
| 1343 | - if (! empty($cfg['content'])) { |
|
| 1344 | - $content = $cfg['content']; |
|
| 1345 | - // second priority goes to filename |
|
| 1346 | - } elseif (! empty($cfg['filename'])) { |
|
| 1347 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1348 | - // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1349 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1350 | - . basename($this->_get_dir()) |
|
| 1351 | - . '/help_tabs/' |
|
| 1352 | - . $cfg['filename'] |
|
| 1353 | - . '.help_tab.php' : $file_path; |
|
| 1354 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1355 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1356 | - EE_Error::add_error( |
|
| 1357 | - sprintf( |
|
| 1358 | - esc_html__( |
|
| 1359 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1360 | - 'event_espresso' |
|
| 1361 | - ), |
|
| 1362 | - $tab_id, |
|
| 1363 | - key($config), |
|
| 1364 | - $file_path |
|
| 1365 | - ), |
|
| 1366 | - __FILE__, |
|
| 1367 | - __FUNCTION__, |
|
| 1368 | - __LINE__ |
|
| 1369 | - ); |
|
| 1370 | - return; |
|
| 1371 | - } |
|
| 1372 | - $template_args['admin_page_obj'] = $this; |
|
| 1373 | - $content = EEH_Template::display_template( |
|
| 1374 | - $file_path, |
|
| 1375 | - $template_args, |
|
| 1376 | - true |
|
| 1377 | - ); |
|
| 1378 | - } else { |
|
| 1379 | - $content = ''; |
|
| 1380 | - } |
|
| 1381 | - // check if callback is valid |
|
| 1382 | - if ( |
|
| 1383 | - empty($content) |
|
| 1384 | - && ( |
|
| 1385 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1386 | - ) |
|
| 1387 | - ) { |
|
| 1388 | - EE_Error::add_error( |
|
| 1389 | - sprintf( |
|
| 1390 | - esc_html__( |
|
| 1391 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1392 | - 'event_espresso' |
|
| 1393 | - ), |
|
| 1394 | - $cfg['title'] |
|
| 1395 | - ), |
|
| 1396 | - __FILE__, |
|
| 1397 | - __FUNCTION__, |
|
| 1398 | - __LINE__ |
|
| 1399 | - ); |
|
| 1400 | - return; |
|
| 1401 | - } |
|
| 1402 | - // setup config array for help tab method |
|
| 1403 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1404 | - $_ht = [ |
|
| 1405 | - 'id' => $id, |
|
| 1406 | - 'title' => $cfg['title'], |
|
| 1407 | - 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1408 | - 'content' => $content, |
|
| 1409 | - ]; |
|
| 1410 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1411 | - } |
|
| 1412 | - } |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1418 | - * |
|
| 1419 | - * @return void |
|
| 1420 | - * @throws ReflectionException |
|
| 1421 | - * @throws EE_Error |
|
| 1422 | - */ |
|
| 1423 | - protected function _add_qtips() |
|
| 1424 | - { |
|
| 1425 | - if (isset($this->_route_config['qtips'])) { |
|
| 1426 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1427 | - // load qtip loader |
|
| 1428 | - $path = [ |
|
| 1429 | - $this->_get_dir() . '/qtips/', |
|
| 1430 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1431 | - ]; |
|
| 1432 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1433 | - } |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - |
|
| 1437 | - /** |
|
| 1438 | - * _set_nav_tabs |
|
| 1439 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1440 | - * wish to add additional tabs or modify accordingly. |
|
| 1441 | - * |
|
| 1442 | - * @return void |
|
| 1443 | - * @throws InvalidArgumentException |
|
| 1444 | - * @throws InvalidInterfaceException |
|
| 1445 | - * @throws InvalidDataTypeException |
|
| 1446 | - */ |
|
| 1447 | - protected function _set_nav_tabs() |
|
| 1448 | - { |
|
| 1449 | - $i = 0; |
|
| 1450 | - $only_tab = count($this->_page_config) < 2; |
|
| 1451 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1452 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1453 | - continue; |
|
| 1454 | - } |
|
| 1455 | - // no nav tab for this config |
|
| 1456 | - // check for persistent flag |
|
| 1457 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1458 | - // nav tab is only to appear when route requested. |
|
| 1459 | - continue; |
|
| 1460 | - } |
|
| 1461 | - if (! $this->check_user_access($slug, true)) { |
|
| 1462 | - // no nav tab because current user does not have access. |
|
| 1463 | - continue; |
|
| 1464 | - } |
|
| 1465 | - $css_class = $config['css_class'] ?? ''; |
|
| 1466 | - $css_class .= $only_tab ? ' ee-only-tab' : ''; |
|
| 1467 | - $css_class .= " ee-nav-tab__$slug"; |
|
| 1468 | - |
|
| 1469 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1470 | - 'url' => $config['nav']['url'] ?? EE_Admin_Page::add_query_args_and_nonce( |
|
| 1471 | - ['action' => $slug], |
|
| 1472 | - $this->_admin_base_url |
|
| 1473 | - ), |
|
| 1474 | - 'link_text' => $this->navTabLabel($config['nav'], $slug), |
|
| 1475 | - 'css_class' => $this->_req_action === $slug ? $css_class . ' nav-tab-active' : $css_class, |
|
| 1476 | - 'order' => $config['nav']['order'] ?? $i, |
|
| 1477 | - ]; |
|
| 1478 | - $i++; |
|
| 1479 | - } |
|
| 1480 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1481 | - if (empty($this->_nav_tabs)) { |
|
| 1482 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1483 | - 'url' => $this->_admin_base_url, |
|
| 1484 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1485 | - 'css_class' => 'nav-tab-active', |
|
| 1486 | - 'order' => 10, |
|
| 1487 | - ]; |
|
| 1488 | - } |
|
| 1489 | - // now let's sort the tabs according to order |
|
| 1490 | - usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - |
|
| 1494 | - private function navTabLabel(array $nav_tab, string $slug): string |
|
| 1495 | - { |
|
| 1496 | - $label = $nav_tab['label'] ?? ucwords(str_replace('_', ' ', $slug)); |
|
| 1497 | - $icon = $nav_tab['icon'] ?? null; |
|
| 1498 | - $icon = $icon ? '<span class="dashicons ' . $icon . '"></span>' : ''; |
|
| 1499 | - return ' |
|
| 138 | + /** |
|
| 139 | + * sanitized request action |
|
| 140 | + */ |
|
| 141 | + protected string $_req_action = ''; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * sanitized request action nonce |
|
| 145 | + */ |
|
| 146 | + protected string $_req_nonce = ''; |
|
| 147 | + |
|
| 148 | + protected string $_search_btn_label = ''; |
|
| 149 | + |
|
| 150 | + protected string $_template_path = ''; |
|
| 151 | + |
|
| 152 | + protected string $_view = ''; |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * set early within EE_Admin_Init |
|
| 156 | + * |
|
| 157 | + * @var string |
|
| 158 | + */ |
|
| 159 | + protected string $_wp_page_slug = ''; |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * if the current class is an admin page extension, like: Extend_Events_Admin_Page, |
|
| 163 | + * then this would be the parent classname: Events_Admin_Page |
|
| 164 | + * |
|
| 165 | + * @var string |
|
| 166 | + */ |
|
| 167 | + public string $base_class_name = ''; |
|
| 168 | + |
|
| 169 | + public string $class_name = ''; |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * unprocessed value for the 'action' request param (default '') |
|
| 173 | + * |
|
| 174 | + * @var string |
|
| 175 | + */ |
|
| 176 | + protected string $raw_req_action = ''; |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * unprocessed value for the 'page' request param (default '') |
|
| 180 | + * |
|
| 181 | + * @var string |
|
| 182 | + */ |
|
| 183 | + protected string $raw_req_page = ''; |
|
| 184 | + |
|
| 185 | + public string $page_folder = ''; |
|
| 186 | + |
|
| 187 | + public string $page_label = ''; |
|
| 188 | + |
|
| 189 | + public string $page_slug = ''; |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * the current page route and route config |
|
| 194 | + * |
|
| 195 | + * @var array|callable|string|null |
|
| 196 | + */ |
|
| 197 | + protected $_route = null; |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @Constructor |
|
| 202 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 203 | + * @throws InvalidArgumentException |
|
| 204 | + * @throws InvalidDataTypeException |
|
| 205 | + * @throws InvalidInterfaceException |
|
| 206 | + * @throws ReflectionException |
|
| 207 | + */ |
|
| 208 | + public function __construct($routing = true) |
|
| 209 | + { |
|
| 210 | + $this->loader = LoaderFactory::getLoader(); |
|
| 211 | + $this->admin_config = $this->loader->getShared(EE_Admin_Config::class); |
|
| 212 | + $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 213 | + $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 214 | + $this->capabilities = $this->loader->getShared(EE_Capabilities::class); |
|
| 215 | + // routing enabled? |
|
| 216 | + $this->_routing = $routing; |
|
| 217 | + |
|
| 218 | + $this->class_name = get_class($this); |
|
| 219 | + $this->base_class_name = strpos($this->class_name, 'Extend_') === 0 |
|
| 220 | + ? str_replace('Extend_', '', $this->class_name) |
|
| 221 | + : ''; |
|
| 222 | + |
|
| 223 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 224 | + $this->_is_caf = true; |
|
| 225 | + } |
|
| 226 | + $this->_yes_no_values = [ |
|
| 227 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 228 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 229 | + ]; |
|
| 230 | + // set the _req_data property. |
|
| 231 | + $this->_req_data = $this->request->requestParams(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @return EE_Admin_Config |
|
| 237 | + */ |
|
| 238 | + public function adminConfig(): EE_Admin_Config |
|
| 239 | + { |
|
| 240 | + return $this->admin_config; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @return FeatureFlags |
|
| 246 | + */ |
|
| 247 | + public function feature(): FeatureFlags |
|
| 248 | + { |
|
| 249 | + return $this->feature; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 255 | + * for child classes that needed to set properties prior to these methods getting called, |
|
| 256 | + * but also needed the parent class to have its construction completed as well. |
|
| 257 | + * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 258 | + * and any complex initialization logic should only run after instantiation is complete. |
|
| 259 | + * This method gets called immediately after construction from within |
|
| 260 | + * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 261 | + * |
|
| 262 | + * @throws EE_Error |
|
| 263 | + * @throws InvalidArgumentException |
|
| 264 | + * @throws InvalidDataTypeException |
|
| 265 | + * @throws InvalidInterfaceException |
|
| 266 | + * @throws ReflectionException |
|
| 267 | + * @throws Throwable |
|
| 268 | + * @since 5.0.0.p |
|
| 269 | + */ |
|
| 270 | + public function initializePage() |
|
| 271 | + { |
|
| 272 | + if ($this->initialized) { |
|
| 273 | + return; |
|
| 274 | + } |
|
| 275 | + // set initial page props (child method) |
|
| 276 | + $this->_init_page_props(); |
|
| 277 | + // set global defaults |
|
| 278 | + $this->_set_defaults(); |
|
| 279 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 280 | + $this->_global_ajax_hooks(); |
|
| 281 | + $this->_ajax_hooks(); |
|
| 282 | + // other_page_hooks have to be early too. |
|
| 283 | + $this->_do_other_page_hooks(); |
|
| 284 | + // set up page dependencies |
|
| 285 | + $this->_before_page_setup(); |
|
| 286 | + $this->_page_setup(); |
|
| 287 | + $this->initialized = true; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * _init_page_props |
|
| 293 | + * Child classes use to set at least the following properties: |
|
| 294 | + * $page_slug. |
|
| 295 | + * $page_label. |
|
| 296 | + * |
|
| 297 | + * @abstract |
|
| 298 | + * @return void |
|
| 299 | + */ |
|
| 300 | + abstract protected function _init_page_props(); |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * _ajax_hooks |
|
| 305 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 306 | + * Note: within the ajax callback methods. |
|
| 307 | + * |
|
| 308 | + * @abstract |
|
| 309 | + * @return void |
|
| 310 | + */ |
|
| 311 | + abstract protected function _ajax_hooks(); |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * _define_page_props |
|
| 316 | + * child classes define page properties in here. Must include at least: |
|
| 317 | + * $_admin_base_url = base_url for all admin pages |
|
| 318 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 319 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 320 | + * array( |
|
| 321 | + * 'buttons' => array( |
|
| 322 | + * 'add' => esc_html__('label for add new button'), |
|
| 323 | + * 'edit' => esc_html__('label for edit button'), |
|
| 324 | + * 'delete' => esc_html__('label for delete button') |
|
| 325 | + * ) |
|
| 326 | + * ) |
|
| 327 | + * |
|
| 328 | + * @abstract |
|
| 329 | + * @return void |
|
| 330 | + */ |
|
| 331 | + abstract protected function _define_page_props(); |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * _set_page_routes |
|
| 336 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 337 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 338 | + * have a 'default' route. Here's the format |
|
| 339 | + * $this->_page_routes = array( |
|
| 340 | + * 'default' => array( |
|
| 341 | + * 'func' => '_default_method_handling_route', |
|
| 342 | + * 'args' => array('array','of','args'), |
|
| 343 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 344 | + * ajax request, backend processing) |
|
| 345 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 346 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 347 | + * headers sent route. |
|
| 348 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 349 | + * this route. |
|
| 350 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 351 | + * checks). |
|
| 352 | + * ), |
|
| 353 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 354 | + * handling method. |
|
| 355 | + * ) |
|
| 356 | + * ) |
|
| 357 | + * |
|
| 358 | + * @abstract |
|
| 359 | + * @return void |
|
| 360 | + */ |
|
| 361 | + abstract protected function _set_page_routes(); |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * _set_page_config |
|
| 366 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 367 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 368 | + * $this->_page_config = array( |
|
| 369 | + * 'default' => array( |
|
| 370 | + * 'labels' => array( |
|
| 371 | + * 'buttons' => array( |
|
| 372 | + * 'add' => esc_html__('label for adding item'), |
|
| 373 | + * 'edit' => esc_html__('label for editing item'), |
|
| 374 | + * 'delete' => esc_html__('label for deleting item') |
|
| 375 | + * ), |
|
| 376 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 377 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 378 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 379 | + * _define_page_props() method |
|
| 380 | + * 'nav' => array( |
|
| 381 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 382 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 383 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 384 | + * 'order' => 10, //required to indicate tab position. |
|
| 385 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 386 | + * displayed then add this parameter. |
|
| 387 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 388 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 389 | + * metaboxes set for eventespresso admin pages. |
|
| 390 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 391 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 392 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 393 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 394 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 395 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 396 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 397 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 398 | + * want to display. |
|
| 399 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 400 | + * 'tab_id' => array( |
|
| 401 | + * 'title' => 'tab_title', |
|
| 402 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 403 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 404 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 405 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 406 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 407 | + * attempt to use the callback which should match the name of a method in the class |
|
| 408 | + * ), |
|
| 409 | + * 'tab2_id' => array( |
|
| 410 | + * 'title' => 'tab2 title', |
|
| 411 | + * 'filename' => 'file_name_2' |
|
| 412 | + * 'callback' => 'callback_method_for_content', |
|
| 413 | + * ), |
|
| 414 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 415 | + * help tab area on an admin page. @return void |
|
| 416 | + * |
|
| 417 | + * @abstract |
|
| 418 | + */ |
|
| 419 | + abstract protected function _set_page_config(); |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * _add_screen_options |
|
| 424 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 425 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 426 | + * to a particular view. |
|
| 427 | + * |
|
| 428 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 429 | + * see also WP_Screen object documents... |
|
| 430 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 431 | + * @abstract |
|
| 432 | + * @return void |
|
| 433 | + */ |
|
| 434 | + abstract protected function _add_screen_options(); |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * _add_feature_pointers |
|
| 439 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 440 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 441 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 442 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 443 | + * extended) also see: |
|
| 444 | + * |
|
| 445 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 446 | + * @abstract |
|
| 447 | + * @return void |
|
| 448 | + */ |
|
| 449 | + abstract protected function _add_feature_pointers(); |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * load_scripts_styles |
|
| 454 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 455 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 456 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 457 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 458 | + * |
|
| 459 | + * @abstract |
|
| 460 | + * @return void |
|
| 461 | + */ |
|
| 462 | + abstract public function load_scripts_styles(); |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * admin_init |
|
| 467 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 468 | + * all pages/views loaded by child class. |
|
| 469 | + * |
|
| 470 | + * @abstract |
|
| 471 | + * @return void |
|
| 472 | + */ |
|
| 473 | + abstract public function admin_init(); |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * admin_notices |
|
| 478 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 479 | + * all pages/views loaded by child class. |
|
| 480 | + * |
|
| 481 | + * @abstract |
|
| 482 | + * @return void |
|
| 483 | + */ |
|
| 484 | + abstract public function admin_notices(); |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * admin_footer_scripts |
|
| 489 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 490 | + * will apply to all pages/views loaded by child class. |
|
| 491 | + * |
|
| 492 | + * @return void |
|
| 493 | + */ |
|
| 494 | + abstract public function admin_footer_scripts(); |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * admin_footer |
|
| 499 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 500 | + * apply to all pages/views loaded by child class. |
|
| 501 | + * |
|
| 502 | + * @return void |
|
| 503 | + */ |
|
| 504 | + public function admin_footer() |
|
| 505 | + { |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * _global_ajax_hooks |
|
| 511 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 512 | + * Note: within the ajax callback methods. |
|
| 513 | + * |
|
| 514 | + * @abstract |
|
| 515 | + * @return void |
|
| 516 | + */ |
|
| 517 | + protected function _global_ajax_hooks() |
|
| 518 | + { |
|
| 519 | + // for lazy loading of metabox content |
|
| 520 | + add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content']); |
|
| 521 | + |
|
| 522 | + add_action( |
|
| 523 | + 'wp_ajax_espresso_hide_status_change_notice', |
|
| 524 | + [$this, 'hideStatusChangeNotice'] |
|
| 525 | + ); |
|
| 526 | + add_action( |
|
| 527 | + 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 528 | + [$this, 'hideStatusChangeNotice'] |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + public function ajax_metabox_content() |
|
| 534 | + { |
|
| 535 | + $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 536 | + $content_url = $this->request->getRequestParam('contenturl', '', DataType::URL); |
|
| 537 | + EE_Admin_Page::cached_rss_display($content_id, $content_url); |
|
| 538 | + wp_die(); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + public function hideStatusChangeNotice() |
|
| 543 | + { |
|
| 544 | + $response = []; |
|
| 545 | + try { |
|
| 546 | + /** @var StatusChangeNotice $status_change_notice */ |
|
| 547 | + $status_change_notice = $this->loader->getShared( |
|
| 548 | + 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 549 | + ); |
|
| 550 | + $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 551 | + } catch (Exception $exception) { |
|
| 552 | + $response['errors'] = $exception->getMessage(); |
|
| 553 | + } |
|
| 554 | + echo wp_json_encode($response); |
|
| 555 | + exit(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 561 | + * |
|
| 562 | + * @return void |
|
| 563 | + */ |
|
| 564 | + protected function _before_page_setup() |
|
| 565 | + { |
|
| 566 | + // default is to do nothing |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Makes sure any things that need to be loaded early get handled. |
|
| 572 | + * We also escape early here if the page requested doesn't match the object. |
|
| 573 | + * |
|
| 574 | + * @final |
|
| 575 | + * @return void |
|
| 576 | + * @throws EE_Error |
|
| 577 | + * @throws InvalidArgumentException |
|
| 578 | + * @throws ReflectionException |
|
| 579 | + * @throws InvalidDataTypeException |
|
| 580 | + * @throws InvalidInterfaceException |
|
| 581 | + * @throws Throwable |
|
| 582 | + */ |
|
| 583 | + final protected function _page_setup() |
|
| 584 | + { |
|
| 585 | + // requires? |
|
| 586 | + // admin_init stuff - global - we're setting this REALLY early |
|
| 587 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 588 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 589 | + add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 590 | + // next verify if we need to load anything... |
|
| 591 | + $this->_current_page = $this->request->getRequestParam('page', '', DataType::KEY); |
|
| 592 | + $this->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, DataType::KEY); |
|
| 593 | + $this->page_folder = strtolower( |
|
| 594 | + str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name) |
|
| 595 | + ); |
|
| 596 | + global $ee_menu_slugs; |
|
| 597 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 598 | + if ( |
|
| 599 | + ! $this->request->isAjax() |
|
| 600 | + && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 601 | + ) { |
|
| 602 | + return; |
|
| 603 | + } |
|
| 604 | + // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 605 | + // we need to copy the action from the second to the first |
|
| 606 | + $action = $this->request->getRequestParam('action', '-1', DataType::KEY); |
|
| 607 | + $action2 = $this->request->getRequestParam('action2', '-1', DataType::KEY); |
|
| 608 | + $action = $action !== '-1' ? $action : $action2; |
|
| 609 | + $req_action = $action !== '-1' ? $action : 'default'; |
|
| 610 | + |
|
| 611 | + // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 612 | + // then let's use the route as the action. |
|
| 613 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 614 | + $route = $this->request->getRequestParam('route'); |
|
| 615 | + $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 616 | + ? $route |
|
| 617 | + : $req_action; |
|
| 618 | + $this->_current_view = $this->_req_action; |
|
| 619 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 620 | + $this->_define_page_props(); |
|
| 621 | + $this->_current_page_view_url = add_query_arg( |
|
| 622 | + ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 623 | + $this->_admin_base_url |
|
| 624 | + ); |
|
| 625 | + // set page configs |
|
| 626 | + $this->_set_page_routes(); |
|
| 627 | + $this->_set_page_config(); |
|
| 628 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 629 | + if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 630 | + $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 631 | + if ($wp_referer) { |
|
| 632 | + $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + // for CPT and other extended functionality. |
|
| 636 | + // If there is an _extend_page_config_for_cpt |
|
| 637 | + // then let's run that to modify all the various page configuration arrays. |
|
| 638 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 639 | + $this->_extend_page_config_for_cpt(); |
|
| 640 | + } |
|
| 641 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 642 | + $this->_page_routes = apply_filters( |
|
| 643 | + 'FHEE__' . $this->class_name . '__page_setup__page_routes', |
|
| 644 | + $this->_page_routes, |
|
| 645 | + $this |
|
| 646 | + ); |
|
| 647 | + $this->_page_config = apply_filters( |
|
| 648 | + 'FHEE__' . $this->class_name . '__page_setup__page_config', |
|
| 649 | + $this->_page_config, |
|
| 650 | + $this |
|
| 651 | + ); |
|
| 652 | + if ($this->base_class_name !== '') { |
|
| 653 | + $this->_page_routes = apply_filters( |
|
| 654 | + 'FHEE__' . $this->base_class_name . '__page_setup__page_routes', |
|
| 655 | + $this->_page_routes, |
|
| 656 | + $this |
|
| 657 | + ); |
|
| 658 | + $this->_page_config = apply_filters( |
|
| 659 | + 'FHEE__' . $this->base_class_name . '__page_setup__page_config', |
|
| 660 | + $this->_page_config, |
|
| 661 | + $this |
|
| 662 | + ); |
|
| 663 | + } |
|
| 664 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 665 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 666 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 667 | + add_action( |
|
| 668 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 669 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 670 | + 10, |
|
| 671 | + 2 |
|
| 672 | + ); |
|
| 673 | + } |
|
| 674 | + // next route only if routing enabled |
|
| 675 | + if ($this->_routing && ! $this->request->isAjax()) { |
|
| 676 | + $this->_verify_routes(); |
|
| 677 | + // next let's just check user_access and kill if no access |
|
| 678 | + $this->check_user_access(); |
|
| 679 | + if ($this->_is_UI_request) { |
|
| 680 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 681 | + add_action('admin_init', [$this, 'admin_init']); |
|
| 682 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 683 | + add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 684 | + } |
|
| 685 | + } else { |
|
| 686 | + // hijack regular WP loading and route admin request immediately |
|
| 687 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 688 | + $this->route_admin_request(); |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 696 | + * |
|
| 697 | + * @return void |
|
| 698 | + * @throws EE_Error |
|
| 699 | + */ |
|
| 700 | + private function _do_other_page_hooks() |
|
| 701 | + { |
|
| 702 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 703 | + foreach ($registered_pages as $page) { |
|
| 704 | + // now let's setup the file name and class that should be present |
|
| 705 | + $classname = str_replace('.class.php', '', $page); |
|
| 706 | + // autoloaders should take care of loading file |
|
| 707 | + if (! class_exists($classname)) { |
|
| 708 | + $error_msg[] = sprintf( |
|
| 709 | + esc_html__( |
|
| 710 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 711 | + 'event_espresso' |
|
| 712 | + ), |
|
| 713 | + $page |
|
| 714 | + ); |
|
| 715 | + $error_msg[] = $error_msg[0] |
|
| 716 | + . "\r\n" |
|
| 717 | + . sprintf( |
|
| 718 | + esc_html__( |
|
| 719 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 720 | + 'event_espresso' |
|
| 721 | + ), |
|
| 722 | + $page, |
|
| 723 | + '<br />', |
|
| 724 | + '<strong>' . $classname . '</strong>' |
|
| 725 | + ); |
|
| 726 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 727 | + } |
|
| 728 | + // don't load the same class twice |
|
| 729 | + static $loaded = []; |
|
| 730 | + if (in_array($classname, $loaded, true)) { |
|
| 731 | + continue; |
|
| 732 | + } |
|
| 733 | + $loaded[] = $classname; |
|
| 734 | + // notice we are passing the instance of this class to the hook object. |
|
| 735 | + $this->loader->getShared($classname, [$this]); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * @throws ReflectionException |
|
| 742 | + * @throws EE_Error |
|
| 743 | + */ |
|
| 744 | + public function load_page_dependencies() |
|
| 745 | + { |
|
| 746 | + try { |
|
| 747 | + $this->_load_page_dependencies(); |
|
| 748 | + } catch (EE_Error $e) { |
|
| 749 | + $e->get_error(); |
|
| 750 | + } |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * load_page_dependencies |
|
| 756 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 757 | + * |
|
| 758 | + * @return void |
|
| 759 | + * @throws DomainException |
|
| 760 | + * @throws EE_Error |
|
| 761 | + * @throws InvalidArgumentException |
|
| 762 | + * @throws InvalidDataTypeException |
|
| 763 | + * @throws InvalidInterfaceException |
|
| 764 | + * @throws ReflectionException |
|
| 765 | + */ |
|
| 766 | + protected function _load_page_dependencies() |
|
| 767 | + { |
|
| 768 | + // let's set the current_screen and screen options to override what WP set |
|
| 769 | + $this->_current_screen = get_current_screen(); |
|
| 770 | + // load admin_notices - global, page class, and view specific |
|
| 771 | + add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 772 | + add_action('admin_notices', [$this, 'admin_notices']); |
|
| 773 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 774 | + add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 775 | + } |
|
| 776 | + // load network admin_notices - global, page class, and view specific |
|
| 777 | + add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 778 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 779 | + add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 780 | + } |
|
| 781 | + // this will save any per_page screen options if they are present |
|
| 782 | + $this->_set_per_page_screen_options(); |
|
| 783 | + // setup list table properties |
|
| 784 | + $this->_set_list_table(); |
|
| 785 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 786 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 787 | + add_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99); |
|
| 788 | + // hack because promos admin was loading the edited promotion object in the metaboxes callback |
|
| 789 | + // which should NOT be generated on non-UI requests like POST updates/inserts |
|
| 790 | + if ( |
|
| 791 | + $this->class_name === 'Promotions_Admin_Page' |
|
| 792 | + && ($this->_req_action === 'edit' || $this->_req_action === 'create_new') |
|
| 793 | + ) { |
|
| 794 | + $this->addRegisteredMetaBoxes(); |
|
| 795 | + } |
|
| 796 | + $this->_add_screen_columns(); |
|
| 797 | + // add screen options - global, page child class, and view specific |
|
| 798 | + $this->_add_global_screen_options(); |
|
| 799 | + $this->_add_screen_options(); |
|
| 800 | + $add_screen_options = "_add_screen_options_$this->_current_view"; |
|
| 801 | + if (method_exists($this, $add_screen_options)) { |
|
| 802 | + $this->{$add_screen_options}(); |
|
| 803 | + } |
|
| 804 | + // add help tab(s) - set via page_config and qtips. |
|
| 805 | + $this->_add_help_tabs(); |
|
| 806 | + $this->_add_qtips(); |
|
| 807 | + // add feature_pointers - global, page child class, and view specific |
|
| 808 | + $this->_add_feature_pointers(); |
|
| 809 | + $this->_add_global_feature_pointers(); |
|
| 810 | + $add_feature_pointer = "_add_feature_pointer_$this->_current_view"; |
|
| 811 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 812 | + $this->{$add_feature_pointer}(); |
|
| 813 | + } |
|
| 814 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 815 | + add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 816 | + add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles']); |
|
| 817 | + if (method_exists($this, "load_scripts_styles_$this->_current_view")) { |
|
| 818 | + add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_$this->_current_view"], 15); |
|
| 819 | + } |
|
| 820 | + add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 821 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 822 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 823 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 824 | + // is a good use case. Notice the late priority we're giving these |
|
| 825 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 826 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 827 | + if (method_exists($this, "admin_footer_scripts_$this->_current_view")) { |
|
| 828 | + add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_$this->_current_view"], 101); |
|
| 829 | + } |
|
| 830 | + // admin footer scripts |
|
| 831 | + add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 832 | + add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 833 | + if (method_exists($this, "admin_footer_$this->_current_view")) { |
|
| 834 | + add_action('admin_footer', [$this, "admin_footer_$this->_current_view"], 101); |
|
| 835 | + } |
|
| 836 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 837 | + // targeted hook |
|
| 838 | + do_action( |
|
| 839 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__$this->_req_action" |
|
| 840 | + ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * _set_defaults |
|
| 846 | + * This sets some global defaults for class properties. |
|
| 847 | + */ |
|
| 848 | + private function _set_defaults() |
|
| 849 | + { |
|
| 850 | + // init template args |
|
| 851 | + $this->set_template_args( |
|
| 852 | + [ |
|
| 853 | + 'admin_page_header' => '', |
|
| 854 | + 'admin_page_content' => '', |
|
| 855 | + 'post_body_content' => '', |
|
| 856 | + 'before_list_table' => '', |
|
| 857 | + 'after_list_table' => '', |
|
| 858 | + ] |
|
| 859 | + ); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * route_admin_request |
|
| 865 | + * |
|
| 866 | + * @return void |
|
| 867 | + * @throws InvalidArgumentException |
|
| 868 | + * @throws InvalidInterfaceException |
|
| 869 | + * @throws InvalidDataTypeException |
|
| 870 | + * @throws EE_Error |
|
| 871 | + * @throws ReflectionException |
|
| 872 | + * @throws Throwable |
|
| 873 | + * @see _route_admin_request() |
|
| 874 | + */ |
|
| 875 | + public function route_admin_request() |
|
| 876 | + { |
|
| 877 | + try { |
|
| 878 | + $this->_route_admin_request(); |
|
| 879 | + } catch (EE_Error $e) { |
|
| 880 | + $e->get_error(); |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + public function set_wp_page_slug($wp_page_slug) |
|
| 886 | + { |
|
| 887 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 888 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 889 | + if (is_network_admin()) { |
|
| 890 | + $this->_wp_page_slug .= '-network'; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * _verify_routes |
|
| 897 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 898 | + * we know if we need to drop out. |
|
| 899 | + * |
|
| 900 | + * @return bool |
|
| 901 | + * @throws EE_Error |
|
| 902 | + */ |
|
| 903 | + protected function _verify_routes(): bool |
|
| 904 | + { |
|
| 905 | + if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 908 | + // check that the page_routes array is not empty |
|
| 909 | + if (empty($this->_page_routes)) { |
|
| 910 | + // user error msg |
|
| 911 | + $error_msg = sprintf( |
|
| 912 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 913 | + $this->_admin_page_title |
|
| 914 | + ); |
|
| 915 | + // developer error msg |
|
| 916 | + $error_msg .= '||' . $error_msg |
|
| 917 | + . esc_html__( |
|
| 918 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 919 | + 'event_espresso' |
|
| 920 | + ); |
|
| 921 | + throw new EE_Error($error_msg); |
|
| 922 | + } |
|
| 923 | + // route 'editpost' routes to CPT 'edit' routes |
|
| 924 | + $alt_edit_route = $this instanceof EE_Admin_Page_CPT ? $this->cpt_editpost_route : 'edit'; |
|
| 925 | + if ( |
|
| 926 | + $this->_req_action === 'editpost' |
|
| 927 | + && ! isset($this->_page_routes['editpost']) |
|
| 928 | + && isset($this->_page_routes[$alt_edit_route]) |
|
| 929 | + ) { |
|
| 930 | + $this->_req_action = $alt_edit_route; |
|
| 931 | + } |
|
| 932 | + // and that the requested page route exists |
|
| 933 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 934 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 935 | + $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 936 | + } else { |
|
| 937 | + // user error msg |
|
| 938 | + $error_msg = sprintf( |
|
| 939 | + esc_html__( |
|
| 940 | + 'The requested page route does not exist for the %s admin page.', |
|
| 941 | + 'event_espresso' |
|
| 942 | + ), |
|
| 943 | + $this->_admin_page_title |
|
| 944 | + ); |
|
| 945 | + // developer error msg |
|
| 946 | + $error_msg .= '||' . $error_msg |
|
| 947 | + . sprintf( |
|
| 948 | + esc_html__( |
|
| 949 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 950 | + 'event_espresso' |
|
| 951 | + ), |
|
| 952 | + $this->_req_action |
|
| 953 | + ); |
|
| 954 | + throw new EE_Error($error_msg); |
|
| 955 | + } |
|
| 956 | + // and that a default route exists |
|
| 957 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 958 | + // user error msg |
|
| 959 | + $error_msg = sprintf( |
|
| 960 | + esc_html__( |
|
| 961 | + 'A default page route has not been set for the % admin page.', |
|
| 962 | + 'event_espresso' |
|
| 963 | + ), |
|
| 964 | + $this->_admin_page_title |
|
| 965 | + ); |
|
| 966 | + // developer error msg |
|
| 967 | + $error_msg .= '||' . $error_msg |
|
| 968 | + . esc_html__( |
|
| 969 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 970 | + 'event_espresso' |
|
| 971 | + ); |
|
| 972 | + throw new EE_Error($error_msg); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + // first lets' catch if the UI request has EVER been set. |
|
| 976 | + if ($this->_is_UI_request === null) { |
|
| 977 | + // lets set if this is a UI request or not. |
|
| 978 | + $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, DataType::BOOL); |
|
| 979 | + // wait a minute... we might have a noheader in the route array |
|
| 980 | + $this->_is_UI_request = ! (isset($this->_route['noheader']) && $this->_route['noheader']) |
|
| 981 | + ? $this->_is_UI_request |
|
| 982 | + : false; |
|
| 983 | + } |
|
| 984 | + $this->_set_current_labels(); |
|
| 985 | + return true; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 991 | + * |
|
| 992 | + * @param string $route the route name we're verifying |
|
| 993 | + * @return bool we'll throw an exception if this isn't a valid route. |
|
| 994 | + * @throws EE_Error |
|
| 995 | + */ |
|
| 996 | + protected function _verify_route(string $route): bool |
|
| 997 | + { |
|
| 998 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 999 | + return true; |
|
| 1000 | + } |
|
| 1001 | + // user error msg |
|
| 1002 | + $error_msg = sprintf( |
|
| 1003 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 1004 | + $this->_admin_page_title |
|
| 1005 | + ); |
|
| 1006 | + // developer error msg |
|
| 1007 | + $error_msg .= '||' . $error_msg |
|
| 1008 | + . sprintf( |
|
| 1009 | + esc_html__( |
|
| 1010 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 1011 | + 'event_espresso' |
|
| 1012 | + ), |
|
| 1013 | + $route |
|
| 1014 | + ); |
|
| 1015 | + throw new EE_Error($error_msg); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * perform nonce verification |
|
| 1021 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 1022 | + * using this method (and save retyping!) |
|
| 1023 | + * |
|
| 1024 | + * @param string $nonce The nonce sent |
|
| 1025 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 1026 | + * @return void |
|
| 1027 | + * @throws EE_Error |
|
| 1028 | + * @throws InvalidArgumentException |
|
| 1029 | + * @throws InvalidDataTypeException |
|
| 1030 | + * @throws InvalidInterfaceException |
|
| 1031 | + */ |
|
| 1032 | + protected function _verify_nonce(string $nonce, string $nonce_ref) |
|
| 1033 | + { |
|
| 1034 | + // verify nonce against expected value |
|
| 1035 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1036 | + // these are not the droids you are looking for !!! |
|
| 1037 | + $msg = sprintf( |
|
| 1038 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1039 | + '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1040 | + '</a>' |
|
| 1041 | + ); |
|
| 1042 | + if (WP_DEBUG) { |
|
| 1043 | + $msg .= "\n "; |
|
| 1044 | + $msg .= sprintf( |
|
| 1045 | + esc_html__( |
|
| 1046 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1047 | + 'event_espresso' |
|
| 1048 | + ), |
|
| 1049 | + __CLASS__ |
|
| 1050 | + ); |
|
| 1051 | + } |
|
| 1052 | + if (! $this->request->isAjax()) { |
|
| 1053 | + wp_die($msg); |
|
| 1054 | + } |
|
| 1055 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1056 | + $this->_return_json(); |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * _route_admin_request() |
|
| 1063 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1064 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1065 | + * in the page routes and then will try to load the corresponding method. |
|
| 1066 | + * |
|
| 1067 | + * @return void |
|
| 1068 | + * @throws EE_Error |
|
| 1069 | + * @throws InvalidArgumentException |
|
| 1070 | + * @throws InvalidDataTypeException |
|
| 1071 | + * @throws InvalidInterfaceException |
|
| 1072 | + * @throws ReflectionException |
|
| 1073 | + * @throws Throwable |
|
| 1074 | + */ |
|
| 1075 | + protected function _route_admin_request() |
|
| 1076 | + { |
|
| 1077 | + if (! $this->_is_UI_request) { |
|
| 1078 | + $this->_verify_routes(); |
|
| 1079 | + } |
|
| 1080 | + $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1081 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1082 | + // set nonce from post data |
|
| 1083 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1084 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1085 | + } |
|
| 1086 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 1087 | + if ($this->_is_UI_request) { |
|
| 1088 | + $this->_set_nav_tabs(); |
|
| 1089 | + } |
|
| 1090 | + // grab callback function |
|
| 1091 | + $func = $this->_route['func'] ?? $this->_route; |
|
| 1092 | + // check if callback has args |
|
| 1093 | + $args = $this->_route['args'] ?? []; |
|
| 1094 | + |
|
| 1095 | + // action right before calling route |
|
| 1096 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1097 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1098 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1099 | + } |
|
| 1100 | + // strip _wp_http_referer from the server REQUEST_URI |
|
| 1101 | + // else it grows in length on every submission due to recursion, |
|
| 1102 | + // ultimately causing a "Request-URI Too Large" error |
|
| 1103 | + $this->request->unSetRequestParam('_wp_http_referer'); |
|
| 1104 | + $this->request->unSetServerParam('_wp_http_referer'); |
|
| 1105 | + $cleaner_request_uri = remove_query_arg( |
|
| 1106 | + '_wp_http_referer', |
|
| 1107 | + wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1108 | + ); |
|
| 1109 | + $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri, true); |
|
| 1110 | + $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri, true); |
|
| 1111 | + $route_callback = []; |
|
| 1112 | + if (! empty($func)) { |
|
| 1113 | + if (is_array($func) && is_callable($func)) { |
|
| 1114 | + $route_callback = $func; |
|
| 1115 | + } elseif (is_string($func)) { |
|
| 1116 | + if (strpos($func, '::') !== false) { |
|
| 1117 | + $route_callback = explode('::', $func); |
|
| 1118 | + } elseif (method_exists($this, $func)) { |
|
| 1119 | + $route_callback = [$this, $func]; |
|
| 1120 | + } else { |
|
| 1121 | + $route_callback = $func; |
|
| 1122 | + } |
|
| 1123 | + } |
|
| 1124 | + [$class, $method] = $route_callback; |
|
| 1125 | + // is it neither a class method NOR a standalone function? |
|
| 1126 | + if (! is_callable($route_callback)) { |
|
| 1127 | + // user error msg |
|
| 1128 | + $error_msg = esc_html__( |
|
| 1129 | + 'An error occurred. The requested page route could not be found.', |
|
| 1130 | + 'event_espresso' |
|
| 1131 | + ); |
|
| 1132 | + // developer error msg |
|
| 1133 | + $error_msg .= '||'; |
|
| 1134 | + $error_msg .= sprintf( |
|
| 1135 | + esc_html__( |
|
| 1136 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1137 | + 'event_espresso' |
|
| 1138 | + ), |
|
| 1139 | + $method |
|
| 1140 | + ); |
|
| 1141 | + throw new DomainException($error_msg); |
|
| 1142 | + } |
|
| 1143 | + if ($class !== $this && ! in_array($this, $args)) { |
|
| 1144 | + // send along this admin page object for access by addons. |
|
| 1145 | + $args['admin_page'] = $this; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + try { |
|
| 1149 | + call_user_func_array($route_callback, $args); |
|
| 1150 | + } catch (Throwable $throwable) { |
|
| 1151 | + $nice_args = []; |
|
| 1152 | + foreach ($args as $key => $arg) { |
|
| 1153 | + $nice_args[ $key ] = is_object($arg) ? get_class($arg) : $key; |
|
| 1154 | + } |
|
| 1155 | + new ExceptionStackTraceDisplay( |
|
| 1156 | + new RuntimeException( |
|
| 1157 | + sprintf( |
|
| 1158 | + esc_html__( |
|
| 1159 | + 'Page route "%1$s" with the supplied arguments (%2$s) threw the following exception: %3$s', |
|
| 1160 | + 'event_espresso' |
|
| 1161 | + ), |
|
| 1162 | + $method, |
|
| 1163 | + implode(', ', $nice_args), |
|
| 1164 | + $throwable->getMessage() |
|
| 1165 | + ), |
|
| 1166 | + $throwable->getCode(), |
|
| 1167 | + $throwable |
|
| 1168 | + ) |
|
| 1169 | + ); |
|
| 1170 | + } |
|
| 1171 | + } |
|
| 1172 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1173 | + // then we need to reset the routing properties to the new route. |
|
| 1174 | + // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1175 | + if ( |
|
| 1176 | + $this->_is_UI_request === false |
|
| 1177 | + && is_array($this->_route) |
|
| 1178 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1179 | + ) { |
|
| 1180 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1181 | + } |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1187 | + * route redirects to a headers route in its route config. |
|
| 1188 | + * |
|
| 1189 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1190 | + * @return void |
|
| 1191 | + * @throws ReflectionException |
|
| 1192 | + * @throws InvalidArgumentException |
|
| 1193 | + * @throws InvalidInterfaceException |
|
| 1194 | + * @throws InvalidDataTypeException |
|
| 1195 | + * @throws EE_Error |
|
| 1196 | + * @throws Throwable |
|
| 1197 | + * @since 4.3.0 |
|
| 1198 | + */ |
|
| 1199 | + protected function _reset_routing_properties(string $new_route) |
|
| 1200 | + { |
|
| 1201 | + $this->_is_UI_request = true; |
|
| 1202 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1203 | + $this->request->setRequestParam('action', $new_route); |
|
| 1204 | + // rerun page setup |
|
| 1205 | + $this->_page_setup(); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + |
|
| 1209 | + /** |
|
| 1210 | + * _add_query_arg |
|
| 1211 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1212 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1213 | + * |
|
| 1214 | + * @param array $args |
|
| 1215 | + * @param string $url |
|
| 1216 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1217 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1218 | + * Example usage: If the current page is: |
|
| 1219 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1220 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1221 | + * &_wpnonce=5467821 |
|
| 1222 | + * and you call: |
|
| 1223 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1224 | + * array( |
|
| 1225 | + * 'action' => 'resend_something', |
|
| 1226 | + * 'page=>espresso_registrations' |
|
| 1227 | + * ), |
|
| 1228 | + * $some_url, |
|
| 1229 | + * true |
|
| 1230 | + * ); |
|
| 1231 | + * It will produce a url in this structure: |
|
| 1232 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1233 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1234 | + * month_range]=March%202015 |
|
| 1235 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1236 | + * @param int $context |
|
| 1237 | + * @return string |
|
| 1238 | + */ |
|
| 1239 | + public static function add_query_args_and_nonce( |
|
| 1240 | + array $args = [], |
|
| 1241 | + string $url = '', |
|
| 1242 | + bool $sticky = false, |
|
| 1243 | + bool $exclude_nonce = false, |
|
| 1244 | + int $context = EEH_URL::CONTEXT_NONE |
|
| 1245 | + ): string { |
|
| 1246 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1247 | + if ($sticky) { |
|
| 1248 | + /** @var RequestInterface $request */ |
|
| 1249 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1250 | + $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true); |
|
| 1251 | + $request->unSetServerParam('_wp_http_referer', true); |
|
| 1252 | + foreach ($request->requestParams() as $key => $value) { |
|
| 1253 | + // do not add nonces |
|
| 1254 | + if (strpos($key, 'nonce') !== false) { |
|
| 1255 | + continue; |
|
| 1256 | + } |
|
| 1257 | + $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1258 | + } |
|
| 1259 | + } |
|
| 1260 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce, $context); |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * This returns a generated link that will load the related help tab. |
|
| 1266 | + * |
|
| 1267 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1268 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1269 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1270 | + * @return string generated link |
|
| 1271 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1272 | + */ |
|
| 1273 | + protected function _get_help_tab_link(string $help_tab_id, string $icon_style = '', string $help_text = ''): string |
|
| 1274 | + { |
|
| 1275 | + return EEH_Template::get_help_tab_link( |
|
| 1276 | + $help_tab_id, |
|
| 1277 | + $this->page_slug, |
|
| 1278 | + $this->_req_action, |
|
| 1279 | + $icon_style, |
|
| 1280 | + $help_text |
|
| 1281 | + ); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * _add_help_tabs |
|
| 1287 | + * Note child classes define their help tabs within the page_config array. |
|
| 1288 | + * |
|
| 1289 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1290 | + * @return void |
|
| 1291 | + * @throws DomainException |
|
| 1292 | + * @throws EE_Error |
|
| 1293 | + * @throws ReflectionException |
|
| 1294 | + */ |
|
| 1295 | + protected function _add_help_tabs() |
|
| 1296 | + { |
|
| 1297 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1298 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1299 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1300 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1301 | + // check that the callback given is valid |
|
| 1302 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1303 | + throw new EE_Error( |
|
| 1304 | + sprintf( |
|
| 1305 | + esc_html__( |
|
| 1306 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1307 | + 'event_espresso' |
|
| 1308 | + ), |
|
| 1309 | + $config['help_sidebar'], |
|
| 1310 | + $this->class_name |
|
| 1311 | + ) |
|
| 1312 | + ); |
|
| 1313 | + } |
|
| 1314 | + $content = apply_filters( |
|
| 1315 | + 'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar', |
|
| 1316 | + $this->{$config['help_sidebar']}() |
|
| 1317 | + ); |
|
| 1318 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1319 | + } |
|
| 1320 | + if (! isset($config['help_tabs'])) { |
|
| 1321 | + return; |
|
| 1322 | + } //no help tabs for this route |
|
| 1323 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1324 | + // we're here so there ARE help tabs! |
|
| 1325 | + // make sure we've got what we need |
|
| 1326 | + if (! isset($cfg['title'])) { |
|
| 1327 | + throw new EE_Error( |
|
| 1328 | + esc_html__( |
|
| 1329 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1330 | + 'event_espresso' |
|
| 1331 | + ) |
|
| 1332 | + ); |
|
| 1333 | + } |
|
| 1334 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1335 | + throw new EE_Error( |
|
| 1336 | + esc_html__( |
|
| 1337 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1338 | + 'event_espresso' |
|
| 1339 | + ) |
|
| 1340 | + ); |
|
| 1341 | + } |
|
| 1342 | + // first priority goes to content. |
|
| 1343 | + if (! empty($cfg['content'])) { |
|
| 1344 | + $content = $cfg['content']; |
|
| 1345 | + // second priority goes to filename |
|
| 1346 | + } elseif (! empty($cfg['filename'])) { |
|
| 1347 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1348 | + // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1349 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1350 | + . basename($this->_get_dir()) |
|
| 1351 | + . '/help_tabs/' |
|
| 1352 | + . $cfg['filename'] |
|
| 1353 | + . '.help_tab.php' : $file_path; |
|
| 1354 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1355 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1356 | + EE_Error::add_error( |
|
| 1357 | + sprintf( |
|
| 1358 | + esc_html__( |
|
| 1359 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1360 | + 'event_espresso' |
|
| 1361 | + ), |
|
| 1362 | + $tab_id, |
|
| 1363 | + key($config), |
|
| 1364 | + $file_path |
|
| 1365 | + ), |
|
| 1366 | + __FILE__, |
|
| 1367 | + __FUNCTION__, |
|
| 1368 | + __LINE__ |
|
| 1369 | + ); |
|
| 1370 | + return; |
|
| 1371 | + } |
|
| 1372 | + $template_args['admin_page_obj'] = $this; |
|
| 1373 | + $content = EEH_Template::display_template( |
|
| 1374 | + $file_path, |
|
| 1375 | + $template_args, |
|
| 1376 | + true |
|
| 1377 | + ); |
|
| 1378 | + } else { |
|
| 1379 | + $content = ''; |
|
| 1380 | + } |
|
| 1381 | + // check if callback is valid |
|
| 1382 | + if ( |
|
| 1383 | + empty($content) |
|
| 1384 | + && ( |
|
| 1385 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1386 | + ) |
|
| 1387 | + ) { |
|
| 1388 | + EE_Error::add_error( |
|
| 1389 | + sprintf( |
|
| 1390 | + esc_html__( |
|
| 1391 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1392 | + 'event_espresso' |
|
| 1393 | + ), |
|
| 1394 | + $cfg['title'] |
|
| 1395 | + ), |
|
| 1396 | + __FILE__, |
|
| 1397 | + __FUNCTION__, |
|
| 1398 | + __LINE__ |
|
| 1399 | + ); |
|
| 1400 | + return; |
|
| 1401 | + } |
|
| 1402 | + // setup config array for help tab method |
|
| 1403 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1404 | + $_ht = [ |
|
| 1405 | + 'id' => $id, |
|
| 1406 | + 'title' => $cfg['title'], |
|
| 1407 | + 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1408 | + 'content' => $content, |
|
| 1409 | + ]; |
|
| 1410 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1411 | + } |
|
| 1412 | + } |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1418 | + * |
|
| 1419 | + * @return void |
|
| 1420 | + * @throws ReflectionException |
|
| 1421 | + * @throws EE_Error |
|
| 1422 | + */ |
|
| 1423 | + protected function _add_qtips() |
|
| 1424 | + { |
|
| 1425 | + if (isset($this->_route_config['qtips'])) { |
|
| 1426 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1427 | + // load qtip loader |
|
| 1428 | + $path = [ |
|
| 1429 | + $this->_get_dir() . '/qtips/', |
|
| 1430 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1431 | + ]; |
|
| 1432 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1433 | + } |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + |
|
| 1437 | + /** |
|
| 1438 | + * _set_nav_tabs |
|
| 1439 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1440 | + * wish to add additional tabs or modify accordingly. |
|
| 1441 | + * |
|
| 1442 | + * @return void |
|
| 1443 | + * @throws InvalidArgumentException |
|
| 1444 | + * @throws InvalidInterfaceException |
|
| 1445 | + * @throws InvalidDataTypeException |
|
| 1446 | + */ |
|
| 1447 | + protected function _set_nav_tabs() |
|
| 1448 | + { |
|
| 1449 | + $i = 0; |
|
| 1450 | + $only_tab = count($this->_page_config) < 2; |
|
| 1451 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1452 | + if (! is_array($config) || empty($config['nav'])) { |
|
| 1453 | + continue; |
|
| 1454 | + } |
|
| 1455 | + // no nav tab for this config |
|
| 1456 | + // check for persistent flag |
|
| 1457 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1458 | + // nav tab is only to appear when route requested. |
|
| 1459 | + continue; |
|
| 1460 | + } |
|
| 1461 | + if (! $this->check_user_access($slug, true)) { |
|
| 1462 | + // no nav tab because current user does not have access. |
|
| 1463 | + continue; |
|
| 1464 | + } |
|
| 1465 | + $css_class = $config['css_class'] ?? ''; |
|
| 1466 | + $css_class .= $only_tab ? ' ee-only-tab' : ''; |
|
| 1467 | + $css_class .= " ee-nav-tab__$slug"; |
|
| 1468 | + |
|
| 1469 | + $this->_nav_tabs[ $slug ] = [ |
|
| 1470 | + 'url' => $config['nav']['url'] ?? EE_Admin_Page::add_query_args_and_nonce( |
|
| 1471 | + ['action' => $slug], |
|
| 1472 | + $this->_admin_base_url |
|
| 1473 | + ), |
|
| 1474 | + 'link_text' => $this->navTabLabel($config['nav'], $slug), |
|
| 1475 | + 'css_class' => $this->_req_action === $slug ? $css_class . ' nav-tab-active' : $css_class, |
|
| 1476 | + 'order' => $config['nav']['order'] ?? $i, |
|
| 1477 | + ]; |
|
| 1478 | + $i++; |
|
| 1479 | + } |
|
| 1480 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1481 | + if (empty($this->_nav_tabs)) { |
|
| 1482 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1483 | + 'url' => $this->_admin_base_url, |
|
| 1484 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1485 | + 'css_class' => 'nav-tab-active', |
|
| 1486 | + 'order' => 10, |
|
| 1487 | + ]; |
|
| 1488 | + } |
|
| 1489 | + // now let's sort the tabs according to order |
|
| 1490 | + usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + |
|
| 1494 | + private function navTabLabel(array $nav_tab, string $slug): string |
|
| 1495 | + { |
|
| 1496 | + $label = $nav_tab['label'] ?? ucwords(str_replace('_', ' ', $slug)); |
|
| 1497 | + $icon = $nav_tab['icon'] ?? null; |
|
| 1498 | + $icon = $icon ? '<span class="dashicons ' . $icon . '"></span>' : ''; |
|
| 1499 | + return ' |
|
| 1500 | 1500 | <span class="ee-admin-screen-tab__label"> |
| 1501 | 1501 | ' . $icon . ' |
| 1502 | 1502 | <span class="ee-nav-label__text">' . $label . '</span> |
| 1503 | 1503 | </span>'; |
| 1504 | - } |
|
| 1505 | - |
|
| 1506 | - |
|
| 1507 | - /** |
|
| 1508 | - * _set_current_labels |
|
| 1509 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1510 | - * property array |
|
| 1511 | - * |
|
| 1512 | - * @return void |
|
| 1513 | - */ |
|
| 1514 | - private function _set_current_labels() |
|
| 1515 | - { |
|
| 1516 | - if (isset($this->_route_config['labels'])) { |
|
| 1517 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1518 | - if (is_array($text)) { |
|
| 1519 | - foreach ($text as $sublabel => $subtext) { |
|
| 1520 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1521 | - } |
|
| 1522 | - } else { |
|
| 1523 | - $this->_labels[ $label ] = $text; |
|
| 1524 | - } |
|
| 1525 | - } |
|
| 1526 | - } |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * verifies user access for this admin page |
|
| 1532 | - * |
|
| 1533 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1534 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1535 | - * return false if verify fail. |
|
| 1536 | - * @return bool |
|
| 1537 | - * @throws InvalidArgumentException |
|
| 1538 | - * @throws InvalidDataTypeException |
|
| 1539 | - * @throws InvalidInterfaceException |
|
| 1540 | - */ |
|
| 1541 | - public function check_user_access(string $route_to_check = '', bool $verify_only = false): bool |
|
| 1542 | - { |
|
| 1543 | - // if no route_to_check is passed in then use the current route set via _req_action |
|
| 1544 | - $action = $route_to_check ?: $this->_req_action; |
|
| 1545 | - $capability = ! empty($this->_page_routes[ $action ]['capability']) |
|
| 1546 | - ? $this->_page_routes[ $action ]['capability'] |
|
| 1547 | - : null; |
|
| 1548 | - |
|
| 1549 | - if (empty($capability)) { |
|
| 1550 | - $capability = empty($route_to_check) && ! empty($this->_route['capability']) |
|
| 1551 | - ? $this->_route['capability'] |
|
| 1552 | - : 'manage_options'; |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - $id = $this->_route['obj_id'] ?? 0; |
|
| 1556 | - |
|
| 1557 | - if ( |
|
| 1558 | - ! $this->request->isAjax() |
|
| 1559 | - && ( |
|
| 1560 | - ! function_exists('is_admin') |
|
| 1561 | - || ! $this->capabilities->current_user_can($capability, "{$this->page_slug}_$route_to_check", $id) |
|
| 1562 | - ) |
|
| 1563 | - ) { |
|
| 1564 | - if ($verify_only) { |
|
| 1565 | - return false; |
|
| 1566 | - } |
|
| 1567 | - if (is_user_logged_in()) { |
|
| 1568 | - wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1569 | - } |
|
| 1570 | - return false; |
|
| 1571 | - } |
|
| 1572 | - return true; |
|
| 1573 | - } |
|
| 1574 | - |
|
| 1575 | - |
|
| 1576 | - /** |
|
| 1577 | - * @param string $box_id |
|
| 1578 | - * @param string $title |
|
| 1579 | - * @param callable|string|null $callback |
|
| 1580 | - * @param string|array|WP_Screen $screen |
|
| 1581 | - * @param string $context Post edit screen contexts include 'normal', 'side', and 'advanced'. |
|
| 1582 | - * Comments screen contexts include 'normal' and 'side'. |
|
| 1583 | - * Menus meta boxes (accordion sections) all use the 'side' context. |
|
| 1584 | - * @param string $priority Accepts 'high', 'core', 'default', or 'low'. |
|
| 1585 | - * @param array|null $callback_args |
|
| 1586 | - */ |
|
| 1587 | - protected function addMetaBox( |
|
| 1588 | - string $box_id, |
|
| 1589 | - string $title, |
|
| 1590 | - $callback, |
|
| 1591 | - $screen, |
|
| 1592 | - string $context = 'normal', |
|
| 1593 | - string $priority = 'default', |
|
| 1594 | - ?array $callback_args = null |
|
| 1595 | - ) { |
|
| 1596 | - if (! (is_callable($callback) || ! function_exists($callback))) { |
|
| 1597 | - return; |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
|
| 1601 | - add_filter( |
|
| 1602 | - "postbox_classes_{$this->_wp_page_slug}_$box_id", |
|
| 1603 | - function ($classes) { |
|
| 1604 | - $classes[] = 'ee-admin-container'; |
|
| 1605 | - return $classes; |
|
| 1606 | - } |
|
| 1607 | - ); |
|
| 1608 | - } |
|
| 1609 | - |
|
| 1610 | - |
|
| 1611 | - /** |
|
| 1612 | - * admin_init_global |
|
| 1613 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1614 | - * This method executes for ALL EE Admin pages. |
|
| 1615 | - * |
|
| 1616 | - * @return void |
|
| 1617 | - */ |
|
| 1618 | - public function admin_init_global() |
|
| 1619 | - { |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - |
|
| 1623 | - /** |
|
| 1624 | - * wp_loaded_global |
|
| 1625 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1626 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1627 | - * |
|
| 1628 | - * @return void |
|
| 1629 | - */ |
|
| 1630 | - public function wp_loaded() |
|
| 1631 | - { |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * admin_notices |
|
| 1637 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1638 | - * ALL EE_Admin pages. |
|
| 1639 | - * |
|
| 1640 | - * @return void |
|
| 1641 | - */ |
|
| 1642 | - public function admin_notices_global() |
|
| 1643 | - { |
|
| 1644 | - $this->_display_no_javascript_warning(); |
|
| 1645 | - $this->_display_espresso_notices(); |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - |
|
| 1649 | - public function network_admin_notices_global() |
|
| 1650 | - { |
|
| 1651 | - $this->_display_no_javascript_warning(); |
|
| 1652 | - $this->_display_espresso_notices(); |
|
| 1653 | - } |
|
| 1654 | - |
|
| 1655 | - |
|
| 1656 | - /** |
|
| 1657 | - * admin_footer_scripts_global |
|
| 1658 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1659 | - * will apply on ALL EE_Admin pages. |
|
| 1660 | - * |
|
| 1661 | - * @return void |
|
| 1662 | - */ |
|
| 1663 | - public function admin_footer_scripts_global() |
|
| 1664 | - { |
|
| 1665 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1666 | - $this->_add_admin_page_overlay(); |
|
| 1667 | - // if metaboxes are present we need to add the nonce field |
|
| 1668 | - if ( |
|
| 1669 | - isset($this->_route_config['metaboxes']) |
|
| 1670 | - || isset($this->_route_config['list_table']) |
|
| 1671 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1672 | - ) { |
|
| 1673 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1674 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1675 | - } |
|
| 1676 | - } |
|
| 1677 | - |
|
| 1678 | - |
|
| 1679 | - /** |
|
| 1680 | - * admin_footer_global |
|
| 1681 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1682 | - * This particular method will apply on ALL EE_Admin Pages. |
|
| 1683 | - * |
|
| 1684 | - * @return void |
|
| 1685 | - */ |
|
| 1686 | - public function admin_footer_global() |
|
| 1687 | - { |
|
| 1688 | - // dialog container for dialog helper |
|
| 1689 | - echo ' |
|
| 1504 | + } |
|
| 1505 | + |
|
| 1506 | + |
|
| 1507 | + /** |
|
| 1508 | + * _set_current_labels |
|
| 1509 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1510 | + * property array |
|
| 1511 | + * |
|
| 1512 | + * @return void |
|
| 1513 | + */ |
|
| 1514 | + private function _set_current_labels() |
|
| 1515 | + { |
|
| 1516 | + if (isset($this->_route_config['labels'])) { |
|
| 1517 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1518 | + if (is_array($text)) { |
|
| 1519 | + foreach ($text as $sublabel => $subtext) { |
|
| 1520 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1521 | + } |
|
| 1522 | + } else { |
|
| 1523 | + $this->_labels[ $label ] = $text; |
|
| 1524 | + } |
|
| 1525 | + } |
|
| 1526 | + } |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * verifies user access for this admin page |
|
| 1532 | + * |
|
| 1533 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1534 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1535 | + * return false if verify fail. |
|
| 1536 | + * @return bool |
|
| 1537 | + * @throws InvalidArgumentException |
|
| 1538 | + * @throws InvalidDataTypeException |
|
| 1539 | + * @throws InvalidInterfaceException |
|
| 1540 | + */ |
|
| 1541 | + public function check_user_access(string $route_to_check = '', bool $verify_only = false): bool |
|
| 1542 | + { |
|
| 1543 | + // if no route_to_check is passed in then use the current route set via _req_action |
|
| 1544 | + $action = $route_to_check ?: $this->_req_action; |
|
| 1545 | + $capability = ! empty($this->_page_routes[ $action ]['capability']) |
|
| 1546 | + ? $this->_page_routes[ $action ]['capability'] |
|
| 1547 | + : null; |
|
| 1548 | + |
|
| 1549 | + if (empty($capability)) { |
|
| 1550 | + $capability = empty($route_to_check) && ! empty($this->_route['capability']) |
|
| 1551 | + ? $this->_route['capability'] |
|
| 1552 | + : 'manage_options'; |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + $id = $this->_route['obj_id'] ?? 0; |
|
| 1556 | + |
|
| 1557 | + if ( |
|
| 1558 | + ! $this->request->isAjax() |
|
| 1559 | + && ( |
|
| 1560 | + ! function_exists('is_admin') |
|
| 1561 | + || ! $this->capabilities->current_user_can($capability, "{$this->page_slug}_$route_to_check", $id) |
|
| 1562 | + ) |
|
| 1563 | + ) { |
|
| 1564 | + if ($verify_only) { |
|
| 1565 | + return false; |
|
| 1566 | + } |
|
| 1567 | + if (is_user_logged_in()) { |
|
| 1568 | + wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1569 | + } |
|
| 1570 | + return false; |
|
| 1571 | + } |
|
| 1572 | + return true; |
|
| 1573 | + } |
|
| 1574 | + |
|
| 1575 | + |
|
| 1576 | + /** |
|
| 1577 | + * @param string $box_id |
|
| 1578 | + * @param string $title |
|
| 1579 | + * @param callable|string|null $callback |
|
| 1580 | + * @param string|array|WP_Screen $screen |
|
| 1581 | + * @param string $context Post edit screen contexts include 'normal', 'side', and 'advanced'. |
|
| 1582 | + * Comments screen contexts include 'normal' and 'side'. |
|
| 1583 | + * Menus meta boxes (accordion sections) all use the 'side' context. |
|
| 1584 | + * @param string $priority Accepts 'high', 'core', 'default', or 'low'. |
|
| 1585 | + * @param array|null $callback_args |
|
| 1586 | + */ |
|
| 1587 | + protected function addMetaBox( |
|
| 1588 | + string $box_id, |
|
| 1589 | + string $title, |
|
| 1590 | + $callback, |
|
| 1591 | + $screen, |
|
| 1592 | + string $context = 'normal', |
|
| 1593 | + string $priority = 'default', |
|
| 1594 | + ?array $callback_args = null |
|
| 1595 | + ) { |
|
| 1596 | + if (! (is_callable($callback) || ! function_exists($callback))) { |
|
| 1597 | + return; |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
|
| 1601 | + add_filter( |
|
| 1602 | + "postbox_classes_{$this->_wp_page_slug}_$box_id", |
|
| 1603 | + function ($classes) { |
|
| 1604 | + $classes[] = 'ee-admin-container'; |
|
| 1605 | + return $classes; |
|
| 1606 | + } |
|
| 1607 | + ); |
|
| 1608 | + } |
|
| 1609 | + |
|
| 1610 | + |
|
| 1611 | + /** |
|
| 1612 | + * admin_init_global |
|
| 1613 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1614 | + * This method executes for ALL EE Admin pages. |
|
| 1615 | + * |
|
| 1616 | + * @return void |
|
| 1617 | + */ |
|
| 1618 | + public function admin_init_global() |
|
| 1619 | + { |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + |
|
| 1623 | + /** |
|
| 1624 | + * wp_loaded_global |
|
| 1625 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1626 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1627 | + * |
|
| 1628 | + * @return void |
|
| 1629 | + */ |
|
| 1630 | + public function wp_loaded() |
|
| 1631 | + { |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * admin_notices |
|
| 1637 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1638 | + * ALL EE_Admin pages. |
|
| 1639 | + * |
|
| 1640 | + * @return void |
|
| 1641 | + */ |
|
| 1642 | + public function admin_notices_global() |
|
| 1643 | + { |
|
| 1644 | + $this->_display_no_javascript_warning(); |
|
| 1645 | + $this->_display_espresso_notices(); |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + |
|
| 1649 | + public function network_admin_notices_global() |
|
| 1650 | + { |
|
| 1651 | + $this->_display_no_javascript_warning(); |
|
| 1652 | + $this->_display_espresso_notices(); |
|
| 1653 | + } |
|
| 1654 | + |
|
| 1655 | + |
|
| 1656 | + /** |
|
| 1657 | + * admin_footer_scripts_global |
|
| 1658 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1659 | + * will apply on ALL EE_Admin pages. |
|
| 1660 | + * |
|
| 1661 | + * @return void |
|
| 1662 | + */ |
|
| 1663 | + public function admin_footer_scripts_global() |
|
| 1664 | + { |
|
| 1665 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1666 | + $this->_add_admin_page_overlay(); |
|
| 1667 | + // if metaboxes are present we need to add the nonce field |
|
| 1668 | + if ( |
|
| 1669 | + isset($this->_route_config['metaboxes']) |
|
| 1670 | + || isset($this->_route_config['list_table']) |
|
| 1671 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1672 | + ) { |
|
| 1673 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1674 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1675 | + } |
|
| 1676 | + } |
|
| 1677 | + |
|
| 1678 | + |
|
| 1679 | + /** |
|
| 1680 | + * admin_footer_global |
|
| 1681 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1682 | + * This particular method will apply on ALL EE_Admin Pages. |
|
| 1683 | + * |
|
| 1684 | + * @return void |
|
| 1685 | + */ |
|
| 1686 | + public function admin_footer_global() |
|
| 1687 | + { |
|
| 1688 | + // dialog container for dialog helper |
|
| 1689 | + echo ' |
|
| 1690 | 1690 | <div class="ee-admin-dialog-container auto-hide hidden"> |
| 1691 | 1691 | <div class="ee-notices"></div> |
| 1692 | 1692 | <div class="ee-admin-dialog-container-inner-content"></div> |
| 1693 | 1693 | </div> |
| 1694 | 1694 | <span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span> |
| 1695 | 1695 | <input type="hidden" id="espresso_admin_current_page" value="' . esc_attr($this->_current_page) . '"/>'; |
| 1696 | - } |
|
| 1697 | - |
|
| 1698 | - |
|
| 1699 | - /** |
|
| 1700 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1701 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1702 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1703 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1704 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1705 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1706 | - * for the |
|
| 1707 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1708 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1709 | - * 'help_trigger_id' => array( |
|
| 1710 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1711 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1712 | - * ) |
|
| 1713 | - * ); |
|
| 1714 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1715 | - * |
|
| 1716 | - * @param array $help_array |
|
| 1717 | - * @param bool $display |
|
| 1718 | - * @return string content |
|
| 1719 | - * @throws DomainException |
|
| 1720 | - * @throws EE_Error |
|
| 1721 | - */ |
|
| 1722 | - protected function _set_help_popup_content(array $help_array = [], bool $display = false): string |
|
| 1723 | - { |
|
| 1724 | - $content = ''; |
|
| 1725 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1726 | - // loop through the array and setup content |
|
| 1727 | - foreach ($help_array as $trigger => $help) { |
|
| 1728 | - // make sure the array is setup properly |
|
| 1729 | - if (! isset($help['title'], $help['content'])) { |
|
| 1730 | - throw new EE_Error( |
|
| 1731 | - esc_html__( |
|
| 1732 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1733 | - 'event_espresso' |
|
| 1734 | - ) |
|
| 1735 | - ); |
|
| 1736 | - } |
|
| 1737 | - // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1738 | - $template_args = [ |
|
| 1739 | - 'help_popup_id' => $trigger, |
|
| 1740 | - 'help_popup_title' => $help['title'], |
|
| 1741 | - 'help_popup_content' => $help['content'], |
|
| 1742 | - ]; |
|
| 1743 | - $content .= EEH_Template::display_template( |
|
| 1744 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1745 | - $template_args, |
|
| 1746 | - true |
|
| 1747 | - ); |
|
| 1748 | - } |
|
| 1749 | - if ($display) { |
|
| 1750 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1751 | - return ''; |
|
| 1752 | - } |
|
| 1753 | - return $content; |
|
| 1754 | - } |
|
| 1755 | - |
|
| 1756 | - |
|
| 1757 | - /** |
|
| 1758 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1759 | - * |
|
| 1760 | - * @return array properly formatted array for help popup content |
|
| 1761 | - * @throws EE_Error |
|
| 1762 | - */ |
|
| 1763 | - private function _get_help_content(): array |
|
| 1764 | - { |
|
| 1765 | - // what is the method we're looking for? |
|
| 1766 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1767 | - // if method doesn't exist let's get out. |
|
| 1768 | - if (! method_exists($this, $method_name)) { |
|
| 1769 | - return []; |
|
| 1770 | - } |
|
| 1771 | - // k we're good to go let's retrieve the help array |
|
| 1772 | - $help_array = $this->{$method_name}(); |
|
| 1773 | - // make sure we've got an array! |
|
| 1774 | - if (! is_array($help_array)) { |
|
| 1775 | - throw new EE_Error( |
|
| 1776 | - esc_html__( |
|
| 1777 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1778 | - 'event_espresso' |
|
| 1779 | - ) |
|
| 1780 | - ); |
|
| 1781 | - } |
|
| 1782 | - return $help_array; |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - |
|
| 1786 | - /** |
|
| 1787 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1788 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1789 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1790 | - * |
|
| 1791 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1792 | - * @param bool $display if false then we return the trigger string |
|
| 1793 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1794 | - * @return string |
|
| 1795 | - * @throws DomainException |
|
| 1796 | - * @throws EE_Error |
|
| 1797 | - */ |
|
| 1798 | - protected function _set_help_trigger(string $trigger_id, bool $display = true, array $dimensions = ['400', '640']) |
|
| 1799 | - { |
|
| 1800 | - if ($this->request->isAjax()) { |
|
| 1801 | - return ''; |
|
| 1802 | - } |
|
| 1803 | - // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1804 | - $help_array = $this->_get_help_content(); |
|
| 1805 | - $help_content = ''; |
|
| 1806 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1807 | - $help_array[ $trigger_id ] = [ |
|
| 1808 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1809 | - 'content' => esc_html__( |
|
| 1810 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1811 | - 'event_espresso' |
|
| 1812 | - ), |
|
| 1813 | - ]; |
|
| 1814 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1815 | - } |
|
| 1816 | - $height = esc_attr($dimensions[0]) ?? 400; |
|
| 1817 | - $width = esc_attr($dimensions[1]) ?? 640; |
|
| 1818 | - $inlineId = esc_attr($trigger_id); |
|
| 1819 | - // let's setup the trigger |
|
| 1820 | - $content = " |
|
| 1696 | + } |
|
| 1697 | + |
|
| 1698 | + |
|
| 1699 | + /** |
|
| 1700 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1701 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1702 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1703 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1704 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1705 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1706 | + * for the |
|
| 1707 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1708 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1709 | + * 'help_trigger_id' => array( |
|
| 1710 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1711 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1712 | + * ) |
|
| 1713 | + * ); |
|
| 1714 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1715 | + * |
|
| 1716 | + * @param array $help_array |
|
| 1717 | + * @param bool $display |
|
| 1718 | + * @return string content |
|
| 1719 | + * @throws DomainException |
|
| 1720 | + * @throws EE_Error |
|
| 1721 | + */ |
|
| 1722 | + protected function _set_help_popup_content(array $help_array = [], bool $display = false): string |
|
| 1723 | + { |
|
| 1724 | + $content = ''; |
|
| 1725 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1726 | + // loop through the array and setup content |
|
| 1727 | + foreach ($help_array as $trigger => $help) { |
|
| 1728 | + // make sure the array is setup properly |
|
| 1729 | + if (! isset($help['title'], $help['content'])) { |
|
| 1730 | + throw new EE_Error( |
|
| 1731 | + esc_html__( |
|
| 1732 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1733 | + 'event_espresso' |
|
| 1734 | + ) |
|
| 1735 | + ); |
|
| 1736 | + } |
|
| 1737 | + // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1738 | + $template_args = [ |
|
| 1739 | + 'help_popup_id' => $trigger, |
|
| 1740 | + 'help_popup_title' => $help['title'], |
|
| 1741 | + 'help_popup_content' => $help['content'], |
|
| 1742 | + ]; |
|
| 1743 | + $content .= EEH_Template::display_template( |
|
| 1744 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1745 | + $template_args, |
|
| 1746 | + true |
|
| 1747 | + ); |
|
| 1748 | + } |
|
| 1749 | + if ($display) { |
|
| 1750 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1751 | + return ''; |
|
| 1752 | + } |
|
| 1753 | + return $content; |
|
| 1754 | + } |
|
| 1755 | + |
|
| 1756 | + |
|
| 1757 | + /** |
|
| 1758 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1759 | + * |
|
| 1760 | + * @return array properly formatted array for help popup content |
|
| 1761 | + * @throws EE_Error |
|
| 1762 | + */ |
|
| 1763 | + private function _get_help_content(): array |
|
| 1764 | + { |
|
| 1765 | + // what is the method we're looking for? |
|
| 1766 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1767 | + // if method doesn't exist let's get out. |
|
| 1768 | + if (! method_exists($this, $method_name)) { |
|
| 1769 | + return []; |
|
| 1770 | + } |
|
| 1771 | + // k we're good to go let's retrieve the help array |
|
| 1772 | + $help_array = $this->{$method_name}(); |
|
| 1773 | + // make sure we've got an array! |
|
| 1774 | + if (! is_array($help_array)) { |
|
| 1775 | + throw new EE_Error( |
|
| 1776 | + esc_html__( |
|
| 1777 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1778 | + 'event_espresso' |
|
| 1779 | + ) |
|
| 1780 | + ); |
|
| 1781 | + } |
|
| 1782 | + return $help_array; |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + |
|
| 1786 | + /** |
|
| 1787 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1788 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1789 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1790 | + * |
|
| 1791 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1792 | + * @param bool $display if false then we return the trigger string |
|
| 1793 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1794 | + * @return string |
|
| 1795 | + * @throws DomainException |
|
| 1796 | + * @throws EE_Error |
|
| 1797 | + */ |
|
| 1798 | + protected function _set_help_trigger(string $trigger_id, bool $display = true, array $dimensions = ['400', '640']) |
|
| 1799 | + { |
|
| 1800 | + if ($this->request->isAjax()) { |
|
| 1801 | + return ''; |
|
| 1802 | + } |
|
| 1803 | + // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1804 | + $help_array = $this->_get_help_content(); |
|
| 1805 | + $help_content = ''; |
|
| 1806 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1807 | + $help_array[ $trigger_id ] = [ |
|
| 1808 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1809 | + 'content' => esc_html__( |
|
| 1810 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1811 | + 'event_espresso' |
|
| 1812 | + ), |
|
| 1813 | + ]; |
|
| 1814 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1815 | + } |
|
| 1816 | + $height = esc_attr($dimensions[0]) ?? 400; |
|
| 1817 | + $width = esc_attr($dimensions[1]) ?? 640; |
|
| 1818 | + $inlineId = esc_attr($trigger_id); |
|
| 1819 | + // let's setup the trigger |
|
| 1820 | + $content = " |
|
| 1821 | 1821 | <a class='ee-dialog' href='?height=$height&width=$width&inlineId=$inlineId' target='_blank'> |
| 1822 | 1822 | <span class='question ee-help-popup-question'></span> |
| 1823 | 1823 | </a>"; |
| 1824 | - $content .= $help_content; |
|
| 1825 | - if ($display) { |
|
| 1826 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1827 | - return ''; |
|
| 1828 | - } |
|
| 1829 | - return $content; |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - |
|
| 1833 | - /** |
|
| 1834 | - * _add_global_screen_options |
|
| 1835 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1836 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1837 | - * |
|
| 1838 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1839 | - * see also WP_Screen object documents... |
|
| 1840 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1841 | - * @abstract |
|
| 1842 | - * @return void |
|
| 1843 | - */ |
|
| 1844 | - private function _add_global_screen_options() |
|
| 1845 | - { |
|
| 1846 | - } |
|
| 1847 | - |
|
| 1848 | - |
|
| 1849 | - /** |
|
| 1850 | - * _add_global_feature_pointers |
|
| 1851 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1852 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1853 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1854 | - * |
|
| 1855 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1856 | - * extended) also see: |
|
| 1857 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1858 | - * @abstract |
|
| 1859 | - * @return void |
|
| 1860 | - */ |
|
| 1861 | - private function _add_global_feature_pointers() |
|
| 1862 | - { |
|
| 1863 | - } |
|
| 1864 | - |
|
| 1865 | - |
|
| 1866 | - /** |
|
| 1867 | - * load_global_scripts_styles |
|
| 1868 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1869 | - * |
|
| 1870 | - * @return void |
|
| 1871 | - */ |
|
| 1872 | - public function load_global_scripts_styles() |
|
| 1873 | - { |
|
| 1874 | - // add debugging styles |
|
| 1875 | - if (WP_DEBUG) { |
|
| 1876 | - add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1877 | - } |
|
| 1878 | - // taking care of metaboxes |
|
| 1879 | - if ( |
|
| 1880 | - empty($this->_cpt_route) |
|
| 1881 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1882 | - ) { |
|
| 1883 | - wp_enqueue_script('dashboard'); |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH); |
|
| 1887 | - wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN); |
|
| 1888 | - // LOCALIZED DATA |
|
| 1889 | - // localize script for ajax lazy loading |
|
| 1890 | - wp_localize_script( |
|
| 1891 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 1892 | - 'eeLazyLoadingContainers', |
|
| 1893 | - apply_filters( |
|
| 1894 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1895 | - ['espresso_news_post_box_content'] |
|
| 1896 | - ) |
|
| 1897 | - ); |
|
| 1898 | - StatusChangeNotice::loadAssets(); |
|
| 1899 | - |
|
| 1900 | - add_filter( |
|
| 1901 | - 'admin_body_class', |
|
| 1902 | - function ($classes) { |
|
| 1903 | - if (strpos($classes, 'espresso-admin') === false) { |
|
| 1904 | - $classes .= ' espresso-admin'; |
|
| 1905 | - } |
|
| 1906 | - return $classes; |
|
| 1907 | - } |
|
| 1908 | - ); |
|
| 1909 | - } |
|
| 1910 | - |
|
| 1911 | - |
|
| 1912 | - /** |
|
| 1913 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1914 | - * |
|
| 1915 | - * @return void |
|
| 1916 | - */ |
|
| 1917 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1918 | - { |
|
| 1919 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1920 | - EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1921 | - __( |
|
| 1922 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 1923 | - 'event_espresso' |
|
| 1924 | - ) |
|
| 1925 | - ); |
|
| 1926 | - EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1927 | - EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1928 | - EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1929 | - EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1930 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1931 | - EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1932 | - EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1933 | - EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1934 | - EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1935 | - EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1936 | - EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1937 | - EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1938 | - EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1939 | - EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1940 | - EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1941 | - EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1942 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1943 | - EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1944 | - EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1945 | - EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1946 | - EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1947 | - EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1948 | - EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1949 | - EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1950 | - EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1951 | - EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1952 | - EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1953 | - EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1954 | - EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1955 | - EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1956 | - EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1957 | - EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1958 | - EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1959 | - EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1960 | - EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1961 | - EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1962 | - EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1963 | - EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - |
|
| 1967 | - /** |
|
| 1968 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1969 | - * |
|
| 1970 | - * @return void |
|
| 1971 | - */ |
|
| 1972 | - public function add_xdebug_style() |
|
| 1973 | - { |
|
| 1974 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - |
|
| 1978 | - /************************/ |
|
| 1979 | - /** LIST TABLE METHODS **/ |
|
| 1980 | - /************************/ |
|
| 1981 | - /** |
|
| 1982 | - * this sets up the list table if the current view requires it. |
|
| 1983 | - * |
|
| 1984 | - * @return void |
|
| 1985 | - * @throws EE_Error |
|
| 1986 | - * @throws InvalidArgumentException |
|
| 1987 | - * @throws InvalidDataTypeException |
|
| 1988 | - * @throws InvalidInterfaceException |
|
| 1989 | - */ |
|
| 1990 | - protected function _set_list_table() |
|
| 1991 | - { |
|
| 1992 | - // first is this a list_table view? |
|
| 1993 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1994 | - return; |
|
| 1995 | - } //not a list_table view so get out. |
|
| 1996 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 1997 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1998 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1999 | - // user error msg |
|
| 2000 | - $error_msg = esc_html__( |
|
| 2001 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2002 | - 'event_espresso' |
|
| 2003 | - ); |
|
| 2004 | - // developer error msg |
|
| 2005 | - $error_msg .= '||' |
|
| 2006 | - . sprintf( |
|
| 2007 | - esc_html__( |
|
| 2008 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2009 | - 'event_espresso' |
|
| 2010 | - ), |
|
| 2011 | - $this->_req_action, |
|
| 2012 | - $list_table_view |
|
| 2013 | - ); |
|
| 2014 | - throw new EE_Error($error_msg); |
|
| 2015 | - } |
|
| 2016 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2017 | - $this->_views = apply_filters( |
|
| 2018 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2019 | - $this->_views |
|
| 2020 | - ); |
|
| 2021 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2022 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2023 | - $this->_set_list_table_view(); |
|
| 2024 | - $this->_set_list_table_object(); |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - |
|
| 2028 | - /** |
|
| 2029 | - * set current view for List Table |
|
| 2030 | - * |
|
| 2031 | - * @return void |
|
| 2032 | - */ |
|
| 2033 | - protected function _set_list_table_view() |
|
| 2034 | - { |
|
| 2035 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2036 | - $status = $this->request->getRequestParam('status', null, DataType::KEY); |
|
| 2037 | - $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2038 | - ? $status |
|
| 2039 | - : $this->_view; |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | - |
|
| 2043 | - /** |
|
| 2044 | - * _set_list_table_object |
|
| 2045 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2046 | - * |
|
| 2047 | - * @throws InvalidInterfaceException |
|
| 2048 | - * @throws InvalidArgumentException |
|
| 2049 | - * @throws InvalidDataTypeException |
|
| 2050 | - * @throws EE_Error |
|
| 2051 | - * @throws InvalidInterfaceException |
|
| 2052 | - */ |
|
| 2053 | - protected function _set_list_table_object() |
|
| 2054 | - { |
|
| 2055 | - if (isset($this->_route_config['list_table'])) { |
|
| 2056 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2057 | - throw new EE_Error( |
|
| 2058 | - sprintf( |
|
| 2059 | - esc_html__( |
|
| 2060 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2061 | - 'event_espresso' |
|
| 2062 | - ), |
|
| 2063 | - $this->_route_config['list_table'], |
|
| 2064 | - $this->class_name |
|
| 2065 | - ) |
|
| 2066 | - ); |
|
| 2067 | - } |
|
| 2068 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2069 | - $this->_route_config['list_table'], |
|
| 2070 | - [ |
|
| 2071 | - $this, |
|
| 2072 | - LoaderFactory::getShared(AdminListTableFilters::class), |
|
| 2073 | - ] |
|
| 2074 | - ); |
|
| 2075 | - } |
|
| 2076 | - } |
|
| 2077 | - |
|
| 2078 | - |
|
| 2079 | - /** |
|
| 2080 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2081 | - * |
|
| 2082 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2083 | - * urls. The array should be indexed by the view it is being |
|
| 2084 | - * added to. |
|
| 2085 | - * @return array |
|
| 2086 | - */ |
|
| 2087 | - public function get_list_table_view_RLs(array $extra_query_args = []): array |
|
| 2088 | - { |
|
| 2089 | - $extra_query_args = apply_filters( |
|
| 2090 | - 'FHEE__EE_Admin_Page__get_list_table_view_RLs__extra_query_args', |
|
| 2091 | - $extra_query_args, |
|
| 2092 | - $this |
|
| 2093 | - ); |
|
| 2094 | - // cycle thru views |
|
| 2095 | - foreach ($this->_views as $key => $view) { |
|
| 2096 | - $query_args = []; |
|
| 2097 | - // check for current view |
|
| 2098 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2099 | - $query_args['action'] = $this->_req_action; |
|
| 2100 | - $action_nonce = "{$this->_req_action}_nonce"; |
|
| 2101 | - $query_args[ $action_nonce ] = wp_create_nonce($action_nonce); |
|
| 2102 | - $query_args['status'] = $view['slug']; |
|
| 2103 | - // merge any other arguments sent in. |
|
| 2104 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2105 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2106 | - } |
|
| 2107 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2108 | - } |
|
| 2109 | - return $this->_views; |
|
| 2110 | - } |
|
| 2111 | - |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2115 | - * |
|
| 2116 | - * @param int $max_entries total number of rows in the table |
|
| 2117 | - * @return string |
|
| 2118 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2119 | - * WP does it. |
|
| 2120 | - */ |
|
| 2121 | - protected function _entries_per_page_dropdown(int $max_entries = 0): string |
|
| 2122 | - { |
|
| 2123 | - $values = [10, 25, 50, 100]; |
|
| 2124 | - $per_page = $this->request->getRequestParam('per_page', 10, DataType::INT); |
|
| 2125 | - if ($max_entries) { |
|
| 2126 | - $values[] = $max_entries; |
|
| 2127 | - sort($values); |
|
| 2128 | - } |
|
| 2129 | - $entries_per_page_dropdown = ' |
|
| 1824 | + $content .= $help_content; |
|
| 1825 | + if ($display) { |
|
| 1826 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1827 | + return ''; |
|
| 1828 | + } |
|
| 1829 | + return $content; |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + |
|
| 1833 | + /** |
|
| 1834 | + * _add_global_screen_options |
|
| 1835 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1836 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1837 | + * |
|
| 1838 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1839 | + * see also WP_Screen object documents... |
|
| 1840 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1841 | + * @abstract |
|
| 1842 | + * @return void |
|
| 1843 | + */ |
|
| 1844 | + private function _add_global_screen_options() |
|
| 1845 | + { |
|
| 1846 | + } |
|
| 1847 | + |
|
| 1848 | + |
|
| 1849 | + /** |
|
| 1850 | + * _add_global_feature_pointers |
|
| 1851 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1852 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1853 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1854 | + * |
|
| 1855 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1856 | + * extended) also see: |
|
| 1857 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1858 | + * @abstract |
|
| 1859 | + * @return void |
|
| 1860 | + */ |
|
| 1861 | + private function _add_global_feature_pointers() |
|
| 1862 | + { |
|
| 1863 | + } |
|
| 1864 | + |
|
| 1865 | + |
|
| 1866 | + /** |
|
| 1867 | + * load_global_scripts_styles |
|
| 1868 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1869 | + * |
|
| 1870 | + * @return void |
|
| 1871 | + */ |
|
| 1872 | + public function load_global_scripts_styles() |
|
| 1873 | + { |
|
| 1874 | + // add debugging styles |
|
| 1875 | + if (WP_DEBUG) { |
|
| 1876 | + add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1877 | + } |
|
| 1878 | + // taking care of metaboxes |
|
| 1879 | + if ( |
|
| 1880 | + empty($this->_cpt_route) |
|
| 1881 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1882 | + ) { |
|
| 1883 | + wp_enqueue_script('dashboard'); |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH); |
|
| 1887 | + wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN); |
|
| 1888 | + // LOCALIZED DATA |
|
| 1889 | + // localize script for ajax lazy loading |
|
| 1890 | + wp_localize_script( |
|
| 1891 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 1892 | + 'eeLazyLoadingContainers', |
|
| 1893 | + apply_filters( |
|
| 1894 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1895 | + ['espresso_news_post_box_content'] |
|
| 1896 | + ) |
|
| 1897 | + ); |
|
| 1898 | + StatusChangeNotice::loadAssets(); |
|
| 1899 | + |
|
| 1900 | + add_filter( |
|
| 1901 | + 'admin_body_class', |
|
| 1902 | + function ($classes) { |
|
| 1903 | + if (strpos($classes, 'espresso-admin') === false) { |
|
| 1904 | + $classes .= ' espresso-admin'; |
|
| 1905 | + } |
|
| 1906 | + return $classes; |
|
| 1907 | + } |
|
| 1908 | + ); |
|
| 1909 | + } |
|
| 1910 | + |
|
| 1911 | + |
|
| 1912 | + /** |
|
| 1913 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1914 | + * |
|
| 1915 | + * @return void |
|
| 1916 | + */ |
|
| 1917 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1918 | + { |
|
| 1919 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1920 | + EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1921 | + __( |
|
| 1922 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 1923 | + 'event_espresso' |
|
| 1924 | + ) |
|
| 1925 | + ); |
|
| 1926 | + EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1927 | + EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1928 | + EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1929 | + EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1930 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1931 | + EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1932 | + EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1933 | + EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1934 | + EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1935 | + EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1936 | + EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1937 | + EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1938 | + EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1939 | + EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1940 | + EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1941 | + EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1942 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1943 | + EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1944 | + EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1945 | + EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1946 | + EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1947 | + EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1948 | + EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1949 | + EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1950 | + EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1951 | + EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1952 | + EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1953 | + EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1954 | + EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1955 | + EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1956 | + EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1957 | + EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1958 | + EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1959 | + EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1960 | + EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1961 | + EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1962 | + EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1963 | + EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1964 | + } |
|
| 1965 | + |
|
| 1966 | + |
|
| 1967 | + /** |
|
| 1968 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1969 | + * |
|
| 1970 | + * @return void |
|
| 1971 | + */ |
|
| 1972 | + public function add_xdebug_style() |
|
| 1973 | + { |
|
| 1974 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + |
|
| 1978 | + /************************/ |
|
| 1979 | + /** LIST TABLE METHODS **/ |
|
| 1980 | + /************************/ |
|
| 1981 | + /** |
|
| 1982 | + * this sets up the list table if the current view requires it. |
|
| 1983 | + * |
|
| 1984 | + * @return void |
|
| 1985 | + * @throws EE_Error |
|
| 1986 | + * @throws InvalidArgumentException |
|
| 1987 | + * @throws InvalidDataTypeException |
|
| 1988 | + * @throws InvalidInterfaceException |
|
| 1989 | + */ |
|
| 1990 | + protected function _set_list_table() |
|
| 1991 | + { |
|
| 1992 | + // first is this a list_table view? |
|
| 1993 | + if (! isset($this->_route_config['list_table'])) { |
|
| 1994 | + return; |
|
| 1995 | + } //not a list_table view so get out. |
|
| 1996 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 1997 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1998 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1999 | + // user error msg |
|
| 2000 | + $error_msg = esc_html__( |
|
| 2001 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2002 | + 'event_espresso' |
|
| 2003 | + ); |
|
| 2004 | + // developer error msg |
|
| 2005 | + $error_msg .= '||' |
|
| 2006 | + . sprintf( |
|
| 2007 | + esc_html__( |
|
| 2008 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2009 | + 'event_espresso' |
|
| 2010 | + ), |
|
| 2011 | + $this->_req_action, |
|
| 2012 | + $list_table_view |
|
| 2013 | + ); |
|
| 2014 | + throw new EE_Error($error_msg); |
|
| 2015 | + } |
|
| 2016 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2017 | + $this->_views = apply_filters( |
|
| 2018 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2019 | + $this->_views |
|
| 2020 | + ); |
|
| 2021 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2022 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2023 | + $this->_set_list_table_view(); |
|
| 2024 | + $this->_set_list_table_object(); |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + |
|
| 2028 | + /** |
|
| 2029 | + * set current view for List Table |
|
| 2030 | + * |
|
| 2031 | + * @return void |
|
| 2032 | + */ |
|
| 2033 | + protected function _set_list_table_view() |
|
| 2034 | + { |
|
| 2035 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2036 | + $status = $this->request->getRequestParam('status', null, DataType::KEY); |
|
| 2037 | + $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2038 | + ? $status |
|
| 2039 | + : $this->_view; |
|
| 2040 | + } |
|
| 2041 | + |
|
| 2042 | + |
|
| 2043 | + /** |
|
| 2044 | + * _set_list_table_object |
|
| 2045 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2046 | + * |
|
| 2047 | + * @throws InvalidInterfaceException |
|
| 2048 | + * @throws InvalidArgumentException |
|
| 2049 | + * @throws InvalidDataTypeException |
|
| 2050 | + * @throws EE_Error |
|
| 2051 | + * @throws InvalidInterfaceException |
|
| 2052 | + */ |
|
| 2053 | + protected function _set_list_table_object() |
|
| 2054 | + { |
|
| 2055 | + if (isset($this->_route_config['list_table'])) { |
|
| 2056 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2057 | + throw new EE_Error( |
|
| 2058 | + sprintf( |
|
| 2059 | + esc_html__( |
|
| 2060 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2061 | + 'event_espresso' |
|
| 2062 | + ), |
|
| 2063 | + $this->_route_config['list_table'], |
|
| 2064 | + $this->class_name |
|
| 2065 | + ) |
|
| 2066 | + ); |
|
| 2067 | + } |
|
| 2068 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2069 | + $this->_route_config['list_table'], |
|
| 2070 | + [ |
|
| 2071 | + $this, |
|
| 2072 | + LoaderFactory::getShared(AdminListTableFilters::class), |
|
| 2073 | + ] |
|
| 2074 | + ); |
|
| 2075 | + } |
|
| 2076 | + } |
|
| 2077 | + |
|
| 2078 | + |
|
| 2079 | + /** |
|
| 2080 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2081 | + * |
|
| 2082 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2083 | + * urls. The array should be indexed by the view it is being |
|
| 2084 | + * added to. |
|
| 2085 | + * @return array |
|
| 2086 | + */ |
|
| 2087 | + public function get_list_table_view_RLs(array $extra_query_args = []): array |
|
| 2088 | + { |
|
| 2089 | + $extra_query_args = apply_filters( |
|
| 2090 | + 'FHEE__EE_Admin_Page__get_list_table_view_RLs__extra_query_args', |
|
| 2091 | + $extra_query_args, |
|
| 2092 | + $this |
|
| 2093 | + ); |
|
| 2094 | + // cycle thru views |
|
| 2095 | + foreach ($this->_views as $key => $view) { |
|
| 2096 | + $query_args = []; |
|
| 2097 | + // check for current view |
|
| 2098 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2099 | + $query_args['action'] = $this->_req_action; |
|
| 2100 | + $action_nonce = "{$this->_req_action}_nonce"; |
|
| 2101 | + $query_args[ $action_nonce ] = wp_create_nonce($action_nonce); |
|
| 2102 | + $query_args['status'] = $view['slug']; |
|
| 2103 | + // merge any other arguments sent in. |
|
| 2104 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2105 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2106 | + } |
|
| 2107 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2108 | + } |
|
| 2109 | + return $this->_views; |
|
| 2110 | + } |
|
| 2111 | + |
|
| 2112 | + |
|
| 2113 | + /** |
|
| 2114 | + * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2115 | + * |
|
| 2116 | + * @param int $max_entries total number of rows in the table |
|
| 2117 | + * @return string |
|
| 2118 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2119 | + * WP does it. |
|
| 2120 | + */ |
|
| 2121 | + protected function _entries_per_page_dropdown(int $max_entries = 0): string |
|
| 2122 | + { |
|
| 2123 | + $values = [10, 25, 50, 100]; |
|
| 2124 | + $per_page = $this->request->getRequestParam('per_page', 10, DataType::INT); |
|
| 2125 | + if ($max_entries) { |
|
| 2126 | + $values[] = $max_entries; |
|
| 2127 | + sort($values); |
|
| 2128 | + } |
|
| 2129 | + $entries_per_page_dropdown = ' |
|
| 2130 | 2130 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2131 | 2131 | <label class="hide-if-no-js"> |
| 2132 | 2132 | Show |
| 2133 | 2133 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2134 | - foreach ($values as $value) { |
|
| 2135 | - if ($value < $max_entries) { |
|
| 2136 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2137 | - $entries_per_page_dropdown .= ' |
|
| 2134 | + foreach ($values as $value) { |
|
| 2135 | + if ($value < $max_entries) { |
|
| 2136 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2137 | + $entries_per_page_dropdown .= ' |
|
| 2138 | 2138 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2139 | - } |
|
| 2140 | - } |
|
| 2141 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2142 | - $entries_per_page_dropdown .= ' |
|
| 2139 | + } |
|
| 2140 | + } |
|
| 2141 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2142 | + $entries_per_page_dropdown .= ' |
|
| 2143 | 2143 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2144 | - $entries_per_page_dropdown .= ' |
|
| 2144 | + $entries_per_page_dropdown .= ' |
|
| 2145 | 2145 | </select> |
| 2146 | 2146 | entries |
| 2147 | 2147 | </label> |
| 2148 | 2148 | <input id="entries-per-page-btn" class="button button--secondary" type="submit" value="Go" > |
| 2149 | 2149 | </div> |
| 2150 | 2150 | '; |
| 2151 | - return $entries_per_page_dropdown; |
|
| 2152 | - } |
|
| 2153 | - |
|
| 2154 | - |
|
| 2155 | - /** |
|
| 2156 | - * _set_search_attributes |
|
| 2157 | - * |
|
| 2158 | - * @return void |
|
| 2159 | - */ |
|
| 2160 | - public function _set_search_attributes() |
|
| 2161 | - { |
|
| 2162 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2163 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2164 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2165 | - : $this->_search_btn_label |
|
| 2166 | - ); |
|
| 2167 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2168 | - } |
|
| 2169 | - |
|
| 2170 | - |
|
| 2171 | - |
|
| 2172 | - /*** END LIST TABLE METHODS **/ |
|
| 2173 | - |
|
| 2174 | - /** |
|
| 2175 | - * @return void |
|
| 2176 | - * @throws EE_Error |
|
| 2177 | - */ |
|
| 2178 | - public function addRegisteredMetaBoxes() |
|
| 2179 | - { |
|
| 2180 | - remove_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99); |
|
| 2181 | - $this->_add_registered_meta_boxes(); |
|
| 2182 | - } |
|
| 2183 | - |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * _add_registered_metaboxes |
|
| 2187 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2188 | - * |
|
| 2189 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2190 | - * @return void |
|
| 2191 | - * @throws EE_Error |
|
| 2192 | - */ |
|
| 2193 | - private function _add_registered_meta_boxes() |
|
| 2194 | - { |
|
| 2195 | - // we only add meta boxes if the page_route calls for it |
|
| 2196 | - if (isset($this->_route_config['metaboxes']) && is_array($this->_route_config['metaboxes'])) { |
|
| 2197 | - // this simply loops through the callbacks provided |
|
| 2198 | - // and checks if there is a corresponding callback registered by the child |
|
| 2199 | - // if there is then we go ahead and process the metabox loader. |
|
| 2200 | - foreach ($this->_route_config['metaboxes'] as $key => $metabox_callback) { |
|
| 2201 | - // first check for Closures |
|
| 2202 | - if ($metabox_callback instanceof Closure) { |
|
| 2203 | - $result = $metabox_callback(); |
|
| 2204 | - } elseif (is_callable($metabox_callback)) { |
|
| 2205 | - $result = call_user_func($metabox_callback); |
|
| 2206 | - } elseif (method_exists($this, $metabox_callback)) { |
|
| 2207 | - $result = $this->{$metabox_callback}(); |
|
| 2208 | - } else { |
|
| 2209 | - $result = false; |
|
| 2210 | - } |
|
| 2211 | - if ($result === false) { |
|
| 2212 | - // user error msg |
|
| 2213 | - $error_msg = esc_html__( |
|
| 2214 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2215 | - 'event_espresso' |
|
| 2216 | - ); |
|
| 2217 | - // developer error msg |
|
| 2218 | - $error_msg .= '||' |
|
| 2219 | - . sprintf( |
|
| 2220 | - esc_html__( |
|
| 2221 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2222 | - 'event_espresso' |
|
| 2223 | - ), |
|
| 2224 | - $metabox_callback |
|
| 2225 | - ); |
|
| 2226 | - throw new EE_Error($error_msg); |
|
| 2227 | - } |
|
| 2228 | - unset($this->_route_config['metaboxes'][ $key ]); |
|
| 2229 | - } |
|
| 2230 | - } |
|
| 2231 | - } |
|
| 2232 | - |
|
| 2233 | - |
|
| 2234 | - /** |
|
| 2235 | - * _add_screen_columns |
|
| 2236 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2237 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2238 | - * |
|
| 2239 | - * @return void |
|
| 2240 | - */ |
|
| 2241 | - private function _add_screen_columns() |
|
| 2242 | - { |
|
| 2243 | - if ( |
|
| 2244 | - isset($this->_route_config['columns']) |
|
| 2245 | - && is_array($this->_route_config['columns']) |
|
| 2246 | - && count($this->_route_config['columns']) === 2 |
|
| 2247 | - ) { |
|
| 2248 | - add_screen_option( |
|
| 2249 | - 'layout_columns', |
|
| 2250 | - [ |
|
| 2251 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2252 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2253 | - ] |
|
| 2254 | - ); |
|
| 2255 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2256 | - $screen_id = $this->_current_screen->id; |
|
| 2257 | - $screen_columns = (int) get_user_option("screen_layout_$screen_id"); |
|
| 2258 | - $total_columns = ! empty($screen_columns) |
|
| 2259 | - ? $screen_columns |
|
| 2260 | - : $this->_route_config['columns'][1]; |
|
| 2261 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2262 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2263 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2264 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2265 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2266 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2267 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2268 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2269 | - } |
|
| 2270 | - } |
|
| 2271 | - |
|
| 2272 | - |
|
| 2273 | - |
|
| 2274 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2275 | - |
|
| 2276 | - |
|
| 2277 | - /** |
|
| 2278 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2279 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2280 | - * these get loaded on. |
|
| 2281 | - */ |
|
| 2282 | - private function _espresso_news_post_box() |
|
| 2283 | - { |
|
| 2284 | - $news_box_title = apply_filters( |
|
| 2285 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2286 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2287 | - ); |
|
| 2288 | - $this->addMetaBox( |
|
| 2289 | - 'espresso_news_post_box', |
|
| 2290 | - $news_box_title, |
|
| 2291 | - [ |
|
| 2292 | - $this, |
|
| 2293 | - 'espresso_news_post_box', |
|
| 2294 | - ], |
|
| 2295 | - $this->_wp_page_slug, |
|
| 2296 | - 'side', |
|
| 2297 | - 'low' |
|
| 2298 | - ); |
|
| 2299 | - } |
|
| 2300 | - |
|
| 2301 | - |
|
| 2302 | - /** |
|
| 2303 | - * Code for setting up espresso ratings request metabox. |
|
| 2304 | - */ |
|
| 2305 | - protected function _espresso_ratings_request() |
|
| 2306 | - { |
|
| 2307 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2308 | - return; |
|
| 2309 | - } |
|
| 2310 | - $ratings_box_title = apply_filters( |
|
| 2311 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2312 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2313 | - ); |
|
| 2314 | - $this->addMetaBox( |
|
| 2315 | - 'espresso_ratings_request', |
|
| 2316 | - $ratings_box_title, |
|
| 2317 | - [ |
|
| 2318 | - $this, |
|
| 2319 | - 'espresso_ratings_request', |
|
| 2320 | - ], |
|
| 2321 | - $this->_wp_page_slug, |
|
| 2322 | - 'side' |
|
| 2323 | - ); |
|
| 2324 | - } |
|
| 2325 | - |
|
| 2326 | - |
|
| 2327 | - /** |
|
| 2328 | - * Code for setting up espresso ratings request metabox content. |
|
| 2329 | - * |
|
| 2330 | - * @throws DomainException |
|
| 2331 | - */ |
|
| 2332 | - public function espresso_ratings_request() |
|
| 2333 | - { |
|
| 2334 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2335 | - } |
|
| 2336 | - |
|
| 2337 | - |
|
| 2338 | - public static function cached_rss_display(string $rss_id, string $url): bool |
|
| 2339 | - { |
|
| 2340 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2341 | - . esc_html__('Loading…', 'event_espresso') |
|
| 2342 | - . '</p><p class="hide-if-js">' |
|
| 2343 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2344 | - . '</p>'; |
|
| 2345 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2346 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2347 | - $post = '</div>' . "\n"; |
|
| 2348 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2349 | - $output = get_transient($cache_key); |
|
| 2350 | - if ($output !== false) { |
|
| 2351 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2352 | - return true; |
|
| 2353 | - } |
|
| 2354 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2355 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2356 | - return false; |
|
| 2357 | - } |
|
| 2358 | - ob_start(); |
|
| 2359 | - wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2360 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2361 | - return true; |
|
| 2362 | - } |
|
| 2363 | - |
|
| 2364 | - |
|
| 2365 | - public function espresso_news_post_box() |
|
| 2366 | - { |
|
| 2367 | - ?> |
|
| 2151 | + return $entries_per_page_dropdown; |
|
| 2152 | + } |
|
| 2153 | + |
|
| 2154 | + |
|
| 2155 | + /** |
|
| 2156 | + * _set_search_attributes |
|
| 2157 | + * |
|
| 2158 | + * @return void |
|
| 2159 | + */ |
|
| 2160 | + public function _set_search_attributes() |
|
| 2161 | + { |
|
| 2162 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2163 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2164 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2165 | + : $this->_search_btn_label |
|
| 2166 | + ); |
|
| 2167 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + |
|
| 2171 | + |
|
| 2172 | + /*** END LIST TABLE METHODS **/ |
|
| 2173 | + |
|
| 2174 | + /** |
|
| 2175 | + * @return void |
|
| 2176 | + * @throws EE_Error |
|
| 2177 | + */ |
|
| 2178 | + public function addRegisteredMetaBoxes() |
|
| 2179 | + { |
|
| 2180 | + remove_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99); |
|
| 2181 | + $this->_add_registered_meta_boxes(); |
|
| 2182 | + } |
|
| 2183 | + |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * _add_registered_metaboxes |
|
| 2187 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2188 | + * |
|
| 2189 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2190 | + * @return void |
|
| 2191 | + * @throws EE_Error |
|
| 2192 | + */ |
|
| 2193 | + private function _add_registered_meta_boxes() |
|
| 2194 | + { |
|
| 2195 | + // we only add meta boxes if the page_route calls for it |
|
| 2196 | + if (isset($this->_route_config['metaboxes']) && is_array($this->_route_config['metaboxes'])) { |
|
| 2197 | + // this simply loops through the callbacks provided |
|
| 2198 | + // and checks if there is a corresponding callback registered by the child |
|
| 2199 | + // if there is then we go ahead and process the metabox loader. |
|
| 2200 | + foreach ($this->_route_config['metaboxes'] as $key => $metabox_callback) { |
|
| 2201 | + // first check for Closures |
|
| 2202 | + if ($metabox_callback instanceof Closure) { |
|
| 2203 | + $result = $metabox_callback(); |
|
| 2204 | + } elseif (is_callable($metabox_callback)) { |
|
| 2205 | + $result = call_user_func($metabox_callback); |
|
| 2206 | + } elseif (method_exists($this, $metabox_callback)) { |
|
| 2207 | + $result = $this->{$metabox_callback}(); |
|
| 2208 | + } else { |
|
| 2209 | + $result = false; |
|
| 2210 | + } |
|
| 2211 | + if ($result === false) { |
|
| 2212 | + // user error msg |
|
| 2213 | + $error_msg = esc_html__( |
|
| 2214 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2215 | + 'event_espresso' |
|
| 2216 | + ); |
|
| 2217 | + // developer error msg |
|
| 2218 | + $error_msg .= '||' |
|
| 2219 | + . sprintf( |
|
| 2220 | + esc_html__( |
|
| 2221 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2222 | + 'event_espresso' |
|
| 2223 | + ), |
|
| 2224 | + $metabox_callback |
|
| 2225 | + ); |
|
| 2226 | + throw new EE_Error($error_msg); |
|
| 2227 | + } |
|
| 2228 | + unset($this->_route_config['metaboxes'][ $key ]); |
|
| 2229 | + } |
|
| 2230 | + } |
|
| 2231 | + } |
|
| 2232 | + |
|
| 2233 | + |
|
| 2234 | + /** |
|
| 2235 | + * _add_screen_columns |
|
| 2236 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2237 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2238 | + * |
|
| 2239 | + * @return void |
|
| 2240 | + */ |
|
| 2241 | + private function _add_screen_columns() |
|
| 2242 | + { |
|
| 2243 | + if ( |
|
| 2244 | + isset($this->_route_config['columns']) |
|
| 2245 | + && is_array($this->_route_config['columns']) |
|
| 2246 | + && count($this->_route_config['columns']) === 2 |
|
| 2247 | + ) { |
|
| 2248 | + add_screen_option( |
|
| 2249 | + 'layout_columns', |
|
| 2250 | + [ |
|
| 2251 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2252 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2253 | + ] |
|
| 2254 | + ); |
|
| 2255 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2256 | + $screen_id = $this->_current_screen->id; |
|
| 2257 | + $screen_columns = (int) get_user_option("screen_layout_$screen_id"); |
|
| 2258 | + $total_columns = ! empty($screen_columns) |
|
| 2259 | + ? $screen_columns |
|
| 2260 | + : $this->_route_config['columns'][1]; |
|
| 2261 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2262 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2263 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2264 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2265 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2266 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2267 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2268 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2269 | + } |
|
| 2270 | + } |
|
| 2271 | + |
|
| 2272 | + |
|
| 2273 | + |
|
| 2274 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2275 | + |
|
| 2276 | + |
|
| 2277 | + /** |
|
| 2278 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2279 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2280 | + * these get loaded on. |
|
| 2281 | + */ |
|
| 2282 | + private function _espresso_news_post_box() |
|
| 2283 | + { |
|
| 2284 | + $news_box_title = apply_filters( |
|
| 2285 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2286 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2287 | + ); |
|
| 2288 | + $this->addMetaBox( |
|
| 2289 | + 'espresso_news_post_box', |
|
| 2290 | + $news_box_title, |
|
| 2291 | + [ |
|
| 2292 | + $this, |
|
| 2293 | + 'espresso_news_post_box', |
|
| 2294 | + ], |
|
| 2295 | + $this->_wp_page_slug, |
|
| 2296 | + 'side', |
|
| 2297 | + 'low' |
|
| 2298 | + ); |
|
| 2299 | + } |
|
| 2300 | + |
|
| 2301 | + |
|
| 2302 | + /** |
|
| 2303 | + * Code for setting up espresso ratings request metabox. |
|
| 2304 | + */ |
|
| 2305 | + protected function _espresso_ratings_request() |
|
| 2306 | + { |
|
| 2307 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2308 | + return; |
|
| 2309 | + } |
|
| 2310 | + $ratings_box_title = apply_filters( |
|
| 2311 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2312 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2313 | + ); |
|
| 2314 | + $this->addMetaBox( |
|
| 2315 | + 'espresso_ratings_request', |
|
| 2316 | + $ratings_box_title, |
|
| 2317 | + [ |
|
| 2318 | + $this, |
|
| 2319 | + 'espresso_ratings_request', |
|
| 2320 | + ], |
|
| 2321 | + $this->_wp_page_slug, |
|
| 2322 | + 'side' |
|
| 2323 | + ); |
|
| 2324 | + } |
|
| 2325 | + |
|
| 2326 | + |
|
| 2327 | + /** |
|
| 2328 | + * Code for setting up espresso ratings request metabox content. |
|
| 2329 | + * |
|
| 2330 | + * @throws DomainException |
|
| 2331 | + */ |
|
| 2332 | + public function espresso_ratings_request() |
|
| 2333 | + { |
|
| 2334 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2335 | + } |
|
| 2336 | + |
|
| 2337 | + |
|
| 2338 | + public static function cached_rss_display(string $rss_id, string $url): bool |
|
| 2339 | + { |
|
| 2340 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2341 | + . esc_html__('Loading…', 'event_espresso') |
|
| 2342 | + . '</p><p class="hide-if-js">' |
|
| 2343 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2344 | + . '</p>'; |
|
| 2345 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2346 | + $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2347 | + $post = '</div>' . "\n"; |
|
| 2348 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2349 | + $output = get_transient($cache_key); |
|
| 2350 | + if ($output !== false) { |
|
| 2351 | + echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2352 | + return true; |
|
| 2353 | + } |
|
| 2354 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2355 | + echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2356 | + return false; |
|
| 2357 | + } |
|
| 2358 | + ob_start(); |
|
| 2359 | + wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2360 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2361 | + return true; |
|
| 2362 | + } |
|
| 2363 | + |
|
| 2364 | + |
|
| 2365 | + public function espresso_news_post_box() |
|
| 2366 | + { |
|
| 2367 | + ?> |
|
| 2368 | 2368 | <div class="padding"> |
| 2369 | 2369 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2370 | 2370 | <?php |
| 2371 | - // Get RSS Feed(s) |
|
| 2372 | - EE_Admin_Page::cached_rss_display( |
|
| 2373 | - 'espresso_news_post_box_content', |
|
| 2374 | - esc_url_raw( |
|
| 2375 | - apply_filters( |
|
| 2376 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2377 | - 'https://eventespresso.com/feed/' |
|
| 2378 | - ) |
|
| 2379 | - ) |
|
| 2380 | - ); |
|
| 2381 | - ?> |
|
| 2371 | + // Get RSS Feed(s) |
|
| 2372 | + EE_Admin_Page::cached_rss_display( |
|
| 2373 | + 'espresso_news_post_box_content', |
|
| 2374 | + esc_url_raw( |
|
| 2375 | + apply_filters( |
|
| 2376 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2377 | + 'https://eventespresso.com/feed/' |
|
| 2378 | + ) |
|
| 2379 | + ) |
|
| 2380 | + ); |
|
| 2381 | + ?> |
|
| 2382 | 2382 | </div> |
| 2383 | 2383 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2384 | 2384 | </div> |
| 2385 | 2385 | <?php |
| 2386 | - } |
|
| 2387 | - |
|
| 2388 | - |
|
| 2389 | - private function _espresso_links_post_box() |
|
| 2390 | - { |
|
| 2391 | - // Hiding until we actually have content to put in here... |
|
| 2392 | - // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2393 | - } |
|
| 2394 | - |
|
| 2395 | - |
|
| 2396 | - public function espresso_links_post_box() |
|
| 2397 | - { |
|
| 2398 | - // Hiding until we actually have content to put in here... |
|
| 2399 | - // EEH_Template::display_template( |
|
| 2400 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2401 | - // ); |
|
| 2402 | - } |
|
| 2403 | - |
|
| 2404 | - |
|
| 2405 | - protected function _espresso_sponsors_post_box() |
|
| 2406 | - { |
|
| 2407 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2408 | - $this->addMetaBox( |
|
| 2409 | - 'espresso_sponsors_post_box', |
|
| 2410 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2411 | - [$this, 'espresso_sponsors_post_box'], |
|
| 2412 | - $this->_wp_page_slug, |
|
| 2413 | - 'side' |
|
| 2414 | - ); |
|
| 2415 | - } |
|
| 2416 | - } |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - public function espresso_sponsors_post_box() |
|
| 2420 | - { |
|
| 2421 | - EEH_Template::display_template( |
|
| 2422 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2423 | - ); |
|
| 2424 | - } |
|
| 2425 | - |
|
| 2426 | - |
|
| 2427 | - /** |
|
| 2428 | - * if there is [ 'label' => [ 'publishbox' => 'some title' ]] |
|
| 2429 | - * present in the _page_config array, then we'll use that for the metabox label. |
|
| 2430 | - * Otherwise we'll just use publish |
|
| 2431 | - * (publishbox itself could be an array of labels indexed by routes) |
|
| 2432 | - * |
|
| 2433 | - * @return string |
|
| 2434 | - * @since 5.0.0.p |
|
| 2435 | - */ |
|
| 2436 | - protected function getPublishBoxTitle(): string |
|
| 2437 | - { |
|
| 2438 | - $publish_box_title = esc_html__('Publish', 'event_espresso'); |
|
| 2439 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2440 | - if (is_array($this->_labels['publishbox'])) { |
|
| 2441 | - $publish_box_title = $this->_labels['publishbox'][ $this->_req_action ] ?? $publish_box_title; |
|
| 2442 | - } else { |
|
| 2443 | - $publish_box_title = $this->_labels['publishbox']; |
|
| 2444 | - } |
|
| 2445 | - } |
|
| 2446 | - return apply_filters( |
|
| 2447 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2448 | - $publish_box_title, |
|
| 2449 | - $this->_req_action, |
|
| 2450 | - $this |
|
| 2451 | - ); |
|
| 2452 | - } |
|
| 2453 | - |
|
| 2454 | - |
|
| 2455 | - /** |
|
| 2456 | - * @throws EE_Error |
|
| 2457 | - */ |
|
| 2458 | - private function _publish_post_box() |
|
| 2459 | - { |
|
| 2460 | - $title = $this->getPublishBoxTitle(); |
|
| 2461 | - if (empty($this->_template_args['save_buttons'])) { |
|
| 2462 | - $this->_set_publish_post_box_vars(sanitize_key($title), "espresso_{$this->page_slug}_editor_overview"); |
|
| 2463 | - } else { |
|
| 2464 | - $this->addPublishPostMetaBoxHiddenFields( |
|
| 2465 | - sanitize_key($title), |
|
| 2466 | - ['type' => 'hidden', 'value' => "espresso_{$this->page_slug}_editor_overview"] |
|
| 2467 | - ); |
|
| 2468 | - } |
|
| 2469 | - $this->addMetaBox( |
|
| 2470 | - "espresso_{$this->page_slug}_editor_overview", |
|
| 2471 | - $title, |
|
| 2472 | - [$this, 'editor_overview'], |
|
| 2473 | - $this->_current_screen->id, |
|
| 2474 | - 'side', |
|
| 2475 | - 'high' |
|
| 2476 | - ); |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - |
|
| 2480 | - public function editor_overview() |
|
| 2481 | - { |
|
| 2482 | - /** |
|
| 2483 | - * @var string $publish_box_extra_content |
|
| 2484 | - * @var string $publish_hidden_fields |
|
| 2485 | - * @var string $publish_delete_link |
|
| 2486 | - * @var string $save_buttons |
|
| 2487 | - */ |
|
| 2488 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2489 | - $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? ''; |
|
| 2490 | - echo EEH_Template::display_template( |
|
| 2491 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2492 | - $this->_template_args, |
|
| 2493 | - true |
|
| 2494 | - ); |
|
| 2495 | - } |
|
| 2496 | - |
|
| 2497 | - |
|
| 2498 | - /** end of globally available metaboxes section **/ |
|
| 2499 | - |
|
| 2500 | - |
|
| 2501 | - /** |
|
| 2502 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2503 | - * Note: currently there is no validation for this. However, if you want the delete button, the |
|
| 2504 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2505 | - * values for the name and id arguments. |
|
| 2506 | - * |
|
| 2507 | - * @param string|null $name key used for the action ID (i.e. event_id) |
|
| 2508 | - * @param int|string $id id attached to the item published |
|
| 2509 | - * @param string|null $delete page route callback for the delete action |
|
| 2510 | - * @param string|null $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2511 | - * @param bool $both_btns whether to display BOTH the "Save & Close" and "Save" buttons |
|
| 2512 | - * or just the "Save" button |
|
| 2513 | - * @throws EE_Error |
|
| 2514 | - * @throws InvalidArgumentException |
|
| 2515 | - * @throws InvalidDataTypeException |
|
| 2516 | - * @throws InvalidInterfaceException |
|
| 2517 | - * @todo Add in validation for name/id arguments. |
|
| 2518 | - */ |
|
| 2519 | - protected function _set_publish_post_box_vars( |
|
| 2520 | - ?string $name = '', |
|
| 2521 | - $id = 0, |
|
| 2522 | - ?string $delete = '', |
|
| 2523 | - ?string $save_close_redirect_URL = '', |
|
| 2524 | - bool $both_btns = true |
|
| 2525 | - ) { |
|
| 2526 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2527 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2528 | - ? $save_close_redirect_URL |
|
| 2529 | - : $this->_admin_base_url; |
|
| 2530 | - // create the Save & Close and Save buttons |
|
| 2531 | - $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2532 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2533 | - $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? ''; |
|
| 2534 | - if ($delete && ! empty($id) && empty($this->_template_args['publish_delete_link'])) { |
|
| 2535 | - // make sure we have a default if just true is sent. |
|
| 2536 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2537 | - $this->_template_args['publish_delete_link'] = $this->get_action_link_or_button( |
|
| 2538 | - $delete, |
|
| 2539 | - $delete, |
|
| 2540 | - [$name => $id], |
|
| 2541 | - 'submitdelete deletion button button--outline button--caution' |
|
| 2542 | - ); |
|
| 2543 | - } |
|
| 2544 | - if (! isset($this->_template_args['publish_delete_link'])) { |
|
| 2545 | - $this->_template_args['publish_delete_link'] = ''; |
|
| 2546 | - } |
|
| 2547 | - if (! empty($name) && ! empty($id)) { |
|
| 2548 | - $this->addPublishPostMetaBoxHiddenFields($name, ['type' => 'hidden', 'value' => $id]); |
|
| 2549 | - } |
|
| 2550 | - $hidden_fields = $this->_generate_admin_form_fields($this->publish_post_meta_box_hidden_fields, 'array'); |
|
| 2551 | - // add hidden fields |
|
| 2552 | - $this->_template_args['publish_hidden_fields'] = $this->_template_args['publish_hidden_fields'] ?? ''; |
|
| 2553 | - foreach ($hidden_fields as $hidden_field) { |
|
| 2554 | - $this->_template_args['publish_hidden_fields'] .= $hidden_field['field'] ?? ''; |
|
| 2555 | - } |
|
| 2556 | - } |
|
| 2557 | - |
|
| 2558 | - |
|
| 2559 | - /** |
|
| 2560 | - * @param string|null $name |
|
| 2561 | - * @param int|string $id |
|
| 2562 | - * @param string|null $delete |
|
| 2563 | - * @param string|null $save_close_redirect_URL |
|
| 2564 | - * @param bool $both_btns |
|
| 2565 | - * @throws EE_Error |
|
| 2566 | - */ |
|
| 2567 | - public function set_publish_post_box_vars( |
|
| 2568 | - ?string $name = '', |
|
| 2569 | - $id = 0, |
|
| 2570 | - ?string $delete = '', |
|
| 2571 | - ?string $save_close_redirect_URL = '', |
|
| 2572 | - bool $both_btns = false |
|
| 2573 | - ) { |
|
| 2574 | - $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2575 | - } |
|
| 2576 | - |
|
| 2577 | - |
|
| 2578 | - protected function addPublishPostMetaBoxHiddenFields(string $field_name, array $field_attributes) |
|
| 2579 | - { |
|
| 2580 | - $this->publish_post_meta_box_hidden_fields[ $field_name ] = $field_attributes; |
|
| 2581 | - } |
|
| 2582 | - |
|
| 2583 | - |
|
| 2584 | - /** |
|
| 2585 | - * displays an error message to ppl who have javascript disabled |
|
| 2586 | - * |
|
| 2587 | - * @return void |
|
| 2588 | - */ |
|
| 2589 | - private function _display_no_javascript_warning() |
|
| 2590 | - { |
|
| 2591 | - ?> |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + |
|
| 2389 | + private function _espresso_links_post_box() |
|
| 2390 | + { |
|
| 2391 | + // Hiding until we actually have content to put in here... |
|
| 2392 | + // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2393 | + } |
|
| 2394 | + |
|
| 2395 | + |
|
| 2396 | + public function espresso_links_post_box() |
|
| 2397 | + { |
|
| 2398 | + // Hiding until we actually have content to put in here... |
|
| 2399 | + // EEH_Template::display_template( |
|
| 2400 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2401 | + // ); |
|
| 2402 | + } |
|
| 2403 | + |
|
| 2404 | + |
|
| 2405 | + protected function _espresso_sponsors_post_box() |
|
| 2406 | + { |
|
| 2407 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2408 | + $this->addMetaBox( |
|
| 2409 | + 'espresso_sponsors_post_box', |
|
| 2410 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2411 | + [$this, 'espresso_sponsors_post_box'], |
|
| 2412 | + $this->_wp_page_slug, |
|
| 2413 | + 'side' |
|
| 2414 | + ); |
|
| 2415 | + } |
|
| 2416 | + } |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + public function espresso_sponsors_post_box() |
|
| 2420 | + { |
|
| 2421 | + EEH_Template::display_template( |
|
| 2422 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2423 | + ); |
|
| 2424 | + } |
|
| 2425 | + |
|
| 2426 | + |
|
| 2427 | + /** |
|
| 2428 | + * if there is [ 'label' => [ 'publishbox' => 'some title' ]] |
|
| 2429 | + * present in the _page_config array, then we'll use that for the metabox label. |
|
| 2430 | + * Otherwise we'll just use publish |
|
| 2431 | + * (publishbox itself could be an array of labels indexed by routes) |
|
| 2432 | + * |
|
| 2433 | + * @return string |
|
| 2434 | + * @since 5.0.0.p |
|
| 2435 | + */ |
|
| 2436 | + protected function getPublishBoxTitle(): string |
|
| 2437 | + { |
|
| 2438 | + $publish_box_title = esc_html__('Publish', 'event_espresso'); |
|
| 2439 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2440 | + if (is_array($this->_labels['publishbox'])) { |
|
| 2441 | + $publish_box_title = $this->_labels['publishbox'][ $this->_req_action ] ?? $publish_box_title; |
|
| 2442 | + } else { |
|
| 2443 | + $publish_box_title = $this->_labels['publishbox']; |
|
| 2444 | + } |
|
| 2445 | + } |
|
| 2446 | + return apply_filters( |
|
| 2447 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2448 | + $publish_box_title, |
|
| 2449 | + $this->_req_action, |
|
| 2450 | + $this |
|
| 2451 | + ); |
|
| 2452 | + } |
|
| 2453 | + |
|
| 2454 | + |
|
| 2455 | + /** |
|
| 2456 | + * @throws EE_Error |
|
| 2457 | + */ |
|
| 2458 | + private function _publish_post_box() |
|
| 2459 | + { |
|
| 2460 | + $title = $this->getPublishBoxTitle(); |
|
| 2461 | + if (empty($this->_template_args['save_buttons'])) { |
|
| 2462 | + $this->_set_publish_post_box_vars(sanitize_key($title), "espresso_{$this->page_slug}_editor_overview"); |
|
| 2463 | + } else { |
|
| 2464 | + $this->addPublishPostMetaBoxHiddenFields( |
|
| 2465 | + sanitize_key($title), |
|
| 2466 | + ['type' => 'hidden', 'value' => "espresso_{$this->page_slug}_editor_overview"] |
|
| 2467 | + ); |
|
| 2468 | + } |
|
| 2469 | + $this->addMetaBox( |
|
| 2470 | + "espresso_{$this->page_slug}_editor_overview", |
|
| 2471 | + $title, |
|
| 2472 | + [$this, 'editor_overview'], |
|
| 2473 | + $this->_current_screen->id, |
|
| 2474 | + 'side', |
|
| 2475 | + 'high' |
|
| 2476 | + ); |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + |
|
| 2480 | + public function editor_overview() |
|
| 2481 | + { |
|
| 2482 | + /** |
|
| 2483 | + * @var string $publish_box_extra_content |
|
| 2484 | + * @var string $publish_hidden_fields |
|
| 2485 | + * @var string $publish_delete_link |
|
| 2486 | + * @var string $save_buttons |
|
| 2487 | + */ |
|
| 2488 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2489 | + $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? ''; |
|
| 2490 | + echo EEH_Template::display_template( |
|
| 2491 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2492 | + $this->_template_args, |
|
| 2493 | + true |
|
| 2494 | + ); |
|
| 2495 | + } |
|
| 2496 | + |
|
| 2497 | + |
|
| 2498 | + /** end of globally available metaboxes section **/ |
|
| 2499 | + |
|
| 2500 | + |
|
| 2501 | + /** |
|
| 2502 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2503 | + * Note: currently there is no validation for this. However, if you want the delete button, the |
|
| 2504 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2505 | + * values for the name and id arguments. |
|
| 2506 | + * |
|
| 2507 | + * @param string|null $name key used for the action ID (i.e. event_id) |
|
| 2508 | + * @param int|string $id id attached to the item published |
|
| 2509 | + * @param string|null $delete page route callback for the delete action |
|
| 2510 | + * @param string|null $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2511 | + * @param bool $both_btns whether to display BOTH the "Save & Close" and "Save" buttons |
|
| 2512 | + * or just the "Save" button |
|
| 2513 | + * @throws EE_Error |
|
| 2514 | + * @throws InvalidArgumentException |
|
| 2515 | + * @throws InvalidDataTypeException |
|
| 2516 | + * @throws InvalidInterfaceException |
|
| 2517 | + * @todo Add in validation for name/id arguments. |
|
| 2518 | + */ |
|
| 2519 | + protected function _set_publish_post_box_vars( |
|
| 2520 | + ?string $name = '', |
|
| 2521 | + $id = 0, |
|
| 2522 | + ?string $delete = '', |
|
| 2523 | + ?string $save_close_redirect_URL = '', |
|
| 2524 | + bool $both_btns = true |
|
| 2525 | + ) { |
|
| 2526 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2527 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2528 | + ? $save_close_redirect_URL |
|
| 2529 | + : $this->_admin_base_url; |
|
| 2530 | + // create the Save & Close and Save buttons |
|
| 2531 | + $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2532 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2533 | + $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? ''; |
|
| 2534 | + if ($delete && ! empty($id) && empty($this->_template_args['publish_delete_link'])) { |
|
| 2535 | + // make sure we have a default if just true is sent. |
|
| 2536 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2537 | + $this->_template_args['publish_delete_link'] = $this->get_action_link_or_button( |
|
| 2538 | + $delete, |
|
| 2539 | + $delete, |
|
| 2540 | + [$name => $id], |
|
| 2541 | + 'submitdelete deletion button button--outline button--caution' |
|
| 2542 | + ); |
|
| 2543 | + } |
|
| 2544 | + if (! isset($this->_template_args['publish_delete_link'])) { |
|
| 2545 | + $this->_template_args['publish_delete_link'] = ''; |
|
| 2546 | + } |
|
| 2547 | + if (! empty($name) && ! empty($id)) { |
|
| 2548 | + $this->addPublishPostMetaBoxHiddenFields($name, ['type' => 'hidden', 'value' => $id]); |
|
| 2549 | + } |
|
| 2550 | + $hidden_fields = $this->_generate_admin_form_fields($this->publish_post_meta_box_hidden_fields, 'array'); |
|
| 2551 | + // add hidden fields |
|
| 2552 | + $this->_template_args['publish_hidden_fields'] = $this->_template_args['publish_hidden_fields'] ?? ''; |
|
| 2553 | + foreach ($hidden_fields as $hidden_field) { |
|
| 2554 | + $this->_template_args['publish_hidden_fields'] .= $hidden_field['field'] ?? ''; |
|
| 2555 | + } |
|
| 2556 | + } |
|
| 2557 | + |
|
| 2558 | + |
|
| 2559 | + /** |
|
| 2560 | + * @param string|null $name |
|
| 2561 | + * @param int|string $id |
|
| 2562 | + * @param string|null $delete |
|
| 2563 | + * @param string|null $save_close_redirect_URL |
|
| 2564 | + * @param bool $both_btns |
|
| 2565 | + * @throws EE_Error |
|
| 2566 | + */ |
|
| 2567 | + public function set_publish_post_box_vars( |
|
| 2568 | + ?string $name = '', |
|
| 2569 | + $id = 0, |
|
| 2570 | + ?string $delete = '', |
|
| 2571 | + ?string $save_close_redirect_URL = '', |
|
| 2572 | + bool $both_btns = false |
|
| 2573 | + ) { |
|
| 2574 | + $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2575 | + } |
|
| 2576 | + |
|
| 2577 | + |
|
| 2578 | + protected function addPublishPostMetaBoxHiddenFields(string $field_name, array $field_attributes) |
|
| 2579 | + { |
|
| 2580 | + $this->publish_post_meta_box_hidden_fields[ $field_name ] = $field_attributes; |
|
| 2581 | + } |
|
| 2582 | + |
|
| 2583 | + |
|
| 2584 | + /** |
|
| 2585 | + * displays an error message to ppl who have javascript disabled |
|
| 2586 | + * |
|
| 2587 | + * @return void |
|
| 2588 | + */ |
|
| 2589 | + private function _display_no_javascript_warning() |
|
| 2590 | + { |
|
| 2591 | + ?> |
|
| 2592 | 2592 | <noscript> |
| 2593 | 2593 | <div id="no-js-message" class="error"> |
| 2594 | 2594 | <p style="font-size:1.3em;"> |
| 2595 | 2595 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2596 | 2596 | <?php esc_html_e( |
| 2597 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2598 | - 'event_espresso' |
|
| 2599 | - ); ?> |
|
| 2597 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2598 | + 'event_espresso' |
|
| 2599 | + ); ?> |
|
| 2600 | 2600 | </p> |
| 2601 | 2601 | </div> |
| 2602 | 2602 | </noscript> |
| 2603 | 2603 | <?php |
| 2604 | - } |
|
| 2605 | - |
|
| 2606 | - |
|
| 2607 | - /** |
|
| 2608 | - * displays espresso success and/or error notices |
|
| 2609 | - * |
|
| 2610 | - * @return void |
|
| 2611 | - */ |
|
| 2612 | - protected function _display_espresso_notices() |
|
| 2613 | - { |
|
| 2614 | - $notices = (array) $this->_get_transient(true); |
|
| 2615 | - foreach ($notices as $notice) { |
|
| 2616 | - echo $notice ? stripslashes($notice) : ''; |
|
| 2617 | - } |
|
| 2618 | - } |
|
| 2619 | - |
|
| 2620 | - |
|
| 2621 | - /** |
|
| 2622 | - * spinny things pacify the masses |
|
| 2623 | - * |
|
| 2624 | - * @return void |
|
| 2625 | - */ |
|
| 2626 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2627 | - { |
|
| 2628 | - ?> |
|
| 2604 | + } |
|
| 2605 | + |
|
| 2606 | + |
|
| 2607 | + /** |
|
| 2608 | + * displays espresso success and/or error notices |
|
| 2609 | + * |
|
| 2610 | + * @return void |
|
| 2611 | + */ |
|
| 2612 | + protected function _display_espresso_notices() |
|
| 2613 | + { |
|
| 2614 | + $notices = (array) $this->_get_transient(true); |
|
| 2615 | + foreach ($notices as $notice) { |
|
| 2616 | + echo $notice ? stripslashes($notice) : ''; |
|
| 2617 | + } |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + |
|
| 2621 | + /** |
|
| 2622 | + * spinny things pacify the masses |
|
| 2623 | + * |
|
| 2624 | + * @return void |
|
| 2625 | + */ |
|
| 2626 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2627 | + { |
|
| 2628 | + ?> |
|
| 2629 | 2629 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2630 | 2630 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2631 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2631 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2632 | 2632 | </div> |
| 2633 | 2633 | <?php |
| 2634 | - } |
|
| 2634 | + } |
|
| 2635 | 2635 | |
| 2636 | 2636 | |
| 2637 | - /** |
|
| 2638 | - * add admin page overlay for modal boxes |
|
| 2639 | - * |
|
| 2640 | - * @return void |
|
| 2641 | - */ |
|
| 2642 | - protected function _add_admin_page_overlay() |
|
| 2643 | - { |
|
| 2644 | - ?> |
|
| 2637 | + /** |
|
| 2638 | + * add admin page overlay for modal boxes |
|
| 2639 | + * |
|
| 2640 | + * @return void |
|
| 2641 | + */ |
|
| 2642 | + protected function _add_admin_page_overlay() |
|
| 2643 | + { |
|
| 2644 | + ?> |
|
| 2645 | 2645 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2646 | 2646 | <?php |
| 2647 | - } |
|
| 2648 | - |
|
| 2649 | - |
|
| 2650 | - /** |
|
| 2651 | - * facade for $this->addMetaBox() |
|
| 2652 | - * |
|
| 2653 | - * @param string $action where the metabox gets displayed |
|
| 2654 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2655 | - * @param callable $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2656 | - * instead of the one created in here. |
|
| 2657 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2658 | - * @param string $column what metabox column |
|
| 2659 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2660 | - * @param bool $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2661 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2662 | - * @throws DomainException |
|
| 2663 | - */ |
|
| 2664 | - public function _add_admin_page_meta_box( |
|
| 2665 | - string $action, |
|
| 2666 | - string $title, |
|
| 2667 | - callable $callback, |
|
| 2668 | - array $callback_args, |
|
| 2669 | - string $column = 'normal', |
|
| 2670 | - string $priority = 'high', |
|
| 2671 | - bool $create_func = true |
|
| 2672 | - ) { |
|
| 2673 | - // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2674 | - if (empty($callback_args) && $create_func) { |
|
| 2675 | - $callback_args = [ |
|
| 2676 | - 'template_path' => $this->_template_path, |
|
| 2677 | - 'template_args' => $this->_template_args, |
|
| 2678 | - ]; |
|
| 2679 | - } |
|
| 2680 | - // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2681 | - $call_back_func = $create_func |
|
| 2682 | - ? static function ($post, $metabox) { |
|
| 2683 | - echo EEH_Template::display_template( |
|
| 2684 | - $metabox['args']['template_path'], |
|
| 2685 | - $metabox['args']['template_args'], |
|
| 2686 | - true |
|
| 2687 | - ); |
|
| 2688 | - } |
|
| 2689 | - : $callback; |
|
| 2690 | - $this->addMetaBox( |
|
| 2691 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2692 | - $title, |
|
| 2693 | - $call_back_func, |
|
| 2694 | - $this->_wp_page_slug, |
|
| 2695 | - $column, |
|
| 2696 | - $priority, |
|
| 2697 | - $callback_args |
|
| 2698 | - ); |
|
| 2699 | - } |
|
| 2700 | - |
|
| 2701 | - |
|
| 2702 | - /** |
|
| 2703 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2704 | - * |
|
| 2705 | - * @throws DomainException |
|
| 2706 | - * @throws EE_Error |
|
| 2707 | - * @throws InvalidArgumentException |
|
| 2708 | - * @throws InvalidDataTypeException |
|
| 2709 | - * @throws InvalidInterfaceException |
|
| 2710 | - */ |
|
| 2711 | - public function display_admin_page_with_metabox_columns() |
|
| 2712 | - { |
|
| 2713 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2714 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2715 | - $this->_column_template_path, |
|
| 2716 | - $this->_template_args, |
|
| 2717 | - true |
|
| 2718 | - ); |
|
| 2719 | - // the final wrapper |
|
| 2720 | - $this->admin_page_wrapper(); |
|
| 2721 | - } |
|
| 2722 | - |
|
| 2723 | - |
|
| 2724 | - /** |
|
| 2725 | - * generates HTML wrapper for an admin details page |
|
| 2726 | - * |
|
| 2727 | - * @return void |
|
| 2728 | - * @throws DomainException |
|
| 2729 | - * @throws EE_Error |
|
| 2730 | - * @throws InvalidArgumentException |
|
| 2731 | - * @throws InvalidDataTypeException |
|
| 2732 | - * @throws InvalidInterfaceException |
|
| 2733 | - */ |
|
| 2734 | - public function display_admin_page_with_sidebar() |
|
| 2735 | - { |
|
| 2736 | - $this->_display_admin_page(true); |
|
| 2737 | - } |
|
| 2738 | - |
|
| 2739 | - |
|
| 2740 | - /** |
|
| 2741 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2742 | - * |
|
| 2743 | - * @return void |
|
| 2744 | - * @throws DomainException |
|
| 2745 | - * @throws EE_Error |
|
| 2746 | - * @throws InvalidArgumentException |
|
| 2747 | - * @throws InvalidDataTypeException |
|
| 2748 | - * @throws InvalidInterfaceException |
|
| 2749 | - */ |
|
| 2750 | - public function display_admin_page_with_no_sidebar() |
|
| 2751 | - { |
|
| 2752 | - $this->_display_admin_page(); |
|
| 2753 | - } |
|
| 2754 | - |
|
| 2755 | - |
|
| 2756 | - /** |
|
| 2757 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2758 | - * |
|
| 2759 | - * @return void |
|
| 2760 | - * @throws DomainException |
|
| 2761 | - * @throws EE_Error |
|
| 2762 | - * @throws InvalidArgumentException |
|
| 2763 | - * @throws InvalidDataTypeException |
|
| 2764 | - * @throws InvalidInterfaceException |
|
| 2765 | - */ |
|
| 2766 | - public function display_about_admin_page() |
|
| 2767 | - { |
|
| 2768 | - $this->_display_admin_page(false, true); |
|
| 2769 | - } |
|
| 2770 | - |
|
| 2771 | - |
|
| 2772 | - /** |
|
| 2773 | - * display_admin_page |
|
| 2774 | - * contains the code for actually displaying an admin page |
|
| 2775 | - * |
|
| 2776 | - * @param bool $sidebar true with sidebar, false without |
|
| 2777 | - * @param bool $about use the about admin wrapper instead of the default. |
|
| 2778 | - * @return void |
|
| 2779 | - * @throws DomainException |
|
| 2780 | - * @throws EE_Error |
|
| 2781 | - * @throws InvalidArgumentException |
|
| 2782 | - * @throws InvalidDataTypeException |
|
| 2783 | - * @throws InvalidInterfaceException |
|
| 2784 | - */ |
|
| 2785 | - private function _display_admin_page(bool $sidebar = false, bool $about = false): void |
|
| 2786 | - { |
|
| 2787 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2788 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2789 | - |
|
| 2790 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2791 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2792 | - $post_body_content = $this->_template_args['before_admin_page_content'] ?? ''; |
|
| 2793 | - |
|
| 2794 | - $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status' |
|
| 2795 | - && $this->_req_action !== 'data_reset' |
|
| 2796 | - && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages' |
|
| 2797 | - && strpos($post_body_content, 'wp-list-table') === false; |
|
| 2798 | - |
|
| 2799 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2800 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2801 | - ? 'poststuff' |
|
| 2802 | - : 'espresso-default-admin'; |
|
| 2803 | - $this->_template_args['admin_page_wrapper_div_class'] = str_replace( |
|
| 2804 | - 'event-espresso_page_espresso_', |
|
| 2805 | - '', |
|
| 2806 | - $this->_wp_page_slug |
|
| 2807 | - ) . ' ' . $this->_req_action . '-route'; |
|
| 2808 | - |
|
| 2809 | - $template_path = $sidebar |
|
| 2810 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2811 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2812 | - |
|
| 2813 | - $this->_template_args['is_ajax'] = $this->request->isAjax(); |
|
| 2814 | - if ($this->request->isAjax()) { |
|
| 2815 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2816 | - } |
|
| 2817 | - $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2818 | - |
|
| 2819 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'] ?? ''; |
|
| 2820 | - $this->_template_args['before_admin_page_content'] = $post_body_content; |
|
| 2821 | - $this->_template_args['after_admin_page_content'] = $this->_template_args['after_admin_page_content'] ?? ''; |
|
| 2822 | - |
|
| 2823 | - // ensure $post_type and $post are set |
|
| 2824 | - // to prevent WooCommerce from blowing things up if not using CPT |
|
| 2825 | - global $post_type, $post; |
|
| 2826 | - $this->_template_args['post_type'] = $post_type ?? ''; |
|
| 2827 | - $this->_template_args['post'] = $post ?? new WP_Post( (object) [ 'ID' => 0, 'filter' => 'raw' ] ); |
|
| 2828 | - |
|
| 2829 | - $this->_template_args['post_body_content'] = EEH_Template::display_template( |
|
| 2830 | - EE_ADMIN_TEMPLATE . 'admin_details_wrapper_post_body_content.template.php', |
|
| 2831 | - $this->_template_args, |
|
| 2832 | - true |
|
| 2833 | - ); |
|
| 2834 | - |
|
| 2835 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2836 | - $template_path, |
|
| 2837 | - $this->_template_args, |
|
| 2838 | - true |
|
| 2839 | - ); |
|
| 2840 | - // the final template wrapper |
|
| 2841 | - $this->admin_page_wrapper($about); |
|
| 2842 | - } |
|
| 2843 | - |
|
| 2844 | - |
|
| 2845 | - /** |
|
| 2846 | - * This is used to display caf preview pages. |
|
| 2847 | - * |
|
| 2848 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2849 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2850 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2851 | - * @return void |
|
| 2852 | - * @throws DomainException |
|
| 2853 | - * @throws EE_Error |
|
| 2854 | - * @throws InvalidArgumentException |
|
| 2855 | - * @throws InvalidDataTypeException |
|
| 2856 | - * @throws InvalidInterfaceException |
|
| 2857 | - * @since 4.3.2 |
|
| 2858 | - */ |
|
| 2859 | - public function display_admin_caf_preview_page(string $utm_campaign_source = '', bool $display_sidebar = true) |
|
| 2860 | - { |
|
| 2861 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2862 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2863 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2864 | - 'event_espresso' |
|
| 2865 | - ); |
|
| 2866 | - $buy_now_url = add_query_arg( |
|
| 2867 | - [ |
|
| 2868 | - 'ee_ver' => 'ee4', |
|
| 2869 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2870 | - 'utm_medium' => 'link', |
|
| 2871 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2872 | - 'utm_content' => 'buy_now_button', |
|
| 2873 | - ], |
|
| 2874 | - 'https://eventespresso.com/pricing/' |
|
| 2875 | - ); |
|
| 2876 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2877 | - ? $this->get_action_link_or_button( |
|
| 2878 | - '', |
|
| 2879 | - 'buy_now', |
|
| 2880 | - [], |
|
| 2881 | - 'button button--primary button--big', |
|
| 2882 | - esc_url_raw($buy_now_url), |
|
| 2883 | - true |
|
| 2884 | - ) |
|
| 2885 | - : $this->_template_args['preview_action_button']; |
|
| 2886 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2887 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2888 | - $this->_template_args, |
|
| 2889 | - true |
|
| 2890 | - ); |
|
| 2891 | - $this->_display_admin_page($display_sidebar); |
|
| 2892 | - } |
|
| 2893 | - |
|
| 2894 | - |
|
| 2895 | - /** |
|
| 2896 | - * display_admin_list_table_page_with_sidebar |
|
| 2897 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2898 | - * |
|
| 2899 | - * @return void |
|
| 2900 | - * @throws DomainException |
|
| 2901 | - * @throws EE_Error |
|
| 2902 | - * @throws InvalidArgumentException |
|
| 2903 | - * @throws InvalidDataTypeException |
|
| 2904 | - * @throws InvalidInterfaceException |
|
| 2905 | - */ |
|
| 2906 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2907 | - { |
|
| 2908 | - $this->_display_admin_list_table_page(true); |
|
| 2909 | - } |
|
| 2910 | - |
|
| 2911 | - |
|
| 2912 | - /** |
|
| 2913 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2914 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2915 | - * |
|
| 2916 | - * @return void |
|
| 2917 | - * @throws DomainException |
|
| 2918 | - * @throws EE_Error |
|
| 2919 | - * @throws InvalidArgumentException |
|
| 2920 | - * @throws InvalidDataTypeException |
|
| 2921 | - * @throws InvalidInterfaceException |
|
| 2922 | - */ |
|
| 2923 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2924 | - { |
|
| 2925 | - $this->_display_admin_list_table_page(); |
|
| 2926 | - } |
|
| 2927 | - |
|
| 2928 | - |
|
| 2929 | - /** |
|
| 2930 | - * generates html wrapper for an admin_list_table page |
|
| 2931 | - * |
|
| 2932 | - * @param bool $sidebar whether to display with sidebar or not. |
|
| 2933 | - * @return void |
|
| 2934 | - * @throws DomainException |
|
| 2935 | - * @throws EE_Error |
|
| 2936 | - * @throws InvalidArgumentException |
|
| 2937 | - * @throws InvalidDataTypeException |
|
| 2938 | - * @throws InvalidInterfaceException |
|
| 2939 | - */ |
|
| 2940 | - private function _display_admin_list_table_page(bool $sidebar = false) |
|
| 2941 | - { |
|
| 2942 | - // setup search attributes |
|
| 2943 | - $this->_set_search_attributes(); |
|
| 2944 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2945 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2946 | - $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2947 | - ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2948 | - : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2949 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2950 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2951 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2952 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2953 | - if (! empty($ajax_sorting_callback)) { |
|
| 2954 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2955 | - $ajax_sorting_callback . '_nonce', |
|
| 2956 | - $ajax_sorting_callback . '_nonce', |
|
| 2957 | - false, |
|
| 2958 | - false |
|
| 2959 | - ); |
|
| 2960 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2961 | - . $this->page_slug |
|
| 2962 | - . '" />'; |
|
| 2963 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2964 | - . $ajax_sorting_callback |
|
| 2965 | - . '" />'; |
|
| 2966 | - } else { |
|
| 2967 | - $sortable_list_table_form_fields = ''; |
|
| 2968 | - } |
|
| 2969 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2970 | - |
|
| 2971 | - $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? ''; |
|
| 2972 | - |
|
| 2973 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2974 | - $hidden_form_fields .= ' |
|
| 2647 | + } |
|
| 2648 | + |
|
| 2649 | + |
|
| 2650 | + /** |
|
| 2651 | + * facade for $this->addMetaBox() |
|
| 2652 | + * |
|
| 2653 | + * @param string $action where the metabox gets displayed |
|
| 2654 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2655 | + * @param callable $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2656 | + * instead of the one created in here. |
|
| 2657 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2658 | + * @param string $column what metabox column |
|
| 2659 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2660 | + * @param bool $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2661 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2662 | + * @throws DomainException |
|
| 2663 | + */ |
|
| 2664 | + public function _add_admin_page_meta_box( |
|
| 2665 | + string $action, |
|
| 2666 | + string $title, |
|
| 2667 | + callable $callback, |
|
| 2668 | + array $callback_args, |
|
| 2669 | + string $column = 'normal', |
|
| 2670 | + string $priority = 'high', |
|
| 2671 | + bool $create_func = true |
|
| 2672 | + ) { |
|
| 2673 | + // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2674 | + if (empty($callback_args) && $create_func) { |
|
| 2675 | + $callback_args = [ |
|
| 2676 | + 'template_path' => $this->_template_path, |
|
| 2677 | + 'template_args' => $this->_template_args, |
|
| 2678 | + ]; |
|
| 2679 | + } |
|
| 2680 | + // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2681 | + $call_back_func = $create_func |
|
| 2682 | + ? static function ($post, $metabox) { |
|
| 2683 | + echo EEH_Template::display_template( |
|
| 2684 | + $metabox['args']['template_path'], |
|
| 2685 | + $metabox['args']['template_args'], |
|
| 2686 | + true |
|
| 2687 | + ); |
|
| 2688 | + } |
|
| 2689 | + : $callback; |
|
| 2690 | + $this->addMetaBox( |
|
| 2691 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2692 | + $title, |
|
| 2693 | + $call_back_func, |
|
| 2694 | + $this->_wp_page_slug, |
|
| 2695 | + $column, |
|
| 2696 | + $priority, |
|
| 2697 | + $callback_args |
|
| 2698 | + ); |
|
| 2699 | + } |
|
| 2700 | + |
|
| 2701 | + |
|
| 2702 | + /** |
|
| 2703 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2704 | + * |
|
| 2705 | + * @throws DomainException |
|
| 2706 | + * @throws EE_Error |
|
| 2707 | + * @throws InvalidArgumentException |
|
| 2708 | + * @throws InvalidDataTypeException |
|
| 2709 | + * @throws InvalidInterfaceException |
|
| 2710 | + */ |
|
| 2711 | + public function display_admin_page_with_metabox_columns() |
|
| 2712 | + { |
|
| 2713 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2714 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2715 | + $this->_column_template_path, |
|
| 2716 | + $this->_template_args, |
|
| 2717 | + true |
|
| 2718 | + ); |
|
| 2719 | + // the final wrapper |
|
| 2720 | + $this->admin_page_wrapper(); |
|
| 2721 | + } |
|
| 2722 | + |
|
| 2723 | + |
|
| 2724 | + /** |
|
| 2725 | + * generates HTML wrapper for an admin details page |
|
| 2726 | + * |
|
| 2727 | + * @return void |
|
| 2728 | + * @throws DomainException |
|
| 2729 | + * @throws EE_Error |
|
| 2730 | + * @throws InvalidArgumentException |
|
| 2731 | + * @throws InvalidDataTypeException |
|
| 2732 | + * @throws InvalidInterfaceException |
|
| 2733 | + */ |
|
| 2734 | + public function display_admin_page_with_sidebar() |
|
| 2735 | + { |
|
| 2736 | + $this->_display_admin_page(true); |
|
| 2737 | + } |
|
| 2738 | + |
|
| 2739 | + |
|
| 2740 | + /** |
|
| 2741 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2742 | + * |
|
| 2743 | + * @return void |
|
| 2744 | + * @throws DomainException |
|
| 2745 | + * @throws EE_Error |
|
| 2746 | + * @throws InvalidArgumentException |
|
| 2747 | + * @throws InvalidDataTypeException |
|
| 2748 | + * @throws InvalidInterfaceException |
|
| 2749 | + */ |
|
| 2750 | + public function display_admin_page_with_no_sidebar() |
|
| 2751 | + { |
|
| 2752 | + $this->_display_admin_page(); |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + |
|
| 2756 | + /** |
|
| 2757 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2758 | + * |
|
| 2759 | + * @return void |
|
| 2760 | + * @throws DomainException |
|
| 2761 | + * @throws EE_Error |
|
| 2762 | + * @throws InvalidArgumentException |
|
| 2763 | + * @throws InvalidDataTypeException |
|
| 2764 | + * @throws InvalidInterfaceException |
|
| 2765 | + */ |
|
| 2766 | + public function display_about_admin_page() |
|
| 2767 | + { |
|
| 2768 | + $this->_display_admin_page(false, true); |
|
| 2769 | + } |
|
| 2770 | + |
|
| 2771 | + |
|
| 2772 | + /** |
|
| 2773 | + * display_admin_page |
|
| 2774 | + * contains the code for actually displaying an admin page |
|
| 2775 | + * |
|
| 2776 | + * @param bool $sidebar true with sidebar, false without |
|
| 2777 | + * @param bool $about use the about admin wrapper instead of the default. |
|
| 2778 | + * @return void |
|
| 2779 | + * @throws DomainException |
|
| 2780 | + * @throws EE_Error |
|
| 2781 | + * @throws InvalidArgumentException |
|
| 2782 | + * @throws InvalidDataTypeException |
|
| 2783 | + * @throws InvalidInterfaceException |
|
| 2784 | + */ |
|
| 2785 | + private function _display_admin_page(bool $sidebar = false, bool $about = false): void |
|
| 2786 | + { |
|
| 2787 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2788 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2789 | + |
|
| 2790 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2791 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2792 | + $post_body_content = $this->_template_args['before_admin_page_content'] ?? ''; |
|
| 2793 | + |
|
| 2794 | + $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status' |
|
| 2795 | + && $this->_req_action !== 'data_reset' |
|
| 2796 | + && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages' |
|
| 2797 | + && strpos($post_body_content, 'wp-list-table') === false; |
|
| 2798 | + |
|
| 2799 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2800 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2801 | + ? 'poststuff' |
|
| 2802 | + : 'espresso-default-admin'; |
|
| 2803 | + $this->_template_args['admin_page_wrapper_div_class'] = str_replace( |
|
| 2804 | + 'event-espresso_page_espresso_', |
|
| 2805 | + '', |
|
| 2806 | + $this->_wp_page_slug |
|
| 2807 | + ) . ' ' . $this->_req_action . '-route'; |
|
| 2808 | + |
|
| 2809 | + $template_path = $sidebar |
|
| 2810 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2811 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2812 | + |
|
| 2813 | + $this->_template_args['is_ajax'] = $this->request->isAjax(); |
|
| 2814 | + if ($this->request->isAjax()) { |
|
| 2815 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2816 | + } |
|
| 2817 | + $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2818 | + |
|
| 2819 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'] ?? ''; |
|
| 2820 | + $this->_template_args['before_admin_page_content'] = $post_body_content; |
|
| 2821 | + $this->_template_args['after_admin_page_content'] = $this->_template_args['after_admin_page_content'] ?? ''; |
|
| 2822 | + |
|
| 2823 | + // ensure $post_type and $post are set |
|
| 2824 | + // to prevent WooCommerce from blowing things up if not using CPT |
|
| 2825 | + global $post_type, $post; |
|
| 2826 | + $this->_template_args['post_type'] = $post_type ?? ''; |
|
| 2827 | + $this->_template_args['post'] = $post ?? new WP_Post( (object) [ 'ID' => 0, 'filter' => 'raw' ] ); |
|
| 2828 | + |
|
| 2829 | + $this->_template_args['post_body_content'] = EEH_Template::display_template( |
|
| 2830 | + EE_ADMIN_TEMPLATE . 'admin_details_wrapper_post_body_content.template.php', |
|
| 2831 | + $this->_template_args, |
|
| 2832 | + true |
|
| 2833 | + ); |
|
| 2834 | + |
|
| 2835 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2836 | + $template_path, |
|
| 2837 | + $this->_template_args, |
|
| 2838 | + true |
|
| 2839 | + ); |
|
| 2840 | + // the final template wrapper |
|
| 2841 | + $this->admin_page_wrapper($about); |
|
| 2842 | + } |
|
| 2843 | + |
|
| 2844 | + |
|
| 2845 | + /** |
|
| 2846 | + * This is used to display caf preview pages. |
|
| 2847 | + * |
|
| 2848 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2849 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2850 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2851 | + * @return void |
|
| 2852 | + * @throws DomainException |
|
| 2853 | + * @throws EE_Error |
|
| 2854 | + * @throws InvalidArgumentException |
|
| 2855 | + * @throws InvalidDataTypeException |
|
| 2856 | + * @throws InvalidInterfaceException |
|
| 2857 | + * @since 4.3.2 |
|
| 2858 | + */ |
|
| 2859 | + public function display_admin_caf_preview_page(string $utm_campaign_source = '', bool $display_sidebar = true) |
|
| 2860 | + { |
|
| 2861 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2862 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2863 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2864 | + 'event_espresso' |
|
| 2865 | + ); |
|
| 2866 | + $buy_now_url = add_query_arg( |
|
| 2867 | + [ |
|
| 2868 | + 'ee_ver' => 'ee4', |
|
| 2869 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2870 | + 'utm_medium' => 'link', |
|
| 2871 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2872 | + 'utm_content' => 'buy_now_button', |
|
| 2873 | + ], |
|
| 2874 | + 'https://eventespresso.com/pricing/' |
|
| 2875 | + ); |
|
| 2876 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2877 | + ? $this->get_action_link_or_button( |
|
| 2878 | + '', |
|
| 2879 | + 'buy_now', |
|
| 2880 | + [], |
|
| 2881 | + 'button button--primary button--big', |
|
| 2882 | + esc_url_raw($buy_now_url), |
|
| 2883 | + true |
|
| 2884 | + ) |
|
| 2885 | + : $this->_template_args['preview_action_button']; |
|
| 2886 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2887 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2888 | + $this->_template_args, |
|
| 2889 | + true |
|
| 2890 | + ); |
|
| 2891 | + $this->_display_admin_page($display_sidebar); |
|
| 2892 | + } |
|
| 2893 | + |
|
| 2894 | + |
|
| 2895 | + /** |
|
| 2896 | + * display_admin_list_table_page_with_sidebar |
|
| 2897 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2898 | + * |
|
| 2899 | + * @return void |
|
| 2900 | + * @throws DomainException |
|
| 2901 | + * @throws EE_Error |
|
| 2902 | + * @throws InvalidArgumentException |
|
| 2903 | + * @throws InvalidDataTypeException |
|
| 2904 | + * @throws InvalidInterfaceException |
|
| 2905 | + */ |
|
| 2906 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2907 | + { |
|
| 2908 | + $this->_display_admin_list_table_page(true); |
|
| 2909 | + } |
|
| 2910 | + |
|
| 2911 | + |
|
| 2912 | + /** |
|
| 2913 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2914 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2915 | + * |
|
| 2916 | + * @return void |
|
| 2917 | + * @throws DomainException |
|
| 2918 | + * @throws EE_Error |
|
| 2919 | + * @throws InvalidArgumentException |
|
| 2920 | + * @throws InvalidDataTypeException |
|
| 2921 | + * @throws InvalidInterfaceException |
|
| 2922 | + */ |
|
| 2923 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2924 | + { |
|
| 2925 | + $this->_display_admin_list_table_page(); |
|
| 2926 | + } |
|
| 2927 | + |
|
| 2928 | + |
|
| 2929 | + /** |
|
| 2930 | + * generates html wrapper for an admin_list_table page |
|
| 2931 | + * |
|
| 2932 | + * @param bool $sidebar whether to display with sidebar or not. |
|
| 2933 | + * @return void |
|
| 2934 | + * @throws DomainException |
|
| 2935 | + * @throws EE_Error |
|
| 2936 | + * @throws InvalidArgumentException |
|
| 2937 | + * @throws InvalidDataTypeException |
|
| 2938 | + * @throws InvalidInterfaceException |
|
| 2939 | + */ |
|
| 2940 | + private function _display_admin_list_table_page(bool $sidebar = false) |
|
| 2941 | + { |
|
| 2942 | + // setup search attributes |
|
| 2943 | + $this->_set_search_attributes(); |
|
| 2944 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2945 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2946 | + $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2947 | + ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2948 | + : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2949 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2950 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2951 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2952 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2953 | + if (! empty($ajax_sorting_callback)) { |
|
| 2954 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2955 | + $ajax_sorting_callback . '_nonce', |
|
| 2956 | + $ajax_sorting_callback . '_nonce', |
|
| 2957 | + false, |
|
| 2958 | + false |
|
| 2959 | + ); |
|
| 2960 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2961 | + . $this->page_slug |
|
| 2962 | + . '" />'; |
|
| 2963 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2964 | + . $ajax_sorting_callback |
|
| 2965 | + . '" />'; |
|
| 2966 | + } else { |
|
| 2967 | + $sortable_list_table_form_fields = ''; |
|
| 2968 | + } |
|
| 2969 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2970 | + |
|
| 2971 | + $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? ''; |
|
| 2972 | + |
|
| 2973 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2974 | + $hidden_form_fields .= ' |
|
| 2975 | 2975 | <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
| 2976 | 2976 | |
| 2977 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2978 | - // display message about search results? |
|
| 2979 | - $search = $this->request->getRequestParam('s'); |
|
| 2980 | - $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2981 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2982 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2983 | - trim($search, '%') |
|
| 2984 | - ) . '</p>' |
|
| 2985 | - : ''; |
|
| 2986 | - // filter before_list_table template arg |
|
| 2987 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 2988 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2989 | - $this->_template_args['before_list_table'], |
|
| 2990 | - $this->page_slug, |
|
| 2991 | - $this->request->requestParams(), |
|
| 2992 | - $this->_req_action |
|
| 2993 | - ); |
|
| 2994 | - // convert to array and filter again |
|
| 2995 | - // arrays are easier to inject new items in a specific location, |
|
| 2996 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2997 | - $this->_template_args['before_list_table'] = implode( |
|
| 2998 | - " \n", |
|
| 2999 | - (array) apply_filters( |
|
| 3000 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3001 | - (array) $this->_template_args['before_list_table'], |
|
| 3002 | - $this->page_slug, |
|
| 3003 | - $this->request->requestParams(), |
|
| 3004 | - $this->_req_action |
|
| 3005 | - ) |
|
| 3006 | - ); |
|
| 3007 | - // filter after_list_table template arg |
|
| 3008 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3009 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3010 | - $this->_template_args['after_list_table'], |
|
| 3011 | - $this->page_slug, |
|
| 3012 | - $this->request->requestParams(), |
|
| 3013 | - $this->_req_action |
|
| 3014 | - ); |
|
| 3015 | - // convert to array and filter again |
|
| 3016 | - // arrays are easier to inject new items in a specific location, |
|
| 3017 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3018 | - $this->_template_args['after_list_table'] = implode( |
|
| 3019 | - " \n", |
|
| 3020 | - (array) apply_filters( |
|
| 3021 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3022 | - (array) $this->_template_args['after_list_table'], |
|
| 3023 | - $this->page_slug, |
|
| 3024 | - $this->request->requestParams(), |
|
| 3025 | - $this->_req_action |
|
| 3026 | - ) |
|
| 3027 | - ); |
|
| 3028 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3029 | - $template_path, |
|
| 3030 | - $this->_template_args, |
|
| 3031 | - true |
|
| 3032 | - ); |
|
| 3033 | - // the final template wrapper |
|
| 3034 | - if ($sidebar) { |
|
| 3035 | - $this->display_admin_page_with_sidebar(); |
|
| 3036 | - } else { |
|
| 3037 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3038 | - } |
|
| 3039 | - } |
|
| 3040 | - |
|
| 3041 | - |
|
| 3042 | - /** |
|
| 3043 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3044 | - * html string for the legend. |
|
| 3045 | - * $items are expected in an array in the following format: |
|
| 3046 | - * $legend_items = array( |
|
| 3047 | - * 'item_id' => array( |
|
| 3048 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3049 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3050 | - * ) |
|
| 3051 | - * ); |
|
| 3052 | - * |
|
| 3053 | - * @param array $items see above for format of array |
|
| 3054 | - * @return string html string of legend |
|
| 3055 | - * @throws DomainException |
|
| 3056 | - */ |
|
| 3057 | - protected function _display_legend(array $items): string |
|
| 3058 | - { |
|
| 3059 | - $this->_template_args['items'] = (array) apply_filters( |
|
| 3060 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3061 | - $items, |
|
| 3062 | - $this |
|
| 3063 | - ); |
|
| 3064 | - /** @var StatusChangeNotice $status_change_notice */ |
|
| 3065 | - $status_change_notice = $this->loader->getShared( |
|
| 3066 | - 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 3067 | - ); |
|
| 3068 | - $this->_template_args['status_change_notice'] = $status_change_notice->display( |
|
| 3069 | - '__admin-legend', |
|
| 3070 | - $this->page_slug |
|
| 3071 | - ); |
|
| 3072 | - return EEH_Template::display_template( |
|
| 3073 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3074 | - $this->_template_args, |
|
| 3075 | - true |
|
| 3076 | - ); |
|
| 3077 | - } |
|
| 3078 | - |
|
| 3079 | - |
|
| 3080 | - /** |
|
| 3081 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3082 | - * The returned json object is created from an array in the following format: |
|
| 3083 | - * array( |
|
| 3084 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3085 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3086 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3087 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3088 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3089 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3090 | - * that might be included in here) |
|
| 3091 | - * ) |
|
| 3092 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3093 | - * |
|
| 3094 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3095 | - * instead of displayed. |
|
| 3096 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3097 | - * @return void |
|
| 3098 | - * @throws EE_Error |
|
| 3099 | - * @throws InvalidArgumentException |
|
| 3100 | - * @throws InvalidDataTypeException |
|
| 3101 | - * @throws InvalidInterfaceException |
|
| 3102 | - */ |
|
| 3103 | - protected function _return_json(bool $sticky_notices = false, array $notices_arguments = []) |
|
| 3104 | - { |
|
| 3105 | - // make sure any EE_Error notices have been handled. |
|
| 3106 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3107 | - $data = $this->_template_args['data'] ?? []; |
|
| 3108 | - unset($this->_template_args['data']); |
|
| 3109 | - $json = [ |
|
| 3110 | - 'error' => $this->_template_args['error'] ?? false, |
|
| 3111 | - 'success' => $this->_template_args['success'] ?? false, |
|
| 3112 | - 'errors' => $this->_template_args['errors'] ?? false, |
|
| 3113 | - 'attention' => $this->_template_args['attention'] ?? false, |
|
| 3114 | - 'notices' => EE_Error::get_notices(), |
|
| 3115 | - 'content' => $this->_template_args['admin_page_content'] ?? '', |
|
| 3116 | - 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3117 | - 'isEEajax' => true, |
|
| 3118 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3119 | - ]; |
|
| 3120 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3121 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3122 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3123 | - } |
|
| 3124 | - echo wp_json_encode($json); |
|
| 3125 | - exit(); |
|
| 3126 | - } |
|
| 3127 | - |
|
| 3128 | - |
|
| 3129 | - /** |
|
| 3130 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3131 | - * |
|
| 3132 | - * @return void |
|
| 3133 | - * @throws EE_Error |
|
| 3134 | - * @throws InvalidArgumentException |
|
| 3135 | - * @throws InvalidDataTypeException |
|
| 3136 | - * @throws InvalidInterfaceException |
|
| 3137 | - */ |
|
| 3138 | - public function return_json() |
|
| 3139 | - { |
|
| 3140 | - if ($this->request->isAjax()) { |
|
| 3141 | - $this->_return_json(); |
|
| 3142 | - } else { |
|
| 3143 | - throw new EE_Error( |
|
| 3144 | - sprintf( |
|
| 3145 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3146 | - __FUNCTION__ |
|
| 3147 | - ) |
|
| 3148 | - ); |
|
| 3149 | - } |
|
| 3150 | - } |
|
| 3151 | - |
|
| 3152 | - |
|
| 3153 | - /** |
|
| 3154 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3155 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3156 | - * |
|
| 3157 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3158 | - * @deprecated 5.0.8.p |
|
| 3159 | - */ |
|
| 3160 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3161 | - { |
|
| 3162 | - $this->_hook_obj = $hook_obj; |
|
| 3163 | - } |
|
| 3164 | - |
|
| 3165 | - |
|
| 3166 | - /** |
|
| 3167 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3168 | - * |
|
| 3169 | - * @param bool $about whether to use the special about page wrapper or default. |
|
| 3170 | - * @return void |
|
| 3171 | - * @throws DomainException |
|
| 3172 | - * @throws EE_Error |
|
| 3173 | - * @throws InvalidArgumentException |
|
| 3174 | - * @throws InvalidDataTypeException |
|
| 3175 | - * @throws InvalidInterfaceException |
|
| 3176 | - */ |
|
| 3177 | - public function admin_page_wrapper(bool $about = false) |
|
| 3178 | - { |
|
| 3179 | - $this->_template_args['nav_tabs'] = $this->_get_main_nav_tabs(); |
|
| 3180 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3181 | - |
|
| 3182 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3183 | - "FHEE_before_admin_page_content$this->_current_page$this->_current_view", |
|
| 3184 | - $this->_template_args['before_admin_page_content'] ?? '' |
|
| 3185 | - ); |
|
| 3186 | - |
|
| 3187 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3188 | - "FHEE_after_admin_page_content$this->_current_page$this->_current_view", |
|
| 3189 | - $this->_template_args['after_admin_page_content'] ?? '' |
|
| 3190 | - ); |
|
| 3191 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3192 | - |
|
| 3193 | - if ($this->request->isAjax()) { |
|
| 3194 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3195 | - // $template_path, |
|
| 3196 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3197 | - $this->_template_args, |
|
| 3198 | - true |
|
| 3199 | - ); |
|
| 3200 | - $this->_return_json(); |
|
| 3201 | - } |
|
| 3202 | - // load settings page wrapper template |
|
| 3203 | - $template_path = $about |
|
| 3204 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3205 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3206 | - |
|
| 3207 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3208 | - } |
|
| 3209 | - |
|
| 3210 | - |
|
| 3211 | - /** |
|
| 3212 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3213 | - * |
|
| 3214 | - * @return string html |
|
| 3215 | - * @throws EE_Error |
|
| 3216 | - */ |
|
| 3217 | - protected function _get_main_nav_tabs(): string |
|
| 3218 | - { |
|
| 3219 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3220 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3221 | - // (rather than setting in the page_routes array) |
|
| 3222 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs, $this->page_slug); |
|
| 3223 | - } |
|
| 3224 | - |
|
| 3225 | - |
|
| 3226 | - /** |
|
| 3227 | - * sort nav tabs |
|
| 3228 | - * |
|
| 3229 | - * @param array $a |
|
| 3230 | - * @param array $b |
|
| 3231 | - * @return int |
|
| 3232 | - */ |
|
| 3233 | - private function _sort_nav_tabs(array $a, array $b): int |
|
| 3234 | - { |
|
| 3235 | - if ($a['order'] === $b['order']) { |
|
| 3236 | - return 0; |
|
| 3237 | - } |
|
| 3238 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3239 | - } |
|
| 3240 | - |
|
| 3241 | - |
|
| 3242 | - /** |
|
| 3243 | - * generates HTML for the forms used on admin pages |
|
| 3244 | - * |
|
| 3245 | - * @param array $input_vars - array of input field details |
|
| 3246 | - * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3247 | - * @param bool $id |
|
| 3248 | - * @return array|string |
|
| 3249 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3250 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3251 | - */ |
|
| 3252 | - protected function _generate_admin_form_fields( |
|
| 3253 | - array $input_vars = [], |
|
| 3254 | - string $generator = 'string', |
|
| 3255 | - bool $id = false |
|
| 3256 | - ) { |
|
| 3257 | - return $generator === 'string' |
|
| 3258 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3259 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3260 | - } |
|
| 3261 | - |
|
| 3262 | - |
|
| 3263 | - /** |
|
| 3264 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3265 | - * |
|
| 3266 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3267 | - * Close" button. |
|
| 3268 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3269 | - * 'Save', [1] => 'save & close') |
|
| 3270 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3271 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3272 | - * default actions by submitting some other value. |
|
| 3273 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3274 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3275 | - * close (normal form handling). |
|
| 3276 | - */ |
|
| 3277 | - protected function _set_save_buttons(bool $both = true, array $text = [], array $actions = [], $referrer = null) |
|
| 3278 | - { |
|
| 3279 | - $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3280 | - $button_text = ! empty($text) |
|
| 3281 | - ? $text |
|
| 3282 | - : [ |
|
| 3283 | - esc_html__('Save', 'event_espresso'), |
|
| 3284 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3285 | - ]; |
|
| 3286 | - $default_names = ['save', 'save_and_close']; |
|
| 3287 | - $buttons = ''; |
|
| 3288 | - foreach ($button_text as $key => $button) { |
|
| 3289 | - $ref = $default_names[ $key ]; |
|
| 3290 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3291 | - $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" ' |
|
| 3292 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3293 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3294 | - if (! $both) { |
|
| 3295 | - break; |
|
| 3296 | - } |
|
| 3297 | - } |
|
| 3298 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3299 | - $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3300 | - . $referrer_url |
|
| 3301 | - . '" />'; |
|
| 3302 | - |
|
| 3303 | - $this->_template_args['save_buttons'] = $buttons; |
|
| 3304 | - } |
|
| 3305 | - |
|
| 3306 | - |
|
| 3307 | - /** |
|
| 3308 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3309 | - * |
|
| 3310 | - * @param string $route |
|
| 3311 | - * @param array $additional_hidden_fields |
|
| 3312 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3313 | - * @since 4.6.0 |
|
| 3314 | - */ |
|
| 3315 | - public function set_add_edit_form_tags(string $route = '', array $additional_hidden_fields = []) |
|
| 3316 | - { |
|
| 3317 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3318 | - } |
|
| 3319 | - |
|
| 3320 | - |
|
| 3321 | - /** |
|
| 3322 | - * set form open and close tags on add/edit pages. |
|
| 3323 | - * |
|
| 3324 | - * @param string $route the route you want the form to direct to |
|
| 3325 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3326 | - * @return void |
|
| 3327 | - */ |
|
| 3328 | - protected function _set_add_edit_form_tags(string $route = '', array $additional_hidden_fields = []) |
|
| 3329 | - { |
|
| 3330 | - if (empty($route)) { |
|
| 3331 | - $user_msg = esc_html__( |
|
| 3332 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3333 | - 'event_espresso' |
|
| 3334 | - ); |
|
| 3335 | - $dev_msg = $user_msg . "\n" |
|
| 3336 | - . sprintf( |
|
| 3337 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3338 | - __FUNCTION__, |
|
| 3339 | - __CLASS__ |
|
| 3340 | - ); |
|
| 3341 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3342 | - } |
|
| 3343 | - // open form |
|
| 3344 | - $action = $this->_admin_base_url; |
|
| 3345 | - $this->_template_args['before_admin_page_content'] = " |
|
| 2977 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2978 | + // display message about search results? |
|
| 2979 | + $search = $this->request->getRequestParam('s'); |
|
| 2980 | + $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2981 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 2982 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2983 | + trim($search, '%') |
|
| 2984 | + ) . '</p>' |
|
| 2985 | + : ''; |
|
| 2986 | + // filter before_list_table template arg |
|
| 2987 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 2988 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2989 | + $this->_template_args['before_list_table'], |
|
| 2990 | + $this->page_slug, |
|
| 2991 | + $this->request->requestParams(), |
|
| 2992 | + $this->_req_action |
|
| 2993 | + ); |
|
| 2994 | + // convert to array and filter again |
|
| 2995 | + // arrays are easier to inject new items in a specific location, |
|
| 2996 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2997 | + $this->_template_args['before_list_table'] = implode( |
|
| 2998 | + " \n", |
|
| 2999 | + (array) apply_filters( |
|
| 3000 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3001 | + (array) $this->_template_args['before_list_table'], |
|
| 3002 | + $this->page_slug, |
|
| 3003 | + $this->request->requestParams(), |
|
| 3004 | + $this->_req_action |
|
| 3005 | + ) |
|
| 3006 | + ); |
|
| 3007 | + // filter after_list_table template arg |
|
| 3008 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3009 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3010 | + $this->_template_args['after_list_table'], |
|
| 3011 | + $this->page_slug, |
|
| 3012 | + $this->request->requestParams(), |
|
| 3013 | + $this->_req_action |
|
| 3014 | + ); |
|
| 3015 | + // convert to array and filter again |
|
| 3016 | + // arrays are easier to inject new items in a specific location, |
|
| 3017 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3018 | + $this->_template_args['after_list_table'] = implode( |
|
| 3019 | + " \n", |
|
| 3020 | + (array) apply_filters( |
|
| 3021 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3022 | + (array) $this->_template_args['after_list_table'], |
|
| 3023 | + $this->page_slug, |
|
| 3024 | + $this->request->requestParams(), |
|
| 3025 | + $this->_req_action |
|
| 3026 | + ) |
|
| 3027 | + ); |
|
| 3028 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3029 | + $template_path, |
|
| 3030 | + $this->_template_args, |
|
| 3031 | + true |
|
| 3032 | + ); |
|
| 3033 | + // the final template wrapper |
|
| 3034 | + if ($sidebar) { |
|
| 3035 | + $this->display_admin_page_with_sidebar(); |
|
| 3036 | + } else { |
|
| 3037 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3038 | + } |
|
| 3039 | + } |
|
| 3040 | + |
|
| 3041 | + |
|
| 3042 | + /** |
|
| 3043 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3044 | + * html string for the legend. |
|
| 3045 | + * $items are expected in an array in the following format: |
|
| 3046 | + * $legend_items = array( |
|
| 3047 | + * 'item_id' => array( |
|
| 3048 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3049 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3050 | + * ) |
|
| 3051 | + * ); |
|
| 3052 | + * |
|
| 3053 | + * @param array $items see above for format of array |
|
| 3054 | + * @return string html string of legend |
|
| 3055 | + * @throws DomainException |
|
| 3056 | + */ |
|
| 3057 | + protected function _display_legend(array $items): string |
|
| 3058 | + { |
|
| 3059 | + $this->_template_args['items'] = (array) apply_filters( |
|
| 3060 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3061 | + $items, |
|
| 3062 | + $this |
|
| 3063 | + ); |
|
| 3064 | + /** @var StatusChangeNotice $status_change_notice */ |
|
| 3065 | + $status_change_notice = $this->loader->getShared( |
|
| 3066 | + 'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice' |
|
| 3067 | + ); |
|
| 3068 | + $this->_template_args['status_change_notice'] = $status_change_notice->display( |
|
| 3069 | + '__admin-legend', |
|
| 3070 | + $this->page_slug |
|
| 3071 | + ); |
|
| 3072 | + return EEH_Template::display_template( |
|
| 3073 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3074 | + $this->_template_args, |
|
| 3075 | + true |
|
| 3076 | + ); |
|
| 3077 | + } |
|
| 3078 | + |
|
| 3079 | + |
|
| 3080 | + /** |
|
| 3081 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3082 | + * The returned json object is created from an array in the following format: |
|
| 3083 | + * array( |
|
| 3084 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3085 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3086 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3087 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3088 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3089 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3090 | + * that might be included in here) |
|
| 3091 | + * ) |
|
| 3092 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3093 | + * |
|
| 3094 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3095 | + * instead of displayed. |
|
| 3096 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3097 | + * @return void |
|
| 3098 | + * @throws EE_Error |
|
| 3099 | + * @throws InvalidArgumentException |
|
| 3100 | + * @throws InvalidDataTypeException |
|
| 3101 | + * @throws InvalidInterfaceException |
|
| 3102 | + */ |
|
| 3103 | + protected function _return_json(bool $sticky_notices = false, array $notices_arguments = []) |
|
| 3104 | + { |
|
| 3105 | + // make sure any EE_Error notices have been handled. |
|
| 3106 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3107 | + $data = $this->_template_args['data'] ?? []; |
|
| 3108 | + unset($this->_template_args['data']); |
|
| 3109 | + $json = [ |
|
| 3110 | + 'error' => $this->_template_args['error'] ?? false, |
|
| 3111 | + 'success' => $this->_template_args['success'] ?? false, |
|
| 3112 | + 'errors' => $this->_template_args['errors'] ?? false, |
|
| 3113 | + 'attention' => $this->_template_args['attention'] ?? false, |
|
| 3114 | + 'notices' => EE_Error::get_notices(), |
|
| 3115 | + 'content' => $this->_template_args['admin_page_content'] ?? '', |
|
| 3116 | + 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3117 | + 'isEEajax' => true, |
|
| 3118 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3119 | + ]; |
|
| 3120 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3121 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3122 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3123 | + } |
|
| 3124 | + echo wp_json_encode($json); |
|
| 3125 | + exit(); |
|
| 3126 | + } |
|
| 3127 | + |
|
| 3128 | + |
|
| 3129 | + /** |
|
| 3130 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3131 | + * |
|
| 3132 | + * @return void |
|
| 3133 | + * @throws EE_Error |
|
| 3134 | + * @throws InvalidArgumentException |
|
| 3135 | + * @throws InvalidDataTypeException |
|
| 3136 | + * @throws InvalidInterfaceException |
|
| 3137 | + */ |
|
| 3138 | + public function return_json() |
|
| 3139 | + { |
|
| 3140 | + if ($this->request->isAjax()) { |
|
| 3141 | + $this->_return_json(); |
|
| 3142 | + } else { |
|
| 3143 | + throw new EE_Error( |
|
| 3144 | + sprintf( |
|
| 3145 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3146 | + __FUNCTION__ |
|
| 3147 | + ) |
|
| 3148 | + ); |
|
| 3149 | + } |
|
| 3150 | + } |
|
| 3151 | + |
|
| 3152 | + |
|
| 3153 | + /** |
|
| 3154 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3155 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3156 | + * |
|
| 3157 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3158 | + * @deprecated 5.0.8.p |
|
| 3159 | + */ |
|
| 3160 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3161 | + { |
|
| 3162 | + $this->_hook_obj = $hook_obj; |
|
| 3163 | + } |
|
| 3164 | + |
|
| 3165 | + |
|
| 3166 | + /** |
|
| 3167 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3168 | + * |
|
| 3169 | + * @param bool $about whether to use the special about page wrapper or default. |
|
| 3170 | + * @return void |
|
| 3171 | + * @throws DomainException |
|
| 3172 | + * @throws EE_Error |
|
| 3173 | + * @throws InvalidArgumentException |
|
| 3174 | + * @throws InvalidDataTypeException |
|
| 3175 | + * @throws InvalidInterfaceException |
|
| 3176 | + */ |
|
| 3177 | + public function admin_page_wrapper(bool $about = false) |
|
| 3178 | + { |
|
| 3179 | + $this->_template_args['nav_tabs'] = $this->_get_main_nav_tabs(); |
|
| 3180 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3181 | + |
|
| 3182 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3183 | + "FHEE_before_admin_page_content$this->_current_page$this->_current_view", |
|
| 3184 | + $this->_template_args['before_admin_page_content'] ?? '' |
|
| 3185 | + ); |
|
| 3186 | + |
|
| 3187 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3188 | + "FHEE_after_admin_page_content$this->_current_page$this->_current_view", |
|
| 3189 | + $this->_template_args['after_admin_page_content'] ?? '' |
|
| 3190 | + ); |
|
| 3191 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3192 | + |
|
| 3193 | + if ($this->request->isAjax()) { |
|
| 3194 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3195 | + // $template_path, |
|
| 3196 | + EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3197 | + $this->_template_args, |
|
| 3198 | + true |
|
| 3199 | + ); |
|
| 3200 | + $this->_return_json(); |
|
| 3201 | + } |
|
| 3202 | + // load settings page wrapper template |
|
| 3203 | + $template_path = $about |
|
| 3204 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3205 | + : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3206 | + |
|
| 3207 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3208 | + } |
|
| 3209 | + |
|
| 3210 | + |
|
| 3211 | + /** |
|
| 3212 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3213 | + * |
|
| 3214 | + * @return string html |
|
| 3215 | + * @throws EE_Error |
|
| 3216 | + */ |
|
| 3217 | + protected function _get_main_nav_tabs(): string |
|
| 3218 | + { |
|
| 3219 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3220 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3221 | + // (rather than setting in the page_routes array) |
|
| 3222 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs, $this->page_slug); |
|
| 3223 | + } |
|
| 3224 | + |
|
| 3225 | + |
|
| 3226 | + /** |
|
| 3227 | + * sort nav tabs |
|
| 3228 | + * |
|
| 3229 | + * @param array $a |
|
| 3230 | + * @param array $b |
|
| 3231 | + * @return int |
|
| 3232 | + */ |
|
| 3233 | + private function _sort_nav_tabs(array $a, array $b): int |
|
| 3234 | + { |
|
| 3235 | + if ($a['order'] === $b['order']) { |
|
| 3236 | + return 0; |
|
| 3237 | + } |
|
| 3238 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3239 | + } |
|
| 3240 | + |
|
| 3241 | + |
|
| 3242 | + /** |
|
| 3243 | + * generates HTML for the forms used on admin pages |
|
| 3244 | + * |
|
| 3245 | + * @param array $input_vars - array of input field details |
|
| 3246 | + * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3247 | + * @param bool $id |
|
| 3248 | + * @return array|string |
|
| 3249 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3250 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3251 | + */ |
|
| 3252 | + protected function _generate_admin_form_fields( |
|
| 3253 | + array $input_vars = [], |
|
| 3254 | + string $generator = 'string', |
|
| 3255 | + bool $id = false |
|
| 3256 | + ) { |
|
| 3257 | + return $generator === 'string' |
|
| 3258 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3259 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3260 | + } |
|
| 3261 | + |
|
| 3262 | + |
|
| 3263 | + /** |
|
| 3264 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3265 | + * |
|
| 3266 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3267 | + * Close" button. |
|
| 3268 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3269 | + * 'Save', [1] => 'save & close') |
|
| 3270 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3271 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3272 | + * default actions by submitting some other value. |
|
| 3273 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3274 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3275 | + * close (normal form handling). |
|
| 3276 | + */ |
|
| 3277 | + protected function _set_save_buttons(bool $both = true, array $text = [], array $actions = [], $referrer = null) |
|
| 3278 | + { |
|
| 3279 | + $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3280 | + $button_text = ! empty($text) |
|
| 3281 | + ? $text |
|
| 3282 | + : [ |
|
| 3283 | + esc_html__('Save', 'event_espresso'), |
|
| 3284 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3285 | + ]; |
|
| 3286 | + $default_names = ['save', 'save_and_close']; |
|
| 3287 | + $buttons = ''; |
|
| 3288 | + foreach ($button_text as $key => $button) { |
|
| 3289 | + $ref = $default_names[ $key ]; |
|
| 3290 | + $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3291 | + $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" ' |
|
| 3292 | + . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3293 | + . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3294 | + if (! $both) { |
|
| 3295 | + break; |
|
| 3296 | + } |
|
| 3297 | + } |
|
| 3298 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3299 | + $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3300 | + . $referrer_url |
|
| 3301 | + . '" />'; |
|
| 3302 | + |
|
| 3303 | + $this->_template_args['save_buttons'] = $buttons; |
|
| 3304 | + } |
|
| 3305 | + |
|
| 3306 | + |
|
| 3307 | + /** |
|
| 3308 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3309 | + * |
|
| 3310 | + * @param string $route |
|
| 3311 | + * @param array $additional_hidden_fields |
|
| 3312 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3313 | + * @since 4.6.0 |
|
| 3314 | + */ |
|
| 3315 | + public function set_add_edit_form_tags(string $route = '', array $additional_hidden_fields = []) |
|
| 3316 | + { |
|
| 3317 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3318 | + } |
|
| 3319 | + |
|
| 3320 | + |
|
| 3321 | + /** |
|
| 3322 | + * set form open and close tags on add/edit pages. |
|
| 3323 | + * |
|
| 3324 | + * @param string $route the route you want the form to direct to |
|
| 3325 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3326 | + * @return void |
|
| 3327 | + */ |
|
| 3328 | + protected function _set_add_edit_form_tags(string $route = '', array $additional_hidden_fields = []) |
|
| 3329 | + { |
|
| 3330 | + if (empty($route)) { |
|
| 3331 | + $user_msg = esc_html__( |
|
| 3332 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3333 | + 'event_espresso' |
|
| 3334 | + ); |
|
| 3335 | + $dev_msg = $user_msg . "\n" |
|
| 3336 | + . sprintf( |
|
| 3337 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3338 | + __FUNCTION__, |
|
| 3339 | + __CLASS__ |
|
| 3340 | + ); |
|
| 3341 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3342 | + } |
|
| 3343 | + // open form |
|
| 3344 | + $action = $this->_admin_base_url; |
|
| 3345 | + $this->_template_args['before_admin_page_content'] = " |
|
| 3346 | 3346 | <form name='form' method='post' action='$action' id='{$route}_event_form' class='ee-admin-page-form' > |
| 3347 | 3347 | "; |
| 3348 | - // add nonce |
|
| 3349 | - $nonce = |
|
| 3350 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3351 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3352 | - // add REQUIRED form action |
|
| 3353 | - $hidden_fields = [ |
|
| 3354 | - 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3355 | - ]; |
|
| 3356 | - // merge arrays |
|
| 3357 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3358 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3359 | - : $hidden_fields; |
|
| 3360 | - // generate form fields |
|
| 3361 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3362 | - // add fields to form |
|
| 3363 | - foreach ((array) $form_fields as $form_field) { |
|
| 3364 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3365 | - } |
|
| 3366 | - // close form |
|
| 3367 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3368 | - } |
|
| 3369 | - |
|
| 3370 | - |
|
| 3371 | - /** |
|
| 3372 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3373 | - * discovered it would be useful for external code to have access. |
|
| 3374 | - * |
|
| 3375 | - * @param bool|int $success |
|
| 3376 | - * @param string $what |
|
| 3377 | - * @param string $action_desc |
|
| 3378 | - * @param array $query_args |
|
| 3379 | - * @param bool $override_overwrite |
|
| 3380 | - * @throws EE_Error |
|
| 3381 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3382 | - * @since 4.5.0 |
|
| 3383 | - */ |
|
| 3384 | - public function redirect_after_action( |
|
| 3385 | - $success = false, |
|
| 3386 | - string $what = 'item', |
|
| 3387 | - string $action_desc = 'processed', |
|
| 3388 | - array $query_args = [], |
|
| 3389 | - bool $override_overwrite = false |
|
| 3390 | - ) { |
|
| 3391 | - $this->_redirect_after_action( |
|
| 3392 | - $success, |
|
| 3393 | - $what, |
|
| 3394 | - $action_desc, |
|
| 3395 | - $query_args, |
|
| 3396 | - $override_overwrite |
|
| 3397 | - ); |
|
| 3398 | - } |
|
| 3399 | - |
|
| 3400 | - |
|
| 3401 | - /** |
|
| 3402 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3403 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3404 | - * filters are still applied. |
|
| 3405 | - * |
|
| 3406 | - * @param array $new_route_data |
|
| 3407 | - * @return array |
|
| 3408 | - */ |
|
| 3409 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data): array |
|
| 3410 | - { |
|
| 3411 | - foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3412 | - // unset nonces |
|
| 3413 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3414 | - $this->request->unSetRequestParam($ref); |
|
| 3415 | - continue; |
|
| 3416 | - } |
|
| 3417 | - // urlencode values. |
|
| 3418 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3419 | - $this->request->setRequestParam($ref, $value); |
|
| 3420 | - } |
|
| 3421 | - return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3422 | - } |
|
| 3423 | - |
|
| 3424 | - |
|
| 3425 | - /** |
|
| 3426 | - * @param int|float|string $success - whether success was for two or more records, or just one, or none |
|
| 3427 | - * @param string $what - what the action was performed on |
|
| 3428 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3429 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to |
|
| 3430 | - * @param BOOL $override_overwrite - by default all EE_Error::success messages are overwritten, |
|
| 3431 | - * this allows you to override this so that they show. |
|
| 3432 | - * @return void |
|
| 3433 | - * @throws EE_Error |
|
| 3434 | - * @throws InvalidArgumentException |
|
| 3435 | - * @throws InvalidDataTypeException |
|
| 3436 | - * @throws InvalidInterfaceException |
|
| 3437 | - */ |
|
| 3438 | - protected function _redirect_after_action( |
|
| 3439 | - $success = 0, |
|
| 3440 | - string $what = 'item', |
|
| 3441 | - string $action_desc = 'processed', |
|
| 3442 | - array $query_args = [], |
|
| 3443 | - bool $override_overwrite = false |
|
| 3444 | - ) { |
|
| 3445 | - $notices = EE_Error::get_notices(false); |
|
| 3446 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3447 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3448 | - EE_Error::overwrite_success(); |
|
| 3449 | - } |
|
| 3450 | - if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3451 | - // how many records affected ? more than one record ? or just one ? |
|
| 3452 | - EE_Error::add_success( |
|
| 3453 | - sprintf( |
|
| 3454 | - esc_html( |
|
| 3455 | - _n( |
|
| 3456 | - 'The "%1$s" has been successfully %2$s.', |
|
| 3457 | - 'The "%1$s" have been successfully %2$s.', |
|
| 3458 | - $success, |
|
| 3459 | - 'event_espresso' |
|
| 3460 | - ) |
|
| 3461 | - ), |
|
| 3462 | - $what, |
|
| 3463 | - $action_desc |
|
| 3464 | - ), |
|
| 3465 | - __FILE__, |
|
| 3466 | - __FUNCTION__, |
|
| 3467 | - __LINE__ |
|
| 3468 | - ); |
|
| 3469 | - } |
|
| 3470 | - // check that $query_args isn't something crazy |
|
| 3471 | - $query_args = is_array($query_args) ? $query_args : []; |
|
| 3472 | - /** |
|
| 3473 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3474 | - * redirections on save and close actions |
|
| 3475 | - * |
|
| 3476 | - * @param array $query_args The original query_args array coming into the |
|
| 3477 | - * method. |
|
| 3478 | - * @since 4.2.0 |
|
| 3479 | - */ |
|
| 3480 | - do_action( |
|
| 3481 | - "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_$this->_req_action", |
|
| 3482 | - $query_args |
|
| 3483 | - ); |
|
| 3484 | - // set redirect url. |
|
| 3485 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3486 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3487 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3488 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3489 | - if ( |
|
| 3490 | - $this->request->requestParamIsSet('save_and_close') |
|
| 3491 | - && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3492 | - ) { |
|
| 3493 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3494 | - $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', DataType::URL)); |
|
| 3495 | - // regenerate query args array from referrer URL |
|
| 3496 | - parse_str($parsed_url['query'], $query_args); |
|
| 3497 | - // correct page and action will be in the query args now |
|
| 3498 | - $redirect_url = admin_url('admin.php'); |
|
| 3499 | - } |
|
| 3500 | - // merge any default query_args set in _default_route_query_args property |
|
| 3501 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3502 | - $args_to_merge = []; |
|
| 3503 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3504 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3505 | - if ($query_param === 'wp_referer') { |
|
| 3506 | - $query_value = (array) $query_value; |
|
| 3507 | - foreach ($query_value as $reference => $value) { |
|
| 3508 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3509 | - continue; |
|
| 3510 | - } |
|
| 3511 | - // finally we will override any arguments in the referer with |
|
| 3512 | - // what might be set on the _default_route_query_args array. |
|
| 3513 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3514 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3515 | - } else { |
|
| 3516 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3517 | - } |
|
| 3518 | - } |
|
| 3519 | - continue; |
|
| 3520 | - } |
|
| 3521 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3522 | - } |
|
| 3523 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3524 | - // redirect. |
|
| 3525 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3526 | - } |
|
| 3527 | - $this->_process_notices($query_args); |
|
| 3528 | - // generate redirect url |
|
| 3529 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3530 | - if (isset($query_args['action'])) { |
|
| 3531 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3532 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3533 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3534 | - } |
|
| 3535 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3536 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3537 | - do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args); |
|
| 3538 | - $redirect_url = apply_filters( |
|
| 3539 | - 'FHEE_redirect_' . $this->class_name . $this->_req_action, |
|
| 3540 | - EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3541 | - $query_args |
|
| 3542 | - ); |
|
| 3543 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3544 | - if ($this->request->isAjax()) { |
|
| 3545 | - $default_data = [ |
|
| 3546 | - 'close' => true, |
|
| 3547 | - 'redirect_url' => $redirect_url, |
|
| 3548 | - 'where' => 'main', |
|
| 3549 | - 'what' => 'append', |
|
| 3550 | - ]; |
|
| 3551 | - $this->_template_args['success'] = $success; |
|
| 3552 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3553 | - $default_data, |
|
| 3554 | - $this->_template_args['data'] |
|
| 3555 | - ) : $default_data; |
|
| 3556 | - $this->_return_json(); |
|
| 3557 | - } |
|
| 3558 | - wp_safe_redirect($redirect_url); |
|
| 3559 | - exit(); |
|
| 3560 | - } |
|
| 3561 | - |
|
| 3562 | - |
|
| 3563 | - /** |
|
| 3564 | - * process any notices before redirecting (or returning ajax request) |
|
| 3565 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3566 | - * |
|
| 3567 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3568 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3569 | - * page_routes haven't been defined yet. |
|
| 3570 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3571 | - * still save a transient for the notice. |
|
| 3572 | - * @return void |
|
| 3573 | - * @throws EE_Error |
|
| 3574 | - * @throws InvalidArgumentException |
|
| 3575 | - * @throws InvalidDataTypeException |
|
| 3576 | - * @throws InvalidInterfaceException |
|
| 3577 | - */ |
|
| 3578 | - protected function _process_notices( |
|
| 3579 | - array $query_args = [], |
|
| 3580 | - bool $skip_route_verify = false, |
|
| 3581 | - bool $sticky_notices = true |
|
| 3582 | - ) { |
|
| 3583 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3584 | - if ($this->request->isAjax()) { |
|
| 3585 | - $notices = EE_Error::get_notices(false); |
|
| 3586 | - if (empty($this->_template_args['success'])) { |
|
| 3587 | - $this->_template_args['success'] = $notices['success'] ?? false; |
|
| 3588 | - } |
|
| 3589 | - if (empty($this->_template_args['errors'])) { |
|
| 3590 | - $this->_template_args['errors'] = $notices['errors'] ?? false; |
|
| 3591 | - } |
|
| 3592 | - if (empty($this->_template_args['attention'])) { |
|
| 3593 | - $this->_template_args['attention'] = $notices['attention'] ?? false; |
|
| 3594 | - } |
|
| 3595 | - } |
|
| 3596 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3597 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3598 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3599 | - $route = $query_args['action'] ?? 'default'; |
|
| 3600 | - $this->_add_transient( |
|
| 3601 | - $route, |
|
| 3602 | - (array) $this->_template_args['notices'], |
|
| 3603 | - true, |
|
| 3604 | - $skip_route_verify |
|
| 3605 | - ); |
|
| 3606 | - } |
|
| 3607 | - } |
|
| 3608 | - |
|
| 3609 | - |
|
| 3610 | - /** |
|
| 3611 | - * get_action_link_or_button |
|
| 3612 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3613 | - * |
|
| 3614 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3615 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3616 | - * property. |
|
| 3617 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3618 | - * @param string $class Use this to give the class for the button. Defaults to 'button--primary' |
|
| 3619 | - * @param string $base_url If this is not provided |
|
| 3620 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3621 | - * Otherwise this value will be used. |
|
| 3622 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3623 | - * @return string |
|
| 3624 | - * @throws InvalidArgumentException |
|
| 3625 | - * @throws InvalidInterfaceException |
|
| 3626 | - * @throws InvalidDataTypeException |
|
| 3627 | - * @throws EE_Error |
|
| 3628 | - */ |
|
| 3629 | - public function get_action_link_or_button( |
|
| 3630 | - string $action, |
|
| 3631 | - string $type = 'add', |
|
| 3632 | - array $extra_request = [], |
|
| 3633 | - string $class = 'button button--primary', |
|
| 3634 | - string $base_url = '', |
|
| 3635 | - bool $exclude_nonce = false |
|
| 3636 | - ): string { |
|
| 3637 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3638 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3639 | - throw new EE_Error( |
|
| 3640 | - sprintf( |
|
| 3641 | - esc_html__( |
|
| 3642 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3643 | - 'event_espresso' |
|
| 3644 | - ), |
|
| 3645 | - $action |
|
| 3646 | - ) |
|
| 3647 | - ); |
|
| 3648 | - } |
|
| 3649 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3650 | - throw new EE_Error( |
|
| 3651 | - sprintf( |
|
| 3652 | - esc_html__( |
|
| 3653 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3654 | - 'event_espresso' |
|
| 3655 | - ), |
|
| 3656 | - $type |
|
| 3657 | - ) |
|
| 3658 | - ); |
|
| 3659 | - } |
|
| 3660 | - // finally check user access for this button. |
|
| 3661 | - $has_access = $this->check_user_access($action, true); |
|
| 3662 | - if (! $has_access) { |
|
| 3663 | - return ''; |
|
| 3664 | - } |
|
| 3665 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3666 | - $query_args = [ |
|
| 3667 | - 'action' => $action, |
|
| 3668 | - ]; |
|
| 3669 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3670 | - if (! empty($extra_request)) { |
|
| 3671 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3672 | - } |
|
| 3673 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3674 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3675 | - } |
|
| 3676 | - |
|
| 3677 | - |
|
| 3678 | - /** |
|
| 3679 | - * _per_page_screen_option |
|
| 3680 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3681 | - * |
|
| 3682 | - * @return void |
|
| 3683 | - * @throws InvalidArgumentException |
|
| 3684 | - * @throws InvalidInterfaceException |
|
| 3685 | - * @throws InvalidDataTypeException |
|
| 3686 | - */ |
|
| 3687 | - protected function _per_page_screen_option() |
|
| 3688 | - { |
|
| 3689 | - $option = 'per_page'; |
|
| 3690 | - $args = [ |
|
| 3691 | - 'label' => apply_filters( |
|
| 3692 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3693 | - $this->_admin_page_title, |
|
| 3694 | - $this |
|
| 3695 | - ), |
|
| 3696 | - 'default' => (int) apply_filters( |
|
| 3697 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3698 | - 20 |
|
| 3699 | - ), |
|
| 3700 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3701 | - ]; |
|
| 3702 | - // ONLY add the screen option if the user has access to it. |
|
| 3703 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3704 | - add_screen_option($option, $args); |
|
| 3705 | - } |
|
| 3706 | - } |
|
| 3707 | - |
|
| 3708 | - |
|
| 3709 | - /** |
|
| 3710 | - * set_per_page_screen_option |
|
| 3711 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3712 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3713 | - * admin_menu. |
|
| 3714 | - * |
|
| 3715 | - * @return void |
|
| 3716 | - */ |
|
| 3717 | - private function _set_per_page_screen_options() |
|
| 3718 | - { |
|
| 3719 | - if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3720 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3721 | - if (! $user = wp_get_current_user()) { |
|
| 3722 | - return; |
|
| 3723 | - } |
|
| 3724 | - $option = $this->request->getRequestParam('wp_screen_options[option]', '', DataType::KEY); |
|
| 3725 | - if (! $option) { |
|
| 3726 | - return; |
|
| 3727 | - } |
|
| 3728 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, DataType::INT); |
|
| 3729 | - $map_option = $option; |
|
| 3730 | - $option = str_replace('-', '_', $option); |
|
| 3731 | - switch ($map_option) { |
|
| 3732 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3733 | - $max_value = apply_filters( |
|
| 3734 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3735 | - 999, |
|
| 3736 | - $this->_current_page, |
|
| 3737 | - $this->_current_view |
|
| 3738 | - ); |
|
| 3739 | - if ($value < 1) { |
|
| 3740 | - return; |
|
| 3741 | - } |
|
| 3742 | - $value = min($value, $max_value); |
|
| 3743 | - break; |
|
| 3744 | - default: |
|
| 3745 | - $value = apply_filters( |
|
| 3746 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3747 | - false, |
|
| 3748 | - $option, |
|
| 3749 | - $value |
|
| 3750 | - ); |
|
| 3751 | - if (false === $value) { |
|
| 3752 | - return; |
|
| 3753 | - } |
|
| 3754 | - break; |
|
| 3755 | - } |
|
| 3756 | - update_user_meta($user->ID, $option, $value); |
|
| 3757 | - wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3758 | - exit; |
|
| 3759 | - } |
|
| 3760 | - } |
|
| 3761 | - |
|
| 3762 | - |
|
| 3763 | - /** |
|
| 3764 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3765 | - * |
|
| 3766 | - * @param array $data array that will be assigned to template args. |
|
| 3767 | - */ |
|
| 3768 | - public function set_template_args(array $data) |
|
| 3769 | - { |
|
| 3770 | - $this->_template_args = array_merge($this->_template_args, $data); |
|
| 3771 | - } |
|
| 3772 | - |
|
| 3773 | - |
|
| 3774 | - public function setAdminPageTitle(string $title) |
|
| 3775 | - { |
|
| 3776 | - $this->_admin_page_title = sanitize_text_field($title); |
|
| 3777 | - } |
|
| 3778 | - |
|
| 3779 | - |
|
| 3780 | - /** |
|
| 3781 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3782 | - * |
|
| 3783 | - * @param string $route the route that should receive the transient |
|
| 3784 | - * @param array $data the data that gets sent |
|
| 3785 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3786 | - * normal route transient. |
|
| 3787 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3788 | - * when we are adding a transient before page_routes have been defined. |
|
| 3789 | - * @return void |
|
| 3790 | - * @throws EE_Error |
|
| 3791 | - */ |
|
| 3792 | - protected function _add_transient( |
|
| 3793 | - string $route, |
|
| 3794 | - array $data, |
|
| 3795 | - bool $notices = false, |
|
| 3796 | - bool $skip_route_verify = false |
|
| 3797 | - ) { |
|
| 3798 | - $user_id = get_current_user_id(); |
|
| 3799 | - if (! $skip_route_verify) { |
|
| 3800 | - $this->_verify_route($route); |
|
| 3801 | - } |
|
| 3802 | - // now let's set the string for what kind of transient we're setting |
|
| 3803 | - $transient = $notices ? "ee_rte_n_tx_{$route}_$user_id" : "rte_tx_{$route}_$user_id"; |
|
| 3804 | - $data = $notices ? ['notices' => $data] : $data; |
|
| 3805 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3806 | - $existing = is_multisite() && is_network_admin() |
|
| 3807 | - ? get_site_transient($transient) |
|
| 3808 | - : get_transient($transient); |
|
| 3809 | - if ($existing) { |
|
| 3810 | - $data = array_merge($data, (array) $existing); |
|
| 3811 | - } |
|
| 3812 | - if (is_multisite() && is_network_admin()) { |
|
| 3813 | - set_site_transient($transient, $data, 8); |
|
| 3814 | - } else { |
|
| 3815 | - set_transient($transient, $data, 8); |
|
| 3816 | - } |
|
| 3817 | - } |
|
| 3818 | - |
|
| 3819 | - |
|
| 3820 | - /** |
|
| 3821 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3822 | - * |
|
| 3823 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3824 | - * @param string $route |
|
| 3825 | - * @return mixed data |
|
| 3826 | - */ |
|
| 3827 | - protected function _get_transient(bool $notices = false, string $route = '') |
|
| 3828 | - { |
|
| 3829 | - $user_id = get_current_user_id(); |
|
| 3830 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3831 | - $transient = $notices |
|
| 3832 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3833 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3834 | - $data = is_multisite() && is_network_admin() |
|
| 3835 | - ? get_site_transient($transient) |
|
| 3836 | - : get_transient($transient); |
|
| 3837 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3838 | - if (is_multisite() && is_network_admin()) { |
|
| 3839 | - delete_site_transient($transient); |
|
| 3840 | - } else { |
|
| 3841 | - delete_transient($transient); |
|
| 3842 | - } |
|
| 3843 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3844 | - } |
|
| 3845 | - |
|
| 3846 | - |
|
| 3847 | - /** |
|
| 3848 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3849 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3850 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3851 | - * |
|
| 3852 | - * @return void |
|
| 3853 | - */ |
|
| 3854 | - protected function _transient_garbage_collection() |
|
| 3855 | - { |
|
| 3856 | - global $wpdb; |
|
| 3857 | - // retrieve all existing transients |
|
| 3858 | - $query = |
|
| 3859 | - "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3860 | - if ($results = $wpdb->get_results($query)) { |
|
| 3861 | - foreach ($results as $result) { |
|
| 3862 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3863 | - get_transient($transient); |
|
| 3864 | - if (is_multisite() && is_network_admin()) { |
|
| 3865 | - get_site_transient($transient); |
|
| 3866 | - } |
|
| 3867 | - } |
|
| 3868 | - } |
|
| 3869 | - } |
|
| 3870 | - |
|
| 3871 | - |
|
| 3872 | - /** |
|
| 3873 | - * get_view |
|
| 3874 | - * |
|
| 3875 | - * @return string content of _view property |
|
| 3876 | - */ |
|
| 3877 | - public function get_view(): string |
|
| 3878 | - { |
|
| 3879 | - return $this->_view; |
|
| 3880 | - } |
|
| 3881 | - |
|
| 3882 | - |
|
| 3883 | - /** |
|
| 3884 | - * getter for the protected $_views property |
|
| 3885 | - * |
|
| 3886 | - * @return array |
|
| 3887 | - */ |
|
| 3888 | - public function get_views(): array |
|
| 3889 | - { |
|
| 3890 | - return $this->_views; |
|
| 3891 | - } |
|
| 3892 | - |
|
| 3893 | - |
|
| 3894 | - /** |
|
| 3895 | - * @param array $views |
|
| 3896 | - * @return void |
|
| 3897 | - * @since 5.0.13.p |
|
| 3898 | - */ |
|
| 3899 | - public function updateViews(array $views) |
|
| 3900 | - { |
|
| 3901 | - $this->_views = array_merge($this->_views, $views); |
|
| 3902 | - } |
|
| 3903 | - |
|
| 3904 | - |
|
| 3905 | - /** |
|
| 3906 | - /** |
|
| 3907 | - * get_current_page |
|
| 3908 | - * |
|
| 3909 | - * @return string _current_page property value |
|
| 3910 | - */ |
|
| 3911 | - public function get_current_page(): string |
|
| 3912 | - { |
|
| 3913 | - return $this->_current_page; |
|
| 3914 | - } |
|
| 3915 | - |
|
| 3916 | - |
|
| 3917 | - /** |
|
| 3918 | - * get_current_view |
|
| 3919 | - * |
|
| 3920 | - * @return string _current_view property value |
|
| 3921 | - */ |
|
| 3922 | - public function get_current_view(): string |
|
| 3923 | - { |
|
| 3924 | - return $this->_current_view; |
|
| 3925 | - } |
|
| 3926 | - |
|
| 3927 | - |
|
| 3928 | - /** |
|
| 3929 | - * get_current_screen |
|
| 3930 | - * |
|
| 3931 | - * @return object The current WP_Screen object |
|
| 3932 | - */ |
|
| 3933 | - public function get_current_screen() |
|
| 3934 | - { |
|
| 3935 | - return $this->_current_screen; |
|
| 3936 | - } |
|
| 3937 | - |
|
| 3938 | - |
|
| 3939 | - /** |
|
| 3940 | - * get_current_page_view_url |
|
| 3941 | - * |
|
| 3942 | - * @return string This returns the url for the current_page_view. |
|
| 3943 | - */ |
|
| 3944 | - public function get_current_page_view_url(): string |
|
| 3945 | - { |
|
| 3946 | - return $this->_current_page_view_url; |
|
| 3947 | - } |
|
| 3948 | - |
|
| 3949 | - |
|
| 3950 | - /** |
|
| 3951 | - * just returns the Request |
|
| 3952 | - * |
|
| 3953 | - * @return RequestInterface |
|
| 3954 | - */ |
|
| 3955 | - public function get_request(): ?RequestInterface |
|
| 3956 | - { |
|
| 3957 | - return $this->request; |
|
| 3958 | - } |
|
| 3959 | - |
|
| 3960 | - |
|
| 3961 | - /** |
|
| 3962 | - * just returns the _req_data property |
|
| 3963 | - * |
|
| 3964 | - * @return array |
|
| 3965 | - */ |
|
| 3966 | - public function get_request_data(): array |
|
| 3967 | - { |
|
| 3968 | - return $this->request->requestParams(); |
|
| 3969 | - } |
|
| 3970 | - |
|
| 3971 | - |
|
| 3972 | - /** |
|
| 3973 | - * returns the _req_data protected property |
|
| 3974 | - * |
|
| 3975 | - * @return string |
|
| 3976 | - */ |
|
| 3977 | - public function get_req_action(): string |
|
| 3978 | - { |
|
| 3979 | - return $this->_req_action; |
|
| 3980 | - } |
|
| 3981 | - |
|
| 3982 | - |
|
| 3983 | - /** |
|
| 3984 | - * @return bool value of $_is_caf property |
|
| 3985 | - */ |
|
| 3986 | - public function is_caf(): bool |
|
| 3987 | - { |
|
| 3988 | - return $this->_is_caf; |
|
| 3989 | - } |
|
| 3990 | - |
|
| 3991 | - |
|
| 3992 | - /** |
|
| 3993 | - * @return array |
|
| 3994 | - */ |
|
| 3995 | - public function default_espresso_metaboxes(): array |
|
| 3996 | - { |
|
| 3997 | - return $this->_default_espresso_metaboxes; |
|
| 3998 | - } |
|
| 3999 | - |
|
| 4000 | - |
|
| 4001 | - /** |
|
| 4002 | - * @return string |
|
| 4003 | - */ |
|
| 4004 | - public function admin_base_url(): string |
|
| 4005 | - { |
|
| 4006 | - return $this->_admin_base_url; |
|
| 4007 | - } |
|
| 4008 | - |
|
| 4009 | - |
|
| 4010 | - /** |
|
| 4011 | - * @return string |
|
| 4012 | - */ |
|
| 4013 | - public function wp_page_slug(): string |
|
| 4014 | - { |
|
| 4015 | - return $this->_wp_page_slug; |
|
| 4016 | - } |
|
| 4017 | - |
|
| 4018 | - |
|
| 4019 | - /** |
|
| 4020 | - * updates espresso configuration settings |
|
| 4021 | - * |
|
| 4022 | - * @param string $tab |
|
| 4023 | - * @param EE_Config_Base|EE_Config $config |
|
| 4024 | - * @param string $file file where error occurred |
|
| 4025 | - * @param string $func function where error occurred |
|
| 4026 | - * @param string $line line no where error occurred |
|
| 4027 | - * @return bool |
|
| 4028 | - */ |
|
| 4029 | - protected function _update_espresso_configuration( |
|
| 4030 | - string $tab, |
|
| 4031 | - $config, |
|
| 4032 | - string $file = '', |
|
| 4033 | - string $func = '', |
|
| 4034 | - string $line = '' |
|
| 4035 | - ): bool { |
|
| 4036 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 4037 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4038 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4039 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4040 | - update_option('ee_ueip_has_notified', true); |
|
| 4041 | - } |
|
| 4042 | - // and save it (note we're also doing the network save here) |
|
| 4043 | - $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 4044 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4045 | - if ($config_saved && $net_saved) { |
|
| 4046 | - EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4047 | - return true; |
|
| 4048 | - } |
|
| 4049 | - EE_Error::add_error( |
|
| 4050 | - sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), |
|
| 4051 | - $file, |
|
| 4052 | - $func, |
|
| 4053 | - $line |
|
| 4054 | - ); |
|
| 4055 | - return false; |
|
| 4056 | - } |
|
| 4057 | - |
|
| 4058 | - |
|
| 4059 | - /** |
|
| 4060 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4061 | - * |
|
| 4062 | - * @return array |
|
| 4063 | - */ |
|
| 4064 | - public function get_yes_no_values(): array |
|
| 4065 | - { |
|
| 4066 | - return $this->_yes_no_values; |
|
| 4067 | - } |
|
| 4068 | - |
|
| 4069 | - |
|
| 4070 | - /** |
|
| 4071 | - * @return string |
|
| 4072 | - * @throws ReflectionException |
|
| 4073 | - * @since 5.0.0.p |
|
| 4074 | - */ |
|
| 4075 | - protected function _get_dir(): string |
|
| 4076 | - { |
|
| 4077 | - $reflector = new ReflectionClass($this->class_name); |
|
| 4078 | - return dirname($reflector->getFileName()); |
|
| 4079 | - } |
|
| 4080 | - |
|
| 4081 | - |
|
| 4082 | - /** |
|
| 4083 | - * A helper for getting a "next link". |
|
| 4084 | - * |
|
| 4085 | - * @param string $url The url to link to |
|
| 4086 | - * @param string $class The class to use. |
|
| 4087 | - * @return string |
|
| 4088 | - */ |
|
| 4089 | - protected function _next_link(string $url, string $class = 'dashicons dashicons-arrow-right'): string |
|
| 4090 | - { |
|
| 4091 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4092 | - } |
|
| 4093 | - |
|
| 4094 | - |
|
| 4095 | - /** |
|
| 4096 | - * A helper for getting a "previous link". |
|
| 4097 | - * |
|
| 4098 | - * @param string $url The url to link to |
|
| 4099 | - * @param string $class The class to use. |
|
| 4100 | - * @return string |
|
| 4101 | - */ |
|
| 4102 | - protected function _previous_link(string $url, string $class = 'dashicons dashicons-arrow-left'): string |
|
| 4103 | - { |
|
| 4104 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4105 | - } |
|
| 4106 | - |
|
| 4107 | - |
|
| 4108 | - |
|
| 4109 | - |
|
| 4110 | - |
|
| 4111 | - |
|
| 4112 | - |
|
| 4113 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4114 | - |
|
| 4115 | - |
|
| 4116 | - /** |
|
| 4117 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4118 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4119 | - * _req_data array. |
|
| 4120 | - * |
|
| 4121 | - * @return bool success/fail |
|
| 4122 | - * @throws EE_Error |
|
| 4123 | - * @throws InvalidArgumentException |
|
| 4124 | - * @throws ReflectionException |
|
| 4125 | - * @throws InvalidDataTypeException |
|
| 4126 | - * @throws InvalidInterfaceException |
|
| 4127 | - */ |
|
| 4128 | - protected function _process_resend_registration(): bool |
|
| 4129 | - { |
|
| 4130 | - $this->_template_args['success'] = EED_Messages::process_resend($this->request->requestParams()); |
|
| 4131 | - do_action( |
|
| 4132 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4133 | - $this->_template_args['success'], |
|
| 4134 | - $this->request->requestParams() |
|
| 4135 | - ); |
|
| 4136 | - return $this->_template_args['success']; |
|
| 4137 | - } |
|
| 4138 | - |
|
| 4139 | - |
|
| 4140 | - /** |
|
| 4141 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4142 | - * |
|
| 4143 | - * @param EE_Payment $payment |
|
| 4144 | - * @return bool success/fail |
|
| 4145 | - */ |
|
| 4146 | - protected function _process_payment_notification(EE_Payment $payment): bool |
|
| 4147 | - { |
|
| 4148 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4149 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4150 | - $this->_template_args['success'] = apply_filters( |
|
| 4151 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4152 | - false, |
|
| 4153 | - $payment |
|
| 4154 | - ); |
|
| 4155 | - return $this->_template_args['success']; |
|
| 4156 | - } |
|
| 4157 | - |
|
| 4158 | - |
|
| 4159 | - /** |
|
| 4160 | - * @param EEM_Base $entity_model |
|
| 4161 | - * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
| 4162 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4163 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4164 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4165 | - * @return int|float |
|
| 4166 | - * @throws EE_Error |
|
| 4167 | - */ |
|
| 4168 | - protected function trashRestoreDeleteEntities( |
|
| 4169 | - EEM_Base $entity_model, |
|
| 4170 | - string $entity_PK_name, |
|
| 4171 | - string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
| 4172 | - string $delete_column = '', |
|
| 4173 | - ?callable $callback = null |
|
| 4174 | - ) { |
|
| 4175 | - $entity_PK = $entity_model->get_primary_key_field(); |
|
| 4176 | - $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
| 4177 | - $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
| 4178 | - // grab ID if deleting a single entity |
|
| 4179 | - if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
| 4180 | - $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
| 4181 | - return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
| 4182 | - } |
|
| 4183 | - // or grab checkbox array if bulk deleting |
|
| 4184 | - $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
| 4185 | - if (empty($checkboxes)) { |
|
| 4186 | - return 0; |
|
| 4187 | - } |
|
| 4188 | - $success = 0; |
|
| 4189 | - $IDs = array_keys($checkboxes); |
|
| 4190 | - // cycle thru bulk action checkboxes |
|
| 4191 | - foreach ($IDs as $ID) { |
|
| 4192 | - // increment $success |
|
| 4193 | - if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
| 4194 | - $success++; |
|
| 4195 | - } |
|
| 4196 | - } |
|
| 4197 | - $count = (int) count($checkboxes); |
|
| 4198 | - // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
| 4199 | - // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
| 4200 | - return $success === $count ? $count : $success / $count; |
|
| 4201 | - } |
|
| 4202 | - |
|
| 4203 | - |
|
| 4204 | - /** |
|
| 4205 | - * @param EE_Primary_Key_Field_Base $entity_PK |
|
| 4206 | - * @return string |
|
| 4207 | - * @throws EE_Error |
|
| 4208 | - * @since 4.10.30.p |
|
| 4209 | - */ |
|
| 4210 | - private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
| 4211 | - { |
|
| 4212 | - $entity_PK_type = $entity_PK->getSchemaType(); |
|
| 4213 | - switch ($entity_PK_type) { |
|
| 4214 | - case 'boolean': |
|
| 4215 | - return DataType::BOOL; |
|
| 4216 | - case 'integer': |
|
| 4217 | - return DataType::INT; |
|
| 4218 | - case 'number': |
|
| 4219 | - return DataType::FLOAT; |
|
| 4220 | - case 'string': |
|
| 4221 | - return DataType::STRING; |
|
| 4222 | - } |
|
| 4223 | - throw new RuntimeException( |
|
| 4224 | - sprintf( |
|
| 4225 | - esc_html__( |
|
| 4226 | - '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
| 4227 | - 'event_espresso' |
|
| 4228 | - ), |
|
| 4229 | - $entity_PK_type, |
|
| 4230 | - $entity_PK->get_name() |
|
| 4231 | - ) |
|
| 4232 | - ); |
|
| 4233 | - } |
|
| 4234 | - |
|
| 4235 | - |
|
| 4236 | - /** |
|
| 4237 | - * @param EEM_Base $entity_model |
|
| 4238 | - * @param int|string $entity_ID |
|
| 4239 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4240 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4241 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4242 | - * @return bool |
|
| 4243 | - */ |
|
| 4244 | - protected function trashRestoreDeleteEntity( |
|
| 4245 | - EEM_Base $entity_model, |
|
| 4246 | - $entity_ID, |
|
| 4247 | - string $action, |
|
| 4248 | - string $delete_column, |
|
| 4249 | - ?callable $callback = null |
|
| 4250 | - ): bool { |
|
| 4251 | - $entity_ID = absint($entity_ID); |
|
| 4252 | - if (! $entity_ID) { |
|
| 4253 | - $this->trashRestoreDeleteError($action, $entity_model); |
|
| 4254 | - } |
|
| 4255 | - $result = 0; |
|
| 4256 | - try { |
|
| 4257 | - $entity = $entity_model->get_one_by_ID($entity_ID); |
|
| 4258 | - if (! $entity instanceof EE_Base_Class) { |
|
| 4259 | - throw new DomainException( |
|
| 4260 | - sprintf( |
|
| 4261 | - esc_html__( |
|
| 4262 | - 'Missing or invalid %1$s entity with ID of "%2$s" returned from db.', |
|
| 4263 | - 'event_espresso' |
|
| 4264 | - ), |
|
| 4265 | - str_replace('EEM_', '', $entity_model->get_this_model_name()), |
|
| 4266 | - $entity_ID |
|
| 4267 | - ) |
|
| 4268 | - ); |
|
| 4269 | - } |
|
| 4270 | - switch ($action) { |
|
| 4271 | - case EE_Admin_List_Table::ACTION_DELETE: |
|
| 4272 | - $result = (bool) $entity->delete_permanently(); |
|
| 4273 | - break; |
|
| 4274 | - case EE_Admin_List_Table::ACTION_RESTORE: |
|
| 4275 | - $result = $entity->delete_or_restore(false); |
|
| 4276 | - break; |
|
| 4277 | - case EE_Admin_List_Table::ACTION_TRASH: |
|
| 4278 | - $result = $entity->delete_or_restore(); |
|
| 4279 | - break; |
|
| 4280 | - } |
|
| 4281 | - } catch (Exception $exception) { |
|
| 4282 | - $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
| 4283 | - } |
|
| 4284 | - if (is_callable($callback)) { |
|
| 4285 | - call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
| 4286 | - } |
|
| 4287 | - return $result; |
|
| 4288 | - } |
|
| 4289 | - |
|
| 4290 | - |
|
| 4291 | - /** |
|
| 4292 | - * @param EEM_Base $entity_model |
|
| 4293 | - * @param string $delete_column |
|
| 4294 | - * @since 4.10.30.p |
|
| 4295 | - */ |
|
| 4296 | - private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
| 4297 | - { |
|
| 4298 | - if (empty($delete_column)) { |
|
| 4299 | - throw new DomainException( |
|
| 4300 | - sprintf( |
|
| 4301 | - esc_html__( |
|
| 4302 | - 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
| 4303 | - 'event_espresso' |
|
| 4304 | - ), |
|
| 4305 | - $entity_model->get_this_model_name() |
|
| 4306 | - ) |
|
| 4307 | - ); |
|
| 4308 | - } |
|
| 4309 | - if (! $entity_model->has_field($delete_column)) { |
|
| 4310 | - throw new DomainException( |
|
| 4311 | - sprintf( |
|
| 4312 | - esc_html__( |
|
| 4313 | - 'The %1$s field does not exist on the %2$s model.', |
|
| 4314 | - 'event_espresso' |
|
| 4315 | - ), |
|
| 4316 | - $delete_column, |
|
| 4317 | - $entity_model->get_this_model_name() |
|
| 4318 | - ) |
|
| 4319 | - ); |
|
| 4320 | - } |
|
| 4321 | - } |
|
| 4322 | - |
|
| 4323 | - |
|
| 4324 | - /** |
|
| 4325 | - * @param EEM_Base $entity_model |
|
| 4326 | - * @param Exception|null $exception |
|
| 4327 | - * @param string $action |
|
| 4328 | - * @since 4.10.30.p |
|
| 4329 | - */ |
|
| 4330 | - private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, Exception $exception = null) |
|
| 4331 | - { |
|
| 4332 | - if ($exception instanceof Exception) { |
|
| 4333 | - throw new RuntimeException( |
|
| 4334 | - sprintf( |
|
| 4335 | - esc_html__( |
|
| 4336 | - 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
| 4337 | - 'event_espresso' |
|
| 4338 | - ), |
|
| 4339 | - $action, |
|
| 4340 | - $entity_model->get_this_model_name(), |
|
| 4341 | - $exception->getMessage() |
|
| 4342 | - ) |
|
| 4343 | - ); |
|
| 4344 | - } |
|
| 4345 | - throw new RuntimeException( |
|
| 4346 | - sprintf( |
|
| 4347 | - esc_html__( |
|
| 4348 | - 'Could not %1$s the %2$s because an invalid ID was received.', |
|
| 4349 | - 'event_espresso' |
|
| 4350 | - ), |
|
| 4351 | - $action, |
|
| 4352 | - $entity_model->get_this_model_name() |
|
| 4353 | - ) |
|
| 4354 | - ); |
|
| 4355 | - } |
|
| 3348 | + // add nonce |
|
| 3349 | + $nonce = |
|
| 3350 | + wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3351 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3352 | + // add REQUIRED form action |
|
| 3353 | + $hidden_fields = [ |
|
| 3354 | + 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3355 | + ]; |
|
| 3356 | + // merge arrays |
|
| 3357 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3358 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3359 | + : $hidden_fields; |
|
| 3360 | + // generate form fields |
|
| 3361 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3362 | + // add fields to form |
|
| 3363 | + foreach ((array) $form_fields as $form_field) { |
|
| 3364 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3365 | + } |
|
| 3366 | + // close form |
|
| 3367 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3368 | + } |
|
| 3369 | + |
|
| 3370 | + |
|
| 3371 | + /** |
|
| 3372 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3373 | + * discovered it would be useful for external code to have access. |
|
| 3374 | + * |
|
| 3375 | + * @param bool|int $success |
|
| 3376 | + * @param string $what |
|
| 3377 | + * @param string $action_desc |
|
| 3378 | + * @param array $query_args |
|
| 3379 | + * @param bool $override_overwrite |
|
| 3380 | + * @throws EE_Error |
|
| 3381 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3382 | + * @since 4.5.0 |
|
| 3383 | + */ |
|
| 3384 | + public function redirect_after_action( |
|
| 3385 | + $success = false, |
|
| 3386 | + string $what = 'item', |
|
| 3387 | + string $action_desc = 'processed', |
|
| 3388 | + array $query_args = [], |
|
| 3389 | + bool $override_overwrite = false |
|
| 3390 | + ) { |
|
| 3391 | + $this->_redirect_after_action( |
|
| 3392 | + $success, |
|
| 3393 | + $what, |
|
| 3394 | + $action_desc, |
|
| 3395 | + $query_args, |
|
| 3396 | + $override_overwrite |
|
| 3397 | + ); |
|
| 3398 | + } |
|
| 3399 | + |
|
| 3400 | + |
|
| 3401 | + /** |
|
| 3402 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3403 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3404 | + * filters are still applied. |
|
| 3405 | + * |
|
| 3406 | + * @param array $new_route_data |
|
| 3407 | + * @return array |
|
| 3408 | + */ |
|
| 3409 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data): array |
|
| 3410 | + { |
|
| 3411 | + foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3412 | + // unset nonces |
|
| 3413 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3414 | + $this->request->unSetRequestParam($ref); |
|
| 3415 | + continue; |
|
| 3416 | + } |
|
| 3417 | + // urlencode values. |
|
| 3418 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3419 | + $this->request->setRequestParam($ref, $value); |
|
| 3420 | + } |
|
| 3421 | + return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3422 | + } |
|
| 3423 | + |
|
| 3424 | + |
|
| 3425 | + /** |
|
| 3426 | + * @param int|float|string $success - whether success was for two or more records, or just one, or none |
|
| 3427 | + * @param string $what - what the action was performed on |
|
| 3428 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3429 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to |
|
| 3430 | + * @param BOOL $override_overwrite - by default all EE_Error::success messages are overwritten, |
|
| 3431 | + * this allows you to override this so that they show. |
|
| 3432 | + * @return void |
|
| 3433 | + * @throws EE_Error |
|
| 3434 | + * @throws InvalidArgumentException |
|
| 3435 | + * @throws InvalidDataTypeException |
|
| 3436 | + * @throws InvalidInterfaceException |
|
| 3437 | + */ |
|
| 3438 | + protected function _redirect_after_action( |
|
| 3439 | + $success = 0, |
|
| 3440 | + string $what = 'item', |
|
| 3441 | + string $action_desc = 'processed', |
|
| 3442 | + array $query_args = [], |
|
| 3443 | + bool $override_overwrite = false |
|
| 3444 | + ) { |
|
| 3445 | + $notices = EE_Error::get_notices(false); |
|
| 3446 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3447 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3448 | + EE_Error::overwrite_success(); |
|
| 3449 | + } |
|
| 3450 | + if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3451 | + // how many records affected ? more than one record ? or just one ? |
|
| 3452 | + EE_Error::add_success( |
|
| 3453 | + sprintf( |
|
| 3454 | + esc_html( |
|
| 3455 | + _n( |
|
| 3456 | + 'The "%1$s" has been successfully %2$s.', |
|
| 3457 | + 'The "%1$s" have been successfully %2$s.', |
|
| 3458 | + $success, |
|
| 3459 | + 'event_espresso' |
|
| 3460 | + ) |
|
| 3461 | + ), |
|
| 3462 | + $what, |
|
| 3463 | + $action_desc |
|
| 3464 | + ), |
|
| 3465 | + __FILE__, |
|
| 3466 | + __FUNCTION__, |
|
| 3467 | + __LINE__ |
|
| 3468 | + ); |
|
| 3469 | + } |
|
| 3470 | + // check that $query_args isn't something crazy |
|
| 3471 | + $query_args = is_array($query_args) ? $query_args : []; |
|
| 3472 | + /** |
|
| 3473 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3474 | + * redirections on save and close actions |
|
| 3475 | + * |
|
| 3476 | + * @param array $query_args The original query_args array coming into the |
|
| 3477 | + * method. |
|
| 3478 | + * @since 4.2.0 |
|
| 3479 | + */ |
|
| 3480 | + do_action( |
|
| 3481 | + "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_$this->_req_action", |
|
| 3482 | + $query_args |
|
| 3483 | + ); |
|
| 3484 | + // set redirect url. |
|
| 3485 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3486 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3487 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3488 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3489 | + if ( |
|
| 3490 | + $this->request->requestParamIsSet('save_and_close') |
|
| 3491 | + && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3492 | + ) { |
|
| 3493 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3494 | + $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', DataType::URL)); |
|
| 3495 | + // regenerate query args array from referrer URL |
|
| 3496 | + parse_str($parsed_url['query'], $query_args); |
|
| 3497 | + // correct page and action will be in the query args now |
|
| 3498 | + $redirect_url = admin_url('admin.php'); |
|
| 3499 | + } |
|
| 3500 | + // merge any default query_args set in _default_route_query_args property |
|
| 3501 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3502 | + $args_to_merge = []; |
|
| 3503 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3504 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3505 | + if ($query_param === 'wp_referer') { |
|
| 3506 | + $query_value = (array) $query_value; |
|
| 3507 | + foreach ($query_value as $reference => $value) { |
|
| 3508 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3509 | + continue; |
|
| 3510 | + } |
|
| 3511 | + // finally we will override any arguments in the referer with |
|
| 3512 | + // what might be set on the _default_route_query_args array. |
|
| 3513 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3514 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3515 | + } else { |
|
| 3516 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3517 | + } |
|
| 3518 | + } |
|
| 3519 | + continue; |
|
| 3520 | + } |
|
| 3521 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3522 | + } |
|
| 3523 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3524 | + // redirect. |
|
| 3525 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3526 | + } |
|
| 3527 | + $this->_process_notices($query_args); |
|
| 3528 | + // generate redirect url |
|
| 3529 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3530 | + if (isset($query_args['action'])) { |
|
| 3531 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3532 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3533 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3534 | + } |
|
| 3535 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3536 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3537 | + do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args); |
|
| 3538 | + $redirect_url = apply_filters( |
|
| 3539 | + 'FHEE_redirect_' . $this->class_name . $this->_req_action, |
|
| 3540 | + EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3541 | + $query_args |
|
| 3542 | + ); |
|
| 3543 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3544 | + if ($this->request->isAjax()) { |
|
| 3545 | + $default_data = [ |
|
| 3546 | + 'close' => true, |
|
| 3547 | + 'redirect_url' => $redirect_url, |
|
| 3548 | + 'where' => 'main', |
|
| 3549 | + 'what' => 'append', |
|
| 3550 | + ]; |
|
| 3551 | + $this->_template_args['success'] = $success; |
|
| 3552 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3553 | + $default_data, |
|
| 3554 | + $this->_template_args['data'] |
|
| 3555 | + ) : $default_data; |
|
| 3556 | + $this->_return_json(); |
|
| 3557 | + } |
|
| 3558 | + wp_safe_redirect($redirect_url); |
|
| 3559 | + exit(); |
|
| 3560 | + } |
|
| 3561 | + |
|
| 3562 | + |
|
| 3563 | + /** |
|
| 3564 | + * process any notices before redirecting (or returning ajax request) |
|
| 3565 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3566 | + * |
|
| 3567 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3568 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3569 | + * page_routes haven't been defined yet. |
|
| 3570 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3571 | + * still save a transient for the notice. |
|
| 3572 | + * @return void |
|
| 3573 | + * @throws EE_Error |
|
| 3574 | + * @throws InvalidArgumentException |
|
| 3575 | + * @throws InvalidDataTypeException |
|
| 3576 | + * @throws InvalidInterfaceException |
|
| 3577 | + */ |
|
| 3578 | + protected function _process_notices( |
|
| 3579 | + array $query_args = [], |
|
| 3580 | + bool $skip_route_verify = false, |
|
| 3581 | + bool $sticky_notices = true |
|
| 3582 | + ) { |
|
| 3583 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3584 | + if ($this->request->isAjax()) { |
|
| 3585 | + $notices = EE_Error::get_notices(false); |
|
| 3586 | + if (empty($this->_template_args['success'])) { |
|
| 3587 | + $this->_template_args['success'] = $notices['success'] ?? false; |
|
| 3588 | + } |
|
| 3589 | + if (empty($this->_template_args['errors'])) { |
|
| 3590 | + $this->_template_args['errors'] = $notices['errors'] ?? false; |
|
| 3591 | + } |
|
| 3592 | + if (empty($this->_template_args['attention'])) { |
|
| 3593 | + $this->_template_args['attention'] = $notices['attention'] ?? false; |
|
| 3594 | + } |
|
| 3595 | + } |
|
| 3596 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3597 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3598 | + if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3599 | + $route = $query_args['action'] ?? 'default'; |
|
| 3600 | + $this->_add_transient( |
|
| 3601 | + $route, |
|
| 3602 | + (array) $this->_template_args['notices'], |
|
| 3603 | + true, |
|
| 3604 | + $skip_route_verify |
|
| 3605 | + ); |
|
| 3606 | + } |
|
| 3607 | + } |
|
| 3608 | + |
|
| 3609 | + |
|
| 3610 | + /** |
|
| 3611 | + * get_action_link_or_button |
|
| 3612 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3613 | + * |
|
| 3614 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3615 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3616 | + * property. |
|
| 3617 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3618 | + * @param string $class Use this to give the class for the button. Defaults to 'button--primary' |
|
| 3619 | + * @param string $base_url If this is not provided |
|
| 3620 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3621 | + * Otherwise this value will be used. |
|
| 3622 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3623 | + * @return string |
|
| 3624 | + * @throws InvalidArgumentException |
|
| 3625 | + * @throws InvalidInterfaceException |
|
| 3626 | + * @throws InvalidDataTypeException |
|
| 3627 | + * @throws EE_Error |
|
| 3628 | + */ |
|
| 3629 | + public function get_action_link_or_button( |
|
| 3630 | + string $action, |
|
| 3631 | + string $type = 'add', |
|
| 3632 | + array $extra_request = [], |
|
| 3633 | + string $class = 'button button--primary', |
|
| 3634 | + string $base_url = '', |
|
| 3635 | + bool $exclude_nonce = false |
|
| 3636 | + ): string { |
|
| 3637 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3638 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3639 | + throw new EE_Error( |
|
| 3640 | + sprintf( |
|
| 3641 | + esc_html__( |
|
| 3642 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3643 | + 'event_espresso' |
|
| 3644 | + ), |
|
| 3645 | + $action |
|
| 3646 | + ) |
|
| 3647 | + ); |
|
| 3648 | + } |
|
| 3649 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3650 | + throw new EE_Error( |
|
| 3651 | + sprintf( |
|
| 3652 | + esc_html__( |
|
| 3653 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3654 | + 'event_espresso' |
|
| 3655 | + ), |
|
| 3656 | + $type |
|
| 3657 | + ) |
|
| 3658 | + ); |
|
| 3659 | + } |
|
| 3660 | + // finally check user access for this button. |
|
| 3661 | + $has_access = $this->check_user_access($action, true); |
|
| 3662 | + if (! $has_access) { |
|
| 3663 | + return ''; |
|
| 3664 | + } |
|
| 3665 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3666 | + $query_args = [ |
|
| 3667 | + 'action' => $action, |
|
| 3668 | + ]; |
|
| 3669 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3670 | + if (! empty($extra_request)) { |
|
| 3671 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3672 | + } |
|
| 3673 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3674 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3675 | + } |
|
| 3676 | + |
|
| 3677 | + |
|
| 3678 | + /** |
|
| 3679 | + * _per_page_screen_option |
|
| 3680 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3681 | + * |
|
| 3682 | + * @return void |
|
| 3683 | + * @throws InvalidArgumentException |
|
| 3684 | + * @throws InvalidInterfaceException |
|
| 3685 | + * @throws InvalidDataTypeException |
|
| 3686 | + */ |
|
| 3687 | + protected function _per_page_screen_option() |
|
| 3688 | + { |
|
| 3689 | + $option = 'per_page'; |
|
| 3690 | + $args = [ |
|
| 3691 | + 'label' => apply_filters( |
|
| 3692 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3693 | + $this->_admin_page_title, |
|
| 3694 | + $this |
|
| 3695 | + ), |
|
| 3696 | + 'default' => (int) apply_filters( |
|
| 3697 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3698 | + 20 |
|
| 3699 | + ), |
|
| 3700 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3701 | + ]; |
|
| 3702 | + // ONLY add the screen option if the user has access to it. |
|
| 3703 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3704 | + add_screen_option($option, $args); |
|
| 3705 | + } |
|
| 3706 | + } |
|
| 3707 | + |
|
| 3708 | + |
|
| 3709 | + /** |
|
| 3710 | + * set_per_page_screen_option |
|
| 3711 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3712 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3713 | + * admin_menu. |
|
| 3714 | + * |
|
| 3715 | + * @return void |
|
| 3716 | + */ |
|
| 3717 | + private function _set_per_page_screen_options() |
|
| 3718 | + { |
|
| 3719 | + if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3720 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3721 | + if (! $user = wp_get_current_user()) { |
|
| 3722 | + return; |
|
| 3723 | + } |
|
| 3724 | + $option = $this->request->getRequestParam('wp_screen_options[option]', '', DataType::KEY); |
|
| 3725 | + if (! $option) { |
|
| 3726 | + return; |
|
| 3727 | + } |
|
| 3728 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, DataType::INT); |
|
| 3729 | + $map_option = $option; |
|
| 3730 | + $option = str_replace('-', '_', $option); |
|
| 3731 | + switch ($map_option) { |
|
| 3732 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3733 | + $max_value = apply_filters( |
|
| 3734 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3735 | + 999, |
|
| 3736 | + $this->_current_page, |
|
| 3737 | + $this->_current_view |
|
| 3738 | + ); |
|
| 3739 | + if ($value < 1) { |
|
| 3740 | + return; |
|
| 3741 | + } |
|
| 3742 | + $value = min($value, $max_value); |
|
| 3743 | + break; |
|
| 3744 | + default: |
|
| 3745 | + $value = apply_filters( |
|
| 3746 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3747 | + false, |
|
| 3748 | + $option, |
|
| 3749 | + $value |
|
| 3750 | + ); |
|
| 3751 | + if (false === $value) { |
|
| 3752 | + return; |
|
| 3753 | + } |
|
| 3754 | + break; |
|
| 3755 | + } |
|
| 3756 | + update_user_meta($user->ID, $option, $value); |
|
| 3757 | + wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3758 | + exit; |
|
| 3759 | + } |
|
| 3760 | + } |
|
| 3761 | + |
|
| 3762 | + |
|
| 3763 | + /** |
|
| 3764 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3765 | + * |
|
| 3766 | + * @param array $data array that will be assigned to template args. |
|
| 3767 | + */ |
|
| 3768 | + public function set_template_args(array $data) |
|
| 3769 | + { |
|
| 3770 | + $this->_template_args = array_merge($this->_template_args, $data); |
|
| 3771 | + } |
|
| 3772 | + |
|
| 3773 | + |
|
| 3774 | + public function setAdminPageTitle(string $title) |
|
| 3775 | + { |
|
| 3776 | + $this->_admin_page_title = sanitize_text_field($title); |
|
| 3777 | + } |
|
| 3778 | + |
|
| 3779 | + |
|
| 3780 | + /** |
|
| 3781 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3782 | + * |
|
| 3783 | + * @param string $route the route that should receive the transient |
|
| 3784 | + * @param array $data the data that gets sent |
|
| 3785 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3786 | + * normal route transient. |
|
| 3787 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3788 | + * when we are adding a transient before page_routes have been defined. |
|
| 3789 | + * @return void |
|
| 3790 | + * @throws EE_Error |
|
| 3791 | + */ |
|
| 3792 | + protected function _add_transient( |
|
| 3793 | + string $route, |
|
| 3794 | + array $data, |
|
| 3795 | + bool $notices = false, |
|
| 3796 | + bool $skip_route_verify = false |
|
| 3797 | + ) { |
|
| 3798 | + $user_id = get_current_user_id(); |
|
| 3799 | + if (! $skip_route_verify) { |
|
| 3800 | + $this->_verify_route($route); |
|
| 3801 | + } |
|
| 3802 | + // now let's set the string for what kind of transient we're setting |
|
| 3803 | + $transient = $notices ? "ee_rte_n_tx_{$route}_$user_id" : "rte_tx_{$route}_$user_id"; |
|
| 3804 | + $data = $notices ? ['notices' => $data] : $data; |
|
| 3805 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3806 | + $existing = is_multisite() && is_network_admin() |
|
| 3807 | + ? get_site_transient($transient) |
|
| 3808 | + : get_transient($transient); |
|
| 3809 | + if ($existing) { |
|
| 3810 | + $data = array_merge($data, (array) $existing); |
|
| 3811 | + } |
|
| 3812 | + if (is_multisite() && is_network_admin()) { |
|
| 3813 | + set_site_transient($transient, $data, 8); |
|
| 3814 | + } else { |
|
| 3815 | + set_transient($transient, $data, 8); |
|
| 3816 | + } |
|
| 3817 | + } |
|
| 3818 | + |
|
| 3819 | + |
|
| 3820 | + /** |
|
| 3821 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3822 | + * |
|
| 3823 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3824 | + * @param string $route |
|
| 3825 | + * @return mixed data |
|
| 3826 | + */ |
|
| 3827 | + protected function _get_transient(bool $notices = false, string $route = '') |
|
| 3828 | + { |
|
| 3829 | + $user_id = get_current_user_id(); |
|
| 3830 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3831 | + $transient = $notices |
|
| 3832 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3833 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3834 | + $data = is_multisite() && is_network_admin() |
|
| 3835 | + ? get_site_transient($transient) |
|
| 3836 | + : get_transient($transient); |
|
| 3837 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3838 | + if (is_multisite() && is_network_admin()) { |
|
| 3839 | + delete_site_transient($transient); |
|
| 3840 | + } else { |
|
| 3841 | + delete_transient($transient); |
|
| 3842 | + } |
|
| 3843 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3844 | + } |
|
| 3845 | + |
|
| 3846 | + |
|
| 3847 | + /** |
|
| 3848 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3849 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3850 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3851 | + * |
|
| 3852 | + * @return void |
|
| 3853 | + */ |
|
| 3854 | + protected function _transient_garbage_collection() |
|
| 3855 | + { |
|
| 3856 | + global $wpdb; |
|
| 3857 | + // retrieve all existing transients |
|
| 3858 | + $query = |
|
| 3859 | + "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3860 | + if ($results = $wpdb->get_results($query)) { |
|
| 3861 | + foreach ($results as $result) { |
|
| 3862 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3863 | + get_transient($transient); |
|
| 3864 | + if (is_multisite() && is_network_admin()) { |
|
| 3865 | + get_site_transient($transient); |
|
| 3866 | + } |
|
| 3867 | + } |
|
| 3868 | + } |
|
| 3869 | + } |
|
| 3870 | + |
|
| 3871 | + |
|
| 3872 | + /** |
|
| 3873 | + * get_view |
|
| 3874 | + * |
|
| 3875 | + * @return string content of _view property |
|
| 3876 | + */ |
|
| 3877 | + public function get_view(): string |
|
| 3878 | + { |
|
| 3879 | + return $this->_view; |
|
| 3880 | + } |
|
| 3881 | + |
|
| 3882 | + |
|
| 3883 | + /** |
|
| 3884 | + * getter for the protected $_views property |
|
| 3885 | + * |
|
| 3886 | + * @return array |
|
| 3887 | + */ |
|
| 3888 | + public function get_views(): array |
|
| 3889 | + { |
|
| 3890 | + return $this->_views; |
|
| 3891 | + } |
|
| 3892 | + |
|
| 3893 | + |
|
| 3894 | + /** |
|
| 3895 | + * @param array $views |
|
| 3896 | + * @return void |
|
| 3897 | + * @since 5.0.13.p |
|
| 3898 | + */ |
|
| 3899 | + public function updateViews(array $views) |
|
| 3900 | + { |
|
| 3901 | + $this->_views = array_merge($this->_views, $views); |
|
| 3902 | + } |
|
| 3903 | + |
|
| 3904 | + |
|
| 3905 | + /** |
|
| 3906 | + /** |
|
| 3907 | + * get_current_page |
|
| 3908 | + * |
|
| 3909 | + * @return string _current_page property value |
|
| 3910 | + */ |
|
| 3911 | + public function get_current_page(): string |
|
| 3912 | + { |
|
| 3913 | + return $this->_current_page; |
|
| 3914 | + } |
|
| 3915 | + |
|
| 3916 | + |
|
| 3917 | + /** |
|
| 3918 | + * get_current_view |
|
| 3919 | + * |
|
| 3920 | + * @return string _current_view property value |
|
| 3921 | + */ |
|
| 3922 | + public function get_current_view(): string |
|
| 3923 | + { |
|
| 3924 | + return $this->_current_view; |
|
| 3925 | + } |
|
| 3926 | + |
|
| 3927 | + |
|
| 3928 | + /** |
|
| 3929 | + * get_current_screen |
|
| 3930 | + * |
|
| 3931 | + * @return object The current WP_Screen object |
|
| 3932 | + */ |
|
| 3933 | + public function get_current_screen() |
|
| 3934 | + { |
|
| 3935 | + return $this->_current_screen; |
|
| 3936 | + } |
|
| 3937 | + |
|
| 3938 | + |
|
| 3939 | + /** |
|
| 3940 | + * get_current_page_view_url |
|
| 3941 | + * |
|
| 3942 | + * @return string This returns the url for the current_page_view. |
|
| 3943 | + */ |
|
| 3944 | + public function get_current_page_view_url(): string |
|
| 3945 | + { |
|
| 3946 | + return $this->_current_page_view_url; |
|
| 3947 | + } |
|
| 3948 | + |
|
| 3949 | + |
|
| 3950 | + /** |
|
| 3951 | + * just returns the Request |
|
| 3952 | + * |
|
| 3953 | + * @return RequestInterface |
|
| 3954 | + */ |
|
| 3955 | + public function get_request(): ?RequestInterface |
|
| 3956 | + { |
|
| 3957 | + return $this->request; |
|
| 3958 | + } |
|
| 3959 | + |
|
| 3960 | + |
|
| 3961 | + /** |
|
| 3962 | + * just returns the _req_data property |
|
| 3963 | + * |
|
| 3964 | + * @return array |
|
| 3965 | + */ |
|
| 3966 | + public function get_request_data(): array |
|
| 3967 | + { |
|
| 3968 | + return $this->request->requestParams(); |
|
| 3969 | + } |
|
| 3970 | + |
|
| 3971 | + |
|
| 3972 | + /** |
|
| 3973 | + * returns the _req_data protected property |
|
| 3974 | + * |
|
| 3975 | + * @return string |
|
| 3976 | + */ |
|
| 3977 | + public function get_req_action(): string |
|
| 3978 | + { |
|
| 3979 | + return $this->_req_action; |
|
| 3980 | + } |
|
| 3981 | + |
|
| 3982 | + |
|
| 3983 | + /** |
|
| 3984 | + * @return bool value of $_is_caf property |
|
| 3985 | + */ |
|
| 3986 | + public function is_caf(): bool |
|
| 3987 | + { |
|
| 3988 | + return $this->_is_caf; |
|
| 3989 | + } |
|
| 3990 | + |
|
| 3991 | + |
|
| 3992 | + /** |
|
| 3993 | + * @return array |
|
| 3994 | + */ |
|
| 3995 | + public function default_espresso_metaboxes(): array |
|
| 3996 | + { |
|
| 3997 | + return $this->_default_espresso_metaboxes; |
|
| 3998 | + } |
|
| 3999 | + |
|
| 4000 | + |
|
| 4001 | + /** |
|
| 4002 | + * @return string |
|
| 4003 | + */ |
|
| 4004 | + public function admin_base_url(): string |
|
| 4005 | + { |
|
| 4006 | + return $this->_admin_base_url; |
|
| 4007 | + } |
|
| 4008 | + |
|
| 4009 | + |
|
| 4010 | + /** |
|
| 4011 | + * @return string |
|
| 4012 | + */ |
|
| 4013 | + public function wp_page_slug(): string |
|
| 4014 | + { |
|
| 4015 | + return $this->_wp_page_slug; |
|
| 4016 | + } |
|
| 4017 | + |
|
| 4018 | + |
|
| 4019 | + /** |
|
| 4020 | + * updates espresso configuration settings |
|
| 4021 | + * |
|
| 4022 | + * @param string $tab |
|
| 4023 | + * @param EE_Config_Base|EE_Config $config |
|
| 4024 | + * @param string $file file where error occurred |
|
| 4025 | + * @param string $func function where error occurred |
|
| 4026 | + * @param string $line line no where error occurred |
|
| 4027 | + * @return bool |
|
| 4028 | + */ |
|
| 4029 | + protected function _update_espresso_configuration( |
|
| 4030 | + string $tab, |
|
| 4031 | + $config, |
|
| 4032 | + string $file = '', |
|
| 4033 | + string $func = '', |
|
| 4034 | + string $line = '' |
|
| 4035 | + ): bool { |
|
| 4036 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 4037 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4038 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4039 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4040 | + update_option('ee_ueip_has_notified', true); |
|
| 4041 | + } |
|
| 4042 | + // and save it (note we're also doing the network save here) |
|
| 4043 | + $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 4044 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4045 | + if ($config_saved && $net_saved) { |
|
| 4046 | + EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4047 | + return true; |
|
| 4048 | + } |
|
| 4049 | + EE_Error::add_error( |
|
| 4050 | + sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), |
|
| 4051 | + $file, |
|
| 4052 | + $func, |
|
| 4053 | + $line |
|
| 4054 | + ); |
|
| 4055 | + return false; |
|
| 4056 | + } |
|
| 4057 | + |
|
| 4058 | + |
|
| 4059 | + /** |
|
| 4060 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4061 | + * |
|
| 4062 | + * @return array |
|
| 4063 | + */ |
|
| 4064 | + public function get_yes_no_values(): array |
|
| 4065 | + { |
|
| 4066 | + return $this->_yes_no_values; |
|
| 4067 | + } |
|
| 4068 | + |
|
| 4069 | + |
|
| 4070 | + /** |
|
| 4071 | + * @return string |
|
| 4072 | + * @throws ReflectionException |
|
| 4073 | + * @since 5.0.0.p |
|
| 4074 | + */ |
|
| 4075 | + protected function _get_dir(): string |
|
| 4076 | + { |
|
| 4077 | + $reflector = new ReflectionClass($this->class_name); |
|
| 4078 | + return dirname($reflector->getFileName()); |
|
| 4079 | + } |
|
| 4080 | + |
|
| 4081 | + |
|
| 4082 | + /** |
|
| 4083 | + * A helper for getting a "next link". |
|
| 4084 | + * |
|
| 4085 | + * @param string $url The url to link to |
|
| 4086 | + * @param string $class The class to use. |
|
| 4087 | + * @return string |
|
| 4088 | + */ |
|
| 4089 | + protected function _next_link(string $url, string $class = 'dashicons dashicons-arrow-right'): string |
|
| 4090 | + { |
|
| 4091 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4092 | + } |
|
| 4093 | + |
|
| 4094 | + |
|
| 4095 | + /** |
|
| 4096 | + * A helper for getting a "previous link". |
|
| 4097 | + * |
|
| 4098 | + * @param string $url The url to link to |
|
| 4099 | + * @param string $class The class to use. |
|
| 4100 | + * @return string |
|
| 4101 | + */ |
|
| 4102 | + protected function _previous_link(string $url, string $class = 'dashicons dashicons-arrow-left'): string |
|
| 4103 | + { |
|
| 4104 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4105 | + } |
|
| 4106 | + |
|
| 4107 | + |
|
| 4108 | + |
|
| 4109 | + |
|
| 4110 | + |
|
| 4111 | + |
|
| 4112 | + |
|
| 4113 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4114 | + |
|
| 4115 | + |
|
| 4116 | + /** |
|
| 4117 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4118 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4119 | + * _req_data array. |
|
| 4120 | + * |
|
| 4121 | + * @return bool success/fail |
|
| 4122 | + * @throws EE_Error |
|
| 4123 | + * @throws InvalidArgumentException |
|
| 4124 | + * @throws ReflectionException |
|
| 4125 | + * @throws InvalidDataTypeException |
|
| 4126 | + * @throws InvalidInterfaceException |
|
| 4127 | + */ |
|
| 4128 | + protected function _process_resend_registration(): bool |
|
| 4129 | + { |
|
| 4130 | + $this->_template_args['success'] = EED_Messages::process_resend($this->request->requestParams()); |
|
| 4131 | + do_action( |
|
| 4132 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4133 | + $this->_template_args['success'], |
|
| 4134 | + $this->request->requestParams() |
|
| 4135 | + ); |
|
| 4136 | + return $this->_template_args['success']; |
|
| 4137 | + } |
|
| 4138 | + |
|
| 4139 | + |
|
| 4140 | + /** |
|
| 4141 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4142 | + * |
|
| 4143 | + * @param EE_Payment $payment |
|
| 4144 | + * @return bool success/fail |
|
| 4145 | + */ |
|
| 4146 | + protected function _process_payment_notification(EE_Payment $payment): bool |
|
| 4147 | + { |
|
| 4148 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4149 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4150 | + $this->_template_args['success'] = apply_filters( |
|
| 4151 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4152 | + false, |
|
| 4153 | + $payment |
|
| 4154 | + ); |
|
| 4155 | + return $this->_template_args['success']; |
|
| 4156 | + } |
|
| 4157 | + |
|
| 4158 | + |
|
| 4159 | + /** |
|
| 4160 | + * @param EEM_Base $entity_model |
|
| 4161 | + * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
| 4162 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4163 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4164 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4165 | + * @return int|float |
|
| 4166 | + * @throws EE_Error |
|
| 4167 | + */ |
|
| 4168 | + protected function trashRestoreDeleteEntities( |
|
| 4169 | + EEM_Base $entity_model, |
|
| 4170 | + string $entity_PK_name, |
|
| 4171 | + string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
| 4172 | + string $delete_column = '', |
|
| 4173 | + ?callable $callback = null |
|
| 4174 | + ) { |
|
| 4175 | + $entity_PK = $entity_model->get_primary_key_field(); |
|
| 4176 | + $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
| 4177 | + $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
| 4178 | + // grab ID if deleting a single entity |
|
| 4179 | + if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
| 4180 | + $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
| 4181 | + return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
| 4182 | + } |
|
| 4183 | + // or grab checkbox array if bulk deleting |
|
| 4184 | + $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
| 4185 | + if (empty($checkboxes)) { |
|
| 4186 | + return 0; |
|
| 4187 | + } |
|
| 4188 | + $success = 0; |
|
| 4189 | + $IDs = array_keys($checkboxes); |
|
| 4190 | + // cycle thru bulk action checkboxes |
|
| 4191 | + foreach ($IDs as $ID) { |
|
| 4192 | + // increment $success |
|
| 4193 | + if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
| 4194 | + $success++; |
|
| 4195 | + } |
|
| 4196 | + } |
|
| 4197 | + $count = (int) count($checkboxes); |
|
| 4198 | + // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
| 4199 | + // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
| 4200 | + return $success === $count ? $count : $success / $count; |
|
| 4201 | + } |
|
| 4202 | + |
|
| 4203 | + |
|
| 4204 | + /** |
|
| 4205 | + * @param EE_Primary_Key_Field_Base $entity_PK |
|
| 4206 | + * @return string |
|
| 4207 | + * @throws EE_Error |
|
| 4208 | + * @since 4.10.30.p |
|
| 4209 | + */ |
|
| 4210 | + private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
| 4211 | + { |
|
| 4212 | + $entity_PK_type = $entity_PK->getSchemaType(); |
|
| 4213 | + switch ($entity_PK_type) { |
|
| 4214 | + case 'boolean': |
|
| 4215 | + return DataType::BOOL; |
|
| 4216 | + case 'integer': |
|
| 4217 | + return DataType::INT; |
|
| 4218 | + case 'number': |
|
| 4219 | + return DataType::FLOAT; |
|
| 4220 | + case 'string': |
|
| 4221 | + return DataType::STRING; |
|
| 4222 | + } |
|
| 4223 | + throw new RuntimeException( |
|
| 4224 | + sprintf( |
|
| 4225 | + esc_html__( |
|
| 4226 | + '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
| 4227 | + 'event_espresso' |
|
| 4228 | + ), |
|
| 4229 | + $entity_PK_type, |
|
| 4230 | + $entity_PK->get_name() |
|
| 4231 | + ) |
|
| 4232 | + ); |
|
| 4233 | + } |
|
| 4234 | + |
|
| 4235 | + |
|
| 4236 | + /** |
|
| 4237 | + * @param EEM_Base $entity_model |
|
| 4238 | + * @param int|string $entity_ID |
|
| 4239 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4240 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4241 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4242 | + * @return bool |
|
| 4243 | + */ |
|
| 4244 | + protected function trashRestoreDeleteEntity( |
|
| 4245 | + EEM_Base $entity_model, |
|
| 4246 | + $entity_ID, |
|
| 4247 | + string $action, |
|
| 4248 | + string $delete_column, |
|
| 4249 | + ?callable $callback = null |
|
| 4250 | + ): bool { |
|
| 4251 | + $entity_ID = absint($entity_ID); |
|
| 4252 | + if (! $entity_ID) { |
|
| 4253 | + $this->trashRestoreDeleteError($action, $entity_model); |
|
| 4254 | + } |
|
| 4255 | + $result = 0; |
|
| 4256 | + try { |
|
| 4257 | + $entity = $entity_model->get_one_by_ID($entity_ID); |
|
| 4258 | + if (! $entity instanceof EE_Base_Class) { |
|
| 4259 | + throw new DomainException( |
|
| 4260 | + sprintf( |
|
| 4261 | + esc_html__( |
|
| 4262 | + 'Missing or invalid %1$s entity with ID of "%2$s" returned from db.', |
|
| 4263 | + 'event_espresso' |
|
| 4264 | + ), |
|
| 4265 | + str_replace('EEM_', '', $entity_model->get_this_model_name()), |
|
| 4266 | + $entity_ID |
|
| 4267 | + ) |
|
| 4268 | + ); |
|
| 4269 | + } |
|
| 4270 | + switch ($action) { |
|
| 4271 | + case EE_Admin_List_Table::ACTION_DELETE: |
|
| 4272 | + $result = (bool) $entity->delete_permanently(); |
|
| 4273 | + break; |
|
| 4274 | + case EE_Admin_List_Table::ACTION_RESTORE: |
|
| 4275 | + $result = $entity->delete_or_restore(false); |
|
| 4276 | + break; |
|
| 4277 | + case EE_Admin_List_Table::ACTION_TRASH: |
|
| 4278 | + $result = $entity->delete_or_restore(); |
|
| 4279 | + break; |
|
| 4280 | + } |
|
| 4281 | + } catch (Exception $exception) { |
|
| 4282 | + $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
| 4283 | + } |
|
| 4284 | + if (is_callable($callback)) { |
|
| 4285 | + call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
| 4286 | + } |
|
| 4287 | + return $result; |
|
| 4288 | + } |
|
| 4289 | + |
|
| 4290 | + |
|
| 4291 | + /** |
|
| 4292 | + * @param EEM_Base $entity_model |
|
| 4293 | + * @param string $delete_column |
|
| 4294 | + * @since 4.10.30.p |
|
| 4295 | + */ |
|
| 4296 | + private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
| 4297 | + { |
|
| 4298 | + if (empty($delete_column)) { |
|
| 4299 | + throw new DomainException( |
|
| 4300 | + sprintf( |
|
| 4301 | + esc_html__( |
|
| 4302 | + 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
| 4303 | + 'event_espresso' |
|
| 4304 | + ), |
|
| 4305 | + $entity_model->get_this_model_name() |
|
| 4306 | + ) |
|
| 4307 | + ); |
|
| 4308 | + } |
|
| 4309 | + if (! $entity_model->has_field($delete_column)) { |
|
| 4310 | + throw new DomainException( |
|
| 4311 | + sprintf( |
|
| 4312 | + esc_html__( |
|
| 4313 | + 'The %1$s field does not exist on the %2$s model.', |
|
| 4314 | + 'event_espresso' |
|
| 4315 | + ), |
|
| 4316 | + $delete_column, |
|
| 4317 | + $entity_model->get_this_model_name() |
|
| 4318 | + ) |
|
| 4319 | + ); |
|
| 4320 | + } |
|
| 4321 | + } |
|
| 4322 | + |
|
| 4323 | + |
|
| 4324 | + /** |
|
| 4325 | + * @param EEM_Base $entity_model |
|
| 4326 | + * @param Exception|null $exception |
|
| 4327 | + * @param string $action |
|
| 4328 | + * @since 4.10.30.p |
|
| 4329 | + */ |
|
| 4330 | + private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, Exception $exception = null) |
|
| 4331 | + { |
|
| 4332 | + if ($exception instanceof Exception) { |
|
| 4333 | + throw new RuntimeException( |
|
| 4334 | + sprintf( |
|
| 4335 | + esc_html__( |
|
| 4336 | + 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
| 4337 | + 'event_espresso' |
|
| 4338 | + ), |
|
| 4339 | + $action, |
|
| 4340 | + $entity_model->get_this_model_name(), |
|
| 4341 | + $exception->getMessage() |
|
| 4342 | + ) |
|
| 4343 | + ); |
|
| 4344 | + } |
|
| 4345 | + throw new RuntimeException( |
|
| 4346 | + sprintf( |
|
| 4347 | + esc_html__( |
|
| 4348 | + 'Could not %1$s the %2$s because an invalid ID was received.', |
|
| 4349 | + 'event_espresso' |
|
| 4350 | + ), |
|
| 4351 | + $action, |
|
| 4352 | + $entity_model->get_this_model_name() |
|
| 4353 | + ) |
|
| 4354 | + ); |
|
| 4355 | + } |
|
| 4356 | 4356 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | protected ?bool $_is_UI_request = null; |
| 104 | 104 | |
| 105 | - protected bool $_is_caf = false; // This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 105 | + protected bool $_is_caf = false; // This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 106 | 106 | |
| 107 | 107 | protected bool $_routing = false; |
| 108 | 108 | |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 598 | 598 | if ( |
| 599 | 599 | ! $this->request->isAjax() |
| 600 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 600 | + && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) |
|
| 601 | 601 | ) { |
| 602 | 602 | return; |
| 603 | 603 | } |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | ? $route |
| 617 | 617 | : $req_action; |
| 618 | 618 | $this->_current_view = $this->_req_action; |
| 619 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 619 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 620 | 620 | $this->_define_page_props(); |
| 621 | 621 | $this->_current_page_view_url = add_query_arg( |
| 622 | 622 | ['page' => $this->_current_page, 'action' => $this->_current_view], |
@@ -640,33 +640,33 @@ discard block |
||
| 640 | 640 | } |
| 641 | 641 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 642 | 642 | $this->_page_routes = apply_filters( |
| 643 | - 'FHEE__' . $this->class_name . '__page_setup__page_routes', |
|
| 643 | + 'FHEE__'.$this->class_name.'__page_setup__page_routes', |
|
| 644 | 644 | $this->_page_routes, |
| 645 | 645 | $this |
| 646 | 646 | ); |
| 647 | 647 | $this->_page_config = apply_filters( |
| 648 | - 'FHEE__' . $this->class_name . '__page_setup__page_config', |
|
| 648 | + 'FHEE__'.$this->class_name.'__page_setup__page_config', |
|
| 649 | 649 | $this->_page_config, |
| 650 | 650 | $this |
| 651 | 651 | ); |
| 652 | 652 | if ($this->base_class_name !== '') { |
| 653 | 653 | $this->_page_routes = apply_filters( |
| 654 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_routes', |
|
| 654 | + 'FHEE__'.$this->base_class_name.'__page_setup__page_routes', |
|
| 655 | 655 | $this->_page_routes, |
| 656 | 656 | $this |
| 657 | 657 | ); |
| 658 | 658 | $this->_page_config = apply_filters( |
| 659 | - 'FHEE__' . $this->base_class_name . '__page_setup__page_config', |
|
| 659 | + 'FHEE__'.$this->base_class_name.'__page_setup__page_config', |
|
| 660 | 660 | $this->_page_config, |
| 661 | 661 | $this |
| 662 | 662 | ); |
| 663 | 663 | } |
| 664 | 664 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 665 | 665 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 666 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 666 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 667 | 667 | add_action( |
| 668 | 668 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 669 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 669 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view], |
|
| 670 | 670 | 10, |
| 671 | 671 | 2 |
| 672 | 672 | ); |
@@ -679,8 +679,8 @@ discard block |
||
| 679 | 679 | if ($this->_is_UI_request) { |
| 680 | 680 | // admin_init stuff - global, all views for this page class, specific view |
| 681 | 681 | add_action('admin_init', [$this, 'admin_init']); |
| 682 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 683 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 682 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 683 | + add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15); |
|
| 684 | 684 | } |
| 685 | 685 | } else { |
| 686 | 686 | // hijack regular WP loading and route admin request immediately |
@@ -699,12 +699,12 @@ discard block |
||
| 699 | 699 | */ |
| 700 | 700 | private function _do_other_page_hooks() |
| 701 | 701 | { |
| 702 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 702 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []); |
|
| 703 | 703 | foreach ($registered_pages as $page) { |
| 704 | 704 | // now let's setup the file name and class that should be present |
| 705 | 705 | $classname = str_replace('.class.php', '', $page); |
| 706 | 706 | // autoloaders should take care of loading file |
| 707 | - if (! class_exists($classname)) { |
|
| 707 | + if ( ! class_exists($classname)) { |
|
| 708 | 708 | $error_msg[] = sprintf( |
| 709 | 709 | esc_html__( |
| 710 | 710 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | ), |
| 722 | 722 | $page, |
| 723 | 723 | '<br />', |
| 724 | - '<strong>' . $classname . '</strong>' |
|
| 724 | + '<strong>'.$classname.'</strong>' |
|
| 725 | 725 | ); |
| 726 | 726 | throw new EE_Error(implode('||', $error_msg)); |
| 727 | 727 | } |
@@ -770,13 +770,13 @@ discard block |
||
| 770 | 770 | // load admin_notices - global, page class, and view specific |
| 771 | 771 | add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
| 772 | 772 | add_action('admin_notices', [$this, 'admin_notices']); |
| 773 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 774 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 773 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 774 | + add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15); |
|
| 775 | 775 | } |
| 776 | 776 | // load network admin_notices - global, page class, and view specific |
| 777 | 777 | add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
| 778 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 779 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 778 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 779 | + add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]); |
|
| 780 | 780 | } |
| 781 | 781 | // this will save any per_page screen options if they are present |
| 782 | 782 | $this->_set_per_page_screen_options(); |
@@ -902,7 +902,7 @@ discard block |
||
| 902 | 902 | */ |
| 903 | 903 | protected function _verify_routes(): bool |
| 904 | 904 | { |
| 905 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 905 | + if ( ! $this->_current_page && ! $this->request->isAjax()) { |
|
| 906 | 906 | return false; |
| 907 | 907 | } |
| 908 | 908 | // check that the page_routes array is not empty |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | $this->_admin_page_title |
| 914 | 914 | ); |
| 915 | 915 | // developer error msg |
| 916 | - $error_msg .= '||' . $error_msg |
|
| 916 | + $error_msg .= '||'.$error_msg |
|
| 917 | 917 | . esc_html__( |
| 918 | 918 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 919 | 919 | 'event_espresso' |
@@ -931,8 +931,8 @@ discard block |
||
| 931 | 931 | } |
| 932 | 932 | // and that the requested page route exists |
| 933 | 933 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 934 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 935 | - $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 934 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 935 | + $this->_route_config = $this->_page_config[$this->_req_action] ?? []; |
|
| 936 | 936 | } else { |
| 937 | 937 | // user error msg |
| 938 | 938 | $error_msg = sprintf( |
@@ -943,7 +943,7 @@ discard block |
||
| 943 | 943 | $this->_admin_page_title |
| 944 | 944 | ); |
| 945 | 945 | // developer error msg |
| 946 | - $error_msg .= '||' . $error_msg |
|
| 946 | + $error_msg .= '||'.$error_msg |
|
| 947 | 947 | . sprintf( |
| 948 | 948 | esc_html__( |
| 949 | 949 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | throw new EE_Error($error_msg); |
| 955 | 955 | } |
| 956 | 956 | // and that a default route exists |
| 957 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 957 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 958 | 958 | // user error msg |
| 959 | 959 | $error_msg = sprintf( |
| 960 | 960 | esc_html__( |
@@ -964,7 +964,7 @@ discard block |
||
| 964 | 964 | $this->_admin_page_title |
| 965 | 965 | ); |
| 966 | 966 | // developer error msg |
| 967 | - $error_msg .= '||' . $error_msg |
|
| 967 | + $error_msg .= '||'.$error_msg |
|
| 968 | 968 | . esc_html__( |
| 969 | 969 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 970 | 970 | 'event_espresso' |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | $this->_admin_page_title |
| 1005 | 1005 | ); |
| 1006 | 1006 | // developer error msg |
| 1007 | - $error_msg .= '||' . $error_msg |
|
| 1007 | + $error_msg .= '||'.$error_msg |
|
| 1008 | 1008 | . sprintf( |
| 1009 | 1009 | esc_html__( |
| 1010 | 1010 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -1032,7 +1032,7 @@ discard block |
||
| 1032 | 1032 | protected function _verify_nonce(string $nonce, string $nonce_ref) |
| 1033 | 1033 | { |
| 1034 | 1034 | // verify nonce against expected value |
| 1035 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1035 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1036 | 1036 | // these are not the droids you are looking for !!! |
| 1037 | 1037 | $msg = sprintf( |
| 1038 | 1038 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -1049,7 +1049,7 @@ discard block |
||
| 1049 | 1049 | __CLASS__ |
| 1050 | 1050 | ); |
| 1051 | 1051 | } |
| 1052 | - if (! $this->request->isAjax()) { |
|
| 1052 | + if ( ! $this->request->isAjax()) { |
|
| 1053 | 1053 | wp_die($msg); |
| 1054 | 1054 | } |
| 1055 | 1055 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -1074,7 +1074,7 @@ discard block |
||
| 1074 | 1074 | */ |
| 1075 | 1075 | protected function _route_admin_request() |
| 1076 | 1076 | { |
| 1077 | - if (! $this->_is_UI_request) { |
|
| 1077 | + if ( ! $this->_is_UI_request) { |
|
| 1078 | 1078 | $this->_verify_routes(); |
| 1079 | 1079 | } |
| 1080 | 1080 | $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | |
| 1095 | 1095 | // action right before calling route |
| 1096 | 1096 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 1097 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1097 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1098 | 1098 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 1099 | 1099 | } |
| 1100 | 1100 | // strip _wp_http_referer from the server REQUEST_URI |
@@ -1109,7 +1109,7 @@ discard block |
||
| 1109 | 1109 | $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri, true); |
| 1110 | 1110 | $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri, true); |
| 1111 | 1111 | $route_callback = []; |
| 1112 | - if (! empty($func)) { |
|
| 1112 | + if ( ! empty($func)) { |
|
| 1113 | 1113 | if (is_array($func) && is_callable($func)) { |
| 1114 | 1114 | $route_callback = $func; |
| 1115 | 1115 | } elseif (is_string($func)) { |
@@ -1123,7 +1123,7 @@ discard block |
||
| 1123 | 1123 | } |
| 1124 | 1124 | [$class, $method] = $route_callback; |
| 1125 | 1125 | // is it neither a class method NOR a standalone function? |
| 1126 | - if (! is_callable($route_callback)) { |
|
| 1126 | + if ( ! is_callable($route_callback)) { |
|
| 1127 | 1127 | // user error msg |
| 1128 | 1128 | $error_msg = esc_html__( |
| 1129 | 1129 | 'An error occurred. The requested page route could not be found.', |
@@ -1150,7 +1150,7 @@ discard block |
||
| 1150 | 1150 | } catch (Throwable $throwable) { |
| 1151 | 1151 | $nice_args = []; |
| 1152 | 1152 | foreach ($args as $key => $arg) { |
| 1153 | - $nice_args[ $key ] = is_object($arg) ? get_class($arg) : $key; |
|
| 1153 | + $nice_args[$key] = is_object($arg) ? get_class($arg) : $key; |
|
| 1154 | 1154 | } |
| 1155 | 1155 | new ExceptionStackTraceDisplay( |
| 1156 | 1156 | new RuntimeException( |
@@ -1254,7 +1254,7 @@ discard block |
||
| 1254 | 1254 | if (strpos($key, 'nonce') !== false) { |
| 1255 | 1255 | continue; |
| 1256 | 1256 | } |
| 1257 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1257 | + $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1258 | 1258 | } |
| 1259 | 1259 | } |
| 1260 | 1260 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce, $context); |
@@ -1294,12 +1294,12 @@ discard block |
||
| 1294 | 1294 | */ |
| 1295 | 1295 | protected function _add_help_tabs() |
| 1296 | 1296 | { |
| 1297 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1298 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1297 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1298 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1299 | 1299 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1300 | 1300 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1301 | 1301 | // check that the callback given is valid |
| 1302 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1302 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1303 | 1303 | throw new EE_Error( |
| 1304 | 1304 | sprintf( |
| 1305 | 1305 | esc_html__( |
@@ -1312,18 +1312,18 @@ discard block |
||
| 1312 | 1312 | ); |
| 1313 | 1313 | } |
| 1314 | 1314 | $content = apply_filters( |
| 1315 | - 'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar', |
|
| 1315 | + 'FHEE__'.$this->class_name.'__add_help_tabs__help_sidebar', |
|
| 1316 | 1316 | $this->{$config['help_sidebar']}() |
| 1317 | 1317 | ); |
| 1318 | 1318 | $this->_current_screen->set_help_sidebar($content); |
| 1319 | 1319 | } |
| 1320 | - if (! isset($config['help_tabs'])) { |
|
| 1320 | + if ( ! isset($config['help_tabs'])) { |
|
| 1321 | 1321 | return; |
| 1322 | 1322 | } //no help tabs for this route |
| 1323 | 1323 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1324 | 1324 | // we're here so there ARE help tabs! |
| 1325 | 1325 | // make sure we've got what we need |
| 1326 | - if (! isset($cfg['title'])) { |
|
| 1326 | + if ( ! isset($cfg['title'])) { |
|
| 1327 | 1327 | throw new EE_Error( |
| 1328 | 1328 | esc_html__( |
| 1329 | 1329 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | ) |
| 1332 | 1332 | ); |
| 1333 | 1333 | } |
| 1334 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1334 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1335 | 1335 | throw new EE_Error( |
| 1336 | 1336 | esc_html__( |
| 1337 | 1337 | 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
@@ -1340,11 +1340,11 @@ discard block |
||
| 1340 | 1340 | ); |
| 1341 | 1341 | } |
| 1342 | 1342 | // first priority goes to content. |
| 1343 | - if (! empty($cfg['content'])) { |
|
| 1343 | + if ( ! empty($cfg['content'])) { |
|
| 1344 | 1344 | $content = $cfg['content']; |
| 1345 | 1345 | // second priority goes to filename |
| 1346 | - } elseif (! empty($cfg['filename'])) { |
|
| 1347 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1346 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1347 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1348 | 1348 | // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
| 1349 | 1349 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1350 | 1350 | . basename($this->_get_dir()) |
@@ -1352,7 +1352,7 @@ discard block |
||
| 1352 | 1352 | . $cfg['filename'] |
| 1353 | 1353 | . '.help_tab.php' : $file_path; |
| 1354 | 1354 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1355 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1355 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1356 | 1356 | EE_Error::add_error( |
| 1357 | 1357 | sprintf( |
| 1358 | 1358 | esc_html__( |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | return; |
| 1401 | 1401 | } |
| 1402 | 1402 | // setup config array for help tab method |
| 1403 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1403 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1404 | 1404 | $_ht = [ |
| 1405 | 1405 | 'id' => $id, |
| 1406 | 1406 | 'title' => $cfg['title'], |
@@ -1426,8 +1426,8 @@ discard block |
||
| 1426 | 1426 | $qtips = (array) $this->_route_config['qtips']; |
| 1427 | 1427 | // load qtip loader |
| 1428 | 1428 | $path = [ |
| 1429 | - $this->_get_dir() . '/qtips/', |
|
| 1430 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1429 | + $this->_get_dir().'/qtips/', |
|
| 1430 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1431 | 1431 | ]; |
| 1432 | 1432 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1433 | 1433 | } |
@@ -1449,7 +1449,7 @@ discard block |
||
| 1449 | 1449 | $i = 0; |
| 1450 | 1450 | $only_tab = count($this->_page_config) < 2; |
| 1451 | 1451 | foreach ($this->_page_config as $slug => $config) { |
| 1452 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1452 | + if ( ! is_array($config) || empty($config['nav'])) { |
|
| 1453 | 1453 | continue; |
| 1454 | 1454 | } |
| 1455 | 1455 | // no nav tab for this config |
@@ -1458,7 +1458,7 @@ discard block |
||
| 1458 | 1458 | // nav tab is only to appear when route requested. |
| 1459 | 1459 | continue; |
| 1460 | 1460 | } |
| 1461 | - if (! $this->check_user_access($slug, true)) { |
|
| 1461 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1462 | 1462 | // no nav tab because current user does not have access. |
| 1463 | 1463 | continue; |
| 1464 | 1464 | } |
@@ -1466,20 +1466,20 @@ discard block |
||
| 1466 | 1466 | $css_class .= $only_tab ? ' ee-only-tab' : ''; |
| 1467 | 1467 | $css_class .= " ee-nav-tab__$slug"; |
| 1468 | 1468 | |
| 1469 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1469 | + $this->_nav_tabs[$slug] = [ |
|
| 1470 | 1470 | 'url' => $config['nav']['url'] ?? EE_Admin_Page::add_query_args_and_nonce( |
| 1471 | 1471 | ['action' => $slug], |
| 1472 | 1472 | $this->_admin_base_url |
| 1473 | 1473 | ), |
| 1474 | 1474 | 'link_text' => $this->navTabLabel($config['nav'], $slug), |
| 1475 | - 'css_class' => $this->_req_action === $slug ? $css_class . ' nav-tab-active' : $css_class, |
|
| 1475 | + 'css_class' => $this->_req_action === $slug ? $css_class.' nav-tab-active' : $css_class, |
|
| 1476 | 1476 | 'order' => $config['nav']['order'] ?? $i, |
| 1477 | 1477 | ]; |
| 1478 | 1478 | $i++; |
| 1479 | 1479 | } |
| 1480 | 1480 | // if $this->_nav_tabs is empty then lets set the default |
| 1481 | 1481 | if (empty($this->_nav_tabs)) { |
| 1482 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1482 | + $this->_nav_tabs[$this->_default_nav_tab_name] = [ |
|
| 1483 | 1483 | 'url' => $this->_admin_base_url, |
| 1484 | 1484 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1485 | 1485 | 'css_class' => 'nav-tab-active', |
@@ -1495,11 +1495,11 @@ discard block |
||
| 1495 | 1495 | { |
| 1496 | 1496 | $label = $nav_tab['label'] ?? ucwords(str_replace('_', ' ', $slug)); |
| 1497 | 1497 | $icon = $nav_tab['icon'] ?? null; |
| 1498 | - $icon = $icon ? '<span class="dashicons ' . $icon . '"></span>' : ''; |
|
| 1498 | + $icon = $icon ? '<span class="dashicons '.$icon.'"></span>' : ''; |
|
| 1499 | 1499 | return ' |
| 1500 | 1500 | <span class="ee-admin-screen-tab__label"> |
| 1501 | - ' . $icon . ' |
|
| 1502 | - <span class="ee-nav-label__text">' . $label . '</span> |
|
| 1501 | + ' . $icon.' |
|
| 1502 | + <span class="ee-nav-label__text">' . $label.'</span> |
|
| 1503 | 1503 | </span>'; |
| 1504 | 1504 | } |
| 1505 | 1505 | |
@@ -1517,10 +1517,10 @@ discard block |
||
| 1517 | 1517 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1518 | 1518 | if (is_array($text)) { |
| 1519 | 1519 | foreach ($text as $sublabel => $subtext) { |
| 1520 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1520 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1521 | 1521 | } |
| 1522 | 1522 | } else { |
| 1523 | - $this->_labels[ $label ] = $text; |
|
| 1523 | + $this->_labels[$label] = $text; |
|
| 1524 | 1524 | } |
| 1525 | 1525 | } |
| 1526 | 1526 | } |
@@ -1542,8 +1542,8 @@ discard block |
||
| 1542 | 1542 | { |
| 1543 | 1543 | // if no route_to_check is passed in then use the current route set via _req_action |
| 1544 | 1544 | $action = $route_to_check ?: $this->_req_action; |
| 1545 | - $capability = ! empty($this->_page_routes[ $action ]['capability']) |
|
| 1546 | - ? $this->_page_routes[ $action ]['capability'] |
|
| 1545 | + $capability = ! empty($this->_page_routes[$action]['capability']) |
|
| 1546 | + ? $this->_page_routes[$action]['capability'] |
|
| 1547 | 1547 | : null; |
| 1548 | 1548 | |
| 1549 | 1549 | if (empty($capability)) { |
@@ -1593,14 +1593,14 @@ discard block |
||
| 1593 | 1593 | string $priority = 'default', |
| 1594 | 1594 | ?array $callback_args = null |
| 1595 | 1595 | ) { |
| 1596 | - if (! (is_callable($callback) || ! function_exists($callback))) { |
|
| 1596 | + if ( ! (is_callable($callback) || ! function_exists($callback))) { |
|
| 1597 | 1597 | return; |
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
| 1601 | 1601 | add_filter( |
| 1602 | 1602 | "postbox_classes_{$this->_wp_page_slug}_$box_id", |
| 1603 | - function ($classes) { |
|
| 1603 | + function($classes) { |
|
| 1604 | 1604 | $classes[] = 'ee-admin-container'; |
| 1605 | 1605 | return $classes; |
| 1606 | 1606 | } |
@@ -1691,8 +1691,8 @@ discard block |
||
| 1691 | 1691 | <div class="ee-notices"></div> |
| 1692 | 1692 | <div class="ee-admin-dialog-container-inner-content"></div> |
| 1693 | 1693 | </div> |
| 1694 | - <span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span> |
|
| 1695 | - <input type="hidden" id="espresso_admin_current_page" value="' . esc_attr($this->_current_page) . '"/>'; |
|
| 1694 | + <span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()).'</span> |
|
| 1695 | + <input type="hidden" id="espresso_admin_current_page" value="' . esc_attr($this->_current_page).'"/>'; |
|
| 1696 | 1696 | } |
| 1697 | 1697 | |
| 1698 | 1698 | |
@@ -1726,7 +1726,7 @@ discard block |
||
| 1726 | 1726 | // loop through the array and setup content |
| 1727 | 1727 | foreach ($help_array as $trigger => $help) { |
| 1728 | 1728 | // make sure the array is setup properly |
| 1729 | - if (! isset($help['title'], $help['content'])) { |
|
| 1729 | + if ( ! isset($help['title'], $help['content'])) { |
|
| 1730 | 1730 | throw new EE_Error( |
| 1731 | 1731 | esc_html__( |
| 1732 | 1732 | 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
@@ -1740,8 +1740,8 @@ discard block |
||
| 1740 | 1740 | 'help_popup_title' => $help['title'], |
| 1741 | 1741 | 'help_popup_content' => $help['content'], |
| 1742 | 1742 | ]; |
| 1743 | - $content .= EEH_Template::display_template( |
|
| 1744 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1743 | + $content .= EEH_Template::display_template( |
|
| 1744 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1745 | 1745 | $template_args, |
| 1746 | 1746 | true |
| 1747 | 1747 | ); |
@@ -1763,15 +1763,15 @@ discard block |
||
| 1763 | 1763 | private function _get_help_content(): array |
| 1764 | 1764 | { |
| 1765 | 1765 | // what is the method we're looking for? |
| 1766 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1766 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1767 | 1767 | // if method doesn't exist let's get out. |
| 1768 | - if (! method_exists($this, $method_name)) { |
|
| 1768 | + if ( ! method_exists($this, $method_name)) { |
|
| 1769 | 1769 | return []; |
| 1770 | 1770 | } |
| 1771 | 1771 | // k we're good to go let's retrieve the help array |
| 1772 | 1772 | $help_array = $this->{$method_name}(); |
| 1773 | 1773 | // make sure we've got an array! |
| 1774 | - if (! is_array($help_array)) { |
|
| 1774 | + if ( ! is_array($help_array)) { |
|
| 1775 | 1775 | throw new EE_Error( |
| 1776 | 1776 | esc_html__( |
| 1777 | 1777 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1803,15 +1803,15 @@ discard block |
||
| 1803 | 1803 | // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
| 1804 | 1804 | $help_array = $this->_get_help_content(); |
| 1805 | 1805 | $help_content = ''; |
| 1806 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1807 | - $help_array[ $trigger_id ] = [ |
|
| 1806 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1807 | + $help_array[$trigger_id] = [ |
|
| 1808 | 1808 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1809 | 1809 | 'content' => esc_html__( |
| 1810 | 1810 | 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
| 1811 | 1811 | 'event_espresso' |
| 1812 | 1812 | ), |
| 1813 | 1813 | ]; |
| 1814 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1814 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1815 | 1815 | } |
| 1816 | 1816 | $height = esc_attr($dimensions[0]) ?? 400; |
| 1817 | 1817 | $width = esc_attr($dimensions[1]) ?? 640; |
@@ -1899,7 +1899,7 @@ discard block |
||
| 1899 | 1899 | |
| 1900 | 1900 | add_filter( |
| 1901 | 1901 | 'admin_body_class', |
| 1902 | - function ($classes) { |
|
| 1902 | + function($classes) { |
|
| 1903 | 1903 | if (strpos($classes, 'espresso-admin') === false) { |
| 1904 | 1904 | $classes .= ' espresso-admin'; |
| 1905 | 1905 | } |
@@ -1990,12 +1990,12 @@ discard block |
||
| 1990 | 1990 | protected function _set_list_table() |
| 1991 | 1991 | { |
| 1992 | 1992 | // first is this a list_table view? |
| 1993 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1993 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 1994 | 1994 | return; |
| 1995 | 1995 | } //not a list_table view so get out. |
| 1996 | 1996 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 1997 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1998 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1997 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 1998 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1999 | 1999 | // user error msg |
| 2000 | 2000 | $error_msg = esc_html__( |
| 2001 | 2001 | 'An error occurred. The requested list table views could not be found.', |
@@ -2015,10 +2015,10 @@ discard block |
||
| 2015 | 2015 | } |
| 2016 | 2016 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 2017 | 2017 | $this->_views = apply_filters( |
| 2018 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2018 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 2019 | 2019 | $this->_views |
| 2020 | 2020 | ); |
| 2021 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2021 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 2022 | 2022 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 2023 | 2023 | $this->_set_list_table_view(); |
| 2024 | 2024 | $this->_set_list_table_object(); |
@@ -2053,7 +2053,7 @@ discard block |
||
| 2053 | 2053 | protected function _set_list_table_object() |
| 2054 | 2054 | { |
| 2055 | 2055 | if (isset($this->_route_config['list_table'])) { |
| 2056 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2056 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 2057 | 2057 | throw new EE_Error( |
| 2058 | 2058 | sprintf( |
| 2059 | 2059 | esc_html__( |
@@ -2095,16 +2095,16 @@ discard block |
||
| 2095 | 2095 | foreach ($this->_views as $key => $view) { |
| 2096 | 2096 | $query_args = []; |
| 2097 | 2097 | // check for current view |
| 2098 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2098 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2099 | 2099 | $query_args['action'] = $this->_req_action; |
| 2100 | 2100 | $action_nonce = "{$this->_req_action}_nonce"; |
| 2101 | - $query_args[ $action_nonce ] = wp_create_nonce($action_nonce); |
|
| 2101 | + $query_args[$action_nonce] = wp_create_nonce($action_nonce); |
|
| 2102 | 2102 | $query_args['status'] = $view['slug']; |
| 2103 | 2103 | // merge any other arguments sent in. |
| 2104 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2105 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2104 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2105 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2106 | 2106 | } |
| 2107 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2107 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2108 | 2108 | } |
| 2109 | 2109 | return $this->_views; |
| 2110 | 2110 | } |
@@ -2133,14 +2133,14 @@ discard block |
||
| 2133 | 2133 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2134 | 2134 | foreach ($values as $value) { |
| 2135 | 2135 | if ($value < $max_entries) { |
| 2136 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2136 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2137 | 2137 | $entries_per_page_dropdown .= ' |
| 2138 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2138 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2139 | 2139 | } |
| 2140 | 2140 | } |
| 2141 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2141 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2142 | 2142 | $entries_per_page_dropdown .= ' |
| 2143 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2143 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2144 | 2144 | $entries_per_page_dropdown .= ' |
| 2145 | 2145 | </select> |
| 2146 | 2146 | entries |
@@ -2164,7 +2164,7 @@ discard block |
||
| 2164 | 2164 | empty($this->_search_btn_label) ? $this->page_label |
| 2165 | 2165 | : $this->_search_btn_label |
| 2166 | 2166 | ); |
| 2167 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2167 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2168 | 2168 | } |
| 2169 | 2169 | |
| 2170 | 2170 | |
@@ -2225,7 +2225,7 @@ discard block |
||
| 2225 | 2225 | ); |
| 2226 | 2226 | throw new EE_Error($error_msg); |
| 2227 | 2227 | } |
| 2228 | - unset($this->_route_config['metaboxes'][ $key ]); |
|
| 2228 | + unset($this->_route_config['metaboxes'][$key]); |
|
| 2229 | 2229 | } |
| 2230 | 2230 | } |
| 2231 | 2231 | } |
@@ -2258,7 +2258,7 @@ discard block |
||
| 2258 | 2258 | $total_columns = ! empty($screen_columns) |
| 2259 | 2259 | ? $screen_columns |
| 2260 | 2260 | : $this->_route_config['columns'][1]; |
| 2261 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2261 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2262 | 2262 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2263 | 2263 | $this->_template_args['screen'] = $this->_current_screen; |
| 2264 | 2264 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2304,7 +2304,7 @@ discard block |
||
| 2304 | 2304 | */ |
| 2305 | 2305 | protected function _espresso_ratings_request() |
| 2306 | 2306 | { |
| 2307 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2307 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2308 | 2308 | return; |
| 2309 | 2309 | } |
| 2310 | 2310 | $ratings_box_title = apply_filters( |
@@ -2331,28 +2331,28 @@ discard block |
||
| 2331 | 2331 | */ |
| 2332 | 2332 | public function espresso_ratings_request() |
| 2333 | 2333 | { |
| 2334 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2334 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php'); |
|
| 2335 | 2335 | } |
| 2336 | 2336 | |
| 2337 | 2337 | |
| 2338 | 2338 | public static function cached_rss_display(string $rss_id, string $url): bool |
| 2339 | 2339 | { |
| 2340 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2340 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2341 | 2341 | . esc_html__('Loading…', 'event_espresso') |
| 2342 | 2342 | . '</p><p class="hide-if-js">' |
| 2343 | 2343 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2344 | 2344 | . '</p>'; |
| 2345 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2346 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2347 | - $post = '</div>' . "\n"; |
|
| 2348 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2345 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2346 | + $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>'; |
|
| 2347 | + $post = '</div>'."\n"; |
|
| 2348 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2349 | 2349 | $output = get_transient($cache_key); |
| 2350 | 2350 | if ($output !== false) { |
| 2351 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2351 | + echo wp_kses($pre.$output.$post, AllowedTags::getWithFormTags()); |
|
| 2352 | 2352 | return true; |
| 2353 | 2353 | } |
| 2354 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2355 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2354 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2355 | + echo wp_kses($pre.$loading.$post, AllowedTags::getWithFormTags()); |
|
| 2356 | 2356 | return false; |
| 2357 | 2357 | } |
| 2358 | 2358 | ob_start(); |
@@ -2419,7 +2419,7 @@ discard block |
||
| 2419 | 2419 | public function espresso_sponsors_post_box() |
| 2420 | 2420 | { |
| 2421 | 2421 | EEH_Template::display_template( |
| 2422 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2422 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2423 | 2423 | ); |
| 2424 | 2424 | } |
| 2425 | 2425 | |
@@ -2436,9 +2436,9 @@ discard block |
||
| 2436 | 2436 | protected function getPublishBoxTitle(): string |
| 2437 | 2437 | { |
| 2438 | 2438 | $publish_box_title = esc_html__('Publish', 'event_espresso'); |
| 2439 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2439 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2440 | 2440 | if (is_array($this->_labels['publishbox'])) { |
| 2441 | - $publish_box_title = $this->_labels['publishbox'][ $this->_req_action ] ?? $publish_box_title; |
|
| 2441 | + $publish_box_title = $this->_labels['publishbox'][$this->_req_action] ?? $publish_box_title; |
|
| 2442 | 2442 | } else { |
| 2443 | 2443 | $publish_box_title = $this->_labels['publishbox']; |
| 2444 | 2444 | } |
@@ -2488,7 +2488,7 @@ discard block |
||
| 2488 | 2488 | // if we have extra content set let's add it in if not make sure its empty |
| 2489 | 2489 | $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? ''; |
| 2490 | 2490 | echo EEH_Template::display_template( |
| 2491 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2491 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2492 | 2492 | $this->_template_args, |
| 2493 | 2493 | true |
| 2494 | 2494 | ); |
@@ -2541,10 +2541,10 @@ discard block |
||
| 2541 | 2541 | 'submitdelete deletion button button--outline button--caution' |
| 2542 | 2542 | ); |
| 2543 | 2543 | } |
| 2544 | - if (! isset($this->_template_args['publish_delete_link'])) { |
|
| 2544 | + if ( ! isset($this->_template_args['publish_delete_link'])) { |
|
| 2545 | 2545 | $this->_template_args['publish_delete_link'] = ''; |
| 2546 | 2546 | } |
| 2547 | - if (! empty($name) && ! empty($id)) { |
|
| 2547 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2548 | 2548 | $this->addPublishPostMetaBoxHiddenFields($name, ['type' => 'hidden', 'value' => $id]); |
| 2549 | 2549 | } |
| 2550 | 2550 | $hidden_fields = $this->_generate_admin_form_fields($this->publish_post_meta_box_hidden_fields, 'array'); |
@@ -2577,7 +2577,7 @@ discard block |
||
| 2577 | 2577 | |
| 2578 | 2578 | protected function addPublishPostMetaBoxHiddenFields(string $field_name, array $field_attributes) |
| 2579 | 2579 | { |
| 2580 | - $this->publish_post_meta_box_hidden_fields[ $field_name ] = $field_attributes; |
|
| 2580 | + $this->publish_post_meta_box_hidden_fields[$field_name] = $field_attributes; |
|
| 2581 | 2581 | } |
| 2582 | 2582 | |
| 2583 | 2583 | |
@@ -2679,7 +2679,7 @@ discard block |
||
| 2679 | 2679 | } |
| 2680 | 2680 | // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
| 2681 | 2681 | $call_back_func = $create_func |
| 2682 | - ? static function ($post, $metabox) { |
|
| 2682 | + ? static function($post, $metabox) { |
|
| 2683 | 2683 | echo EEH_Template::display_template( |
| 2684 | 2684 | $metabox['args']['template_path'], |
| 2685 | 2685 | $metabox['args']['template_args'], |
@@ -2688,7 +2688,7 @@ discard block |
||
| 2688 | 2688 | } |
| 2689 | 2689 | : $callback; |
| 2690 | 2690 | $this->addMetaBox( |
| 2691 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2691 | + str_replace('_', '-', $action).'-mbox', |
|
| 2692 | 2692 | $title, |
| 2693 | 2693 | $call_back_func, |
| 2694 | 2694 | $this->_wp_page_slug, |
@@ -2804,15 +2804,15 @@ discard block |
||
| 2804 | 2804 | 'event-espresso_page_espresso_', |
| 2805 | 2805 | '', |
| 2806 | 2806 | $this->_wp_page_slug |
| 2807 | - ) . ' ' . $this->_req_action . '-route'; |
|
| 2807 | + ).' '.$this->_req_action.'-route'; |
|
| 2808 | 2808 | |
| 2809 | 2809 | $template_path = $sidebar |
| 2810 | 2810 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2811 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2811 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2812 | 2812 | |
| 2813 | 2813 | $this->_template_args['is_ajax'] = $this->request->isAjax(); |
| 2814 | 2814 | if ($this->request->isAjax()) { |
| 2815 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2815 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2816 | 2816 | } |
| 2817 | 2817 | $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
| 2818 | 2818 | |
@@ -2824,10 +2824,10 @@ discard block |
||
| 2824 | 2824 | // to prevent WooCommerce from blowing things up if not using CPT |
| 2825 | 2825 | global $post_type, $post; |
| 2826 | 2826 | $this->_template_args['post_type'] = $post_type ?? ''; |
| 2827 | - $this->_template_args['post'] = $post ?? new WP_Post( (object) [ 'ID' => 0, 'filter' => 'raw' ] ); |
|
| 2827 | + $this->_template_args['post'] = $post ?? new WP_Post((object) ['ID' => 0, 'filter' => 'raw']); |
|
| 2828 | 2828 | |
| 2829 | 2829 | $this->_template_args['post_body_content'] = EEH_Template::display_template( |
| 2830 | - EE_ADMIN_TEMPLATE . 'admin_details_wrapper_post_body_content.template.php', |
|
| 2830 | + EE_ADMIN_TEMPLATE.'admin_details_wrapper_post_body_content.template.php', |
|
| 2831 | 2831 | $this->_template_args, |
| 2832 | 2832 | true |
| 2833 | 2833 | ); |
@@ -2859,11 +2859,11 @@ discard block |
||
| 2859 | 2859 | public function display_admin_caf_preview_page(string $utm_campaign_source = '', bool $display_sidebar = true) |
| 2860 | 2860 | { |
| 2861 | 2861 | // let's generate a default preview action button if there isn't one already present. |
| 2862 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2862 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2863 | 2863 | 'Upgrade to Event Espresso 4 Right Now', |
| 2864 | 2864 | 'event_espresso' |
| 2865 | 2865 | ); |
| 2866 | - $buy_now_url = add_query_arg( |
|
| 2866 | + $buy_now_url = add_query_arg( |
|
| 2867 | 2867 | [ |
| 2868 | 2868 | 'ee_ver' => 'ee4', |
| 2869 | 2869 | 'utm_source' => 'ee4_plugin_admin', |
@@ -2883,8 +2883,8 @@ discard block |
||
| 2883 | 2883 | true |
| 2884 | 2884 | ) |
| 2885 | 2885 | : $this->_template_args['preview_action_button']; |
| 2886 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2887 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2886 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2887 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2888 | 2888 | $this->_template_args, |
| 2889 | 2889 | true |
| 2890 | 2890 | ); |
@@ -2942,7 +2942,7 @@ discard block |
||
| 2942 | 2942 | // setup search attributes |
| 2943 | 2943 | $this->_set_search_attributes(); |
| 2944 | 2944 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2945 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2945 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2946 | 2946 | $this->_template_args['table_url'] = $this->request->isAjax() |
| 2947 | 2947 | ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
| 2948 | 2948 | : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
@@ -2950,10 +2950,10 @@ discard block |
||
| 2950 | 2950 | $this->_template_args['current_route'] = $this->_req_action; |
| 2951 | 2951 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 2952 | 2952 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2953 | - if (! empty($ajax_sorting_callback)) { |
|
| 2953 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2954 | 2954 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2955 | - $ajax_sorting_callback . '_nonce', |
|
| 2956 | - $ajax_sorting_callback . '_nonce', |
|
| 2955 | + $ajax_sorting_callback.'_nonce', |
|
| 2956 | + $ajax_sorting_callback.'_nonce', |
|
| 2957 | 2957 | false, |
| 2958 | 2958 | false |
| 2959 | 2959 | ); |
@@ -2970,18 +2970,18 @@ discard block |
||
| 2970 | 2970 | |
| 2971 | 2971 | $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? ''; |
| 2972 | 2972 | |
| 2973 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2973 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2974 | 2974 | $hidden_form_fields .= ' |
| 2975 | - <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2975 | + <input type="hidden" name="' . $nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">'; |
|
| 2976 | 2976 | |
| 2977 | 2977 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
| 2978 | 2978 | // display message about search results? |
| 2979 | - $search = $this->request->getRequestParam('s'); |
|
| 2979 | + $search = $this->request->getRequestParam('s'); |
|
| 2980 | 2980 | $this->_template_args['before_list_table'] .= ! empty($search) |
| 2981 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2981 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 2982 | 2982 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 2983 | 2983 | trim($search, '%') |
| 2984 | - ) . '</p>' |
|
| 2984 | + ).'</p>' |
|
| 2985 | 2985 | : ''; |
| 2986 | 2986 | // filter before_list_table template arg |
| 2987 | 2987 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -3015,7 +3015,7 @@ discard block |
||
| 3015 | 3015 | // convert to array and filter again |
| 3016 | 3016 | // arrays are easier to inject new items in a specific location, |
| 3017 | 3017 | // but would not be backwards compatible, so we have to add a new filter |
| 3018 | - $this->_template_args['after_list_table'] = implode( |
|
| 3018 | + $this->_template_args['after_list_table'] = implode( |
|
| 3019 | 3019 | " \n", |
| 3020 | 3020 | (array) apply_filters( |
| 3021 | 3021 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
@@ -3070,7 +3070,7 @@ discard block |
||
| 3070 | 3070 | $this->page_slug |
| 3071 | 3071 | ); |
| 3072 | 3072 | return EEH_Template::display_template( |
| 3073 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3073 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 3074 | 3074 | $this->_template_args, |
| 3075 | 3075 | true |
| 3076 | 3076 | ); |
@@ -3193,7 +3193,7 @@ discard block |
||
| 3193 | 3193 | if ($this->request->isAjax()) { |
| 3194 | 3194 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 3195 | 3195 | // $template_path, |
| 3196 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3196 | + EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php', |
|
| 3197 | 3197 | $this->_template_args, |
| 3198 | 3198 | true |
| 3199 | 3199 | ); |
@@ -3202,7 +3202,7 @@ discard block |
||
| 3202 | 3202 | // load settings page wrapper template |
| 3203 | 3203 | $template_path = $about |
| 3204 | 3204 | ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
| 3205 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3205 | + : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php'; |
|
| 3206 | 3206 | |
| 3207 | 3207 | EEH_Template::display_template($template_path, $this->_template_args); |
| 3208 | 3208 | } |
@@ -3286,12 +3286,12 @@ discard block |
||
| 3286 | 3286 | $default_names = ['save', 'save_and_close']; |
| 3287 | 3287 | $buttons = ''; |
| 3288 | 3288 | foreach ($button_text as $key => $button) { |
| 3289 | - $ref = $default_names[ $key ]; |
|
| 3290 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3291 | - $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" ' |
|
| 3292 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3293 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3294 | - if (! $both) { |
|
| 3289 | + $ref = $default_names[$key]; |
|
| 3290 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 3291 | + $buttons .= '<input type="submit" class="button button--primary '.$ref.'" ' |
|
| 3292 | + . 'value="'.$button.'" name="'.$name.'" ' |
|
| 3293 | + . 'id="'.$this->_current_view.'_'.$ref.'" />'; |
|
| 3294 | + if ( ! $both) { |
|
| 3295 | 3295 | break; |
| 3296 | 3296 | } |
| 3297 | 3297 | } |
@@ -3332,13 +3332,13 @@ discard block |
||
| 3332 | 3332 | 'An error occurred. No action was set for this page\'s form.', |
| 3333 | 3333 | 'event_espresso' |
| 3334 | 3334 | ); |
| 3335 | - $dev_msg = $user_msg . "\n" |
|
| 3335 | + $dev_msg = $user_msg."\n" |
|
| 3336 | 3336 | . sprintf( |
| 3337 | 3337 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3338 | 3338 | __FUNCTION__, |
| 3339 | 3339 | __CLASS__ |
| 3340 | 3340 | ); |
| 3341 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3341 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3342 | 3342 | } |
| 3343 | 3343 | // open form |
| 3344 | 3344 | $action = $this->_admin_base_url; |
@@ -3346,9 +3346,9 @@ discard block |
||
| 3346 | 3346 | <form name='form' method='post' action='$action' id='{$route}_event_form' class='ee-admin-page-form' > |
| 3347 | 3347 | "; |
| 3348 | 3348 | // add nonce |
| 3349 | - $nonce = |
|
| 3350 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3351 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3349 | + $nonce = |
|
| 3350 | + wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3351 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3352 | 3352 | // add REQUIRED form action |
| 3353 | 3353 | $hidden_fields = [ |
| 3354 | 3354 | 'action' => ['type' => 'hidden', 'value' => $route], |
@@ -3361,7 +3361,7 @@ discard block |
||
| 3361 | 3361 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3362 | 3362 | // add fields to form |
| 3363 | 3363 | foreach ((array) $form_fields as $form_field) { |
| 3364 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3364 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3365 | 3365 | } |
| 3366 | 3366 | // close form |
| 3367 | 3367 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3444,10 +3444,10 @@ discard block |
||
| 3444 | 3444 | ) { |
| 3445 | 3445 | $notices = EE_Error::get_notices(false); |
| 3446 | 3446 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3447 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3447 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3448 | 3448 | EE_Error::overwrite_success(); |
| 3449 | 3449 | } |
| 3450 | - if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3450 | + if ( ! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3451 | 3451 | // how many records affected ? more than one record ? or just one ? |
| 3452 | 3452 | EE_Error::add_success( |
| 3453 | 3453 | sprintf( |
@@ -3498,7 +3498,7 @@ discard block |
||
| 3498 | 3498 | $redirect_url = admin_url('admin.php'); |
| 3499 | 3499 | } |
| 3500 | 3500 | // merge any default query_args set in _default_route_query_args property |
| 3501 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3501 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3502 | 3502 | $args_to_merge = []; |
| 3503 | 3503 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3504 | 3504 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3510,15 +3510,15 @@ discard block |
||
| 3510 | 3510 | } |
| 3511 | 3511 | // finally we will override any arguments in the referer with |
| 3512 | 3512 | // what might be set on the _default_route_query_args array. |
| 3513 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3514 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3513 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3514 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3515 | 3515 | } else { |
| 3516 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3516 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3517 | 3517 | } |
| 3518 | 3518 | } |
| 3519 | 3519 | continue; |
| 3520 | 3520 | } |
| 3521 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3521 | + $args_to_merge[$query_param] = $query_value; |
|
| 3522 | 3522 | } |
| 3523 | 3523 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3524 | 3524 | // redirect. |
@@ -3530,19 +3530,19 @@ discard block |
||
| 3530 | 3530 | if (isset($query_args['action'])) { |
| 3531 | 3531 | // manually generate wp_nonce and merge that with the query vars |
| 3532 | 3532 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3533 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3533 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3534 | 3534 | } |
| 3535 | 3535 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3536 | 3536 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3537 | - do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args); |
|
| 3537 | + do_action('AHEE_redirect_'.$this->class_name.$this->_req_action, $query_args); |
|
| 3538 | 3538 | $redirect_url = apply_filters( |
| 3539 | - 'FHEE_redirect_' . $this->class_name . $this->_req_action, |
|
| 3539 | + 'FHEE_redirect_'.$this->class_name.$this->_req_action, |
|
| 3540 | 3540 | EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
| 3541 | 3541 | $query_args |
| 3542 | 3542 | ); |
| 3543 | 3543 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 3544 | 3544 | if ($this->request->isAjax()) { |
| 3545 | - $default_data = [ |
|
| 3545 | + $default_data = [ |
|
| 3546 | 3546 | 'close' => true, |
| 3547 | 3547 | 'redirect_url' => $redirect_url, |
| 3548 | 3548 | 'where' => 'main', |
@@ -3595,7 +3595,7 @@ discard block |
||
| 3595 | 3595 | } |
| 3596 | 3596 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3597 | 3597 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3598 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3598 | + if ( ! $this->request->isAjax() || $sticky_notices) { |
|
| 3599 | 3599 | $route = $query_args['action'] ?? 'default'; |
| 3600 | 3600 | $this->_add_transient( |
| 3601 | 3601 | $route, |
@@ -3635,7 +3635,7 @@ discard block |
||
| 3635 | 3635 | bool $exclude_nonce = false |
| 3636 | 3636 | ): string { |
| 3637 | 3637 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3638 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3638 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3639 | 3639 | throw new EE_Error( |
| 3640 | 3640 | sprintf( |
| 3641 | 3641 | esc_html__( |
@@ -3646,7 +3646,7 @@ discard block |
||
| 3646 | 3646 | ) |
| 3647 | 3647 | ); |
| 3648 | 3648 | } |
| 3649 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3649 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3650 | 3650 | throw new EE_Error( |
| 3651 | 3651 | sprintf( |
| 3652 | 3652 | esc_html__( |
@@ -3659,7 +3659,7 @@ discard block |
||
| 3659 | 3659 | } |
| 3660 | 3660 | // finally check user access for this button. |
| 3661 | 3661 | $has_access = $this->check_user_access($action, true); |
| 3662 | - if (! $has_access) { |
|
| 3662 | + if ( ! $has_access) { |
|
| 3663 | 3663 | return ''; |
| 3664 | 3664 | } |
| 3665 | 3665 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3667,11 +3667,11 @@ discard block |
||
| 3667 | 3667 | 'action' => $action, |
| 3668 | 3668 | ]; |
| 3669 | 3669 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3670 | - if (! empty($extra_request)) { |
|
| 3670 | + if ( ! empty($extra_request)) { |
|
| 3671 | 3671 | $query_args = array_merge($extra_request, $query_args); |
| 3672 | 3672 | } |
| 3673 | 3673 | $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3674 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3674 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3675 | 3675 | } |
| 3676 | 3676 | |
| 3677 | 3677 | |
@@ -3697,7 +3697,7 @@ discard block |
||
| 3697 | 3697 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3698 | 3698 | 20 |
| 3699 | 3699 | ), |
| 3700 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3700 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3701 | 3701 | ]; |
| 3702 | 3702 | // ONLY add the screen option if the user has access to it. |
| 3703 | 3703 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3718,18 +3718,18 @@ discard block |
||
| 3718 | 3718 | { |
| 3719 | 3719 | if ($this->request->requestParamIsSet('wp_screen_options')) { |
| 3720 | 3720 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3721 | - if (! $user = wp_get_current_user()) { |
|
| 3721 | + if ( ! $user = wp_get_current_user()) { |
|
| 3722 | 3722 | return; |
| 3723 | 3723 | } |
| 3724 | 3724 | $option = $this->request->getRequestParam('wp_screen_options[option]', '', DataType::KEY); |
| 3725 | - if (! $option) { |
|
| 3725 | + if ( ! $option) { |
|
| 3726 | 3726 | return; |
| 3727 | 3727 | } |
| 3728 | 3728 | $value = $this->request->getRequestParam('wp_screen_options[value]', 0, DataType::INT); |
| 3729 | 3729 | $map_option = $option; |
| 3730 | 3730 | $option = str_replace('-', '_', $option); |
| 3731 | 3731 | switch ($map_option) { |
| 3732 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3732 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3733 | 3733 | $max_value = apply_filters( |
| 3734 | 3734 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
| 3735 | 3735 | 999, |
@@ -3796,7 +3796,7 @@ discard block |
||
| 3796 | 3796 | bool $skip_route_verify = false |
| 3797 | 3797 | ) { |
| 3798 | 3798 | $user_id = get_current_user_id(); |
| 3799 | - if (! $skip_route_verify) { |
|
| 3799 | + if ( ! $skip_route_verify) { |
|
| 3800 | 3800 | $this->_verify_route($route); |
| 3801 | 3801 | } |
| 3802 | 3802 | // now let's set the string for what kind of transient we're setting |
@@ -3829,8 +3829,8 @@ discard block |
||
| 3829 | 3829 | $user_id = get_current_user_id(); |
| 3830 | 3830 | $route = ! $route ? $this->_req_action : $route; |
| 3831 | 3831 | $transient = $notices |
| 3832 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3833 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3832 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3833 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3834 | 3834 | $data = is_multisite() && is_network_admin() |
| 3835 | 3835 | ? get_site_transient($transient) |
| 3836 | 3836 | : get_transient($transient); |
@@ -4088,7 +4088,7 @@ discard block |
||
| 4088 | 4088 | */ |
| 4089 | 4089 | protected function _next_link(string $url, string $class = 'dashicons dashicons-arrow-right'): string |
| 4090 | 4090 | { |
| 4091 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4091 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4092 | 4092 | } |
| 4093 | 4093 | |
| 4094 | 4094 | |
@@ -4101,7 +4101,7 @@ discard block |
||
| 4101 | 4101 | */ |
| 4102 | 4102 | protected function _previous_link(string $url, string $class = 'dashicons dashicons-arrow-left'): string |
| 4103 | 4103 | { |
| 4104 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4104 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4105 | 4105 | } |
| 4106 | 4106 | |
| 4107 | 4107 | |
@@ -4249,13 +4249,13 @@ discard block |
||
| 4249 | 4249 | ?callable $callback = null |
| 4250 | 4250 | ): bool { |
| 4251 | 4251 | $entity_ID = absint($entity_ID); |
| 4252 | - if (! $entity_ID) { |
|
| 4252 | + if ( ! $entity_ID) { |
|
| 4253 | 4253 | $this->trashRestoreDeleteError($action, $entity_model); |
| 4254 | 4254 | } |
| 4255 | 4255 | $result = 0; |
| 4256 | 4256 | try { |
| 4257 | 4257 | $entity = $entity_model->get_one_by_ID($entity_ID); |
| 4258 | - if (! $entity instanceof EE_Base_Class) { |
|
| 4258 | + if ( ! $entity instanceof EE_Base_Class) { |
|
| 4259 | 4259 | throw new DomainException( |
| 4260 | 4260 | sprintf( |
| 4261 | 4261 | esc_html__( |
@@ -4306,7 +4306,7 @@ discard block |
||
| 4306 | 4306 | ) |
| 4307 | 4307 | ); |
| 4308 | 4308 | } |
| 4309 | - if (! $entity_model->has_field($delete_column)) { |
|
| 4309 | + if ( ! $entity_model->has_field($delete_column)) { |
|
| 4310 | 4310 | throw new DomainException( |
| 4311 | 4311 | sprintf( |
| 4312 | 4312 | esc_html__( |
@@ -23,541 +23,541 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | abstract class EE_Gateway |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * a constant used as a possible value for $_currencies_supported to indicate |
|
| 28 | - * that ALL currencies are supported by this gateway |
|
| 29 | - */ |
|
| 30 | - const all_currencies_supported = 'all_currencies_supported'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Where values are 3-letter currency codes |
|
| 34 | - * |
|
| 35 | - * @var array|string |
|
| 36 | - */ |
|
| 37 | - protected $_currencies_supported = []; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Whether this gateway can support SENDING a refund request (ie, initiated by |
|
| 41 | - * admin in EE's wp-admin page) |
|
| 42 | - * |
|
| 43 | - * @var boolean |
|
| 44 | - */ |
|
| 45 | - protected bool $_supports_sending_refunds = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Whether this gateway can support RECEIVING a refund request from the payment |
|
| 49 | - * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
| 50 | - * |
|
| 51 | - * @var boolean |
|
| 52 | - */ |
|
| 53 | - protected bool $_supports_receiving_refunds = false; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Model for querying for existing payments |
|
| 57 | - * |
|
| 58 | - * @var EEMI_Payment|null |
|
| 59 | - */ |
|
| 60 | - protected ?EEMI_Payment $_pay_model = null; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Model used for adding to the payments log |
|
| 64 | - * |
|
| 65 | - * @var EEM_Change_Log|null |
|
| 66 | - */ |
|
| 67 | - protected ?EEM_Change_Log $_pay_log = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Used for formatting some input to gateways |
|
| 71 | - * |
|
| 72 | - * @var EEH_Template|null |
|
| 73 | - */ |
|
| 74 | - protected ?EEH_Template $_template = null; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Concrete class that implements EEHI_Money, used by most gateways |
|
| 78 | - * |
|
| 79 | - * @var EEH_Money|null |
|
| 80 | - */ |
|
| 81 | - protected ?EEH_Money $_money = null; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Concrete class that implements EEH_Line_Item, used for manipulating the line item tree |
|
| 85 | - * |
|
| 86 | - * @var EEH_Line_Item|null |
|
| 87 | - */ |
|
| 88 | - protected ?EEH_Line_Item $_line_item = null; |
|
| 89 | - |
|
| 90 | - protected ?GatewayDataFormatterInterface $_gateway_data_formatter = null; |
|
| 91 | - |
|
| 92 | - protected ?FormatterInterface $_unsupported_character_remover = null; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * The ID of the payment method using this gateway |
|
| 96 | - * |
|
| 97 | - * @var int |
|
| 98 | - */ |
|
| 99 | - protected int $_ID = 0; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
| 103 | - */ |
|
| 104 | - protected bool $_debug_mode = false; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @var string $_name name to show for this payment method |
|
| 108 | - */ |
|
| 109 | - protected string $_name = ''; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @var string name to show for this payment method to admin-type users |
|
| 113 | - */ |
|
| 114 | - protected string $_admin_name = ''; |
|
| 115 | - |
|
| 116 | - protected array $settings = []; |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * We don't want to serialize models as they often have circular structures |
|
| 123 | - * (eg a payment model has a reference to each payment model object; and most |
|
| 124 | - * payments have a transaction, most transactions have a payment method; |
|
| 125 | - * most payment methods have a payment method type; most payment method types |
|
| 126 | - * have a gateway. And if a gateway serializes its models, we start at the |
|
| 127 | - * beginning again) |
|
| 128 | - * |
|
| 129 | - * @return array |
|
| 130 | - */ |
|
| 131 | - public function __sleep() |
|
| 132 | - { |
|
| 133 | - $properties = get_object_vars($this); |
|
| 134 | - unset($properties['_pay_model'], $properties['_pay_log']); |
|
| 135 | - return array_keys($properties); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Returns whether this gateway should support SENDING refunds |
|
| 141 | - * see $_supports_sending_refunds |
|
| 142 | - * |
|
| 143 | - * @return bool |
|
| 144 | - */ |
|
| 145 | - public function supports_sending_refunds(): bool |
|
| 146 | - { |
|
| 147 | - return $this->_supports_sending_refunds; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Returns whether this gateway should support RECEIVING refunds |
|
| 153 | - * see $_supports_receiving_refunds |
|
| 154 | - * |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function supports_receiving_refunds(): bool |
|
| 158 | - { |
|
| 159 | - return $this->_supports_receiving_refunds; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Tries to refund the payment specified, taking into account the extra |
|
| 165 | - * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
| 166 | - * this should just throw an exception. |
|
| 167 | - * |
|
| 168 | - * @param EE_Payment|null $payment |
|
| 169 | - * @param array|null $refund_info |
|
| 170 | - * @return EE_Payment|null |
|
| 171 | - */ |
|
| 172 | - public function do_direct_refund(?EE_Payment $payment, ?array $refund_info = null): ?EE_Payment |
|
| 173 | - { |
|
| 174 | - return null; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Sets the payment method's settings so the gateway knows where to send the request |
|
| 180 | - * etc |
|
| 181 | - * |
|
| 182 | - * @param array $settings_array |
|
| 183 | - */ |
|
| 184 | - public function set_settings(array $settings_array) |
|
| 185 | - { |
|
| 186 | - foreach ($settings_array as $name => $value) { |
|
| 187 | - // preface property name with underscore |
|
| 188 | - $property_name = strpos($name, '_') !== 0 |
|
| 189 | - ? '_' . $name |
|
| 190 | - : $name; |
|
| 191 | - if (property_exists($this, $property_name)) { |
|
| 192 | - $this->{$property_name} = $value; |
|
| 193 | - } else { |
|
| 194 | - $this->settings[ $property_name ] = $value; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - public function __get($property_name) |
|
| 201 | - { |
|
| 202 | - if (property_exists($this, $property_name)) { |
|
| 203 | - return $this->{$property_name}; |
|
| 204 | - } |
|
| 205 | - return $this->settings[ $property_name ] ?? null; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * See this class description |
|
| 211 | - * |
|
| 212 | - * @param EEM_Payment $payment_model |
|
| 213 | - */ |
|
| 214 | - public function set_payment_model(EEM_Payment $payment_model) |
|
| 215 | - { |
|
| 216 | - $this->_pay_model = $payment_model; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * See this class description |
|
| 222 | - * |
|
| 223 | - * @param EEM_Change_Log $payment_log_model |
|
| 224 | - */ |
|
| 225 | - public function set_payment_log(EEM_Change_Log $payment_log_model) |
|
| 226 | - { |
|
| 227 | - $this->_pay_log = $payment_log_model; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * See this class description |
|
| 233 | - * |
|
| 234 | - * @param EEH_Template $template_helper |
|
| 235 | - */ |
|
| 236 | - public function set_template_helper(EEH_Template $template_helper) |
|
| 237 | - { |
|
| 238 | - $this->_template = $template_helper; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * See this class description |
|
| 244 | - * |
|
| 245 | - * @param EEH_Line_Item $line_item_helper |
|
| 246 | - */ |
|
| 247 | - public function set_line_item_helper(EEH_Line_Item $line_item_helper) |
|
| 248 | - { |
|
| 249 | - $this->_line_item = $line_item_helper; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * See this class description |
|
| 255 | - * |
|
| 256 | - * @param EEH_Money $money_helper |
|
| 257 | - */ |
|
| 258 | - public function set_money_helper(EEH_Money $money_helper) |
|
| 259 | - { |
|
| 260 | - $this->_money = $money_helper; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Sets the gateway data formatter helper |
|
| 266 | - * |
|
| 267 | - * @param GatewayDataFormatterInterface|null $gateway_data_formatter |
|
| 268 | - * @throws InvalidEntityException if it's not set properly |
|
| 269 | - */ |
|
| 270 | - public function set_gateway_data_formatter(?GatewayDataFormatterInterface $gateway_data_formatter) |
|
| 271 | - { |
|
| 272 | - if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
| 273 | - throw new InvalidEntityException( |
|
| 274 | - is_object($gateway_data_formatter) |
|
| 275 | - ? get_class($gateway_data_formatter) |
|
| 276 | - : esc_html__('Not an object', 'event_espresso'), |
|
| 277 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - $this->_gateway_data_formatter = $gateway_data_formatter; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Gets the gateway data formatter |
|
| 286 | - * |
|
| 287 | - * @return GatewayDataFormatterInterface |
|
| 288 | - * @throws InvalidEntityException if it's not set properly |
|
| 289 | - */ |
|
| 290 | - protected function _get_gateway_formatter(): GatewayDataFormatterInterface |
|
| 291 | - { |
|
| 292 | - if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
| 293 | - throw new InvalidEntityException( |
|
| 294 | - is_object($this->_gateway_data_formatter) |
|
| 295 | - ? get_class($this->_gateway_data_formatter) |
|
| 296 | - : esc_html__('Not an object', 'event_espresso'), |
|
| 297 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 298 | - ); |
|
| 299 | - } |
|
| 300 | - return $this->_gateway_data_formatter; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Sets the helper which will remove unsupported characters for most gateways |
|
| 306 | - * |
|
| 307 | - * @param FormatterInterface|null $formatter |
|
| 308 | - * @return void |
|
| 309 | - * @throws InvalidEntityException |
|
| 310 | - */ |
|
| 311 | - public function set_unsupported_character_remover(?FormatterInterface $formatter) |
|
| 312 | - { |
|
| 313 | - if (! $formatter instanceof FormatterInterface) { |
|
| 314 | - throw new InvalidEntityException( |
|
| 315 | - is_object($formatter) |
|
| 316 | - ? get_class($formatter) |
|
| 317 | - : esc_html__('Not an object', 'event_espresso'), |
|
| 318 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 319 | - ); |
|
| 320 | - } |
|
| 321 | - $this->_unsupported_character_remover = $formatter; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
| 327 | - * |
|
| 328 | - * @return FormatterInterface |
|
| 329 | - * @throws InvalidEntityException |
|
| 330 | - */ |
|
| 331 | - protected function _get_unsupported_character_remover(): FormatterInterface |
|
| 332 | - { |
|
| 333 | - if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
| 334 | - throw new InvalidEntityException( |
|
| 335 | - is_object($this->_unsupported_character_remover) |
|
| 336 | - ? get_class($this->_unsupported_character_remover) |
|
| 337 | - : esc_html__('Not an object', 'event_espresso'), |
|
| 338 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 339 | - ); |
|
| 340 | - } |
|
| 341 | - return $this->_unsupported_character_remover; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @param array|string $message |
|
| 347 | - * @param mixed $object_logged |
|
| 348 | - * @throws EE_Error |
|
| 349 | - * @throws ReflectionException |
|
| 350 | - */ |
|
| 351 | - public function log($message, $object_logged) |
|
| 352 | - { |
|
| 353 | - if ($object_logged instanceof EE_Payment) { |
|
| 354 | - $type = 'Payment'; |
|
| 355 | - $id = $object_logged->ID(); |
|
| 356 | - } elseif ($object_logged instanceof EE_Transaction) { |
|
| 357 | - $type = 'Transaction'; |
|
| 358 | - $id = $object_logged->ID(); |
|
| 359 | - } else { |
|
| 360 | - $type = 'Payment_Method'; |
|
| 361 | - $id = $this->_ID; |
|
| 362 | - } |
|
| 363 | - // only log if we're going to store it for longer than the minimum time |
|
| 364 | - $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
| 365 | - if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
| 366 | - $this->_pay_log->gateway_log($message, $id, $type); |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Formats the amount so it can generally be sent to gateways |
|
| 373 | - * |
|
| 374 | - * @param float $amount |
|
| 375 | - * @return string |
|
| 376 | - * @deprecated since 4.9.31 insetad use |
|
| 377 | - * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
| 378 | - */ |
|
| 379 | - public function format_currency(float $amount): string |
|
| 380 | - { |
|
| 381 | - return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Returns either an array of all the currency codes supported, |
|
| 387 | - * or a string indicating they are all supported (EE_gateway::all_currencies_supported) |
|
| 388 | - * |
|
| 389 | - * @return array|string |
|
| 390 | - */ |
|
| 391 | - public function currencies_supported() |
|
| 392 | - { |
|
| 393 | - return $this->_currencies_supported; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Returns what a simple summing of items and taxes for this transaction. This |
|
| 399 | - * can be used to determine if some more complex line items, like promotions, |
|
| 400 | - * surcharges, or cancellations occurred (in which case we might want to forget |
|
| 401 | - * about creating an itemized list of purchases and instead only send the total due) |
|
| 402 | - * |
|
| 403 | - * @param EE_Transaction $transaction |
|
| 404 | - * @return float |
|
| 405 | - * @throws EE_Error |
|
| 406 | - * @throws ReflectionException |
|
| 407 | - */ |
|
| 408 | - protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
| 409 | - { |
|
| 410 | - $total_line_item = $transaction->total_line_item(); |
|
| 411 | - $total = 0; |
|
| 412 | - foreach ($total_line_item->get_items() as $item_line_item) { |
|
| 413 | - $total += max($item_line_item->total(), 0); |
|
| 414 | - } |
|
| 415 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
| 416 | - $total += max($tax_line_item->total(), 0); |
|
| 417 | - } |
|
| 418 | - return $total; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Determines whether we can easily itemize the transaction using only |
|
| 424 | - * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
| 425 | - * |
|
| 426 | - * @param EE_Payment $payment |
|
| 427 | - * @return boolean |
|
| 428 | - * @throws EE_Error |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - */ |
|
| 431 | - protected function _can_easily_itemize_transaction_for(EE_Payment $payment): bool |
|
| 432 | - { |
|
| 433 | - return $this->_money->compare_floats( |
|
| 434 | - $this->_sum_items_and_taxes($payment->transaction()), |
|
| 435 | - $payment->transaction()->total() |
|
| 436 | - ) |
|
| 437 | - && $this->_money->compare_floats( |
|
| 438 | - $payment->amount(), |
|
| 439 | - $payment->transaction()->total() |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Handles updating the transaction and any other related data based on the payment. |
|
| 446 | - * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
| 447 | - * but doing so on those functions might be too early. It's possible that the changes |
|
| 448 | - * you make to teh transaction or registration or line items may just get overwritten |
|
| 449 | - * at that point. Instead, you should store any info you need on the payment during those |
|
| 450 | - * functions, and use that information at this step, which client code will decide |
|
| 451 | - * for you when it should be called. |
|
| 452 | - * |
|
| 453 | - * @param EE_Payment $payment |
|
| 454 | - * @return void |
|
| 455 | - */ |
|
| 456 | - public function update_txn_based_on_payment($payment) |
|
| 457 | - { |
|
| 458 | - // maybe update the transaction or line items or registrations |
|
| 459 | - // but most gateways don't need to do this, because they only update the payment |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 465 | - * |
|
| 466 | - * @param EE_Payment $payment |
|
| 467 | - * @return EE_Event|null |
|
| 468 | - * @deprecated since 4.9.31 instead use EE_Payment::get_first_event() |
|
| 469 | - */ |
|
| 470 | - protected function _get_first_event_for_payment(EE_Payment $payment): ?EE_Event |
|
| 471 | - { |
|
| 472 | - return $payment->get_first_event(); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * Gets the name of the first event for which is being paid |
|
| 478 | - * |
|
| 479 | - * @param EE_Payment $payment |
|
| 480 | - * @return string |
|
| 481 | - * @deprecated since 4.9.31 instead use EE_Payment::get_first_event_name() |
|
| 482 | - */ |
|
| 483 | - protected function _get_first_event_name_for_payment(EE_Payment $payment): string |
|
| 484 | - { |
|
| 485 | - return $payment->get_first_event_name(); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 491 | - * |
|
| 492 | - * @param EE_Payment $payment |
|
| 493 | - * @return string |
|
| 494 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
| 495 | - */ |
|
| 496 | - protected function _format_partial_payment_line_item_name(EE_Payment $payment): string |
|
| 497 | - { |
|
| 498 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 504 | - * |
|
| 505 | - * @param EE_Payment $payment |
|
| 506 | - * @return string |
|
| 507 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
| 508 | - */ |
|
| 509 | - protected function _format_partial_payment_line_item_desc(EE_Payment $payment): string |
|
| 510 | - { |
|
| 511 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Gets the name to use for a line item when sending line items to the gateway |
|
| 517 | - * |
|
| 518 | - * @param EE_Line_Item $line_item |
|
| 519 | - * @param EE_Payment $payment |
|
| 520 | - * @return string |
|
| 521 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
| 522 | - */ |
|
| 523 | - protected function _format_line_item_name(EE_Line_Item $line_item, EE_Payment $payment): string |
|
| 524 | - { |
|
| 525 | - return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Gets the description to use for a line item when sending line items to the gateway |
|
| 531 | - * |
|
| 532 | - * @param EE_Line_Item $line_item |
|
| 533 | - * @param EE_Payment $payment |
|
| 534 | - * @return string |
|
| 535 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
| 536 | - */ |
|
| 537 | - protected function _format_line_item_desc(EE_Line_Item $line_item, EE_Payment $payment): string |
|
| 538 | - { |
|
| 539 | - return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * Gets the order description that should generlly be sent to gateways |
|
| 545 | - * |
|
| 546 | - * @param EE_Payment $payment |
|
| 547 | - * @return string |
|
| 548 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
| 549 | - */ |
|
| 550 | - protected function _format_order_description(EE_Payment $payment): string |
|
| 551 | - { |
|
| 552 | - return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * @return bool |
|
| 558 | - */ |
|
| 559 | - public function isInSandboxMode(): bool |
|
| 560 | - { |
|
| 561 | - return $this->_debug_mode; |
|
| 562 | - } |
|
| 26 | + /** |
|
| 27 | + * a constant used as a possible value for $_currencies_supported to indicate |
|
| 28 | + * that ALL currencies are supported by this gateway |
|
| 29 | + */ |
|
| 30 | + const all_currencies_supported = 'all_currencies_supported'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Where values are 3-letter currency codes |
|
| 34 | + * |
|
| 35 | + * @var array|string |
|
| 36 | + */ |
|
| 37 | + protected $_currencies_supported = []; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Whether this gateway can support SENDING a refund request (ie, initiated by |
|
| 41 | + * admin in EE's wp-admin page) |
|
| 42 | + * |
|
| 43 | + * @var boolean |
|
| 44 | + */ |
|
| 45 | + protected bool $_supports_sending_refunds = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Whether this gateway can support RECEIVING a refund request from the payment |
|
| 49 | + * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
| 50 | + * |
|
| 51 | + * @var boolean |
|
| 52 | + */ |
|
| 53 | + protected bool $_supports_receiving_refunds = false; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Model for querying for existing payments |
|
| 57 | + * |
|
| 58 | + * @var EEMI_Payment|null |
|
| 59 | + */ |
|
| 60 | + protected ?EEMI_Payment $_pay_model = null; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Model used for adding to the payments log |
|
| 64 | + * |
|
| 65 | + * @var EEM_Change_Log|null |
|
| 66 | + */ |
|
| 67 | + protected ?EEM_Change_Log $_pay_log = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Used for formatting some input to gateways |
|
| 71 | + * |
|
| 72 | + * @var EEH_Template|null |
|
| 73 | + */ |
|
| 74 | + protected ?EEH_Template $_template = null; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Concrete class that implements EEHI_Money, used by most gateways |
|
| 78 | + * |
|
| 79 | + * @var EEH_Money|null |
|
| 80 | + */ |
|
| 81 | + protected ?EEH_Money $_money = null; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Concrete class that implements EEH_Line_Item, used for manipulating the line item tree |
|
| 85 | + * |
|
| 86 | + * @var EEH_Line_Item|null |
|
| 87 | + */ |
|
| 88 | + protected ?EEH_Line_Item $_line_item = null; |
|
| 89 | + |
|
| 90 | + protected ?GatewayDataFormatterInterface $_gateway_data_formatter = null; |
|
| 91 | + |
|
| 92 | + protected ?FormatterInterface $_unsupported_character_remover = null; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * The ID of the payment method using this gateway |
|
| 96 | + * |
|
| 97 | + * @var int |
|
| 98 | + */ |
|
| 99 | + protected int $_ID = 0; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
| 103 | + */ |
|
| 104 | + protected bool $_debug_mode = false; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @var string $_name name to show for this payment method |
|
| 108 | + */ |
|
| 109 | + protected string $_name = ''; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @var string name to show for this payment method to admin-type users |
|
| 113 | + */ |
|
| 114 | + protected string $_admin_name = ''; |
|
| 115 | + |
|
| 116 | + protected array $settings = []; |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * We don't want to serialize models as they often have circular structures |
|
| 123 | + * (eg a payment model has a reference to each payment model object; and most |
|
| 124 | + * payments have a transaction, most transactions have a payment method; |
|
| 125 | + * most payment methods have a payment method type; most payment method types |
|
| 126 | + * have a gateway. And if a gateway serializes its models, we start at the |
|
| 127 | + * beginning again) |
|
| 128 | + * |
|
| 129 | + * @return array |
|
| 130 | + */ |
|
| 131 | + public function __sleep() |
|
| 132 | + { |
|
| 133 | + $properties = get_object_vars($this); |
|
| 134 | + unset($properties['_pay_model'], $properties['_pay_log']); |
|
| 135 | + return array_keys($properties); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Returns whether this gateway should support SENDING refunds |
|
| 141 | + * see $_supports_sending_refunds |
|
| 142 | + * |
|
| 143 | + * @return bool |
|
| 144 | + */ |
|
| 145 | + public function supports_sending_refunds(): bool |
|
| 146 | + { |
|
| 147 | + return $this->_supports_sending_refunds; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Returns whether this gateway should support RECEIVING refunds |
|
| 153 | + * see $_supports_receiving_refunds |
|
| 154 | + * |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function supports_receiving_refunds(): bool |
|
| 158 | + { |
|
| 159 | + return $this->_supports_receiving_refunds; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Tries to refund the payment specified, taking into account the extra |
|
| 165 | + * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
| 166 | + * this should just throw an exception. |
|
| 167 | + * |
|
| 168 | + * @param EE_Payment|null $payment |
|
| 169 | + * @param array|null $refund_info |
|
| 170 | + * @return EE_Payment|null |
|
| 171 | + */ |
|
| 172 | + public function do_direct_refund(?EE_Payment $payment, ?array $refund_info = null): ?EE_Payment |
|
| 173 | + { |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Sets the payment method's settings so the gateway knows where to send the request |
|
| 180 | + * etc |
|
| 181 | + * |
|
| 182 | + * @param array $settings_array |
|
| 183 | + */ |
|
| 184 | + public function set_settings(array $settings_array) |
|
| 185 | + { |
|
| 186 | + foreach ($settings_array as $name => $value) { |
|
| 187 | + // preface property name with underscore |
|
| 188 | + $property_name = strpos($name, '_') !== 0 |
|
| 189 | + ? '_' . $name |
|
| 190 | + : $name; |
|
| 191 | + if (property_exists($this, $property_name)) { |
|
| 192 | + $this->{$property_name} = $value; |
|
| 193 | + } else { |
|
| 194 | + $this->settings[ $property_name ] = $value; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + public function __get($property_name) |
|
| 201 | + { |
|
| 202 | + if (property_exists($this, $property_name)) { |
|
| 203 | + return $this->{$property_name}; |
|
| 204 | + } |
|
| 205 | + return $this->settings[ $property_name ] ?? null; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * See this class description |
|
| 211 | + * |
|
| 212 | + * @param EEM_Payment $payment_model |
|
| 213 | + */ |
|
| 214 | + public function set_payment_model(EEM_Payment $payment_model) |
|
| 215 | + { |
|
| 216 | + $this->_pay_model = $payment_model; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * See this class description |
|
| 222 | + * |
|
| 223 | + * @param EEM_Change_Log $payment_log_model |
|
| 224 | + */ |
|
| 225 | + public function set_payment_log(EEM_Change_Log $payment_log_model) |
|
| 226 | + { |
|
| 227 | + $this->_pay_log = $payment_log_model; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * See this class description |
|
| 233 | + * |
|
| 234 | + * @param EEH_Template $template_helper |
|
| 235 | + */ |
|
| 236 | + public function set_template_helper(EEH_Template $template_helper) |
|
| 237 | + { |
|
| 238 | + $this->_template = $template_helper; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * See this class description |
|
| 244 | + * |
|
| 245 | + * @param EEH_Line_Item $line_item_helper |
|
| 246 | + */ |
|
| 247 | + public function set_line_item_helper(EEH_Line_Item $line_item_helper) |
|
| 248 | + { |
|
| 249 | + $this->_line_item = $line_item_helper; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * See this class description |
|
| 255 | + * |
|
| 256 | + * @param EEH_Money $money_helper |
|
| 257 | + */ |
|
| 258 | + public function set_money_helper(EEH_Money $money_helper) |
|
| 259 | + { |
|
| 260 | + $this->_money = $money_helper; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Sets the gateway data formatter helper |
|
| 266 | + * |
|
| 267 | + * @param GatewayDataFormatterInterface|null $gateway_data_formatter |
|
| 268 | + * @throws InvalidEntityException if it's not set properly |
|
| 269 | + */ |
|
| 270 | + public function set_gateway_data_formatter(?GatewayDataFormatterInterface $gateway_data_formatter) |
|
| 271 | + { |
|
| 272 | + if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
| 273 | + throw new InvalidEntityException( |
|
| 274 | + is_object($gateway_data_formatter) |
|
| 275 | + ? get_class($gateway_data_formatter) |
|
| 276 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 277 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + $this->_gateway_data_formatter = $gateway_data_formatter; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Gets the gateway data formatter |
|
| 286 | + * |
|
| 287 | + * @return GatewayDataFormatterInterface |
|
| 288 | + * @throws InvalidEntityException if it's not set properly |
|
| 289 | + */ |
|
| 290 | + protected function _get_gateway_formatter(): GatewayDataFormatterInterface |
|
| 291 | + { |
|
| 292 | + if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
| 293 | + throw new InvalidEntityException( |
|
| 294 | + is_object($this->_gateway_data_formatter) |
|
| 295 | + ? get_class($this->_gateway_data_formatter) |
|
| 296 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 297 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
| 298 | + ); |
|
| 299 | + } |
|
| 300 | + return $this->_gateway_data_formatter; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Sets the helper which will remove unsupported characters for most gateways |
|
| 306 | + * |
|
| 307 | + * @param FormatterInterface|null $formatter |
|
| 308 | + * @return void |
|
| 309 | + * @throws InvalidEntityException |
|
| 310 | + */ |
|
| 311 | + public function set_unsupported_character_remover(?FormatterInterface $formatter) |
|
| 312 | + { |
|
| 313 | + if (! $formatter instanceof FormatterInterface) { |
|
| 314 | + throw new InvalidEntityException( |
|
| 315 | + is_object($formatter) |
|
| 316 | + ? get_class($formatter) |
|
| 317 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 318 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 319 | + ); |
|
| 320 | + } |
|
| 321 | + $this->_unsupported_character_remover = $formatter; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
| 327 | + * |
|
| 328 | + * @return FormatterInterface |
|
| 329 | + * @throws InvalidEntityException |
|
| 330 | + */ |
|
| 331 | + protected function _get_unsupported_character_remover(): FormatterInterface |
|
| 332 | + { |
|
| 333 | + if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
| 334 | + throw new InvalidEntityException( |
|
| 335 | + is_object($this->_unsupported_character_remover) |
|
| 336 | + ? get_class($this->_unsupported_character_remover) |
|
| 337 | + : esc_html__('Not an object', 'event_espresso'), |
|
| 338 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
| 339 | + ); |
|
| 340 | + } |
|
| 341 | + return $this->_unsupported_character_remover; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @param array|string $message |
|
| 347 | + * @param mixed $object_logged |
|
| 348 | + * @throws EE_Error |
|
| 349 | + * @throws ReflectionException |
|
| 350 | + */ |
|
| 351 | + public function log($message, $object_logged) |
|
| 352 | + { |
|
| 353 | + if ($object_logged instanceof EE_Payment) { |
|
| 354 | + $type = 'Payment'; |
|
| 355 | + $id = $object_logged->ID(); |
|
| 356 | + } elseif ($object_logged instanceof EE_Transaction) { |
|
| 357 | + $type = 'Transaction'; |
|
| 358 | + $id = $object_logged->ID(); |
|
| 359 | + } else { |
|
| 360 | + $type = 'Payment_Method'; |
|
| 361 | + $id = $this->_ID; |
|
| 362 | + } |
|
| 363 | + // only log if we're going to store it for longer than the minimum time |
|
| 364 | + $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
| 365 | + if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
| 366 | + $this->_pay_log->gateway_log($message, $id, $type); |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Formats the amount so it can generally be sent to gateways |
|
| 373 | + * |
|
| 374 | + * @param float $amount |
|
| 375 | + * @return string |
|
| 376 | + * @deprecated since 4.9.31 insetad use |
|
| 377 | + * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
| 378 | + */ |
|
| 379 | + public function format_currency(float $amount): string |
|
| 380 | + { |
|
| 381 | + return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Returns either an array of all the currency codes supported, |
|
| 387 | + * or a string indicating they are all supported (EE_gateway::all_currencies_supported) |
|
| 388 | + * |
|
| 389 | + * @return array|string |
|
| 390 | + */ |
|
| 391 | + public function currencies_supported() |
|
| 392 | + { |
|
| 393 | + return $this->_currencies_supported; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Returns what a simple summing of items and taxes for this transaction. This |
|
| 399 | + * can be used to determine if some more complex line items, like promotions, |
|
| 400 | + * surcharges, or cancellations occurred (in which case we might want to forget |
|
| 401 | + * about creating an itemized list of purchases and instead only send the total due) |
|
| 402 | + * |
|
| 403 | + * @param EE_Transaction $transaction |
|
| 404 | + * @return float |
|
| 405 | + * @throws EE_Error |
|
| 406 | + * @throws ReflectionException |
|
| 407 | + */ |
|
| 408 | + protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
| 409 | + { |
|
| 410 | + $total_line_item = $transaction->total_line_item(); |
|
| 411 | + $total = 0; |
|
| 412 | + foreach ($total_line_item->get_items() as $item_line_item) { |
|
| 413 | + $total += max($item_line_item->total(), 0); |
|
| 414 | + } |
|
| 415 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
| 416 | + $total += max($tax_line_item->total(), 0); |
|
| 417 | + } |
|
| 418 | + return $total; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Determines whether we can easily itemize the transaction using only |
|
| 424 | + * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
| 425 | + * |
|
| 426 | + * @param EE_Payment $payment |
|
| 427 | + * @return boolean |
|
| 428 | + * @throws EE_Error |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + */ |
|
| 431 | + protected function _can_easily_itemize_transaction_for(EE_Payment $payment): bool |
|
| 432 | + { |
|
| 433 | + return $this->_money->compare_floats( |
|
| 434 | + $this->_sum_items_and_taxes($payment->transaction()), |
|
| 435 | + $payment->transaction()->total() |
|
| 436 | + ) |
|
| 437 | + && $this->_money->compare_floats( |
|
| 438 | + $payment->amount(), |
|
| 439 | + $payment->transaction()->total() |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Handles updating the transaction and any other related data based on the payment. |
|
| 446 | + * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
| 447 | + * but doing so on those functions might be too early. It's possible that the changes |
|
| 448 | + * you make to teh transaction or registration or line items may just get overwritten |
|
| 449 | + * at that point. Instead, you should store any info you need on the payment during those |
|
| 450 | + * functions, and use that information at this step, which client code will decide |
|
| 451 | + * for you when it should be called. |
|
| 452 | + * |
|
| 453 | + * @param EE_Payment $payment |
|
| 454 | + * @return void |
|
| 455 | + */ |
|
| 456 | + public function update_txn_based_on_payment($payment) |
|
| 457 | + { |
|
| 458 | + // maybe update the transaction or line items or registrations |
|
| 459 | + // but most gateways don't need to do this, because they only update the payment |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 465 | + * |
|
| 466 | + * @param EE_Payment $payment |
|
| 467 | + * @return EE_Event|null |
|
| 468 | + * @deprecated since 4.9.31 instead use EE_Payment::get_first_event() |
|
| 469 | + */ |
|
| 470 | + protected function _get_first_event_for_payment(EE_Payment $payment): ?EE_Event |
|
| 471 | + { |
|
| 472 | + return $payment->get_first_event(); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * Gets the name of the first event for which is being paid |
|
| 478 | + * |
|
| 479 | + * @param EE_Payment $payment |
|
| 480 | + * @return string |
|
| 481 | + * @deprecated since 4.9.31 instead use EE_Payment::get_first_event_name() |
|
| 482 | + */ |
|
| 483 | + protected function _get_first_event_name_for_payment(EE_Payment $payment): string |
|
| 484 | + { |
|
| 485 | + return $payment->get_first_event_name(); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
| 491 | + * |
|
| 492 | + * @param EE_Payment $payment |
|
| 493 | + * @return string |
|
| 494 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
| 495 | + */ |
|
| 496 | + protected function _format_partial_payment_line_item_name(EE_Payment $payment): string |
|
| 497 | + { |
|
| 498 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
| 504 | + * |
|
| 505 | + * @param EE_Payment $payment |
|
| 506 | + * @return string |
|
| 507 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
| 508 | + */ |
|
| 509 | + protected function _format_partial_payment_line_item_desc(EE_Payment $payment): string |
|
| 510 | + { |
|
| 511 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Gets the name to use for a line item when sending line items to the gateway |
|
| 517 | + * |
|
| 518 | + * @param EE_Line_Item $line_item |
|
| 519 | + * @param EE_Payment $payment |
|
| 520 | + * @return string |
|
| 521 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
| 522 | + */ |
|
| 523 | + protected function _format_line_item_name(EE_Line_Item $line_item, EE_Payment $payment): string |
|
| 524 | + { |
|
| 525 | + return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Gets the description to use for a line item when sending line items to the gateway |
|
| 531 | + * |
|
| 532 | + * @param EE_Line_Item $line_item |
|
| 533 | + * @param EE_Payment $payment |
|
| 534 | + * @return string |
|
| 535 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
| 536 | + */ |
|
| 537 | + protected function _format_line_item_desc(EE_Line_Item $line_item, EE_Payment $payment): string |
|
| 538 | + { |
|
| 539 | + return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * Gets the order description that should generlly be sent to gateways |
|
| 545 | + * |
|
| 546 | + * @param EE_Payment $payment |
|
| 547 | + * @return string |
|
| 548 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
| 549 | + */ |
|
| 550 | + protected function _format_order_description(EE_Payment $payment): string |
|
| 551 | + { |
|
| 552 | + return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * @return bool |
|
| 558 | + */ |
|
| 559 | + public function isInSandboxMode(): bool |
|
| 560 | + { |
|
| 561 | + return $this->_debug_mode; |
|
| 562 | + } |
|
| 563 | 563 | } |
@@ -15,1537 +15,1537 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 17 | 17 | { |
| 18 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Subsections |
|
| 22 | - * |
|
| 23 | - * @var EE_Form_Section_Validatable[] |
|
| 24 | - */ |
|
| 25 | - protected $_subsections = array(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Strategy for laying out the form |
|
| 29 | - * |
|
| 30 | - * @var EE_Form_Section_Layout_Base |
|
| 31 | - */ |
|
| 32 | - protected $_layout_strategy; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Whether or not this form has received and validated a form submission yet |
|
| 36 | - * |
|
| 37 | - * @var boolean |
|
| 38 | - */ |
|
| 39 | - protected $_received_submission = false; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * message displayed to users upon successful form submission |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - protected $_form_submission_success_message = ''; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * message displayed to users upon unsuccessful form submission |
|
| 50 | - * |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $_form_submission_error_message = ''; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var array like post / request |
|
| 57 | - */ |
|
| 58 | - protected $cached_request_data; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 62 | - * Starts off as null, but once the form is validated, it set to either true or false |
|
| 63 | - * @var boolean|null |
|
| 64 | - */ |
|
| 65 | - protected $is_valid; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Stores all the data that will localized for form validation |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - protected static $_js_localization = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * whether or not the form's localized validation JS vars have been set |
|
| 76 | - * |
|
| 77 | - * @type boolean |
|
| 78 | - */ |
|
| 79 | - protected static $_scripts_localized = false; |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 84 | - * so that they know who their parent is, and what name they've been given. |
|
| 85 | - * |
|
| 86 | - * @param array[] $options_array { |
|
| 87 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 88 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 89 | - * and in that order. This is handy if you want |
|
| 90 | - * the subsections to be ordered differently than the default, and if you override |
|
| 91 | - * which fields are shown |
|
| 92 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 93 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 94 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 95 | - * items from that list of inclusions) |
|
| 96 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 97 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 98 | - * @throws EE_Error |
|
| 99 | - */ |
|
| 100 | - public function __construct($options_array = array()) |
|
| 101 | - { |
|
| 102 | - $options_array = (array) apply_filters( |
|
| 103 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 104 | - $options_array, |
|
| 105 | - $this |
|
| 106 | - ); |
|
| 107 | - // call parent first, as it may be setting the name |
|
| 108 | - parent::__construct($options_array); |
|
| 109 | - // if they've included subsections in the constructor, add them now |
|
| 110 | - if (isset($options_array['include'])) { |
|
| 111 | - // we are going to make sure we ONLY have those subsections to include |
|
| 112 | - // AND we are going to make sure they're in that specified order |
|
| 113 | - $reordered_subsections = array(); |
|
| 114 | - foreach ($options_array['include'] as $input_name) { |
|
| 115 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 116 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - $this->_subsections = $reordered_subsections; |
|
| 120 | - } |
|
| 121 | - if (isset($options_array['exclude'])) { |
|
| 122 | - $exclude = $options_array['exclude']; |
|
| 123 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 124 | - } |
|
| 125 | - if (isset($options_array['layout_strategy'])) { |
|
| 126 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 127 | - } |
|
| 128 | - if (! $this->_layout_strategy) { |
|
| 129 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 130 | - } |
|
| 131 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 132 | - // ok so we are definitely going to want the forms JS, |
|
| 133 | - // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 134 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 135 | - // ok so they've constructed this object after when they should have. |
|
| 136 | - // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 137 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 138 | - } else { |
|
| 139 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 141 | - } |
|
| 142 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 143 | - /** |
|
| 144 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 145 | - * The form probably doesn't yet have a parent form section. |
|
| 146 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 147 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 148 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 149 | - * |
|
| 150 | - * @since 4.9.32 |
|
| 151 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 152 | - * except maybe calling _construct_finalize has been done |
|
| 153 | - * @param array $options_array options passed into the constructor |
|
| 154 | - */ |
|
| 155 | - do_action( |
|
| 156 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 157 | - $this, |
|
| 158 | - $options_array |
|
| 159 | - ); |
|
| 160 | - if (isset($options_array['name'])) { |
|
| 161 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Finishes construction given the parent form section and this form section's name |
|
| 168 | - * |
|
| 169 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 170 | - * @param string $name |
|
| 171 | - * @throws EE_Error |
|
| 172 | - */ |
|
| 173 | - public function _construct_finalize($parent_form_section, $name) |
|
| 174 | - { |
|
| 175 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 176 | - $this->_set_default_name_if_empty(); |
|
| 177 | - $this->_set_default_html_id_if_empty(); |
|
| 178 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 179 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 180 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 181 | - } else { |
|
| 182 | - throw new EE_Error( |
|
| 183 | - sprintf( |
|
| 184 | - esc_html__( |
|
| 185 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 186 | - 'event_espresso' |
|
| 187 | - ), |
|
| 188 | - $subsection_name, |
|
| 189 | - get_class($this), |
|
| 190 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - /** |
|
| 196 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 197 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 198 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 199 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 200 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 201 | - * ensured it has a name, HTML IDs, etc |
|
| 202 | - * |
|
| 203 | - * @param EE_Form_Section_Proper $this |
|
| 204 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 205 | - * @param string $name |
|
| 206 | - */ |
|
| 207 | - do_action( |
|
| 208 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 209 | - $this, |
|
| 210 | - $parent_form_section, |
|
| 211 | - $name |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Gets the layout strategy for this form section |
|
| 218 | - * |
|
| 219 | - * @return EE_Form_Section_Layout_Base |
|
| 220 | - */ |
|
| 221 | - public function get_layout_strategy() |
|
| 222 | - { |
|
| 223 | - return $this->_layout_strategy; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Gets the HTML for a single input for this form section according |
|
| 229 | - * to the layout strategy |
|
| 230 | - * |
|
| 231 | - * @param EE_Form_Input_Base $input |
|
| 232 | - * @return string |
|
| 233 | - */ |
|
| 234 | - public function get_html_for_input($input) |
|
| 235 | - { |
|
| 236 | - return $this->_layout_strategy->layout_input($input); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * was_submitted - checks if form inputs are present in request data |
|
| 242 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 243 | - * proper form sections and form inputs) |
|
| 244 | - * |
|
| 245 | - * @param null $form_data |
|
| 246 | - * @return boolean |
|
| 247 | - * @throws EE_Error |
|
| 248 | - */ |
|
| 249 | - public function was_submitted($form_data = null) |
|
| 250 | - { |
|
| 251 | - return $this->form_data_present_in($form_data); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 256 | - * something different, refresh the cache, and then return it |
|
| 257 | - * @param null $req_data |
|
| 258 | - * @return array |
|
| 259 | - */ |
|
| 260 | - protected function getCachedRequest($req_data = null) |
|
| 261 | - { |
|
| 262 | - if ( |
|
| 263 | - $this->cached_request_data === null |
|
| 264 | - || ( |
|
| 265 | - $req_data !== null |
|
| 266 | - && $req_data !== $this->cached_request_data |
|
| 267 | - ) |
|
| 268 | - ) { |
|
| 269 | - $req_data = apply_filters( |
|
| 270 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 271 | - $req_data, |
|
| 272 | - $this |
|
| 273 | - ); |
|
| 274 | - if ($req_data === null) { |
|
| 275 | - /** @var RequestInterface $request */ |
|
| 276 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 277 | - $req_data = $request->requestParams(); |
|
| 278 | - } |
|
| 279 | - $req_data = apply_filters( |
|
| 280 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 281 | - $req_data, |
|
| 282 | - $this |
|
| 283 | - ); |
|
| 284 | - $this->cached_request_data = (array) $req_data; |
|
| 285 | - } |
|
| 286 | - return $this->cached_request_data; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 292 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 293 | - * |
|
| 294 | - * @param array|null $req_data should usually be post data (the default). |
|
| 295 | - * However, you CAN supply a different array. |
|
| 296 | - * Consider using set_defaults() instead however. |
|
| 297 | - * (If you rendered the form in the page using $form_x->get_html() |
|
| 298 | - * the inputs will have the correct name in the request data for this function |
|
| 299 | - * to find them and populate the form with them. |
|
| 300 | - * If you have a flat form (with only input subsections), |
|
| 301 | - * you can supply a flat array where keys |
|
| 302 | - * are the form input names and values are their values) |
|
| 303 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 304 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 305 | - * But if the data has already been validated |
|
| 306 | - * (eg you validated the data then stored it in the DB) |
|
| 307 | - * you may want to skip this step. |
|
| 308 | - * @throws InvalidArgumentException |
|
| 309 | - * @throws InvalidInterfaceException |
|
| 310 | - * @throws InvalidDataTypeException |
|
| 311 | - * @throws EE_Error |
|
| 312 | - */ |
|
| 313 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 314 | - { |
|
| 315 | - $req_data = $this->getCachedRequest($req_data); |
|
| 316 | - $this->_normalize($req_data); |
|
| 317 | - if ($validate) { |
|
| 318 | - $this->_validate(); |
|
| 319 | - // if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 320 | - if (! $this->is_valid()) { |
|
| 321 | - $this->store_submitted_form_data_in_session(); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 325 | - $this->set_submission_error_message(); |
|
| 326 | - } |
|
| 327 | - do_action( |
|
| 328 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 329 | - $req_data, |
|
| 330 | - $this, |
|
| 331 | - $validate |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * caches the originally submitted input values in the session |
|
| 338 | - * so that they can be used to repopulate the form if it failed validation |
|
| 339 | - * |
|
| 340 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidInterfaceException |
|
| 343 | - * @throws InvalidDataTypeException |
|
| 344 | - * @throws EE_Error |
|
| 345 | - */ |
|
| 346 | - protected function store_submitted_form_data_in_session() |
|
| 347 | - { |
|
| 348 | - $session = EE_Registry::instance()->SSN; |
|
| 349 | - if ($session instanceof EE_Session) { |
|
| 350 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 351 | - [ |
|
| 352 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 353 | - ] |
|
| 354 | - ); |
|
| 355 | - } |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * retrieves the originally submitted input values in the session |
|
| 362 | - * so that they can be used to repopulate the form if it failed validation |
|
| 363 | - * |
|
| 364 | - * @return array |
|
| 365 | - * @throws InvalidArgumentException |
|
| 366 | - * @throws InvalidInterfaceException |
|
| 367 | - * @throws InvalidDataTypeException |
|
| 368 | - */ |
|
| 369 | - protected function get_submitted_form_data_from_session() |
|
| 370 | - { |
|
| 371 | - $session = EE_Registry::instance()->SSN; |
|
| 372 | - if ($session instanceof EE_Session) { |
|
| 373 | - return $session->get_session_data( |
|
| 374 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 375 | - ); |
|
| 376 | - } |
|
| 377 | - return array(); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * flushed the originally submitted input values from the session |
|
| 383 | - * |
|
| 384 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 385 | - * @throws InvalidArgumentException |
|
| 386 | - * @throws InvalidInterfaceException |
|
| 387 | - * @throws InvalidDataTypeException |
|
| 388 | - */ |
|
| 389 | - public static function flush_submitted_form_data_from_session() |
|
| 390 | - { |
|
| 391 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 392 | - [EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY] |
|
| 393 | - ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Populates this form and its subsections with data from the session. |
|
| 399 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 400 | - * validation errors when displaying too) |
|
| 401 | - * Returns true if the form was populated from the session, false otherwise |
|
| 402 | - * |
|
| 403 | - * @return boolean |
|
| 404 | - * @throws InvalidArgumentException |
|
| 405 | - * @throws InvalidInterfaceException |
|
| 406 | - * @throws InvalidDataTypeException |
|
| 407 | - * @throws EE_Error |
|
| 408 | - */ |
|
| 409 | - public function populate_from_session() |
|
| 410 | - { |
|
| 411 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 412 | - if (empty($form_data_in_session)) { |
|
| 413 | - return false; |
|
| 414 | - } |
|
| 415 | - $this->receive_form_submission($form_data_in_session); |
|
| 416 | - add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
| 417 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 418 | - return true; |
|
| 419 | - } |
|
| 420 | - return false; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Populates the default data for the form, given an array where keys are |
|
| 426 | - * the input names, and values are their values (preferably normalized to be their |
|
| 427 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 428 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 429 | - * the value being an array formatted in teh same way |
|
| 430 | - * |
|
| 431 | - * @param array $default_data |
|
| 432 | - * @throws EE_Error |
|
| 433 | - */ |
|
| 434 | - public function populate_defaults($default_data) |
|
| 435 | - { |
|
| 436 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 437 | - if (isset($default_data[ $subsection_name ])) { |
|
| 438 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 439 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 440 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 441 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * returns true if subsection exists |
|
| 450 | - * |
|
| 451 | - * @param string $name |
|
| 452 | - * @return boolean |
|
| 453 | - */ |
|
| 454 | - public function subsection_exists($name) |
|
| 455 | - { |
|
| 456 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Gets the subsection specified by its name |
|
| 462 | - * |
|
| 463 | - * @param string $name |
|
| 464 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 465 | - * so that the inputs will be properly configured. |
|
| 466 | - * However, some client code may be ok |
|
| 467 | - * with construction finalize being called later |
|
| 468 | - * (realizing that the subsections' html names |
|
| 469 | - * might not be set yet, etc.) |
|
| 470 | - * @return EE_Form_Section_Base |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 474 | - { |
|
| 475 | - if ($require_construction_to_be_finalized) { |
|
| 476 | - $this->ensure_construct_finalized_called(); |
|
| 477 | - } |
|
| 478 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Gets all the validatable subsections of this form section |
|
| 484 | - * |
|
| 485 | - * @return EE_Form_Section_Validatable[] |
|
| 486 | - * @throws EE_Error |
|
| 487 | - */ |
|
| 488 | - public function get_validatable_subsections() |
|
| 489 | - { |
|
| 490 | - $validatable_subsections = array(); |
|
| 491 | - foreach ($this->subsections() as $name => $obj) { |
|
| 492 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 493 | - $validatable_subsections[ $name ] = $obj; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $validatable_subsections; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 502 | - * throw an EE_Error. |
|
| 503 | - * |
|
| 504 | - * @param string $name |
|
| 505 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 506 | - * leave this as TRUE so that the inputs will be properly |
|
| 507 | - * configured. However, some client code may be ok with |
|
| 508 | - * construction finalize being called later |
|
| 509 | - * (realizing that the subsections' html names might not be |
|
| 510 | - * set yet, etc.) |
|
| 511 | - * @return EE_Form_Input_Base |
|
| 512 | - * @throws EE_Error |
|
| 513 | - */ |
|
| 514 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 515 | - { |
|
| 516 | - $subsection = $this->get_subsection( |
|
| 517 | - $name, |
|
| 518 | - $require_construction_to_be_finalized |
|
| 519 | - ); |
|
| 520 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 521 | - throw new EE_Error( |
|
| 522 | - sprintf( |
|
| 523 | - esc_html__( |
|
| 524 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 525 | - 'event_espresso' |
|
| 526 | - ), |
|
| 527 | - $name, |
|
| 528 | - get_class($this), |
|
| 529 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 530 | - ) |
|
| 531 | - ); |
|
| 532 | - } |
|
| 533 | - return $subsection; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 539 | - * otherwise throws an EE_Error |
|
| 540 | - * |
|
| 541 | - * @param string $name |
|
| 542 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 543 | - * leave this as TRUE so that the inputs will be properly |
|
| 544 | - * configured. However, some client code may be ok with |
|
| 545 | - * construction finalize being called later |
|
| 546 | - * (realizing that the subsections' html names might not be |
|
| 547 | - * set yet, etc.) |
|
| 548 | - * @return EE_Form_Section_Proper |
|
| 549 | - * @throws EE_Error |
|
| 550 | - */ |
|
| 551 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 552 | - { |
|
| 553 | - $subsection = $this->get_subsection( |
|
| 554 | - $name, |
|
| 555 | - $require_construction_to_be_finalized |
|
| 556 | - ); |
|
| 557 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 558 | - throw new EE_Error( |
|
| 559 | - sprintf( |
|
| 560 | - esc_html__( |
|
| 561 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 562 | - 'event_espresso' |
|
| 563 | - ), |
|
| 564 | - $name, |
|
| 565 | - get_class($this) |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - } |
|
| 569 | - return $subsection; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 575 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 576 | - * |
|
| 577 | - * @param string $name |
|
| 578 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 579 | - * @throws EE_Error |
|
| 580 | - */ |
|
| 581 | - public function get_input_value($name) |
|
| 582 | - { |
|
| 583 | - $input = $this->get_input($name); |
|
| 584 | - return $input->normalized_value(); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 590 | - * |
|
| 591 | - * @throws EE_Error |
|
| 592 | - * @return boolean |
|
| 593 | - */ |
|
| 594 | - public function is_valid() |
|
| 595 | - { |
|
| 596 | - if ($this->is_valid === null) { |
|
| 597 | - if (! $this->has_received_submission()) { |
|
| 598 | - throw new EE_Error( |
|
| 599 | - sprintf( |
|
| 600 | - esc_html__( |
|
| 601 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 602 | - 'event_espresso' |
|
| 603 | - ) |
|
| 604 | - ) |
|
| 605 | - ); |
|
| 606 | - } |
|
| 607 | - if (! parent::is_valid()) { |
|
| 608 | - $this->is_valid = false; |
|
| 609 | - } else { |
|
| 610 | - // ok so no general errors to this entire form section. |
|
| 611 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 612 | - $this->is_valid = true; |
|
| 613 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 614 | - if (! $subsection->is_valid()) { |
|
| 615 | - $this->is_valid = false; |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - return $this->is_valid; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * gets the default name of this form section if none is specified |
|
| 626 | - * |
|
| 627 | - * @return void |
|
| 628 | - */ |
|
| 629 | - protected function _set_default_name_if_empty() |
|
| 630 | - { |
|
| 631 | - if (! $this->_name) { |
|
| 632 | - $classname = get_class($this); |
|
| 633 | - $default_name = str_replace('EE_', '', $classname); |
|
| 634 | - $this->_name = $default_name; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 641 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 642 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 643 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 644 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 645 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 646 | - * any CSS. |
|
| 647 | - * |
|
| 648 | - * @throws InvalidArgumentException |
|
| 649 | - * @throws InvalidInterfaceException |
|
| 650 | - * @throws InvalidDataTypeException |
|
| 651 | - * @throws EE_Error |
|
| 652 | - */ |
|
| 653 | - public function get_html_and_js() |
|
| 654 | - { |
|
| 655 | - $this->enqueue_js(); |
|
| 656 | - return $this->get_html(); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 662 | - * |
|
| 663 | - * @param bool $display_previously_submitted_data |
|
| 664 | - * @return string |
|
| 665 | - * @throws InvalidArgumentException |
|
| 666 | - * @throws InvalidInterfaceException |
|
| 667 | - * @throws InvalidDataTypeException |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws EE_Error |
|
| 670 | - * @throws EE_Error |
|
| 671 | - */ |
|
| 672 | - public function get_html($display_previously_submitted_data = true) |
|
| 673 | - { |
|
| 674 | - $this->ensure_construct_finalized_called(); |
|
| 675 | - if ($display_previously_submitted_data) { |
|
| 676 | - $this->populate_from_session(); |
|
| 677 | - } |
|
| 678 | - return $this->_form_html_filter |
|
| 679 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 680 | - : $this->_layout_strategy->layout_form(); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * enqueues JS and CSS for the form. |
|
| 686 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 687 | - * scripts and styles can be put in the header, but if called later |
|
| 688 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 689 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 690 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 691 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 692 | - * |
|
| 693 | - * @return void |
|
| 694 | - * @throws EE_Error |
|
| 695 | - */ |
|
| 696 | - public function enqueue_js() |
|
| 697 | - { |
|
| 698 | - $this->_enqueue_and_localize_form_js(); |
|
| 699 | - foreach ($this->subsections() as $subsection) { |
|
| 700 | - $subsection->enqueue_js(); |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 707 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 708 | - * the wp_enqueue_scripts hook. |
|
| 709 | - * However, registering the form js and localizing it can happen when we |
|
| 710 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 711 | - * could change until it's actually outputted) |
|
| 712 | - * |
|
| 713 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 714 | - * to be triggered automatically or not |
|
| 715 | - * @return void |
|
| 716 | - */ |
|
| 717 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 718 | - { |
|
| 719 | - wp_register_script( |
|
| 720 | - 'ee_form_section_validation', |
|
| 721 | - EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
| 722 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 723 | - EVENT_ESPRESSO_VERSION, |
|
| 724 | - true |
|
| 725 | - ); |
|
| 726 | - wp_localize_script( |
|
| 727 | - 'ee_form_section_validation', |
|
| 728 | - 'ee_form_section_validation_init', |
|
| 729 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 730 | - ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * gets the variables used by form_section_validation.js. |
|
| 736 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 737 | - * but before the wordpress hook wp_loaded |
|
| 738 | - * |
|
| 739 | - * @throws EE_Error |
|
| 740 | - */ |
|
| 741 | - public function _enqueue_and_localize_form_js() |
|
| 742 | - { |
|
| 743 | - $this->ensure_construct_finalized_called(); |
|
| 744 | - // actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 745 | - // so we need to add our form section data to a static variable accessible by all form sections |
|
| 746 | - // and localize it just before the footer |
|
| 747 | - $this->localize_validation_rules(); |
|
| 748 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 749 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * add our form section data to a static variable accessible by all form sections |
|
| 755 | - * |
|
| 756 | - * @param bool $return_for_subsection |
|
| 757 | - * @return void |
|
| 758 | - * @throws EE_Error |
|
| 759 | - */ |
|
| 760 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 761 | - { |
|
| 762 | - // we only want to localize vars ONCE for the entire form, |
|
| 763 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 764 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 765 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 766 | - 'form_section_id' => $this->html_id(true), |
|
| 767 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 768 | - 'other_data' => $this->get_other_js_data(), |
|
| 769 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 770 | - ); |
|
| 771 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 778 | - * This is primarily data added by inputs and forms in addition to any |
|
| 779 | - * scripts they might enqueue |
|
| 780 | - * |
|
| 781 | - * @param array $form_other_js_data |
|
| 782 | - * @return array |
|
| 783 | - * @throws EE_Error |
|
| 784 | - */ |
|
| 785 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 786 | - { |
|
| 787 | - foreach ($this->subsections() as $subsection) { |
|
| 788 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 789 | - } |
|
| 790 | - return $form_other_js_data; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 796 | - * Keys are their form names, and values are the inputs themselves |
|
| 797 | - * |
|
| 798 | - * @return EE_Form_Input_Base |
|
| 799 | - * @throws EE_Error |
|
| 800 | - */ |
|
| 801 | - public function inputs_in_subsections() |
|
| 802 | - { |
|
| 803 | - $inputs = array(); |
|
| 804 | - foreach ($this->subsections() as $subsection) { |
|
| 805 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 806 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 807 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 808 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - return $inputs; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Gets a flat array of all the validation errors. |
|
| 817 | - * Keys are html names (because those should be unique) |
|
| 818 | - * and values are a string of all their validation errors |
|
| 819 | - * |
|
| 820 | - * @return string[] |
|
| 821 | - * @throws EE_Error |
|
| 822 | - */ |
|
| 823 | - public function subsection_validation_errors_by_html_name() |
|
| 824 | - { |
|
| 825 | - $inputs = $this->inputs(); |
|
| 826 | - $errors = array(); |
|
| 827 | - foreach ($inputs as $form_input) { |
|
| 828 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 829 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - return $errors; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 838 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 839 | - * |
|
| 840 | - * @throws InvalidArgumentException |
|
| 841 | - * @throws InvalidInterfaceException |
|
| 842 | - * @throws InvalidDataTypeException |
|
| 843 | - */ |
|
| 844 | - public static function localize_script_for_all_forms() |
|
| 845 | - { |
|
| 846 | - // allow inputs and stuff to hook in their JS and stuff here |
|
| 847 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 848 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 849 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 850 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 851 | - : 'wp_default'; |
|
| 852 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 853 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 854 | - wp_localize_script( |
|
| 855 | - 'ee_form_section_validation', |
|
| 856 | - 'ee_form_section_vars', |
|
| 857 | - EE_Form_Section_Proper::$_js_localization |
|
| 858 | - ); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * ensure_scripts_localized |
|
| 864 | - * |
|
| 865 | - * @throws EE_Error |
|
| 866 | - */ |
|
| 867 | - public function ensure_scripts_localized() |
|
| 868 | - { |
|
| 869 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 870 | - $this->_enqueue_and_localize_form_js(); |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 877 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 878 | - * |
|
| 879 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 880 | - */ |
|
| 881 | - private static function _get_localized_error_messages() |
|
| 882 | - { |
|
| 883 | - return array( |
|
| 884 | - 'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')), |
|
| 885 | - 'regex' => wp_strip_all_tags(__('Please check your input', 'event_espresso')) |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * @return array |
|
| 892 | - */ |
|
| 893 | - public static function js_localization() |
|
| 894 | - { |
|
| 895 | - return self::$_js_localization; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * @return void |
|
| 901 | - */ |
|
| 902 | - public static function reset_js_localization() |
|
| 903 | - { |
|
| 904 | - self::$_js_localization = array(); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 910 | - * See parent function for more... |
|
| 911 | - * |
|
| 912 | - * @return array |
|
| 913 | - * @throws EE_Error |
|
| 914 | - */ |
|
| 915 | - public function get_jquery_validation_rules() |
|
| 916 | - { |
|
| 917 | - $jquery_validation_rules = array(); |
|
| 918 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 919 | - $jquery_validation_rules = array_merge( |
|
| 920 | - $jquery_validation_rules, |
|
| 921 | - $subsection->get_jquery_validation_rules() |
|
| 922 | - ); |
|
| 923 | - } |
|
| 924 | - return $jquery_validation_rules; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 930 | - * |
|
| 931 | - * @param array $req_data |
|
| 932 | - * @return void |
|
| 933 | - * @throws EE_Error |
|
| 934 | - */ |
|
| 935 | - protected function _normalize($req_data) |
|
| 936 | - { |
|
| 937 | - $this->_received_submission = true; |
|
| 938 | - $this->_validation_errors = array(); |
|
| 939 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 940 | - try { |
|
| 941 | - $subsection->_normalize($req_data); |
|
| 942 | - } catch (EE_Validation_Error $e) { |
|
| 943 | - $subsection->add_validation_error($e); |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * Performs validation on this form section and its subsections. |
|
| 951 | - * For each subsection, |
|
| 952 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 953 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 954 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 955 | - * you would be best to override this _validate method, |
|
| 956 | - * calling parent::_validate() first. |
|
| 957 | - * |
|
| 958 | - * @throws EE_Error |
|
| 959 | - */ |
|
| 960 | - protected function _validate() |
|
| 961 | - { |
|
| 962 | - // reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 963 | - $this->is_valid = null; |
|
| 964 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 965 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 966 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 967 | - } |
|
| 968 | - $subsection->_validate(); |
|
| 969 | - } |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - /** |
|
| 974 | - * Gets all the validated inputs for the form section |
|
| 975 | - * |
|
| 976 | - * @return array |
|
| 977 | - * @throws EE_Error |
|
| 978 | - */ |
|
| 979 | - public function valid_data() |
|
| 980 | - { |
|
| 981 | - $inputs = array(); |
|
| 982 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 983 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 984 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 985 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 986 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - return $inputs; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * Gets all the inputs on this form section |
|
| 995 | - * |
|
| 996 | - * @return EE_Form_Input_Base[] |
|
| 997 | - * @throws EE_Error |
|
| 998 | - */ |
|
| 999 | - public function inputs() |
|
| 1000 | - { |
|
| 1001 | - $inputs = array(); |
|
| 1002 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1003 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1004 | - $inputs[ $subsection_name ] = $subsection; |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - return $inputs; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * Gets all the subsections which are a proper form |
|
| 1013 | - * |
|
| 1014 | - * @return EE_Form_Section_Proper[] |
|
| 1015 | - * @throws EE_Error |
|
| 1016 | - */ |
|
| 1017 | - public function subforms() |
|
| 1018 | - { |
|
| 1019 | - $form_sections = array(); |
|
| 1020 | - foreach ($this->subsections() as $name => $obj) { |
|
| 1021 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1022 | - $form_sections[ $name ] = $obj; |
|
| 1023 | - } |
|
| 1024 | - } |
|
| 1025 | - return $form_sections; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - |
|
| 1029 | - /** |
|
| 1030 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1031 | - * Consider using inputs() or subforms() |
|
| 1032 | - * if you only want form inputs or proper form sections. |
|
| 1033 | - * |
|
| 1034 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1035 | - * leave this as TRUE so that the inputs will be properly |
|
| 1036 | - * configured. However, some client code may be ok with |
|
| 1037 | - * construction finalize being called later |
|
| 1038 | - * (realizing that the subsections' html names might not be |
|
| 1039 | - * set yet, etc.) |
|
| 1040 | - * @return EE_Form_Section_Proper[] |
|
| 1041 | - * @throws EE_Error |
|
| 1042 | - */ |
|
| 1043 | - public function subsections($require_construction_to_be_finalized = true) |
|
| 1044 | - { |
|
| 1045 | - if ($require_construction_to_be_finalized) { |
|
| 1046 | - $this->ensure_construct_finalized_called(); |
|
| 1047 | - } |
|
| 1048 | - return $this->_subsections; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * Returns whether this form has any subforms or inputs |
|
| 1054 | - * @return bool |
|
| 1055 | - */ |
|
| 1056 | - public function hasSubsections() |
|
| 1057 | - { |
|
| 1058 | - return ! empty($this->_subsections); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - |
|
| 1062 | - /** |
|
| 1063 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 1064 | - * values. (Similar to calling get_input_value on inputs) |
|
| 1065 | - * |
|
| 1066 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1067 | - * or just this forms' direct children inputs |
|
| 1068 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1069 | - * or allow multidimensional array |
|
| 1070 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1071 | - * with array keys being input names |
|
| 1072 | - * (regardless of whether they are from a subsection or not), |
|
| 1073 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1074 | - * where keys are always subsection names and values are either |
|
| 1075 | - * the input's normalized value, or an array like the top-level array |
|
| 1076 | - * @throws EE_Error |
|
| 1077 | - */ |
|
| 1078 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1079 | - { |
|
| 1080 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - /** |
|
| 1085 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1086 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1087 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 1088 | - * where keys are the input names, and values are their display values |
|
| 1089 | - * |
|
| 1090 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1091 | - * or just this forms' direct children inputs |
|
| 1092 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1093 | - * or allow multidimensional array |
|
| 1094 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1095 | - * with array keys being input names |
|
| 1096 | - * (regardless of whether they are from a subsection or not), |
|
| 1097 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1098 | - * where keys are always subsection names and values are either |
|
| 1099 | - * the input's normalized value, or an array like the top-level array |
|
| 1100 | - * @throws EE_Error |
|
| 1101 | - */ |
|
| 1102 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1103 | - { |
|
| 1104 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Gets the input values from the form |
|
| 1110 | - * |
|
| 1111 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1112 | - * or just the normalized value |
|
| 1113 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1114 | - * or just this forms' direct children inputs |
|
| 1115 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1116 | - * or allow multidimensional array |
|
| 1117 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1118 | - * input names (regardless of whether they are from a subsection or not), |
|
| 1119 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1120 | - * where keys are always subsection names and values are either |
|
| 1121 | - * the input's normalized value, or an array like the top-level array |
|
| 1122 | - * @throws EE_Error |
|
| 1123 | - */ |
|
| 1124 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1125 | - { |
|
| 1126 | - $input_values = array(); |
|
| 1127 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1128 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1129 | - $input_values[ $subsection_name ] = $pretty |
|
| 1130 | - ? $subsection->pretty_value() |
|
| 1131 | - : $subsection->normalized_value(); |
|
| 1132 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1133 | - $subform_input_values = $subsection->_input_values( |
|
| 1134 | - $pretty, |
|
| 1135 | - $include_subform_inputs, |
|
| 1136 | - $flatten |
|
| 1137 | - ); |
|
| 1138 | - if ($flatten) { |
|
| 1139 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1140 | - } else { |
|
| 1141 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - return $input_values; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Gets the originally submitted input values from the form |
|
| 1151 | - * |
|
| 1152 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1153 | - * or just this forms' direct children inputs |
|
| 1154 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1155 | - * with array keys being input names |
|
| 1156 | - * (regardless of whether they are from a subsection or not), |
|
| 1157 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1158 | - * where keys are always subsection names and values are either |
|
| 1159 | - * the input's normalized value, or an array like the top-level array |
|
| 1160 | - * @throws EE_Error |
|
| 1161 | - */ |
|
| 1162 | - public function submitted_values($include_subforms = false) |
|
| 1163 | - { |
|
| 1164 | - $submitted_values = array(); |
|
| 1165 | - foreach ($this->subsections() as $subsection) { |
|
| 1166 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1167 | - // is this input part of an array of inputs? |
|
| 1168 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1169 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1170 | - explode( |
|
| 1171 | - '[', |
|
| 1172 | - str_replace(']', '', $subsection->html_name()) |
|
| 1173 | - ), |
|
| 1174 | - $subsection->raw_value() |
|
| 1175 | - ); |
|
| 1176 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1177 | - } else { |
|
| 1178 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1179 | - } |
|
| 1180 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1181 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1182 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1185 | - return $submitted_values; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - |
|
| 1189 | - /** |
|
| 1190 | - * Indicates whether or not this form has received a submission yet |
|
| 1191 | - * (ie, had receive_form_submission called on it yet) |
|
| 1192 | - * |
|
| 1193 | - * @return boolean |
|
| 1194 | - * @throws EE_Error |
|
| 1195 | - */ |
|
| 1196 | - public function has_received_submission() |
|
| 1197 | - { |
|
| 1198 | - $this->ensure_construct_finalized_called(); |
|
| 1199 | - return $this->_received_submission; |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - |
|
| 1203 | - /** |
|
| 1204 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1205 | - * Removes the listed inputs from the form |
|
| 1206 | - * |
|
| 1207 | - * @param array $inputs_to_exclude values are the input names |
|
| 1208 | - * @return void |
|
| 1209 | - */ |
|
| 1210 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1211 | - { |
|
| 1212 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1213 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1220 | - * @param array $inputs_to_hide |
|
| 1221 | - * @throws EE_Error |
|
| 1222 | - */ |
|
| 1223 | - public function hide(array $inputs_to_hide = array()) |
|
| 1224 | - { |
|
| 1225 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1226 | - $input = $this->get_input($input_to_hide); |
|
| 1227 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * add_subsections |
|
| 1234 | - * Adds the listed subsections to the form section. |
|
| 1235 | - * If $subsection_name_to_target is provided, |
|
| 1236 | - * then new subsections are added before or after that subsection, |
|
| 1237 | - * otherwise to the start or end of the entire subsections array. |
|
| 1238 | - * |
|
| 1239 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1240 | - * where keys are their names |
|
| 1241 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1242 | - * should be added before or after |
|
| 1243 | - * IF $subsection_name_to_target is null, |
|
| 1244 | - * then $new_subsections will be added to |
|
| 1245 | - * the beginning or end of the entire subsections array |
|
| 1246 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1247 | - * $subsection_name_to_target, |
|
| 1248 | - * or if $subsection_name_to_target is null, |
|
| 1249 | - * before or after entire subsections array |
|
| 1250 | - * @return void |
|
| 1251 | - * @throws EE_Error |
|
| 1252 | - */ |
|
| 1253 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1254 | - { |
|
| 1255 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1256 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1257 | - EE_Error::add_error( |
|
| 1258 | - sprintf( |
|
| 1259 | - esc_html__( |
|
| 1260 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1261 | - 'event_espresso' |
|
| 1262 | - ), |
|
| 1263 | - get_class($subsection), |
|
| 1264 | - $subsection_name, |
|
| 1265 | - $this->name() |
|
| 1266 | - ), |
|
| 1267 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1268 | - ); |
|
| 1269 | - unset($new_subsections[ $subsection_name ]); |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1273 | - $this->_subsections, |
|
| 1274 | - $new_subsections, |
|
| 1275 | - $subsection_name_to_target, |
|
| 1276 | - $add_before |
|
| 1277 | - ); |
|
| 1278 | - if ($this->_construction_finalized) { |
|
| 1279 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1280 | - $subsection->_construct_finalize($this, $name); |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - |
|
| 1286 | - /** |
|
| 1287 | - * @param string $subsection_name |
|
| 1288 | - * @param bool $recursive |
|
| 1289 | - * @return bool |
|
| 1290 | - */ |
|
| 1291 | - public function has_subsection($subsection_name, $recursive = false) |
|
| 1292 | - { |
|
| 1293 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1294 | - if ( |
|
| 1295 | - $name === $subsection_name |
|
| 1296 | - || ( |
|
| 1297 | - $recursive |
|
| 1298 | - && $subsection instanceof EE_Form_Section_Proper |
|
| 1299 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1300 | - ) |
|
| 1301 | - ) { |
|
| 1302 | - return true; |
|
| 1303 | - } |
|
| 1304 | - } |
|
| 1305 | - return false; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1312 | - * |
|
| 1313 | - * @throws EE_Error |
|
| 1314 | - */ |
|
| 1315 | - public function clean_sensitive_data() |
|
| 1316 | - { |
|
| 1317 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1318 | - $subsection->clean_sensitive_data(); |
|
| 1319 | - } |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - |
|
| 1323 | - /** |
|
| 1324 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1325 | - * @param string $form_submission_error_message |
|
| 1326 | - * @param EE_Form_Section_Validatable $form_section unused |
|
| 1327 | - * @throws EE_Error |
|
| 1328 | - */ |
|
| 1329 | - public function set_submission_error_message( |
|
| 1330 | - $form_submission_error_message = '' |
|
| 1331 | - ) { |
|
| 1332 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1333 | - ? $form_submission_error_message |
|
| 1334 | - : $this->getAllValidationErrorsString(); |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - |
|
| 1338 | - /** |
|
| 1339 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1340 | - * (called during receive_form_submission) but it can be explicitly set using |
|
| 1341 | - * set_submission_error_message |
|
| 1342 | - * |
|
| 1343 | - * @return string |
|
| 1344 | - */ |
|
| 1345 | - public function submission_error_message() |
|
| 1346 | - { |
|
| 1347 | - return $this->_form_submission_error_message; |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * Sets a message to display if the data submitted to the form was valid. |
|
| 1353 | - * @param string $form_submission_success_message |
|
| 1354 | - */ |
|
| 1355 | - public function set_submission_success_message($form_submission_success_message = '') |
|
| 1356 | - { |
|
| 1357 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1358 | - ? $form_submission_success_message |
|
| 1359 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * Gets a message appropriate for display when the form is correctly submitted |
|
| 1365 | - * @return string |
|
| 1366 | - */ |
|
| 1367 | - public function submission_success_message() |
|
| 1368 | - { |
|
| 1369 | - return $this->_form_submission_success_message; |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * Returns the prefix that should be used on child of this form section for |
|
| 1375 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1376 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1377 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1378 | - * |
|
| 1379 | - * @return string |
|
| 1380 | - * @throws EE_Error |
|
| 1381 | - */ |
|
| 1382 | - public function html_name_prefix() |
|
| 1383 | - { |
|
| 1384 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1385 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1386 | - } |
|
| 1387 | - return $this->name(); |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - |
|
| 1391 | - /** |
|
| 1392 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1393 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1394 | - * was set, which is probably nothing, or the classname) |
|
| 1395 | - * |
|
| 1396 | - * @return string |
|
| 1397 | - * @throws EE_Error |
|
| 1398 | - */ |
|
| 1399 | - public function name() |
|
| 1400 | - { |
|
| 1401 | - $this->ensure_construct_finalized_called(); |
|
| 1402 | - return parent::name(); |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * @return EE_Form_Section_Proper |
|
| 1408 | - * @throws EE_Error |
|
| 1409 | - */ |
|
| 1410 | - public function parent_section() |
|
| 1411 | - { |
|
| 1412 | - $this->ensure_construct_finalized_called(); |
|
| 1413 | - return parent::parent_section(); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1419 | - * |
|
| 1420 | - * @return void |
|
| 1421 | - * @throws EE_Error |
|
| 1422 | - */ |
|
| 1423 | - public function ensure_construct_finalized_called() |
|
| 1424 | - { |
|
| 1425 | - if (! $this->_construction_finalized) { |
|
| 1426 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1427 | - } |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - |
|
| 1431 | - /** |
|
| 1432 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1433 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1434 | - * |
|
| 1435 | - * @param array $req_data |
|
| 1436 | - * @return boolean |
|
| 1437 | - * @throws EE_Error |
|
| 1438 | - */ |
|
| 1439 | - public function form_data_present_in($req_data = null) |
|
| 1440 | - { |
|
| 1441 | - $req_data = $this->getCachedRequest($req_data); |
|
| 1442 | - foreach ($this->subsections() as $subsection) { |
|
| 1443 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1444 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1445 | - return true; |
|
| 1446 | - } |
|
| 1447 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1448 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1449 | - return true; |
|
| 1450 | - } |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - return false; |
|
| 1454 | - } |
|
| 1455 | - |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * Gets validation errors for this form section and subsections |
|
| 1459 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1460 | - * gets the validation errors for ALL subsection |
|
| 1461 | - * |
|
| 1462 | - * @return EE_Validation_Error[] |
|
| 1463 | - * @throws EE_Error |
|
| 1464 | - */ |
|
| 1465 | - public function get_validation_errors_accumulated() |
|
| 1466 | - { |
|
| 1467 | - $validation_errors = $this->get_validation_errors(); |
|
| 1468 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1469 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1470 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1471 | - } else { |
|
| 1472 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1473 | - } |
|
| 1474 | - if ($validation_errors_on_this_subsection) { |
|
| 1475 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1476 | - } |
|
| 1477 | - } |
|
| 1478 | - return $validation_errors; |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1483 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1484 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1485 | - * |
|
| 1486 | - * @return string |
|
| 1487 | - * @since 4.9.59.p |
|
| 1488 | - */ |
|
| 1489 | - protected function getAllValidationErrorsString() |
|
| 1490 | - { |
|
| 1491 | - $submission_error_messages = array(); |
|
| 1492 | - // bad, bad, bad registrant |
|
| 1493 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1494 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1495 | - $form_section = $validation_error->get_form_section(); |
|
| 1496 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1497 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1498 | - } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1499 | - $label = $validation_error->get_form_section()->name(); |
|
| 1500 | - } else { |
|
| 1501 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1502 | - } |
|
| 1503 | - $submission_error_messages[] = sprintf( |
|
| 1504 | - esc_html__('%s : %s', 'event_espresso'), |
|
| 1505 | - $label, |
|
| 1506 | - $validation_error->getMessage() |
|
| 1507 | - ); |
|
| 1508 | - } |
|
| 1509 | - } |
|
| 1510 | - return implode('<br>', $submission_error_messages); |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1516 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1517 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1518 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1519 | - * which will be returned. |
|
| 1520 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1521 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1522 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1523 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1524 | - * Etc |
|
| 1525 | - * |
|
| 1526 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1527 | - * @return EE_Form_Section_Base |
|
| 1528 | - * @throws EE_Error |
|
| 1529 | - */ |
|
| 1530 | - public function find_section_from_path($form_section_path) |
|
| 1531 | - { |
|
| 1532 | - // check if we can find the input from purely going straight up the tree |
|
| 1533 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1534 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1535 | - return $input; |
|
| 1536 | - } |
|
| 1537 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1538 | - if ($next_slash_pos !== false) { |
|
| 1539 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1540 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1541 | - } else { |
|
| 1542 | - $child_section_name = $form_section_path; |
|
| 1543 | - $subpath = ''; |
|
| 1544 | - } |
|
| 1545 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1546 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1547 | - return $child_section->find_section_from_path($subpath); |
|
| 1548 | - } |
|
| 1549 | - return null; |
|
| 1550 | - } |
|
| 18 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Subsections |
|
| 22 | + * |
|
| 23 | + * @var EE_Form_Section_Validatable[] |
|
| 24 | + */ |
|
| 25 | + protected $_subsections = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Strategy for laying out the form |
|
| 29 | + * |
|
| 30 | + * @var EE_Form_Section_Layout_Base |
|
| 31 | + */ |
|
| 32 | + protected $_layout_strategy; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Whether or not this form has received and validated a form submission yet |
|
| 36 | + * |
|
| 37 | + * @var boolean |
|
| 38 | + */ |
|
| 39 | + protected $_received_submission = false; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * message displayed to users upon successful form submission |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + protected $_form_submission_success_message = ''; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * message displayed to users upon unsuccessful form submission |
|
| 50 | + * |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $_form_submission_error_message = ''; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var array like post / request |
|
| 57 | + */ |
|
| 58 | + protected $cached_request_data; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
| 62 | + * Starts off as null, but once the form is validated, it set to either true or false |
|
| 63 | + * @var boolean|null |
|
| 64 | + */ |
|
| 65 | + protected $is_valid; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Stores all the data that will localized for form validation |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + protected static $_js_localization = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * whether or not the form's localized validation JS vars have been set |
|
| 76 | + * |
|
| 77 | + * @type boolean |
|
| 78 | + */ |
|
| 79 | + protected static $_scripts_localized = false; |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 84 | + * so that they know who their parent is, and what name they've been given. |
|
| 85 | + * |
|
| 86 | + * @param array[] $options_array { |
|
| 87 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 88 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 89 | + * and in that order. This is handy if you want |
|
| 90 | + * the subsections to be ordered differently than the default, and if you override |
|
| 91 | + * which fields are shown |
|
| 92 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 93 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 94 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 95 | + * items from that list of inclusions) |
|
| 96 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 97 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 98 | + * @throws EE_Error |
|
| 99 | + */ |
|
| 100 | + public function __construct($options_array = array()) |
|
| 101 | + { |
|
| 102 | + $options_array = (array) apply_filters( |
|
| 103 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 104 | + $options_array, |
|
| 105 | + $this |
|
| 106 | + ); |
|
| 107 | + // call parent first, as it may be setting the name |
|
| 108 | + parent::__construct($options_array); |
|
| 109 | + // if they've included subsections in the constructor, add them now |
|
| 110 | + if (isset($options_array['include'])) { |
|
| 111 | + // we are going to make sure we ONLY have those subsections to include |
|
| 112 | + // AND we are going to make sure they're in that specified order |
|
| 113 | + $reordered_subsections = array(); |
|
| 114 | + foreach ($options_array['include'] as $input_name) { |
|
| 115 | + if (isset($this->_subsections[ $input_name ])) { |
|
| 116 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + $this->_subsections = $reordered_subsections; |
|
| 120 | + } |
|
| 121 | + if (isset($options_array['exclude'])) { |
|
| 122 | + $exclude = $options_array['exclude']; |
|
| 123 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 124 | + } |
|
| 125 | + if (isset($options_array['layout_strategy'])) { |
|
| 126 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 127 | + } |
|
| 128 | + if (! $this->_layout_strategy) { |
|
| 129 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 130 | + } |
|
| 131 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 132 | + // ok so we are definitely going to want the forms JS, |
|
| 133 | + // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 134 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 135 | + // ok so they've constructed this object after when they should have. |
|
| 136 | + // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 137 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 138 | + } else { |
|
| 139 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 140 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 141 | + } |
|
| 142 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 143 | + /** |
|
| 144 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 145 | + * The form probably doesn't yet have a parent form section. |
|
| 146 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 147 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 148 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 149 | + * |
|
| 150 | + * @since 4.9.32 |
|
| 151 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 152 | + * except maybe calling _construct_finalize has been done |
|
| 153 | + * @param array $options_array options passed into the constructor |
|
| 154 | + */ |
|
| 155 | + do_action( |
|
| 156 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 157 | + $this, |
|
| 158 | + $options_array |
|
| 159 | + ); |
|
| 160 | + if (isset($options_array['name'])) { |
|
| 161 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Finishes construction given the parent form section and this form section's name |
|
| 168 | + * |
|
| 169 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 170 | + * @param string $name |
|
| 171 | + * @throws EE_Error |
|
| 172 | + */ |
|
| 173 | + public function _construct_finalize($parent_form_section, $name) |
|
| 174 | + { |
|
| 175 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 176 | + $this->_set_default_name_if_empty(); |
|
| 177 | + $this->_set_default_html_id_if_empty(); |
|
| 178 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 179 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 180 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 181 | + } else { |
|
| 182 | + throw new EE_Error( |
|
| 183 | + sprintf( |
|
| 184 | + esc_html__( |
|
| 185 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 186 | + 'event_espresso' |
|
| 187 | + ), |
|
| 188 | + $subsection_name, |
|
| 189 | + get_class($this), |
|
| 190 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + /** |
|
| 196 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 197 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 198 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 199 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 200 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 201 | + * ensured it has a name, HTML IDs, etc |
|
| 202 | + * |
|
| 203 | + * @param EE_Form_Section_Proper $this |
|
| 204 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 205 | + * @param string $name |
|
| 206 | + */ |
|
| 207 | + do_action( |
|
| 208 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 209 | + $this, |
|
| 210 | + $parent_form_section, |
|
| 211 | + $name |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Gets the layout strategy for this form section |
|
| 218 | + * |
|
| 219 | + * @return EE_Form_Section_Layout_Base |
|
| 220 | + */ |
|
| 221 | + public function get_layout_strategy() |
|
| 222 | + { |
|
| 223 | + return $this->_layout_strategy; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Gets the HTML for a single input for this form section according |
|
| 229 | + * to the layout strategy |
|
| 230 | + * |
|
| 231 | + * @param EE_Form_Input_Base $input |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 234 | + public function get_html_for_input($input) |
|
| 235 | + { |
|
| 236 | + return $this->_layout_strategy->layout_input($input); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * was_submitted - checks if form inputs are present in request data |
|
| 242 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 243 | + * proper form sections and form inputs) |
|
| 244 | + * |
|
| 245 | + * @param null $form_data |
|
| 246 | + * @return boolean |
|
| 247 | + * @throws EE_Error |
|
| 248 | + */ |
|
| 249 | + public function was_submitted($form_data = null) |
|
| 250 | + { |
|
| 251 | + return $this->form_data_present_in($form_data); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Gets the cached request data; but if there is none, or $req_data was set with |
|
| 256 | + * something different, refresh the cache, and then return it |
|
| 257 | + * @param null $req_data |
|
| 258 | + * @return array |
|
| 259 | + */ |
|
| 260 | + protected function getCachedRequest($req_data = null) |
|
| 261 | + { |
|
| 262 | + if ( |
|
| 263 | + $this->cached_request_data === null |
|
| 264 | + || ( |
|
| 265 | + $req_data !== null |
|
| 266 | + && $req_data !== $this->cached_request_data |
|
| 267 | + ) |
|
| 268 | + ) { |
|
| 269 | + $req_data = apply_filters( |
|
| 270 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 271 | + $req_data, |
|
| 272 | + $this |
|
| 273 | + ); |
|
| 274 | + if ($req_data === null) { |
|
| 275 | + /** @var RequestInterface $request */ |
|
| 276 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 277 | + $req_data = $request->requestParams(); |
|
| 278 | + } |
|
| 279 | + $req_data = apply_filters( |
|
| 280 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 281 | + $req_data, |
|
| 282 | + $this |
|
| 283 | + ); |
|
| 284 | + $this->cached_request_data = (array) $req_data; |
|
| 285 | + } |
|
| 286 | + return $this->cached_request_data; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 292 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 293 | + * |
|
| 294 | + * @param array|null $req_data should usually be post data (the default). |
|
| 295 | + * However, you CAN supply a different array. |
|
| 296 | + * Consider using set_defaults() instead however. |
|
| 297 | + * (If you rendered the form in the page using $form_x->get_html() |
|
| 298 | + * the inputs will have the correct name in the request data for this function |
|
| 299 | + * to find them and populate the form with them. |
|
| 300 | + * If you have a flat form (with only input subsections), |
|
| 301 | + * you can supply a flat array where keys |
|
| 302 | + * are the form input names and values are their values) |
|
| 303 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 304 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 305 | + * But if the data has already been validated |
|
| 306 | + * (eg you validated the data then stored it in the DB) |
|
| 307 | + * you may want to skip this step. |
|
| 308 | + * @throws InvalidArgumentException |
|
| 309 | + * @throws InvalidInterfaceException |
|
| 310 | + * @throws InvalidDataTypeException |
|
| 311 | + * @throws EE_Error |
|
| 312 | + */ |
|
| 313 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 314 | + { |
|
| 315 | + $req_data = $this->getCachedRequest($req_data); |
|
| 316 | + $this->_normalize($req_data); |
|
| 317 | + if ($validate) { |
|
| 318 | + $this->_validate(); |
|
| 319 | + // if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 320 | + if (! $this->is_valid()) { |
|
| 321 | + $this->store_submitted_form_data_in_session(); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
| 325 | + $this->set_submission_error_message(); |
|
| 326 | + } |
|
| 327 | + do_action( |
|
| 328 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 329 | + $req_data, |
|
| 330 | + $this, |
|
| 331 | + $validate |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * caches the originally submitted input values in the session |
|
| 338 | + * so that they can be used to repopulate the form if it failed validation |
|
| 339 | + * |
|
| 340 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidInterfaceException |
|
| 343 | + * @throws InvalidDataTypeException |
|
| 344 | + * @throws EE_Error |
|
| 345 | + */ |
|
| 346 | + protected function store_submitted_form_data_in_session() |
|
| 347 | + { |
|
| 348 | + $session = EE_Registry::instance()->SSN; |
|
| 349 | + if ($session instanceof EE_Session) { |
|
| 350 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 351 | + [ |
|
| 352 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 353 | + ] |
|
| 354 | + ); |
|
| 355 | + } |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * retrieves the originally submitted input values in the session |
|
| 362 | + * so that they can be used to repopulate the form if it failed validation |
|
| 363 | + * |
|
| 364 | + * @return array |
|
| 365 | + * @throws InvalidArgumentException |
|
| 366 | + * @throws InvalidInterfaceException |
|
| 367 | + * @throws InvalidDataTypeException |
|
| 368 | + */ |
|
| 369 | + protected function get_submitted_form_data_from_session() |
|
| 370 | + { |
|
| 371 | + $session = EE_Registry::instance()->SSN; |
|
| 372 | + if ($session instanceof EE_Session) { |
|
| 373 | + return $session->get_session_data( |
|
| 374 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 375 | + ); |
|
| 376 | + } |
|
| 377 | + return array(); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * flushed the originally submitted input values from the session |
|
| 383 | + * |
|
| 384 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 385 | + * @throws InvalidArgumentException |
|
| 386 | + * @throws InvalidInterfaceException |
|
| 387 | + * @throws InvalidDataTypeException |
|
| 388 | + */ |
|
| 389 | + public static function flush_submitted_form_data_from_session() |
|
| 390 | + { |
|
| 391 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 392 | + [EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY] |
|
| 393 | + ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Populates this form and its subsections with data from the session. |
|
| 399 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 400 | + * validation errors when displaying too) |
|
| 401 | + * Returns true if the form was populated from the session, false otherwise |
|
| 402 | + * |
|
| 403 | + * @return boolean |
|
| 404 | + * @throws InvalidArgumentException |
|
| 405 | + * @throws InvalidInterfaceException |
|
| 406 | + * @throws InvalidDataTypeException |
|
| 407 | + * @throws EE_Error |
|
| 408 | + */ |
|
| 409 | + public function populate_from_session() |
|
| 410 | + { |
|
| 411 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 412 | + if (empty($form_data_in_session)) { |
|
| 413 | + return false; |
|
| 414 | + } |
|
| 415 | + $this->receive_form_submission($form_data_in_session); |
|
| 416 | + add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
| 417 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 418 | + return true; |
|
| 419 | + } |
|
| 420 | + return false; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Populates the default data for the form, given an array where keys are |
|
| 426 | + * the input names, and values are their values (preferably normalized to be their |
|
| 427 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 428 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 429 | + * the value being an array formatted in teh same way |
|
| 430 | + * |
|
| 431 | + * @param array $default_data |
|
| 432 | + * @throws EE_Error |
|
| 433 | + */ |
|
| 434 | + public function populate_defaults($default_data) |
|
| 435 | + { |
|
| 436 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 437 | + if (isset($default_data[ $subsection_name ])) { |
|
| 438 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 439 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
| 440 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 441 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * returns true if subsection exists |
|
| 450 | + * |
|
| 451 | + * @param string $name |
|
| 452 | + * @return boolean |
|
| 453 | + */ |
|
| 454 | + public function subsection_exists($name) |
|
| 455 | + { |
|
| 456 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Gets the subsection specified by its name |
|
| 462 | + * |
|
| 463 | + * @param string $name |
|
| 464 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 465 | + * so that the inputs will be properly configured. |
|
| 466 | + * However, some client code may be ok |
|
| 467 | + * with construction finalize being called later |
|
| 468 | + * (realizing that the subsections' html names |
|
| 469 | + * might not be set yet, etc.) |
|
| 470 | + * @return EE_Form_Section_Base |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 474 | + { |
|
| 475 | + if ($require_construction_to_be_finalized) { |
|
| 476 | + $this->ensure_construct_finalized_called(); |
|
| 477 | + } |
|
| 478 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Gets all the validatable subsections of this form section |
|
| 484 | + * |
|
| 485 | + * @return EE_Form_Section_Validatable[] |
|
| 486 | + * @throws EE_Error |
|
| 487 | + */ |
|
| 488 | + public function get_validatable_subsections() |
|
| 489 | + { |
|
| 490 | + $validatable_subsections = array(); |
|
| 491 | + foreach ($this->subsections() as $name => $obj) { |
|
| 492 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 493 | + $validatable_subsections[ $name ] = $obj; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $validatable_subsections; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 502 | + * throw an EE_Error. |
|
| 503 | + * |
|
| 504 | + * @param string $name |
|
| 505 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 506 | + * leave this as TRUE so that the inputs will be properly |
|
| 507 | + * configured. However, some client code may be ok with |
|
| 508 | + * construction finalize being called later |
|
| 509 | + * (realizing that the subsections' html names might not be |
|
| 510 | + * set yet, etc.) |
|
| 511 | + * @return EE_Form_Input_Base |
|
| 512 | + * @throws EE_Error |
|
| 513 | + */ |
|
| 514 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 515 | + { |
|
| 516 | + $subsection = $this->get_subsection( |
|
| 517 | + $name, |
|
| 518 | + $require_construction_to_be_finalized |
|
| 519 | + ); |
|
| 520 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 521 | + throw new EE_Error( |
|
| 522 | + sprintf( |
|
| 523 | + esc_html__( |
|
| 524 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 525 | + 'event_espresso' |
|
| 526 | + ), |
|
| 527 | + $name, |
|
| 528 | + get_class($this), |
|
| 529 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 530 | + ) |
|
| 531 | + ); |
|
| 532 | + } |
|
| 533 | + return $subsection; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 539 | + * otherwise throws an EE_Error |
|
| 540 | + * |
|
| 541 | + * @param string $name |
|
| 542 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 543 | + * leave this as TRUE so that the inputs will be properly |
|
| 544 | + * configured. However, some client code may be ok with |
|
| 545 | + * construction finalize being called later |
|
| 546 | + * (realizing that the subsections' html names might not be |
|
| 547 | + * set yet, etc.) |
|
| 548 | + * @return EE_Form_Section_Proper |
|
| 549 | + * @throws EE_Error |
|
| 550 | + */ |
|
| 551 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 552 | + { |
|
| 553 | + $subsection = $this->get_subsection( |
|
| 554 | + $name, |
|
| 555 | + $require_construction_to_be_finalized |
|
| 556 | + ); |
|
| 557 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 558 | + throw new EE_Error( |
|
| 559 | + sprintf( |
|
| 560 | + esc_html__( |
|
| 561 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 562 | + 'event_espresso' |
|
| 563 | + ), |
|
| 564 | + $name, |
|
| 565 | + get_class($this) |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + } |
|
| 569 | + return $subsection; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 575 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 576 | + * |
|
| 577 | + * @param string $name |
|
| 578 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 579 | + * @throws EE_Error |
|
| 580 | + */ |
|
| 581 | + public function get_input_value($name) |
|
| 582 | + { |
|
| 583 | + $input = $this->get_input($name); |
|
| 584 | + return $input->normalized_value(); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 590 | + * |
|
| 591 | + * @throws EE_Error |
|
| 592 | + * @return boolean |
|
| 593 | + */ |
|
| 594 | + public function is_valid() |
|
| 595 | + { |
|
| 596 | + if ($this->is_valid === null) { |
|
| 597 | + if (! $this->has_received_submission()) { |
|
| 598 | + throw new EE_Error( |
|
| 599 | + sprintf( |
|
| 600 | + esc_html__( |
|
| 601 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 602 | + 'event_espresso' |
|
| 603 | + ) |
|
| 604 | + ) |
|
| 605 | + ); |
|
| 606 | + } |
|
| 607 | + if (! parent::is_valid()) { |
|
| 608 | + $this->is_valid = false; |
|
| 609 | + } else { |
|
| 610 | + // ok so no general errors to this entire form section. |
|
| 611 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 612 | + $this->is_valid = true; |
|
| 613 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 614 | + if (! $subsection->is_valid()) { |
|
| 615 | + $this->is_valid = false; |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + return $this->is_valid; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * gets the default name of this form section if none is specified |
|
| 626 | + * |
|
| 627 | + * @return void |
|
| 628 | + */ |
|
| 629 | + protected function _set_default_name_if_empty() |
|
| 630 | + { |
|
| 631 | + if (! $this->_name) { |
|
| 632 | + $classname = get_class($this); |
|
| 633 | + $default_name = str_replace('EE_', '', $classname); |
|
| 634 | + $this->_name = $default_name; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 641 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 642 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 643 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 644 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 645 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 646 | + * any CSS. |
|
| 647 | + * |
|
| 648 | + * @throws InvalidArgumentException |
|
| 649 | + * @throws InvalidInterfaceException |
|
| 650 | + * @throws InvalidDataTypeException |
|
| 651 | + * @throws EE_Error |
|
| 652 | + */ |
|
| 653 | + public function get_html_and_js() |
|
| 654 | + { |
|
| 655 | + $this->enqueue_js(); |
|
| 656 | + return $this->get_html(); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 662 | + * |
|
| 663 | + * @param bool $display_previously_submitted_data |
|
| 664 | + * @return string |
|
| 665 | + * @throws InvalidArgumentException |
|
| 666 | + * @throws InvalidInterfaceException |
|
| 667 | + * @throws InvalidDataTypeException |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws EE_Error |
|
| 670 | + * @throws EE_Error |
|
| 671 | + */ |
|
| 672 | + public function get_html($display_previously_submitted_data = true) |
|
| 673 | + { |
|
| 674 | + $this->ensure_construct_finalized_called(); |
|
| 675 | + if ($display_previously_submitted_data) { |
|
| 676 | + $this->populate_from_session(); |
|
| 677 | + } |
|
| 678 | + return $this->_form_html_filter |
|
| 679 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 680 | + : $this->_layout_strategy->layout_form(); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * enqueues JS and CSS for the form. |
|
| 686 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 687 | + * scripts and styles can be put in the header, but if called later |
|
| 688 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 689 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 690 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 691 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 692 | + * |
|
| 693 | + * @return void |
|
| 694 | + * @throws EE_Error |
|
| 695 | + */ |
|
| 696 | + public function enqueue_js() |
|
| 697 | + { |
|
| 698 | + $this->_enqueue_and_localize_form_js(); |
|
| 699 | + foreach ($this->subsections() as $subsection) { |
|
| 700 | + $subsection->enqueue_js(); |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 707 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 708 | + * the wp_enqueue_scripts hook. |
|
| 709 | + * However, registering the form js and localizing it can happen when we |
|
| 710 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 711 | + * could change until it's actually outputted) |
|
| 712 | + * |
|
| 713 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 714 | + * to be triggered automatically or not |
|
| 715 | + * @return void |
|
| 716 | + */ |
|
| 717 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 718 | + { |
|
| 719 | + wp_register_script( |
|
| 720 | + 'ee_form_section_validation', |
|
| 721 | + EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js', |
|
| 722 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 723 | + EVENT_ESPRESSO_VERSION, |
|
| 724 | + true |
|
| 725 | + ); |
|
| 726 | + wp_localize_script( |
|
| 727 | + 'ee_form_section_validation', |
|
| 728 | + 'ee_form_section_validation_init', |
|
| 729 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 730 | + ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * gets the variables used by form_section_validation.js. |
|
| 736 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 737 | + * but before the wordpress hook wp_loaded |
|
| 738 | + * |
|
| 739 | + * @throws EE_Error |
|
| 740 | + */ |
|
| 741 | + public function _enqueue_and_localize_form_js() |
|
| 742 | + { |
|
| 743 | + $this->ensure_construct_finalized_called(); |
|
| 744 | + // actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 745 | + // so we need to add our form section data to a static variable accessible by all form sections |
|
| 746 | + // and localize it just before the footer |
|
| 747 | + $this->localize_validation_rules(); |
|
| 748 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 749 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * add our form section data to a static variable accessible by all form sections |
|
| 755 | + * |
|
| 756 | + * @param bool $return_for_subsection |
|
| 757 | + * @return void |
|
| 758 | + * @throws EE_Error |
|
| 759 | + */ |
|
| 760 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 761 | + { |
|
| 762 | + // we only want to localize vars ONCE for the entire form, |
|
| 763 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 764 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 765 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 766 | + 'form_section_id' => $this->html_id(true), |
|
| 767 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 768 | + 'other_data' => $this->get_other_js_data(), |
|
| 769 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 770 | + ); |
|
| 771 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 778 | + * This is primarily data added by inputs and forms in addition to any |
|
| 779 | + * scripts they might enqueue |
|
| 780 | + * |
|
| 781 | + * @param array $form_other_js_data |
|
| 782 | + * @return array |
|
| 783 | + * @throws EE_Error |
|
| 784 | + */ |
|
| 785 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 786 | + { |
|
| 787 | + foreach ($this->subsections() as $subsection) { |
|
| 788 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 789 | + } |
|
| 790 | + return $form_other_js_data; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 796 | + * Keys are their form names, and values are the inputs themselves |
|
| 797 | + * |
|
| 798 | + * @return EE_Form_Input_Base |
|
| 799 | + * @throws EE_Error |
|
| 800 | + */ |
|
| 801 | + public function inputs_in_subsections() |
|
| 802 | + { |
|
| 803 | + $inputs = array(); |
|
| 804 | + foreach ($this->subsections() as $subsection) { |
|
| 805 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 806 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
| 807 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 808 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + return $inputs; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Gets a flat array of all the validation errors. |
|
| 817 | + * Keys are html names (because those should be unique) |
|
| 818 | + * and values are a string of all their validation errors |
|
| 819 | + * |
|
| 820 | + * @return string[] |
|
| 821 | + * @throws EE_Error |
|
| 822 | + */ |
|
| 823 | + public function subsection_validation_errors_by_html_name() |
|
| 824 | + { |
|
| 825 | + $inputs = $this->inputs(); |
|
| 826 | + $errors = array(); |
|
| 827 | + foreach ($inputs as $form_input) { |
|
| 828 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 829 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + return $errors; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 838 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 839 | + * |
|
| 840 | + * @throws InvalidArgumentException |
|
| 841 | + * @throws InvalidInterfaceException |
|
| 842 | + * @throws InvalidDataTypeException |
|
| 843 | + */ |
|
| 844 | + public static function localize_script_for_all_forms() |
|
| 845 | + { |
|
| 846 | + // allow inputs and stuff to hook in their JS and stuff here |
|
| 847 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 848 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 849 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 850 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 851 | + : 'wp_default'; |
|
| 852 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 853 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 854 | + wp_localize_script( |
|
| 855 | + 'ee_form_section_validation', |
|
| 856 | + 'ee_form_section_vars', |
|
| 857 | + EE_Form_Section_Proper::$_js_localization |
|
| 858 | + ); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * ensure_scripts_localized |
|
| 864 | + * |
|
| 865 | + * @throws EE_Error |
|
| 866 | + */ |
|
| 867 | + public function ensure_scripts_localized() |
|
| 868 | + { |
|
| 869 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 870 | + $this->_enqueue_and_localize_form_js(); |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 877 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 878 | + * |
|
| 879 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 880 | + */ |
|
| 881 | + private static function _get_localized_error_messages() |
|
| 882 | + { |
|
| 883 | + return array( |
|
| 884 | + 'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')), |
|
| 885 | + 'regex' => wp_strip_all_tags(__('Please check your input', 'event_espresso')) |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * @return array |
|
| 892 | + */ |
|
| 893 | + public static function js_localization() |
|
| 894 | + { |
|
| 895 | + return self::$_js_localization; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * @return void |
|
| 901 | + */ |
|
| 902 | + public static function reset_js_localization() |
|
| 903 | + { |
|
| 904 | + self::$_js_localization = array(); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 910 | + * See parent function for more... |
|
| 911 | + * |
|
| 912 | + * @return array |
|
| 913 | + * @throws EE_Error |
|
| 914 | + */ |
|
| 915 | + public function get_jquery_validation_rules() |
|
| 916 | + { |
|
| 917 | + $jquery_validation_rules = array(); |
|
| 918 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 919 | + $jquery_validation_rules = array_merge( |
|
| 920 | + $jquery_validation_rules, |
|
| 921 | + $subsection->get_jquery_validation_rules() |
|
| 922 | + ); |
|
| 923 | + } |
|
| 924 | + return $jquery_validation_rules; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 930 | + * |
|
| 931 | + * @param array $req_data |
|
| 932 | + * @return void |
|
| 933 | + * @throws EE_Error |
|
| 934 | + */ |
|
| 935 | + protected function _normalize($req_data) |
|
| 936 | + { |
|
| 937 | + $this->_received_submission = true; |
|
| 938 | + $this->_validation_errors = array(); |
|
| 939 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 940 | + try { |
|
| 941 | + $subsection->_normalize($req_data); |
|
| 942 | + } catch (EE_Validation_Error $e) { |
|
| 943 | + $subsection->add_validation_error($e); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * Performs validation on this form section and its subsections. |
|
| 951 | + * For each subsection, |
|
| 952 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 953 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 954 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 955 | + * you would be best to override this _validate method, |
|
| 956 | + * calling parent::_validate() first. |
|
| 957 | + * |
|
| 958 | + * @throws EE_Error |
|
| 959 | + */ |
|
| 960 | + protected function _validate() |
|
| 961 | + { |
|
| 962 | + // reset the cache of whether this form is valid or not- we're re-validating it now |
|
| 963 | + $this->is_valid = null; |
|
| 964 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 965 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 966 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 967 | + } |
|
| 968 | + $subsection->_validate(); |
|
| 969 | + } |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + /** |
|
| 974 | + * Gets all the validated inputs for the form section |
|
| 975 | + * |
|
| 976 | + * @return array |
|
| 977 | + * @throws EE_Error |
|
| 978 | + */ |
|
| 979 | + public function valid_data() |
|
| 980 | + { |
|
| 981 | + $inputs = array(); |
|
| 982 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 983 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 984 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 985 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 986 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + return $inputs; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * Gets all the inputs on this form section |
|
| 995 | + * |
|
| 996 | + * @return EE_Form_Input_Base[] |
|
| 997 | + * @throws EE_Error |
|
| 998 | + */ |
|
| 999 | + public function inputs() |
|
| 1000 | + { |
|
| 1001 | + $inputs = array(); |
|
| 1002 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1003 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1004 | + $inputs[ $subsection_name ] = $subsection; |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + return $inputs; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * Gets all the subsections which are a proper form |
|
| 1013 | + * |
|
| 1014 | + * @return EE_Form_Section_Proper[] |
|
| 1015 | + * @throws EE_Error |
|
| 1016 | + */ |
|
| 1017 | + public function subforms() |
|
| 1018 | + { |
|
| 1019 | + $form_sections = array(); |
|
| 1020 | + foreach ($this->subsections() as $name => $obj) { |
|
| 1021 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 1022 | + $form_sections[ $name ] = $obj; |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + return $form_sections; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + |
|
| 1029 | + /** |
|
| 1030 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 1031 | + * Consider using inputs() or subforms() |
|
| 1032 | + * if you only want form inputs or proper form sections. |
|
| 1033 | + * |
|
| 1034 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 1035 | + * leave this as TRUE so that the inputs will be properly |
|
| 1036 | + * configured. However, some client code may be ok with |
|
| 1037 | + * construction finalize being called later |
|
| 1038 | + * (realizing that the subsections' html names might not be |
|
| 1039 | + * set yet, etc.) |
|
| 1040 | + * @return EE_Form_Section_Proper[] |
|
| 1041 | + * @throws EE_Error |
|
| 1042 | + */ |
|
| 1043 | + public function subsections($require_construction_to_be_finalized = true) |
|
| 1044 | + { |
|
| 1045 | + if ($require_construction_to_be_finalized) { |
|
| 1046 | + $this->ensure_construct_finalized_called(); |
|
| 1047 | + } |
|
| 1048 | + return $this->_subsections; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * Returns whether this form has any subforms or inputs |
|
| 1054 | + * @return bool |
|
| 1055 | + */ |
|
| 1056 | + public function hasSubsections() |
|
| 1057 | + { |
|
| 1058 | + return ! empty($this->_subsections); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + |
|
| 1062 | + /** |
|
| 1063 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 1064 | + * values. (Similar to calling get_input_value on inputs) |
|
| 1065 | + * |
|
| 1066 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1067 | + * or just this forms' direct children inputs |
|
| 1068 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1069 | + * or allow multidimensional array |
|
| 1070 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1071 | + * with array keys being input names |
|
| 1072 | + * (regardless of whether they are from a subsection or not), |
|
| 1073 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1074 | + * where keys are always subsection names and values are either |
|
| 1075 | + * the input's normalized value, or an array like the top-level array |
|
| 1076 | + * @throws EE_Error |
|
| 1077 | + */ |
|
| 1078 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1079 | + { |
|
| 1080 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + /** |
|
| 1085 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1086 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1087 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 1088 | + * where keys are the input names, and values are their display values |
|
| 1089 | + * |
|
| 1090 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1091 | + * or just this forms' direct children inputs |
|
| 1092 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1093 | + * or allow multidimensional array |
|
| 1094 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1095 | + * with array keys being input names |
|
| 1096 | + * (regardless of whether they are from a subsection or not), |
|
| 1097 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1098 | + * where keys are always subsection names and values are either |
|
| 1099 | + * the input's normalized value, or an array like the top-level array |
|
| 1100 | + * @throws EE_Error |
|
| 1101 | + */ |
|
| 1102 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1103 | + { |
|
| 1104 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Gets the input values from the form |
|
| 1110 | + * |
|
| 1111 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1112 | + * or just the normalized value |
|
| 1113 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1114 | + * or just this forms' direct children inputs |
|
| 1115 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1116 | + * or allow multidimensional array |
|
| 1117 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1118 | + * input names (regardless of whether they are from a subsection or not), |
|
| 1119 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1120 | + * where keys are always subsection names and values are either |
|
| 1121 | + * the input's normalized value, or an array like the top-level array |
|
| 1122 | + * @throws EE_Error |
|
| 1123 | + */ |
|
| 1124 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1125 | + { |
|
| 1126 | + $input_values = array(); |
|
| 1127 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1128 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1129 | + $input_values[ $subsection_name ] = $pretty |
|
| 1130 | + ? $subsection->pretty_value() |
|
| 1131 | + : $subsection->normalized_value(); |
|
| 1132 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1133 | + $subform_input_values = $subsection->_input_values( |
|
| 1134 | + $pretty, |
|
| 1135 | + $include_subform_inputs, |
|
| 1136 | + $flatten |
|
| 1137 | + ); |
|
| 1138 | + if ($flatten) { |
|
| 1139 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1140 | + } else { |
|
| 1141 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + return $input_values; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Gets the originally submitted input values from the form |
|
| 1151 | + * |
|
| 1152 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1153 | + * or just this forms' direct children inputs |
|
| 1154 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1155 | + * with array keys being input names |
|
| 1156 | + * (regardless of whether they are from a subsection or not), |
|
| 1157 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1158 | + * where keys are always subsection names and values are either |
|
| 1159 | + * the input's normalized value, or an array like the top-level array |
|
| 1160 | + * @throws EE_Error |
|
| 1161 | + */ |
|
| 1162 | + public function submitted_values($include_subforms = false) |
|
| 1163 | + { |
|
| 1164 | + $submitted_values = array(); |
|
| 1165 | + foreach ($this->subsections() as $subsection) { |
|
| 1166 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1167 | + // is this input part of an array of inputs? |
|
| 1168 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1169 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1170 | + explode( |
|
| 1171 | + '[', |
|
| 1172 | + str_replace(']', '', $subsection->html_name()) |
|
| 1173 | + ), |
|
| 1174 | + $subsection->raw_value() |
|
| 1175 | + ); |
|
| 1176 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1177 | + } else { |
|
| 1178 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1179 | + } |
|
| 1180 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1181 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1182 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | + return $submitted_values; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + |
|
| 1189 | + /** |
|
| 1190 | + * Indicates whether or not this form has received a submission yet |
|
| 1191 | + * (ie, had receive_form_submission called on it yet) |
|
| 1192 | + * |
|
| 1193 | + * @return boolean |
|
| 1194 | + * @throws EE_Error |
|
| 1195 | + */ |
|
| 1196 | + public function has_received_submission() |
|
| 1197 | + { |
|
| 1198 | + $this->ensure_construct_finalized_called(); |
|
| 1199 | + return $this->_received_submission; |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + |
|
| 1203 | + /** |
|
| 1204 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1205 | + * Removes the listed inputs from the form |
|
| 1206 | + * |
|
| 1207 | + * @param array $inputs_to_exclude values are the input names |
|
| 1208 | + * @return void |
|
| 1209 | + */ |
|
| 1210 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1211 | + { |
|
| 1212 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1213 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
| 1220 | + * @param array $inputs_to_hide |
|
| 1221 | + * @throws EE_Error |
|
| 1222 | + */ |
|
| 1223 | + public function hide(array $inputs_to_hide = array()) |
|
| 1224 | + { |
|
| 1225 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1226 | + $input = $this->get_input($input_to_hide); |
|
| 1227 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * add_subsections |
|
| 1234 | + * Adds the listed subsections to the form section. |
|
| 1235 | + * If $subsection_name_to_target is provided, |
|
| 1236 | + * then new subsections are added before or after that subsection, |
|
| 1237 | + * otherwise to the start or end of the entire subsections array. |
|
| 1238 | + * |
|
| 1239 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1240 | + * where keys are their names |
|
| 1241 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1242 | + * should be added before or after |
|
| 1243 | + * IF $subsection_name_to_target is null, |
|
| 1244 | + * then $new_subsections will be added to |
|
| 1245 | + * the beginning or end of the entire subsections array |
|
| 1246 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1247 | + * $subsection_name_to_target, |
|
| 1248 | + * or if $subsection_name_to_target is null, |
|
| 1249 | + * before or after entire subsections array |
|
| 1250 | + * @return void |
|
| 1251 | + * @throws EE_Error |
|
| 1252 | + */ |
|
| 1253 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1254 | + { |
|
| 1255 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1256 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1257 | + EE_Error::add_error( |
|
| 1258 | + sprintf( |
|
| 1259 | + esc_html__( |
|
| 1260 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1261 | + 'event_espresso' |
|
| 1262 | + ), |
|
| 1263 | + get_class($subsection), |
|
| 1264 | + $subsection_name, |
|
| 1265 | + $this->name() |
|
| 1266 | + ), |
|
| 1267 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1268 | + ); |
|
| 1269 | + unset($new_subsections[ $subsection_name ]); |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1273 | + $this->_subsections, |
|
| 1274 | + $new_subsections, |
|
| 1275 | + $subsection_name_to_target, |
|
| 1276 | + $add_before |
|
| 1277 | + ); |
|
| 1278 | + if ($this->_construction_finalized) { |
|
| 1279 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1280 | + $subsection->_construct_finalize($this, $name); |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + |
|
| 1286 | + /** |
|
| 1287 | + * @param string $subsection_name |
|
| 1288 | + * @param bool $recursive |
|
| 1289 | + * @return bool |
|
| 1290 | + */ |
|
| 1291 | + public function has_subsection($subsection_name, $recursive = false) |
|
| 1292 | + { |
|
| 1293 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1294 | + if ( |
|
| 1295 | + $name === $subsection_name |
|
| 1296 | + || ( |
|
| 1297 | + $recursive |
|
| 1298 | + && $subsection instanceof EE_Form_Section_Proper |
|
| 1299 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
| 1300 | + ) |
|
| 1301 | + ) { |
|
| 1302 | + return true; |
|
| 1303 | + } |
|
| 1304 | + } |
|
| 1305 | + return false; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1312 | + * |
|
| 1313 | + * @throws EE_Error |
|
| 1314 | + */ |
|
| 1315 | + public function clean_sensitive_data() |
|
| 1316 | + { |
|
| 1317 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1318 | + $subsection->clean_sensitive_data(); |
|
| 1319 | + } |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
| 1325 | + * @param string $form_submission_error_message |
|
| 1326 | + * @param EE_Form_Section_Validatable $form_section unused |
|
| 1327 | + * @throws EE_Error |
|
| 1328 | + */ |
|
| 1329 | + public function set_submission_error_message( |
|
| 1330 | + $form_submission_error_message = '' |
|
| 1331 | + ) { |
|
| 1332 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
| 1333 | + ? $form_submission_error_message |
|
| 1334 | + : $this->getAllValidationErrorsString(); |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + |
|
| 1338 | + /** |
|
| 1339 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
| 1340 | + * (called during receive_form_submission) but it can be explicitly set using |
|
| 1341 | + * set_submission_error_message |
|
| 1342 | + * |
|
| 1343 | + * @return string |
|
| 1344 | + */ |
|
| 1345 | + public function submission_error_message() |
|
| 1346 | + { |
|
| 1347 | + return $this->_form_submission_error_message; |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * Sets a message to display if the data submitted to the form was valid. |
|
| 1353 | + * @param string $form_submission_success_message |
|
| 1354 | + */ |
|
| 1355 | + public function set_submission_success_message($form_submission_success_message = '') |
|
| 1356 | + { |
|
| 1357 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
| 1358 | + ? $form_submission_success_message |
|
| 1359 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * Gets a message appropriate for display when the form is correctly submitted |
|
| 1365 | + * @return string |
|
| 1366 | + */ |
|
| 1367 | + public function submission_success_message() |
|
| 1368 | + { |
|
| 1369 | + return $this->_form_submission_success_message; |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * Returns the prefix that should be used on child of this form section for |
|
| 1375 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1376 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1377 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1378 | + * |
|
| 1379 | + * @return string |
|
| 1380 | + * @throws EE_Error |
|
| 1381 | + */ |
|
| 1382 | + public function html_name_prefix() |
|
| 1383 | + { |
|
| 1384 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1385 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1386 | + } |
|
| 1387 | + return $this->name(); |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + |
|
| 1391 | + /** |
|
| 1392 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1393 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1394 | + * was set, which is probably nothing, or the classname) |
|
| 1395 | + * |
|
| 1396 | + * @return string |
|
| 1397 | + * @throws EE_Error |
|
| 1398 | + */ |
|
| 1399 | + public function name() |
|
| 1400 | + { |
|
| 1401 | + $this->ensure_construct_finalized_called(); |
|
| 1402 | + return parent::name(); |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * @return EE_Form_Section_Proper |
|
| 1408 | + * @throws EE_Error |
|
| 1409 | + */ |
|
| 1410 | + public function parent_section() |
|
| 1411 | + { |
|
| 1412 | + $this->ensure_construct_finalized_called(); |
|
| 1413 | + return parent::parent_section(); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1419 | + * |
|
| 1420 | + * @return void |
|
| 1421 | + * @throws EE_Error |
|
| 1422 | + */ |
|
| 1423 | + public function ensure_construct_finalized_called() |
|
| 1424 | + { |
|
| 1425 | + if (! $this->_construction_finalized) { |
|
| 1426 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1427 | + } |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + |
|
| 1431 | + /** |
|
| 1432 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1433 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1434 | + * |
|
| 1435 | + * @param array $req_data |
|
| 1436 | + * @return boolean |
|
| 1437 | + * @throws EE_Error |
|
| 1438 | + */ |
|
| 1439 | + public function form_data_present_in($req_data = null) |
|
| 1440 | + { |
|
| 1441 | + $req_data = $this->getCachedRequest($req_data); |
|
| 1442 | + foreach ($this->subsections() as $subsection) { |
|
| 1443 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1444 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1445 | + return true; |
|
| 1446 | + } |
|
| 1447 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1448 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1449 | + return true; |
|
| 1450 | + } |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + return false; |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * Gets validation errors for this form section and subsections |
|
| 1459 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1460 | + * gets the validation errors for ALL subsection |
|
| 1461 | + * |
|
| 1462 | + * @return EE_Validation_Error[] |
|
| 1463 | + * @throws EE_Error |
|
| 1464 | + */ |
|
| 1465 | + public function get_validation_errors_accumulated() |
|
| 1466 | + { |
|
| 1467 | + $validation_errors = $this->get_validation_errors(); |
|
| 1468 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1469 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1470 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1471 | + } else { |
|
| 1472 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1473 | + } |
|
| 1474 | + if ($validation_errors_on_this_subsection) { |
|
| 1475 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1476 | + } |
|
| 1477 | + } |
|
| 1478 | + return $validation_errors; |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
| 1483 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
| 1484 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
| 1485 | + * |
|
| 1486 | + * @return string |
|
| 1487 | + * @since 4.9.59.p |
|
| 1488 | + */ |
|
| 1489 | + protected function getAllValidationErrorsString() |
|
| 1490 | + { |
|
| 1491 | + $submission_error_messages = array(); |
|
| 1492 | + // bad, bad, bad registrant |
|
| 1493 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
| 1494 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1495 | + $form_section = $validation_error->get_form_section(); |
|
| 1496 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 1497 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
| 1498 | + } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
| 1499 | + $label = $validation_error->get_form_section()->name(); |
|
| 1500 | + } else { |
|
| 1501 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
| 1502 | + } |
|
| 1503 | + $submission_error_messages[] = sprintf( |
|
| 1504 | + esc_html__('%s : %s', 'event_espresso'), |
|
| 1505 | + $label, |
|
| 1506 | + $validation_error->getMessage() |
|
| 1507 | + ); |
|
| 1508 | + } |
|
| 1509 | + } |
|
| 1510 | + return implode('<br>', $submission_error_messages); |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + |
|
| 1514 | + /** |
|
| 1515 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1516 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1517 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1518 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1519 | + * which will be returned. |
|
| 1520 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1521 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1522 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1523 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1524 | + * Etc |
|
| 1525 | + * |
|
| 1526 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1527 | + * @return EE_Form_Section_Base |
|
| 1528 | + * @throws EE_Error |
|
| 1529 | + */ |
|
| 1530 | + public function find_section_from_path($form_section_path) |
|
| 1531 | + { |
|
| 1532 | + // check if we can find the input from purely going straight up the tree |
|
| 1533 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1534 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1535 | + return $input; |
|
| 1536 | + } |
|
| 1537 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1538 | + if ($next_slash_pos !== false) { |
|
| 1539 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1540 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1541 | + } else { |
|
| 1542 | + $child_section_name = $form_section_path; |
|
| 1543 | + $subpath = ''; |
|
| 1544 | + } |
|
| 1545 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1546 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1547 | + return $child_section->find_section_from_path($subpath); |
|
| 1548 | + } |
|
| 1549 | + return null; |
|
| 1550 | + } |
|
| 1551 | 1551 | } |