| @@ -1,23 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -/** | |
| 4 | - * All registered action's handlers should be in app\Hooks\Handlers, | |
| 5 | - * addAction is similar to add_action and addCustomAction is just a | |
| 6 | - * wrapper over add_action which will add a prefix to the hook name | |
| 7 | - * using the plugin slug to make it unique in all wordpress plugins, | |
| 8 | - * ex: $app->addCustomAction('foo', ['FooHandler', 'handleFoo']) is | |
| 9 | - * equivalent to add_action('slug-foo', ['FooHandler', 'handleFoo']). | |
| 10 | - */ | |
| 3 | +defined('ABSPATH') or die; | |
| 11 | 4 | |
| 12 | 5 | /** |
| 13 | 6 | * @var $app FluentSupport\Framework\Foundation\Application |
| 14 | 7 | */ |
| 15 | 8 | |
| 16 | -use FluentSupport\App\App; | |
| 17 | - | |
| 18 | -require_once 'Handlers/AuthHandler.php'; | |
| 19 | - | |
| 20 | 9 | (new \FluentSupport\App\Hooks\Handlers\AuthHandler)->init(); |
| 21 | 10 | |
| 22 | 11 | $app->addCustomAction('handle_exception', 'ExceptionHandler@handle'); |
| 23 | 12 | |
| @@ -22,70 +11,40 @@ | ||
| 22 | 11 | $app->addCustomAction('handle_exception', 'ExceptionHandler@handle'); |
| 23 | 12 | |
| 24 | 13 | $app->addAction('admin_menu', 'Menu@add'); |
| 25 | 14 | $app->addAction('admin_enqueue_scripts', 'Menu@maybeEnqueueAssets'); |
| 15 | +$app->addAction('admin_bar_menu', 'AdminBarHandler@init'); | |
| 16 | +$app->addAction('wp_dashboard_setup', 'AdminBarHandler@initAdminWidget'); | |
| 26 | 17 | |
| 27 | -add_shortcode('fluent_support_portal', function () { | |
| 28 | - return (new \FluentSupport\App\Hooks\Handlers\CustomerPortalHandler())->renderPortal(); | |
| 29 | -}); | |
| 18 | +$app->addShortcode('fluent_support_portal', 'ShortcodeHandler@fluentSupportPortal'); | |
| 30 | 19 | |
| 31 | -add_shortcode('fluent_support_admin_portal', function () { | |
| 32 | - $app = App::getInstance(); | |
| 33 | - $assets = $app['url.assets']; | |
| 34 | - wp_enqueue_style('fluent_support_login_style', $assets.'admin/css/all_public.css'); | |
| 35 | - if (!get_current_user_id()) { | |
| 36 | - $return = '<div class="fst_login"><h3>'.__('Please Login', 'fluent-support').'</h3>'; | |
| 37 | - $return .= do_shortcode('[fluent_support_login]'); | |
| 38 | - $return .= '</div>'; | |
| 39 | - return $return; | |
| 40 | - } | |
| 41 | - | |
| 42 | - $currentUserPermissions = \FluentSupport\App\Modules\PermissionManager::currentUserPermissions(); | |
| 43 | - if (!$currentUserPermissions) { | |
| 44 | - return __('Sorry, You do not have permission to this page', 'fluent-support'); | |
| 45 | - } | |
| 46 | - | |
| 47 | - add_filter('fluent_support/base_url', function ($url) { | |
| 48 | - global $wp; | |
| 49 | - return home_url(add_query_arg(array(), $wp->request)) . '/#/'; | |
| 50 | - }); | |
| 51 | - | |
| 52 | - add_filter('fluent_support/secondary_menu_items', function ($items) { | |
| 53 | - global $wp; | |
| 54 | - $items[] = [ | |
| 55 | - 'key' => 'logout', | |
| 56 | - 'label' => __('Logout', 'fluent-support'), | |
| 57 | - 'permalink' => wp_logout_url(home_url(add_query_arg(array(), $wp->request))) | |
| 58 | - ]; | |
| 59 | - return $items; | |
| 60 | - }); | |
| 61 | - | |
| 62 | - ob_start(); | |
| 63 | - echo '<div class="fst_front">'; | |
| 64 | - (new \FluentSupport\App\Hooks\Handlers\Menu())->renderApp(); | |
| 65 | - echo '</div>'; | |
| 66 | - return ob_get_clean(); | |
| 20 | +add_action('init', function () { | |
| 21 | + (new \FluentSupport\App\Services\Integrations\IntegrationInit())->init(); | |
| 67 | 22 | }); |
| 68 | 23 | |
| 69 | -// init integrations | |
| 70 | -(new \FluentSupport\App\Services\Integrations\IntegrationInit())->init(); | |
| 24 | +(new \FluentSupport\App\Hooks\Handlers\ActivityLogger())->init(); | |
| 71 | 25 | |
| 72 | -// Activities | |
| 73 | -(new \FluentSupport\App\Hooks\Handlers\ActivityLogger())->init(); | |
| 26 | +(new \FluentSupport\App\Hooks\Handlers\AIActivityLogger())->init(); | |
| 74 | 27 | |
| 75 | -/* | |
| 76 | - * Email Notification Hooks | |
| 77 | - */ | |
| 28 | +(new \FluentSupport\App\Hooks\Handlers\InternalNotificationHandler())->init(); | |
| 78 | 29 | |
| 79 | 30 | $app->addAction('fluent_support/ticket_created', 'EmailNotificationHandler@ticketCreated', 10, 2); |
| 80 | 31 | $app->addAction('fluent_support/response_added_by_agent', 'EmailNotificationHandler@agentReplied', 10, 3); |
| 81 | 32 | $app->addAction('fluent_support/response_added_by_customer', 'EmailNotificationHandler@customerReplied', 10, 3); |
| 82 | 33 | $app->addAction('fluent_support/ticket_closed_by_agent', 'EmailNotificationHandler@closedByAgent', 10, 2); |
| 34 | +$app->addAction('fluent_support/agent_assigned_to_ticket', 'EmailNotificationHandler@onAgentAssign', 10, 3); | |
| 35 | +$app->addAction('fluent_support/ticket_created_behalf_of_customer', 'EmailNotificationHandler@ticketCreatedByAgent', 10, 3); | |
| 36 | +$app->addAction('fluent_support/agent_initiated_ticket_response', 'EmailNotificationHandler@ticketCreatedByAgentOnBehalf', 10, 3); | |
| 83 | 37 | |
| 84 | -// Cleanup | |
| 38 | +$app->addAction('fluent_support/async_agent_assigned_to_ticket', 'AsyncActionHandler@resolveAgentAssigned', 10, 4); | |
| 39 | + | |
| 85 | 40 | $app->addAction('fluent_support_hourly_tasks', 'CleanupHandler@initHourlyTasks'); |
| 86 | 41 | $app->addAction('fluent_support_daily_tasks', 'CleanupHandler@initDailyTasks'); |
| 42 | +$app->addAction('fluent_support_weekly_tasks', 'CleanupHandler@maybeMaintanceTask'); | |
| 87 | 43 | |
| 44 | +$app->addAction('fluent_support/deleting_ticket', 'CleanupHandler@deleteTicketAttachments'); | |
| 45 | +$app->addAction('fluent_support/ticket_closed', 'CleanupHandler@maybeDeleteAttachmentsOnClose'); | |
| 46 | + | |
| 88 | 47 | if(isset($_GET['fs_view'])) { |
| 89 | 48 | $app->addAction('init', 'ExternalPages@route'); |
| 90 | 49 | } |
| 91 | 50 | |
| @@ -94,9 +53,8 @@ | ||
| 94 | 53 | (new \FluentSupport\App\Hooks\Handlers\ExternalPages())->view_attachment(); |
| 95 | 54 | }); |
| 96 | 55 | } |
| 97 | 56 | |
| 98 | -// require the CLI | |
| 99 | 57 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 100 | 58 | \WP_CLI::add_command( 'fluent_support', '\FluentSupport\App\Hooks\CLI\FluentCli' ); |
| 101 | 59 | } |
| 102 | 60 | |
| @@ -101,5 +59,29 @@ | ||
| 101 | 59 | } |
| 102 | 60 | |
| 103 | 61 | |
| 104 | 62 | (new \FluentSupport\App\Hooks\Handlers\PermissionFilterManager)->init(); |
| 63 | + | |
| 64 | +(new \FluentSupport\App\Hooks\Handlers\PrivacyHandler())->init(); | |
| 65 | + | |
| 66 | +$app->addAction('profile_update', '\FluentSupport\App\Services\ProfileInfoService@onWPProfileUpdate', 10, 3); | |
| 67 | + | |
| 68 | +// Registration is the only point that auto-links a customer row to a WP user. | |
| 69 | +// An email change alone never claims a row. | |
| 70 | +$app->addAction('user_register', '\FluentSupport\App\Services\ProfileInfoService@onWPUserRegister', 10, 1); | |
| 71 | +$app->addAction('wp_ajax_fs_export_agent_report', 'FluentSupport\App\Hooks\Handlers\DataExporter@exportReport'); | |
| 72 | + | |
| 73 | +// Disable LiteSpeed ESI on Fluent Support requests. | |
| 74 | +if(defined('LSCWP_V')){ | |
| 75 | + add_action('litespeed_init', function (){ | |
| 76 | + if(isset($_SERVER['REQUEST_URI']) && strpos(esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])), 'fluent-support') !== false){ | |
| 77 | + defined( 'LITESPEED_ESI_OFF' ) || define( 'LITESPEED_ESI_OFF', true ); | |
| 78 | + } | |
| 79 | + }); | |
| 80 | +} | |
| 81 | + | |
| 82 | +$app->addAction('init', 'BlockEditorHandler@init'); | |
| 83 | + | |
| 84 | +// Boot MCP unconditionally so FluentHub can list us on WP < 6.9. The | |
| 85 | +// ability/server hooks only fire when the Abilities API or MCP adapter exists. | |
| 86 | +\FluentSupport\App\Modules\MCP\MCPInit::boot(); | |
| 105 | 87 | |