PluginProbe
Plugins Condition & Site Check / trunk
Plugins Condition & Site Check vtrunk
2.01 trunk 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 2.00
plugins-condition / lib / class-pluginsconditionadmin.php

class-pluginsconditionadmin.php in Plugins Condition & Site Check trunk, at lib/class-pluginsconditionadmin.php

301 lines 11.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugins Condition & Site Check
4 *
5 * @package Plugins Condition
6 * @subpackage PluginsConditionAdmin Management screen
7 /*
8 Copyright (c) 2019- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 $pluginsconditionadmin = new PluginsConditionAdmin();
28
29 /** ==================================================
30 * Management screen
31 */
32 class PluginsConditionAdmin {
33
34 /** ==================================================
35 * Construct
36 *
37 * @since 1.14
38 */
39 public function __construct() {
40
41 add_action( 'init', array( $this, 'register_settings' ) );
42
43 add_action( 'admin_menu', array( $this, 'plugin_menu' ) );
44 add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
45 }
46
47 /** ==================================================
48 * Add a "Settings" link to the plugins page
49 *
50 * @param array $links links array.
51 * @param string $file file.
52 * @return array $links links array.
53 * @since 1.00
54 */
55 public function settings_link( $links, $file ) {
56 static $this_plugin;
57 if ( empty( $this_plugin ) ) {
58 $this_plugin = 'plugins-condition/pluginscondition.php';
59 }
60 if ( $file == $this_plugin ) {
61 $links[] = '<a href="' . admin_url( 'options-general.php?page=PluginsCondition' ) . '">' . __( 'Settings', 'plugins-condition' ) . '</a>';
62 }
63 return $links;
64 }
65
66 /** ==================================================
67 * Settings page
68 *
69 * @since 1.01
70 */
71 public function plugin_menu() {
72 add_options_page( 'PluginsCondition Options', 'Plugins Condition & Site Check', 'manage_options', 'PluginsCondition', array( $this, 'plugin_options' ) );
73 }
74
75 /** ==================================================
76 * Settings page
77 *
78 * @since 1.01
79 */
80 public function plugin_options() {
81
82 if ( ! current_user_can( 'manage_options' ) ) {
83 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'plugins-condition' ) );
84 }
85
86 $this->options_updated();
87
88 $scriptname = admin_url( 'options-general.php?page=PluginsCondition' );
89 $plg_cond_notify_interval = get_option( 'plg_cond_notify_interval', 30 );
90
91 $next_notify = null;
92 $event = wp_get_scheduled_event( 'plugins_condition_notify_cron' );
93 if ( $event ) {
94 $next_day = wp_date( 'Y/m/d H:i:s', $event->timestamp, wp_timezone() );
95 /* translators: days later */
96 $next_interval_days = sprintf( __( '%d days later', 'plugins-condition' ), $event->interval / DAY_IN_SECONDS );
97 $next_notify = $next_day . ' (' . $next_interval_days . ')';
98 } else {
99 $next_notify = __( 'No notification interval has been set.', 'plugins-condition' );
100 }
101
102 ?>
103 <div class="wrap">
104 <h2>Plugins Condition & Site Check</h2>
105
106 <details>
107 <summary><strong><?php esc_html_e( 'Various links of this plugin', 'plugins-condition' ); ?></strong></summary>
108 <?php $this->credit(); ?>
109 </details>
110
111 <form style="padding:10px;" method="post" action="<?php echo esc_url( $scriptname ); ?>" />
112 <?php wp_nonce_field( 'plg_cond_settings', 'pluginscondition_settings' ); ?>
113 <div style="margin: 5px; padding: 5px;">
114 <h3><?php esc_html_e( 'E-mail notification interval', 'plugins-condition' ); ?></h3>
115 <p class="description">
116 <?php esc_html_e( 'Specifies the notification interval of the email to notify the plugin status.', 'plugins-condition' ); ?>
117 </p>
118 <input type="number" name="pc_notify_interval" min="1" max="90" value="<?php echo esc_attr( $plg_cond_notify_interval ); ?>">&nbsp;&nbsp;<?php esc_html_e( 'days', 'plugins-condition' ); ?>
119 <div style="padding: 5px;">
120 <strong><?php esc_html_e( 'Next Notice', 'plugins-condition' ); ?> : <?php echo esc_html( $next_notify ); ?></strong>
121 </div>
122 <div style="display: flex; gap: 10px;">
123 <?php submit_button( __( 'Save Changes', 'plugins-condition' ), 'large', 'plg-settings-apply', true ); ?>
124 <?php submit_button( __( 'Force Email Send', 'plugins-condition' ), 'large', 'plg-cron-run', true ); ?>
125 </div>
126 </div>
127 <hr>
128 <div style="margin: 5px; padding: 5px;">
129 <h3><?php esc_html_e( 'Remove Cache', 'plugins-condition' ); ?></h3>
130 <p class="description">
131 <?php esc_html_e( 'It will create a cache in one-day intervals for speedup. Please delete the cache if you want to display the most recent data.', 'plugins-condition' ); ?>
132 </p>
133 <?php submit_button( __( 'Remove Cache', 'plugins-condition' ), 'large', 'plg-cache-remove', true ); ?>
134 </div>
135 </form>
136
137 </div>
138 <?php
139 }
140
141 /** ==================================================
142 * Credit
143 *
144 * @since 1.00
145 */
146 private function credit() {
147
148 $plugin_name = null;
149 $plugin_ver_num = null;
150 $plugin_path = plugin_dir_path( __DIR__ );
151 $plugin_dir = untrailingslashit( wp_normalize_path( $plugin_path ) );
152 $slugs = explode( '/', $plugin_dir );
153 $slug = end( $slugs );
154 $files = scandir( $plugin_dir );
155 foreach ( $files as $file ) {
156 if ( '.' === $file || '..' === $file || is_dir( $plugin_path . $file ) ) {
157 continue;
158 } else {
159 $exts = explode( '.', $file );
160 $ext = strtolower( end( $exts ) );
161 if ( 'php' === $ext ) {
162 $plugin_datas = get_file_data(
163 $plugin_path . $file,
164 array(
165 'name' => 'Plugin Name',
166 'version' => 'Version',
167 )
168 );
169 if ( array_key_exists( 'name', $plugin_datas ) && ! empty( $plugin_datas['name'] ) && array_key_exists( 'version', $plugin_datas ) && ! empty( $plugin_datas['version'] ) ) {
170 $plugin_name = $plugin_datas['name'];
171 $plugin_ver_num = $plugin_datas['version'];
172 break;
173 }
174 }
175 }
176 }
177 $plugin_version = __( 'Version:', 'plugins-condition' ) . ' ' . $plugin_ver_num;
178 /* translators: FAQ Link & Slug */
179 $faq = sprintf( __( 'https://wordpress.org/plugins/%s/faq', 'plugins-condition' ), $slug );
180 $support = 'https://wordpress.org/support/plugin/' . $slug;
181 $review = 'https://wordpress.org/support/view/plugin-reviews/' . $slug;
182 $translate = 'https://translate.wordpress.org/projects/wp-plugins/' . $slug;
183 $facebook = 'https://www.facebook.com/katsushikawamori/';
184 $twitter = 'https://twitter.com/dodesyo312';
185 $youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w';
186 $donate = __( 'https://shop.riverforest-wp.info/donate/', 'plugins-condition' );
187
188 ?>
189 <span style="font-weight: bold;">
190 <div>
191 <?php echo esc_html( $plugin_version ); ?> |
192 <a style="text-decoration: none;" href="<?php echo esc_url( $faq ); ?>" target="_blank" rel="noopener noreferrer">FAQ</a> | <a style="text-decoration: none;" href="<?php echo esc_url( $support ); ?>" target="_blank" rel="noopener noreferrer">Support Forums</a> | <a style="text-decoration: none;" href="<?php echo esc_url( $review ); ?>" target="_blank" rel="noopener noreferrer">Reviews</a>
193 </div>
194 <div>
195 <a style="text-decoration: none;" href="<?php echo esc_url( $translate ); ?>" target="_blank" rel="noopener noreferrer">
196 <?php
197 /* translators: Plugin translation link */
198 echo esc_html( sprintf( __( 'Translations for %s', 'plugins-condition' ), $plugin_name ) );
199 ?>
200 </a> | <a style="text-decoration: none;" href="<?php echo esc_url( $facebook ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $twitter ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $youtube ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-video-alt3"></span></a>
201 </div>
202 </span>
203
204 <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
205 <h3><?php esc_html_e( 'Please make a donation if you like my work or would like to further the development of this plugin.', 'plugins-condition' ); ?></h3>
206 <div style="text-align: right; margin: 5px; padding: 5px;"><span style="padding: 3px; color: #ffffff; background-color: #008000">Plugin Author</span> <span style="font-weight: bold;">Katsushi Kawamori</span></div>
207 <button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo esc_url( $donate ); ?>')"><?php esc_html_e( 'Donate to this plugin &#187;', 'plugins-condition' ); ?></button>
208 </div>
209
210 <?php
211 }
212
213 /** ==================================================
214 * Update wp_options table.
215 *
216 * @since 1.00
217 */
218 private function options_updated() {
219
220 if ( isset( $_POST['plg-settings-apply'] ) && ! empty( $_POST['plg-settings-apply'] ) ) {
221 if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_settings' ) ) {
222 if ( ! empty( $_POST['pc_notify_interval'] ) ) {
223 do_action( 'plugins_condition_notify_cron_stop' );
224 update_option( 'plg_cond_notify_interval', intval( $_POST['pc_notify_interval'] ) );
225 do_action( 'plugins_condition_notify_cron_start' );
226 echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Settings', 'plugins-condition' ) . ' --> ' . __( 'Settings saved.', 'plugins-condition' ) ) . '</li></ul></div>';
227 }
228 }
229 }
230
231 if ( isset( $_POST['plg-cron-run'] ) && ! empty( $_POST['plg-cron-run'] ) ) {
232 if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_settings' ) ) {
233 do_action( 'plugins_condition_notify_cron_now' );
234 echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'The email has been sent.', 'plugins-condition' ) ) . '</li></ul></div>';
235 }
236 }
237
238 if ( isset( $_POST['plg-cache-remove'] ) && ! empty( $_POST['plg-cache-remove'] ) ) {
239 if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_settings' ) ) {
240 $del_cash_count = $this->delete_all_cash();
241 if ( 0 < $del_cash_count ) {
242 echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Removed the cache.', 'plugins-condition' ) . '</li></ul></div>';
243 } else {
244 echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No Cache', 'plugins-condition' ) . '</li></ul></div>';
245 }
246 }
247 }
248 }
249
250 /** ==================================================
251 * Delete all cache
252 *
253 * @return int $del_cash_count(int)
254 * @since 1.00
255 */
256 private function delete_all_cash() {
257
258 global $wpdb;
259 $search_transients = '%plg_cond_datas_%';
260 $del_transients = $wpdb->get_results(
261 $wpdb->prepare(
262 "
263 SELECT option_name
264 FROM {$wpdb->prefix}options
265 WHERE option_name LIKE %s
266 ",
267 $search_transients
268 )
269 );
270
271 $del_cash_count = 0;
272 foreach ( $del_transients as $del_transient ) {
273 $transient = str_replace( '_transient_', '', $del_transient->option_name );
274 $value_del_cash = get_transient( $transient );
275 if ( false <> $value_del_cash ) {
276 delete_transient( $transient );
277 ++$del_cash_count;
278 }
279 }
280
281 return $del_cash_count;
282 }
283
284 /** ==================================================
285 * Settings register
286 *
287 * @since 1.07
288 */
289 public function register_settings() {
290
291 if ( ! get_option( 'plg_cond_notify_interval' ) ) {
292 /* ver 1.06 -> 1.07 */
293 do_action( 'plugins_condition_notify_cron_stop' );
294 update_option( 'plg_cond_notify_interval', 30 );
295 do_action( 'plugins_condition_notify_cron_start' );
296 }
297 }
298 }
299
300
301