images
1 day ago
class-mo-firebase-authentication-deactivator.php
1 day ago
class-mo-firebase-authentication-loader.php
1 day ago
class-mo-firebase-authentication.php
1 day ago
class-mo-firebase-authentication-loader.php
133 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Register all actions and filters for the plugin |
| 4 | * |
| 5 | * @link https://miniorange.com |
| 6 | * @since 1.0.0 |
| 7 | * |
| 8 | * @package Firebase_Authentication |
| 9 | * @subpackage Firebase_Authentication/includes |
| 10 | */ |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Register all actions and filters for the plugin. |
| 18 | * |
| 19 | * Maintain a list of all hooks that are registered throughout |
| 20 | * the plugin, and register them with the WordPress API. Call the |
| 21 | * run function to execute the list of actions and filters. |
| 22 | * |
| 23 | * @package Firebase_Authentication |
| 24 | * @subpackage Firebase_Authentication/includes |
| 25 | * @author miniOrange <info@miniorange.com> |
| 26 | */ |
| 27 | class MO_Firebase_Authentication_Loader { |
| 28 | |
| 29 | /** |
| 30 | * The array of actions registered with WordPress. |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | * @access protected |
| 34 | * @var array $actions The actions registered with WordPress to fire when the plugin loads. |
| 35 | */ |
| 36 | protected $actions; |
| 37 | |
| 38 | /** |
| 39 | * The array of filters registered with WordPress. |
| 40 | * |
| 41 | * @since 1.0.0 |
| 42 | * @access protected |
| 43 | * @var array $filters The filters registered with WordPress to fire when the plugin loads. |
| 44 | */ |
| 45 | protected $filters; |
| 46 | |
| 47 | /** |
| 48 | * Initialize the collections used to maintain the actions and filters. |
| 49 | * |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | public function __construct() { |
| 53 | |
| 54 | $this->actions = array(); |
| 55 | $this->filters = array(); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Add a new action to the collection to be registered with WordPress. |
| 61 | * |
| 62 | * @since 1.0.0 |
| 63 | * @param string $hook The name of the WordPress action that is being registered. |
| 64 | * @param object $component A reference to the instance of the object on which the action is defined. |
| 65 | * @param string $callback The name of the function definition on the $component. |
| 66 | * @param int $priority Optional. The priority at which the function should be fired. Default is 10. |
| 67 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
| 68 | */ |
| 69 | public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
| 70 | $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Add a new filter to the collection to be registered with WordPress. |
| 75 | * |
| 76 | * @since 1.0.0 |
| 77 | * @param string $hook The name of the WordPress filter that is being registered. |
| 78 | * @param object $component A reference to the instance of the object on which the filter is defined. |
| 79 | * @param string $callback The name of the function definition on the $component. |
| 80 | * @param int $priority Optional. The priority at which the function should be fired. Default is 10. |
| 81 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
| 82 | */ |
| 83 | public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
| 84 | $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * A utility function that is used to register the actions and hooks into a single |
| 89 | * collection. |
| 90 | * |
| 91 | * @since 1.0.0 |
| 92 | * @access private |
| 93 | * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). |
| 94 | * @param string $hook The name of the WordPress filter that is being registered. |
| 95 | * @param object $component A reference to the instance of the object on which the filter is defined. |
| 96 | * @param string $callback The name of the function definition on the $component. |
| 97 | * @param int $priority The priority at which the function should be fired. |
| 98 | * @param int $accepted_args The number of arguments that should be passed to the $callback. |
| 99 | * @return array The collection of actions and filters registered with WordPress. |
| 100 | */ |
| 101 | private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
| 102 | |
| 103 | $hooks[] = array( |
| 104 | 'hook' => $hook, |
| 105 | 'component' => $component, |
| 106 | 'callback' => $callback, |
| 107 | 'priority' => $priority, |
| 108 | 'accepted_args' => $accepted_args, |
| 109 | ); |
| 110 | |
| 111 | return $hooks; |
| 112 | |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Register the filters and actions with WordPress. |
| 117 | * |
| 118 | * @since 1.0.0 |
| 119 | */ |
| 120 | public function run() { |
| 121 | |
| 122 | foreach ( $this->filters as $hook ) { |
| 123 | add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
| 124 | } |
| 125 | |
| 126 | foreach ( $this->actions as $hook ) { |
| 127 | add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
| 128 | } |
| 129 | |
| 130 | } |
| 131 | |
| 132 | } |
| 133 |