WP Updates Notifier - Version 1.0

Version Description

  • Initial release
Download this release

Release Info

Developer l3rady
Plugin Icon wp plugin WP Updates Notifier
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (5) hide show
  1. readme.txt +51 -0
  2. screenshot-1.jpg +0 -0
  3. screenshot-2.jpg +0 -0
  4. uninstall.php +24 -0
  5. wp-updates-notifier.php +502 -0
readme.txt ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: l3rady
3
+ Donate link: http://l3rady.com/donate
4
+ Tags: admin, theme, monitor, plugin, notification, upgrade, security
5
+ Requires at least: 3.1
6
+ Tested up to: 3.1.3
7
+ Stable tag: 1.0
8
+
9
+ Sends email to notify you if there are any updates for your WordPress site. Can notify about core, plugin and theme updates.
10
+
11
+ == Description ==
12
+
13
+ Monitors your WordPress installation for core, plugin and theme updates and emails you when they are available. This plugin is ideal if you don't login to your WordPress admin regularly or you support a client's website.
14
+
15
+ *Features*
16
+
17
+ - Set the interval of how often to check for updates; hourly, twice daily or daily.
18
+ - Sets WordPress to check for updates more often meaning you get to know about updates sooner.
19
+ - Get emailed about core, plugin and theme updates.
20
+ - Chose if you want to be notified about active only themes and plugins updates.
21
+ - Remove upgrade nag message to non-admin users.
22
+ - For advanced users there are a number of filters and actions you can use. More coming soon.
23
+
24
+ This plugin is a fork of [Update Notifier](http://wordpress.org/extend/plugins/update-notifier/). This plugin was forked because there seemed to be no further development on the existing plugin and there was no way to contact the original author to ask about taking ownership. WP Updates Notifier has the following improvements over Updates Notifier:
25
+
26
+ - Completely rewritten from the ground up using best practises for writing WordPress plugins
27
+ - Code wrapped in a class so better namespace.
28
+ - You can set the cron interval, allowing for more frequent checks.
29
+ - Update checks trigger WordPress internal update check before notification.
30
+ - Allows you to set the 'from address'.
31
+ - Makes use of the Settings API.
32
+ - A number of available hooks and filters for advanced users.
33
+ - Active support and development.
34
+
35
+ == Installation ==
36
+
37
+ * Unzip and upload contents to your plugins directory (usually wp-content/plugins/).
38
+ * Activate plugin
39
+ * Visit Settings page under Settings -> WP Updates Monitor in your WordPress Administration Area
40
+ * Configure plugin settings
41
+ * Wait for email notifications of updates
42
+
43
+ == Screenshots ==
44
+
45
+ 1. Settings page
46
+ 2. Email alert
47
+
48
+ == Changelog ==
49
+
50
+ = 1.0 =
51
+ * Initial release
screenshot-1.jpg ADDED
Binary file
screenshot-2.jpg ADDED
Binary file
uninstall.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Copyright 2011 Scott Cariss (email : scott@l3rady.com)
3
+
4
+ This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+ if(!defined('WP_UNINSTALL_PLUGIN')) {
20
+ exit();
21
+ }
22
+ delete_option("sc_wpun_settings");
23
+ delete_option("sc_wpun_settings_ver");
24
+ ?>
wp-updates-notifier.php ADDED
@@ -0,0 +1,502 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP Updates Notifier
4
+ Plugin URI: http://l3rady.com/projects/wp-updates-notifier/
5
+ Description: Sends email to notify you if there are any updates for your WordPress site. Can notify about core, plugin and theme updates.
6
+ Author: Scott Cariss
7
+ Version: 1.0
8
+ Author URI: http://l3rady.com/
9
+ */
10
+
11
+ /* Copyright 2011 Scott Cariss (email : scott@l3rady.com)
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 2 of the License, or
16
+ (at your option) any later version.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+
28
+ // Only load class if it hasn't already been loaded
29
+ if (!class_exists('sc_WPUpdatesNotifier')) {
30
+
31
+ // WP Updates Notifier - All the magic happens here!
32
+ class sc_WPUpdatesNotifier {
33
+ protected static $options_field = "sc_wpun_settings";
34
+ protected static $options_field_ver = "sc_wpun_settings_ver";
35
+ protected static $options_field_current_ver = "1.0";
36
+ protected static $cron_name = "sc_wpun_update_check";
37
+ protected static $frequency_intervals = array("hourly", "twicedaily", "daily");
38
+
39
+ function __construct() {
40
+ // Check settings are up to date
41
+ $this->settingsUpToDate();
42
+ // Create Activation and Deactivation Hooks
43
+ register_activation_hook(__FILE__, array(&$this, 'activate'));
44
+ register_deactivation_hook(__FILE__, array(&$this, 'deactive'));
45
+ // Internationalization
46
+ load_plugin_textdomain('wp-updates-notifier', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
47
+ // Add Filters
48
+ add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2); // Add settings link to plugin in plugin list
49
+ add_filter('sc_wpun_plugins_need_update', array(&$this, 'check_plugins_against_notified')); // Filter out plugins that need update if already been notified
50
+ add_filter('sc_wpun_themes_need_update', array(&$this, 'check_themes_against_notified')); // Filter out themes that need update if already been notified
51
+ // Add Actions
52
+ add_action('admin_menu', array(&$this, 'admin_settings_menu')); // Add menu to options
53
+ add_action('admin_init', array(&$this, 'admin_settings_init')); // Add admin init functions
54
+ add_action('admin_init', array(&$this, 'remove_update_nag_for_nonadmins')); // See if we remove update nag for non admins
55
+ add_action('sc_wpun_enable_cron', array(&$this, 'enable_cron')); // action to enable cron
56
+ add_action('sc_wpun_disable_cron', array(&$this, 'disable_cron')); // action to disable cron
57
+ add_action(self::$cron_name, array(&$this, 'do_update_check')); // action to link cron task to actual task
58
+ }
59
+
60
+
61
+ /**
62
+ * Check if this plugin settings are up to date. Firstly check the version in
63
+ * the DB. If they don't match then load in defaults but don't override values
64
+ * already set. Also this will remove obsolete settings that are not needed.
65
+ *
66
+ * @return void
67
+ */
68
+ protected function settingsUpToDate() {
69
+ $current_ver = get_option(self::$options_field_ver); // Get current plugin version
70
+ if(self::$options_field_current_ver != $current_ver) { // is the version the same as this plugin?
71
+ $options = (array) get_option(self::$options_field); // get current settings from DB
72
+ $defaults = array( // Here are our default values for this plugin
73
+ 'frequency' => self::$frequency_intervals[0],
74
+ 'notify_to' => get_option('admin_email'),
75
+ 'notify_from' => get_option('admin_email'),
76
+ 'notify_plugins' => 1,
77
+ 'notify_themes' => 1,
78
+ 'hide_updates' => 1,
79
+ 'notified' => array(
80
+ 'core' => 0,
81
+ 'plugin' => array(),
82
+ 'theme' => array(),
83
+ )
84
+ );
85
+ // Intersect current options with defaults. Basically removing settings that are obsolete
86
+ $options = array_intersect_key($options, $defaults);
87
+ // Merge current settings with defaults. Basically adding any new settings with defaults that we dont have.
88
+ $options = array_merge($defaults, $options);
89
+ update_option(self::$options_field, $options); // update settings
90
+ update_option(self::$options_field_ver, self::$options_field_current_ver); // update settings version
91
+ }
92
+ }
93
+
94
+
95
+ /**
96
+ * Function that deals with activation of this plugin
97
+ *
98
+ * @return void
99
+ */
100
+ public function activate() {
101
+ do_action("sc_wpun_enable_cron"); // Enable cron
102
+ }
103
+
104
+
105
+ /**
106
+ * Function that deals with de-activation of this plugin
107
+ *
108
+ * @return void
109
+ */
110
+ public function deactivate() {
111
+ do_action("sc_wpun_disable_cron"); // Disable cron
112
+ }
113
+
114
+
115
+ /**
116
+ * Enable cron for this plugin. Check if a cron should be scheduled.
117
+ *
118
+ * @param bool|string $manual_interval For setting a manual cron interval.
119
+ * @return void
120
+ */
121
+ public function enable_cron($manual_interval = false) {
122
+ $options = get_option(self::$options_field); // get current settings
123
+ $currentSchedule = wp_get_schedule(self::$cron_name); // find if a schedule already exists
124
+ if(false !== $manual_interval) {$options['frequency'] = $manual_interval;} // if a manual cron interval is set, use this
125
+ if($currentSchedule != $options['frequency']) { // check if the current schedule matches the one set in settings
126
+ if(in_array($options['frequency'], self::$frequency_intervals)) { // check the cron setting is valid
127
+ do_action("sc_wpun_disable_cron"); // remove any crons for this plugin first so we don't end up with multiple crons doing the same thing.
128
+ wp_schedule_event(time(), $options['frequency'], self::$cron_name); // schedule cron for this plugin.
129
+ }
130
+ }
131
+ }
132
+
133
+
134
+ /**
135
+ * Removes cron for this plugin.
136
+ *
137
+ * @return void
138
+ */
139
+ public function disable_cron() {
140
+ wp_clear_scheduled_hook(self::$cron_name); // clear cron
141
+ }
142
+
143
+
144
+ /**
145
+ * Adds the settings link under the plugin on the plugin screen.
146
+ *
147
+ * @param array $links
148
+ * @param string $file
149
+ * @return array $links
150
+ */
151
+ public function plugin_action_links($links, $file) {
152
+ static $this_plugin;
153
+ if (!$this_plugin) {
154
+ $this_plugin = plugin_basename(__FILE__);
155
+ }
156
+ if ($file == $this_plugin){
157
+ $settings_link = '<a href="'.site_url().'/wp-admin/options-general.php?page=wp-updates-notifier">'.__("Settings", "wp-updates-notifier").'</a>';
158
+ array_unshift($links, $settings_link);
159
+ }
160
+ return $links;
161
+ }
162
+
163
+
164
+ /**
165
+ * This is run by the cron. The update check checks the core always, the
166
+ * plugins and themes if asked. If updates found email notification sent.
167
+ *
168
+ * @return void
169
+ */
170
+ public function do_update_check() {
171
+ $options = get_option(self::$options_field); // get settings
172
+ $message = ""; // start with a blank message
173
+ $core_updated = $this->core_update_check(&$message); // check the WP core for updates
174
+ if(0 != $options['notify_plugins']) { // are we to check for plugin updates?
175
+ $plugins_updated = $this->plugins_update_check(&$message, $options['notify_plugins']); // check for plugin updates
176
+ } else {
177
+ $plugins_updated = false; // no plugin updates
178
+ }
179
+ if(0 != $options['notify_themes']) { // are we to check for theme updates?
180
+ $themes_updated = $this->themes_update_check(&$message, $options['notify_themes']); // check for theme updates
181
+ } else {
182
+ $themes_updated = false; // no theme updates
183
+ }
184
+ if ($core_updated || $plugins_updated || $themes_updated) { // Did anything come back as need updating?
185
+ $message = __("There are updates available for your WordPress site:", "wp-updates-notifier")."\n\n".$message."\n";
186
+ $message .= sprintf(__("Please visit %s to update.", "wp-updates-notifier"), admin_url('update-core.php'));
187
+ $this->send_notification_email($message); // send our notification email.
188
+ }
189
+ }
190
+
191
+
192
+ /**
193
+ * Checks to see if any WP core updates
194
+ *
195
+ * @param string $message holds message to be sent via notification
196
+ * @return bool
197
+ */
198
+ protected function core_update_check(&$message) {
199
+ $settings = get_option(self::$options_field); // get settings
200
+ do_action("wp_version_check"); // force WP to check its core for updates
201
+ $update_core = get_site_transient("update_core"); // get information of updates
202
+ if('upgrade' == $update_core->updates[0]->response) { // is WP core update available?
203
+ if($update_core->updates[0]->current != $settings['notified']['core']) { // have we already notified about this version?
204
+ include( ABSPATH . WPINC . '/version.php' ); // Including this because some plugins can mess with the real version stored in the DB.
205
+ $new_core_ver = $update_core->updates[0]->current; // The new WP core version
206
+ $old_core_ver = $wp_version; // the old WP core version
207
+ $message .= sprintf(__("WP-Core: WordPress is out of date. Please update from version %s to %s", "wp-updates-notifier"), $old_core_ver, $new_core_ver)."\n";
208
+ $settings['notified']['core'] = $new_core_ver; // set core version we are notifying about
209
+ update_option(self::$options_field, $settings); // update settings
210
+ return true; // we have updates so return true
211
+ }
212
+ }
213
+ $settings['notified']['core'] = 0; // no updates lets set this 0
214
+ update_option(self::$options_field, $settings); // update settings
215
+ return false; // no updates return false
216
+ }
217
+
218
+
219
+ /**
220
+ * Check to see if any plugin updates.
221
+ *
222
+ * @param string $message holds message to be sent via notification
223
+ * @param int $allOrActive should we look for all plugins or just active ones
224
+ * @return bool
225
+ */
226
+ protected function plugins_update_check(&$message, $allOrActive) {
227
+ $settings = get_option(self::$options_field); // get settings
228
+ do_action("wp_update_plugins"); // force WP to check plugins for updates
229
+ $update_plugins = get_site_transient('update_plugins'); // get information of updates
230
+ if (!empty($update_plugins->response)) { // any plugin updates available?
231
+ $plugins_need_update = $update_plugins->response; // plugins that need updating
232
+ if(2 == $allOrActive) { // are we to check just active plugins?
233
+ $active_plugins = array_flip(get_option('active_plugins')); // find which plugins are active
234
+ $plugins_need_update = array_intersect_key($plugins_need_update, $active_plugins); // only keep plugins that are active
235
+ }
236
+ $plugins_need_update = apply_filters('sc_wpun_plugins_need_update', $plugins_need_update); // additional filtering of plugins need update
237
+ if(count($plugins_need_update) >= 1) { // any plugins need updating after all the filtering gone on above?
238
+ foreach($plugins_need_update as $key => $data) { // loop through the plugins that need updating
239
+ $plugin_info = get_plugin_data(WP_PLUGIN_DIR . "/" . $key); // get plugin info
240
+ $message .= sprintf(__("Plugin: %s is out of date. Please update from version %s to %s", "wp-updates-notifier"), $plugin_info['Name'], $plugin_info['Version'], $data->new_version)."\n";
241
+ $settings['notified']['plugin'][$key] = $data->new_version; // set plugin version we are notifying about
242
+ }
243
+ update_option(self::$options_field, $settings); // save settings
244
+ return true; // we have plugin updates return true
245
+ }
246
+ } else {
247
+ if(0 != count($settings['notified']['plugin'])) { // is there any plugin notifications?
248
+ $settings['notified']['plugin'] = array(); // set plugin notifications to empty as all plugins up-to-date
249
+ update_option(self::$options_field, $settings); // save settings
250
+ }
251
+ }
252
+ return false; // No plugin updates so return false
253
+ }
254
+
255
+
256
+ /**
257
+ * Check to see if any theme updates.
258
+ *
259
+ * @param string $message holds message to be sent via notification
260
+ * @param int $allOrActive should we look for all themes or just active ones
261
+ * @return bool
262
+ */
263
+ protected function themes_update_check(&$message, $allOrActive) {
264
+ $settings = get_option(self::$options_field); // get settings
265
+ do_action("wp_update_themes"); // force WP to check for theme updates
266
+ $update_themes = get_site_transient('update_themes'); // get information of updates
267
+ if (!empty($update_themes->response)) { // any theme updates available?
268
+ $themes_need_update = $update_themes->response; // themes that need updating
269
+ if(2 == $allOrActive) { // are we to check just active themes?
270
+ $active_theme = array(get_option('template') => array()); // find current theme that is active
271
+ $themes_need_update = array_intersect_key($themes_need_update, $active_theme); // only keep theme that is active
272
+ }
273
+ $themes_need_update = apply_filters('sc_wpun_themes_need_update', $themes_need_update); // additional filtering of themes need update
274
+ if(count($themes_need_update) >= 1) { // any themes need updating after all the filtering gone on above?
275
+ foreach($themes_need_update as $key => $data) { // loop through the themes that need updating
276
+ $theme_info = get_theme_data(WP_CONTENT_DIR . "/themes/" . $key . "/style.css"); // get theme info
277
+ $message .= sprintf(__("Theme: %s is out of date. Please update from version %s to %s", "wp-updates-notifier"), $theme_info['Name'], $theme_info['Version'], $data['new_version'])."\n";
278
+ $settings['notified']['theme'][$key] = $data['new_version']; // set theme version we are notifying about
279
+ }
280
+ update_option(self::$options_field, $settings); // save settings
281
+ return true; // we have theme updates return true
282
+ }
283
+ } else {
284
+ if(0 != count($settings['notified']['theme'])) { // is there any theme notifications?
285
+ $settings['notified']['theme'] = array(); // set theme notifications to empty as all themes up-to-date
286
+ update_option(self::$options_field, $settings); // save settings
287
+ }
288
+ }
289
+ return false; // No theme updates so return false
290
+ }
291
+
292
+
293
+ /**
294
+ * Filter for removing plugins from update list if already been notified about
295
+ *
296
+ * @param array $plugins_need_update
297
+ * @return array $plugins_need_update
298
+ */
299
+ public function check_plugins_against_notified($plugins_need_update) {
300
+ $settings = get_option(self::$options_field); // get settings
301
+ foreach($plugins_need_update as $key => $data) { // loop through plugins that need update
302
+ if(isset($settings['notified']['plugin'][$key])) { // has this plugin been notified before?
303
+ if($data->new_version == $settings['notified']['plugin'][$key]) { // does this plugin version match that of the one that's been notified?
304
+ unset($plugins_need_update[$key]); // don't notify this plugin as has already been notified
305
+ }
306
+ }
307
+ }
308
+ return $plugins_need_update;
309
+ }
310
+
311
+
312
+ /**
313
+ * Filter for removing themes from update list if already been notified about
314
+ *
315
+ * @param array $themes_need_update
316
+ * @return array $themes_need_update
317
+ */
318
+ public function check_themes_against_notified($themes_need_update) {
319
+ $settings = get_option(self::$options_field); // get settings
320
+ foreach($themes_need_update as $key => $data) { // loop through themes that need update
321
+ if(isset($settings['notified']['theme'][$key])) { // has this theme been notified before?
322
+ if($data['new_version'] == $settings['notified']['theme'][$key]) { // does this theme version match that of the one that's been notified?
323
+ unset($themes_need_update[$key]); // don't notify this theme as has already been notified
324
+ }
325
+ }
326
+ }
327
+ return $themes_need_update;
328
+ }
329
+
330
+
331
+ /**
332
+ * Sends email notification.
333
+ *
334
+ * @param string $message holds message to be sent in body of email
335
+ * @return void
336
+ */
337
+ public function send_notification_email($message) {
338
+ $settings = get_option(self::$options_field); // get settings
339
+ $subject = sprintf(__("WP Updates Notifier: Updates Available @ %s", "wp-updates-notifier"), site_url());
340
+ add_filter('wp_mail_from', array(&$this, 'sc_wpun_wp_mail_from')); // add from filter
341
+ add_filter('wp_mail_from_name', array(&$this, 'sc_wpun_wp_mail_from_name')); // add from name filter
342
+ add_filter('wp_mail_content_type', array(&$this, 'sc_wpun_wp_mail_content_type')); // add content type filter
343
+ wp_mail($settings['notify_to'], $subject, $message); // send email
344
+ remove_filter('wp_mail_from', array(&$this, 'sc_wpun_wp_mail_from')); // remove from filter
345
+ remove_filter('wp_mail_from_name', array(&$this, 'sc_wpun_wp_mail_from_name')); // remove from name filter
346
+ remove_filter('wp_mail_content_type', array(&$this, 'sc_wpun_wp_mail_content_type')); // remove content type filter
347
+ }
348
+ public function sc_wpun_wp_mail_from() { $settings = get_option(self::$options_field); return $settings['notify_from']; }
349
+ public function sc_wpun_wp_mail_from_name() { return __("WP Updates Notifier", "wp-updates-notifier"); }
350
+ public function sc_wpun_wp_mail_content_type() { return "text/plain"; }
351
+
352
+
353
+ /**
354
+ * Removes the update nag for non admin users.
355
+ *
356
+ * @return void
357
+ */
358
+ public function remove_update_nag_for_nonadmins() {
359
+ $settings = get_option(self::$options_field); // get settings
360
+ if(1 == $settings['hide_updates']) { // is this enabled?
361
+ if (!current_user_can('update_plugins')) { // can the current user update plugins?
362
+ remove_action('admin_notices', 'update_nag', 3); // no they cannot so remove the nag for them.
363
+ }
364
+ }
365
+ }
366
+
367
+
368
+
369
+ /*
370
+ * EVERYTHING SETTINGS
371
+ *
372
+ * I'm not going to comment any of this as its all pretty
373
+ * much straight forward use of the WordPress Settings API.
374
+ */
375
+ public function admin_settings_menu() {
376
+ $page = add_options_page('WP Updates Notifier', 'WP Updates Notifier', 'manage_options', 'wp-updates-notifier', array(&$this, 'settings_page'));
377
+ }
378
+ public function settings_page() {
379
+ ?>
380
+ <div class="wrap">
381
+ <?php screen_icon(); ?>
382
+ <h2><?php _e("WP Updates Notifier", "wp-updates-notifier"); ?></h2>
383
+ <form action="options.php" method="post">
384
+ <?php
385
+ settings_fields("sc_wpun_settings");
386
+ do_settings_sections("wp-updates-notifier");
387
+ ?>
388
+ <input class="button-primary" name="Submit" type="submit" value="<?php _e("Save Changes", "wp-updates-notifier"); ?>" />
389
+ </form>
390
+ </div>
391
+ <?php
392
+ }
393
+ public function admin_settings_init() {
394
+ register_setting(self::$options_field, self::$options_field, array(&$this, "sc_wpun_settings_validate")); // Register Main Settings
395
+ add_settings_section("sc_wpun_settings_main", __("Settings", "wp-updates-notifier"), array(&$this, "sc_wpun_settings_main_text"), "wp-updates-notifier"); // Make settings main section
396
+ add_settings_field("sc_wpun_settings_main_frequency", __("Frequency to check", "wp-updates-notifier"), array(&$this, "sc_wpun_settings_main_field_frequency"), "wp-updates-notifier", "sc_wpun_settings_main");
397
+ add_settings_field("sc_wpun_settings_main_notify_to", __("Notify email to", "wp-updates-notifier"), array(&$this, "sc_wpun_settings_main_field_notify_to"), "wp-updates-notifier", "sc_wpun_settings_main");
398
+ add_settings_field("sc_wpun_settings_main_notify_from", __("Notify email from", "wp-updates-notifier"), array(&$this, "sc_wpun_settings_main_field_notify_from"), "wp-updates-notifier", "sc_wpun_settings_main");
399
+ add_settings_field("sc_wpun_settings_main_notify_plugins", __("Notify about plugin updates?", "wp-updates-notifier"), array(&$this, "sc_wpun_settings_main_field_notify_plugins"), "wp-updates-notifier", "sc_wpun_settings_main");
400
+ add_settings_field("sc_wpun_settings_main_notify_themes", __("Notify about theme updates?", "wp-updates-notifier"), array(&$this, "sc_wpun_settings_main_field_notify_themes"), "wp-updates-notifier", "sc_wpun_settings_main");
401
+ add_settings_field("sc_wpun_settings_main_hide_updates", __("Hide core WP update nag from non-admin users?", "wp-updates-notifier"), array(&$this, "sc_wpun_settings_main_field_hide_updates"), "wp-updates-notifier", "sc_wpun_settings_main");
402
+ }
403
+ public function sc_wpun_settings_validate($input) {
404
+ $valid = get_option(self::$options_field);
405
+
406
+ if(in_array($input['frequency'], self::$frequency_intervals)) {
407
+ $valid['frequency'] = $input['frequency'];
408
+ do_action("sc_wpun_enable_cron", $input['frequency']);
409
+ } else {
410
+ add_settings_error("sc_wpun_settings_main_frequency", "sc_wpun_settings_main_frequency_error", __("Invalid frequency entered", "wp-updates-notifier"), "error");
411
+ }
412
+
413
+ $sanitized_email_to = sanitize_email($input['notify_to']);
414
+ if(is_email($sanitized_email_to)) {
415
+ $valid['notify_to'] = $sanitized_email_to;
416
+ } else {
417
+ add_settings_error("sc_wpun_settings_main_notify_to", "sc_wpun_settings_main_notify_to_error", __("Invalid email to entered", "wp-updates-notifier"), "error");
418
+ }
419
+
420
+ $sanitized_email_from = sanitize_email($input['notify_from']);
421
+ if(is_email($sanitized_email_from)) {
422
+ $valid['notify_from'] = $sanitized_email_from;
423
+ } else {
424
+ add_settings_error("sc_wpun_settings_main_notify_from", "sc_wpun_settings_main_notify_from_error", __("Invalid email from entered", "wp-updates-notifier"), "error");
425
+ }
426
+
427
+ $sanitized_notify_plugins = absint($input['notify_plugins']);
428
+ if($sanitized_notify_plugins >= 0 && $sanitized_notify_plugins <= 2) {
429
+ $valid['notify_plugins'] = $sanitized_notify_plugins;
430
+ } else {
431
+ add_settings_error("sc_wpun_settings_main_notify_plugins", "sc_wpun_settings_main_notify_plugins_error", __("Invalid plugin updates value entered", "wp-updates-notifier"), "error");
432
+ }
433
+
434
+ $sanitized_notify_themes = absint($input['notify_themes']);
435
+ if($sanitized_notify_themes >= 0 && $sanitized_notify_themes <= 2) {
436
+ $valid['notify_themes'] = $sanitized_notify_themes;
437
+ } else {
438
+ add_settings_error("sc_wpun_settings_main_notify_themes", "sc_wpun_settings_main_notify_themes_error", __("Invalid theme updates value entered", "wp-updates-notifier"), "error");
439
+ }
440
+
441
+ $sanitized_hide_updates = absint($input['hide_updates']);
442
+ if($sanitized_hide_updates <= 1) {
443
+ $valid['hide_updates'] = $sanitized_hide_updates;
444
+ } else {
445
+ add_settings_error("sc_wpun_settings_main_hide_updates", "sc_wpun_settings_main_hide_updates_error", __("Invalid hide updates value entered", "wp-updates-notifier"), "error");
446
+ }
447
+ return $valid;
448
+ }
449
+ public function sc_wpun_settings_main_text() {}
450
+ public function sc_wpun_settings_main_field_frequency() {
451
+ $options = get_option(self::$options_field);
452
+ ?>
453
+ <select id="sc_wpun_settings_main_frequency" name="<?php echo self::$options_field; ?>[frequency]">
454
+ <option value="<?php echo self::$frequency_intervals[0]; ?>" <?php selected( $options['frequency'], self::$frequency_intervals[0] ); ?>><?php _e("Hourly", "wp-updates-notifier"); ?></option>
455
+ <option value="<?php echo self::$frequency_intervals[1]; ?>" <?php selected( $options['frequency'], self::$frequency_intervals[1] ); ?>><?php _e("Twice Daily", "wp-updates-notifier"); ?></option>
456
+ <option value="<?php echo self::$frequency_intervals[2]; ?>" <?php selected( $options['frequency'], self::$frequency_intervals[2] ); ?>><?php _e("Daily", "wp-updates-notifier"); ?></option>
457
+ <select>
458
+ <?php
459
+ }
460
+ public function sc_wpun_settings_main_field_notify_to() {
461
+ $options = get_option(self::$options_field);
462
+ ?><input id="sc_wpun_settings_main_notify_to" class="regular-text" name="<?php echo self::$options_field; ?>[notify_to]" value="<?php echo $options['notify_to']; ?>" /><?php
463
+ }
464
+ public function sc_wpun_settings_main_field_notify_from() {
465
+ $options = get_option(self::$options_field);
466
+ ?><input id="sc_wpun_settings_main_notify_from" class="regular-text" name="<?php echo self::$options_field; ?>[notify_from]" value="<?php echo $options['notify_from']; ?>" /><?php
467
+ }
468
+ public function sc_wpun_settings_main_field_notify_plugins() {
469
+ $options = get_option(self::$options_field);
470
+ ?>
471
+ <label><input name="<?php echo self::$options_field; ?>[notify_plugins]" type="radio" value="0" <?php checked( $options['notify_plugins'], 0 ); ?> /> <?php _e("No", "wp-updates-notifier"); ?></label><br />
472
+ <label><input name="<?php echo self::$options_field; ?>[notify_plugins]" type="radio" value="1" <?php checked( $options['notify_plugins'], 1 ); ?> /> <?php _e("Yes", "wp-updates-notifier"); ?></label><br />
473
+ <label><input name="<?php echo self::$options_field; ?>[notify_plugins]" type="radio" value="2" <?php checked( $options['notify_plugins'], 2 ); ?> /> <?php _e("Yes but only active plugins", "wp-updates-notifier"); ?></label>
474
+ <?php
475
+ }
476
+ public function sc_wpun_settings_main_field_notify_themes() {
477
+ $options = get_option(self::$options_field);
478
+ ?>
479
+ <label><input name="<?php echo self::$options_field; ?>[notify_themes]" type="radio" value="0" <?php checked( $options['notify_themes'], 0 ); ?> /> <?php _e("No", "wp-updates-notifier"); ?></label><br />
480
+ <label><input name="<?php echo self::$options_field; ?>[notify_themes]" type="radio" value="1" <?php checked( $options['notify_themes'], 1 ); ?> /> <?php _e("Yes", "wp-updates-notifier"); ?></label><br />
481
+ <label><input name="<?php echo self::$options_field; ?>[notify_themes]" type="radio" value="2" <?php checked( $options['notify_themes'], 2 ); ?> /> <?php _e("Yes but only active themes", "wp-updates-notifier"); ?></label>
482
+ <?php
483
+ }
484
+ public function sc_wpun_settings_main_field_hide_updates() {
485
+ $options = get_option(self::$options_field);
486
+ ?>
487
+ <select id="sc_wpun_settings_main_hide_updates" name="<?php echo self::$options_field; ?>[hide_updates]">
488
+ <option value="1" <?php selected( $options['hide_updates'], 1 ); ?>><?php _e("Yes", "wp-updates-notifier"); ?></option>
489
+ <option value="0" <?php selected( $options['hide_updates'], 0 ); ?>><?php _e("No", "wp-updates-notifier"); ?></option>
490
+ <select>
491
+ <?php
492
+ }
493
+ /**** END EVERYTHING SETTINGS ****/
494
+ }
495
+ }
496
+
497
+
498
+ // Create Instance of WPUN Class
499
+ if (!isset($sc_wpun) && function_exists('add_action')) {
500
+ $sc_wpun = new sc_WPUpdatesNotifier();
501
+ }
502
+ ?>