@@ -18,825 +18,825 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class AdminToolBar |
| 20 | 20 | { |
| 21 | - private ?WP_Admin_Bar $admin_bar = null; |
|
| 22 | - |
|
| 23 | - private EE_Capabilities $capabilities; |
|
| 24 | - |
|
| 25 | - private string $events_admin_url = ''; |
|
| 26 | - |
|
| 27 | - private string $menu_class = 'espresso_menu_item_class'; |
|
| 28 | - |
|
| 29 | - private string $reg_admin_url = ''; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * AdminToolBar constructor. |
|
| 34 | - * |
|
| 35 | - * @param EE_Capabilities $capabilities |
|
| 36 | - */ |
|
| 37 | - public function __construct(EE_Capabilities $capabilities) |
|
| 38 | - { |
|
| 39 | - $this->capabilities = $capabilities; |
|
| 40 | - add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100); |
|
| 41 | - $this->enqueueAssets(); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * espresso_toolbar_items |
|
| 47 | - * |
|
| 48 | - * @access public |
|
| 49 | - * @param WP_Admin_Bar $admin_bar |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
| 53 | - { |
|
| 54 | - // if it's an AJAX request, or user is NOT an admin, or in full M-Mode |
|
| 55 | - if ( |
|
| 56 | - (defined('DOING_AJAX') && DOING_AJAX) |
|
| 57 | - || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 58 | - || MaintenanceStatus::isFullSite() |
|
| 59 | - ) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 62 | - $this->admin_bar = $admin_bar; |
|
| 63 | - // we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 64 | - // because they're only defined in each of their respective constructors |
|
| 65 | - // and this might be a frontend request, in which case they aren't available |
|
| 66 | - $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
| 67 | - $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
| 68 | - // now let's add all the menu items |
|
| 69 | - $this->addTopLevelMenu(); |
|
| 70 | - $this->addEventsSubMenu(); |
|
| 71 | - $this->addEventsAddEditHeader(); |
|
| 72 | - $this->addEventsAddNew(); |
|
| 73 | - $this->addEventsEditCurrentEvent(); |
|
| 74 | - $this->addEventsViewHeader(); |
|
| 75 | - $this->addEventsViewAll(); |
|
| 76 | - $this->addEventsViewToday(); |
|
| 77 | - $this->addEventsViewThisMonth(); |
|
| 78 | - $this->addRegistrationSubMenu(); |
|
| 79 | - $this->addRegistrationOverviewToday(); |
|
| 80 | - $this->addRegistrationOverviewTodayApproved(); |
|
| 81 | - $this->addRegistrationOverviewTodayPendingPayment(); |
|
| 82 | - $this->addRegistrationOverviewTodayNotApproved(); |
|
| 83 | - $this->addRegistrationOverviewTodayCancelled(); |
|
| 84 | - $this->addRegistrationOverviewThisMonth(); |
|
| 85 | - $this->addRegistrationOverviewThisMonthApproved(); |
|
| 86 | - $this->addRegistrationOverviewThisMonthPending(); |
|
| 87 | - $this->addRegistrationOverviewThisMonthNotApproved(); |
|
| 88 | - $this->addRegistrationOverviewThisMonthCancelled(); |
|
| 89 | - $this->addExtensionsAndServices(); |
|
| 90 | - $this->addFontSizeSubMenu(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - private function enqueueAssets() |
|
| 98 | - { |
|
| 99 | - wp_register_style( |
|
| 100 | - 'espresso-admin-toolbar', |
|
| 101 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
| 102 | - ['dashicons'], |
|
| 103 | - EVENT_ESPRESSO_VERSION |
|
| 104 | - ); |
|
| 105 | - wp_enqueue_style('espresso-admin-toolbar'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - private function addTopLevelMenu() |
|
| 113 | - { |
|
| 114 | - $this->admin_bar->add_menu( |
|
| 115 | - [ |
|
| 116 | - 'id' => 'espresso-toolbar', |
|
| 117 | - 'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 118 | - . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 119 | - . '</span>', |
|
| 120 | - 'href' => $this->events_admin_url, |
|
| 121 | - 'meta' => [ |
|
| 122 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 123 | - 'class' => $this->menu_class . 'first', |
|
| 124 | - ], |
|
| 125 | - ] |
|
| 126 | - ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return void |
|
| 132 | - */ |
|
| 133 | - private function addEventsSubMenu() |
|
| 134 | - { |
|
| 135 | - if ( |
|
| 136 | - $this->capabilities->current_user_can( |
|
| 137 | - 'ee_read_events', |
|
| 138 | - 'ee_admin_bar_menu_espresso-toolbar-events' |
|
| 139 | - ) |
|
| 140 | - ) { |
|
| 141 | - $this->admin_bar->add_menu( |
|
| 142 | - [ |
|
| 143 | - 'id' => 'espresso-toolbar-events', |
|
| 144 | - 'parent' => 'espresso-toolbar', |
|
| 145 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 146 | - . esc_html__('Events', 'event_espresso'), |
|
| 147 | - 'href' => $this->events_admin_url, |
|
| 148 | - 'meta' => [ |
|
| 149 | - 'title' => esc_html__('Events', 'event_espresso'), |
|
| 150 | - 'target' => '', |
|
| 151 | - 'class' => $this->menu_class, |
|
| 152 | - ], |
|
| 153 | - ] |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return void |
|
| 161 | - */ |
|
| 162 | - private function addEventsAddEditHeader() |
|
| 163 | - { |
|
| 164 | - if ( |
|
| 165 | - $this->capabilities->current_user_can( |
|
| 166 | - 'ee_read_events', |
|
| 167 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 168 | - ) |
|
| 169 | - ) { |
|
| 170 | - $this->admin_bar->add_menu( |
|
| 171 | - [ |
|
| 172 | - 'id' => 'espresso-toolbar-events-add-edit', |
|
| 173 | - 'parent' => 'espresso-toolbar-events', |
|
| 174 | - 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
| 175 | - 'href' => '', |
|
| 176 | - ] |
|
| 177 | - ); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @return void |
|
| 184 | - */ |
|
| 185 | - private function addEventsAddNew() |
|
| 186 | - { |
|
| 187 | - if ( |
|
| 188 | - $this->capabilities->current_user_can( |
|
| 189 | - 'ee_edit_events', |
|
| 190 | - 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
| 191 | - ) |
|
| 192 | - ) { |
|
| 193 | - $this->admin_bar->add_menu( |
|
| 194 | - [ |
|
| 195 | - 'id' => 'espresso-toolbar-events-new', |
|
| 196 | - 'parent' => 'espresso-toolbar-events', |
|
| 197 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 198 | - . esc_html__('Add New', 'event_espresso'), |
|
| 199 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 200 | - ['action' => 'create_new'], |
|
| 201 | - $this->events_admin_url |
|
| 202 | - ), |
|
| 203 | - 'meta' => [ |
|
| 204 | - 'title' => esc_html__('Add New', 'event_espresso'), |
|
| 205 | - 'target' => '', |
|
| 206 | - 'class' => $this->menu_class, |
|
| 207 | - ], |
|
| 208 | - ] |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @return void |
|
| 216 | - */ |
|
| 217 | - private function addEventsEditCurrentEvent() |
|
| 218 | - { |
|
| 219 | - if (is_single() && (get_post_type() === 'espresso_events')) { |
|
| 220 | - // Current post |
|
| 221 | - global $post; |
|
| 222 | - if ( |
|
| 223 | - $this->capabilities->current_user_can( |
|
| 224 | - 'ee_edit_event', |
|
| 225 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', |
|
| 226 | - $post->ID |
|
| 227 | - ) |
|
| 228 | - ) { |
|
| 229 | - $this->admin_bar->add_menu( |
|
| 230 | - [ |
|
| 231 | - 'id' => 'espresso-toolbar-events-edit', |
|
| 232 | - 'parent' => 'espresso-toolbar-events', |
|
| 233 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 234 | - . esc_html__('Edit Event', 'event_espresso'), |
|
| 235 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 236 | - [ |
|
| 237 | - 'action' => 'edit', |
|
| 238 | - 'post' => $post->ID, |
|
| 239 | - ], |
|
| 240 | - $this->events_admin_url |
|
| 241 | - ), |
|
| 242 | - 'meta' => [ |
|
| 243 | - 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
| 244 | - 'target' => '', |
|
| 245 | - 'class' => $this->menu_class, |
|
| 246 | - ], |
|
| 247 | - ] |
|
| 248 | - ); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - private function addEventsViewHeader() |
|
| 258 | - { |
|
| 259 | - if ( |
|
| 260 | - $this->capabilities->current_user_can( |
|
| 261 | - 'ee_read_events', |
|
| 262 | - 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 263 | - ) |
|
| 264 | - ) { |
|
| 265 | - $this->admin_bar->add_menu( |
|
| 266 | - [ |
|
| 267 | - 'id' => 'espresso-toolbar-events-view', |
|
| 268 | - 'parent' => 'espresso-toolbar-events', |
|
| 269 | - 'title' => esc_html__('View', 'event_espresso'), |
|
| 270 | - 'href' => '', |
|
| 271 | - ] |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - private function addEventsViewAll() |
|
| 281 | - { |
|
| 282 | - if ( |
|
| 283 | - $this->capabilities->current_user_can( |
|
| 284 | - 'ee_read_events', |
|
| 285 | - 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
| 286 | - ) |
|
| 287 | - ) { |
|
| 288 | - $this->admin_bar->add_menu( |
|
| 289 | - [ |
|
| 290 | - 'id' => 'espresso-toolbar-events-all', |
|
| 291 | - 'parent' => 'espresso-toolbar-events', |
|
| 292 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 293 | - . esc_html__('All', 'event_espresso'), |
|
| 294 | - 'href' => $this->events_admin_url, |
|
| 295 | - 'meta' => [ |
|
| 296 | - 'title' => esc_html__('All', 'event_espresso'), |
|
| 297 | - 'target' => '', |
|
| 298 | - 'class' => $this->menu_class, |
|
| 299 | - ], |
|
| 300 | - ] |
|
| 301 | - ); |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @return void |
|
| 308 | - */ |
|
| 309 | - private function addEventsViewToday() |
|
| 310 | - { |
|
| 311 | - if ( |
|
| 312 | - $this->capabilities->current_user_can( |
|
| 313 | - 'ee_read_events', |
|
| 314 | - 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
| 315 | - ) |
|
| 316 | - ) { |
|
| 317 | - $this->admin_bar->add_menu( |
|
| 318 | - [ |
|
| 319 | - 'id' => 'espresso-toolbar-events-today', |
|
| 320 | - 'parent' => 'espresso-toolbar-events', |
|
| 321 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 322 | - . esc_html__('Today', 'event_espresso'), |
|
| 323 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 324 | - [ |
|
| 325 | - 'action' => 'default', |
|
| 326 | - 'status' => 'today', |
|
| 327 | - ], |
|
| 328 | - $this->events_admin_url |
|
| 329 | - ), |
|
| 330 | - 'meta' => [ |
|
| 331 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
| 332 | - 'target' => '', |
|
| 333 | - 'class' => $this->menu_class, |
|
| 334 | - ], |
|
| 335 | - ] |
|
| 336 | - ); |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @return void |
|
| 343 | - */ |
|
| 344 | - private function addEventsViewThisMonth() |
|
| 345 | - { |
|
| 346 | - if ( |
|
| 347 | - $this->capabilities->current_user_can( |
|
| 348 | - 'ee_read_events', |
|
| 349 | - 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
| 350 | - ) |
|
| 351 | - ) { |
|
| 352 | - $this->admin_bar->add_menu( |
|
| 353 | - [ |
|
| 354 | - 'id' => 'espresso-toolbar-events-month', |
|
| 355 | - 'parent' => 'espresso-toolbar-events', |
|
| 356 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 357 | - . esc_html__('This Month', 'event_espresso'), |
|
| 358 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 359 | - [ |
|
| 360 | - 'action' => 'default', |
|
| 361 | - 'status' => 'month', |
|
| 362 | - ], |
|
| 363 | - $this->events_admin_url |
|
| 364 | - ), |
|
| 365 | - 'meta' => [ |
|
| 366 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 367 | - 'target' => '', |
|
| 368 | - 'class' => $this->menu_class, |
|
| 369 | - ], |
|
| 370 | - ] |
|
| 371 | - ); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * @return void |
|
| 378 | - */ |
|
| 379 | - private function addRegistrationSubMenu() |
|
| 380 | - { |
|
| 381 | - if ( |
|
| 382 | - $this->capabilities->current_user_can( |
|
| 383 | - 'ee_read_registrations', |
|
| 384 | - 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
| 385 | - ) |
|
| 386 | - ) { |
|
| 387 | - $this->admin_bar->add_menu( |
|
| 388 | - [ |
|
| 389 | - 'id' => 'espresso-toolbar-registrations', |
|
| 390 | - 'parent' => 'espresso-toolbar', |
|
| 391 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 392 | - . esc_html__('Registrations', 'event_espresso'), |
|
| 393 | - 'href' => $this->reg_admin_url, |
|
| 394 | - 'meta' => [ |
|
| 395 | - 'title' => esc_html__('Registrations', 'event_espresso'), |
|
| 396 | - 'target' => '', |
|
| 397 | - 'class' => $this->menu_class, |
|
| 398 | - ], |
|
| 399 | - ] |
|
| 400 | - ); |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @return void |
|
| 407 | - */ |
|
| 408 | - private function addRegistrationOverviewToday() |
|
| 409 | - { |
|
| 410 | - if ( |
|
| 411 | - $this->capabilities->current_user_can( |
|
| 412 | - 'ee_read_registrations', |
|
| 413 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
| 414 | - ) |
|
| 415 | - ) { |
|
| 416 | - $this->admin_bar->add_menu( |
|
| 417 | - [ |
|
| 418 | - 'id' => 'espresso-toolbar-registrations-today', |
|
| 419 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 420 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
| 421 | - 'href' => '', |
|
| 422 | - 'meta' => [ |
|
| 423 | - 'title' => esc_html__('Today', 'event_espresso'), |
|
| 424 | - 'target' => '', |
|
| 425 | - 'class' => $this->menu_class, |
|
| 426 | - ], |
|
| 427 | - ] |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @return void |
|
| 435 | - */ |
|
| 436 | - private function addRegistrationOverviewTodayApproved() |
|
| 437 | - { |
|
| 438 | - if ( |
|
| 439 | - $this->capabilities->current_user_can( |
|
| 440 | - 'ee_read_registrations', |
|
| 441 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
| 442 | - ) |
|
| 443 | - ) { |
|
| 444 | - $this->admin_bar->add_menu( |
|
| 445 | - [ |
|
| 446 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 447 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 448 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 449 | - . esc_html__('Approved', 'event_espresso'), |
|
| 450 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 451 | - [ |
|
| 452 | - 'action' => 'default', |
|
| 453 | - 'status' => 'today', |
|
| 454 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 455 | - ], |
|
| 456 | - $this->reg_admin_url |
|
| 457 | - ), |
|
| 458 | - 'meta' => [ |
|
| 459 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 460 | - 'target' => '', |
|
| 461 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 462 | - ], |
|
| 463 | - ] |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * @return void |
|
| 471 | - */ |
|
| 472 | - private function addRegistrationOverviewTodayPendingPayment() |
|
| 473 | - { |
|
| 474 | - if ( |
|
| 475 | - $this->capabilities->current_user_can( |
|
| 476 | - 'ee_read_registrations', |
|
| 477 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
| 478 | - ) |
|
| 479 | - ) { |
|
| 480 | - $this->admin_bar->add_menu( |
|
| 481 | - [ |
|
| 482 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 483 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 484 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 485 | - . esc_html__('Pending', 'event_espresso'), |
|
| 486 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 487 | - [ |
|
| 488 | - 'action' => 'default', |
|
| 489 | - 'status' => 'today', |
|
| 490 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 491 | - ], |
|
| 492 | - $this->reg_admin_url |
|
| 493 | - ), |
|
| 494 | - 'meta' => [ |
|
| 495 | - 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
| 496 | - 'target' => '', |
|
| 497 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 498 | - ], |
|
| 499 | - ] |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * @return void |
|
| 507 | - */ |
|
| 508 | - private function addRegistrationOverviewTodayNotApproved() |
|
| 509 | - { |
|
| 510 | - if ( |
|
| 511 | - $this->capabilities->current_user_can( |
|
| 512 | - 'ee_read_registrations', |
|
| 513 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
| 514 | - ) |
|
| 515 | - ) { |
|
| 516 | - $this->admin_bar->add_menu( |
|
| 517 | - [ |
|
| 518 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 519 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 520 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 521 | - . esc_html__('Not Approved', 'event_espresso'), |
|
| 522 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 523 | - [ |
|
| 524 | - 'action' => 'default', |
|
| 525 | - 'status' => 'today', |
|
| 526 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 527 | - ], |
|
| 528 | - $this->reg_admin_url |
|
| 529 | - ), |
|
| 530 | - 'meta' => [ |
|
| 531 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 532 | - 'target' => '', |
|
| 533 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 534 | - ], |
|
| 535 | - ] |
|
| 536 | - ); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - private function addRegistrationOverviewTodayCancelled() |
|
| 545 | - { |
|
| 546 | - if ( |
|
| 547 | - $this->capabilities->current_user_can( |
|
| 548 | - 'ee_read_registrations', |
|
| 549 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
| 550 | - ) |
|
| 551 | - ) { |
|
| 552 | - $this->admin_bar->add_menu( |
|
| 553 | - [ |
|
| 554 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 555 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 556 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 557 | - . esc_html__('Cancelled', 'event_espresso'), |
|
| 558 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 559 | - [ |
|
| 560 | - 'action' => 'default', |
|
| 561 | - 'status' => 'today', |
|
| 562 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 563 | - ], |
|
| 564 | - $this->reg_admin_url |
|
| 565 | - ), |
|
| 566 | - 'meta' => [ |
|
| 567 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 568 | - 'target' => '', |
|
| 569 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 570 | - ], |
|
| 571 | - ] |
|
| 572 | - ); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @return void |
|
| 579 | - */ |
|
| 580 | - private function addRegistrationOverviewThisMonth() |
|
| 581 | - { |
|
| 582 | - if ( |
|
| 583 | - $this->capabilities->current_user_can( |
|
| 584 | - 'ee_read_registrations', |
|
| 585 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
| 586 | - ) |
|
| 587 | - ) { |
|
| 588 | - $this->admin_bar->add_menu( |
|
| 589 | - [ |
|
| 590 | - 'id' => 'espresso-toolbar-registrations-month', |
|
| 591 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 592 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 593 | - 'href' => '', // EEH_URL::add_query_args_and_nonce( |
|
| 594 | - // array( |
|
| 595 | - // 'action' => 'default', |
|
| 596 | - // 'status' => 'month' |
|
| 597 | - // ), |
|
| 598 | - // $this->reg_admin_url |
|
| 599 | - // ), |
|
| 600 | - 'meta' => [ |
|
| 601 | - 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 602 | - 'target' => '', |
|
| 603 | - 'class' => $this->menu_class, |
|
| 604 | - ], |
|
| 605 | - ] |
|
| 606 | - ); |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * @return void |
|
| 613 | - */ |
|
| 614 | - private function addRegistrationOverviewThisMonthApproved() |
|
| 615 | - { |
|
| 616 | - if ( |
|
| 617 | - $this->capabilities->current_user_can( |
|
| 618 | - 'ee_read_registrations', |
|
| 619 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
| 620 | - ) |
|
| 621 | - ) { |
|
| 622 | - $this->admin_bar->add_menu( |
|
| 623 | - [ |
|
| 624 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 625 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 626 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 627 | - . esc_html__('Approved', 'event_espresso'), |
|
| 628 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 629 | - [ |
|
| 630 | - 'action' => 'default', |
|
| 631 | - 'status' => 'month', |
|
| 632 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 633 | - ], |
|
| 634 | - $this->reg_admin_url |
|
| 635 | - ), |
|
| 636 | - 'meta' => [ |
|
| 637 | - 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 638 | - 'target' => '', |
|
| 639 | - 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 640 | - ], |
|
| 641 | - ] |
|
| 642 | - ); |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * @return void |
|
| 649 | - */ |
|
| 650 | - private function addRegistrationOverviewThisMonthPending() |
|
| 651 | - { |
|
| 652 | - if ( |
|
| 653 | - $this->capabilities->current_user_can( |
|
| 654 | - 'ee_read_registrations', |
|
| 655 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
| 656 | - ) |
|
| 657 | - ) { |
|
| 658 | - $this->admin_bar->add_menu( |
|
| 659 | - [ |
|
| 660 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 661 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 662 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 663 | - . esc_html__('Pending', 'event_espresso'), |
|
| 664 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 665 | - [ |
|
| 666 | - 'action' => 'default', |
|
| 667 | - 'status' => 'month', |
|
| 668 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 669 | - ], |
|
| 670 | - $this->reg_admin_url |
|
| 671 | - ), |
|
| 672 | - 'meta' => [ |
|
| 673 | - 'title' => esc_html__('Pending', 'event_espresso'), |
|
| 674 | - 'target' => '', |
|
| 675 | - 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 676 | - ], |
|
| 677 | - ] |
|
| 678 | - ); |
|
| 679 | - } |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * @return void |
|
| 685 | - */ |
|
| 686 | - private function addRegistrationOverviewThisMonthNotApproved() |
|
| 687 | - { |
|
| 688 | - if ( |
|
| 689 | - $this->capabilities->current_user_can( |
|
| 690 | - 'ee_read_registrations', |
|
| 691 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
| 692 | - ) |
|
| 693 | - ) { |
|
| 694 | - $this->admin_bar->add_menu( |
|
| 695 | - [ |
|
| 696 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 697 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 698 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 699 | - . esc_html__('Not Approved', 'event_espresso'), |
|
| 700 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 701 | - [ |
|
| 702 | - 'action' => 'default', |
|
| 703 | - 'status' => 'month', |
|
| 704 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 705 | - ], |
|
| 706 | - $this->reg_admin_url |
|
| 707 | - ), |
|
| 708 | - 'meta' => [ |
|
| 709 | - 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 710 | - 'target' => '', |
|
| 711 | - 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 712 | - ], |
|
| 713 | - ] |
|
| 714 | - ); |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * @return void |
|
| 721 | - */ |
|
| 722 | - private function addRegistrationOverviewThisMonthCancelled() |
|
| 723 | - { |
|
| 724 | - if ( |
|
| 725 | - $this->capabilities->current_user_can( |
|
| 726 | - 'ee_read_registrations', |
|
| 727 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
| 728 | - ) |
|
| 729 | - ) { |
|
| 730 | - $this->admin_bar->add_menu( |
|
| 731 | - [ |
|
| 732 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 733 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 734 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 735 | - . esc_html__('Cancelled', 'event_espresso'), |
|
| 736 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 737 | - [ |
|
| 738 | - 'action' => 'default', |
|
| 739 | - 'status' => 'month', |
|
| 740 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 741 | - ], |
|
| 742 | - $this->reg_admin_url |
|
| 743 | - ), |
|
| 744 | - 'meta' => [ |
|
| 745 | - 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 746 | - 'target' => '', |
|
| 747 | - 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 748 | - ], |
|
| 749 | - ] |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * @return void |
|
| 757 | - */ |
|
| 758 | - private function addExtensionsAndServices() |
|
| 759 | - { |
|
| 760 | - if ( |
|
| 761 | - $this->capabilities->current_user_can( |
|
| 762 | - 'ee_read_ee', |
|
| 763 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
| 764 | - ) |
|
| 765 | - ) { |
|
| 766 | - $this->admin_bar->add_menu( |
|
| 767 | - [ |
|
| 768 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 769 | - 'parent' => 'espresso-toolbar', |
|
| 770 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 771 | - . esc_html__('Extensions & Services', 'event_espresso'), |
|
| 772 | - 'href' => admin_url('admin.php?page=espresso_packages'), |
|
| 773 | - 'meta' => [ |
|
| 774 | - 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
| 775 | - 'target' => '', |
|
| 776 | - 'class' => $this->menu_class, |
|
| 777 | - ], |
|
| 778 | - ] |
|
| 779 | - ); |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * @return void |
|
| 786 | - */ |
|
| 787 | - private function addFontSizeSubMenu() |
|
| 788 | - { |
|
| 789 | - if (! is_admin()) { |
|
| 790 | - return; |
|
| 791 | - } |
|
| 792 | - $this->admin_bar->add_menu( |
|
| 793 | - [ |
|
| 794 | - 'id' => 'espresso-toolbar-font-size', |
|
| 795 | - 'parent' => 'espresso-toolbar', |
|
| 796 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 797 | - . esc_html__('Set Font Size', 'event_espresso'), |
|
| 798 | - 'href' => '', |
|
| 799 | - 'meta' => [ |
|
| 800 | - 'title' => esc_html__('Set Font Size', 'event_espresso'), |
|
| 801 | - 'target' => '', |
|
| 802 | - 'class' => $this->menu_class, |
|
| 803 | - ], |
|
| 804 | - ] |
|
| 805 | - ); |
|
| 806 | - |
|
| 807 | - $settings_admin_url = admin_url('admin.php?page=espresso_general_settings'); |
|
| 808 | - |
|
| 809 | - $font_sizes = [ |
|
| 810 | - 'tiny' => AdminFontSize::FONT_SIZE_TINY, |
|
| 811 | - 'smaller' => AdminFontSize::FONT_SIZE_SMALLER, |
|
| 812 | - 'small' => AdminFontSize::FONT_SIZE_SMALL, |
|
| 813 | - 'default' => AdminFontSize::FONT_SIZE_DEFAULT, |
|
| 814 | - 'big' => AdminFontSize::FONT_SIZE_BIG, |
|
| 815 | - 'bigger' => AdminFontSize::FONT_SIZE_BIGGER, |
|
| 816 | - ]; |
|
| 817 | - |
|
| 818 | - foreach ($font_sizes as $font_size => $value) { |
|
| 819 | - $this->admin_bar->add_menu( |
|
| 820 | - [ |
|
| 821 | - 'id' => "espresso-toolbar-set-font-size-$font_size", |
|
| 822 | - 'parent' => 'espresso-toolbar-font-size', |
|
| 823 | - 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 824 | - . sprintf( |
|
| 825 | - /* translators: Font Size Small */ |
|
| 826 | - esc_html__('Font Size %1$s', 'event_espresso'), |
|
| 827 | - ucwords($font_size) |
|
| 828 | - ), |
|
| 829 | - 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 830 | - ['action' => 'set_font_size', 'font_size' => $value], |
|
| 831 | - $settings_admin_url |
|
| 832 | - ), |
|
| 833 | - 'meta' => [ |
|
| 834 | - 'title' => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'), |
|
| 835 | - 'target' => '', |
|
| 836 | - 'class' => $this->menu_class, |
|
| 837 | - ], |
|
| 838 | - ] |
|
| 839 | - ); |
|
| 840 | - } |
|
| 841 | - } |
|
| 21 | + private ?WP_Admin_Bar $admin_bar = null; |
|
| 22 | + |
|
| 23 | + private EE_Capabilities $capabilities; |
|
| 24 | + |
|
| 25 | + private string $events_admin_url = ''; |
|
| 26 | + |
|
| 27 | + private string $menu_class = 'espresso_menu_item_class'; |
|
| 28 | + |
|
| 29 | + private string $reg_admin_url = ''; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * AdminToolBar constructor. |
|
| 34 | + * |
|
| 35 | + * @param EE_Capabilities $capabilities |
|
| 36 | + */ |
|
| 37 | + public function __construct(EE_Capabilities $capabilities) |
|
| 38 | + { |
|
| 39 | + $this->capabilities = $capabilities; |
|
| 40 | + add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100); |
|
| 41 | + $this->enqueueAssets(); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * espresso_toolbar_items |
|
| 47 | + * |
|
| 48 | + * @access public |
|
| 49 | + * @param WP_Admin_Bar $admin_bar |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + public function espressoToolbarItems(WP_Admin_Bar $admin_bar) |
|
| 53 | + { |
|
| 54 | + // if it's an AJAX request, or user is NOT an admin, or in full M-Mode |
|
| 55 | + if ( |
|
| 56 | + (defined('DOING_AJAX') && DOING_AJAX) |
|
| 57 | + || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 58 | + || MaintenanceStatus::isFullSite() |
|
| 59 | + ) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | + $this->admin_bar = $admin_bar; |
|
| 63 | + // we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 64 | + // because they're only defined in each of their respective constructors |
|
| 65 | + // and this might be a frontend request, in which case they aren't available |
|
| 66 | + $this->events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
| 67 | + $this->reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
| 68 | + // now let's add all the menu items |
|
| 69 | + $this->addTopLevelMenu(); |
|
| 70 | + $this->addEventsSubMenu(); |
|
| 71 | + $this->addEventsAddEditHeader(); |
|
| 72 | + $this->addEventsAddNew(); |
|
| 73 | + $this->addEventsEditCurrentEvent(); |
|
| 74 | + $this->addEventsViewHeader(); |
|
| 75 | + $this->addEventsViewAll(); |
|
| 76 | + $this->addEventsViewToday(); |
|
| 77 | + $this->addEventsViewThisMonth(); |
|
| 78 | + $this->addRegistrationSubMenu(); |
|
| 79 | + $this->addRegistrationOverviewToday(); |
|
| 80 | + $this->addRegistrationOverviewTodayApproved(); |
|
| 81 | + $this->addRegistrationOverviewTodayPendingPayment(); |
|
| 82 | + $this->addRegistrationOverviewTodayNotApproved(); |
|
| 83 | + $this->addRegistrationOverviewTodayCancelled(); |
|
| 84 | + $this->addRegistrationOverviewThisMonth(); |
|
| 85 | + $this->addRegistrationOverviewThisMonthApproved(); |
|
| 86 | + $this->addRegistrationOverviewThisMonthPending(); |
|
| 87 | + $this->addRegistrationOverviewThisMonthNotApproved(); |
|
| 88 | + $this->addRegistrationOverviewThisMonthCancelled(); |
|
| 89 | + $this->addExtensionsAndServices(); |
|
| 90 | + $this->addFontSizeSubMenu(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + private function enqueueAssets() |
|
| 98 | + { |
|
| 99 | + wp_register_style( |
|
| 100 | + 'espresso-admin-toolbar', |
|
| 101 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css', |
|
| 102 | + ['dashicons'], |
|
| 103 | + EVENT_ESPRESSO_VERSION |
|
| 104 | + ); |
|
| 105 | + wp_enqueue_style('espresso-admin-toolbar'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + private function addTopLevelMenu() |
|
| 113 | + { |
|
| 114 | + $this->admin_bar->add_menu( |
|
| 115 | + [ |
|
| 116 | + 'id' => 'espresso-toolbar', |
|
| 117 | + 'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 118 | + . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 119 | + . '</span>', |
|
| 120 | + 'href' => $this->events_admin_url, |
|
| 121 | + 'meta' => [ |
|
| 122 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 123 | + 'class' => $this->menu_class . 'first', |
|
| 124 | + ], |
|
| 125 | + ] |
|
| 126 | + ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return void |
|
| 132 | + */ |
|
| 133 | + private function addEventsSubMenu() |
|
| 134 | + { |
|
| 135 | + if ( |
|
| 136 | + $this->capabilities->current_user_can( |
|
| 137 | + 'ee_read_events', |
|
| 138 | + 'ee_admin_bar_menu_espresso-toolbar-events' |
|
| 139 | + ) |
|
| 140 | + ) { |
|
| 141 | + $this->admin_bar->add_menu( |
|
| 142 | + [ |
|
| 143 | + 'id' => 'espresso-toolbar-events', |
|
| 144 | + 'parent' => 'espresso-toolbar', |
|
| 145 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 146 | + . esc_html__('Events', 'event_espresso'), |
|
| 147 | + 'href' => $this->events_admin_url, |
|
| 148 | + 'meta' => [ |
|
| 149 | + 'title' => esc_html__('Events', 'event_espresso'), |
|
| 150 | + 'target' => '', |
|
| 151 | + 'class' => $this->menu_class, |
|
| 152 | + ], |
|
| 153 | + ] |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return void |
|
| 161 | + */ |
|
| 162 | + private function addEventsAddEditHeader() |
|
| 163 | + { |
|
| 164 | + if ( |
|
| 165 | + $this->capabilities->current_user_can( |
|
| 166 | + 'ee_read_events', |
|
| 167 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 168 | + ) |
|
| 169 | + ) { |
|
| 170 | + $this->admin_bar->add_menu( |
|
| 171 | + [ |
|
| 172 | + 'id' => 'espresso-toolbar-events-add-edit', |
|
| 173 | + 'parent' => 'espresso-toolbar-events', |
|
| 174 | + 'title' => esc_html__('Add / Edit', 'event_espresso'), |
|
| 175 | + 'href' => '', |
|
| 176 | + ] |
|
| 177 | + ); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @return void |
|
| 184 | + */ |
|
| 185 | + private function addEventsAddNew() |
|
| 186 | + { |
|
| 187 | + if ( |
|
| 188 | + $this->capabilities->current_user_can( |
|
| 189 | + 'ee_edit_events', |
|
| 190 | + 'ee_admin_bar_menu_espresso-toolbar-events-new' |
|
| 191 | + ) |
|
| 192 | + ) { |
|
| 193 | + $this->admin_bar->add_menu( |
|
| 194 | + [ |
|
| 195 | + 'id' => 'espresso-toolbar-events-new', |
|
| 196 | + 'parent' => 'espresso-toolbar-events', |
|
| 197 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 198 | + . esc_html__('Add New', 'event_espresso'), |
|
| 199 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 200 | + ['action' => 'create_new'], |
|
| 201 | + $this->events_admin_url |
|
| 202 | + ), |
|
| 203 | + 'meta' => [ |
|
| 204 | + 'title' => esc_html__('Add New', 'event_espresso'), |
|
| 205 | + 'target' => '', |
|
| 206 | + 'class' => $this->menu_class, |
|
| 207 | + ], |
|
| 208 | + ] |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @return void |
|
| 216 | + */ |
|
| 217 | + private function addEventsEditCurrentEvent() |
|
| 218 | + { |
|
| 219 | + if (is_single() && (get_post_type() === 'espresso_events')) { |
|
| 220 | + // Current post |
|
| 221 | + global $post; |
|
| 222 | + if ( |
|
| 223 | + $this->capabilities->current_user_can( |
|
| 224 | + 'ee_edit_event', |
|
| 225 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', |
|
| 226 | + $post->ID |
|
| 227 | + ) |
|
| 228 | + ) { |
|
| 229 | + $this->admin_bar->add_menu( |
|
| 230 | + [ |
|
| 231 | + 'id' => 'espresso-toolbar-events-edit', |
|
| 232 | + 'parent' => 'espresso-toolbar-events', |
|
| 233 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 234 | + . esc_html__('Edit Event', 'event_espresso'), |
|
| 235 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 236 | + [ |
|
| 237 | + 'action' => 'edit', |
|
| 238 | + 'post' => $post->ID, |
|
| 239 | + ], |
|
| 240 | + $this->events_admin_url |
|
| 241 | + ), |
|
| 242 | + 'meta' => [ |
|
| 243 | + 'title' => esc_html__('Edit Event', 'event_espresso'), |
|
| 244 | + 'target' => '', |
|
| 245 | + 'class' => $this->menu_class, |
|
| 246 | + ], |
|
| 247 | + ] |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + private function addEventsViewHeader() |
|
| 258 | + { |
|
| 259 | + if ( |
|
| 260 | + $this->capabilities->current_user_can( |
|
| 261 | + 'ee_read_events', |
|
| 262 | + 'ee_admin_bar_menu_espresso-toolbar-events-view' |
|
| 263 | + ) |
|
| 264 | + ) { |
|
| 265 | + $this->admin_bar->add_menu( |
|
| 266 | + [ |
|
| 267 | + 'id' => 'espresso-toolbar-events-view', |
|
| 268 | + 'parent' => 'espresso-toolbar-events', |
|
| 269 | + 'title' => esc_html__('View', 'event_espresso'), |
|
| 270 | + 'href' => '', |
|
| 271 | + ] |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + private function addEventsViewAll() |
|
| 281 | + { |
|
| 282 | + if ( |
|
| 283 | + $this->capabilities->current_user_can( |
|
| 284 | + 'ee_read_events', |
|
| 285 | + 'ee_admin_bar_menu_espresso-toolbar-events-all' |
|
| 286 | + ) |
|
| 287 | + ) { |
|
| 288 | + $this->admin_bar->add_menu( |
|
| 289 | + [ |
|
| 290 | + 'id' => 'espresso-toolbar-events-all', |
|
| 291 | + 'parent' => 'espresso-toolbar-events', |
|
| 292 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 293 | + . esc_html__('All', 'event_espresso'), |
|
| 294 | + 'href' => $this->events_admin_url, |
|
| 295 | + 'meta' => [ |
|
| 296 | + 'title' => esc_html__('All', 'event_espresso'), |
|
| 297 | + 'target' => '', |
|
| 298 | + 'class' => $this->menu_class, |
|
| 299 | + ], |
|
| 300 | + ] |
|
| 301 | + ); |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @return void |
|
| 308 | + */ |
|
| 309 | + private function addEventsViewToday() |
|
| 310 | + { |
|
| 311 | + if ( |
|
| 312 | + $this->capabilities->current_user_can( |
|
| 313 | + 'ee_read_events', |
|
| 314 | + 'ee_admin_bar_menu_espresso-toolbar-events-today' |
|
| 315 | + ) |
|
| 316 | + ) { |
|
| 317 | + $this->admin_bar->add_menu( |
|
| 318 | + [ |
|
| 319 | + 'id' => 'espresso-toolbar-events-today', |
|
| 320 | + 'parent' => 'espresso-toolbar-events', |
|
| 321 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 322 | + . esc_html__('Today', 'event_espresso'), |
|
| 323 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 324 | + [ |
|
| 325 | + 'action' => 'default', |
|
| 326 | + 'status' => 'today', |
|
| 327 | + ], |
|
| 328 | + $this->events_admin_url |
|
| 329 | + ), |
|
| 330 | + 'meta' => [ |
|
| 331 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
| 332 | + 'target' => '', |
|
| 333 | + 'class' => $this->menu_class, |
|
| 334 | + ], |
|
| 335 | + ] |
|
| 336 | + ); |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @return void |
|
| 343 | + */ |
|
| 344 | + private function addEventsViewThisMonth() |
|
| 345 | + { |
|
| 346 | + if ( |
|
| 347 | + $this->capabilities->current_user_can( |
|
| 348 | + 'ee_read_events', |
|
| 349 | + 'ee_admin_bar_menu_espresso-toolbar-events-month' |
|
| 350 | + ) |
|
| 351 | + ) { |
|
| 352 | + $this->admin_bar->add_menu( |
|
| 353 | + [ |
|
| 354 | + 'id' => 'espresso-toolbar-events-month', |
|
| 355 | + 'parent' => 'espresso-toolbar-events', |
|
| 356 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 357 | + . esc_html__('This Month', 'event_espresso'), |
|
| 358 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 359 | + [ |
|
| 360 | + 'action' => 'default', |
|
| 361 | + 'status' => 'month', |
|
| 362 | + ], |
|
| 363 | + $this->events_admin_url |
|
| 364 | + ), |
|
| 365 | + 'meta' => [ |
|
| 366 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 367 | + 'target' => '', |
|
| 368 | + 'class' => $this->menu_class, |
|
| 369 | + ], |
|
| 370 | + ] |
|
| 371 | + ); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * @return void |
|
| 378 | + */ |
|
| 379 | + private function addRegistrationSubMenu() |
|
| 380 | + { |
|
| 381 | + if ( |
|
| 382 | + $this->capabilities->current_user_can( |
|
| 383 | + 'ee_read_registrations', |
|
| 384 | + 'ee_admin_bar_menu_espresso-toolbar-registrations' |
|
| 385 | + ) |
|
| 386 | + ) { |
|
| 387 | + $this->admin_bar->add_menu( |
|
| 388 | + [ |
|
| 389 | + 'id' => 'espresso-toolbar-registrations', |
|
| 390 | + 'parent' => 'espresso-toolbar', |
|
| 391 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 392 | + . esc_html__('Registrations', 'event_espresso'), |
|
| 393 | + 'href' => $this->reg_admin_url, |
|
| 394 | + 'meta' => [ |
|
| 395 | + 'title' => esc_html__('Registrations', 'event_espresso'), |
|
| 396 | + 'target' => '', |
|
| 397 | + 'class' => $this->menu_class, |
|
| 398 | + ], |
|
| 399 | + ] |
|
| 400 | + ); |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @return void |
|
| 407 | + */ |
|
| 408 | + private function addRegistrationOverviewToday() |
|
| 409 | + { |
|
| 410 | + if ( |
|
| 411 | + $this->capabilities->current_user_can( |
|
| 412 | + 'ee_read_registrations', |
|
| 413 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today' |
|
| 414 | + ) |
|
| 415 | + ) { |
|
| 416 | + $this->admin_bar->add_menu( |
|
| 417 | + [ |
|
| 418 | + 'id' => 'espresso-toolbar-registrations-today', |
|
| 419 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 420 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
| 421 | + 'href' => '', |
|
| 422 | + 'meta' => [ |
|
| 423 | + 'title' => esc_html__('Today', 'event_espresso'), |
|
| 424 | + 'target' => '', |
|
| 425 | + 'class' => $this->menu_class, |
|
| 426 | + ], |
|
| 427 | + ] |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @return void |
|
| 435 | + */ |
|
| 436 | + private function addRegistrationOverviewTodayApproved() |
|
| 437 | + { |
|
| 438 | + if ( |
|
| 439 | + $this->capabilities->current_user_can( |
|
| 440 | + 'ee_read_registrations', |
|
| 441 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' |
|
| 442 | + ) |
|
| 443 | + ) { |
|
| 444 | + $this->admin_bar->add_menu( |
|
| 445 | + [ |
|
| 446 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 447 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 448 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 449 | + . esc_html__('Approved', 'event_espresso'), |
|
| 450 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 451 | + [ |
|
| 452 | + 'action' => 'default', |
|
| 453 | + 'status' => 'today', |
|
| 454 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 455 | + ], |
|
| 456 | + $this->reg_admin_url |
|
| 457 | + ), |
|
| 458 | + 'meta' => [ |
|
| 459 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 460 | + 'target' => '', |
|
| 461 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 462 | + ], |
|
| 463 | + ] |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * @return void |
|
| 471 | + */ |
|
| 472 | + private function addRegistrationOverviewTodayPendingPayment() |
|
| 473 | + { |
|
| 474 | + if ( |
|
| 475 | + $this->capabilities->current_user_can( |
|
| 476 | + 'ee_read_registrations', |
|
| 477 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' |
|
| 478 | + ) |
|
| 479 | + ) { |
|
| 480 | + $this->admin_bar->add_menu( |
|
| 481 | + [ |
|
| 482 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 483 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 484 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 485 | + . esc_html__('Pending', 'event_espresso'), |
|
| 486 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 487 | + [ |
|
| 488 | + 'action' => 'default', |
|
| 489 | + 'status' => 'today', |
|
| 490 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 491 | + ], |
|
| 492 | + $this->reg_admin_url |
|
| 493 | + ), |
|
| 494 | + 'meta' => [ |
|
| 495 | + 'title' => esc_html__('Pending Payment', 'event_espresso'), |
|
| 496 | + 'target' => '', |
|
| 497 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 498 | + ], |
|
| 499 | + ] |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * @return void |
|
| 507 | + */ |
|
| 508 | + private function addRegistrationOverviewTodayNotApproved() |
|
| 509 | + { |
|
| 510 | + if ( |
|
| 511 | + $this->capabilities->current_user_can( |
|
| 512 | + 'ee_read_registrations', |
|
| 513 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' |
|
| 514 | + ) |
|
| 515 | + ) { |
|
| 516 | + $this->admin_bar->add_menu( |
|
| 517 | + [ |
|
| 518 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 519 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 520 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 521 | + . esc_html__('Not Approved', 'event_espresso'), |
|
| 522 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 523 | + [ |
|
| 524 | + 'action' => 'default', |
|
| 525 | + 'status' => 'today', |
|
| 526 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 527 | + ], |
|
| 528 | + $this->reg_admin_url |
|
| 529 | + ), |
|
| 530 | + 'meta' => [ |
|
| 531 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 532 | + 'target' => '', |
|
| 533 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 534 | + ], |
|
| 535 | + ] |
|
| 536 | + ); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + private function addRegistrationOverviewTodayCancelled() |
|
| 545 | + { |
|
| 546 | + if ( |
|
| 547 | + $this->capabilities->current_user_can( |
|
| 548 | + 'ee_read_registrations', |
|
| 549 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' |
|
| 550 | + ) |
|
| 551 | + ) { |
|
| 552 | + $this->admin_bar->add_menu( |
|
| 553 | + [ |
|
| 554 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 555 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 556 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 557 | + . esc_html__('Cancelled', 'event_espresso'), |
|
| 558 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 559 | + [ |
|
| 560 | + 'action' => 'default', |
|
| 561 | + 'status' => 'today', |
|
| 562 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 563 | + ], |
|
| 564 | + $this->reg_admin_url |
|
| 565 | + ), |
|
| 566 | + 'meta' => [ |
|
| 567 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 568 | + 'target' => '', |
|
| 569 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 570 | + ], |
|
| 571 | + ] |
|
| 572 | + ); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @return void |
|
| 579 | + */ |
|
| 580 | + private function addRegistrationOverviewThisMonth() |
|
| 581 | + { |
|
| 582 | + if ( |
|
| 583 | + $this->capabilities->current_user_can( |
|
| 584 | + 'ee_read_registrations', |
|
| 585 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month' |
|
| 586 | + ) |
|
| 587 | + ) { |
|
| 588 | + $this->admin_bar->add_menu( |
|
| 589 | + [ |
|
| 590 | + 'id' => 'espresso-toolbar-registrations-month', |
|
| 591 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 592 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 593 | + 'href' => '', // EEH_URL::add_query_args_and_nonce( |
|
| 594 | + // array( |
|
| 595 | + // 'action' => 'default', |
|
| 596 | + // 'status' => 'month' |
|
| 597 | + // ), |
|
| 598 | + // $this->reg_admin_url |
|
| 599 | + // ), |
|
| 600 | + 'meta' => [ |
|
| 601 | + 'title' => esc_html__('This Month', 'event_espresso'), |
|
| 602 | + 'target' => '', |
|
| 603 | + 'class' => $this->menu_class, |
|
| 604 | + ], |
|
| 605 | + ] |
|
| 606 | + ); |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * @return void |
|
| 613 | + */ |
|
| 614 | + private function addRegistrationOverviewThisMonthApproved() |
|
| 615 | + { |
|
| 616 | + if ( |
|
| 617 | + $this->capabilities->current_user_can( |
|
| 618 | + 'ee_read_registrations', |
|
| 619 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' |
|
| 620 | + ) |
|
| 621 | + ) { |
|
| 622 | + $this->admin_bar->add_menu( |
|
| 623 | + [ |
|
| 624 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 625 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 626 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 627 | + . esc_html__('Approved', 'event_espresso'), |
|
| 628 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 629 | + [ |
|
| 630 | + 'action' => 'default', |
|
| 631 | + 'status' => 'month', |
|
| 632 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 633 | + ], |
|
| 634 | + $this->reg_admin_url |
|
| 635 | + ), |
|
| 636 | + 'meta' => [ |
|
| 637 | + 'title' => esc_html__('Approved', 'event_espresso'), |
|
| 638 | + 'target' => '', |
|
| 639 | + 'class' => $this->menu_class . ' ee-toolbar-icon-approved', |
|
| 640 | + ], |
|
| 641 | + ] |
|
| 642 | + ); |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * @return void |
|
| 649 | + */ |
|
| 650 | + private function addRegistrationOverviewThisMonthPending() |
|
| 651 | + { |
|
| 652 | + if ( |
|
| 653 | + $this->capabilities->current_user_can( |
|
| 654 | + 'ee_read_registrations', |
|
| 655 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' |
|
| 656 | + ) |
|
| 657 | + ) { |
|
| 658 | + $this->admin_bar->add_menu( |
|
| 659 | + [ |
|
| 660 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 661 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 662 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 663 | + . esc_html__('Pending', 'event_espresso'), |
|
| 664 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 665 | + [ |
|
| 666 | + 'action' => 'default', |
|
| 667 | + 'status' => 'month', |
|
| 668 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 669 | + ], |
|
| 670 | + $this->reg_admin_url |
|
| 671 | + ), |
|
| 672 | + 'meta' => [ |
|
| 673 | + 'title' => esc_html__('Pending', 'event_espresso'), |
|
| 674 | + 'target' => '', |
|
| 675 | + 'class' => $this->menu_class . ' ee-toolbar-icon-pending', |
|
| 676 | + ], |
|
| 677 | + ] |
|
| 678 | + ); |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * @return void |
|
| 685 | + */ |
|
| 686 | + private function addRegistrationOverviewThisMonthNotApproved() |
|
| 687 | + { |
|
| 688 | + if ( |
|
| 689 | + $this->capabilities->current_user_can( |
|
| 690 | + 'ee_read_registrations', |
|
| 691 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' |
|
| 692 | + ) |
|
| 693 | + ) { |
|
| 694 | + $this->admin_bar->add_menu( |
|
| 695 | + [ |
|
| 696 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 697 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 698 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 699 | + . esc_html__('Not Approved', 'event_espresso'), |
|
| 700 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 701 | + [ |
|
| 702 | + 'action' => 'default', |
|
| 703 | + 'status' => 'month', |
|
| 704 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 705 | + ], |
|
| 706 | + $this->reg_admin_url |
|
| 707 | + ), |
|
| 708 | + 'meta' => [ |
|
| 709 | + 'title' => esc_html__('Not Approved', 'event_espresso'), |
|
| 710 | + 'target' => '', |
|
| 711 | + 'class' => $this->menu_class . ' ee-toolbar-icon-not-approved', |
|
| 712 | + ], |
|
| 713 | + ] |
|
| 714 | + ); |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * @return void |
|
| 721 | + */ |
|
| 722 | + private function addRegistrationOverviewThisMonthCancelled() |
|
| 723 | + { |
|
| 724 | + if ( |
|
| 725 | + $this->capabilities->current_user_can( |
|
| 726 | + 'ee_read_registrations', |
|
| 727 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' |
|
| 728 | + ) |
|
| 729 | + ) { |
|
| 730 | + $this->admin_bar->add_menu( |
|
| 731 | + [ |
|
| 732 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 733 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 734 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 735 | + . esc_html__('Cancelled', 'event_espresso'), |
|
| 736 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 737 | + [ |
|
| 738 | + 'action' => 'default', |
|
| 739 | + 'status' => 'month', |
|
| 740 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 741 | + ], |
|
| 742 | + $this->reg_admin_url |
|
| 743 | + ), |
|
| 744 | + 'meta' => [ |
|
| 745 | + 'title' => esc_html__('Cancelled', 'event_espresso'), |
|
| 746 | + 'target' => '', |
|
| 747 | + 'class' => $this->menu_class . ' ee-toolbar-icon-cancelled', |
|
| 748 | + ], |
|
| 749 | + ] |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * @return void |
|
| 757 | + */ |
|
| 758 | + private function addExtensionsAndServices() |
|
| 759 | + { |
|
| 760 | + if ( |
|
| 761 | + $this->capabilities->current_user_can( |
|
| 762 | + 'ee_read_ee', |
|
| 763 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' |
|
| 764 | + ) |
|
| 765 | + ) { |
|
| 766 | + $this->admin_bar->add_menu( |
|
| 767 | + [ |
|
| 768 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 769 | + 'parent' => 'espresso-toolbar', |
|
| 770 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 771 | + . esc_html__('Extensions & Services', 'event_espresso'), |
|
| 772 | + 'href' => admin_url('admin.php?page=espresso_packages'), |
|
| 773 | + 'meta' => [ |
|
| 774 | + 'title' => esc_html__('Extensions & Services', 'event_espresso'), |
|
| 775 | + 'target' => '', |
|
| 776 | + 'class' => $this->menu_class, |
|
| 777 | + ], |
|
| 778 | + ] |
|
| 779 | + ); |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + |
|
| 784 | + /** |
|
| 785 | + * @return void |
|
| 786 | + */ |
|
| 787 | + private function addFontSizeSubMenu() |
|
| 788 | + { |
|
| 789 | + if (! is_admin()) { |
|
| 790 | + return; |
|
| 791 | + } |
|
| 792 | + $this->admin_bar->add_menu( |
|
| 793 | + [ |
|
| 794 | + 'id' => 'espresso-toolbar-font-size', |
|
| 795 | + 'parent' => 'espresso-toolbar', |
|
| 796 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 797 | + . esc_html__('Set Font Size', 'event_espresso'), |
|
| 798 | + 'href' => '', |
|
| 799 | + 'meta' => [ |
|
| 800 | + 'title' => esc_html__('Set Font Size', 'event_espresso'), |
|
| 801 | + 'target' => '', |
|
| 802 | + 'class' => $this->menu_class, |
|
| 803 | + ], |
|
| 804 | + ] |
|
| 805 | + ); |
|
| 806 | + |
|
| 807 | + $settings_admin_url = admin_url('admin.php?page=espresso_general_settings'); |
|
| 808 | + |
|
| 809 | + $font_sizes = [ |
|
| 810 | + 'tiny' => AdminFontSize::FONT_SIZE_TINY, |
|
| 811 | + 'smaller' => AdminFontSize::FONT_SIZE_SMALLER, |
|
| 812 | + 'small' => AdminFontSize::FONT_SIZE_SMALL, |
|
| 813 | + 'default' => AdminFontSize::FONT_SIZE_DEFAULT, |
|
| 814 | + 'big' => AdminFontSize::FONT_SIZE_BIG, |
|
| 815 | + 'bigger' => AdminFontSize::FONT_SIZE_BIGGER, |
|
| 816 | + ]; |
|
| 817 | + |
|
| 818 | + foreach ($font_sizes as $font_size => $value) { |
|
| 819 | + $this->admin_bar->add_menu( |
|
| 820 | + [ |
|
| 821 | + 'id' => "espresso-toolbar-set-font-size-$font_size", |
|
| 822 | + 'parent' => 'espresso-toolbar-font-size', |
|
| 823 | + 'title' => '<span class="ee-toolbar-icon"></span>' |
|
| 824 | + . sprintf( |
|
| 825 | + /* translators: Font Size Small */ |
|
| 826 | + esc_html__('Font Size %1$s', 'event_espresso'), |
|
| 827 | + ucwords($font_size) |
|
| 828 | + ), |
|
| 829 | + 'href' => EEH_URL::add_query_args_and_nonce( |
|
| 830 | + ['action' => 'set_font_size', 'font_size' => $value], |
|
| 831 | + $settings_admin_url |
|
| 832 | + ), |
|
| 833 | + 'meta' => [ |
|
| 834 | + 'title' => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'), |
|
| 835 | + 'target' => '', |
|
| 836 | + 'class' => $this->menu_class, |
|
| 837 | + ], |
|
| 838 | + ] |
|
| 839 | + ); |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | 842 | } |
@@ -22,407 +22,407 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class QueryBuilder |
| 24 | 24 | { |
| 25 | - protected RequestInterface $request; |
|
| 26 | - |
|
| 27 | - protected EEM_Registration $registration_model; |
|
| 28 | - |
|
| 29 | - protected array $filters; |
|
| 30 | - |
|
| 31 | - protected string $view; |
|
| 32 | - |
|
| 33 | - protected array $where_params; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * QueryBuilder constructor. |
|
| 38 | - * |
|
| 39 | - * @param RequestInterface $request |
|
| 40 | - * @param EEM_Registration $registration_model |
|
| 41 | - * @param array $extra_request_params |
|
| 42 | - */ |
|
| 43 | - public function __construct( |
|
| 44 | - RequestInterface $request, |
|
| 45 | - EEM_Registration $registration_model, |
|
| 46 | - array $extra_request_params = [] |
|
| 47 | - ) { |
|
| 48 | - $this->request = $request; |
|
| 49 | - $this->filters = $this->request->getRequestParam('filters', [], DataType::STRING, true); |
|
| 50 | - $this->registration_model = $registration_model; |
|
| 51 | - foreach ($extra_request_params as $key => $value) { |
|
| 52 | - if (! $this->request->requestParamIsSet($key)) { |
|
| 53 | - $this->request->setRequestParam($key, $value); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - $this->view = $this->request->getRequestParam('status', ''); |
|
| 57 | - $this->where_params = []; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Sets up the where conditions for the registrations query. |
|
| 63 | - * |
|
| 64 | - * @param int $per_page |
|
| 65 | - * @param bool $count_query |
|
| 66 | - * @return array |
|
| 67 | - * @throws EE_Error |
|
| 68 | - * @throws InvalidArgumentException |
|
| 69 | - * @throws InvalidDataTypeException |
|
| 70 | - * @throws InvalidInterfaceException |
|
| 71 | - */ |
|
| 72 | - public function getQueryParams(int $per_page = 10, bool $count_query = false): array |
|
| 73 | - { |
|
| 74 | - $query_params = [ |
|
| 75 | - 0 => $this->getWhereClause(), |
|
| 76 | - 'caps' => EEM_Base::caps_read_admin, |
|
| 77 | - 'default_where_conditions' => 'this_model_only', |
|
| 78 | - ]; |
|
| 79 | - if (! $count_query) { |
|
| 80 | - $query_params = array_merge( |
|
| 81 | - $query_params, |
|
| 82 | - $this->getOrderbyClause(), |
|
| 83 | - $this->getLimitClause($per_page) |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return $query_params; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Sets up the where conditions for the registrations query. |
|
| 93 | - * |
|
| 94 | - * @return array |
|
| 95 | - * @throws EE_Error |
|
| 96 | - * @throws InvalidArgumentException |
|
| 97 | - * @throws InvalidDataTypeException |
|
| 98 | - * @throws InvalidInterfaceException |
|
| 99 | - */ |
|
| 100 | - protected function getWhereClause(): array |
|
| 101 | - { |
|
| 102 | - $this->addAttendeeIdToWhereConditions(); |
|
| 103 | - $this->addEventIdToWhereConditions(); |
|
| 104 | - $this->addCategoryIdToWhereConditions(); |
|
| 105 | - $this->addDatetimeIdToWhereConditions(); |
|
| 106 | - $this->addTicketIdToWhereConditions(); |
|
| 107 | - $this->addRegistrationStatusToWhereConditions(); |
|
| 108 | - $this->addDateToWhereConditions(); |
|
| 109 | - $this->addSearchToWhereConditions(); |
|
| 110 | - return apply_filters( |
|
| 111 | - 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 112 | - $this->where_params, |
|
| 113 | - $this->request->requestParams() |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters. |
|
| 120 | - */ |
|
| 121 | - protected function addAttendeeIdToWhereConditions() |
|
| 122 | - { |
|
| 123 | - $ATT_ID = $this->request->getRequestParam('attendee_id'); |
|
| 124 | - $ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int'); |
|
| 125 | - if ($ATT_ID) { |
|
| 126 | - $this->where_params['ATT_ID'] = $ATT_ID; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters. |
|
| 133 | - */ |
|
| 134 | - protected function addEventIdToWhereConditions() |
|
| 135 | - { |
|
| 136 | - $EVT_ID = $this->request->getRequestParam('event_id'); |
|
| 137 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int'); |
|
| 138 | - if ($EVT_ID) { |
|
| 139 | - $this->where_params['EVT_ID'] = $EVT_ID; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 146 | - */ |
|
| 147 | - protected function addCategoryIdToWhereConditions() |
|
| 148 | - { |
|
| 149 | - $EVT_CAT = $this->request->getRequestParam('EVT_CAT', 0, DataType::INTEGER); |
|
| 150 | - $EVT_CAT = $this->filters['EVT_CAT'] ?? $EVT_CAT; |
|
| 151 | - $EVT_CAT = (int) $EVT_CAT; |
|
| 152 | - if ($EVT_CAT > 0) { |
|
| 153 | - $this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 160 | - */ |
|
| 161 | - protected function addDatetimeIdToWhereConditions() |
|
| 162 | - { |
|
| 163 | - // first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value |
|
| 164 | - $DTT_ID = $this->request->getRequestParam('datetime_id'); |
|
| 165 | - $DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, DataType::INTEGER); |
|
| 166 | - $DTT_ID = $this->filters['datetime_id'] ?? $DTT_ID; |
|
| 167 | - $DTT_ID = (int) $DTT_ID; |
|
| 168 | - |
|
| 169 | - if ($DTT_ID) { |
|
| 170 | - $this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Adds the ticket ID if it exists in the request to the where conditions for the registrations query. |
|
| 177 | - */ |
|
| 178 | - protected function addTicketIdToWhereConditions() |
|
| 179 | - { |
|
| 180 | - // first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value |
|
| 181 | - $TKT_ID = $this->request->getRequestParam('ticket_id'); |
|
| 182 | - $TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, DataType::INTEGER); |
|
| 183 | - $TKT_ID = $this->filters['ticket_id'] ?? $TKT_ID; |
|
| 184 | - $TKT_ID = (int) $TKT_ID; |
|
| 185 | - |
|
| 186 | - if ($TKT_ID) { |
|
| 187 | - $this->where_params['TKT_ID'] = $TKT_ID; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
| 194 | - * If filtering by registration status, then we show registrations matching that status. |
|
| 195 | - * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
|
| 196 | - * UNLESS viewing trashed registrations. |
|
| 197 | - */ |
|
| 198 | - protected function addRegistrationStatusToWhereConditions() |
|
| 199 | - { |
|
| 200 | - $registration_status = $this->request->getRequestParam('_reg_status'); |
|
| 201 | - $registration_status = $this->filters['_reg_status'] ?? $registration_status; |
|
| 202 | - if ($registration_status) { |
|
| 203 | - $this->where_params['STS_ID'] = sanitize_text_field($registration_status); |
|
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - // make sure we exclude incomplete registrations, but only if not trashed. |
|
| 207 | - if ($this->view === 'trash') { |
|
| 208 | - $this->where_params['REG_deleted'] = true; |
|
| 209 | - return; |
|
| 210 | - } |
|
| 211 | - $this->where_params['STS_ID'] = $this->view === 'incomplete' |
|
| 212 | - ? EEM_Registration::status_id_incomplete |
|
| 213 | - : ['!=', EEM_Registration::status_id_incomplete]; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 219 | - * |
|
| 220 | - * @throws EE_Error |
|
| 221 | - * @throws InvalidArgumentException |
|
| 222 | - * @throws InvalidDataTypeException |
|
| 223 | - * @throws InvalidInterfaceException |
|
| 224 | - */ |
|
| 225 | - protected function addDateToWhereConditions() |
|
| 226 | - { |
|
| 227 | - $current_time = current_time('timestamp'); |
|
| 228 | - if ($this->view === 'today') { |
|
| 229 | - $now = date('Y-m-d', $current_time); |
|
| 230 | - $this->where_params['REG_date'] = [ |
|
| 231 | - 'BETWEEN', |
|
| 232 | - [ |
|
| 233 | - $this->registration_model->convert_datetime_for_query( |
|
| 234 | - 'REG_date', |
|
| 235 | - $now . ' 00:00:00', |
|
| 236 | - 'Y-m-d H:i:s' |
|
| 237 | - ), |
|
| 238 | - $this->registration_model->convert_datetime_for_query( |
|
| 239 | - 'REG_date', |
|
| 240 | - $now . ' 23:59:59', |
|
| 241 | - 'Y-m-d H:i:s' |
|
| 242 | - ), |
|
| 243 | - ], |
|
| 244 | - ]; |
|
| 245 | - return; |
|
| 246 | - } |
|
| 247 | - if ($this->view === 'yesterday') { |
|
| 248 | - $yesterday = date('Y-m-d', $current_time - DAY_IN_SECONDS); |
|
| 249 | - $this->where_params['REG_date'] = [ |
|
| 250 | - 'BETWEEN', |
|
| 251 | - [ |
|
| 252 | - $this->registration_model->convert_datetime_for_query( |
|
| 253 | - 'REG_date', |
|
| 254 | - $yesterday . ' 00:00:00', |
|
| 255 | - 'Y-m-d H:i:s' |
|
| 256 | - ), |
|
| 257 | - $this->registration_model->convert_datetime_for_query( |
|
| 258 | - 'REG_date', |
|
| 259 | - $yesterday . ' 23:59:59', |
|
| 260 | - 'Y-m-d H:i:s' |
|
| 261 | - ), |
|
| 262 | - ], |
|
| 263 | - ]; |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - if ($this->view === 'month') { |
|
| 267 | - $current_year_and_month = date('Y-m', $current_time); |
|
| 268 | - $days_this_month = date('t', $current_time); |
|
| 269 | - $this->where_params['REG_date'] = [ |
|
| 270 | - 'BETWEEN', |
|
| 271 | - [ |
|
| 272 | - $this->registration_model->convert_datetime_for_query( |
|
| 273 | - 'REG_date', |
|
| 274 | - $current_year_and_month . '-01 00:00:00', |
|
| 275 | - 'Y-m-d H:i:s' |
|
| 276 | - ), |
|
| 277 | - $this->registration_model->convert_datetime_for_query( |
|
| 278 | - 'REG_date', |
|
| 279 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 280 | - 'Y-m-d H:i:s' |
|
| 281 | - ), |
|
| 282 | - ], |
|
| 283 | - ]; |
|
| 284 | - return; |
|
| 285 | - } |
|
| 286 | - $month_range = $this->request->getRequestParam('month_range'); |
|
| 287 | - $month_range = $this->filters['month_range'] ?? $month_range; |
|
| 288 | - if ($month_range) { |
|
| 289 | - $month_range = sanitize_text_field($month_range); |
|
| 290 | - $pieces = explode(' ', $month_range, 3); |
|
| 291 | - $month_requested = ! empty($pieces[0]) |
|
| 292 | - ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 293 | - : ''; |
|
| 294 | - $year_requested = ! empty($pieces[1]) |
|
| 295 | - ? $pieces[1] |
|
| 296 | - : ''; |
|
| 297 | - // if there is not a month or year then we can't go further |
|
| 298 | - if ($month_requested && $year_requested) { |
|
| 299 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 300 | - $this->where_params['REG_date'] = [ |
|
| 301 | - 'BETWEEN', |
|
| 302 | - [ |
|
| 303 | - $this->registration_model->convert_datetime_for_query( |
|
| 304 | - 'REG_date', |
|
| 305 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 306 | - 'Y-m-d H:i:s' |
|
| 307 | - ), |
|
| 308 | - $this->registration_model->convert_datetime_for_query( |
|
| 309 | - 'REG_date', |
|
| 310 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 311 | - 'Y-m-d H:i:s' |
|
| 312 | - ), |
|
| 313 | - ], |
|
| 314 | - ]; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
| 322 | - */ |
|
| 323 | - protected function addSearchToWhereConditions() |
|
| 324 | - { |
|
| 325 | - $search = $this->request->getRequestParam('s'); |
|
| 326 | - if ($search) { |
|
| 327 | - $search_string = '%' . sanitize_text_field($search) . '%'; |
|
| 328 | - $this->where_params['OR*search_conditions'] = [ |
|
| 329 | - 'Event.EVT_name' => ['LIKE', $search_string], |
|
| 330 | - 'Event.EVT_desc' => ['LIKE', $search_string], |
|
| 331 | - 'Event.EVT_short_desc' => ['LIKE', $search_string], |
|
| 332 | - 'Attendee.ATT_full_name' => ['LIKE', $search_string], |
|
| 333 | - 'Attendee.ATT_fname' => ['LIKE', $search_string], |
|
| 334 | - 'Attendee.ATT_lname' => ['LIKE', $search_string], |
|
| 335 | - 'Attendee.ATT_short_bio' => ['LIKE', $search_string], |
|
| 336 | - 'Attendee.ATT_email' => ['LIKE', $search_string], |
|
| 337 | - 'Attendee.ATT_address' => ['LIKE', $search_string], |
|
| 338 | - 'Attendee.ATT_address2' => ['LIKE', $search_string], |
|
| 339 | - 'Attendee.ATT_city' => ['LIKE', $search_string], |
|
| 340 | - 'REG_final_price' => ['LIKE', $search_string], |
|
| 341 | - 'REG_code' => ['LIKE', $search_string], |
|
| 342 | - 'REG_count' => ['LIKE', $search_string], |
|
| 343 | - 'REG_group_size' => ['LIKE', $search_string], |
|
| 344 | - 'Ticket.TKT_name' => ['LIKE', $search_string], |
|
| 345 | - 'Ticket.TKT_description' => ['LIKE', $search_string], |
|
| 346 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string], |
|
| 347 | - ]; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Sets up the orderby for the registrations query. |
|
| 354 | - * |
|
| 355 | - * @return array |
|
| 356 | - */ |
|
| 357 | - protected function getOrderbyClause(): array |
|
| 358 | - { |
|
| 359 | - $orderby_field = $this->request->getRequestParam('orderby'); |
|
| 360 | - $orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date'; |
|
| 361 | - switch ($orderby_field) { |
|
| 362 | - case '_REG_ID': |
|
| 363 | - $orderby = ['REG_ID']; |
|
| 364 | - break; |
|
| 365 | - case '_Reg_status': |
|
| 366 | - $orderby = ['STS_ID']; |
|
| 367 | - break; |
|
| 368 | - case 'ATT_fname': |
|
| 369 | - $orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname']; |
|
| 370 | - break; |
|
| 371 | - case 'ATT_lname': |
|
| 372 | - $orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname']; |
|
| 373 | - break; |
|
| 374 | - case 'event_name': |
|
| 375 | - $orderby = ['Event.EVT_name']; |
|
| 376 | - break; |
|
| 377 | - case 'DTT_EVT_start': |
|
| 378 | - $orderby = ['Event.Datetime.DTT_EVT_start']; |
|
| 379 | - break; |
|
| 380 | - case '_REG_date': |
|
| 381 | - $orderby = ['REG_date']; |
|
| 382 | - break; |
|
| 383 | - default: |
|
| 384 | - $orderby = [$orderby_field]; |
|
| 385 | - break; |
|
| 386 | - } |
|
| 387 | - $order = $this->request->getRequestParam('order'); |
|
| 388 | - $order = $order ? sanitize_text_field($order) : 'DESC'; |
|
| 389 | - |
|
| 390 | - $orderby = array_combine( |
|
| 391 | - $orderby, |
|
| 392 | - array_fill(0, count($orderby), $order) |
|
| 393 | - ); |
|
| 394 | - // always add REG_count to the orderby array |
|
| 395 | - $orderby['REG_count'] = 'ASC'; |
|
| 396 | - // because there are many registrations with the same date, define |
|
| 397 | - // a secondary way to order them, otherwise MySQL seems to be a bit random |
|
| 398 | - if (empty($orderby['REG_ID'])) { |
|
| 399 | - $orderby['REG_ID'] = $order; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - $orderby = apply_filters( |
|
| 403 | - 'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query', |
|
| 404 | - $orderby, |
|
| 405 | - $this->request->requestParams() |
|
| 406 | - ); |
|
| 407 | - return ['order_by' => $orderby]; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Sets up the limit for the registrations query. |
|
| 413 | - * |
|
| 414 | - * @param int $per_page |
|
| 415 | - * @return array |
|
| 416 | - */ |
|
| 417 | - protected function getLimitClause(int $per_page): array |
|
| 418 | - { |
|
| 419 | - $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
| 420 | - $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
| 421 | - // -1 means return all results so get out if that's set. |
|
| 422 | - if ($per_page === -1) { |
|
| 423 | - return []; |
|
| 424 | - } |
|
| 425 | - $offset = ($current_page - 1) * $per_page; |
|
| 426 | - return ['limit' => [$offset, $per_page]]; |
|
| 427 | - } |
|
| 25 | + protected RequestInterface $request; |
|
| 26 | + |
|
| 27 | + protected EEM_Registration $registration_model; |
|
| 28 | + |
|
| 29 | + protected array $filters; |
|
| 30 | + |
|
| 31 | + protected string $view; |
|
| 32 | + |
|
| 33 | + protected array $where_params; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * QueryBuilder constructor. |
|
| 38 | + * |
|
| 39 | + * @param RequestInterface $request |
|
| 40 | + * @param EEM_Registration $registration_model |
|
| 41 | + * @param array $extra_request_params |
|
| 42 | + */ |
|
| 43 | + public function __construct( |
|
| 44 | + RequestInterface $request, |
|
| 45 | + EEM_Registration $registration_model, |
|
| 46 | + array $extra_request_params = [] |
|
| 47 | + ) { |
|
| 48 | + $this->request = $request; |
|
| 49 | + $this->filters = $this->request->getRequestParam('filters', [], DataType::STRING, true); |
|
| 50 | + $this->registration_model = $registration_model; |
|
| 51 | + foreach ($extra_request_params as $key => $value) { |
|
| 52 | + if (! $this->request->requestParamIsSet($key)) { |
|
| 53 | + $this->request->setRequestParam($key, $value); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + $this->view = $this->request->getRequestParam('status', ''); |
|
| 57 | + $this->where_params = []; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Sets up the where conditions for the registrations query. |
|
| 63 | + * |
|
| 64 | + * @param int $per_page |
|
| 65 | + * @param bool $count_query |
|
| 66 | + * @return array |
|
| 67 | + * @throws EE_Error |
|
| 68 | + * @throws InvalidArgumentException |
|
| 69 | + * @throws InvalidDataTypeException |
|
| 70 | + * @throws InvalidInterfaceException |
|
| 71 | + */ |
|
| 72 | + public function getQueryParams(int $per_page = 10, bool $count_query = false): array |
|
| 73 | + { |
|
| 74 | + $query_params = [ |
|
| 75 | + 0 => $this->getWhereClause(), |
|
| 76 | + 'caps' => EEM_Base::caps_read_admin, |
|
| 77 | + 'default_where_conditions' => 'this_model_only', |
|
| 78 | + ]; |
|
| 79 | + if (! $count_query) { |
|
| 80 | + $query_params = array_merge( |
|
| 81 | + $query_params, |
|
| 82 | + $this->getOrderbyClause(), |
|
| 83 | + $this->getLimitClause($per_page) |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return $query_params; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Sets up the where conditions for the registrations query. |
|
| 93 | + * |
|
| 94 | + * @return array |
|
| 95 | + * @throws EE_Error |
|
| 96 | + * @throws InvalidArgumentException |
|
| 97 | + * @throws InvalidDataTypeException |
|
| 98 | + * @throws InvalidInterfaceException |
|
| 99 | + */ |
|
| 100 | + protected function getWhereClause(): array |
|
| 101 | + { |
|
| 102 | + $this->addAttendeeIdToWhereConditions(); |
|
| 103 | + $this->addEventIdToWhereConditions(); |
|
| 104 | + $this->addCategoryIdToWhereConditions(); |
|
| 105 | + $this->addDatetimeIdToWhereConditions(); |
|
| 106 | + $this->addTicketIdToWhereConditions(); |
|
| 107 | + $this->addRegistrationStatusToWhereConditions(); |
|
| 108 | + $this->addDateToWhereConditions(); |
|
| 109 | + $this->addSearchToWhereConditions(); |
|
| 110 | + return apply_filters( |
|
| 111 | + 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 112 | + $this->where_params, |
|
| 113 | + $this->request->requestParams() |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters. |
|
| 120 | + */ |
|
| 121 | + protected function addAttendeeIdToWhereConditions() |
|
| 122 | + { |
|
| 123 | + $ATT_ID = $this->request->getRequestParam('attendee_id'); |
|
| 124 | + $ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int'); |
|
| 125 | + if ($ATT_ID) { |
|
| 126 | + $this->where_params['ATT_ID'] = $ATT_ID; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters. |
|
| 133 | + */ |
|
| 134 | + protected function addEventIdToWhereConditions() |
|
| 135 | + { |
|
| 136 | + $EVT_ID = $this->request->getRequestParam('event_id'); |
|
| 137 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int'); |
|
| 138 | + if ($EVT_ID) { |
|
| 139 | + $this->where_params['EVT_ID'] = $EVT_ID; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 146 | + */ |
|
| 147 | + protected function addCategoryIdToWhereConditions() |
|
| 148 | + { |
|
| 149 | + $EVT_CAT = $this->request->getRequestParam('EVT_CAT', 0, DataType::INTEGER); |
|
| 150 | + $EVT_CAT = $this->filters['EVT_CAT'] ?? $EVT_CAT; |
|
| 151 | + $EVT_CAT = (int) $EVT_CAT; |
|
| 152 | + if ($EVT_CAT > 0) { |
|
| 153 | + $this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 160 | + */ |
|
| 161 | + protected function addDatetimeIdToWhereConditions() |
|
| 162 | + { |
|
| 163 | + // first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value |
|
| 164 | + $DTT_ID = $this->request->getRequestParam('datetime_id'); |
|
| 165 | + $DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, DataType::INTEGER); |
|
| 166 | + $DTT_ID = $this->filters['datetime_id'] ?? $DTT_ID; |
|
| 167 | + $DTT_ID = (int) $DTT_ID; |
|
| 168 | + |
|
| 169 | + if ($DTT_ID) { |
|
| 170 | + $this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Adds the ticket ID if it exists in the request to the where conditions for the registrations query. |
|
| 177 | + */ |
|
| 178 | + protected function addTicketIdToWhereConditions() |
|
| 179 | + { |
|
| 180 | + // first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value |
|
| 181 | + $TKT_ID = $this->request->getRequestParam('ticket_id'); |
|
| 182 | + $TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, DataType::INTEGER); |
|
| 183 | + $TKT_ID = $this->filters['ticket_id'] ?? $TKT_ID; |
|
| 184 | + $TKT_ID = (int) $TKT_ID; |
|
| 185 | + |
|
| 186 | + if ($TKT_ID) { |
|
| 187 | + $this->where_params['TKT_ID'] = $TKT_ID; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
| 194 | + * If filtering by registration status, then we show registrations matching that status. |
|
| 195 | + * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
|
| 196 | + * UNLESS viewing trashed registrations. |
|
| 197 | + */ |
|
| 198 | + protected function addRegistrationStatusToWhereConditions() |
|
| 199 | + { |
|
| 200 | + $registration_status = $this->request->getRequestParam('_reg_status'); |
|
| 201 | + $registration_status = $this->filters['_reg_status'] ?? $registration_status; |
|
| 202 | + if ($registration_status) { |
|
| 203 | + $this->where_params['STS_ID'] = sanitize_text_field($registration_status); |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + // make sure we exclude incomplete registrations, but only if not trashed. |
|
| 207 | + if ($this->view === 'trash') { |
|
| 208 | + $this->where_params['REG_deleted'] = true; |
|
| 209 | + return; |
|
| 210 | + } |
|
| 211 | + $this->where_params['STS_ID'] = $this->view === 'incomplete' |
|
| 212 | + ? EEM_Registration::status_id_incomplete |
|
| 213 | + : ['!=', EEM_Registration::status_id_incomplete]; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 219 | + * |
|
| 220 | + * @throws EE_Error |
|
| 221 | + * @throws InvalidArgumentException |
|
| 222 | + * @throws InvalidDataTypeException |
|
| 223 | + * @throws InvalidInterfaceException |
|
| 224 | + */ |
|
| 225 | + protected function addDateToWhereConditions() |
|
| 226 | + { |
|
| 227 | + $current_time = current_time('timestamp'); |
|
| 228 | + if ($this->view === 'today') { |
|
| 229 | + $now = date('Y-m-d', $current_time); |
|
| 230 | + $this->where_params['REG_date'] = [ |
|
| 231 | + 'BETWEEN', |
|
| 232 | + [ |
|
| 233 | + $this->registration_model->convert_datetime_for_query( |
|
| 234 | + 'REG_date', |
|
| 235 | + $now . ' 00:00:00', |
|
| 236 | + 'Y-m-d H:i:s' |
|
| 237 | + ), |
|
| 238 | + $this->registration_model->convert_datetime_for_query( |
|
| 239 | + 'REG_date', |
|
| 240 | + $now . ' 23:59:59', |
|
| 241 | + 'Y-m-d H:i:s' |
|
| 242 | + ), |
|
| 243 | + ], |
|
| 244 | + ]; |
|
| 245 | + return; |
|
| 246 | + } |
|
| 247 | + if ($this->view === 'yesterday') { |
|
| 248 | + $yesterday = date('Y-m-d', $current_time - DAY_IN_SECONDS); |
|
| 249 | + $this->where_params['REG_date'] = [ |
|
| 250 | + 'BETWEEN', |
|
| 251 | + [ |
|
| 252 | + $this->registration_model->convert_datetime_for_query( |
|
| 253 | + 'REG_date', |
|
| 254 | + $yesterday . ' 00:00:00', |
|
| 255 | + 'Y-m-d H:i:s' |
|
| 256 | + ), |
|
| 257 | + $this->registration_model->convert_datetime_for_query( |
|
| 258 | + 'REG_date', |
|
| 259 | + $yesterday . ' 23:59:59', |
|
| 260 | + 'Y-m-d H:i:s' |
|
| 261 | + ), |
|
| 262 | + ], |
|
| 263 | + ]; |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + if ($this->view === 'month') { |
|
| 267 | + $current_year_and_month = date('Y-m', $current_time); |
|
| 268 | + $days_this_month = date('t', $current_time); |
|
| 269 | + $this->where_params['REG_date'] = [ |
|
| 270 | + 'BETWEEN', |
|
| 271 | + [ |
|
| 272 | + $this->registration_model->convert_datetime_for_query( |
|
| 273 | + 'REG_date', |
|
| 274 | + $current_year_and_month . '-01 00:00:00', |
|
| 275 | + 'Y-m-d H:i:s' |
|
| 276 | + ), |
|
| 277 | + $this->registration_model->convert_datetime_for_query( |
|
| 278 | + 'REG_date', |
|
| 279 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 280 | + 'Y-m-d H:i:s' |
|
| 281 | + ), |
|
| 282 | + ], |
|
| 283 | + ]; |
|
| 284 | + return; |
|
| 285 | + } |
|
| 286 | + $month_range = $this->request->getRequestParam('month_range'); |
|
| 287 | + $month_range = $this->filters['month_range'] ?? $month_range; |
|
| 288 | + if ($month_range) { |
|
| 289 | + $month_range = sanitize_text_field($month_range); |
|
| 290 | + $pieces = explode(' ', $month_range, 3); |
|
| 291 | + $month_requested = ! empty($pieces[0]) |
|
| 292 | + ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 293 | + : ''; |
|
| 294 | + $year_requested = ! empty($pieces[1]) |
|
| 295 | + ? $pieces[1] |
|
| 296 | + : ''; |
|
| 297 | + // if there is not a month or year then we can't go further |
|
| 298 | + if ($month_requested && $year_requested) { |
|
| 299 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 300 | + $this->where_params['REG_date'] = [ |
|
| 301 | + 'BETWEEN', |
|
| 302 | + [ |
|
| 303 | + $this->registration_model->convert_datetime_for_query( |
|
| 304 | + 'REG_date', |
|
| 305 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 306 | + 'Y-m-d H:i:s' |
|
| 307 | + ), |
|
| 308 | + $this->registration_model->convert_datetime_for_query( |
|
| 309 | + 'REG_date', |
|
| 310 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 311 | + 'Y-m-d H:i:s' |
|
| 312 | + ), |
|
| 313 | + ], |
|
| 314 | + ]; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
| 322 | + */ |
|
| 323 | + protected function addSearchToWhereConditions() |
|
| 324 | + { |
|
| 325 | + $search = $this->request->getRequestParam('s'); |
|
| 326 | + if ($search) { |
|
| 327 | + $search_string = '%' . sanitize_text_field($search) . '%'; |
|
| 328 | + $this->where_params['OR*search_conditions'] = [ |
|
| 329 | + 'Event.EVT_name' => ['LIKE', $search_string], |
|
| 330 | + 'Event.EVT_desc' => ['LIKE', $search_string], |
|
| 331 | + 'Event.EVT_short_desc' => ['LIKE', $search_string], |
|
| 332 | + 'Attendee.ATT_full_name' => ['LIKE', $search_string], |
|
| 333 | + 'Attendee.ATT_fname' => ['LIKE', $search_string], |
|
| 334 | + 'Attendee.ATT_lname' => ['LIKE', $search_string], |
|
| 335 | + 'Attendee.ATT_short_bio' => ['LIKE', $search_string], |
|
| 336 | + 'Attendee.ATT_email' => ['LIKE', $search_string], |
|
| 337 | + 'Attendee.ATT_address' => ['LIKE', $search_string], |
|
| 338 | + 'Attendee.ATT_address2' => ['LIKE', $search_string], |
|
| 339 | + 'Attendee.ATT_city' => ['LIKE', $search_string], |
|
| 340 | + 'REG_final_price' => ['LIKE', $search_string], |
|
| 341 | + 'REG_code' => ['LIKE', $search_string], |
|
| 342 | + 'REG_count' => ['LIKE', $search_string], |
|
| 343 | + 'REG_group_size' => ['LIKE', $search_string], |
|
| 344 | + 'Ticket.TKT_name' => ['LIKE', $search_string], |
|
| 345 | + 'Ticket.TKT_description' => ['LIKE', $search_string], |
|
| 346 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string], |
|
| 347 | + ]; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Sets up the orderby for the registrations query. |
|
| 354 | + * |
|
| 355 | + * @return array |
|
| 356 | + */ |
|
| 357 | + protected function getOrderbyClause(): array |
|
| 358 | + { |
|
| 359 | + $orderby_field = $this->request->getRequestParam('orderby'); |
|
| 360 | + $orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date'; |
|
| 361 | + switch ($orderby_field) { |
|
| 362 | + case '_REG_ID': |
|
| 363 | + $orderby = ['REG_ID']; |
|
| 364 | + break; |
|
| 365 | + case '_Reg_status': |
|
| 366 | + $orderby = ['STS_ID']; |
|
| 367 | + break; |
|
| 368 | + case 'ATT_fname': |
|
| 369 | + $orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname']; |
|
| 370 | + break; |
|
| 371 | + case 'ATT_lname': |
|
| 372 | + $orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname']; |
|
| 373 | + break; |
|
| 374 | + case 'event_name': |
|
| 375 | + $orderby = ['Event.EVT_name']; |
|
| 376 | + break; |
|
| 377 | + case 'DTT_EVT_start': |
|
| 378 | + $orderby = ['Event.Datetime.DTT_EVT_start']; |
|
| 379 | + break; |
|
| 380 | + case '_REG_date': |
|
| 381 | + $orderby = ['REG_date']; |
|
| 382 | + break; |
|
| 383 | + default: |
|
| 384 | + $orderby = [$orderby_field]; |
|
| 385 | + break; |
|
| 386 | + } |
|
| 387 | + $order = $this->request->getRequestParam('order'); |
|
| 388 | + $order = $order ? sanitize_text_field($order) : 'DESC'; |
|
| 389 | + |
|
| 390 | + $orderby = array_combine( |
|
| 391 | + $orderby, |
|
| 392 | + array_fill(0, count($orderby), $order) |
|
| 393 | + ); |
|
| 394 | + // always add REG_count to the orderby array |
|
| 395 | + $orderby['REG_count'] = 'ASC'; |
|
| 396 | + // because there are many registrations with the same date, define |
|
| 397 | + // a secondary way to order them, otherwise MySQL seems to be a bit random |
|
| 398 | + if (empty($orderby['REG_ID'])) { |
|
| 399 | + $orderby['REG_ID'] = $order; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + $orderby = apply_filters( |
|
| 403 | + 'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query', |
|
| 404 | + $orderby, |
|
| 405 | + $this->request->requestParams() |
|
| 406 | + ); |
|
| 407 | + return ['order_by' => $orderby]; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Sets up the limit for the registrations query. |
|
| 413 | + * |
|
| 414 | + * @param int $per_page |
|
| 415 | + * @return array |
|
| 416 | + */ |
|
| 417 | + protected function getLimitClause(int $per_page): array |
|
| 418 | + { |
|
| 419 | + $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
| 420 | + $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
| 421 | + // -1 means return all results so get out if that's set. |
|
| 422 | + if ($per_page === -1) { |
|
| 423 | + return []; |
|
| 424 | + } |
|
| 425 | + $offset = ($current_page - 1) * $per_page; |
|
| 426 | + return ['limit' => [$offset, $per_page]]; |
|
| 427 | + } |
|
| 428 | 428 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->filters = $this->request->getRequestParam('filters', [], DataType::STRING, true); |
| 50 | 50 | $this->registration_model = $registration_model; |
| 51 | 51 | foreach ($extra_request_params as $key => $value) { |
| 52 | - if (! $this->request->requestParamIsSet($key)) { |
|
| 52 | + if ( ! $this->request->requestParamIsSet($key)) { |
|
| 53 | 53 | $this->request->setRequestParam($key, $value); |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | 'caps' => EEM_Base::caps_read_admin, |
| 77 | 77 | 'default_where_conditions' => 'this_model_only', |
| 78 | 78 | ]; |
| 79 | - if (! $count_query) { |
|
| 79 | + if ( ! $count_query) { |
|
| 80 | 80 | $query_params = array_merge( |
| 81 | 81 | $query_params, |
| 82 | 82 | $this->getOrderbyClause(), |
@@ -232,12 +232,12 @@ discard block |
||
| 232 | 232 | [ |
| 233 | 233 | $this->registration_model->convert_datetime_for_query( |
| 234 | 234 | 'REG_date', |
| 235 | - $now . ' 00:00:00', |
|
| 235 | + $now.' 00:00:00', |
|
| 236 | 236 | 'Y-m-d H:i:s' |
| 237 | 237 | ), |
| 238 | 238 | $this->registration_model->convert_datetime_for_query( |
| 239 | 239 | 'REG_date', |
| 240 | - $now . ' 23:59:59', |
|
| 240 | + $now.' 23:59:59', |
|
| 241 | 241 | 'Y-m-d H:i:s' |
| 242 | 242 | ), |
| 243 | 243 | ], |
@@ -251,12 +251,12 @@ discard block |
||
| 251 | 251 | [ |
| 252 | 252 | $this->registration_model->convert_datetime_for_query( |
| 253 | 253 | 'REG_date', |
| 254 | - $yesterday . ' 00:00:00', |
|
| 254 | + $yesterday.' 00:00:00', |
|
| 255 | 255 | 'Y-m-d H:i:s' |
| 256 | 256 | ), |
| 257 | 257 | $this->registration_model->convert_datetime_for_query( |
| 258 | 258 | 'REG_date', |
| 259 | - $yesterday . ' 23:59:59', |
|
| 259 | + $yesterday.' 23:59:59', |
|
| 260 | 260 | 'Y-m-d H:i:s' |
| 261 | 261 | ), |
| 262 | 262 | ], |
@@ -271,12 +271,12 @@ discard block |
||
| 271 | 271 | [ |
| 272 | 272 | $this->registration_model->convert_datetime_for_query( |
| 273 | 273 | 'REG_date', |
| 274 | - $current_year_and_month . '-01 00:00:00', |
|
| 274 | + $current_year_and_month.'-01 00:00:00', |
|
| 275 | 275 | 'Y-m-d H:i:s' |
| 276 | 276 | ), |
| 277 | 277 | $this->registration_model->convert_datetime_for_query( |
| 278 | 278 | 'REG_date', |
| 279 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 279 | + $current_year_and_month.'-'.$days_this_month.' 23:59:59', |
|
| 280 | 280 | 'Y-m-d H:i:s' |
| 281 | 281 | ), |
| 282 | 282 | ], |
@@ -296,18 +296,18 @@ discard block |
||
| 296 | 296 | : ''; |
| 297 | 297 | // if there is not a month or year then we can't go further |
| 298 | 298 | if ($month_requested && $year_requested) { |
| 299 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 299 | + $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01')); |
|
| 300 | 300 | $this->where_params['REG_date'] = [ |
| 301 | 301 | 'BETWEEN', |
| 302 | 302 | [ |
| 303 | 303 | $this->registration_model->convert_datetime_for_query( |
| 304 | 304 | 'REG_date', |
| 305 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 305 | + $year_requested.'-'.$month_requested.'-01 00:00:00', |
|
| 306 | 306 | 'Y-m-d H:i:s' |
| 307 | 307 | ), |
| 308 | 308 | $this->registration_model->convert_datetime_for_query( |
| 309 | 309 | 'REG_date', |
| 310 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 310 | + $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59', |
|
| 311 | 311 | 'Y-m-d H:i:s' |
| 312 | 312 | ), |
| 313 | 313 | ], |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | { |
| 325 | 325 | $search = $this->request->getRequestParam('s'); |
| 326 | 326 | if ($search) { |
| 327 | - $search_string = '%' . sanitize_text_field($search) . '%'; |
|
| 327 | + $search_string = '%'.sanitize_text_field($search).'%'; |
|
| 328 | 328 | $this->where_params['OR*search_conditions'] = [ |
| 329 | 329 | 'Event.EVT_name' => ['LIKE', $search_string], |
| 330 | 330 | 'Event.EVT_desc' => ['LIKE', $search_string], |
@@ -15,419 +15,419 @@ |
||
| 15 | 15 | |
| 16 | 16 | class AdminMenuManager |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Default: null - defaults to below Comments |
|
| 20 | - * |
|
| 21 | - * 5 - below Posts |
|
| 22 | - * 10 - below Media |
|
| 23 | - * 15 - below Links |
|
| 24 | - * 20 - below Pages |
|
| 25 | - * 25 - below comments |
|
| 26 | - * 60 - below first separator |
|
| 27 | - * 65 - below Plugins |
|
| 28 | - * 70 - below Users |
|
| 29 | - * 75 - below Tools |
|
| 30 | - * 80 - below Settings |
|
| 31 | - * 100 - below second separator |
|
| 32 | - */ |
|
| 33 | - const DEFAULT_MENU_POSITION = 100; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var AdminMenuItem[] |
|
| 38 | - */ |
|
| 39 | - private $menu_items = []; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * objects for page_init objects detected and loaded |
|
| 43 | - * |
|
| 44 | - * @var EE_Admin_Page_Init[] |
|
| 45 | - */ |
|
| 46 | - private $installed_pages = []; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * set to TRUE if site is currently in maintenance mode level 2 |
|
| 50 | - * |
|
| 51 | - * @var bool |
|
| 52 | - */ |
|
| 53 | - protected bool $maintenance_mode = false; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * same values used by AdminMenuManager::DEFAULT_MENU_POSITION |
|
| 57 | - * |
|
| 58 | - * @var int |
|
| 59 | - */ |
|
| 60 | - private $menu_position; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var AdminMenuItem |
|
| 64 | - */ |
|
| 65 | - private $top_level_menu_item; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - public function __construct() |
|
| 69 | - { |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - public function initialize() |
|
| 74 | - { |
|
| 75 | - $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
| 76 | - $this->menu_position = apply_filters( |
|
| 77 | - 'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position', |
|
| 78 | - AdminMenuManager::DEFAULT_MENU_POSITION, |
|
| 79 | - $this->maintenance_mode |
|
| 80 | - ); |
|
| 81 | - $this->addTopLevelMenuItem(); |
|
| 82 | - $this->initializeMenuGroups(); |
|
| 83 | - add_action('admin_menu', [$this, 'generateAdminMenu']); |
|
| 84 | - add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']); |
|
| 85 | - add_filter('custom_menu_order', '__return_true'); |
|
| 86 | - add_filter('menu_order', [$this, 'reorderAdminMenu']); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * adds the top level menu item that everything else descends from. |
|
| 92 | - * changes depending on whether site is in full maintenance mode or not |
|
| 93 | - * |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - private function addTopLevelMenuItem() |
|
| 97 | - { |
|
| 98 | - $this->top_level_menu_item = $this->maintenance_mode |
|
| 99 | - ? $this->instantiateAdminMenu( |
|
| 100 | - [ |
|
| 101 | - 'menu_slug' => 'espresso_maintenance_settings', |
|
| 102 | - 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 103 | - 'capability' => 'manage_options', |
|
| 104 | - 'menu_group' => 'main', |
|
| 105 | - 'menu_order' => 10, |
|
| 106 | - 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
| 107 | - 'parent_slug' => 'espresso_maintenance_settings', |
|
| 108 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 109 | - ] |
|
| 110 | - ) |
|
| 111 | - : $this->instantiateAdminMenu( |
|
| 112 | - [ |
|
| 113 | - 'menu_slug' => 'espresso_events', |
|
| 114 | - 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 115 | - 'capability' => 'ee_read_events', |
|
| 116 | - 'menu_group' => 'main', |
|
| 117 | - 'menu_order' => 10, |
|
| 118 | - 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
| 119 | - 'parent_slug' => 'espresso_events', |
|
| 120 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 121 | - ] |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
| 128 | - * |
|
| 129 | - * @return void |
|
| 130 | - */ |
|
| 131 | - private function initializeMenuGroups() |
|
| 132 | - { |
|
| 133 | - $this->menu_items = apply_filters( |
|
| 134 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
| 135 | - [ |
|
| 136 | - 'main' => $this->instantiateAdminMenu( |
|
| 137 | - [ |
|
| 138 | - 'menu_slug' => 'main', |
|
| 139 | - 'menu_label' => esc_html__('Main', 'event_espresso'), |
|
| 140 | - 'capability' => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee', |
|
| 141 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 142 | - 'menu_order' => 0, |
|
| 143 | - 'parent_slug' => 'espresso_events', |
|
| 144 | - 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
| 145 | - ] |
|
| 146 | - ), |
|
| 147 | - 'management' => $this->instantiateAdminMenu( |
|
| 148 | - [ |
|
| 149 | - 'menu_slug' => 'management', |
|
| 150 | - 'menu_label' => esc_html__('Management', 'event_espresso'), |
|
| 151 | - 'capability' => 'ee_read_ee', |
|
| 152 | - 'menu_order' => 10, |
|
| 153 | - 'parent_slug' => 'espresso_events', |
|
| 154 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 155 | - ] |
|
| 156 | - ), |
|
| 157 | - 'addons' => $this->instantiateAdminMenu( |
|
| 158 | - [ |
|
| 159 | - 'menu_slug' => 'addons', |
|
| 160 | - 'menu_label' => esc_html__('Add-ons', 'event_espresso'), |
|
| 161 | - 'capability' => 'ee_read_ee', |
|
| 162 | - 'menu_order' => 20, |
|
| 163 | - 'parent_slug' => 'espresso_events', |
|
| 164 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
| 165 | - ] |
|
| 166 | - ), |
|
| 167 | - 'settings' => $this->instantiateAdminMenu( |
|
| 168 | - [ |
|
| 169 | - 'menu_slug' => 'settings', |
|
| 170 | - 'menu_label' => esc_html__('Settings', 'event_espresso'), |
|
| 171 | - 'capability' => 'ee_read_ee', |
|
| 172 | - 'menu_order' => 30, |
|
| 173 | - 'parent_slug' => 'espresso_events', |
|
| 174 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 175 | - ] |
|
| 176 | - ), |
|
| 177 | - 'templates' => $this->instantiateAdminMenu( |
|
| 178 | - [ |
|
| 179 | - 'menu_slug' => 'templates', |
|
| 180 | - 'menu_label' => esc_html__('Templates', 'event_espresso'), |
|
| 181 | - 'capability' => 'ee_read_ee', |
|
| 182 | - 'menu_order' => 40, |
|
| 183 | - 'parent_slug' => 'espresso_events', |
|
| 184 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 185 | - ] |
|
| 186 | - ), |
|
| 187 | - 'extras' => $this->instantiateAdminMenu( |
|
| 188 | - [ |
|
| 189 | - 'menu_slug' => 'extras', |
|
| 190 | - 'menu_label' => esc_html__('Extras', 'event_espresso'), |
|
| 191 | - 'capability' => 'ee_read_ee', |
|
| 192 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 193 | - 'menu_order' => 50, |
|
| 194 | - 'parent_slug' => 'espresso_events', |
|
| 195 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
| 196 | - ] |
|
| 197 | - ), |
|
| 198 | - 'tools' => $this->instantiateAdminMenu( |
|
| 199 | - [ |
|
| 200 | - 'menu_slug' => 'tools', |
|
| 201 | - 'menu_label' => esc_html__('Tools', 'event_espresso'), |
|
| 202 | - 'capability' => 'ee_read_ee', |
|
| 203 | - 'menu_order' => 60, |
|
| 204 | - 'parent_slug' => 'espresso_events', |
|
| 205 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 206 | - ] |
|
| 207 | - ), |
|
| 208 | - ] |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init |
|
| 215 | - * |
|
| 216 | - * @param EE_Admin_Page_Init $admin_page_init |
|
| 217 | - * @return AdminMenuItem |
|
| 218 | - */ |
|
| 219 | - public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem |
|
| 220 | - { |
|
| 221 | - // see if admin page init is using new classes |
|
| 222 | - $menu_properties = $admin_page_init->getMenuProperties(); |
|
| 223 | - if (empty($menu_properties)) { |
|
| 224 | - // no? ok setup the admin menu item the old way |
|
| 225 | - $admin_page_init->setupLegacyAdminMenuItem(); |
|
| 226 | - } else { |
|
| 227 | - // adding the admin page init callback here means the menu doesn't have to cart that object around |
|
| 228 | - $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page']; |
|
| 229 | - $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
|
| 230 | - } |
|
| 231 | - $admin_menu = $admin_page_init->adminMenu(); |
|
| 232 | - if (! $admin_menu instanceof AdminMenuItem) { |
|
| 233 | - throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
| 234 | - } |
|
| 235 | - if (! is_callable($admin_menu->menuCallback())) { |
|
| 236 | - $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
|
| 237 | - } |
|
| 238 | - // get the menu group that this menu item belongs to and then add it |
|
| 239 | - $admin_group = $this->getMenuGroup($admin_menu); |
|
| 240 | - $admin_group->addMenuItem($admin_menu); |
|
| 241 | - return $admin_menu; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param array $menu_properties |
|
| 247 | - * @return AdminMenuItem|null |
|
| 248 | - */ |
|
| 249 | - private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem |
|
| 250 | - { |
|
| 251 | - $type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP; |
|
| 252 | - unset($menu_properties['menu_type']); |
|
| 253 | - switch ($type) { |
|
| 254 | - case AdminMenuItem::TYPE_MENU_GROUP: |
|
| 255 | - unset($menu_properties['menu_callback']); |
|
| 256 | - return new AdminMenuGroup($menu_properties); |
|
| 257 | - case AdminMenuItem::TYPE_MENU_TOP: |
|
| 258 | - return new AdminMenuTopLevel($menu_properties); |
|
| 259 | - case AdminMenuItem::TYPE_MENU_SUB_ITEM: |
|
| 260 | - return new AdminMenuSubItem($menu_properties); |
|
| 261 | - } |
|
| 262 | - return null; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param AdminMenuItem $admin_menu |
|
| 268 | - * @return AdminMenuGroup |
|
| 269 | - * @throws DomainException |
|
| 270 | - * @throws OutOfRangeException |
|
| 271 | - */ |
|
| 272 | - private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
|
| 273 | - { |
|
| 274 | - if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
| 275 | - throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
|
| 276 | - } |
|
| 277 | - $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
| 278 | - if (! $admin_group instanceof AdminMenuGroup) { |
|
| 279 | - throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
|
| 280 | - } |
|
| 281 | - return $admin_group; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * set_network_menus |
|
| 287 | - * This method sets up the menus for network EE Admin Pages. |
|
| 288 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
| 289 | - * are only added to the menu map if they are intended for the admin menu |
|
| 290 | - * |
|
| 291 | - * @return void |
|
| 292 | - * @throws DomainException |
|
| 293 | - */ |
|
| 294 | - public function generateNetworkAdminMenu() |
|
| 295 | - { |
|
| 296 | - $this->generateAdminMenu(true); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * This method sets up the menus for EE Admin Pages |
|
| 302 | - * |
|
| 303 | - * @return void |
|
| 304 | - * @throws DomainException |
|
| 305 | - */ |
|
| 306 | - public function generateAdminMenu(bool $network_admin = false) |
|
| 307 | - { |
|
| 308 | - $admin_menu = $this->sortMenu($this->menu_items); |
|
| 309 | - $this->top_level_menu_item->registerAdminMenuItem($network_admin); |
|
| 310 | - $this->registerAdminMenu($admin_menu, $network_admin); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @param array $admin_menu |
|
| 316 | - * @param bool $network_admin |
|
| 317 | - */ |
|
| 318 | - private function registerAdminMenu(array $admin_menu, bool $network_admin) |
|
| 319 | - { |
|
| 320 | - foreach ($admin_menu as $menu_item) { |
|
| 321 | - if ($this->skipMenuItem($menu_item)) { |
|
| 322 | - continue; |
|
| 323 | - } |
|
| 324 | - try { |
|
| 325 | - $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
|
| 326 | - $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
| 327 | - if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
|
| 328 | - $admin_init_page->setWpPageSlug($wp_page_slug); |
|
| 329 | - $admin_init_page->set_page_dependencies($wp_page_slug); |
|
| 330 | - } |
|
| 331 | - if ($menu_item instanceof AdminMenuGroup) { |
|
| 332 | - $this->registerAdminMenu($menu_item->getMenuItems(), $network_admin); |
|
| 333 | - } |
|
| 334 | - } catch (Exception $e) { |
|
| 335 | - EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine()); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * returns TRUE if any of the following conditions is met: |
|
| 343 | - * - menu item is NOT an instanceof AdminMenuItem |
|
| 344 | - * - menu item has already been registered |
|
| 345 | - * - menu item should not be shown when site is in full maintenance mode |
|
| 346 | - * - current user does not have the required access permission |
|
| 347 | - * - menu item is a group but has no sub items |
|
| 348 | - * |
|
| 349 | - * @param AdminMenuItem|null $menu_item |
|
| 350 | - * @return bool |
|
| 351 | - */ |
|
| 352 | - private function skipMenuItem(?AdminMenuItem $menu_item): bool |
|
| 353 | - { |
|
| 354 | - return ! $menu_item instanceof AdminMenuItem |
|
| 355 | - || $menu_item->isRegistered() |
|
| 356 | - || ! $menu_item->showOnMaintenanceModeMenu() |
|
| 357 | - || ! $menu_item->currentUserHasAccess() |
|
| 358 | - || ( |
|
| 359 | - $menu_item instanceof AdminMenuGroup |
|
| 360 | - && $menu_item->hasNoMenuItems() |
|
| 361 | - ); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * @param EE_Admin_Page_Init[] $installed_pages |
|
| 367 | - */ |
|
| 368 | - public function setInstalledPages(array $installed_pages): void |
|
| 369 | - { |
|
| 370 | - $this->installed_pages = $installed_pages; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Recursively sort menu groups and their sub items |
|
| 376 | - * |
|
| 377 | - * @return AdminMenuItem[] |
|
| 378 | - * @throws DomainException |
|
| 379 | - */ |
|
| 380 | - public function sortMenu(array $admin_menu): array |
|
| 381 | - { |
|
| 382 | - foreach ($admin_menu as $menu_group) { |
|
| 383 | - if (! $menu_group instanceof AdminMenuItem) { |
|
| 384 | - throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
| 385 | - } |
|
| 386 | - if ($menu_group instanceof AdminMenuGroup) { |
|
| 387 | - // sort sub items |
|
| 388 | - $menu_items = $this->sortMenu($menu_group->getMenuItems()); |
|
| 389 | - $menu_group->setMenuItems($menu_items); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - // sort incoming array AFTER it's been looped through and elements have been validated |
|
| 393 | - usort($admin_menu, [$this, 'sortMenuItems']); |
|
| 394 | - return $admin_menu; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * sort sub menu items |
|
| 400 | - * |
|
| 401 | - * @param AdminMenuItem $a menu_item |
|
| 402 | - * @param AdminMenuItem $b being compared to |
|
| 403 | - * @return int sort order |
|
| 404 | - */ |
|
| 405 | - private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int |
|
| 406 | - { |
|
| 407 | - if ($a->menuOrder() === $b->menuOrder()) { |
|
| 408 | - return 0; |
|
| 409 | - } |
|
| 410 | - return $a->menuOrder() < $b->menuOrder() ? -1 : 1; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Moves the Event Espresso admin menu to the position set by $this->menu_position |
|
| 416 | - * |
|
| 417 | - * @param array $menu_order |
|
| 418 | - * @return array |
|
| 419 | - */ |
|
| 420 | - public function reorderAdminMenu(array $menu_order): array |
|
| 421 | - { |
|
| 422 | - $menu_slug = $this->maintenance_mode ? 'espresso_maintenance_settings' : 'espresso_events'; |
|
| 423 | - $current_index = array_search($menu_slug, $menu_order); |
|
| 424 | - if ($current_index === false) { |
|
| 425 | - return $menu_order; |
|
| 426 | - } |
|
| 427 | - // chop out the espresso admin menu if found |
|
| 428 | - $espresso_menu = array_splice($menu_order, $current_index, 1); |
|
| 429 | - // reinsert at position set by $this->menu_position |
|
| 430 | - array_splice($menu_order, $this->menu_position, 0, $espresso_menu); |
|
| 431 | - return $menu_order; |
|
| 432 | - } |
|
| 18 | + /** |
|
| 19 | + * Default: null - defaults to below Comments |
|
| 20 | + * |
|
| 21 | + * 5 - below Posts |
|
| 22 | + * 10 - below Media |
|
| 23 | + * 15 - below Links |
|
| 24 | + * 20 - below Pages |
|
| 25 | + * 25 - below comments |
|
| 26 | + * 60 - below first separator |
|
| 27 | + * 65 - below Plugins |
|
| 28 | + * 70 - below Users |
|
| 29 | + * 75 - below Tools |
|
| 30 | + * 80 - below Settings |
|
| 31 | + * 100 - below second separator |
|
| 32 | + */ |
|
| 33 | + const DEFAULT_MENU_POSITION = 100; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var AdminMenuItem[] |
|
| 38 | + */ |
|
| 39 | + private $menu_items = []; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * objects for page_init objects detected and loaded |
|
| 43 | + * |
|
| 44 | + * @var EE_Admin_Page_Init[] |
|
| 45 | + */ |
|
| 46 | + private $installed_pages = []; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * set to TRUE if site is currently in maintenance mode level 2 |
|
| 50 | + * |
|
| 51 | + * @var bool |
|
| 52 | + */ |
|
| 53 | + protected bool $maintenance_mode = false; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * same values used by AdminMenuManager::DEFAULT_MENU_POSITION |
|
| 57 | + * |
|
| 58 | + * @var int |
|
| 59 | + */ |
|
| 60 | + private $menu_position; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var AdminMenuItem |
|
| 64 | + */ |
|
| 65 | + private $top_level_menu_item; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + public function __construct() |
|
| 69 | + { |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + public function initialize() |
|
| 74 | + { |
|
| 75 | + $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
| 76 | + $this->menu_position = apply_filters( |
|
| 77 | + 'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position', |
|
| 78 | + AdminMenuManager::DEFAULT_MENU_POSITION, |
|
| 79 | + $this->maintenance_mode |
|
| 80 | + ); |
|
| 81 | + $this->addTopLevelMenuItem(); |
|
| 82 | + $this->initializeMenuGroups(); |
|
| 83 | + add_action('admin_menu', [$this, 'generateAdminMenu']); |
|
| 84 | + add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']); |
|
| 85 | + add_filter('custom_menu_order', '__return_true'); |
|
| 86 | + add_filter('menu_order', [$this, 'reorderAdminMenu']); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * adds the top level menu item that everything else descends from. |
|
| 92 | + * changes depending on whether site is in full maintenance mode or not |
|
| 93 | + * |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + private function addTopLevelMenuItem() |
|
| 97 | + { |
|
| 98 | + $this->top_level_menu_item = $this->maintenance_mode |
|
| 99 | + ? $this->instantiateAdminMenu( |
|
| 100 | + [ |
|
| 101 | + 'menu_slug' => 'espresso_maintenance_settings', |
|
| 102 | + 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 103 | + 'capability' => 'manage_options', |
|
| 104 | + 'menu_group' => 'main', |
|
| 105 | + 'menu_order' => 10, |
|
| 106 | + 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
| 107 | + 'parent_slug' => 'espresso_maintenance_settings', |
|
| 108 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 109 | + ] |
|
| 110 | + ) |
|
| 111 | + : $this->instantiateAdminMenu( |
|
| 112 | + [ |
|
| 113 | + 'menu_slug' => 'espresso_events', |
|
| 114 | + 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
| 115 | + 'capability' => 'ee_read_events', |
|
| 116 | + 'menu_group' => 'main', |
|
| 117 | + 'menu_order' => 10, |
|
| 118 | + 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
| 119 | + 'parent_slug' => 'espresso_events', |
|
| 120 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 121 | + ] |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
| 128 | + * |
|
| 129 | + * @return void |
|
| 130 | + */ |
|
| 131 | + private function initializeMenuGroups() |
|
| 132 | + { |
|
| 133 | + $this->menu_items = apply_filters( |
|
| 134 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
| 135 | + [ |
|
| 136 | + 'main' => $this->instantiateAdminMenu( |
|
| 137 | + [ |
|
| 138 | + 'menu_slug' => 'main', |
|
| 139 | + 'menu_label' => esc_html__('Main', 'event_espresso'), |
|
| 140 | + 'capability' => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee', |
|
| 141 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 142 | + 'menu_order' => 0, |
|
| 143 | + 'parent_slug' => 'espresso_events', |
|
| 144 | + 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
| 145 | + ] |
|
| 146 | + ), |
|
| 147 | + 'management' => $this->instantiateAdminMenu( |
|
| 148 | + [ |
|
| 149 | + 'menu_slug' => 'management', |
|
| 150 | + 'menu_label' => esc_html__('Management', 'event_espresso'), |
|
| 151 | + 'capability' => 'ee_read_ee', |
|
| 152 | + 'menu_order' => 10, |
|
| 153 | + 'parent_slug' => 'espresso_events', |
|
| 154 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 155 | + ] |
|
| 156 | + ), |
|
| 157 | + 'addons' => $this->instantiateAdminMenu( |
|
| 158 | + [ |
|
| 159 | + 'menu_slug' => 'addons', |
|
| 160 | + 'menu_label' => esc_html__('Add-ons', 'event_espresso'), |
|
| 161 | + 'capability' => 'ee_read_ee', |
|
| 162 | + 'menu_order' => 20, |
|
| 163 | + 'parent_slug' => 'espresso_events', |
|
| 164 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
| 165 | + ] |
|
| 166 | + ), |
|
| 167 | + 'settings' => $this->instantiateAdminMenu( |
|
| 168 | + [ |
|
| 169 | + 'menu_slug' => 'settings', |
|
| 170 | + 'menu_label' => esc_html__('Settings', 'event_espresso'), |
|
| 171 | + 'capability' => 'ee_read_ee', |
|
| 172 | + 'menu_order' => 30, |
|
| 173 | + 'parent_slug' => 'espresso_events', |
|
| 174 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 175 | + ] |
|
| 176 | + ), |
|
| 177 | + 'templates' => $this->instantiateAdminMenu( |
|
| 178 | + [ |
|
| 179 | + 'menu_slug' => 'templates', |
|
| 180 | + 'menu_label' => esc_html__('Templates', 'event_espresso'), |
|
| 181 | + 'capability' => 'ee_read_ee', |
|
| 182 | + 'menu_order' => 40, |
|
| 183 | + 'parent_slug' => 'espresso_events', |
|
| 184 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 185 | + ] |
|
| 186 | + ), |
|
| 187 | + 'extras' => $this->instantiateAdminMenu( |
|
| 188 | + [ |
|
| 189 | + 'menu_slug' => 'extras', |
|
| 190 | + 'menu_label' => esc_html__('Extras', 'event_espresso'), |
|
| 191 | + 'capability' => 'ee_read_ee', |
|
| 192 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 193 | + 'menu_order' => 50, |
|
| 194 | + 'parent_slug' => 'espresso_events', |
|
| 195 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
| 196 | + ] |
|
| 197 | + ), |
|
| 198 | + 'tools' => $this->instantiateAdminMenu( |
|
| 199 | + [ |
|
| 200 | + 'menu_slug' => 'tools', |
|
| 201 | + 'menu_label' => esc_html__('Tools', 'event_espresso'), |
|
| 202 | + 'capability' => 'ee_read_ee', |
|
| 203 | + 'menu_order' => 60, |
|
| 204 | + 'parent_slug' => 'espresso_events', |
|
| 205 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
| 206 | + ] |
|
| 207 | + ), |
|
| 208 | + ] |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init |
|
| 215 | + * |
|
| 216 | + * @param EE_Admin_Page_Init $admin_page_init |
|
| 217 | + * @return AdminMenuItem |
|
| 218 | + */ |
|
| 219 | + public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem |
|
| 220 | + { |
|
| 221 | + // see if admin page init is using new classes |
|
| 222 | + $menu_properties = $admin_page_init->getMenuProperties(); |
|
| 223 | + if (empty($menu_properties)) { |
|
| 224 | + // no? ok setup the admin menu item the old way |
|
| 225 | + $admin_page_init->setupLegacyAdminMenuItem(); |
|
| 226 | + } else { |
|
| 227 | + // adding the admin page init callback here means the menu doesn't have to cart that object around |
|
| 228 | + $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page']; |
|
| 229 | + $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
|
| 230 | + } |
|
| 231 | + $admin_menu = $admin_page_init->adminMenu(); |
|
| 232 | + if (! $admin_menu instanceof AdminMenuItem) { |
|
| 233 | + throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
| 234 | + } |
|
| 235 | + if (! is_callable($admin_menu->menuCallback())) { |
|
| 236 | + $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
|
| 237 | + } |
|
| 238 | + // get the menu group that this menu item belongs to and then add it |
|
| 239 | + $admin_group = $this->getMenuGroup($admin_menu); |
|
| 240 | + $admin_group->addMenuItem($admin_menu); |
|
| 241 | + return $admin_menu; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param array $menu_properties |
|
| 247 | + * @return AdminMenuItem|null |
|
| 248 | + */ |
|
| 249 | + private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem |
|
| 250 | + { |
|
| 251 | + $type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP; |
|
| 252 | + unset($menu_properties['menu_type']); |
|
| 253 | + switch ($type) { |
|
| 254 | + case AdminMenuItem::TYPE_MENU_GROUP: |
|
| 255 | + unset($menu_properties['menu_callback']); |
|
| 256 | + return new AdminMenuGroup($menu_properties); |
|
| 257 | + case AdminMenuItem::TYPE_MENU_TOP: |
|
| 258 | + return new AdminMenuTopLevel($menu_properties); |
|
| 259 | + case AdminMenuItem::TYPE_MENU_SUB_ITEM: |
|
| 260 | + return new AdminMenuSubItem($menu_properties); |
|
| 261 | + } |
|
| 262 | + return null; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param AdminMenuItem $admin_menu |
|
| 268 | + * @return AdminMenuGroup |
|
| 269 | + * @throws DomainException |
|
| 270 | + * @throws OutOfRangeException |
|
| 271 | + */ |
|
| 272 | + private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
|
| 273 | + { |
|
| 274 | + if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
| 275 | + throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
|
| 276 | + } |
|
| 277 | + $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
| 278 | + if (! $admin_group instanceof AdminMenuGroup) { |
|
| 279 | + throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
|
| 280 | + } |
|
| 281 | + return $admin_group; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * set_network_menus |
|
| 287 | + * This method sets up the menus for network EE Admin Pages. |
|
| 288 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
| 289 | + * are only added to the menu map if they are intended for the admin menu |
|
| 290 | + * |
|
| 291 | + * @return void |
|
| 292 | + * @throws DomainException |
|
| 293 | + */ |
|
| 294 | + public function generateNetworkAdminMenu() |
|
| 295 | + { |
|
| 296 | + $this->generateAdminMenu(true); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * This method sets up the menus for EE Admin Pages |
|
| 302 | + * |
|
| 303 | + * @return void |
|
| 304 | + * @throws DomainException |
|
| 305 | + */ |
|
| 306 | + public function generateAdminMenu(bool $network_admin = false) |
|
| 307 | + { |
|
| 308 | + $admin_menu = $this->sortMenu($this->menu_items); |
|
| 309 | + $this->top_level_menu_item->registerAdminMenuItem($network_admin); |
|
| 310 | + $this->registerAdminMenu($admin_menu, $network_admin); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @param array $admin_menu |
|
| 316 | + * @param bool $network_admin |
|
| 317 | + */ |
|
| 318 | + private function registerAdminMenu(array $admin_menu, bool $network_admin) |
|
| 319 | + { |
|
| 320 | + foreach ($admin_menu as $menu_item) { |
|
| 321 | + if ($this->skipMenuItem($menu_item)) { |
|
| 322 | + continue; |
|
| 323 | + } |
|
| 324 | + try { |
|
| 325 | + $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
|
| 326 | + $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
| 327 | + if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
|
| 328 | + $admin_init_page->setWpPageSlug($wp_page_slug); |
|
| 329 | + $admin_init_page->set_page_dependencies($wp_page_slug); |
|
| 330 | + } |
|
| 331 | + if ($menu_item instanceof AdminMenuGroup) { |
|
| 332 | + $this->registerAdminMenu($menu_item->getMenuItems(), $network_admin); |
|
| 333 | + } |
|
| 334 | + } catch (Exception $e) { |
|
| 335 | + EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine()); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * returns TRUE if any of the following conditions is met: |
|
| 343 | + * - menu item is NOT an instanceof AdminMenuItem |
|
| 344 | + * - menu item has already been registered |
|
| 345 | + * - menu item should not be shown when site is in full maintenance mode |
|
| 346 | + * - current user does not have the required access permission |
|
| 347 | + * - menu item is a group but has no sub items |
|
| 348 | + * |
|
| 349 | + * @param AdminMenuItem|null $menu_item |
|
| 350 | + * @return bool |
|
| 351 | + */ |
|
| 352 | + private function skipMenuItem(?AdminMenuItem $menu_item): bool |
|
| 353 | + { |
|
| 354 | + return ! $menu_item instanceof AdminMenuItem |
|
| 355 | + || $menu_item->isRegistered() |
|
| 356 | + || ! $menu_item->showOnMaintenanceModeMenu() |
|
| 357 | + || ! $menu_item->currentUserHasAccess() |
|
| 358 | + || ( |
|
| 359 | + $menu_item instanceof AdminMenuGroup |
|
| 360 | + && $menu_item->hasNoMenuItems() |
|
| 361 | + ); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * @param EE_Admin_Page_Init[] $installed_pages |
|
| 367 | + */ |
|
| 368 | + public function setInstalledPages(array $installed_pages): void |
|
| 369 | + { |
|
| 370 | + $this->installed_pages = $installed_pages; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Recursively sort menu groups and their sub items |
|
| 376 | + * |
|
| 377 | + * @return AdminMenuItem[] |
|
| 378 | + * @throws DomainException |
|
| 379 | + */ |
|
| 380 | + public function sortMenu(array $admin_menu): array |
|
| 381 | + { |
|
| 382 | + foreach ($admin_menu as $menu_group) { |
|
| 383 | + if (! $menu_group instanceof AdminMenuItem) { |
|
| 384 | + throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
| 385 | + } |
|
| 386 | + if ($menu_group instanceof AdminMenuGroup) { |
|
| 387 | + // sort sub items |
|
| 388 | + $menu_items = $this->sortMenu($menu_group->getMenuItems()); |
|
| 389 | + $menu_group->setMenuItems($menu_items); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + // sort incoming array AFTER it's been looped through and elements have been validated |
|
| 393 | + usort($admin_menu, [$this, 'sortMenuItems']); |
|
| 394 | + return $admin_menu; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * sort sub menu items |
|
| 400 | + * |
|
| 401 | + * @param AdminMenuItem $a menu_item |
|
| 402 | + * @param AdminMenuItem $b being compared to |
|
| 403 | + * @return int sort order |
|
| 404 | + */ |
|
| 405 | + private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int |
|
| 406 | + { |
|
| 407 | + if ($a->menuOrder() === $b->menuOrder()) { |
|
| 408 | + return 0; |
|
| 409 | + } |
|
| 410 | + return $a->menuOrder() < $b->menuOrder() ? -1 : 1; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Moves the Event Espresso admin menu to the position set by $this->menu_position |
|
| 416 | + * |
|
| 417 | + * @param array $menu_order |
|
| 418 | + * @return array |
|
| 419 | + */ |
|
| 420 | + public function reorderAdminMenu(array $menu_order): array |
|
| 421 | + { |
|
| 422 | + $menu_slug = $this->maintenance_mode ? 'espresso_maintenance_settings' : 'espresso_events'; |
|
| 423 | + $current_index = array_search($menu_slug, $menu_order); |
|
| 424 | + if ($current_index === false) { |
|
| 425 | + return $menu_order; |
|
| 426 | + } |
|
| 427 | + // chop out the espresso admin menu if found |
|
| 428 | + $espresso_menu = array_splice($menu_order, $current_index, 1); |
|
| 429 | + // reinsert at position set by $this->menu_position |
|
| 430 | + array_splice($menu_order, $this->menu_position, 0, $espresso_menu); |
|
| 431 | + return $menu_order; |
|
| 432 | + } |
|
| 433 | 433 | } |
@@ -17,140 +17,140 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class FeatureFlagsConfig extends JsonDataWordpressOption |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * WP option name for saving the Feature Flags configuration |
|
| 22 | - */ |
|
| 23 | - private const OPTION_NAME = 'ee_feature_flags'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Whether to use the New Event Editor (EDTR) or continue using the legacy Event Editor |
|
| 27 | - * deafult: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
| 28 | - */ |
|
| 29 | - public const USE_ADVANCED_EVENT_EDITOR = 'ee_advanced_event_editor'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR) |
|
| 33 | - * default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
| 34 | - */ |
|
| 35 | - public const USE_EVENT_EDITOR_BULK_EDIT = 'ee_event_editor_bulk_edit'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Whether to enable the new Default Ticket Manager in the EDTR |
|
| 39 | - * default: Enabled |
|
| 40 | - */ |
|
| 41 | - public const USE_DEFAULT_TICKET_MANAGER = 'use_default_ticket_manager'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce |
|
| 45 | - * default: Disabled |
|
| 46 | - */ |
|
| 47 | - public const USE_EVENT_DESCRIPTION_RTE = 'use_event_description_rte'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Whether to enable the Rich Text Editor for all other RTE fields in the EDTR |
|
| 51 | - * default: Disabled |
|
| 52 | - */ |
|
| 53 | - public const USE_EXPERIMENTAL_RTE = 'use_experimental_rte'; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Whether to enable the new Registration Form Builder in the EDTR |
|
| 57 | - * or continue using the legacy Question Groups and Registration Form admin pages |
|
| 58 | - * default: Disabled |
|
| 59 | - */ |
|
| 60 | - public const USE_REG_FORM_BUILDER = 'use_reg_form_builder'; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Whether to enable the new Registration Options meta box in the EDTR |
|
| 64 | - * or continue using the legacy Event Registration Options |
|
| 65 | - * default: Disabled |
|
| 66 | - */ |
|
| 67 | - public const USE_REG_OPTIONS_META_BOX = 'use_reg_options_meta_box'; |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - protected Domain $domain; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - public function __construct(Domain $domain, JsonDataHandler $json_data_handler) |
|
| 74 | - { |
|
| 75 | - $this->domain = $domain; |
|
| 76 | - parent::__construct($json_data_handler, FeatureFlagsConfig::OPTION_NAME, $this->getDefaultFeatureFlagOptions()); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * see the FeatureFlagsConfig::USE_* constants for descriptions of each feature flag and their default values |
|
| 82 | - * |
|
| 83 | - * @return stdClass |
|
| 84 | - */ |
|
| 85 | - public function getDefaultFeatureFlagOptions(): stdClass |
|
| 86 | - { |
|
| 87 | - return (object) [ |
|
| 88 | - self::USE_ADVANCED_EVENT_EDITOR => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
| 89 | - self::USE_EVENT_EDITOR_BULK_EDIT => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
| 90 | - self::USE_DEFAULT_TICKET_MANAGER => true, |
|
| 91 | - self::USE_EVENT_DESCRIPTION_RTE => false, |
|
| 92 | - self::USE_EXPERIMENTAL_RTE => false, |
|
| 93 | - self::USE_REG_FORM_BUILDER => false, |
|
| 94 | - self::USE_REG_OPTIONS_META_BOX => false, |
|
| 95 | - ]; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return stdClass |
|
| 101 | - */ |
|
| 102 | - public function getFeatureFlags(): stdClass |
|
| 103 | - { |
|
| 104 | - if (apply_filters('FHEE__FeatureFlagsConfig__getFeatureFlags__use_default_feature_flags', true)) { |
|
| 105 | - return $this->getDefaultFeatureFlagOptions(); |
|
| 106 | - } |
|
| 107 | - return $this->getAll() ?: $this->getDefaultFeatureFlagOptions(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - public function saveFeatureFlagsConfig(stdClass $feature_flags): int |
|
| 112 | - { |
|
| 113 | - return $this->updateOption($feature_flags); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * enables a feature flag, ex: |
|
| 119 | - * $this->enableFeatureFlag(FeatureFlagsConfig::USE_ADVANCED_EVENT_EDITOR); |
|
| 120 | - * |
|
| 121 | - * @param string $feature_flag the feature flag to enable. One of the FeatureFlagsConfig::USE_* constants |
|
| 122 | - * @return int |
|
| 123 | - */ |
|
| 124 | - public function enableFeatureFlag(string $feature_flag): int |
|
| 125 | - { |
|
| 126 | - $feature_flags = $this->getFeatureFlags(); |
|
| 127 | - if (! property_exists($feature_flags, $feature_flag)) { |
|
| 128 | - return WordPressOption::UPDATE_ERROR; |
|
| 129 | - } |
|
| 130 | - $feature_flags->{$feature_flag} = true; |
|
| 131 | - // if feature flag is the advanced event editor or bulk edit options |
|
| 132 | - // then only enabled if the site is Caffeinated and not MultiSite |
|
| 133 | - if ($feature_flag === self::USE_ADVANCED_EVENT_EDITOR || $feature_flag === self::USE_EVENT_EDITOR_BULK_EDIT) { |
|
| 134 | - $feature_flags->{$feature_flag} = $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(); |
|
| 135 | - } |
|
| 136 | - return $this->saveFeatureFlagsConfig($feature_flags); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * disables a feature flag, ex: |
|
| 142 | - * $this->disableFeatureFlag(FeatureFlagsConfig::USE_ADVANCED_EVENT_EDITOR); |
|
| 143 | - * |
|
| 144 | - * @param string $feature_flag the feature flag to disable. One of the FeatureFlagsConfig::USE_* constants |
|
| 145 | - * @return int |
|
| 146 | - */ |
|
| 147 | - public function disableFeatureFlag(string $feature_flag): int |
|
| 148 | - { |
|
| 149 | - $feature_flags = $this->getFeatureFlags(); |
|
| 150 | - if (! property_exists($feature_flags, $feature_flag)) { |
|
| 151 | - return WordPressOption::UPDATE_ERROR; |
|
| 152 | - } |
|
| 153 | - $feature_flags->{$feature_flag} = false; |
|
| 154 | - return $this->saveFeatureFlagsConfig($feature_flags); |
|
| 155 | - } |
|
| 20 | + /** |
|
| 21 | + * WP option name for saving the Feature Flags configuration |
|
| 22 | + */ |
|
| 23 | + private const OPTION_NAME = 'ee_feature_flags'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Whether to use the New Event Editor (EDTR) or continue using the legacy Event Editor |
|
| 27 | + * deafult: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
| 28 | + */ |
|
| 29 | + public const USE_ADVANCED_EVENT_EDITOR = 'ee_advanced_event_editor'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR) |
|
| 33 | + * default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
| 34 | + */ |
|
| 35 | + public const USE_EVENT_EDITOR_BULK_EDIT = 'ee_event_editor_bulk_edit'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Whether to enable the new Default Ticket Manager in the EDTR |
|
| 39 | + * default: Enabled |
|
| 40 | + */ |
|
| 41 | + public const USE_DEFAULT_TICKET_MANAGER = 'use_default_ticket_manager'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce |
|
| 45 | + * default: Disabled |
|
| 46 | + */ |
|
| 47 | + public const USE_EVENT_DESCRIPTION_RTE = 'use_event_description_rte'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Whether to enable the Rich Text Editor for all other RTE fields in the EDTR |
|
| 51 | + * default: Disabled |
|
| 52 | + */ |
|
| 53 | + public const USE_EXPERIMENTAL_RTE = 'use_experimental_rte'; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Whether to enable the new Registration Form Builder in the EDTR |
|
| 57 | + * or continue using the legacy Question Groups and Registration Form admin pages |
|
| 58 | + * default: Disabled |
|
| 59 | + */ |
|
| 60 | + public const USE_REG_FORM_BUILDER = 'use_reg_form_builder'; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Whether to enable the new Registration Options meta box in the EDTR |
|
| 64 | + * or continue using the legacy Event Registration Options |
|
| 65 | + * default: Disabled |
|
| 66 | + */ |
|
| 67 | + public const USE_REG_OPTIONS_META_BOX = 'use_reg_options_meta_box'; |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + protected Domain $domain; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + public function __construct(Domain $domain, JsonDataHandler $json_data_handler) |
|
| 74 | + { |
|
| 75 | + $this->domain = $domain; |
|
| 76 | + parent::__construct($json_data_handler, FeatureFlagsConfig::OPTION_NAME, $this->getDefaultFeatureFlagOptions()); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * see the FeatureFlagsConfig::USE_* constants for descriptions of each feature flag and their default values |
|
| 82 | + * |
|
| 83 | + * @return stdClass |
|
| 84 | + */ |
|
| 85 | + public function getDefaultFeatureFlagOptions(): stdClass |
|
| 86 | + { |
|
| 87 | + return (object) [ |
|
| 88 | + self::USE_ADVANCED_EVENT_EDITOR => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
| 89 | + self::USE_EVENT_EDITOR_BULK_EDIT => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
| 90 | + self::USE_DEFAULT_TICKET_MANAGER => true, |
|
| 91 | + self::USE_EVENT_DESCRIPTION_RTE => false, |
|
| 92 | + self::USE_EXPERIMENTAL_RTE => false, |
|
| 93 | + self::USE_REG_FORM_BUILDER => false, |
|
| 94 | + self::USE_REG_OPTIONS_META_BOX => false, |
|
| 95 | + ]; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return stdClass |
|
| 101 | + */ |
|
| 102 | + public function getFeatureFlags(): stdClass |
|
| 103 | + { |
|
| 104 | + if (apply_filters('FHEE__FeatureFlagsConfig__getFeatureFlags__use_default_feature_flags', true)) { |
|
| 105 | + return $this->getDefaultFeatureFlagOptions(); |
|
| 106 | + } |
|
| 107 | + return $this->getAll() ?: $this->getDefaultFeatureFlagOptions(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + public function saveFeatureFlagsConfig(stdClass $feature_flags): int |
|
| 112 | + { |
|
| 113 | + return $this->updateOption($feature_flags); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * enables a feature flag, ex: |
|
| 119 | + * $this->enableFeatureFlag(FeatureFlagsConfig::USE_ADVANCED_EVENT_EDITOR); |
|
| 120 | + * |
|
| 121 | + * @param string $feature_flag the feature flag to enable. One of the FeatureFlagsConfig::USE_* constants |
|
| 122 | + * @return int |
|
| 123 | + */ |
|
| 124 | + public function enableFeatureFlag(string $feature_flag): int |
|
| 125 | + { |
|
| 126 | + $feature_flags = $this->getFeatureFlags(); |
|
| 127 | + if (! property_exists($feature_flags, $feature_flag)) { |
|
| 128 | + return WordPressOption::UPDATE_ERROR; |
|
| 129 | + } |
|
| 130 | + $feature_flags->{$feature_flag} = true; |
|
| 131 | + // if feature flag is the advanced event editor or bulk edit options |
|
| 132 | + // then only enabled if the site is Caffeinated and not MultiSite |
|
| 133 | + if ($feature_flag === self::USE_ADVANCED_EVENT_EDITOR || $feature_flag === self::USE_EVENT_EDITOR_BULK_EDIT) { |
|
| 134 | + $feature_flags->{$feature_flag} = $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(); |
|
| 135 | + } |
|
| 136 | + return $this->saveFeatureFlagsConfig($feature_flags); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * disables a feature flag, ex: |
|
| 142 | + * $this->disableFeatureFlag(FeatureFlagsConfig::USE_ADVANCED_EVENT_EDITOR); |
|
| 143 | + * |
|
| 144 | + * @param string $feature_flag the feature flag to disable. One of the FeatureFlagsConfig::USE_* constants |
|
| 145 | + * @return int |
|
| 146 | + */ |
|
| 147 | + public function disableFeatureFlag(string $feature_flag): int |
|
| 148 | + { |
|
| 149 | + $feature_flags = $this->getFeatureFlags(); |
|
| 150 | + if (! property_exists($feature_flags, $feature_flag)) { |
|
| 151 | + return WordPressOption::UPDATE_ERROR; |
|
| 152 | + } |
|
| 153 | + $feature_flags->{$feature_flag} = false; |
|
| 154 | + return $this->saveFeatureFlagsConfig($feature_flags); |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -20,182 +20,182 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | abstract class AbstractConnectionResolver extends WPGraphQLConnectionResolver |
| 22 | 22 | { |
| 23 | - public const MAX_QUERY_LIMIT = 250; |
|
| 24 | - |
|
| 25 | - private ?Utilities $utilities = null; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - public function __construct($source, array $args, AppContext $context, ResolveInfo $info) |
|
| 29 | - { |
|
| 30 | - add_filter( |
|
| 31 | - 'graphql_connection_max_query_amount', |
|
| 32 | - static function ($max_query_amount) { |
|
| 33 | - return self::MAX_QUERY_LIMIT; |
|
| 34 | - } |
|
| 35 | - ); |
|
| 36 | - parent::__construct($source, $args, $context, $info); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @return Utilities |
|
| 42 | - */ |
|
| 43 | - public function getUtilities(): Utilities |
|
| 44 | - { |
|
| 45 | - if (! $this->utilities instanceof Utilities) { |
|
| 46 | - $this->utilities = LoaderFactory::getLoader()->getShared(Utilities::class); |
|
| 47 | - } |
|
| 48 | - return $this->utilities; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Determine whether the Query should execute. If it's determined that the query should |
|
| 53 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 54 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 55 | - * Return false to prevent the query from executing. |
|
| 56 | - * |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 60 | - public function should_execute(): bool |
|
| 61 | - { |
|
| 62 | - return $this->should_execute; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Set limit the highest value of first and last, with a (filterable) max of 500 |
|
| 68 | - * |
|
| 69 | - * @return int |
|
| 70 | - */ |
|
| 71 | - protected function getLimit(): int |
|
| 72 | - { |
|
| 73 | - $first = ! empty($this->args['first']) |
|
| 74 | - ? absint($this->args['first']) |
|
| 75 | - : null; |
|
| 76 | - $last = ! empty($this->args['last']) |
|
| 77 | - ? absint($this->args['last']) |
|
| 78 | - : null; |
|
| 79 | - |
|
| 80 | - $limit = min( |
|
| 81 | - max($first, $last, self::MAX_QUERY_LIMIT), |
|
| 82 | - $this->query_amount |
|
| 83 | - ); |
|
| 84 | - $limit++; |
|
| 85 | - return $limit; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // /** |
|
| 89 | - // * Get_amount_requested |
|
| 90 | - // * |
|
| 91 | - // * This checks the $args to determine the amount requested |
|
| 92 | - // * |
|
| 93 | - // * @return int|null |
|
| 94 | - // * @throws Exception |
|
| 95 | - // */ |
|
| 96 | - // // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 97 | - // public function get_amount_requested(): ?int |
|
| 98 | - // { |
|
| 99 | - // $amount_requested = parent::get_amount_requested(); |
|
| 100 | - // |
|
| 101 | - // /** |
|
| 102 | - // * If both first & last are used in the input args, throw an exception as that won't |
|
| 103 | - // * work properly |
|
| 104 | - // */ |
|
| 105 | - // if (empty($this->args['first']) && empty($this->args['last']) && $amount_requested === ConnectionsManager::MAX_AMOUNT_REQUESTED) { |
|
| 106 | - // return ConnectionsManager::MAX_AMOUNT_REQUESTED; // default. |
|
| 107 | - // } |
|
| 108 | - // |
|
| 109 | - // return $amount_requested; |
|
| 110 | - // } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Determine whether the offset is valid, i.e the entity corresponding to the |
|
| 114 | - * offset exists. Offset is equivalent to entity ID. So this function is equivalent to |
|
| 115 | - * checking if the entity with the given ID exists. |
|
| 116 | - * |
|
| 117 | - * @param int $offset The ID of the node used for the cursor offset |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 121 | - public function is_valid_offset($offset): bool |
|
| 122 | - { |
|
| 123 | - $entity = $this->get_query()->get_one_by_ID($offset); |
|
| 124 | - |
|
| 125 | - return $entity instanceof EE_Base_Class; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Validates Model. |
|
| 130 | - * |
|
| 131 | - * @param EE_Base_Class|null $model Entity node. |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 135 | - protected function is_valid_model($model): bool |
|
| 136 | - { |
|
| 137 | - return $model instanceof EE_Base_Class; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 143 | - * friendly keys. |
|
| 144 | - * |
|
| 145 | - * @param array $query_args |
|
| 146 | - * @param array $where_params |
|
| 147 | - * @param string $primary_key |
|
| 148 | - * @return array |
|
| 149 | - */ |
|
| 150 | - protected function mapOrderbyInputArgs(array $query_args, array $where_params, string $primary_key): array |
|
| 151 | - { |
|
| 152 | - // ID of the current offset |
|
| 153 | - $cursor = $this->args['after'] ?? null; |
|
| 154 | - $cursor = $cursor ?: ($this->args['before'] ?? null); |
|
| 155 | - $offset = $this->get_offset_for_cursor($cursor); |
|
| 156 | - /** |
|
| 157 | - * Map the orderby inputArgs to the WP_Query |
|
| 158 | - */ |
|
| 159 | - if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
| 160 | - $query_args['order_by'] = []; |
|
| 161 | - foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
| 162 | - $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
| 163 | - } |
|
| 164 | - } elseif ($offset) { |
|
| 165 | - $compare = $this->args['last'] ? '<' : '>'; |
|
| 166 | - $where_params[ $primary_key ] = [$compare, $offset]; |
|
| 167 | - } |
|
| 168 | - return [$query_args, $where_params]; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 174 | - * friendly keys. |
|
| 175 | - * |
|
| 176 | - * @param array $where_args |
|
| 177 | - * @param array $arg_mapping |
|
| 178 | - * @param array $id_fields The fields to convert from global IDs to DB IDs. |
|
| 179 | - * @return array |
|
| 180 | - */ |
|
| 181 | - protected function sanitizeWhereArgsForInputFields(array $where_args, array $arg_mapping, array $id_fields = []): array |
|
| 182 | - { |
|
| 183 | - return $this->getUtilities()->sanitizeWhereArgs($where_args, $arg_mapping, $id_fields); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * This returns the sanitized "search" keywords from where_args |
|
| 189 | - * |
|
| 190 | - * @param array $where_args |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - protected function getSearchKeywords(array $where_args): string |
|
| 194 | - { |
|
| 195 | - $search = ''; |
|
| 196 | - if (! empty($where_args['search'])) { |
|
| 197 | - $search = sanitize_text_field($where_args['search']); |
|
| 198 | - } |
|
| 199 | - return esc_sql($search); |
|
| 200 | - } |
|
| 23 | + public const MAX_QUERY_LIMIT = 250; |
|
| 24 | + |
|
| 25 | + private ?Utilities $utilities = null; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + public function __construct($source, array $args, AppContext $context, ResolveInfo $info) |
|
| 29 | + { |
|
| 30 | + add_filter( |
|
| 31 | + 'graphql_connection_max_query_amount', |
|
| 32 | + static function ($max_query_amount) { |
|
| 33 | + return self::MAX_QUERY_LIMIT; |
|
| 34 | + } |
|
| 35 | + ); |
|
| 36 | + parent::__construct($source, $args, $context, $info); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @return Utilities |
|
| 42 | + */ |
|
| 43 | + public function getUtilities(): Utilities |
|
| 44 | + { |
|
| 45 | + if (! $this->utilities instanceof Utilities) { |
|
| 46 | + $this->utilities = LoaderFactory::getLoader()->getShared(Utilities::class); |
|
| 47 | + } |
|
| 48 | + return $this->utilities; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Determine whether the Query should execute. If it's determined that the query should |
|
| 53 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 54 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 55 | + * Return false to prevent the query from executing. |
|
| 56 | + * |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 60 | + public function should_execute(): bool |
|
| 61 | + { |
|
| 62 | + return $this->should_execute; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Set limit the highest value of first and last, with a (filterable) max of 500 |
|
| 68 | + * |
|
| 69 | + * @return int |
|
| 70 | + */ |
|
| 71 | + protected function getLimit(): int |
|
| 72 | + { |
|
| 73 | + $first = ! empty($this->args['first']) |
|
| 74 | + ? absint($this->args['first']) |
|
| 75 | + : null; |
|
| 76 | + $last = ! empty($this->args['last']) |
|
| 77 | + ? absint($this->args['last']) |
|
| 78 | + : null; |
|
| 79 | + |
|
| 80 | + $limit = min( |
|
| 81 | + max($first, $last, self::MAX_QUERY_LIMIT), |
|
| 82 | + $this->query_amount |
|
| 83 | + ); |
|
| 84 | + $limit++; |
|
| 85 | + return $limit; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // /** |
|
| 89 | + // * Get_amount_requested |
|
| 90 | + // * |
|
| 91 | + // * This checks the $args to determine the amount requested |
|
| 92 | + // * |
|
| 93 | + // * @return int|null |
|
| 94 | + // * @throws Exception |
|
| 95 | + // */ |
|
| 96 | + // // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 97 | + // public function get_amount_requested(): ?int |
|
| 98 | + // { |
|
| 99 | + // $amount_requested = parent::get_amount_requested(); |
|
| 100 | + // |
|
| 101 | + // /** |
|
| 102 | + // * If both first & last are used in the input args, throw an exception as that won't |
|
| 103 | + // * work properly |
|
| 104 | + // */ |
|
| 105 | + // if (empty($this->args['first']) && empty($this->args['last']) && $amount_requested === ConnectionsManager::MAX_AMOUNT_REQUESTED) { |
|
| 106 | + // return ConnectionsManager::MAX_AMOUNT_REQUESTED; // default. |
|
| 107 | + // } |
|
| 108 | + // |
|
| 109 | + // return $amount_requested; |
|
| 110 | + // } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Determine whether the offset is valid, i.e the entity corresponding to the |
|
| 114 | + * offset exists. Offset is equivalent to entity ID. So this function is equivalent to |
|
| 115 | + * checking if the entity with the given ID exists. |
|
| 116 | + * |
|
| 117 | + * @param int $offset The ID of the node used for the cursor offset |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 121 | + public function is_valid_offset($offset): bool |
|
| 122 | + { |
|
| 123 | + $entity = $this->get_query()->get_one_by_ID($offset); |
|
| 124 | + |
|
| 125 | + return $entity instanceof EE_Base_Class; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Validates Model. |
|
| 130 | + * |
|
| 131 | + * @param EE_Base_Class|null $model Entity node. |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 135 | + protected function is_valid_model($model): bool |
|
| 136 | + { |
|
| 137 | + return $model instanceof EE_Base_Class; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 143 | + * friendly keys. |
|
| 144 | + * |
|
| 145 | + * @param array $query_args |
|
| 146 | + * @param array $where_params |
|
| 147 | + * @param string $primary_key |
|
| 148 | + * @return array |
|
| 149 | + */ |
|
| 150 | + protected function mapOrderbyInputArgs(array $query_args, array $where_params, string $primary_key): array |
|
| 151 | + { |
|
| 152 | + // ID of the current offset |
|
| 153 | + $cursor = $this->args['after'] ?? null; |
|
| 154 | + $cursor = $cursor ?: ($this->args['before'] ?? null); |
|
| 155 | + $offset = $this->get_offset_for_cursor($cursor); |
|
| 156 | + /** |
|
| 157 | + * Map the orderby inputArgs to the WP_Query |
|
| 158 | + */ |
|
| 159 | + if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
| 160 | + $query_args['order_by'] = []; |
|
| 161 | + foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
| 162 | + $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
| 163 | + } |
|
| 164 | + } elseif ($offset) { |
|
| 165 | + $compare = $this->args['last'] ? '<' : '>'; |
|
| 166 | + $where_params[ $primary_key ] = [$compare, $offset]; |
|
| 167 | + } |
|
| 168 | + return [$query_args, $where_params]; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 174 | + * friendly keys. |
|
| 175 | + * |
|
| 176 | + * @param array $where_args |
|
| 177 | + * @param array $arg_mapping |
|
| 178 | + * @param array $id_fields The fields to convert from global IDs to DB IDs. |
|
| 179 | + * @return array |
|
| 180 | + */ |
|
| 181 | + protected function sanitizeWhereArgsForInputFields(array $where_args, array $arg_mapping, array $id_fields = []): array |
|
| 182 | + { |
|
| 183 | + return $this->getUtilities()->sanitizeWhereArgs($where_args, $arg_mapping, $id_fields); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * This returns the sanitized "search" keywords from where_args |
|
| 189 | + * |
|
| 190 | + * @param array $where_args |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + protected function getSearchKeywords(array $where_args): string |
|
| 194 | + { |
|
| 195 | + $search = ''; |
|
| 196 | + if (! empty($where_args['search'])) { |
|
| 197 | + $search = sanitize_text_field($where_args['search']); |
|
| 198 | + } |
|
| 199 | + return esc_sql($search); |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | add_filter( |
| 31 | 31 | 'graphql_connection_max_query_amount', |
| 32 | - static function ($max_query_amount) { |
|
| 32 | + static function($max_query_amount) { |
|
| 33 | 33 | return self::MAX_QUERY_LIMIT; |
| 34 | 34 | } |
| 35 | 35 | ); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function getUtilities(): Utilities |
| 44 | 44 | { |
| 45 | - if (! $this->utilities instanceof Utilities) { |
|
| 45 | + if ( ! $this->utilities instanceof Utilities) { |
|
| 46 | 46 | $this->utilities = LoaderFactory::getLoader()->getShared(Utilities::class); |
| 47 | 47 | } |
| 48 | 48 | return $this->utilities; |
@@ -156,14 +156,14 @@ discard block |
||
| 156 | 156 | /** |
| 157 | 157 | * Map the orderby inputArgs to the WP_Query |
| 158 | 158 | */ |
| 159 | - if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
| 159 | + if ( ! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
| 160 | 160 | $query_args['order_by'] = []; |
| 161 | 161 | foreach ($this->args['where']['orderby'] as $orderby_input) { |
| 162 | - $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
| 162 | + $query_args['order_by'][$orderby_input['field']] = $orderby_input['order']; |
|
| 163 | 163 | } |
| 164 | 164 | } elseif ($offset) { |
| 165 | 165 | $compare = $this->args['last'] ? '<' : '>'; |
| 166 | - $where_params[ $primary_key ] = [$compare, $offset]; |
|
| 166 | + $where_params[$primary_key] = [$compare, $offset]; |
|
| 167 | 167 | } |
| 168 | 168 | return [$query_args, $where_params]; |
| 169 | 169 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | protected function getSearchKeywords(array $where_args): string |
| 194 | 194 | { |
| 195 | 195 | $search = ''; |
| 196 | - if (! empty($where_args['search'])) { |
|
| 196 | + if ( ! empty($where_args['search'])) { |
|
| 197 | 197 | $search = sanitize_text_field($where_args['search']); |
| 198 | 198 | } |
| 199 | 199 | return esc_sql($search); |
@@ -15,265 +15,265 @@ |
||
| 15 | 15 | class EspressoLegacyAdminAssetManager extends AssetManager |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - const JS_HANDLE_EE_ADMIN = 'ee_admin_js'; |
|
| 18 | + const JS_HANDLE_EE_ADMIN = 'ee_admin_js'; |
|
| 19 | 19 | |
| 20 | - const JS_HANDLE_EE_AJAX_TABLE_SORTING = 'espresso_ajax_table_sorting'; |
|
| 20 | + const JS_HANDLE_EE_AJAX_TABLE_SORTING = 'espresso_ajax_table_sorting'; |
|
| 21 | 21 | |
| 22 | - const JS_HANDLE_EE_DATEPICKER = 'ee-datepicker'; |
|
| 22 | + const JS_HANDLE_EE_DATEPICKER = 'ee-datepicker'; |
|
| 23 | 23 | |
| 24 | - const JS_HANDLE_EE_DIALOG = 'ee-dialog'; |
|
| 24 | + const JS_HANDLE_EE_DIALOG = 'ee-dialog'; |
|
| 25 | 25 | |
| 26 | - const JS_HANDLE_EE_HELP_TOUR = 'ee-help-tour'; |
|
| 26 | + const JS_HANDLE_EE_HELP_TOUR = 'ee-help-tour'; |
|
| 27 | 27 | |
| 28 | - const JS_HANDLE_EE_INJECT_WP = 'ee-inject-wp'; |
|
| 28 | + const JS_HANDLE_EE_INJECT_WP = 'ee-inject-wp'; |
|
| 29 | 29 | |
| 30 | - const JS_HANDLE_GOOGLE_CHARTS = 'google-charts'; |
|
| 30 | + const JS_HANDLE_GOOGLE_CHARTS = 'google-charts'; |
|
| 31 | 31 | |
| 32 | - const JS_HANDLE_MOMENT = 'ee-moment'; |
|
| 32 | + const JS_HANDLE_MOMENT = 'ee-moment'; |
|
| 33 | 33 | |
| 34 | - const JS_HANDLE_MOMENT_CORE = 'ee-moment-core'; |
|
| 34 | + const JS_HANDLE_MOMENT_CORE = 'ee-moment-core'; |
|
| 35 | 35 | |
| 36 | - const JS_HANDLE_PARSE_URI = 'ee-parse-uri'; |
|
| 36 | + const JS_HANDLE_PARSE_URI = 'ee-parse-uri'; |
|
| 37 | 37 | |
| 38 | - const JS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 38 | + const JS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 39 | 39 | |
| 40 | - const JS_HANDLE_EE_SERIALIZE_FULL_ARRAY = 'ee-serialize-full-array'; |
|
| 40 | + const JS_HANDLE_EE_SERIALIZE_FULL_ARRAY = 'ee-serialize-full-array'; |
|
| 41 | 41 | |
| 42 | - const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
| 42 | + const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
| 43 | 43 | |
| 44 | - const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
| 44 | + const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
| 45 | 45 | |
| 46 | - const CSS_HANDLE_EE_ADMIN = 'ee-admin-css'; |
|
| 46 | + const CSS_HANDLE_EE_ADMIN = 'ee-admin-css'; |
|
| 47 | 47 | |
| 48 | - const CSS_HANDLE_EE_ADMIN_MEDIA_MODAL = 'ee-admin-media-modal-css'; |
|
| 48 | + const CSS_HANDLE_EE_ADMIN_MEDIA_MODAL = 'ee-admin-media-modal-css'; |
|
| 49 | 49 | |
| 50 | - const CSS_HANDLE_EE_ADMIN_FILEBIRD = 'ee-admin-filebird-css'; |
|
| 50 | + const CSS_HANDLE_EE_ADMIN_FILEBIRD = 'ee-admin-filebird-css'; |
|
| 51 | 51 | |
| 52 | - const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
| 52 | + const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
| 53 | 53 | |
| 54 | - const CSS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 54 | + const CSS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 55 | 55 | |
| 56 | - const CSS_HANDLE_EE_UI_THEME = 'espresso-ui-theme'; |
|
| 57 | - |
|
| 58 | - const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @inheritDoc |
|
| 63 | - */ |
|
| 64 | - public function addAssets() |
|
| 65 | - { |
|
| 66 | - $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
| 67 | - $this->registerJavascript($joyride); |
|
| 68 | - $this->registerStyleSheets($joyride); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Register javascript assets |
|
| 74 | - * |
|
| 75 | - * @param bool $joyride |
|
| 76 | - */ |
|
| 77 | - private function registerJavascript($joyride = false) |
|
| 78 | - { |
|
| 79 | - $this->addJavascript( |
|
| 80 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 81 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 82 | - [ |
|
| 83 | - JqueryAssetManager::JS_HANDLE_JQUERY, |
|
| 84 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
|
| 85 | - ] |
|
| 86 | - ); |
|
| 87 | - $this->addJavascript( |
|
| 88 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 89 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 90 | - [ |
|
| 91 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 92 | - EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 93 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 94 | - ] |
|
| 95 | - ); |
|
| 96 | - |
|
| 97 | - // script for sorting tables |
|
| 98 | - $this->addJavascript( |
|
| 99 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
|
| 100 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 101 | - [ |
|
| 102 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 103 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
|
| 104 | - ] |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - // script for parsing uri's |
|
| 108 | - $this->addJavascript( |
|
| 109 | - EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 110 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - // and parsing associative serialized form elements |
|
| 114 | - $this->addJavascript( |
|
| 115 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
|
| 116 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 117 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 118 | - |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - // helpers scripts |
|
| 122 | - $this->addJavascript( |
|
| 123 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
|
| 124 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 125 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - $this->addJavascript( |
|
| 129 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
|
| 130 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 131 | - ); |
|
| 132 | - |
|
| 133 | - $this->addJavascript( |
|
| 134 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 135 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 136 | - [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
|
| 137 | - ); |
|
| 138 | - |
|
| 139 | - $this->addJavascript( |
|
| 140 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
|
| 141 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 142 | - [ |
|
| 143 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
|
| 144 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 145 | - ] |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - // google charts |
|
| 149 | - $this->addJavascript( |
|
| 150 | - EspressoLegacyAdminAssetManager::JS_HANDLE_GOOGLE_CHARTS, |
|
| 151 | - 'https://www.gstatic.com/charts/loader.js' |
|
| 152 | - ); |
|
| 153 | - |
|
| 154 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 155 | - // Note: the intention of this script is to only do TARGETED injections. |
|
| 156 | - //ie: only injecting on certain script calls. |
|
| 157 | - $this->addJavascript( |
|
| 158 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
|
| 159 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 160 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - $this->loadQtipJs(); |
|
| 164 | - |
|
| 165 | - // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
| 166 | - // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 167 | - if (! $joyride) { |
|
| 168 | - return; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $this->addJavascript( |
|
| 172 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 173 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 174 | - [], |
|
| 175 | - true, |
|
| 176 | - '2.1' |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - // wanna go for a joyride? |
|
| 180 | - $this->addJavascript( |
|
| 181 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 182 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 183 | - [ |
|
| 184 | - JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
| 185 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 186 | - ], |
|
| 187 | - true, |
|
| 188 | - '2.1' |
|
| 189 | - )->setEnqueueImmediately(); |
|
| 190 | - |
|
| 191 | - $this->addJavascript( |
|
| 192 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
|
| 193 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 194 | - [ |
|
| 195 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 196 | - ], |
|
| 197 | - true, |
|
| 198 | - '2.1' |
|
| 199 | - )->setEnqueueImmediately(); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Register CSS assets. |
|
| 205 | - * |
|
| 206 | - * @param bool $joyride |
|
| 207 | - */ |
|
| 208 | - private function registerStyleSheets($joyride = false) |
|
| 209 | - { |
|
| 210 | - $this->addStylesheet( |
|
| 211 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
|
| 212 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - $this->addStylesheet( |
|
| 216 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
|
| 217 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - $this->addStylesheet( |
|
| 221 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
|
| 222 | - EE_ADMIN_URL . 'assets/ee-admin-page.css', |
|
| 223 | - ['espresso_admin_base'] |
|
| 224 | - )->setEnqueueImmediately(); |
|
| 225 | - |
|
| 226 | - if ( |
|
| 227 | - apply_filters( |
|
| 228 | - 'FHEE__EventEspresso_core_domain_services_assets_EspressoLegacyAdminAssetManager__registerStyleSheets__load_media_modal_css', |
|
| 229 | - ! class_exists('FileBird\Plugin') |
|
| 230 | - ) |
|
| 231 | - ) { |
|
| 232 | - $this->addStylesheet( |
|
| 233 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN_MEDIA_MODAL, |
|
| 234 | - EE_ADMIN_URL . 'assets/ee-admin-media-modal.css', |
|
| 235 | - [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN] |
|
| 236 | - )->setEnqueueImmediately(); |
|
| 237 | - } else { |
|
| 238 | - $this->addStylesheet( |
|
| 239 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN_FILEBIRD, |
|
| 240 | - EE_ADMIN_URL . 'assets/ee-admin-media-modal-reset.css', |
|
| 241 | - [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN] |
|
| 242 | - )->setEnqueueImmediately(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if (! $joyride) { |
|
| 246 | - return; |
|
| 247 | - } |
|
| 248 | - // joyride style |
|
| 249 | - $this->addStylesheet( |
|
| 250 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
| 251 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 252 | - [], |
|
| 253 | - 'all', |
|
| 254 | - '2.1' |
|
| 255 | - ); |
|
| 256 | - |
|
| 257 | - $this->addStylesheet( |
|
| 258 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
| 259 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 260 | - [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE] |
|
| 261 | - )->setEnqueueImmediately(); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * registers assets for cleaning your ears |
|
| 267 | - */ |
|
| 268 | - public function loadQtipJs() |
|
| 269 | - { |
|
| 270 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 271 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 272 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 273 | - $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 274 | - if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 275 | - $qtip_loader->register_and_enqueue(); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 56 | + const CSS_HANDLE_EE_UI_THEME = 'espresso-ui-theme'; |
|
| 57 | + |
|
| 58 | + const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @inheritDoc |
|
| 63 | + */ |
|
| 64 | + public function addAssets() |
|
| 65 | + { |
|
| 66 | + $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
| 67 | + $this->registerJavascript($joyride); |
|
| 68 | + $this->registerStyleSheets($joyride); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Register javascript assets |
|
| 74 | + * |
|
| 75 | + * @param bool $joyride |
|
| 76 | + */ |
|
| 77 | + private function registerJavascript($joyride = false) |
|
| 78 | + { |
|
| 79 | + $this->addJavascript( |
|
| 80 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 81 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 82 | + [ |
|
| 83 | + JqueryAssetManager::JS_HANDLE_JQUERY, |
|
| 84 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
|
| 85 | + ] |
|
| 86 | + ); |
|
| 87 | + $this->addJavascript( |
|
| 88 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 89 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 90 | + [ |
|
| 91 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 92 | + EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 93 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 94 | + ] |
|
| 95 | + ); |
|
| 96 | + |
|
| 97 | + // script for sorting tables |
|
| 98 | + $this->addJavascript( |
|
| 99 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
|
| 100 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 101 | + [ |
|
| 102 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 103 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
|
| 104 | + ] |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + // script for parsing uri's |
|
| 108 | + $this->addJavascript( |
|
| 109 | + EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 110 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + // and parsing associative serialized form elements |
|
| 114 | + $this->addJavascript( |
|
| 115 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
|
| 116 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 117 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 118 | + |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + // helpers scripts |
|
| 122 | + $this->addJavascript( |
|
| 123 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
|
| 124 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 125 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + $this->addJavascript( |
|
| 129 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
|
| 130 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 131 | + ); |
|
| 132 | + |
|
| 133 | + $this->addJavascript( |
|
| 134 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 135 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 136 | + [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
|
| 137 | + ); |
|
| 138 | + |
|
| 139 | + $this->addJavascript( |
|
| 140 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
|
| 141 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 142 | + [ |
|
| 143 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
|
| 144 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 145 | + ] |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + // google charts |
|
| 149 | + $this->addJavascript( |
|
| 150 | + EspressoLegacyAdminAssetManager::JS_HANDLE_GOOGLE_CHARTS, |
|
| 151 | + 'https://www.gstatic.com/charts/loader.js' |
|
| 152 | + ); |
|
| 153 | + |
|
| 154 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 155 | + // Note: the intention of this script is to only do TARGETED injections. |
|
| 156 | + //ie: only injecting on certain script calls. |
|
| 157 | + $this->addJavascript( |
|
| 158 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
|
| 159 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 160 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + $this->loadQtipJs(); |
|
| 164 | + |
|
| 165 | + // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
| 166 | + // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 167 | + if (! $joyride) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $this->addJavascript( |
|
| 172 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 173 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 174 | + [], |
|
| 175 | + true, |
|
| 176 | + '2.1' |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + // wanna go for a joyride? |
|
| 180 | + $this->addJavascript( |
|
| 181 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 182 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 183 | + [ |
|
| 184 | + JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
| 185 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 186 | + ], |
|
| 187 | + true, |
|
| 188 | + '2.1' |
|
| 189 | + )->setEnqueueImmediately(); |
|
| 190 | + |
|
| 191 | + $this->addJavascript( |
|
| 192 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
|
| 193 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 194 | + [ |
|
| 195 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 196 | + ], |
|
| 197 | + true, |
|
| 198 | + '2.1' |
|
| 199 | + )->setEnqueueImmediately(); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Register CSS assets. |
|
| 205 | + * |
|
| 206 | + * @param bool $joyride |
|
| 207 | + */ |
|
| 208 | + private function registerStyleSheets($joyride = false) |
|
| 209 | + { |
|
| 210 | + $this->addStylesheet( |
|
| 211 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
|
| 212 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + $this->addStylesheet( |
|
| 216 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
|
| 217 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + $this->addStylesheet( |
|
| 221 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
|
| 222 | + EE_ADMIN_URL . 'assets/ee-admin-page.css', |
|
| 223 | + ['espresso_admin_base'] |
|
| 224 | + )->setEnqueueImmediately(); |
|
| 225 | + |
|
| 226 | + if ( |
|
| 227 | + apply_filters( |
|
| 228 | + 'FHEE__EventEspresso_core_domain_services_assets_EspressoLegacyAdminAssetManager__registerStyleSheets__load_media_modal_css', |
|
| 229 | + ! class_exists('FileBird\Plugin') |
|
| 230 | + ) |
|
| 231 | + ) { |
|
| 232 | + $this->addStylesheet( |
|
| 233 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN_MEDIA_MODAL, |
|
| 234 | + EE_ADMIN_URL . 'assets/ee-admin-media-modal.css', |
|
| 235 | + [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN] |
|
| 236 | + )->setEnqueueImmediately(); |
|
| 237 | + } else { |
|
| 238 | + $this->addStylesheet( |
|
| 239 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN_FILEBIRD, |
|
| 240 | + EE_ADMIN_URL . 'assets/ee-admin-media-modal-reset.css', |
|
| 241 | + [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN] |
|
| 242 | + )->setEnqueueImmediately(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if (! $joyride) { |
|
| 246 | + return; |
|
| 247 | + } |
|
| 248 | + // joyride style |
|
| 249 | + $this->addStylesheet( |
|
| 250 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
| 251 | + EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 252 | + [], |
|
| 253 | + 'all', |
|
| 254 | + '2.1' |
|
| 255 | + ); |
|
| 256 | + |
|
| 257 | + $this->addStylesheet( |
|
| 258 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
| 259 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 260 | + [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE] |
|
| 261 | + )->setEnqueueImmediately(); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * registers assets for cleaning your ears |
|
| 267 | + */ |
|
| 268 | + public function loadQtipJs() |
|
| 269 | + { |
|
| 270 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 271 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 272 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 273 | + $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 274 | + if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 275 | + $qtip_loader->register_and_enqueue(); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | 279 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | $this->addJavascript( |
| 80 | 80 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
| 81 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 81 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
| 82 | 82 | [ |
| 83 | 83 | JqueryAssetManager::JS_HANDLE_JQUERY, |
| 84 | 84 | JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | ); |
| 87 | 87 | $this->addJavascript( |
| 88 | 88 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
| 89 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 89 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
| 90 | 90 | [ |
| 91 | 91 | CoreAssetManager::JS_HANDLE_CORE, |
| 92 | 92 | EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | // script for sorting tables |
| 98 | 98 | $this->addJavascript( |
| 99 | 99 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
| 100 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 100 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
| 101 | 101 | [ |
| 102 | 102 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
| 103 | 103 | JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | // script for parsing uri's |
| 108 | 108 | $this->addJavascript( |
| 109 | 109 | EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
| 110 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 110 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js' |
|
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | 113 | // and parsing associative serialized form elements |
| 114 | 114 | $this->addJavascript( |
| 115 | 115 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
| 116 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 116 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
| 117 | 117 | [JqueryAssetManager::JS_HANDLE_JQUERY] |
| 118 | 118 | |
| 119 | 119 | ); |
@@ -121,24 +121,24 @@ discard block |
||
| 121 | 121 | // helpers scripts |
| 122 | 122 | $this->addJavascript( |
| 123 | 123 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
| 124 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 124 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
| 125 | 125 | [JqueryAssetManager::JS_HANDLE_JQUERY] |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | 128 | $this->addJavascript( |
| 129 | 129 | EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
| 130 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 130 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js' |
|
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | $this->addJavascript( |
| 134 | 134 | EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
| 135 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 135 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
| 136 | 136 | [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | 139 | $this->addJavascript( |
| 140 | 140 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
| 141 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 141 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
| 142 | 142 | [ |
| 143 | 143 | JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
| 144 | 144 | EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | //ie: only injecting on certain script calls. |
| 157 | 157 | $this->addJavascript( |
| 158 | 158 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
| 159 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 159 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
| 160 | 160 | [JqueryAssetManager::JS_HANDLE_JQUERY] |
| 161 | 161 | ); |
| 162 | 162 | |
@@ -164,13 +164,13 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
| 166 | 166 | // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
| 167 | - if (! $joyride) { |
|
| 167 | + if ( ! $joyride) { |
|
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | $this->addJavascript( |
| 172 | 172 | EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
| 173 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 173 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
| 174 | 174 | [], |
| 175 | 175 | true, |
| 176 | 176 | '2.1' |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | // wanna go for a joyride? |
| 180 | 180 | $this->addJavascript( |
| 181 | 181 | EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
| 182 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 182 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 183 | 183 | [ |
| 184 | 184 | JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
| 185 | 185 | EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | $this->addJavascript( |
| 192 | 192 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
| 193 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 193 | + EE_ADMIN_URL.'assets/ee-help-tour.js', |
|
| 194 | 194 | [ |
| 195 | 195 | EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
| 196 | 196 | ], |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $this->addStylesheet( |
| 211 | 211 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
| 212 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 212 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 213 | 213 | ); |
| 214 | 214 | |
| 215 | 215 | $this->addStylesheet( |
| 216 | 216 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
| 217 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 217 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css' |
|
| 218 | 218 | ); |
| 219 | 219 | |
| 220 | 220 | $this->addStylesheet( |
| 221 | 221 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
| 222 | - EE_ADMIN_URL . 'assets/ee-admin-page.css', |
|
| 222 | + EE_ADMIN_URL.'assets/ee-admin-page.css', |
|
| 223 | 223 | ['espresso_admin_base'] |
| 224 | 224 | )->setEnqueueImmediately(); |
| 225 | 225 | |
@@ -231,24 +231,24 @@ discard block |
||
| 231 | 231 | ) { |
| 232 | 232 | $this->addStylesheet( |
| 233 | 233 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN_MEDIA_MODAL, |
| 234 | - EE_ADMIN_URL . 'assets/ee-admin-media-modal.css', |
|
| 234 | + EE_ADMIN_URL.'assets/ee-admin-media-modal.css', |
|
| 235 | 235 | [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN] |
| 236 | 236 | )->setEnqueueImmediately(); |
| 237 | 237 | } else { |
| 238 | 238 | $this->addStylesheet( |
| 239 | 239 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN_FILEBIRD, |
| 240 | - EE_ADMIN_URL . 'assets/ee-admin-media-modal-reset.css', |
|
| 240 | + EE_ADMIN_URL.'assets/ee-admin-media-modal-reset.css', |
|
| 241 | 241 | [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN] |
| 242 | 242 | )->setEnqueueImmediately(); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if (! $joyride) { |
|
| 245 | + if ( ! $joyride) { |
|
| 246 | 246 | return; |
| 247 | 247 | } |
| 248 | 248 | // joyride style |
| 249 | 249 | $this->addStylesheet( |
| 250 | 250 | EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
| 251 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 251 | + EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', |
|
| 252 | 252 | [], |
| 253 | 253 | 'all', |
| 254 | 254 | '2.1' |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | $this->addStylesheet( |
| 258 | 258 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
| 259 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 259 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 260 | 260 | [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE] |
| 261 | 261 | )->setEnqueueImmediately(); |
| 262 | 262 | } |
@@ -17,134 +17,134 @@ |
||
| 17 | 17 | |
| 18 | 18 | class UpdateTransactionsWithPayment extends CronJob |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 22 | - * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 23 | - */ |
|
| 24 | - public const RESCHEDULE_TIMEOUT = 605; |
|
| 20 | + /** |
|
| 21 | + * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 22 | + * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 23 | + */ |
|
| 24 | + public const RESCHEDULE_TIMEOUT = 605; |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * array of TXN IDs and the payment |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected array $update_transactions_with_payment = []; |
|
| 27 | + /** |
|
| 28 | + * array of TXN IDs and the payment |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected array $update_transactions_with_payment = []; |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - public function setHooks(): void |
|
| 36 | - { |
|
| 37 | - add_action( |
|
| 38 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 39 | - [$this, 'setupUpdateForTransactionWithPayment'], |
|
| 40 | - 10, |
|
| 41 | - 2 |
|
| 42 | - ); |
|
| 43 | - } |
|
| 35 | + public function setHooks(): void |
|
| 36 | + { |
|
| 37 | + add_action( |
|
| 38 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 39 | + [$this, 'setupUpdateForTransactionWithPayment'], |
|
| 40 | + 10, |
|
| 41 | + 2 |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * schedule_update_transaction_with_payment |
|
| 48 | - * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 49 | - * require updating due to recently received payments |
|
| 50 | - * |
|
| 51 | - * @param int $timestamp |
|
| 52 | - * @param int $TXN_ID |
|
| 53 | - * @param int $PAY_ID |
|
| 54 | - */ |
|
| 55 | - public static function scheduleUpdateTransactionWithPayment( |
|
| 56 | - int $timestamp, |
|
| 57 | - int $TXN_ID, |
|
| 58 | - int $PAY_ID |
|
| 59 | - ): void { |
|
| 60 | - // validate $TXN_ID and $timestamp |
|
| 61 | - $TXN_ID = absint($TXN_ID); |
|
| 62 | - $timestamp = absint($timestamp); |
|
| 63 | - if ($TXN_ID && $timestamp) { |
|
| 64 | - wp_schedule_single_event( |
|
| 65 | - $timestamp, |
|
| 66 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 67 | - [$TXN_ID, $PAY_ID] |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - } |
|
| 46 | + /** |
|
| 47 | + * schedule_update_transaction_with_payment |
|
| 48 | + * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 49 | + * require updating due to recently received payments |
|
| 50 | + * |
|
| 51 | + * @param int $timestamp |
|
| 52 | + * @param int $TXN_ID |
|
| 53 | + * @param int $PAY_ID |
|
| 54 | + */ |
|
| 55 | + public static function scheduleUpdateTransactionWithPayment( |
|
| 56 | + int $timestamp, |
|
| 57 | + int $TXN_ID, |
|
| 58 | + int $PAY_ID |
|
| 59 | + ): void { |
|
| 60 | + // validate $TXN_ID and $timestamp |
|
| 61 | + $TXN_ID = absint($TXN_ID); |
|
| 62 | + $timestamp = absint($timestamp); |
|
| 63 | + if ($TXN_ID && $timestamp) { |
|
| 64 | + wp_schedule_single_event( |
|
| 65 | + $timestamp, |
|
| 66 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 67 | + [$TXN_ID, $PAY_ID] |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * setup_update_for_transaction_with_payment |
|
| 75 | - * this is the callback for the action hook: |
|
| 76 | - * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 77 | - * which is set up by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 78 | - * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 79 | - * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 80 | - * 'shutdown' which will actually handle the processing of any |
|
| 81 | - * transactions requiring updating, because doing so now would be too early |
|
| 82 | - * and the required resources may not be available |
|
| 83 | - * |
|
| 84 | - * @param int $TXN_ID |
|
| 85 | - * @param int $PAY_ID |
|
| 86 | - */ |
|
| 87 | - public function setupUpdateForTransactionWithPayment(int $TXN_ID = 0, int $PAY_ID = 0): void |
|
| 88 | - { |
|
| 89 | - if (absint($TXN_ID)) { |
|
| 90 | - $this->update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 91 | - add_action( |
|
| 92 | - 'shutdown', |
|
| 93 | - [$this, 'updateTransactionWithPayment'], |
|
| 94 | - 5 |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 73 | + /** |
|
| 74 | + * setup_update_for_transaction_with_payment |
|
| 75 | + * this is the callback for the action hook: |
|
| 76 | + * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 77 | + * which is set up by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 78 | + * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 79 | + * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 80 | + * 'shutdown' which will actually handle the processing of any |
|
| 81 | + * transactions requiring updating, because doing so now would be too early |
|
| 82 | + * and the required resources may not be available |
|
| 83 | + * |
|
| 84 | + * @param int $TXN_ID |
|
| 85 | + * @param int $PAY_ID |
|
| 86 | + */ |
|
| 87 | + public function setupUpdateForTransactionWithPayment(int $TXN_ID = 0, int $PAY_ID = 0): void |
|
| 88 | + { |
|
| 89 | + if (absint($TXN_ID)) { |
|
| 90 | + $this->update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 91 | + add_action( |
|
| 92 | + 'shutdown', |
|
| 93 | + [$this, 'updateTransactionWithPayment'], |
|
| 94 | + 5 |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * update_transaction_with_payment |
|
| 102 | - * loops through the self::$_abandoned_transactions array |
|
| 103 | - * and attempts to finalize any TXNs that have not been completed |
|
| 104 | - * but have had their sessions expired, most likely due to a user not |
|
| 105 | - * returning from an off-site payment gateway |
|
| 106 | - * |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws DomainException |
|
| 109 | - * @throws ReflectionException |
|
| 110 | - * @throws RuntimeException |
|
| 111 | - */ |
|
| 112 | - public function updateTransactionWithPayment(): void |
|
| 113 | - { |
|
| 114 | - if ( |
|
| 115 | - // are there any TXNs that need cleaning up ? |
|
| 116 | - empty($this->update_transactions_with_payment) |
|
| 117 | - // reschedule the cron if we can't hit the db right now |
|
| 118 | - || CronUtilities::rescheduleCronForTransactions( |
|
| 119 | - [UpdateTransactionsWithPayment::class, 'scheduleUpdateTransactionWithPayment'], |
|
| 120 | - $this->update_transactions_with_payment |
|
| 121 | - ) |
|
| 122 | - ) { |
|
| 123 | - return; |
|
| 124 | - } |
|
| 125 | - /** @var EE_Payment_Processor $payment_processor */ |
|
| 126 | - $payment_processor = $this->loader->getShared(EE_Payment_Processor::class); |
|
| 127 | - // set revisit flag for payment processor |
|
| 128 | - $payment_processor->set_revisit(); |
|
| 129 | - foreach ($this->update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 130 | - // reschedule the cron if we can't hit the db right now |
|
| 131 | - if (DbStatus::isOffline()) { |
|
| 132 | - // reset cron job for updating the TXN |
|
| 133 | - UpdateTransactionsWithPayment::scheduleUpdateTransactionWithPayment( |
|
| 134 | - time() + UpdateTransactionsWithPayment::RESCHEDULE_TIMEOUT, |
|
| 135 | - $TXN_ID, |
|
| 136 | - $PAY_ID |
|
| 137 | - ); |
|
| 138 | - continue; |
|
| 139 | - } |
|
| 140 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 141 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 142 | - // verify transaction |
|
| 143 | - if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 144 | - // now try to update the TXN with any payments |
|
| 145 | - $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 146 | - } |
|
| 147 | - unset($this->update_transactions_with_payment[ $TXN_ID ]); |
|
| 148 | - } |
|
| 149 | - } |
|
| 100 | + /** |
|
| 101 | + * update_transaction_with_payment |
|
| 102 | + * loops through the self::$_abandoned_transactions array |
|
| 103 | + * and attempts to finalize any TXNs that have not been completed |
|
| 104 | + * but have had their sessions expired, most likely due to a user not |
|
| 105 | + * returning from an off-site payment gateway |
|
| 106 | + * |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws DomainException |
|
| 109 | + * @throws ReflectionException |
|
| 110 | + * @throws RuntimeException |
|
| 111 | + */ |
|
| 112 | + public function updateTransactionWithPayment(): void |
|
| 113 | + { |
|
| 114 | + if ( |
|
| 115 | + // are there any TXNs that need cleaning up ? |
|
| 116 | + empty($this->update_transactions_with_payment) |
|
| 117 | + // reschedule the cron if we can't hit the db right now |
|
| 118 | + || CronUtilities::rescheduleCronForTransactions( |
|
| 119 | + [UpdateTransactionsWithPayment::class, 'scheduleUpdateTransactionWithPayment'], |
|
| 120 | + $this->update_transactions_with_payment |
|
| 121 | + ) |
|
| 122 | + ) { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | + /** @var EE_Payment_Processor $payment_processor */ |
|
| 126 | + $payment_processor = $this->loader->getShared(EE_Payment_Processor::class); |
|
| 127 | + // set revisit flag for payment processor |
|
| 128 | + $payment_processor->set_revisit(); |
|
| 129 | + foreach ($this->update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 130 | + // reschedule the cron if we can't hit the db right now |
|
| 131 | + if (DbStatus::isOffline()) { |
|
| 132 | + // reset cron job for updating the TXN |
|
| 133 | + UpdateTransactionsWithPayment::scheduleUpdateTransactionWithPayment( |
|
| 134 | + time() + UpdateTransactionsWithPayment::RESCHEDULE_TIMEOUT, |
|
| 135 | + $TXN_ID, |
|
| 136 | + $PAY_ID |
|
| 137 | + ); |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 140 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 141 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 142 | + // verify transaction |
|
| 143 | + if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 144 | + // now try to update the TXN with any payments |
|
| 145 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 146 | + } |
|
| 147 | + unset($this->update_transactions_with_payment[ $TXN_ID ]); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | public function setupUpdateForTransactionWithPayment(int $TXN_ID = 0, int $PAY_ID = 0): void |
| 88 | 88 | { |
| 89 | 89 | if (absint($TXN_ID)) { |
| 90 | - $this->update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
| 90 | + $this->update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
| 91 | 91 | add_action( |
| 92 | 92 | 'shutdown', |
| 93 | 93 | [$this, 'updateTransactionWithPayment'], |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | // now try to update the TXN with any payments |
| 145 | 145 | $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
| 146 | 146 | } |
| 147 | - unset($this->update_transactions_with_payment[ $TXN_ID ]); |
|
| 147 | + unset($this->update_transactions_with_payment[$TXN_ID]); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -18,54 +18,54 @@ |
||
| 18 | 18 | |
| 19 | 19 | class GarbageCollection extends CronJob |
| 20 | 20 | { |
| 21 | - public function setHooks(): void |
|
| 22 | - { |
|
| 23 | - add_action( |
|
| 24 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 25 | - [$this, 'cleanUpJunkTransactions'] |
|
| 26 | - ); |
|
| 27 | - add_action( |
|
| 28 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 29 | - [$this, 'cleanUpOldGatewayLogs'] |
|
| 30 | - ); |
|
| 31 | - } |
|
| 21 | + public function setHooks(): void |
|
| 22 | + { |
|
| 23 | + add_action( |
|
| 24 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 25 | + [$this, 'cleanUpJunkTransactions'] |
|
| 26 | + ); |
|
| 27 | + add_action( |
|
| 28 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 29 | + [$this, 'cleanUpOldGatewayLogs'] |
|
| 30 | + ); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
| 36 | - * which is set up during activation to run on an hourly cron |
|
| 37 | - * |
|
| 38 | - * @throws EE_Error |
|
| 39 | - * @throws DomainException |
|
| 40 | - * @throws ReflectionException |
|
| 41 | - */ |
|
| 42 | - public function cleanUpJunkTransactions(): void |
|
| 43 | - { |
|
| 44 | - if (DbStatus::isOnline()) { |
|
| 45 | - EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
| 46 | - EEM_Transaction::instance()->delete_junk_transactions(); |
|
| 47 | - EEM_Registration::instance()->delete_registrations_with_no_transaction(); |
|
| 48 | - EEM_Line_Item::instance()->delete_line_items_with_no_transaction(); |
|
| 49 | - } |
|
| 50 | - } |
|
| 34 | + /** |
|
| 35 | + * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
| 36 | + * which is set up during activation to run on an hourly cron |
|
| 37 | + * |
|
| 38 | + * @throws EE_Error |
|
| 39 | + * @throws DomainException |
|
| 40 | + * @throws ReflectionException |
|
| 41 | + */ |
|
| 42 | + public function cleanUpJunkTransactions(): void |
|
| 43 | + { |
|
| 44 | + if (DbStatus::isOnline()) { |
|
| 45 | + EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
| 46 | + EEM_Transaction::instance()->delete_junk_transactions(); |
|
| 47 | + EEM_Registration::instance()->delete_registrations_with_no_transaction(); |
|
| 48 | + EEM_Line_Item::instance()->delete_line_items_with_no_transaction(); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 55 | - * |
|
| 56 | - * @throws EE_Error |
|
| 57 | - * @throws ReflectionException |
|
| 58 | - * @throws Exception |
|
| 59 | - */ |
|
| 60 | - public function cleanUpOldGatewayLogs(): void |
|
| 61 | - { |
|
| 62 | - if (DbStatus::isOnline()) { |
|
| 63 | - $reg_config = $this->loader->getShared(EE_Registration_Config::class); |
|
| 64 | - $time_diff_for_comparison = apply_filters( |
|
| 65 | - 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 66 | - '-' . $reg_config->gateway_log_lifespan |
|
| 67 | - ); |
|
| 68 | - EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 69 | - } |
|
| 70 | - } |
|
| 53 | + /** |
|
| 54 | + * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 55 | + * |
|
| 56 | + * @throws EE_Error |
|
| 57 | + * @throws ReflectionException |
|
| 58 | + * @throws Exception |
|
| 59 | + */ |
|
| 60 | + public function cleanUpOldGatewayLogs(): void |
|
| 61 | + { |
|
| 62 | + if (DbStatus::isOnline()) { |
|
| 63 | + $reg_config = $this->loader->getShared(EE_Registration_Config::class); |
|
| 64 | + $time_diff_for_comparison = apply_filters( |
|
| 65 | + 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 66 | + '-' . $reg_config->gateway_log_lifespan |
|
| 67 | + ); |
|
| 68 | + EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | $reg_config = $this->loader->getShared(EE_Registration_Config::class); |
| 64 | 64 | $time_diff_for_comparison = apply_filters( |
| 65 | 65 | 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
| 66 | - '-' . $reg_config->gateway_log_lifespan |
|
| 66 | + '-'.$reg_config->gateway_log_lifespan |
|
| 67 | 67 | ); |
| 68 | 68 | EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
| 69 | 69 | } |
@@ -17,252 +17,252 @@ |
||
| 17 | 17 | |
| 18 | 18 | class ExpiredTransactionCheck extends CronJob |
| 19 | 19 | { |
| 20 | - private ?EE_Payment_Processor $payment_processor = null; |
|
| 21 | - |
|
| 22 | - private ?EE_Transaction_Processor $transaction_processor = null; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * array of TXN IDs |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected array $expired_transactions = []; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - private function loadTransactionProcessor() |
|
| 33 | - { |
|
| 34 | - $this->transaction_processor = $this->loader->getShared(EE_Transaction_Processor::class); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - private function loadPaymentProcessor() |
|
| 39 | - { |
|
| 40 | - $this->payment_processor = $this->loader->getShared(EE_Payment_Processor::class); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - public function setHooks(): void |
|
| 45 | - { |
|
| 46 | - add_action( |
|
| 47 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 48 | - [$this, 'expiredTransactionCheck'] |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * schedule_expired_transaction_check |
|
| 55 | - * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
| 56 | - * |
|
| 57 | - * @param int $timestamp |
|
| 58 | - * @param int $TXN_ID |
|
| 59 | - */ |
|
| 60 | - public static function scheduleExpiredTransactionCheck( |
|
| 61 | - int $timestamp, |
|
| 62 | - int $TXN_ID |
|
| 63 | - ): void { |
|
| 64 | - // validate $TXN_ID and $timestamp |
|
| 65 | - $TXN_ID = absint($TXN_ID); |
|
| 66 | - $timestamp = absint($timestamp); |
|
| 67 | - if ($TXN_ID && $timestamp) { |
|
| 68 | - wp_schedule_single_event( |
|
| 69 | - $timestamp, |
|
| 70 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 71 | - [$TXN_ID] |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * this is the callback for the action hook: |
|
| 79 | - * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
| 80 | - * which is utilized by wp_schedule_single_event() |
|
| 81 | - * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
| 82 | - * The passed TXN_ID gets added to an array, and then the |
|
| 83 | - * process_expired_transactions() function is hooked into |
|
| 84 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 85 | - * processing of any failed transactions, because doing so now would be |
|
| 86 | - * too early and the required resources may not be available |
|
| 87 | - * |
|
| 88 | - * @param int $TXN_ID |
|
| 89 | - */ |
|
| 90 | - public function expiredTransactionCheck(int $TXN_ID = 0): void |
|
| 91 | - { |
|
| 92 | - if (absint($TXN_ID)) { |
|
| 93 | - $this->expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 94 | - add_action( |
|
| 95 | - 'shutdown', |
|
| 96 | - [$this, 'processExpiredTransactions'], |
|
| 97 | - 5 |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * loops through the $this->expired_transactions array and processes any failed TXNs |
|
| 105 | - * |
|
| 106 | - * @throws EE_Error |
|
| 107 | - * @throws ReflectionException |
|
| 108 | - * @throws DomainException |
|
| 109 | - * @throws RuntimeException |
|
| 110 | - */ |
|
| 111 | - public function processExpiredTransactions(): void |
|
| 112 | - { |
|
| 113 | - if ( |
|
| 114 | - // are there any TXNs that need cleaning up ? |
|
| 115 | - empty($this->expired_transactions) |
|
| 116 | - // reschedule the cron if we can't hit the db right now |
|
| 117 | - || CronUtilities::rescheduleCronForTransactions( |
|
| 118 | - [ExpiredTransactionCheck::class, 'scheduleExpiredTransactionCheck'], |
|
| 119 | - $this->expired_transactions |
|
| 120 | - ) |
|
| 121 | - ) { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 124 | - $this->loadTransactionProcessor(); |
|
| 125 | - // set revisit flag for txn processor |
|
| 126 | - $this->transaction_processor->set_revisit(); |
|
| 127 | - foreach ($this->expired_transactions as $TXN_ID) { |
|
| 128 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 129 | - // verify transaction and whether it is failed or not |
|
| 130 | - if ($transaction instanceof EE_Transaction) { |
|
| 131 | - switch ($transaction->status_ID()) { |
|
| 132 | - |
|
| 133 | - case EEM_Transaction::complete_status_code: |
|
| 134 | - $this->processCompletedTransaction($transaction); |
|
| 135 | - break; |
|
| 136 | - |
|
| 137 | - case EEM_Transaction::overpaid_status_code: |
|
| 138 | - $this->processOverpaidTransaction($transaction); |
|
| 139 | - break; |
|
| 140 | - |
|
| 141 | - case EEM_Transaction::incomplete_status_code: |
|
| 142 | - $this->processIncompletedTransaction($transaction); |
|
| 143 | - break; |
|
| 144 | - |
|
| 145 | - case EEM_Transaction::abandoned_status_code: |
|
| 146 | - $this->processAbandonedTransaction($transaction); |
|
| 147 | - break; |
|
| 148 | - |
|
| 149 | - case EEM_Transaction::failed_status_code: |
|
| 150 | - $this->processFailedTransaction($transaction); |
|
| 151 | - break; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - unset($this->expired_transactions[ $TXN_ID ]); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param EE_Transaction $transaction |
|
| 161 | - * @return void |
|
| 162 | - * @throws EE_Error |
|
| 163 | - * @throws ReflectionException |
|
| 164 | - */ |
|
| 165 | - private function processCompletedTransaction(EE_Transaction $transaction) |
|
| 166 | - { |
|
| 167 | - // Don't update the transaction/registrations if the Primary Registration is Not Approved. |
|
| 168 | - $primary_registration = $transaction->primary_registration(); |
|
| 169 | - if ( |
|
| 170 | - $primary_registration instanceof EE_Registration |
|
| 171 | - && $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 172 | - ) { |
|
| 173 | - $this->transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 174 | - $transaction, |
|
| 175 | - $transaction->last_payment() |
|
| 176 | - ); |
|
| 177 | - do_action( |
|
| 178 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
| 179 | - $transaction |
|
| 180 | - ); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @param EE_Transaction $transaction |
|
| 187 | - * @return void |
|
| 188 | - */ |
|
| 189 | - private function processOverpaidTransaction(EE_Transaction $transaction) |
|
| 190 | - { |
|
| 191 | - do_action( |
|
| 192 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
| 193 | - $transaction |
|
| 194 | - ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * @param EE_Transaction $transaction |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - private function processIncompletedTransaction(EE_Transaction $transaction) |
|
| 203 | - { |
|
| 204 | - do_action( |
|
| 205 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 206 | - $transaction |
|
| 207 | - ); |
|
| 208 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @param EE_Transaction $transaction |
|
| 214 | - * @return void |
|
| 215 | - * @throws EE_Error |
|
| 216 | - * @throws ReflectionException |
|
| 217 | - */ |
|
| 218 | - private function processAbandonedTransaction(EE_Transaction $transaction) |
|
| 219 | - { |
|
| 220 | - // run hook before updating transaction, primarily so |
|
| 221 | - // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
| 222 | - do_action( |
|
| 223 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 224 | - $transaction |
|
| 225 | - ); |
|
| 226 | - // don't finalize the TXN if it has already been completed |
|
| 227 | - if ($transaction->all_reg_steps_completed() !== true) { |
|
| 228 | - $this->loadPaymentProcessor(); |
|
| 229 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 230 | - $this->payment_processor->update_txn_based_on_payment( |
|
| 231 | - $transaction, |
|
| 232 | - $transaction->last_payment(), |
|
| 233 | - true, |
|
| 234 | - true |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param EE_Transaction $transaction |
|
| 242 | - * @return void |
|
| 243 | - */ |
|
| 244 | - private function processFailedTransaction(EE_Transaction $transaction) |
|
| 245 | - { |
|
| 246 | - do_action( |
|
| 247 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 248 | - $transaction |
|
| 249 | - ); |
|
| 250 | - // todo : |
|
| 251 | - // perform garbage collection here and remove clean_out_junk_transactions() |
|
| 252 | - // $registrations = $transaction->registrations(); |
|
| 253 | - // if (! empty($registrations)) { |
|
| 254 | - // foreach ($registrations as $registration) { |
|
| 255 | - // if ($registration instanceof EE_Registration) { |
|
| 256 | - // $delete_registration = true; |
|
| 257 | - // if ($registration->attendee() instanceof EE_Attendee) { |
|
| 258 | - // $delete_registration = false; |
|
| 259 | - // } |
|
| 260 | - // if ($delete_registration) { |
|
| 261 | - // $registration->delete_permanently(); |
|
| 262 | - // $registration->delete_related_permanently(); |
|
| 263 | - // } |
|
| 264 | - // } |
|
| 265 | - // } |
|
| 266 | - // } |
|
| 267 | - } |
|
| 20 | + private ?EE_Payment_Processor $payment_processor = null; |
|
| 21 | + |
|
| 22 | + private ?EE_Transaction_Processor $transaction_processor = null; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * array of TXN IDs |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected array $expired_transactions = []; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + private function loadTransactionProcessor() |
|
| 33 | + { |
|
| 34 | + $this->transaction_processor = $this->loader->getShared(EE_Transaction_Processor::class); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + private function loadPaymentProcessor() |
|
| 39 | + { |
|
| 40 | + $this->payment_processor = $this->loader->getShared(EE_Payment_Processor::class); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + public function setHooks(): void |
|
| 45 | + { |
|
| 46 | + add_action( |
|
| 47 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 48 | + [$this, 'expiredTransactionCheck'] |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * schedule_expired_transaction_check |
|
| 55 | + * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
| 56 | + * |
|
| 57 | + * @param int $timestamp |
|
| 58 | + * @param int $TXN_ID |
|
| 59 | + */ |
|
| 60 | + public static function scheduleExpiredTransactionCheck( |
|
| 61 | + int $timestamp, |
|
| 62 | + int $TXN_ID |
|
| 63 | + ): void { |
|
| 64 | + // validate $TXN_ID and $timestamp |
|
| 65 | + $TXN_ID = absint($TXN_ID); |
|
| 66 | + $timestamp = absint($timestamp); |
|
| 67 | + if ($TXN_ID && $timestamp) { |
|
| 68 | + wp_schedule_single_event( |
|
| 69 | + $timestamp, |
|
| 70 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
| 71 | + [$TXN_ID] |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * this is the callback for the action hook: |
|
| 79 | + * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
| 80 | + * which is utilized by wp_schedule_single_event() |
|
| 81 | + * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
| 82 | + * The passed TXN_ID gets added to an array, and then the |
|
| 83 | + * process_expired_transactions() function is hooked into |
|
| 84 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 85 | + * processing of any failed transactions, because doing so now would be |
|
| 86 | + * too early and the required resources may not be available |
|
| 87 | + * |
|
| 88 | + * @param int $TXN_ID |
|
| 89 | + */ |
|
| 90 | + public function expiredTransactionCheck(int $TXN_ID = 0): void |
|
| 91 | + { |
|
| 92 | + if (absint($TXN_ID)) { |
|
| 93 | + $this->expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 94 | + add_action( |
|
| 95 | + 'shutdown', |
|
| 96 | + [$this, 'processExpiredTransactions'], |
|
| 97 | + 5 |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * loops through the $this->expired_transactions array and processes any failed TXNs |
|
| 105 | + * |
|
| 106 | + * @throws EE_Error |
|
| 107 | + * @throws ReflectionException |
|
| 108 | + * @throws DomainException |
|
| 109 | + * @throws RuntimeException |
|
| 110 | + */ |
|
| 111 | + public function processExpiredTransactions(): void |
|
| 112 | + { |
|
| 113 | + if ( |
|
| 114 | + // are there any TXNs that need cleaning up ? |
|
| 115 | + empty($this->expired_transactions) |
|
| 116 | + // reschedule the cron if we can't hit the db right now |
|
| 117 | + || CronUtilities::rescheduleCronForTransactions( |
|
| 118 | + [ExpiredTransactionCheck::class, 'scheduleExpiredTransactionCheck'], |
|
| 119 | + $this->expired_transactions |
|
| 120 | + ) |
|
| 121 | + ) { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | + $this->loadTransactionProcessor(); |
|
| 125 | + // set revisit flag for txn processor |
|
| 126 | + $this->transaction_processor->set_revisit(); |
|
| 127 | + foreach ($this->expired_transactions as $TXN_ID) { |
|
| 128 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 129 | + // verify transaction and whether it is failed or not |
|
| 130 | + if ($transaction instanceof EE_Transaction) { |
|
| 131 | + switch ($transaction->status_ID()) { |
|
| 132 | + |
|
| 133 | + case EEM_Transaction::complete_status_code: |
|
| 134 | + $this->processCompletedTransaction($transaction); |
|
| 135 | + break; |
|
| 136 | + |
|
| 137 | + case EEM_Transaction::overpaid_status_code: |
|
| 138 | + $this->processOverpaidTransaction($transaction); |
|
| 139 | + break; |
|
| 140 | + |
|
| 141 | + case EEM_Transaction::incomplete_status_code: |
|
| 142 | + $this->processIncompletedTransaction($transaction); |
|
| 143 | + break; |
|
| 144 | + |
|
| 145 | + case EEM_Transaction::abandoned_status_code: |
|
| 146 | + $this->processAbandonedTransaction($transaction); |
|
| 147 | + break; |
|
| 148 | + |
|
| 149 | + case EEM_Transaction::failed_status_code: |
|
| 150 | + $this->processFailedTransaction($transaction); |
|
| 151 | + break; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + unset($this->expired_transactions[ $TXN_ID ]); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param EE_Transaction $transaction |
|
| 161 | + * @return void |
|
| 162 | + * @throws EE_Error |
|
| 163 | + * @throws ReflectionException |
|
| 164 | + */ |
|
| 165 | + private function processCompletedTransaction(EE_Transaction $transaction) |
|
| 166 | + { |
|
| 167 | + // Don't update the transaction/registrations if the Primary Registration is Not Approved. |
|
| 168 | + $primary_registration = $transaction->primary_registration(); |
|
| 169 | + if ( |
|
| 170 | + $primary_registration instanceof EE_Registration |
|
| 171 | + && $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 172 | + ) { |
|
| 173 | + $this->transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 174 | + $transaction, |
|
| 175 | + $transaction->last_payment() |
|
| 176 | + ); |
|
| 177 | + do_action( |
|
| 178 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
| 179 | + $transaction |
|
| 180 | + ); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @param EE_Transaction $transaction |
|
| 187 | + * @return void |
|
| 188 | + */ |
|
| 189 | + private function processOverpaidTransaction(EE_Transaction $transaction) |
|
| 190 | + { |
|
| 191 | + do_action( |
|
| 192 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
| 193 | + $transaction |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @param EE_Transaction $transaction |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + private function processIncompletedTransaction(EE_Transaction $transaction) |
|
| 203 | + { |
|
| 204 | + do_action( |
|
| 205 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 206 | + $transaction |
|
| 207 | + ); |
|
| 208 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @param EE_Transaction $transaction |
|
| 214 | + * @return void |
|
| 215 | + * @throws EE_Error |
|
| 216 | + * @throws ReflectionException |
|
| 217 | + */ |
|
| 218 | + private function processAbandonedTransaction(EE_Transaction $transaction) |
|
| 219 | + { |
|
| 220 | + // run hook before updating transaction, primarily so |
|
| 221 | + // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
| 222 | + do_action( |
|
| 223 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 224 | + $transaction |
|
| 225 | + ); |
|
| 226 | + // don't finalize the TXN if it has already been completed |
|
| 227 | + if ($transaction->all_reg_steps_completed() !== true) { |
|
| 228 | + $this->loadPaymentProcessor(); |
|
| 229 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 230 | + $this->payment_processor->update_txn_based_on_payment( |
|
| 231 | + $transaction, |
|
| 232 | + $transaction->last_payment(), |
|
| 233 | + true, |
|
| 234 | + true |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param EE_Transaction $transaction |
|
| 242 | + * @return void |
|
| 243 | + */ |
|
| 244 | + private function processFailedTransaction(EE_Transaction $transaction) |
|
| 245 | + { |
|
| 246 | + do_action( |
|
| 247 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 248 | + $transaction |
|
| 249 | + ); |
|
| 250 | + // todo : |
|
| 251 | + // perform garbage collection here and remove clean_out_junk_transactions() |
|
| 252 | + // $registrations = $transaction->registrations(); |
|
| 253 | + // if (! empty($registrations)) { |
|
| 254 | + // foreach ($registrations as $registration) { |
|
| 255 | + // if ($registration instanceof EE_Registration) { |
|
| 256 | + // $delete_registration = true; |
|
| 257 | + // if ($registration->attendee() instanceof EE_Attendee) { |
|
| 258 | + // $delete_registration = false; |
|
| 259 | + // } |
|
| 260 | + // if ($delete_registration) { |
|
| 261 | + // $registration->delete_permanently(); |
|
| 262 | + // $registration->delete_related_permanently(); |
|
| 263 | + // } |
|
| 264 | + // } |
|
| 265 | + // } |
|
| 266 | + // } |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function expiredTransactionCheck(int $TXN_ID = 0): void |
| 91 | 91 | { |
| 92 | 92 | if (absint($TXN_ID)) { |
| 93 | - $this->expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 93 | + $this->expired_transactions[$TXN_ID] = $TXN_ID; |
|
| 94 | 94 | add_action( |
| 95 | 95 | 'shutdown', |
| 96 | 96 | [$this, 'processExpiredTransactions'], |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | break; |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | - unset($this->expired_transactions[ $TXN_ID ]); |
|
| 154 | + unset($this->expired_transactions[$TXN_ID]); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |