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

284 lines 10.0 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( 'admin_menu', array( $this, 'plugin_menu' ) );
38 add_action( 'admin_enqueue_scripts', array( $this, 'load_custom_wp_admin_style' ) );
39 add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
40
41 }
42
43 /** ==================================================
44 * Add a "Settings" link to the plugins page
45 *
46 * @param array $links links array.
47 * @param string $file file.
48 * @return array $links links array.
49 * @since 1.00
50 */
51 public function settings_link( $links, $file ) {
52 static $this_plugin;
53 if ( empty( $this_plugin ) ) {
54 $this_plugin = 'plugins-condition/pluginscondition.php';
55 }
56 if ( $file == $this_plugin ) {
57 $links[] = '<a href="' . admin_url( 'options-general.php?page=PluginsCondition' ) . '">' . __( 'Settings' ) . '</a>';
58 }
59 return $links;
60 }
61
62 /** ==================================================
63 * Settings page
64 *
65 * @since 1.01
66 */
67 public function plugin_menu() {
68 add_options_page( 'PluginsCondition Options', 'Plugins Condition', 'manage_options', 'PluginsCondition', array( $this, 'plugin_options' ) );
69 }
70
71 /** ==================================================
72 * Add Css and Script
73 *
74 * @since 1.01
75 */
76 public function load_custom_wp_admin_style() {
77 if ( $this->is_my_plugin_screen() ) {
78 wp_enqueue_style( 'jquery-responsiveTabs', plugin_dir_url( __DIR__ ) . 'css/responsive-tabs.css', array(), '1.4.0' );
79 wp_enqueue_style( 'jquery-responsiveTabs-style', plugin_dir_url( __DIR__ ) . 'css/style.css', array(), '1.4.0' );
80 wp_enqueue_script( 'jquery' );
81 wp_enqueue_script( 'jquery-responsiveTabs', plugin_dir_url( __DIR__ ) . 'js/jquery.responsiveTabs.min.js', array(), '1.4.0', false );
82 wp_enqueue_script( 'pluginscondition-js', plugin_dir_url( __DIR__ ) . 'js/jquery.pluginscondition.admin.js', array( 'jquery' ), '1.00', false );
83 }
84 }
85
86 /** ==================================================
87 * For only admin style
88 *
89 * @since 1.01
90 */
91 private function is_my_plugin_screen() {
92 $screen = get_current_screen();
93 if ( is_object( $screen ) && 'settings_page_PluginsCondition' == $screen->id ) {
94 return true;
95 } else {
96 return false;
97 }
98 }
99
100 /** ==================================================
101 * Settings page
102 *
103 * @since 1.01
104 */
105 public function plugin_options() {
106
107 if ( ! current_user_can( 'manage_options' ) ) {
108 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
109 }
110
111 $this->options_updated();
112
113 $scriptname = admin_url( 'options-general.php?page=PluginsCondition' );
114
115 ?>
116 <div class="wrap">
117 <h2>PluginsCondition</h2>
118 <div id="pluginscondition-tabs">
119 <ul>
120 <li><a href="#pluginscondition-tabs-1"><?php esc_html_e( 'Remove Cache', 'plugins-condition' ); ?></a></li>
121 <li><a href="#pluginscondition-tabs-2"><?php esc_html_e( 'Donate to this plugin &#187;' ); ?></a></li>
122 </ul>
123 <div id="pluginscondition-tabs-1">
124 <div class="wrap">
125 <h2><?php esc_html_e( 'Remove Cache', 'plugins-condition' ); ?></h2>
126 <div style="padding:10px;">
127 <h3><?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' ); ?></h3>
128
129 <form style="padding:10px;" method="post" action="<?php echo esc_url( $scriptname ); ?>" />
130 <?php wp_nonce_field( 'plg_cond_settings', 'pluginscondition_tabs' ); ?>
131 <input type="hidden" name="plg_cond_clear_cash" value="1" />
132 <?php submit_button( __( 'Remove Cache', 'plugins-condition' ), 'large', 'Submit', false ); ?>
133 </form>
134 </div>
135 </div>
136 </div>
137
138 <div id="pluginscondition-tabs-2">
139 <div class="wrap">
140 <?php $this->credit(); ?>
141 </div>
142 </div>
143
144 </div>
145 </div>
146 <?php
147 }
148
149 /** ==================================================
150 * Credit
151 *
152 * @since 1.00
153 */
154 private function credit() {
155
156 $plugin_name = null;
157 $plugin_ver_num = null;
158 $plugin_path = plugin_dir_path( __DIR__ );
159 $plugin_dir = untrailingslashit( $plugin_path );
160 $slugs = explode( '/', $plugin_dir );
161 $slug = end( $slugs );
162 $files = scandir( $plugin_dir );
163 foreach ( $files as $file ) {
164 if ( '.' === $file || '..' === $file || is_dir( $plugin_path . $file ) ) {
165 continue;
166 } else {
167 $exts = explode( '.', $file );
168 $ext = strtolower( end( $exts ) );
169 if ( 'php' === $ext ) {
170 $plugin_datas = get_file_data(
171 $plugin_path . $file,
172 array(
173 'name' => 'Plugin Name',
174 'version' => 'Version',
175 )
176 );
177 if ( array_key_exists( 'name', $plugin_datas ) && ! empty( $plugin_datas['name'] ) && array_key_exists( 'version', $plugin_datas ) && ! empty( $plugin_datas['version'] ) ) {
178 $plugin_name = $plugin_datas['name'];
179 $plugin_ver_num = $plugin_datas['version'];
180 break;
181 }
182 }
183 }
184 }
185 $plugin_version = __( 'Version:' ) . ' ' . $plugin_ver_num;
186 /* translators: FAQ Link & Slug */
187 $faq = sprintf( esc_html__( 'https://wordpress.org/plugins/%s/faq', '%s' ), $slug );
188 $support = 'https://wordpress.org/support/plugin/' . $slug;
189 $review = 'https://wordpress.org/support/view/plugin-reviews/' . $slug;
190 $translate = 'https://translate.wordpress.org/projects/wp-plugins/' . $slug;
191 $facebook = 'https://www.facebook.com/katsushikawamori/';
192 $twitter = 'https://twitter.com/dodesyo312';
193 $youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w';
194 $donate = sprintf( esc_html__( 'https://shop.riverforest-wp.info/donate/', '%s' ), $slug );
195
196 ?>
197 <span style="font-weight: bold;">
198 <div>
199 <?php echo esc_html( $plugin_version ); ?> |
200 <a style="text-decoration: none;" href="<?php echo esc_url( $faq ); ?>" target="_blank"><?php esc_html_e( 'FAQ' ); ?></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $support ); ?>" target="_blank"><?php esc_html_e( 'Support Forums' ); ?></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $review ); ?>" target="_blank"><?php sprintf( esc_html_e( 'Reviews', '%s' ), $slug ); ?></a>
201 </div>
202 <div>
203 <a style="text-decoration: none;" href="<?php echo esc_url( $translate ); ?>" target="_blank">
204 <?php
205 /* translators: Plugin translation link */
206 echo sprintf( esc_html__( 'Translations for %s' ), esc_html( $plugin_name ) );
207 ?>
208 </a> | <a style="text-decoration: none;" href="<?php echo esc_url( $facebook ); ?>" target="_blank"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $twitter ); ?>" target="_blank"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $youtube ); ?>" target="_blank"><span class="dashicons dashicons-video-alt3"></span></a>
209 </div>
210 </span>
211
212 <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
213 <h3><?php sprintf( esc_html_e( 'Please make a donation if you like my work or would like to further the development of this plugin.', '%s' ), $slug ); ?></h3>
214 <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>
215 <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>
216 </div>
217
218 <?php
219
220 }
221
222 /** ==================================================
223 * Update wp_options table.
224 *
225 * @since 1.00
226 */
227 private function options_updated() {
228
229 if ( ! empty( $_POST ) ) {
230 if ( isset( $_POST['pluginscondition_tabs'] ) && ! empty( $_POST['pluginscondition_tabs'] ) ) {
231 if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_tabs' ) ) {
232 if ( ! empty( $_POST['plg_cond_clear_cash'] ) ) {
233 $del_cash_count = $this->delete_all_cash();
234 if ( 0 < $del_cash_count ) {
235 echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Removed the cache.', 'plugins-condition' ) . '</li></ul></div>';
236 } else {
237 echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No Cache', 'plugins-condition' ) . '</li></ul></div>';
238 }
239 }
240 }
241 }
242 }
243
244 }
245
246 /** ==================================================
247 * Delete all cache
248 *
249 * @return int $del_cash_count(int)
250 * @since 1.00
251 */
252 private function delete_all_cash() {
253
254 global $wpdb;
255 $search_transients = '%plg_cond_datas_%';
256 $del_transients = $wpdb->get_results(
257 $wpdb->prepare(
258 "
259 SELECT option_name
260 FROM $wpdb->options
261 WHERE option_name LIKE %s
262 ",
263 $search_transients
264 )
265 );
266
267 $del_cash_count = 0;
268 foreach ( $del_transients as $del_transient ) {
269 $transient = str_replace( '_transient_', '', $del_transient->option_name );
270 $value_del_cash = get_transient( $transient );
271 if ( false <> $value_del_cash ) {
272 delete_transient( $transient );
273 ++$del_cash_count;
274 }
275 }
276
277 return $del_cash_count;
278
279 }
280
281 }
282
283
284