@@ -14,1323 +14,1323 @@ |
||
| 14 | 14 | class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 19 | - */ |
|
| 20 | - public function __construct($routing = true) |
|
| 21 | - { |
|
| 22 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
| 23 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
| 24 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 25 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
| 26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 27 | - parent::__construct($routing); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - protected function _extend_page_config() |
|
| 35 | - { |
|
| 36 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 37 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
| 38 | - ? $this->_req_data['QST_ID'] : 0; |
|
| 39 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
| 40 | - ? $this->_req_data['QSG_ID'] : 0; |
|
| 41 | - |
|
| 42 | - $new_page_routes = array( |
|
| 43 | - 'question_groups' => array( |
|
| 44 | - 'func' => '_question_groups_overview_list_table', |
|
| 45 | - 'capability' => 'ee_read_question_groups', |
|
| 46 | - ), |
|
| 47 | - 'add_question' => array( |
|
| 48 | - 'func' => '_edit_question', |
|
| 49 | - 'capability' => 'ee_edit_questions', |
|
| 50 | - ), |
|
| 51 | - 'insert_question' => array( |
|
| 52 | - 'func' => '_insert_or_update_question', |
|
| 53 | - 'args' => array('new_question' => true), |
|
| 54 | - 'capability' => 'ee_edit_questions', |
|
| 55 | - 'noheader' => true, |
|
| 56 | - ), |
|
| 57 | - 'duplicate_question' => array( |
|
| 58 | - 'func' => '_duplicate_question', |
|
| 59 | - 'capability' => 'ee_edit_questions', |
|
| 60 | - 'noheader' => true, |
|
| 61 | - ), |
|
| 62 | - 'trash_question' => array( |
|
| 63 | - 'func' => '_trash_question', |
|
| 64 | - 'capability' => 'ee_delete_question', |
|
| 65 | - 'obj_id' => $qst_id, |
|
| 66 | - 'noheader' => true, |
|
| 67 | - ), |
|
| 68 | - |
|
| 69 | - 'restore_question' => array( |
|
| 70 | - 'func' => '_trash_or_restore_questions', |
|
| 71 | - 'capability' => 'ee_delete_question', |
|
| 72 | - 'obj_id' => $qst_id, |
|
| 73 | - 'args' => array('trash' => false), |
|
| 74 | - 'noheader' => true, |
|
| 75 | - ), |
|
| 76 | - |
|
| 77 | - 'delete_question' => array( |
|
| 78 | - 'func' => '_delete_question', |
|
| 79 | - 'capability' => 'ee_delete_question', |
|
| 80 | - 'obj_id' => $qst_id, |
|
| 81 | - 'noheader' => true, |
|
| 82 | - ), |
|
| 83 | - |
|
| 84 | - 'trash_questions' => array( |
|
| 85 | - 'func' => '_trash_or_restore_questions', |
|
| 86 | - 'capability' => 'ee_delete_questions', |
|
| 87 | - 'args' => array('trash' => true), |
|
| 88 | - 'noheader' => true, |
|
| 89 | - ), |
|
| 90 | - |
|
| 91 | - 'restore_questions' => array( |
|
| 92 | - 'func' => '_trash_or_restore_questions', |
|
| 93 | - 'capability' => 'ee_delete_questions', |
|
| 94 | - 'args' => array('trash' => false), |
|
| 95 | - 'noheader' => true, |
|
| 96 | - ), |
|
| 97 | - |
|
| 98 | - 'delete_questions' => array( |
|
| 99 | - 'func' => '_delete_questions', |
|
| 100 | - 'args' => array(), |
|
| 101 | - 'capability' => 'ee_delete_questions', |
|
| 102 | - 'noheader' => true, |
|
| 103 | - ), |
|
| 104 | - |
|
| 105 | - 'add_question_group' => array( |
|
| 106 | - 'func' => '_edit_question_group', |
|
| 107 | - 'capability' => 'ee_edit_question_groups', |
|
| 108 | - ), |
|
| 109 | - |
|
| 110 | - 'edit_question_group' => array( |
|
| 111 | - 'func' => '_edit_question_group', |
|
| 112 | - 'capability' => 'ee_edit_question_group', |
|
| 113 | - 'obj_id' => $qsg_id, |
|
| 114 | - 'args' => array('edit'), |
|
| 115 | - ), |
|
| 116 | - |
|
| 117 | - 'delete_question_groups' => array( |
|
| 118 | - 'func' => '_delete_question_groups', |
|
| 119 | - 'capability' => 'ee_delete_question_groups', |
|
| 120 | - 'noheader' => true, |
|
| 121 | - ), |
|
| 122 | - |
|
| 123 | - 'delete_question_group' => array( |
|
| 124 | - 'func' => '_delete_question_groups', |
|
| 125 | - 'capability' => 'ee_delete_question_group', |
|
| 126 | - 'obj_id' => $qsg_id, |
|
| 127 | - 'noheader' => true, |
|
| 128 | - ), |
|
| 129 | - |
|
| 130 | - 'trash_question_group' => array( |
|
| 131 | - 'func' => '_trash_or_restore_question_groups', |
|
| 132 | - 'args' => array('trash' => true), |
|
| 133 | - 'capability' => 'ee_delete_question_group', |
|
| 134 | - 'obj_id' => $qsg_id, |
|
| 135 | - 'noheader' => true, |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'restore_question_group' => array( |
|
| 139 | - 'func' => '_trash_or_restore_question_groups', |
|
| 140 | - 'args' => array('trash' => false), |
|
| 141 | - 'capability' => 'ee_delete_question_group', |
|
| 142 | - 'obj_id' => $qsg_id, |
|
| 143 | - 'noheader' => true, |
|
| 144 | - ), |
|
| 145 | - |
|
| 146 | - 'insert_question_group' => array( |
|
| 147 | - 'func' => '_insert_or_update_question_group', |
|
| 148 | - 'args' => array('new_question_group' => true), |
|
| 149 | - 'capability' => 'ee_edit_question_groups', |
|
| 150 | - 'noheader' => true, |
|
| 151 | - ), |
|
| 152 | - |
|
| 153 | - 'update_question_group' => array( |
|
| 154 | - 'func' => '_insert_or_update_question_group', |
|
| 155 | - 'args' => array('new_question_group' => false), |
|
| 156 | - 'capability' => 'ee_edit_question_group', |
|
| 157 | - 'obj_id' => $qsg_id, |
|
| 158 | - 'noheader' => true, |
|
| 159 | - ), |
|
| 160 | - |
|
| 161 | - 'trash_question_groups' => array( |
|
| 162 | - 'func' => '_trash_or_restore_question_groups', |
|
| 163 | - 'args' => array('trash' => true), |
|
| 164 | - 'capability' => 'ee_delete_question_groups', |
|
| 165 | - 'noheader' => array('trash' => false), |
|
| 166 | - ), |
|
| 167 | - |
|
| 168 | - 'restore_question_groups' => array( |
|
| 169 | - 'func' => '_trash_or_restore_question_groups', |
|
| 170 | - 'args' => array('trash' => false), |
|
| 171 | - 'capability' => 'ee_delete_question_groups', |
|
| 172 | - 'noheader' => true, |
|
| 173 | - ), |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - 'espresso_update_question_group_order' => array( |
|
| 177 | - 'func' => 'update_question_group_order', |
|
| 178 | - 'capability' => 'ee_edit_question_groups', |
|
| 179 | - 'noheader' => true, |
|
| 180 | - ), |
|
| 181 | - |
|
| 182 | - 'view_reg_form_settings' => array( |
|
| 183 | - 'func' => '_reg_form_settings', |
|
| 184 | - 'capability' => 'manage_options', |
|
| 185 | - ), |
|
| 186 | - |
|
| 187 | - 'update_reg_form_settings' => array( |
|
| 188 | - 'func' => '_update_reg_form_settings', |
|
| 189 | - 'capability' => 'manage_options', |
|
| 190 | - 'noheader' => true, |
|
| 191 | - ), |
|
| 192 | - ); |
|
| 193 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 194 | - |
|
| 195 | - $new_page_config = array( |
|
| 196 | - |
|
| 197 | - 'question_groups' => array( |
|
| 198 | - 'nav' => array( |
|
| 199 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 200 | - 'order' => 20, |
|
| 201 | - ), |
|
| 202 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 203 | - 'help_tabs' => array( |
|
| 204 | - 'registration_form_question_groups_help_tab' => array( |
|
| 205 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 206 | - 'filename' => 'registration_form_question_groups', |
|
| 207 | - ), |
|
| 208 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 209 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 210 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 211 | - ), |
|
| 212 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 213 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 214 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 215 | - ), |
|
| 216 | - ), |
|
| 217 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 218 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 219 | - 'require_nonce' => false, |
|
| 220 | - 'qtips' => array( |
|
| 221 | - 'EE_Registration_Form_Tips', |
|
| 222 | - ), |
|
| 223 | - ), |
|
| 224 | - |
|
| 225 | - 'add_question' => array( |
|
| 226 | - 'nav' => array( |
|
| 227 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 228 | - 'order' => 5, |
|
| 229 | - 'persistent' => false, |
|
| 230 | - ), |
|
| 231 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 232 | - 'help_tabs' => array( |
|
| 233 | - 'registration_form_add_question_help_tab' => array( |
|
| 234 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 235 | - 'filename' => 'registration_form_add_question', |
|
| 236 | - ), |
|
| 237 | - ), |
|
| 238 | - 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
| 239 | - 'require_nonce' => false, |
|
| 240 | - ), |
|
| 241 | - |
|
| 242 | - 'add_question_group' => array( |
|
| 243 | - 'nav' => array( |
|
| 244 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 245 | - 'order' => 5, |
|
| 246 | - 'persistent' => false, |
|
| 247 | - ), |
|
| 248 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 249 | - 'help_tabs' => array( |
|
| 250 | - 'registration_form_add_question_group_help_tab' => array( |
|
| 251 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 252 | - 'filename' => 'registration_form_add_question_group', |
|
| 253 | - ), |
|
| 254 | - ), |
|
| 255 | - 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 256 | - 'require_nonce' => false, |
|
| 257 | - ), |
|
| 258 | - |
|
| 259 | - 'edit_question_group' => array( |
|
| 260 | - 'nav' => array( |
|
| 261 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 262 | - 'order' => 5, |
|
| 263 | - 'persistent' => false, |
|
| 264 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
| 265 | - array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 266 | - $this->_current_page_view_url |
|
| 267 | - ) : $this->_admin_base_url, |
|
| 268 | - ), |
|
| 269 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 270 | - 'help_tabs' => array( |
|
| 271 | - 'registration_form_edit_question_group_help_tab' => array( |
|
| 272 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 273 | - 'filename' => 'registration_form_edit_question_group', |
|
| 274 | - ), |
|
| 275 | - ), |
|
| 276 | - 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 277 | - 'require_nonce' => false, |
|
| 278 | - ), |
|
| 279 | - |
|
| 280 | - 'view_reg_form_settings' => array( |
|
| 281 | - 'nav' => array( |
|
| 282 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 283 | - 'order' => 40, |
|
| 284 | - ), |
|
| 285 | - 'labels' => array( |
|
| 286 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 287 | - ), |
|
| 288 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 289 | - 'help_tabs' => array( |
|
| 290 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
| 291 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 292 | - 'filename' => 'registration_form_reg_form_settings', |
|
| 293 | - ), |
|
| 294 | - ), |
|
| 295 | - 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 296 | - 'require_nonce' => false, |
|
| 297 | - ), |
|
| 298 | - |
|
| 299 | - ); |
|
| 300 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 301 | - |
|
| 302 | - // change the list table we're going to use so it's the NEW list table! |
|
| 303 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - // additional labels |
|
| 307 | - $new_labels = array( |
|
| 308 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 309 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 310 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 311 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 312 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 313 | - ); |
|
| 314 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @return void |
|
| 320 | - */ |
|
| 321 | - protected function _ajax_hooks() |
|
| 322 | - { |
|
| 323 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * @return void |
|
| 329 | - */ |
|
| 330 | - public function load_scripts_styles_question_groups() |
|
| 331 | - { |
|
| 332 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @return void |
|
| 338 | - */ |
|
| 339 | - public function load_scripts_styles_add_question_group() |
|
| 340 | - { |
|
| 341 | - $this->load_scripts_styles_forms(); |
|
| 342 | - $this->load_sortable_question_script(); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @return void |
|
| 348 | - */ |
|
| 349 | - public function load_scripts_styles_edit_question_group() |
|
| 350 | - { |
|
| 351 | - $this->load_scripts_styles_forms(); |
|
| 352 | - $this->load_sortable_question_script(); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * registers and enqueues script for questions |
|
| 358 | - * |
|
| 359 | - * @return void |
|
| 360 | - */ |
|
| 361 | - public function load_sortable_question_script() |
|
| 362 | - { |
|
| 363 | - wp_register_script( |
|
| 364 | - 'ee-question-sortable', |
|
| 365 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 366 | - array('jquery-ui-sortable'), |
|
| 367 | - EVENT_ESPRESSO_VERSION, |
|
| 368 | - true |
|
| 369 | - ); |
|
| 370 | - wp_enqueue_script('ee-question-sortable'); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * @return void |
|
| 376 | - */ |
|
| 377 | - protected function _set_list_table_views_default() |
|
| 378 | - { |
|
| 379 | - $this->_views = array( |
|
| 380 | - 'all' => array( |
|
| 381 | - 'slug' => 'all', |
|
| 382 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 383 | - 'count' => 0, |
|
| 384 | - 'bulk_action' => array( |
|
| 385 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 386 | - ), |
|
| 387 | - ), |
|
| 388 | - ); |
|
| 389 | - |
|
| 390 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 391 | - 'ee_delete_questions', |
|
| 392 | - 'espresso_registration_form_trash_questions' |
|
| 393 | - ) |
|
| 394 | - ) { |
|
| 395 | - $this->_views['trash'] = array( |
|
| 396 | - 'slug' => 'trash', |
|
| 397 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 398 | - 'count' => 0, |
|
| 399 | - 'bulk_action' => array( |
|
| 400 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 401 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 402 | - ), |
|
| 403 | - ); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @return void |
|
| 410 | - */ |
|
| 411 | - protected function _set_list_table_views_question_groups() |
|
| 412 | - { |
|
| 413 | - $this->_views = array( |
|
| 414 | - 'all' => array( |
|
| 415 | - 'slug' => 'all', |
|
| 416 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 417 | - 'count' => 0, |
|
| 418 | - 'bulk_action' => array( |
|
| 419 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 420 | - ), |
|
| 421 | - ), |
|
| 422 | - ); |
|
| 423 | - |
|
| 424 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 425 | - 'ee_delete_question_groups', |
|
| 426 | - 'espresso_registration_form_trash_question_groups' |
|
| 427 | - ) |
|
| 428 | - ) { |
|
| 429 | - $this->_views['trash'] = array( |
|
| 430 | - 'slug' => 'trash', |
|
| 431 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 432 | - 'count' => 0, |
|
| 433 | - 'bulk_action' => array( |
|
| 434 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 435 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 436 | - ), |
|
| 437 | - ); |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @return void |
|
| 444 | - * @throws EE_Error |
|
| 445 | - * @throws InvalidArgumentException |
|
| 446 | - * @throws InvalidDataTypeException |
|
| 447 | - * @throws InvalidInterfaceException |
|
| 448 | - */ |
|
| 449 | - protected function _questions_overview_list_table() |
|
| 450 | - { |
|
| 451 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 452 | - 'add_question', |
|
| 453 | - 'add_question', |
|
| 454 | - array(), |
|
| 455 | - 'add-new-h2' |
|
| 456 | - ); |
|
| 457 | - parent::_questions_overview_list_table(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * @return void |
|
| 463 | - * @throws DomainException |
|
| 464 | - * @throws EE_Error |
|
| 465 | - * @throws InvalidArgumentException |
|
| 466 | - * @throws InvalidDataTypeException |
|
| 467 | - * @throws InvalidInterfaceException |
|
| 468 | - */ |
|
| 469 | - protected function _question_groups_overview_list_table() |
|
| 470 | - { |
|
| 471 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 472 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 473 | - 'add_question_group', |
|
| 474 | - 'add_question_group', |
|
| 475 | - array(), |
|
| 476 | - 'add-new-h2' |
|
| 477 | - ); |
|
| 478 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @return void |
|
| 484 | - * @throws EE_Error |
|
| 485 | - * @throws InvalidArgumentException |
|
| 486 | - * @throws InvalidDataTypeException |
|
| 487 | - * @throws InvalidInterfaceException |
|
| 488 | - */ |
|
| 489 | - protected function _delete_question() |
|
| 490 | - { |
|
| 491 | - $success = $this->_delete_items($this->_question_model); |
|
| 492 | - $this->_redirect_after_action( |
|
| 493 | - $success, |
|
| 494 | - $this->_question_model->item_name($success), |
|
| 495 | - 'deleted', |
|
| 496 | - array('action' => 'default', 'status' => 'all') |
|
| 497 | - ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @return void |
|
| 503 | - * @throws EE_Error |
|
| 504 | - * @throws InvalidArgumentException |
|
| 505 | - * @throws InvalidDataTypeException |
|
| 506 | - * @throws InvalidInterfaceException |
|
| 507 | - */ |
|
| 508 | - protected function _delete_questions() |
|
| 509 | - { |
|
| 510 | - $success = $this->_delete_items($this->_question_model); |
|
| 511 | - $this->_redirect_after_action( |
|
| 512 | - $success, |
|
| 513 | - $this->_question_model->item_name($success), |
|
| 514 | - 'deleted permanently', |
|
| 515 | - array('action' => 'default', 'status' => 'trash') |
|
| 516 | - ); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Performs the deletion of a single or multiple questions or question groups. |
|
| 522 | - * |
|
| 523 | - * @param EEM_Soft_Delete_Base $model |
|
| 524 | - * @return int number of items deleted permanently |
|
| 525 | - * @throws EE_Error |
|
| 526 | - * @throws InvalidArgumentException |
|
| 527 | - * @throws InvalidDataTypeException |
|
| 528 | - * @throws InvalidInterfaceException |
|
| 529 | - */ |
|
| 530 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 531 | - { |
|
| 532 | - $success = 0; |
|
| 533 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 534 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 535 | - // if array has more than one element than success message should be plural |
|
| 536 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 537 | - // cycle thru bulk action checkboxes |
|
| 538 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 539 | - if (! $this->_delete_item($ID, $model)) { |
|
| 540 | - $success = 0; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 544 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 545 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 546 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 547 | - } else { |
|
| 548 | - EE_Error::add_error( |
|
| 549 | - sprintf( |
|
| 550 | - esc_html__( |
|
| 551 | - "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 552 | - "event_espresso" |
|
| 553 | - ) |
|
| 554 | - ), |
|
| 555 | - __FILE__, |
|
| 556 | - __FUNCTION__, |
|
| 557 | - __LINE__ |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - return $success; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Deletes the specified question (and its associated question options) or question group |
|
| 566 | - * |
|
| 567 | - * @param int $id |
|
| 568 | - * @param EEM_Soft_Delete_Base $model |
|
| 569 | - * @return boolean |
|
| 570 | - * @throws EE_Error |
|
| 571 | - * @throws InvalidArgumentException |
|
| 572 | - * @throws InvalidDataTypeException |
|
| 573 | - * @throws InvalidInterfaceException |
|
| 574 | - */ |
|
| 575 | - protected function _delete_item($id, $model) |
|
| 576 | - { |
|
| 577 | - if ($model instanceof EEM_Question) { |
|
| 578 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 579 | - } |
|
| 580 | - return $model->delete_permanently_by_ID(absint($id)); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /****************************** QUESTION GROUPS ******************************/ |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * @param string $type |
|
| 589 | - * @return void |
|
| 590 | - * @throws DomainException |
|
| 591 | - * @throws EE_Error |
|
| 592 | - * @throws InvalidArgumentException |
|
| 593 | - * @throws InvalidDataTypeException |
|
| 594 | - * @throws InvalidInterfaceException |
|
| 595 | - */ |
|
| 596 | - protected function _edit_question_group($type = 'add') |
|
| 597 | - { |
|
| 598 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 599 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
| 600 | - ? absint($this->_req_data['QSG_ID']) |
|
| 601 | - : false; |
|
| 602 | - |
|
| 603 | - switch ($this->_req_action) { |
|
| 604 | - case 'add_question_group': |
|
| 605 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 606 | - break; |
|
| 607 | - case 'edit_question_group': |
|
| 608 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 609 | - break; |
|
| 610 | - default: |
|
| 611 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 612 | - } |
|
| 613 | - // add ID to title if editing |
|
| 614 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 615 | - if ($ID) { |
|
| 616 | - /** @var EE_Question_Group $questionGroup */ |
|
| 617 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 618 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 619 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 620 | - } else { |
|
| 621 | - /** @var EE_Question_Group $questionGroup */ |
|
| 622 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 623 | - $questionGroup->set_order_to_latest(); |
|
| 624 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 625 | - } |
|
| 626 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 627 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 628 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 629 | - $this->_template_args['question_group'] = $questionGroup; |
|
| 630 | - |
|
| 631 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 632 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 633 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 634 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 635 | - $this->_template_args, |
|
| 636 | - true |
|
| 637 | - ); |
|
| 638 | - |
|
| 639 | - // the details template wrapper |
|
| 640 | - $this->display_admin_page_with_sidebar(); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * @return void |
|
| 646 | - * @throws EE_Error |
|
| 647 | - * @throws InvalidArgumentException |
|
| 648 | - * @throws InvalidDataTypeException |
|
| 649 | - * @throws InvalidInterfaceException |
|
| 650 | - */ |
|
| 651 | - protected function _delete_question_groups() |
|
| 652 | - { |
|
| 653 | - $success = $this->_delete_items($this->_question_group_model); |
|
| 654 | - $this->_redirect_after_action( |
|
| 655 | - $success, |
|
| 656 | - $this->_question_group_model->item_name($success), |
|
| 657 | - 'deleted permanently', |
|
| 658 | - array('action' => 'question_groups', 'status' => 'trash') |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * @param bool $new_question_group |
|
| 665 | - * @throws EE_Error |
|
| 666 | - * @throws InvalidArgumentException |
|
| 667 | - * @throws InvalidDataTypeException |
|
| 668 | - * @throws InvalidInterfaceException |
|
| 669 | - */ |
|
| 670 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
| 671 | - { |
|
| 672 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 673 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 674 | - if ($new_question_group) { |
|
| 675 | - // make sure identifier is unique |
|
| 676 | - $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
| 677 | - $identifier_exists = ! empty($identifier_value) |
|
| 678 | - ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
| 679 | - : false; |
|
| 680 | - if ($identifier_exists) { |
|
| 681 | - $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
| 682 | - } |
|
| 683 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 684 | - $success = $QSG_ID ? 1 : 0; |
|
| 685 | - if ($success === 0) { |
|
| 686 | - EE_Error::add_error( |
|
| 687 | - esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
| 688 | - __FILE__, |
|
| 689 | - __FUNCTION__, |
|
| 690 | - __LINE__ |
|
| 691 | - ); |
|
| 692 | - $this->_redirect_after_action( |
|
| 693 | - false, |
|
| 694 | - '', |
|
| 695 | - '', |
|
| 696 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 697 | - true |
|
| 698 | - ); |
|
| 699 | - } |
|
| 700 | - } else { |
|
| 701 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 702 | - unset($set_column_values['QSG_ID']); |
|
| 703 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
| 707 | - EEM_Attendee::system_question_phone |
|
| 708 | - ); |
|
| 709 | - // update the existing related questions |
|
| 710 | - // BUT FIRST... delete the phone question from the Question_Group_Question |
|
| 711 | - // if it is being added to this question group (therefore removed from the existing group) |
|
| 712 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
| 713 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 714 | - EEM_Question_Group_Question::instance()->delete( |
|
| 715 | - array( |
|
| 716 | - array( |
|
| 717 | - 'QST_ID' => $phone_question_id, |
|
| 718 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
| 719 | - ), |
|
| 720 | - ) |
|
| 721 | - ); |
|
| 722 | - } |
|
| 723 | - /** @type EE_Question_Group $question_group */ |
|
| 724 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 725 | - $questions = $question_group->questions(); |
|
| 726 | - // make sure system phone question is added to list of questions for this group |
|
| 727 | - if (! isset($questions[ $phone_question_id ])) { |
|
| 728 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - foreach ($questions as $question_ID => $question) { |
|
| 732 | - // first we always check for order. |
|
| 733 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
| 734 | - // update question order |
|
| 735 | - $question_group->update_question_order( |
|
| 736 | - $question_ID, |
|
| 737 | - $this->_req_data['question_orders'][ $question_ID ] |
|
| 738 | - ); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - // then we always check if adding or removing. |
|
| 742 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
| 743 | - $question_group->add_question($question_ID); |
|
| 744 | - } else { |
|
| 745 | - // not found, remove it (but only if not a system question for the personal group |
|
| 746 | - // with the exception of lname system question - we allow removal of it) |
|
| 747 | - if (in_array( |
|
| 748 | - $question->system_ID(), |
|
| 749 | - EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 750 | - $question_group->system_group() |
|
| 751 | - ) |
|
| 752 | - )) { |
|
| 753 | - continue; |
|
| 754 | - } else { |
|
| 755 | - $question_group->remove_question($question_ID); |
|
| 756 | - } |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - // save new related questions |
|
| 760 | - if (isset($this->_req_data['questions'])) { |
|
| 761 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 762 | - $question_group->add_question($QST_ID); |
|
| 763 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
| 764 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - if ($success !== false) { |
|
| 770 | - $msg = $new_question_group |
|
| 771 | - ? sprintf( |
|
| 772 | - esc_html__('The %s has been created', 'event_espresso'), |
|
| 773 | - $this->_question_group_model->item_name() |
|
| 774 | - ) |
|
| 775 | - : sprintf( |
|
| 776 | - esc_html__( |
|
| 777 | - 'The %s has been updated', |
|
| 778 | - 'event_espresso' |
|
| 779 | - ), |
|
| 780 | - $this->_question_group_model->item_name() |
|
| 781 | - ); |
|
| 782 | - EE_Error::add_success($msg); |
|
| 783 | - } |
|
| 784 | - $this->_redirect_after_action( |
|
| 785 | - false, |
|
| 786 | - '', |
|
| 787 | - '', |
|
| 788 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 789 | - true |
|
| 790 | - ); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * duplicates a question and all its question options and redirects to the new question. |
|
| 796 | - * |
|
| 797 | - * @return void |
|
| 798 | - * @throws EE_Error |
|
| 799 | - * @throws InvalidArgumentException |
|
| 800 | - * @throws ReflectionException |
|
| 801 | - * @throws InvalidDataTypeException |
|
| 802 | - * @throws InvalidInterfaceException |
|
| 803 | - */ |
|
| 804 | - public function _duplicate_question() |
|
| 805 | - { |
|
| 806 | - $question_ID = (int) $this->_req_data['QST_ID']; |
|
| 807 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 808 | - if ($question instanceof EE_Question) { |
|
| 809 | - $new_question = $question->duplicate(); |
|
| 810 | - if ($new_question instanceof EE_Question) { |
|
| 811 | - $this->_redirect_after_action( |
|
| 812 | - true, |
|
| 813 | - esc_html__('Question', 'event_espresso'), |
|
| 814 | - esc_html__('Duplicated', 'event_espresso'), |
|
| 815 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
| 816 | - true |
|
| 817 | - ); |
|
| 818 | - } else { |
|
| 819 | - global $wpdb; |
|
| 820 | - EE_Error::add_error( |
|
| 821 | - sprintf( |
|
| 822 | - esc_html__( |
|
| 823 | - 'Could not duplicate question with ID %1$d because: %2$s', |
|
| 824 | - 'event_espresso' |
|
| 825 | - ), |
|
| 826 | - $question_ID, |
|
| 827 | - $wpdb->last_error |
|
| 828 | - ), |
|
| 829 | - __FILE__, |
|
| 830 | - __FUNCTION__, |
|
| 831 | - __LINE__ |
|
| 832 | - ); |
|
| 833 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 834 | - } |
|
| 835 | - } else { |
|
| 836 | - EE_Error::add_error( |
|
| 837 | - sprintf( |
|
| 838 | - esc_html__( |
|
| 839 | - 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 840 | - 'event_espresso' |
|
| 841 | - ), |
|
| 842 | - $question_ID |
|
| 843 | - ), |
|
| 844 | - __FILE__, |
|
| 845 | - __FUNCTION__, |
|
| 846 | - __LINE__ |
|
| 847 | - ); |
|
| 848 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * @param bool $trash |
|
| 855 | - * @throws EE_Error |
|
| 856 | - */ |
|
| 857 | - protected function _trash_or_restore_question_groups($trash = true) |
|
| 858 | - { |
|
| 859 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - *_trash_question |
|
| 865 | - * |
|
| 866 | - * @return void |
|
| 867 | - * @throws EE_Error |
|
| 868 | - */ |
|
| 869 | - protected function _trash_question() |
|
| 870 | - { |
|
| 871 | - $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
| 872 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 873 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * @param bool $trash |
|
| 879 | - * @throws EE_Error |
|
| 880 | - */ |
|
| 881 | - protected function _trash_or_restore_questions($trash = true) |
|
| 882 | - { |
|
| 883 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
| 889 | - * flexible between question or question groups |
|
| 890 | - * |
|
| 891 | - * @param EEM_Soft_Delete_Base $model |
|
| 892 | - * @param boolean $trash whether to trash or restore |
|
| 893 | - * @throws EE_Error |
|
| 894 | - */ |
|
| 895 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 896 | - { |
|
| 897 | - |
|
| 898 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 899 | - |
|
| 900 | - $success = 1; |
|
| 901 | - // Checkboxes |
|
| 902 | - // echo "trash $trash"; |
|
| 903 | - // var_dump($this->_req_data['checkbox']);die; |
|
| 904 | - if (isset($this->_req_data['checkbox'])) { |
|
| 905 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 906 | - // if array has more than one element than success message should be plural |
|
| 907 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 908 | - // cycle thru bulk action checkboxes |
|
| 909 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 910 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 911 | - $success = 0; |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - } else { |
|
| 915 | - // grab single id and delete |
|
| 916 | - $ID = absint($this->_req_data['checkbox']); |
|
| 917 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 918 | - $success = 0; |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - } else { |
|
| 922 | - // delete via trash link |
|
| 923 | - // grab single id and delete |
|
| 924 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 925 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 926 | - $success = 0; |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
| 932 | - // echo "action :$action"; |
|
| 933 | - // $action = 'questions' ? 'default' : $action; |
|
| 934 | - if ($trash) { |
|
| 935 | - $action_desc = 'trashed'; |
|
| 936 | - $status = 'trash'; |
|
| 937 | - } else { |
|
| 938 | - $action_desc = 'restored'; |
|
| 939 | - $status = 'all'; |
|
| 940 | - } |
|
| 941 | - $this->_redirect_after_action( |
|
| 942 | - $success, |
|
| 943 | - $model->item_name($success), |
|
| 944 | - $action_desc, |
|
| 945 | - array('action' => $action, 'status' => $status) |
|
| 946 | - ); |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - |
|
| 950 | - /** |
|
| 951 | - * @param $per_page |
|
| 952 | - * @param int $current_page |
|
| 953 | - * @param bool|false $count |
|
| 954 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 955 | - * @throws EE_Error |
|
| 956 | - * @throws InvalidArgumentException |
|
| 957 | - * @throws InvalidDataTypeException |
|
| 958 | - * @throws InvalidInterfaceException |
|
| 959 | - */ |
|
| 960 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 961 | - { |
|
| 962 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 963 | - |
|
| 964 | - if ($count) { |
|
| 965 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 966 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 967 | - $results = $this->_question_model->count_deleted($where); |
|
| 968 | - } else { |
|
| 969 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 970 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
| 971 | - } |
|
| 972 | - return $results; |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - |
|
| 976 | - /** |
|
| 977 | - * @param $per_page |
|
| 978 | - * @param int $current_page |
|
| 979 | - * @param bool|false $count |
|
| 980 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 981 | - * @throws EE_Error |
|
| 982 | - * @throws InvalidArgumentException |
|
| 983 | - * @throws InvalidDataTypeException |
|
| 984 | - * @throws InvalidInterfaceException |
|
| 985 | - */ |
|
| 986 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 987 | - { |
|
| 988 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 989 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 990 | - if ($count) { |
|
| 991 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 992 | - $results = $questionGroupModel->count($where); |
|
| 993 | - } else { |
|
| 994 | - $results = $questionGroupModel->get_all($query_params); |
|
| 995 | - } |
|
| 996 | - return $results; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * @param $per_page |
|
| 1002 | - * @param int $current_page |
|
| 1003 | - * @param bool $count |
|
| 1004 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1005 | - * @throws EE_Error |
|
| 1006 | - * @throws InvalidArgumentException |
|
| 1007 | - * @throws InvalidDataTypeException |
|
| 1008 | - * @throws InvalidInterfaceException |
|
| 1009 | - */ |
|
| 1010 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 1011 | - { |
|
| 1012 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 1013 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 1014 | - if ($count) { |
|
| 1015 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 1016 | - $query_params['limit'] = null; |
|
| 1017 | - $results = $questionGroupModel->count_deleted($where); |
|
| 1018 | - } else { |
|
| 1019 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 1020 | - } |
|
| 1021 | - return $results; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * method for performing updates to question order |
|
| 1027 | - * |
|
| 1028 | - * @return void results array |
|
| 1029 | - * @throws EE_Error |
|
| 1030 | - * @throws InvalidArgumentException |
|
| 1031 | - * @throws InvalidDataTypeException |
|
| 1032 | - * @throws InvalidInterfaceException |
|
| 1033 | - */ |
|
| 1034 | - public function update_question_group_order() |
|
| 1035 | - { |
|
| 1036 | - |
|
| 1037 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 1038 | - |
|
| 1039 | - // grab our row IDs |
|
| 1040 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 1041 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 1042 | - : array(); |
|
| 1043 | - |
|
| 1044 | - $perpage = ! empty($this->_req_data['perpage']) |
|
| 1045 | - ? (int) $this->_req_data['perpage'] |
|
| 1046 | - : null; |
|
| 1047 | - $curpage = ! empty($this->_req_data['curpage']) |
|
| 1048 | - ? (int) $this->_req_data['curpage'] |
|
| 1049 | - : null; |
|
| 1050 | - |
|
| 1051 | - if (! empty($row_ids)) { |
|
| 1052 | - // figure out where we start the row_id count at for the current page. |
|
| 1053 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 1054 | - |
|
| 1055 | - $row_count = count($row_ids); |
|
| 1056 | - for ($i = 0; $i < $row_count; $i++) { |
|
| 1057 | - // Update the questions when re-ordering |
|
| 1058 | - $updated = EEM_Question_Group::instance()->update( |
|
| 1059 | - array('QSG_order' => $qsgcount), |
|
| 1060 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
| 1061 | - ); |
|
| 1062 | - if ($updated === false) { |
|
| 1063 | - $success = false; |
|
| 1064 | - } |
|
| 1065 | - $qsgcount++; |
|
| 1066 | - } |
|
| 1067 | - } else { |
|
| 1068 | - $success = false; |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - $errors = ! $success |
|
| 1072 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 1073 | - : false; |
|
| 1074 | - |
|
| 1075 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 1076 | - die(); |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - /** |
|
| 1085 | - * @throws DomainException |
|
| 1086 | - * @throws EE_Error |
|
| 1087 | - * @throws InvalidArgumentException |
|
| 1088 | - * @throws InvalidDataTypeException |
|
| 1089 | - * @throws InvalidInterfaceException |
|
| 1090 | - */ |
|
| 1091 | - protected function _reg_form_settings() |
|
| 1092 | - { |
|
| 1093 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 1094 | - add_action( |
|
| 1095 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1096 | - array($this, 'email_validation_settings_form'), |
|
| 1097 | - 2 |
|
| 1098 | - ); |
|
| 1099 | - $this->_template_args = (array) apply_filters( |
|
| 1100 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 1101 | - $this->_template_args |
|
| 1102 | - ); |
|
| 1103 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 1104 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1105 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1106 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 1107 | - $this->_template_args, |
|
| 1108 | - true |
|
| 1109 | - ); |
|
| 1110 | - $this->display_admin_page_with_sidebar(); |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * @return void |
|
| 1116 | - * @throws EE_Error |
|
| 1117 | - * @throws InvalidArgumentException |
|
| 1118 | - * @throws ReflectionException |
|
| 1119 | - * @throws InvalidDataTypeException |
|
| 1120 | - * @throws InvalidInterfaceException |
|
| 1121 | - */ |
|
| 1122 | - protected function _update_reg_form_settings() |
|
| 1123 | - { |
|
| 1124 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 1125 | - EE_Registry::instance()->CFG->registration |
|
| 1126 | - ); |
|
| 1127 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 1128 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 1129 | - EE_Registry::instance()->CFG->registration |
|
| 1130 | - ); |
|
| 1131 | - $success = $this->_update_espresso_configuration( |
|
| 1132 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1133 | - EE_Registry::instance()->CFG, |
|
| 1134 | - __FILE__, |
|
| 1135 | - __FUNCTION__, |
|
| 1136 | - __LINE__ |
|
| 1137 | - ); |
|
| 1138 | - $this->_redirect_after_action( |
|
| 1139 | - $success, |
|
| 1140 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1141 | - 'updated', |
|
| 1142 | - array('action' => 'view_reg_form_settings') |
|
| 1143 | - ); |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - |
|
| 1147 | - /** |
|
| 1148 | - * @return void |
|
| 1149 | - * @throws EE_Error |
|
| 1150 | - * @throws InvalidArgumentException |
|
| 1151 | - * @throws InvalidDataTypeException |
|
| 1152 | - * @throws InvalidInterfaceException |
|
| 1153 | - */ |
|
| 1154 | - public function email_validation_settings_form() |
|
| 1155 | - { |
|
| 1156 | - echo $this->_email_validation_settings_form()->get_html(); |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - |
|
| 1160 | - /** |
|
| 1161 | - * _email_validation_settings_form |
|
| 1162 | - * |
|
| 1163 | - * @access protected |
|
| 1164 | - * @return EE_Form_Section_Proper |
|
| 1165 | - * @throws \EE_Error |
|
| 1166 | - */ |
|
| 1167 | - protected function _email_validation_settings_form() |
|
| 1168 | - { |
|
| 1169 | - return new EE_Form_Section_Proper( |
|
| 1170 | - array( |
|
| 1171 | - 'name' => 'email_validation_settings', |
|
| 1172 | - 'html_id' => 'email_validation_settings', |
|
| 1173 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1174 | - 'subsections' => apply_filters( |
|
| 1175 | - 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
| 1176 | - array( |
|
| 1177 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 1178 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 1179 | - ), |
|
| 1180 | - 'email_validation_level' => new EE_Select_Input( |
|
| 1181 | - array( |
|
| 1182 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 1183 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 1184 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 1185 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 1186 | - ), |
|
| 1187 | - array( |
|
| 1188 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 1189 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 1190 | - 'html_help_text' => esc_html__( |
|
| 1191 | - 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 1192 | - 'event_espresso' |
|
| 1193 | - ), |
|
| 1194 | - 'default' => isset( |
|
| 1195 | - EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1196 | - ) |
|
| 1197 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1198 | - : 'wp_default', |
|
| 1199 | - 'required' => false, |
|
| 1200 | - ) |
|
| 1201 | - ), |
|
| 1202 | - ) |
|
| 1203 | - ), |
|
| 1204 | - ) |
|
| 1205 | - ); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - |
|
| 1209 | - /** |
|
| 1210 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1211 | - * @return EE_Registration_Config |
|
| 1212 | - * @throws EE_Error |
|
| 1213 | - * @throws InvalidArgumentException |
|
| 1214 | - * @throws ReflectionException |
|
| 1215 | - * @throws InvalidDataTypeException |
|
| 1216 | - * @throws InvalidInterfaceException |
|
| 1217 | - */ |
|
| 1218 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1219 | - { |
|
| 1220 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1221 | - try { |
|
| 1222 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1223 | - // if not displaying a form, then check for form submission |
|
| 1224 | - if ($email_validation_settings_form->was_submitted()) { |
|
| 1225 | - // capture form data |
|
| 1226 | - $email_validation_settings_form->receive_form_submission(); |
|
| 1227 | - // validate form data |
|
| 1228 | - if ($email_validation_settings_form->is_valid()) { |
|
| 1229 | - // grab validated data from form |
|
| 1230 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1231 | - if (isset($valid_data['email_validation_level'])) { |
|
| 1232 | - $email_validation_level = $valid_data['email_validation_level']; |
|
| 1233 | - // now if they want to use international email addresses |
|
| 1234 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1235 | - // in case we need to reset their email validation level, |
|
| 1236 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1237 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1238 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1239 | - // despite offering poor validation, supports i18n email addresses |
|
| 1240 | - $prev_email_validation_level = 'basic'; |
|
| 1241 | - } |
|
| 1242 | - // confirm our i18n email validation will work on the server |
|
| 1243 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1244 | - // or reset email validation level to previous value |
|
| 1245 | - $email_validation_level = $prev_email_validation_level; |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1249 | - } else { |
|
| 1250 | - EE_Error::add_error( |
|
| 1251 | - esc_html__( |
|
| 1252 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1253 | - 'event_espresso' |
|
| 1254 | - ), |
|
| 1255 | - __FILE__, |
|
| 1256 | - __FUNCTION__, |
|
| 1257 | - __LINE__ |
|
| 1258 | - ); |
|
| 1259 | - } |
|
| 1260 | - } else { |
|
| 1261 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1262 | - EE_Error::add_error( |
|
| 1263 | - $email_validation_settings_form->submission_error_message(), |
|
| 1264 | - __FILE__, |
|
| 1265 | - __FUNCTION__, |
|
| 1266 | - __LINE__ |
|
| 1267 | - ); |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - } catch (EE_Error $e) { |
|
| 1272 | - $e->get_error(); |
|
| 1273 | - } |
|
| 1274 | - return $EE_Registration_Config; |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1280 | - * and that the PCRE version works with our i18n email validation |
|
| 1281 | - * |
|
| 1282 | - * @param EE_Registration_Config $EE_Registration_Config |
|
| 1283 | - * @param string $email_validation_level |
|
| 1284 | - * @return bool |
|
| 1285 | - */ |
|
| 1286 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1287 | - { |
|
| 1288 | - // first check that PCRE is enabled |
|
| 1289 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1290 | - EE_Error::add_error( |
|
| 1291 | - sprintf( |
|
| 1292 | - esc_html__( |
|
| 1293 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1294 | - 'event_espresso' |
|
| 1295 | - ), |
|
| 1296 | - '<br />' |
|
| 1297 | - ), |
|
| 1298 | - __FILE__, |
|
| 1299 | - __FUNCTION__, |
|
| 1300 | - __LINE__ |
|
| 1301 | - ); |
|
| 1302 | - return false; |
|
| 1303 | - } else { |
|
| 1304 | - // PCRE support is enabled, but let's still |
|
| 1305 | - // perform a test to see if the server will support it. |
|
| 1306 | - // but first, save the updated validation level to the config, |
|
| 1307 | - // so that the validation strategy picks it up. |
|
| 1308 | - // this will get bumped back down if it doesn't work |
|
| 1309 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1310 | - try { |
|
| 1311 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1312 | - $i18n_email_address = apply_filters( |
|
| 1313 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1314 | - 'jägerjü[email protected]' |
|
| 1315 | - ); |
|
| 1316 | - $email_validator->validate($i18n_email_address); |
|
| 1317 | - } catch (Exception $e) { |
|
| 1318 | - EE_Error::add_error( |
|
| 1319 | - sprintf( |
|
| 1320 | - esc_html__( |
|
| 1321 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1322 | - 'event_espresso' |
|
| 1323 | - ), |
|
| 1324 | - '<br />', |
|
| 1325 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1326 | - ), |
|
| 1327 | - __FILE__, |
|
| 1328 | - __FUNCTION__, |
|
| 1329 | - __LINE__ |
|
| 1330 | - ); |
|
| 1331 | - return false; |
|
| 1332 | - } |
|
| 1333 | - } |
|
| 1334 | - return true; |
|
| 1335 | - } |
|
| 17 | + /** |
|
| 18 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 19 | + */ |
|
| 20 | + public function __construct($routing = true) |
|
| 21 | + { |
|
| 22 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
| 23 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
| 24 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 25 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
| 26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 27 | + parent::__construct($routing); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + protected function _extend_page_config() |
|
| 35 | + { |
|
| 36 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 37 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
| 38 | + ? $this->_req_data['QST_ID'] : 0; |
|
| 39 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
| 40 | + ? $this->_req_data['QSG_ID'] : 0; |
|
| 41 | + |
|
| 42 | + $new_page_routes = array( |
|
| 43 | + 'question_groups' => array( |
|
| 44 | + 'func' => '_question_groups_overview_list_table', |
|
| 45 | + 'capability' => 'ee_read_question_groups', |
|
| 46 | + ), |
|
| 47 | + 'add_question' => array( |
|
| 48 | + 'func' => '_edit_question', |
|
| 49 | + 'capability' => 'ee_edit_questions', |
|
| 50 | + ), |
|
| 51 | + 'insert_question' => array( |
|
| 52 | + 'func' => '_insert_or_update_question', |
|
| 53 | + 'args' => array('new_question' => true), |
|
| 54 | + 'capability' => 'ee_edit_questions', |
|
| 55 | + 'noheader' => true, |
|
| 56 | + ), |
|
| 57 | + 'duplicate_question' => array( |
|
| 58 | + 'func' => '_duplicate_question', |
|
| 59 | + 'capability' => 'ee_edit_questions', |
|
| 60 | + 'noheader' => true, |
|
| 61 | + ), |
|
| 62 | + 'trash_question' => array( |
|
| 63 | + 'func' => '_trash_question', |
|
| 64 | + 'capability' => 'ee_delete_question', |
|
| 65 | + 'obj_id' => $qst_id, |
|
| 66 | + 'noheader' => true, |
|
| 67 | + ), |
|
| 68 | + |
|
| 69 | + 'restore_question' => array( |
|
| 70 | + 'func' => '_trash_or_restore_questions', |
|
| 71 | + 'capability' => 'ee_delete_question', |
|
| 72 | + 'obj_id' => $qst_id, |
|
| 73 | + 'args' => array('trash' => false), |
|
| 74 | + 'noheader' => true, |
|
| 75 | + ), |
|
| 76 | + |
|
| 77 | + 'delete_question' => array( |
|
| 78 | + 'func' => '_delete_question', |
|
| 79 | + 'capability' => 'ee_delete_question', |
|
| 80 | + 'obj_id' => $qst_id, |
|
| 81 | + 'noheader' => true, |
|
| 82 | + ), |
|
| 83 | + |
|
| 84 | + 'trash_questions' => array( |
|
| 85 | + 'func' => '_trash_or_restore_questions', |
|
| 86 | + 'capability' => 'ee_delete_questions', |
|
| 87 | + 'args' => array('trash' => true), |
|
| 88 | + 'noheader' => true, |
|
| 89 | + ), |
|
| 90 | + |
|
| 91 | + 'restore_questions' => array( |
|
| 92 | + 'func' => '_trash_or_restore_questions', |
|
| 93 | + 'capability' => 'ee_delete_questions', |
|
| 94 | + 'args' => array('trash' => false), |
|
| 95 | + 'noheader' => true, |
|
| 96 | + ), |
|
| 97 | + |
|
| 98 | + 'delete_questions' => array( |
|
| 99 | + 'func' => '_delete_questions', |
|
| 100 | + 'args' => array(), |
|
| 101 | + 'capability' => 'ee_delete_questions', |
|
| 102 | + 'noheader' => true, |
|
| 103 | + ), |
|
| 104 | + |
|
| 105 | + 'add_question_group' => array( |
|
| 106 | + 'func' => '_edit_question_group', |
|
| 107 | + 'capability' => 'ee_edit_question_groups', |
|
| 108 | + ), |
|
| 109 | + |
|
| 110 | + 'edit_question_group' => array( |
|
| 111 | + 'func' => '_edit_question_group', |
|
| 112 | + 'capability' => 'ee_edit_question_group', |
|
| 113 | + 'obj_id' => $qsg_id, |
|
| 114 | + 'args' => array('edit'), |
|
| 115 | + ), |
|
| 116 | + |
|
| 117 | + 'delete_question_groups' => array( |
|
| 118 | + 'func' => '_delete_question_groups', |
|
| 119 | + 'capability' => 'ee_delete_question_groups', |
|
| 120 | + 'noheader' => true, |
|
| 121 | + ), |
|
| 122 | + |
|
| 123 | + 'delete_question_group' => array( |
|
| 124 | + 'func' => '_delete_question_groups', |
|
| 125 | + 'capability' => 'ee_delete_question_group', |
|
| 126 | + 'obj_id' => $qsg_id, |
|
| 127 | + 'noheader' => true, |
|
| 128 | + ), |
|
| 129 | + |
|
| 130 | + 'trash_question_group' => array( |
|
| 131 | + 'func' => '_trash_or_restore_question_groups', |
|
| 132 | + 'args' => array('trash' => true), |
|
| 133 | + 'capability' => 'ee_delete_question_group', |
|
| 134 | + 'obj_id' => $qsg_id, |
|
| 135 | + 'noheader' => true, |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'restore_question_group' => array( |
|
| 139 | + 'func' => '_trash_or_restore_question_groups', |
|
| 140 | + 'args' => array('trash' => false), |
|
| 141 | + 'capability' => 'ee_delete_question_group', |
|
| 142 | + 'obj_id' => $qsg_id, |
|
| 143 | + 'noheader' => true, |
|
| 144 | + ), |
|
| 145 | + |
|
| 146 | + 'insert_question_group' => array( |
|
| 147 | + 'func' => '_insert_or_update_question_group', |
|
| 148 | + 'args' => array('new_question_group' => true), |
|
| 149 | + 'capability' => 'ee_edit_question_groups', |
|
| 150 | + 'noheader' => true, |
|
| 151 | + ), |
|
| 152 | + |
|
| 153 | + 'update_question_group' => array( |
|
| 154 | + 'func' => '_insert_or_update_question_group', |
|
| 155 | + 'args' => array('new_question_group' => false), |
|
| 156 | + 'capability' => 'ee_edit_question_group', |
|
| 157 | + 'obj_id' => $qsg_id, |
|
| 158 | + 'noheader' => true, |
|
| 159 | + ), |
|
| 160 | + |
|
| 161 | + 'trash_question_groups' => array( |
|
| 162 | + 'func' => '_trash_or_restore_question_groups', |
|
| 163 | + 'args' => array('trash' => true), |
|
| 164 | + 'capability' => 'ee_delete_question_groups', |
|
| 165 | + 'noheader' => array('trash' => false), |
|
| 166 | + ), |
|
| 167 | + |
|
| 168 | + 'restore_question_groups' => array( |
|
| 169 | + 'func' => '_trash_or_restore_question_groups', |
|
| 170 | + 'args' => array('trash' => false), |
|
| 171 | + 'capability' => 'ee_delete_question_groups', |
|
| 172 | + 'noheader' => true, |
|
| 173 | + ), |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + 'espresso_update_question_group_order' => array( |
|
| 177 | + 'func' => 'update_question_group_order', |
|
| 178 | + 'capability' => 'ee_edit_question_groups', |
|
| 179 | + 'noheader' => true, |
|
| 180 | + ), |
|
| 181 | + |
|
| 182 | + 'view_reg_form_settings' => array( |
|
| 183 | + 'func' => '_reg_form_settings', |
|
| 184 | + 'capability' => 'manage_options', |
|
| 185 | + ), |
|
| 186 | + |
|
| 187 | + 'update_reg_form_settings' => array( |
|
| 188 | + 'func' => '_update_reg_form_settings', |
|
| 189 | + 'capability' => 'manage_options', |
|
| 190 | + 'noheader' => true, |
|
| 191 | + ), |
|
| 192 | + ); |
|
| 193 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 194 | + |
|
| 195 | + $new_page_config = array( |
|
| 196 | + |
|
| 197 | + 'question_groups' => array( |
|
| 198 | + 'nav' => array( |
|
| 199 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 200 | + 'order' => 20, |
|
| 201 | + ), |
|
| 202 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 203 | + 'help_tabs' => array( |
|
| 204 | + 'registration_form_question_groups_help_tab' => array( |
|
| 205 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 206 | + 'filename' => 'registration_form_question_groups', |
|
| 207 | + ), |
|
| 208 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 209 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 210 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 211 | + ), |
|
| 212 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 213 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 214 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 215 | + ), |
|
| 216 | + ), |
|
| 217 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 218 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 219 | + 'require_nonce' => false, |
|
| 220 | + 'qtips' => array( |
|
| 221 | + 'EE_Registration_Form_Tips', |
|
| 222 | + ), |
|
| 223 | + ), |
|
| 224 | + |
|
| 225 | + 'add_question' => array( |
|
| 226 | + 'nav' => array( |
|
| 227 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 228 | + 'order' => 5, |
|
| 229 | + 'persistent' => false, |
|
| 230 | + ), |
|
| 231 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 232 | + 'help_tabs' => array( |
|
| 233 | + 'registration_form_add_question_help_tab' => array( |
|
| 234 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 235 | + 'filename' => 'registration_form_add_question', |
|
| 236 | + ), |
|
| 237 | + ), |
|
| 238 | + 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
| 239 | + 'require_nonce' => false, |
|
| 240 | + ), |
|
| 241 | + |
|
| 242 | + 'add_question_group' => array( |
|
| 243 | + 'nav' => array( |
|
| 244 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 245 | + 'order' => 5, |
|
| 246 | + 'persistent' => false, |
|
| 247 | + ), |
|
| 248 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 249 | + 'help_tabs' => array( |
|
| 250 | + 'registration_form_add_question_group_help_tab' => array( |
|
| 251 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 252 | + 'filename' => 'registration_form_add_question_group', |
|
| 253 | + ), |
|
| 254 | + ), |
|
| 255 | + 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 256 | + 'require_nonce' => false, |
|
| 257 | + ), |
|
| 258 | + |
|
| 259 | + 'edit_question_group' => array( |
|
| 260 | + 'nav' => array( |
|
| 261 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 262 | + 'order' => 5, |
|
| 263 | + 'persistent' => false, |
|
| 264 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
| 265 | + array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 266 | + $this->_current_page_view_url |
|
| 267 | + ) : $this->_admin_base_url, |
|
| 268 | + ), |
|
| 269 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 270 | + 'help_tabs' => array( |
|
| 271 | + 'registration_form_edit_question_group_help_tab' => array( |
|
| 272 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 273 | + 'filename' => 'registration_form_edit_question_group', |
|
| 274 | + ), |
|
| 275 | + ), |
|
| 276 | + 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 277 | + 'require_nonce' => false, |
|
| 278 | + ), |
|
| 279 | + |
|
| 280 | + 'view_reg_form_settings' => array( |
|
| 281 | + 'nav' => array( |
|
| 282 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 283 | + 'order' => 40, |
|
| 284 | + ), |
|
| 285 | + 'labels' => array( |
|
| 286 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 287 | + ), |
|
| 288 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 289 | + 'help_tabs' => array( |
|
| 290 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
| 291 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 292 | + 'filename' => 'registration_form_reg_form_settings', |
|
| 293 | + ), |
|
| 294 | + ), |
|
| 295 | + 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 296 | + 'require_nonce' => false, |
|
| 297 | + ), |
|
| 298 | + |
|
| 299 | + ); |
|
| 300 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 301 | + |
|
| 302 | + // change the list table we're going to use so it's the NEW list table! |
|
| 303 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + // additional labels |
|
| 307 | + $new_labels = array( |
|
| 308 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 309 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 310 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 311 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 312 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 313 | + ); |
|
| 314 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @return void |
|
| 320 | + */ |
|
| 321 | + protected function _ajax_hooks() |
|
| 322 | + { |
|
| 323 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @return void |
|
| 329 | + */ |
|
| 330 | + public function load_scripts_styles_question_groups() |
|
| 331 | + { |
|
| 332 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @return void |
|
| 338 | + */ |
|
| 339 | + public function load_scripts_styles_add_question_group() |
|
| 340 | + { |
|
| 341 | + $this->load_scripts_styles_forms(); |
|
| 342 | + $this->load_sortable_question_script(); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @return void |
|
| 348 | + */ |
|
| 349 | + public function load_scripts_styles_edit_question_group() |
|
| 350 | + { |
|
| 351 | + $this->load_scripts_styles_forms(); |
|
| 352 | + $this->load_sortable_question_script(); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * registers and enqueues script for questions |
|
| 358 | + * |
|
| 359 | + * @return void |
|
| 360 | + */ |
|
| 361 | + public function load_sortable_question_script() |
|
| 362 | + { |
|
| 363 | + wp_register_script( |
|
| 364 | + 'ee-question-sortable', |
|
| 365 | + REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 366 | + array('jquery-ui-sortable'), |
|
| 367 | + EVENT_ESPRESSO_VERSION, |
|
| 368 | + true |
|
| 369 | + ); |
|
| 370 | + wp_enqueue_script('ee-question-sortable'); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * @return void |
|
| 376 | + */ |
|
| 377 | + protected function _set_list_table_views_default() |
|
| 378 | + { |
|
| 379 | + $this->_views = array( |
|
| 380 | + 'all' => array( |
|
| 381 | + 'slug' => 'all', |
|
| 382 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 383 | + 'count' => 0, |
|
| 384 | + 'bulk_action' => array( |
|
| 385 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 386 | + ), |
|
| 387 | + ), |
|
| 388 | + ); |
|
| 389 | + |
|
| 390 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 391 | + 'ee_delete_questions', |
|
| 392 | + 'espresso_registration_form_trash_questions' |
|
| 393 | + ) |
|
| 394 | + ) { |
|
| 395 | + $this->_views['trash'] = array( |
|
| 396 | + 'slug' => 'trash', |
|
| 397 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 398 | + 'count' => 0, |
|
| 399 | + 'bulk_action' => array( |
|
| 400 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 401 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 402 | + ), |
|
| 403 | + ); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @return void |
|
| 410 | + */ |
|
| 411 | + protected function _set_list_table_views_question_groups() |
|
| 412 | + { |
|
| 413 | + $this->_views = array( |
|
| 414 | + 'all' => array( |
|
| 415 | + 'slug' => 'all', |
|
| 416 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 417 | + 'count' => 0, |
|
| 418 | + 'bulk_action' => array( |
|
| 419 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 420 | + ), |
|
| 421 | + ), |
|
| 422 | + ); |
|
| 423 | + |
|
| 424 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 425 | + 'ee_delete_question_groups', |
|
| 426 | + 'espresso_registration_form_trash_question_groups' |
|
| 427 | + ) |
|
| 428 | + ) { |
|
| 429 | + $this->_views['trash'] = array( |
|
| 430 | + 'slug' => 'trash', |
|
| 431 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 432 | + 'count' => 0, |
|
| 433 | + 'bulk_action' => array( |
|
| 434 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 435 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 436 | + ), |
|
| 437 | + ); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @return void |
|
| 444 | + * @throws EE_Error |
|
| 445 | + * @throws InvalidArgumentException |
|
| 446 | + * @throws InvalidDataTypeException |
|
| 447 | + * @throws InvalidInterfaceException |
|
| 448 | + */ |
|
| 449 | + protected function _questions_overview_list_table() |
|
| 450 | + { |
|
| 451 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 452 | + 'add_question', |
|
| 453 | + 'add_question', |
|
| 454 | + array(), |
|
| 455 | + 'add-new-h2' |
|
| 456 | + ); |
|
| 457 | + parent::_questions_overview_list_table(); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @return void |
|
| 463 | + * @throws DomainException |
|
| 464 | + * @throws EE_Error |
|
| 465 | + * @throws InvalidArgumentException |
|
| 466 | + * @throws InvalidDataTypeException |
|
| 467 | + * @throws InvalidInterfaceException |
|
| 468 | + */ |
|
| 469 | + protected function _question_groups_overview_list_table() |
|
| 470 | + { |
|
| 471 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 472 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 473 | + 'add_question_group', |
|
| 474 | + 'add_question_group', |
|
| 475 | + array(), |
|
| 476 | + 'add-new-h2' |
|
| 477 | + ); |
|
| 478 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @return void |
|
| 484 | + * @throws EE_Error |
|
| 485 | + * @throws InvalidArgumentException |
|
| 486 | + * @throws InvalidDataTypeException |
|
| 487 | + * @throws InvalidInterfaceException |
|
| 488 | + */ |
|
| 489 | + protected function _delete_question() |
|
| 490 | + { |
|
| 491 | + $success = $this->_delete_items($this->_question_model); |
|
| 492 | + $this->_redirect_after_action( |
|
| 493 | + $success, |
|
| 494 | + $this->_question_model->item_name($success), |
|
| 495 | + 'deleted', |
|
| 496 | + array('action' => 'default', 'status' => 'all') |
|
| 497 | + ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @return void |
|
| 503 | + * @throws EE_Error |
|
| 504 | + * @throws InvalidArgumentException |
|
| 505 | + * @throws InvalidDataTypeException |
|
| 506 | + * @throws InvalidInterfaceException |
|
| 507 | + */ |
|
| 508 | + protected function _delete_questions() |
|
| 509 | + { |
|
| 510 | + $success = $this->_delete_items($this->_question_model); |
|
| 511 | + $this->_redirect_after_action( |
|
| 512 | + $success, |
|
| 513 | + $this->_question_model->item_name($success), |
|
| 514 | + 'deleted permanently', |
|
| 515 | + array('action' => 'default', 'status' => 'trash') |
|
| 516 | + ); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Performs the deletion of a single or multiple questions or question groups. |
|
| 522 | + * |
|
| 523 | + * @param EEM_Soft_Delete_Base $model |
|
| 524 | + * @return int number of items deleted permanently |
|
| 525 | + * @throws EE_Error |
|
| 526 | + * @throws InvalidArgumentException |
|
| 527 | + * @throws InvalidDataTypeException |
|
| 528 | + * @throws InvalidInterfaceException |
|
| 529 | + */ |
|
| 530 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 531 | + { |
|
| 532 | + $success = 0; |
|
| 533 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 534 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 535 | + // if array has more than one element than success message should be plural |
|
| 536 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 537 | + // cycle thru bulk action checkboxes |
|
| 538 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 539 | + if (! $this->_delete_item($ID, $model)) { |
|
| 540 | + $success = 0; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 544 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 545 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 546 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 547 | + } else { |
|
| 548 | + EE_Error::add_error( |
|
| 549 | + sprintf( |
|
| 550 | + esc_html__( |
|
| 551 | + "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 552 | + "event_espresso" |
|
| 553 | + ) |
|
| 554 | + ), |
|
| 555 | + __FILE__, |
|
| 556 | + __FUNCTION__, |
|
| 557 | + __LINE__ |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + return $success; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Deletes the specified question (and its associated question options) or question group |
|
| 566 | + * |
|
| 567 | + * @param int $id |
|
| 568 | + * @param EEM_Soft_Delete_Base $model |
|
| 569 | + * @return boolean |
|
| 570 | + * @throws EE_Error |
|
| 571 | + * @throws InvalidArgumentException |
|
| 572 | + * @throws InvalidDataTypeException |
|
| 573 | + * @throws InvalidInterfaceException |
|
| 574 | + */ |
|
| 575 | + protected function _delete_item($id, $model) |
|
| 576 | + { |
|
| 577 | + if ($model instanceof EEM_Question) { |
|
| 578 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 579 | + } |
|
| 580 | + return $model->delete_permanently_by_ID(absint($id)); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /****************************** QUESTION GROUPS ******************************/ |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * @param string $type |
|
| 589 | + * @return void |
|
| 590 | + * @throws DomainException |
|
| 591 | + * @throws EE_Error |
|
| 592 | + * @throws InvalidArgumentException |
|
| 593 | + * @throws InvalidDataTypeException |
|
| 594 | + * @throws InvalidInterfaceException |
|
| 595 | + */ |
|
| 596 | + protected function _edit_question_group($type = 'add') |
|
| 597 | + { |
|
| 598 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 599 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
| 600 | + ? absint($this->_req_data['QSG_ID']) |
|
| 601 | + : false; |
|
| 602 | + |
|
| 603 | + switch ($this->_req_action) { |
|
| 604 | + case 'add_question_group': |
|
| 605 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 606 | + break; |
|
| 607 | + case 'edit_question_group': |
|
| 608 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 609 | + break; |
|
| 610 | + default: |
|
| 611 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 612 | + } |
|
| 613 | + // add ID to title if editing |
|
| 614 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 615 | + if ($ID) { |
|
| 616 | + /** @var EE_Question_Group $questionGroup */ |
|
| 617 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 618 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 619 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 620 | + } else { |
|
| 621 | + /** @var EE_Question_Group $questionGroup */ |
|
| 622 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 623 | + $questionGroup->set_order_to_latest(); |
|
| 624 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 625 | + } |
|
| 626 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 627 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 628 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 629 | + $this->_template_args['question_group'] = $questionGroup; |
|
| 630 | + |
|
| 631 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 632 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 633 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 634 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 635 | + $this->_template_args, |
|
| 636 | + true |
|
| 637 | + ); |
|
| 638 | + |
|
| 639 | + // the details template wrapper |
|
| 640 | + $this->display_admin_page_with_sidebar(); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * @return void |
|
| 646 | + * @throws EE_Error |
|
| 647 | + * @throws InvalidArgumentException |
|
| 648 | + * @throws InvalidDataTypeException |
|
| 649 | + * @throws InvalidInterfaceException |
|
| 650 | + */ |
|
| 651 | + protected function _delete_question_groups() |
|
| 652 | + { |
|
| 653 | + $success = $this->_delete_items($this->_question_group_model); |
|
| 654 | + $this->_redirect_after_action( |
|
| 655 | + $success, |
|
| 656 | + $this->_question_group_model->item_name($success), |
|
| 657 | + 'deleted permanently', |
|
| 658 | + array('action' => 'question_groups', 'status' => 'trash') |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * @param bool $new_question_group |
|
| 665 | + * @throws EE_Error |
|
| 666 | + * @throws InvalidArgumentException |
|
| 667 | + * @throws InvalidDataTypeException |
|
| 668 | + * @throws InvalidInterfaceException |
|
| 669 | + */ |
|
| 670 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
| 671 | + { |
|
| 672 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 673 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 674 | + if ($new_question_group) { |
|
| 675 | + // make sure identifier is unique |
|
| 676 | + $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
| 677 | + $identifier_exists = ! empty($identifier_value) |
|
| 678 | + ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
| 679 | + : false; |
|
| 680 | + if ($identifier_exists) { |
|
| 681 | + $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
| 682 | + } |
|
| 683 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 684 | + $success = $QSG_ID ? 1 : 0; |
|
| 685 | + if ($success === 0) { |
|
| 686 | + EE_Error::add_error( |
|
| 687 | + esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
| 688 | + __FILE__, |
|
| 689 | + __FUNCTION__, |
|
| 690 | + __LINE__ |
|
| 691 | + ); |
|
| 692 | + $this->_redirect_after_action( |
|
| 693 | + false, |
|
| 694 | + '', |
|
| 695 | + '', |
|
| 696 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 697 | + true |
|
| 698 | + ); |
|
| 699 | + } |
|
| 700 | + } else { |
|
| 701 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 702 | + unset($set_column_values['QSG_ID']); |
|
| 703 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
| 707 | + EEM_Attendee::system_question_phone |
|
| 708 | + ); |
|
| 709 | + // update the existing related questions |
|
| 710 | + // BUT FIRST... delete the phone question from the Question_Group_Question |
|
| 711 | + // if it is being added to this question group (therefore removed from the existing group) |
|
| 712 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
| 713 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 714 | + EEM_Question_Group_Question::instance()->delete( |
|
| 715 | + array( |
|
| 716 | + array( |
|
| 717 | + 'QST_ID' => $phone_question_id, |
|
| 718 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
| 719 | + ), |
|
| 720 | + ) |
|
| 721 | + ); |
|
| 722 | + } |
|
| 723 | + /** @type EE_Question_Group $question_group */ |
|
| 724 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 725 | + $questions = $question_group->questions(); |
|
| 726 | + // make sure system phone question is added to list of questions for this group |
|
| 727 | + if (! isset($questions[ $phone_question_id ])) { |
|
| 728 | + $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + foreach ($questions as $question_ID => $question) { |
|
| 732 | + // first we always check for order. |
|
| 733 | + if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
| 734 | + // update question order |
|
| 735 | + $question_group->update_question_order( |
|
| 736 | + $question_ID, |
|
| 737 | + $this->_req_data['question_orders'][ $question_ID ] |
|
| 738 | + ); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + // then we always check if adding or removing. |
|
| 742 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
| 743 | + $question_group->add_question($question_ID); |
|
| 744 | + } else { |
|
| 745 | + // not found, remove it (but only if not a system question for the personal group |
|
| 746 | + // with the exception of lname system question - we allow removal of it) |
|
| 747 | + if (in_array( |
|
| 748 | + $question->system_ID(), |
|
| 749 | + EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
| 750 | + $question_group->system_group() |
|
| 751 | + ) |
|
| 752 | + )) { |
|
| 753 | + continue; |
|
| 754 | + } else { |
|
| 755 | + $question_group->remove_question($question_ID); |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + // save new related questions |
|
| 760 | + if (isset($this->_req_data['questions'])) { |
|
| 761 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 762 | + $question_group->add_question($QST_ID); |
|
| 763 | + if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
| 764 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + if ($success !== false) { |
|
| 770 | + $msg = $new_question_group |
|
| 771 | + ? sprintf( |
|
| 772 | + esc_html__('The %s has been created', 'event_espresso'), |
|
| 773 | + $this->_question_group_model->item_name() |
|
| 774 | + ) |
|
| 775 | + : sprintf( |
|
| 776 | + esc_html__( |
|
| 777 | + 'The %s has been updated', |
|
| 778 | + 'event_espresso' |
|
| 779 | + ), |
|
| 780 | + $this->_question_group_model->item_name() |
|
| 781 | + ); |
|
| 782 | + EE_Error::add_success($msg); |
|
| 783 | + } |
|
| 784 | + $this->_redirect_after_action( |
|
| 785 | + false, |
|
| 786 | + '', |
|
| 787 | + '', |
|
| 788 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 789 | + true |
|
| 790 | + ); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * duplicates a question and all its question options and redirects to the new question. |
|
| 796 | + * |
|
| 797 | + * @return void |
|
| 798 | + * @throws EE_Error |
|
| 799 | + * @throws InvalidArgumentException |
|
| 800 | + * @throws ReflectionException |
|
| 801 | + * @throws InvalidDataTypeException |
|
| 802 | + * @throws InvalidInterfaceException |
|
| 803 | + */ |
|
| 804 | + public function _duplicate_question() |
|
| 805 | + { |
|
| 806 | + $question_ID = (int) $this->_req_data['QST_ID']; |
|
| 807 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 808 | + if ($question instanceof EE_Question) { |
|
| 809 | + $new_question = $question->duplicate(); |
|
| 810 | + if ($new_question instanceof EE_Question) { |
|
| 811 | + $this->_redirect_after_action( |
|
| 812 | + true, |
|
| 813 | + esc_html__('Question', 'event_espresso'), |
|
| 814 | + esc_html__('Duplicated', 'event_espresso'), |
|
| 815 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
| 816 | + true |
|
| 817 | + ); |
|
| 818 | + } else { |
|
| 819 | + global $wpdb; |
|
| 820 | + EE_Error::add_error( |
|
| 821 | + sprintf( |
|
| 822 | + esc_html__( |
|
| 823 | + 'Could not duplicate question with ID %1$d because: %2$s', |
|
| 824 | + 'event_espresso' |
|
| 825 | + ), |
|
| 826 | + $question_ID, |
|
| 827 | + $wpdb->last_error |
|
| 828 | + ), |
|
| 829 | + __FILE__, |
|
| 830 | + __FUNCTION__, |
|
| 831 | + __LINE__ |
|
| 832 | + ); |
|
| 833 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 834 | + } |
|
| 835 | + } else { |
|
| 836 | + EE_Error::add_error( |
|
| 837 | + sprintf( |
|
| 838 | + esc_html__( |
|
| 839 | + 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 840 | + 'event_espresso' |
|
| 841 | + ), |
|
| 842 | + $question_ID |
|
| 843 | + ), |
|
| 844 | + __FILE__, |
|
| 845 | + __FUNCTION__, |
|
| 846 | + __LINE__ |
|
| 847 | + ); |
|
| 848 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * @param bool $trash |
|
| 855 | + * @throws EE_Error |
|
| 856 | + */ |
|
| 857 | + protected function _trash_or_restore_question_groups($trash = true) |
|
| 858 | + { |
|
| 859 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + *_trash_question |
|
| 865 | + * |
|
| 866 | + * @return void |
|
| 867 | + * @throws EE_Error |
|
| 868 | + */ |
|
| 869 | + protected function _trash_question() |
|
| 870 | + { |
|
| 871 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
| 872 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 873 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * @param bool $trash |
|
| 879 | + * @throws EE_Error |
|
| 880 | + */ |
|
| 881 | + protected function _trash_or_restore_questions($trash = true) |
|
| 882 | + { |
|
| 883 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
| 889 | + * flexible between question or question groups |
|
| 890 | + * |
|
| 891 | + * @param EEM_Soft_Delete_Base $model |
|
| 892 | + * @param boolean $trash whether to trash or restore |
|
| 893 | + * @throws EE_Error |
|
| 894 | + */ |
|
| 895 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 896 | + { |
|
| 897 | + |
|
| 898 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 899 | + |
|
| 900 | + $success = 1; |
|
| 901 | + // Checkboxes |
|
| 902 | + // echo "trash $trash"; |
|
| 903 | + // var_dump($this->_req_data['checkbox']);die; |
|
| 904 | + if (isset($this->_req_data['checkbox'])) { |
|
| 905 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 906 | + // if array has more than one element than success message should be plural |
|
| 907 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 908 | + // cycle thru bulk action checkboxes |
|
| 909 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 910 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 911 | + $success = 0; |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + } else { |
|
| 915 | + // grab single id and delete |
|
| 916 | + $ID = absint($this->_req_data['checkbox']); |
|
| 917 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 918 | + $success = 0; |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + } else { |
|
| 922 | + // delete via trash link |
|
| 923 | + // grab single id and delete |
|
| 924 | + $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 925 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 926 | + $success = 0; |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
| 932 | + // echo "action :$action"; |
|
| 933 | + // $action = 'questions' ? 'default' : $action; |
|
| 934 | + if ($trash) { |
|
| 935 | + $action_desc = 'trashed'; |
|
| 936 | + $status = 'trash'; |
|
| 937 | + } else { |
|
| 938 | + $action_desc = 'restored'; |
|
| 939 | + $status = 'all'; |
|
| 940 | + } |
|
| 941 | + $this->_redirect_after_action( |
|
| 942 | + $success, |
|
| 943 | + $model->item_name($success), |
|
| 944 | + $action_desc, |
|
| 945 | + array('action' => $action, 'status' => $status) |
|
| 946 | + ); |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + |
|
| 950 | + /** |
|
| 951 | + * @param $per_page |
|
| 952 | + * @param int $current_page |
|
| 953 | + * @param bool|false $count |
|
| 954 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 955 | + * @throws EE_Error |
|
| 956 | + * @throws InvalidArgumentException |
|
| 957 | + * @throws InvalidDataTypeException |
|
| 958 | + * @throws InvalidInterfaceException |
|
| 959 | + */ |
|
| 960 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 961 | + { |
|
| 962 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 963 | + |
|
| 964 | + if ($count) { |
|
| 965 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 966 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 967 | + $results = $this->_question_model->count_deleted($where); |
|
| 968 | + } else { |
|
| 969 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 970 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
| 971 | + } |
|
| 972 | + return $results; |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + |
|
| 976 | + /** |
|
| 977 | + * @param $per_page |
|
| 978 | + * @param int $current_page |
|
| 979 | + * @param bool|false $count |
|
| 980 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 981 | + * @throws EE_Error |
|
| 982 | + * @throws InvalidArgumentException |
|
| 983 | + * @throws InvalidDataTypeException |
|
| 984 | + * @throws InvalidInterfaceException |
|
| 985 | + */ |
|
| 986 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 987 | + { |
|
| 988 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 989 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 990 | + if ($count) { |
|
| 991 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 992 | + $results = $questionGroupModel->count($where); |
|
| 993 | + } else { |
|
| 994 | + $results = $questionGroupModel->get_all($query_params); |
|
| 995 | + } |
|
| 996 | + return $results; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * @param $per_page |
|
| 1002 | + * @param int $current_page |
|
| 1003 | + * @param bool $count |
|
| 1004 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1005 | + * @throws EE_Error |
|
| 1006 | + * @throws InvalidArgumentException |
|
| 1007 | + * @throws InvalidDataTypeException |
|
| 1008 | + * @throws InvalidInterfaceException |
|
| 1009 | + */ |
|
| 1010 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 1011 | + { |
|
| 1012 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 1013 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 1014 | + if ($count) { |
|
| 1015 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 1016 | + $query_params['limit'] = null; |
|
| 1017 | + $results = $questionGroupModel->count_deleted($where); |
|
| 1018 | + } else { |
|
| 1019 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 1020 | + } |
|
| 1021 | + return $results; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * method for performing updates to question order |
|
| 1027 | + * |
|
| 1028 | + * @return void results array |
|
| 1029 | + * @throws EE_Error |
|
| 1030 | + * @throws InvalidArgumentException |
|
| 1031 | + * @throws InvalidDataTypeException |
|
| 1032 | + * @throws InvalidInterfaceException |
|
| 1033 | + */ |
|
| 1034 | + public function update_question_group_order() |
|
| 1035 | + { |
|
| 1036 | + |
|
| 1037 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 1038 | + |
|
| 1039 | + // grab our row IDs |
|
| 1040 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 1041 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 1042 | + : array(); |
|
| 1043 | + |
|
| 1044 | + $perpage = ! empty($this->_req_data['perpage']) |
|
| 1045 | + ? (int) $this->_req_data['perpage'] |
|
| 1046 | + : null; |
|
| 1047 | + $curpage = ! empty($this->_req_data['curpage']) |
|
| 1048 | + ? (int) $this->_req_data['curpage'] |
|
| 1049 | + : null; |
|
| 1050 | + |
|
| 1051 | + if (! empty($row_ids)) { |
|
| 1052 | + // figure out where we start the row_id count at for the current page. |
|
| 1053 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 1054 | + |
|
| 1055 | + $row_count = count($row_ids); |
|
| 1056 | + for ($i = 0; $i < $row_count; $i++) { |
|
| 1057 | + // Update the questions when re-ordering |
|
| 1058 | + $updated = EEM_Question_Group::instance()->update( |
|
| 1059 | + array('QSG_order' => $qsgcount), |
|
| 1060 | + array(array('QSG_ID' => $row_ids[ $i ])) |
|
| 1061 | + ); |
|
| 1062 | + if ($updated === false) { |
|
| 1063 | + $success = false; |
|
| 1064 | + } |
|
| 1065 | + $qsgcount++; |
|
| 1066 | + } |
|
| 1067 | + } else { |
|
| 1068 | + $success = false; |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + $errors = ! $success |
|
| 1072 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 1073 | + : false; |
|
| 1074 | + |
|
| 1075 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 1076 | + die(); |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + /** |
|
| 1085 | + * @throws DomainException |
|
| 1086 | + * @throws EE_Error |
|
| 1087 | + * @throws InvalidArgumentException |
|
| 1088 | + * @throws InvalidDataTypeException |
|
| 1089 | + * @throws InvalidInterfaceException |
|
| 1090 | + */ |
|
| 1091 | + protected function _reg_form_settings() |
|
| 1092 | + { |
|
| 1093 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 1094 | + add_action( |
|
| 1095 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 1096 | + array($this, 'email_validation_settings_form'), |
|
| 1097 | + 2 |
|
| 1098 | + ); |
|
| 1099 | + $this->_template_args = (array) apply_filters( |
|
| 1100 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 1101 | + $this->_template_args |
|
| 1102 | + ); |
|
| 1103 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 1104 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1105 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1106 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 1107 | + $this->_template_args, |
|
| 1108 | + true |
|
| 1109 | + ); |
|
| 1110 | + $this->display_admin_page_with_sidebar(); |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * @return void |
|
| 1116 | + * @throws EE_Error |
|
| 1117 | + * @throws InvalidArgumentException |
|
| 1118 | + * @throws ReflectionException |
|
| 1119 | + * @throws InvalidDataTypeException |
|
| 1120 | + * @throws InvalidInterfaceException |
|
| 1121 | + */ |
|
| 1122 | + protected function _update_reg_form_settings() |
|
| 1123 | + { |
|
| 1124 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 1125 | + EE_Registry::instance()->CFG->registration |
|
| 1126 | + ); |
|
| 1127 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 1128 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 1129 | + EE_Registry::instance()->CFG->registration |
|
| 1130 | + ); |
|
| 1131 | + $success = $this->_update_espresso_configuration( |
|
| 1132 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1133 | + EE_Registry::instance()->CFG, |
|
| 1134 | + __FILE__, |
|
| 1135 | + __FUNCTION__, |
|
| 1136 | + __LINE__ |
|
| 1137 | + ); |
|
| 1138 | + $this->_redirect_after_action( |
|
| 1139 | + $success, |
|
| 1140 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1141 | + 'updated', |
|
| 1142 | + array('action' => 'view_reg_form_settings') |
|
| 1143 | + ); |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + |
|
| 1147 | + /** |
|
| 1148 | + * @return void |
|
| 1149 | + * @throws EE_Error |
|
| 1150 | + * @throws InvalidArgumentException |
|
| 1151 | + * @throws InvalidDataTypeException |
|
| 1152 | + * @throws InvalidInterfaceException |
|
| 1153 | + */ |
|
| 1154 | + public function email_validation_settings_form() |
|
| 1155 | + { |
|
| 1156 | + echo $this->_email_validation_settings_form()->get_html(); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + |
|
| 1160 | + /** |
|
| 1161 | + * _email_validation_settings_form |
|
| 1162 | + * |
|
| 1163 | + * @access protected |
|
| 1164 | + * @return EE_Form_Section_Proper |
|
| 1165 | + * @throws \EE_Error |
|
| 1166 | + */ |
|
| 1167 | + protected function _email_validation_settings_form() |
|
| 1168 | + { |
|
| 1169 | + return new EE_Form_Section_Proper( |
|
| 1170 | + array( |
|
| 1171 | + 'name' => 'email_validation_settings', |
|
| 1172 | + 'html_id' => 'email_validation_settings', |
|
| 1173 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1174 | + 'subsections' => apply_filters( |
|
| 1175 | + 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
| 1176 | + array( |
|
| 1177 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 1178 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 1179 | + ), |
|
| 1180 | + 'email_validation_level' => new EE_Select_Input( |
|
| 1181 | + array( |
|
| 1182 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 1183 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 1184 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 1185 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 1186 | + ), |
|
| 1187 | + array( |
|
| 1188 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 1189 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 1190 | + 'html_help_text' => esc_html__( |
|
| 1191 | + 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 1192 | + 'event_espresso' |
|
| 1193 | + ), |
|
| 1194 | + 'default' => isset( |
|
| 1195 | + EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1196 | + ) |
|
| 1197 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 1198 | + : 'wp_default', |
|
| 1199 | + 'required' => false, |
|
| 1200 | + ) |
|
| 1201 | + ), |
|
| 1202 | + ) |
|
| 1203 | + ), |
|
| 1204 | + ) |
|
| 1205 | + ); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + |
|
| 1209 | + /** |
|
| 1210 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1211 | + * @return EE_Registration_Config |
|
| 1212 | + * @throws EE_Error |
|
| 1213 | + * @throws InvalidArgumentException |
|
| 1214 | + * @throws ReflectionException |
|
| 1215 | + * @throws InvalidDataTypeException |
|
| 1216 | + * @throws InvalidInterfaceException |
|
| 1217 | + */ |
|
| 1218 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1219 | + { |
|
| 1220 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1221 | + try { |
|
| 1222 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1223 | + // if not displaying a form, then check for form submission |
|
| 1224 | + if ($email_validation_settings_form->was_submitted()) { |
|
| 1225 | + // capture form data |
|
| 1226 | + $email_validation_settings_form->receive_form_submission(); |
|
| 1227 | + // validate form data |
|
| 1228 | + if ($email_validation_settings_form->is_valid()) { |
|
| 1229 | + // grab validated data from form |
|
| 1230 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1231 | + if (isset($valid_data['email_validation_level'])) { |
|
| 1232 | + $email_validation_level = $valid_data['email_validation_level']; |
|
| 1233 | + // now if they want to use international email addresses |
|
| 1234 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1235 | + // in case we need to reset their email validation level, |
|
| 1236 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1237 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1238 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1239 | + // despite offering poor validation, supports i18n email addresses |
|
| 1240 | + $prev_email_validation_level = 'basic'; |
|
| 1241 | + } |
|
| 1242 | + // confirm our i18n email validation will work on the server |
|
| 1243 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1244 | + // or reset email validation level to previous value |
|
| 1245 | + $email_validation_level = $prev_email_validation_level; |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1249 | + } else { |
|
| 1250 | + EE_Error::add_error( |
|
| 1251 | + esc_html__( |
|
| 1252 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1253 | + 'event_espresso' |
|
| 1254 | + ), |
|
| 1255 | + __FILE__, |
|
| 1256 | + __FUNCTION__, |
|
| 1257 | + __LINE__ |
|
| 1258 | + ); |
|
| 1259 | + } |
|
| 1260 | + } else { |
|
| 1261 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1262 | + EE_Error::add_error( |
|
| 1263 | + $email_validation_settings_form->submission_error_message(), |
|
| 1264 | + __FILE__, |
|
| 1265 | + __FUNCTION__, |
|
| 1266 | + __LINE__ |
|
| 1267 | + ); |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + } catch (EE_Error $e) { |
|
| 1272 | + $e->get_error(); |
|
| 1273 | + } |
|
| 1274 | + return $EE_Registration_Config; |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1280 | + * and that the PCRE version works with our i18n email validation |
|
| 1281 | + * |
|
| 1282 | + * @param EE_Registration_Config $EE_Registration_Config |
|
| 1283 | + * @param string $email_validation_level |
|
| 1284 | + * @return bool |
|
| 1285 | + */ |
|
| 1286 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1287 | + { |
|
| 1288 | + // first check that PCRE is enabled |
|
| 1289 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1290 | + EE_Error::add_error( |
|
| 1291 | + sprintf( |
|
| 1292 | + esc_html__( |
|
| 1293 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1294 | + 'event_espresso' |
|
| 1295 | + ), |
|
| 1296 | + '<br />' |
|
| 1297 | + ), |
|
| 1298 | + __FILE__, |
|
| 1299 | + __FUNCTION__, |
|
| 1300 | + __LINE__ |
|
| 1301 | + ); |
|
| 1302 | + return false; |
|
| 1303 | + } else { |
|
| 1304 | + // PCRE support is enabled, but let's still |
|
| 1305 | + // perform a test to see if the server will support it. |
|
| 1306 | + // but first, save the updated validation level to the config, |
|
| 1307 | + // so that the validation strategy picks it up. |
|
| 1308 | + // this will get bumped back down if it doesn't work |
|
| 1309 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1310 | + try { |
|
| 1311 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1312 | + $i18n_email_address = apply_filters( |
|
| 1313 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1314 | + 'jägerjü[email protected]' |
|
| 1315 | + ); |
|
| 1316 | + $email_validator->validate($i18n_email_address); |
|
| 1317 | + } catch (Exception $e) { |
|
| 1318 | + EE_Error::add_error( |
|
| 1319 | + sprintf( |
|
| 1320 | + esc_html__( |
|
| 1321 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1322 | + 'event_espresso' |
|
| 1323 | + ), |
|
| 1324 | + '<br />', |
|
| 1325 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1326 | + ), |
|
| 1327 | + __FILE__, |
|
| 1328 | + __FUNCTION__, |
|
| 1329 | + __LINE__ |
|
| 1330 | + ); |
|
| 1331 | + return false; |
|
| 1332 | + } |
|
| 1333 | + } |
|
| 1334 | + return true; |
|
| 1335 | + } |
|
| 1336 | 1336 | } |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.79.rc.000'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.79.rc.000'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |