forked from obenland/wp-approve-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-obenland-wp-plugins-v5.php
306 lines (283 loc) · 8.16 KB
/
class-obenland-wp-plugins-v5.php
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
/**
* Obenland plugin base class.
*
* @author Konstantin Obenland
* @version 5
* @package Obenland Plugins
*/
/**
* Class Obenland_Wp_Plugins_V5
*/
class Obenland_Wp_Plugins_V5 {
/**
* 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 donate link for the plugin.
*
* @author Konstantin Obenland
* @since 1.0 - 23.03.2011
* @access protected
*
* @var string
*/
protected $donate_link;
/**
* 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;
/**
* Constructor
*
* @author Konstantin Obenland
* @since 1.0 - 23.03.2011
* @access public
*
* @param array $args {.
* @type string $textdomain
* @type string $plugin_name
* @type string $plugin_path
* @type string $donate_link_id
* }
*/
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( 'obenland-wp', false, $this->textdomain . '/lang' );
$this->set_donate_link( $args['donate_link_id'] );
$this->hook( 'plugins_loaded', 'parent_plugins_loaded' );
}
/**
* Hooks in all the hooks :)
*
* @author Konstantin Obenland
* @since 2.0.0 - 12.04.2012
* @access public
*/
public function parent_plugins_loaded() {
$this->hook( 'plugin_row_meta' );
}
/**
* Adds a Donate link to our plugin row.
*
* @author Konstantin Obenland
* @since 1.0 - 23.03.2011
* @access public
*
* @param array $plugin_meta Existing plugin meta.
* @param string $plugin_file Plugin slug.
* @return array
*/
public function plugin_row_meta( $plugin_meta, $plugin_file ) {
if ( $this->plugin_name === $plugin_file ) {
$plugin_meta[] = sprintf(
'<a href="%1$s" target="_blank" title="%2$s">%2$s</a>',
$this->donate_link,
__( 'Donate', 'obenland-wp' )
);
}
return $plugin_meta;
}
/**
* Displays a box with a donate button and call to action links.
*
* Props Joost de Valk, as this is almost entirely from his awesome WordPress
* SEO Plugin.
*
* @see http://plugins.svn.wordpress.org/wordpress-seo/tags/1.1.5/admin/class-config.php
*
* @author Joost de Valk, Konstantin Obenland
* @since 2.0.0 - 31.03.2012
* @access public
*/
public function donate_box() {
$plugin_data = get_plugin_data( $this->plugin_path );
?>
<div id="formatdiv" class="postbox">
<h3 class="hndle"><span><?php esc_html_e( 'Help spread the word!', 'obenland-wp' ); ?></span></h3>
<div class="inside">
<p>
<strong>
<?php
printf(
/* translators: Plugin name. */
esc_html_x( 'Want to help make this plugin even better? All donations are used to improve %1$s, so donate $20, $50 or $100 now!', 'Plugin Name', 'obenland-wp' ),
esc_html( $plugin_data['Name'] )
);
?>
</strong>
</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="G65Y5CM3HVRNY">
<input type="image" src="https://www.paypalobjects.com/<?php echo esc_attr( get_locale() ); ?>/i/btn/btn_donate_LG.gif" border="0" name="submit">
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
<p><?php esc_html_e( 'Or you could:', 'obenland-wp' ); ?></p>
<ul>
<li><a href="http://wordpress.org/plugins/wp-approve-user/"><?php esc_html_e( 'Rate the plugin 5★ on WordPress.org', 'obenland-wp' ); ?></a></li>
<li><a href="<?php echo esc_url( $plugin_data['PluginURI'] ); ?>"><?php esc_html_e( 'Blog about it & link to the plugin page', 'obenland-wp' ); ?></a></li>
</ul>
</div>
</div>
<?php
}
/**
* Displays a box with feed items and social media links.
*
* Props Joost de Valk, as this is almost entirely from his awesome WordPress
* SEO Plugin.
*
* @see http://plugins.svn.wordpress.org/wordpress-seo/tags/1.1.5/admin/yst_plugin_tools.php
*
* @author Joost de Valk, Konstantin Obenland
* @since 2.0.0 - 31.03.2012
* @access public
*/
public function feed_box() {
include_once ABSPATH . WPINC . '/feed.php';
$feed_url = 'https://konstantin.obenland.it/feed/';
$rss = fetch_feed( $feed_url );
// Bail if feed doesn't work.
if ( is_wp_error( $rss ) ) {
return;
}
$rss_items = $rss->get_items( 0, $rss->get_item_quantity( 5 ) );
// If the feed was erroneously.
if ( ! $rss_items ) {
$md5 = md5( $feed_url );
delete_transient( 'feed_' . $md5 );
delete_transient( 'feed_mod_' . $md5 );
$rss = fetch_feed( $feed_url );
$rss_items = $rss->get_items( 0, $rss->get_item_quantity( 5 ) );
}
?>
<div id="formatdiv" class="postbox">
<h3 class="hndle"><span><?php esc_html_e( 'News from Konstantin', 'obenland-wp' ); ?></span></h3>
<div class="inside">
<ul>
<?php if ( ! $rss_items ) : ?>
<li><?php esc_html_e( 'No news items, feed might be broken...', 'obenland-wp' ); ?></li>
<?php
else :
foreach ( $rss_items as $item ) :
$url = preg_replace( '/#.*/', '#utm_source=WordPress&utm_medium=sidebannerpostbox&utm_term=rssitem&utm_campaign=' . $this->textdomain, $item->get_permalink() );
?>
<li><a class="rsswidget" href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $item->get_title() ); ?></a></li>
<?php
endforeach;
endif;
?>
<li class="twitter"><a href="http://twitter.com/obenland"><?php esc_html_e( 'Follow Konstantin on Twitter', 'obenland-wp' ); ?></a></li>
<li class="rss"><a href="<?php echo esc_url( $feed_url ); ?>"><?php esc_html_e( 'Subscribe via RSS', 'obenland-wp' ); ?></a></li>
</ul>
</div>
</div>
<?php
}
/**
* 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 );
}
/**
* Sets the donate link.
*
* @author Konstantin Obenland
* @since 1.1 - 03.04.2011
* @access protected
*
* @param string $donate_link_id Donate link ID.
*/
protected function set_donate_link( $donate_link_id ) {
$this->donate_link = add_query_arg(
array(
'cmd' => '_s-xclick',
'hosted_button_id' => $donate_link_id,
),
'https://www.paypal.com/cgi-bin/webscr'
);
}
/**
* 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 );
}
}