PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.2
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.2
7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 6.0.7 All 35 releases
mlsimport / includes / class-mlsimport-loader.php

class-mlsimport-loader.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.2, at includes/class-mlsimport-loader.php

143 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Guard: block direct web access — only load when WordPress is bootstrapped.
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7
8 /**
9 * Register all actions and filters for the plugin
10 *
11 * File role: the hook registry (WordPress Plugin Boilerplate "Loader" pattern). Admin/public
12 * classes queue their hooks here via add_action()/add_filter(); the core class then calls
13 * run() once to bind every queued hook to WordPress in a single pass.
14 *
15 * @link http://mlsimport.com/
16 * @since 1.0.0
17 *
18 * @package Mlsimport
19 * @subpackage Mlsimport/includes
20 */
21
22 /**
23 * Register all actions and filters for the plugin.
24 *
25 * Maintain a list of all hooks that are registered throughout
26 * the plugin, and register them with the WordPress API. Call the
27 * run function to execute the list of actions and filters.
28 *
29 * @package Mlsimport
30 * @subpackage Mlsimport/includes
31 * @author MlsImport <office@mlsimport.com>
32 */
33 class Mlsimport_Loader {
34
35
36 /**
37 * The array of actions registered with WordPress.
38 *
39 * @since 1.0.0
40 * @access protected
41 * @var array $actions The actions registered with WordPress to fire when the plugin loads.
42 */
43 protected $actions;
44
45 /**
46 * The array of filters registered with WordPress.
47 *
48 * @since 1.0.0
49 * @access protected
50 * @var array $filters The filters registered with WordPress to fire when the plugin loads.
51 */
52 protected $filters;
53
54 /**
55 * Initialize the collections used to maintain the actions and filters.
56 *
57 * @since 1.0.0
58 */
59 public function __construct() {
60
61 // Start with empty queues; hooks are appended as components register them.
62 $this->actions = array();
63 $this->filters = array();
64 }
65
66 /**
67 * Add a new action to the collection to be registered with WordPress.
68 *
69 * @since 1.0.0
70 * @param string $hook The name of the WordPress action that is being registered.
71 * @param object $component A reference to the instance of the object on which the action is defined.
72 * @param string $callback The name of the function definition on the $component.
73 * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
74 * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
75 */
76 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
77 // Append this action to the actions queue via the shared add() helper.
78 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
79 }
80
81 /**
82 * Add a new filter to the collection to be registered with WordPress.
83 *
84 * @since 1.0.0
85 * @param string $hook The name of the WordPress filter that is being registered.
86 * @param object $component A reference to the instance of the object on which the filter is defined.
87 * @param string $callback The name of the function definition on the $component.
88 * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
89 * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
90 */
91 public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
92 // Append this filter to the filters queue via the shared add() helper.
93 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
94 }
95
96 /**
97 * A utility function that is used to register the actions and hooks into a single
98 * collection.
99 *
100 * @since 1.0.0
101 * @access private
102 * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
103 * @param string $hook The name of the WordPress filter that is being registered.
104 * @param object $component A reference to the instance of the object on which the filter is defined.
105 * @param string $callback The name of the function definition on the $component.
106 * @param int $priority The priority at which the function should be fired.
107 * @param int $accepted_args The number of arguments that should be passed to the $callback.
108 * @return array The collection of actions and filters registered with WordPress.
109 */
110 private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
111
112 // Store the hook definition as an associative array for later binding in run().
113 $hooks[] = array(
114 'hook' => $hook,
115 'component' => $component,
116 'callback' => $callback,
117 'priority' => $priority,
118 'accepted_args' => $accepted_args,
119 );
120
121 // Return the extended collection back to the caller for reassignment.
122 return $hooks;
123 }
124
125 /**
126 * Register the filters and actions with WordPress.
127 *
128 * @since 1.0.0
129 */
130 public function run() {
131
132 // Bind every queued filter to WordPress via add_filter().
133 foreach ( $this->filters as $hook ) {
134 add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
135 }
136
137 // Bind every queued action to WordPress via add_action().
138 foreach ( $this->actions as $hook ) {
139 add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
140 }
141 }
142 }
143