PluginProbe
Plugins Condition & Site Check / 1.07
Plugins Condition & Site Check v1.07
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 1.07, at lib/class-pluginsconditionadmin.php

279 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugins Condition
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 $pluginsconditionadmin = new PluginsConditionAdmin();
24
25 /** ==================================================
26 * Management screen
27 */
28 class PluginsConditionAdmin {
29
30 /** ==================================================
31 * Construct
32 *
33 * @since 1.14
34 */
35 public function __construct() {
36
37 add_action( 'init', array( $this, 'register_settings' ) );
38
39 add_action( 'admin_menu', array( $this, 'plugin_menu' ) );
40 add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
41
42 }
43
44 /** ==================================================
45 * Add a "Settings" link to the plugins page
46 *
47 * @param array $links links array.
48 * @param string $file file.
49 * @return array $links links array.
50 * @since 1.00
51 */
52 public function settings_link( $links, $file ) {
53 static $this_plugin;
54 if ( empty( $this_plugin ) ) {
55 $this_plugin = 'plugins-condition/pluginscondition.php';
56 }
57 if ( $file == $this_plugin ) {
58 $links[] = '<a href="' . admin_url( 'options-general.php?page=PluginsCondition' ) . '">' . __( 'Settings' ) . '</a>';
59 }
60 return $links;
61 }
62
63 /** ==================================================
64 * Settings page
65 *
66 * @since 1.01
67 */
68 public function plugin_menu() {
69 add_options_page( 'PluginsCondition Options', 'Plugins Condition', 'manage_options', 'PluginsCondition', array( $this, 'plugin_options' ) );
70 }
71
72 /** ==================================================
73 * Settings page
74 *
75 * @since 1.01
76 */
77 public function plugin_options() {
78
79 if ( ! current_user_can( 'manage_options' ) ) {
80 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
81 }
82
83 $this->options_updated();
84
85 $scriptname = admin_url( 'options-general.php?page=PluginsCondition' );
86 $plg_cond_notify_interval = get_option( 'plg_cond_notify_interval', 30 );
87
88 ?>
89 <div class="wrap">
90 <h2>Plugins Condition</h2>
91
92 <details>
93 <summary><strong><?php esc_html_e( 'Various links of this plugin', 'plugins-condition' ); ?></strong></summary>
94 <?php $this->credit(); ?>
95 </details>
96
97 <form style="padding:10px;" method="post" action="<?php echo esc_url( $scriptname ); ?>" />
98 <?php wp_nonce_field( 'plg_cond_settings', 'pluginscondition_settings' ); ?>
99 <div style="margin: 5px; padding: 5px;">
100 <h3><?php esc_html_e( 'E-mail notification interval', 'plugins-condition' ); ?></h3>
101 <p class="description">
102 <?php esc_html_e( 'Specifies the notification interval of the email to notify the plugin status.', 'plugins-condition' ); ?>
103 </p>
104 <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' ); ?>
105 <?php submit_button( __( 'Save Changes' ), 'large', 'plg-settings-apply', true ); ?>
106 </div>
107 <hr>
108 <div style="margin: 5px; padding: 5px;">
109 <h3><?php esc_html_e( 'Remove Cache', 'plugins-condition' ); ?></h3>
110 <p class="description">
111 <?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' ); ?>
112 </p>
113 <?php submit_button( __( 'Remove Cache', 'plugins-condition' ), 'large', 'plg-cache-remove', true ); ?>
114 </div>
115 </form>
116
117 </div>
118 <?php
119 }
120
121 /** ==================================================
122 * Credit
123 *
124 * @since 1.00
125 */
126 private function credit() {
127
128 $plugin_name = null;
129 $plugin_ver_num = null;
130 $plugin_path = plugin_dir_path( __DIR__ );
131 $plugin_dir = untrailingslashit( wp_normalize_path( $plugin_path ) );
132 $slugs = explode( '/', $plugin_dir );
133 $slug = end( $slugs );
134 $files = scandir( $plugin_dir );
135 foreach ( $files as $file ) {
136 if ( '.' === $file || '..' === $file || is_dir( $plugin_path . $file ) ) {
137 continue;
138 } else {
139 $exts = explode( '.', $file );
140 $ext = strtolower( end( $exts ) );
141 if ( 'php' === $ext ) {
142 $plugin_datas = get_file_data(
143 $plugin_path . $file,
144 array(
145 'name' => 'Plugin Name',
146 'version' => 'Version',
147 )
148 );
149 if ( array_key_exists( 'name', $plugin_datas ) && ! empty( $plugin_datas['name'] ) && array_key_exists( 'version', $plugin_datas ) && ! empty( $plugin_datas['version'] ) ) {
150 $plugin_name = $plugin_datas['name'];
151 $plugin_ver_num = $plugin_datas['version'];
152 break;
153 }
154 }
155 }
156 }
157 $plugin_version = __( 'Version:' ) . ' ' . $plugin_ver_num;
158 /* translators: FAQ Link & Slug */
159 $faq = sprintf( __( 'https://wordpress.org/plugins/%s/faq', 'plugins-condition' ), $slug );
160 $support = 'https://wordpress.org/support/plugin/' . $slug;
161 $review = 'https://wordpress.org/support/view/plugin-reviews/' . $slug;
162 $translate = 'https://translate.wordpress.org/projects/wp-plugins/' . $slug;
163 $facebook = 'https://www.facebook.com/katsushikawamori/';
164 $twitter = 'https://twitter.com/dodesyo312';
165 $youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w';
166 $donate = __( 'https://shop.riverforest-wp.info/donate/', 'plugins-condition' );
167
168 ?>
169 <span style="font-weight: bold;">
170 <div>
171 <?php echo esc_html( $plugin_version ); ?> |
172 <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>
173 </div>
174 <div>
175 <a style="text-decoration: none;" href="<?php echo esc_url( $translate ); ?>" target="_blank" rel="noopener noreferrer">
176 <?php
177 /* translators: Plugin translation link */
178 echo esc_html( sprintf( __( 'Translations for %s' ), $plugin_name ) );
179 ?>
180 </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>
181 </div>
182 </span>
183
184 <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
185 <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>
186 <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>
187 <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;' ); ?></button>
188 </div>
189
190 <?php
191
192 }
193
194 /** ==================================================
195 * Update wp_options table.
196 *
197 * @since 1.00
198 */
199 private function options_updated() {
200
201 if ( isset( $_POST['plg-settings-apply'] ) && ! empty( $_POST['plg-settings-apply'] ) ) {
202 if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_settings' ) ) {
203 if ( ! empty( $_POST['pc_notify_interval'] ) ) {
204 do_action( 'plugins_condition_notify_cron_stop' );
205 update_option( 'plg_cond_notify_interval', intval( $_POST['pc_notify_interval'] ) );
206 do_action( 'plugins_condition_notify_cron_start' );
207 echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Settings' ) . ' --> ' . __( 'Settings saved.' ) ) . '</li></ul></div>';
208 }
209 }
210 }
211
212 if ( isset( $_POST['plg-cache-remove'] ) && ! empty( $_POST['plg-cache-remove'] ) ) {
213 if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_settings' ) ) {
214 $del_cash_count = $this->delete_all_cash();
215 if ( 0 < $del_cash_count ) {
216 echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Removed the cache.', 'plugins-condition' ) . '</li></ul></div>';
217 } else {
218 echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No Cache', 'plugins-condition' ) . '</li></ul></div>';
219 }
220 }
221 }
222
223 }
224
225 /** ==================================================
226 * Delete all cache
227 *
228 * @return int $del_cash_count(int)
229 * @since 1.00
230 */
231 private function delete_all_cash() {
232
233 global $wpdb;
234 $search_transients = '%plg_cond_datas_%';
235 $del_transients = $wpdb->get_results(
236 $wpdb->prepare(
237 "
238 SELECT option_name
239 FROM {$wpdb->prefix}options
240 WHERE option_name LIKE %s
241 ",
242 $search_transients
243 )
244 );
245
246 $del_cash_count = 0;
247 foreach ( $del_transients as $del_transient ) {
248 $transient = str_replace( '_transient_', '', $del_transient->option_name );
249 $value_del_cash = get_transient( $transient );
250 if ( false <> $value_del_cash ) {
251 delete_transient( $transient );
252 ++$del_cash_count;
253 }
254 }
255
256 return $del_cash_count;
257
258 }
259
260 /** ==================================================
261 * Settings register
262 *
263 * @since 1.07
264 */
265 public function register_settings() {
266
267 if ( ! get_option( 'plg_cond_notify_interval' ) ) {
268 /* ver 1.06 -> 1.07 */
269 do_action( 'plugins_condition_notify_cron_stop' );
270 update_option( 'plg_cond_notify_interval', 30 );
271 do_action( 'plugins_condition_notify_cron_start' );
272 }
273
274 }
275
276 }
277
278
279