fluent-community
/
vendor
/
wpfluent
/
framework
/
src
/
WPFluent
/
Foundation
/
Concerns
/
AjaxTrait.php
AjaxTrait.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.9.1, at vendor/wpfluent/framework/src/WPFluent/Foundation/Concerns/AjaxTrait.php
| 1 | <?php |
| 2 | |
| 3 | namespace FluentCommunity\Framework\Foundation\Concerns; |
| 4 | |
| 5 | trait AjaxTrait |
| 6 | { |
| 7 | /** |
| 8 | * Add ajax action |
| 9 | * |
| 10 | * @param string $action |
| 11 | * @param string|\Closure $handler |
| 12 | * @param int $priority |
| 13 | * @param string $scope |
| 14 | * @return void |
| 15 | */ |
| 16 | private function addAjaxAction($action, $handler, $priority, $scope) |
| 17 | { |
| 18 | $hook = $scope == 'admin' ? 'wp_ajax_' : 'wp_ajax_nopriv_'; |
| 19 | |
| 20 | $action = $hook.$this->config->get('app.hook_prefix').$action; |
| 21 | |
| 22 | $callback = $this->parseHookHandler($handler); |
| 23 | |
| 24 | add_action($action, $callback, $priority); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Add ajax actions including non_prive |
| 29 | * @param string $action |
| 30 | * @param string|\Closure $handler |
| 31 | * @param int $priority |
| 32 | * @return void |
| 33 | */ |
| 34 | public function addAjaxActions($action, $handler, $priority = 10) |
| 35 | { |
| 36 | $this->addAjaxAction($action, $handler, $priority, 'admin'); |
| 37 | $this->addAjaxAction($action, $handler, $priority, 'public'); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Add ajax action for privilaged user |
| 42 | * @param string $action |
| 43 | * @param string|\Closure $handler |
| 44 | * @param int $priority |
| 45 | * @return void |
| 46 | */ |
| 47 | public function addAdminAjaxAction($action, $handler, $priority = 10) |
| 48 | { |
| 49 | $this->addAjaxAction($action, $handler, $priority, 'admin'); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Add ajax action for non-privilaged user |
| 54 | * @param string $action |
| 55 | * @param string|\Closure $handler |
| 56 | * @param int $priority |
| 57 | * @return void |
| 58 | */ |
| 59 | public function addPublicAjaxAction($action, $handler, $priority = 10) |
| 60 | { |
| 61 | $this->addAjaxAction($action, $handler, $priority, 'public'); |
| 62 | } |
| 63 | } |
| 64 |