-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproud-plugin.class.php
More file actions
140 lines (123 loc) · 3.46 KB
/
proud-plugin.class.php
File metadata and controls
140 lines (123 loc) · 3.46 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* @author ProudCity
*/
if ( ! class_exists( 'ProudPlugin' ) ) {
class ProudPlugin {
/////////////////////////////////////////////////////////////////////////////
// PROPERTIES, PROTECTED
/////////////////////////////////////////////////////////////////////////////
/**
* The plugins' text domain.
*
* @author Konstantin Obenland
* @since 1.1 - 03.04.2011
* @access protected
*
* @var string
*/
protected $textdomain;
/**
* The name of the calling plugin.
*
* @author Konstantin Obenland
* @since 1.0 - 23.03.2011
* @access protected
*
* @var string
*/
protected $plugin_name;
/**
* The path to the plugin file.
*
* /path/to/wp-content/plugins/{plugin-name}/{plugin-name}.php
*
* @author Konstantin Obenland
* @since 2.0.0 - 30.05.2012
* @access protected
*
* @var string
*/
protected $plugin_path;
/**
* The path to the plugin directory.
*
* /path/to/wp-content/plugins/{plugin-name}/
*
* @author Konstantin Obenland
* @since 1.2 - 21.04.2011
* @access protected
*
* @var string
*/
protected $plugin_dir_path;
///////////////////////////////////////////////////////////////////////////
// METHODS, PUBLIC
///////////////////////////////////////////////////////////////////////////
/**
* Constructor
*
* @author Konstantin Obenland
* @since 1.0 - 23.03.2011
* @access public
*
* @param string $plugin_name
* @param string $donate_link_id
*
* @return Obenland_Wp_Plugins
*/
public function __construct( $args = array() ) {
// Set class properties
$this->textdomain = $args['textdomain'];
$this->plugin_path = $args['plugin_path'];
$this->plugin_dir_path = plugin_dir_path( $args['plugin_path'] );
$this->plugin_name = plugin_basename( $args['plugin_path'] );
load_plugin_textdomain( 'wp-proud', false, $this->textdomain . '/lang' );
}
/**
* Sanitizes method names.
*
* @author Mark Jaquith
* @see http://sliwww.slideshare.net/markjaquith/creating-and-maintaining-wordpress-plugins
* @since 1.5 - 12.02.2012
* @access private
*
* @param string $method Method name to be sanitized.
*
* @return string Sanitized method name
*/
private function sanitize_method( $method ) {
return str_replace( array( '.', '-' ), '_', $method );
}
/**
* Hooks methods to their WordPress Actions and Filters.
*
* @example:
* $this->hook( 'the_title' );
* $this->hook( 'init', 5 );
* $this->hook( 'omg', 'is_really_tedious', 3 );
*
* @author Mark Jaquith
* @see http://sliwww.slideshare.net/markjaquith/creating-and-maintaining-wordpress-plugins
* @since 1.5 - 12.02.2012
* @access protected
*
* @param string $hook Action or Filter Hook name.
*
* @return boolean true
*/
protected function hook( $hook ) {
$priority = 10;
$method = $this->sanitize_method( $hook );
$args = func_get_args();
unset( $args[0] ); // Filter name
foreach ( (array) $args as $arg ) {
if ( is_int( $arg ) )
$priority = $arg;
else
$method = $arg;
}
return add_action( $hook, array( $this, $method ), $priority , 999 );
}
}
}