-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
executable file
·88 lines (78 loc) · 2.69 KB
/
plugin.php
File metadata and controls
executable file
·88 lines (78 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
if (!class_exists('Rotor_WPPlugin_Base')) {
require_once(dirname(__FILE__) . '/Base.php');
}
/**
* A new way of using the WordPress API
*
* @package Rotor WP Plugin
*/
class Rotor_WPPlugin extends Rotor_WPPlugin_Base {
/**
* Constructor
*
* Ensure you call this from your child class
*
* @param boolean $enable_prefixes Whether to enable prefixed methods (i.e. `action_init` or `filter_the_title`)
*/
protected function __construct($enable_prefixes = false) {
$this->_register_hooks($enable_prefixes, $this);
}
/**
* Add a method as a filter
*
* This is exactly the same as {@see add_filter()} but instead of passing
* a full callback, only the method needs to be passed in.
*
* @param string $hook Filter name
* @param string $method Method name on current class, or priority (as an int)
* @param int $priority Specify the order in which the functions associated with a particular action are executed (default: 10)
* @param int $accepted_args Number of parameters which callback accepts (default: corresponds to method prototype)
*/
protected function add_filter($hook, $method = null, $priority = 10, $params = null) {
if ($method === null) {
$method = $hook;
}
elseif (is_int($method)) {
$priority = $method;
$method = $hook;
}
if (!method_exists($this, $method)) {
throw new InvalidArgumentException('Method does not exist');
}
if ($params === null) {
$ref = new ReflectionMethod($this, $method);
$params = $ref->getNumberOfParameters();
}
return add_filter($hook, array($this, $method), $priority, $params);
}
/**
* Add a method as a action
*
* This is exactly the same as {@see add_action()} but instead of passing
* a full callback, only the method needs to be passed in.
*
* @internal This is duplication, but ensures consistency with WordPress API
* @param string $hook Action name
* @param string|int $method Method name on current class, or priority (as an int)
* @param int $priority Specify the order in which the functions associated with a particular action are executed (default: 10)
* @param int $accepted_args Number of parameters which callback accepts (default: corresponds to method prototype)
*/
protected function add_action($hook, $method = null, $priority = 10, $params = null) {
if ($method === null) {
$method = $hook;
}
elseif (is_int($method)) {
$priority = $method;
$method = $hook;
}
if (!method_exists($this, $method)) {
throw new InvalidArgumentException('Method does not exist');
}
if ($params === null) {
$ref = new ReflectionMethod($this, $method);
$params = $ref->getNumberOfParameters();
}
return add_action($hook, array($this, $method), $priority, $params);
}
}