| 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 |
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', '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 |
?> |
| 92 |
<div class="wrap"> |
| 93 |
<h2>Plugins Condition</h2> |
| 94 |
|
| 95 |
<details> |
| 96 |
<summary><strong><?php esc_html_e( 'Various links of this plugin', 'plugins-condition' ); ?></strong></summary> |
| 97 |
<?php $this->credit(); ?> |
| 98 |
</details> |
| 99 |
|
| 100 |
<form style="padding:10px;" method="post" action="<?php echo esc_url( $scriptname ); ?>" /> |
| 101 |
<?php wp_nonce_field( 'plg_cond_settings', 'pluginscondition_settings' ); ?> |
| 102 |
<div style="margin: 5px; padding: 5px;"> |
| 103 |
<h3><?php esc_html_e( 'E-mail notification interval', 'plugins-condition' ); ?></h3> |
| 104 |
<p class="description"> |
| 105 |
<?php esc_html_e( 'Specifies the notification interval of the email to notify the plugin status.', 'plugins-condition' ); ?> |
| 106 |
</p> |
| 107 |
<input type="number" name="pc_notify_interval" min="1" max="90" value="<?php echo esc_attr( $plg_cond_notify_interval ); ?>"> <?php esc_html_e( 'days', 'plugins-condition' ); ?> |
| 108 |
<?php submit_button( __( 'Save Changes', 'plugins-condition' ), 'large', 'plg-settings-apply', true ); ?> |
| 109 |
</div> |
| 110 |
<hr> |
| 111 |
<div style="margin: 5px; padding: 5px;"> |
| 112 |
<h3><?php esc_html_e( 'Remove Cache', 'plugins-condition' ); ?></h3> |
| 113 |
<p class="description"> |
| 114 |
<?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' ); ?> |
| 115 |
</p> |
| 116 |
<?php submit_button( __( 'Remove Cache', 'plugins-condition' ), 'large', 'plg-cache-remove', true ); ?> |
| 117 |
</div> |
| 118 |
</form> |
| 119 |
|
| 120 |
</div> |
| 121 |
<?php |
| 122 |
} |
| 123 |
|
| 124 |
/** ================================================== |
| 125 |
* Credit |
| 126 |
* |
| 127 |
* @since 1.00 |
| 128 |
*/ |
| 129 |
private function credit() { |
| 130 |
|
| 131 |
$plugin_name = null; |
| 132 |
$plugin_ver_num = null; |
| 133 |
$plugin_path = plugin_dir_path( __DIR__ ); |
| 134 |
$plugin_dir = untrailingslashit( wp_normalize_path( $plugin_path ) ); |
| 135 |
$slugs = explode( '/', $plugin_dir ); |
| 136 |
$slug = end( $slugs ); |
| 137 |
$files = scandir( $plugin_dir ); |
| 138 |
foreach ( $files as $file ) { |
| 139 |
if ( '.' === $file || '..' === $file || is_dir( $plugin_path . $file ) ) { |
| 140 |
continue; |
| 141 |
} else { |
| 142 |
$exts = explode( '.', $file ); |
| 143 |
$ext = strtolower( end( $exts ) ); |
| 144 |
if ( 'php' === $ext ) { |
| 145 |
$plugin_datas = get_file_data( |
| 146 |
$plugin_path . $file, |
| 147 |
array( |
| 148 |
'name' => 'Plugin Name', |
| 149 |
'version' => 'Version', |
| 150 |
) |
| 151 |
); |
| 152 |
if ( array_key_exists( 'name', $plugin_datas ) && ! empty( $plugin_datas['name'] ) && array_key_exists( 'version', $plugin_datas ) && ! empty( $plugin_datas['version'] ) ) { |
| 153 |
$plugin_name = $plugin_datas['name']; |
| 154 |
$plugin_ver_num = $plugin_datas['version']; |
| 155 |
break; |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
$plugin_version = __( 'Version:', 'plugins-condition' ) . ' ' . $plugin_ver_num; |
| 161 |
/* translators: FAQ Link & Slug */ |
| 162 |
$faq = sprintf( __( 'https://wordpress.org/plugins/%s/faq', 'plugins-condition' ), $slug ); |
| 163 |
$support = 'https://wordpress.org/support/plugin/' . $slug; |
| 164 |
$review = 'https://wordpress.org/support/view/plugin-reviews/' . $slug; |
| 165 |
$translate = 'https://translate.wordpress.org/projects/wp-plugins/' . $slug; |
| 166 |
$facebook = 'https://www.facebook.com/katsushikawamori/'; |
| 167 |
$twitter = 'https://twitter.com/dodesyo312'; |
| 168 |
$youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w'; |
| 169 |
$donate = __( 'https://shop.riverforest-wp.info/donate/', 'plugins-condition' ); |
| 170 |
|
| 171 |
?> |
| 172 |
<span style="font-weight: bold;"> |
| 173 |
<div> |
| 174 |
<?php echo esc_html( $plugin_version ); ?> | |
| 175 |
<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> |
| 176 |
</div> |
| 177 |
<div> |
| 178 |
<a style="text-decoration: none;" href="<?php echo esc_url( $translate ); ?>" target="_blank" rel="noopener noreferrer"> |
| 179 |
<?php |
| 180 |
/* translators: Plugin translation link */ |
| 181 |
echo esc_html( sprintf( __( 'Translations for %s', 'plugins-condition' ), $plugin_name ) ); |
| 182 |
?> |
| 183 |
</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> |
| 184 |
</div> |
| 185 |
</span> |
| 186 |
|
| 187 |
<div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;"> |
| 188 |
<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> |
| 189 |
<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> |
| 190 |
<button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo esc_url( $donate ); ?>')"><?php esc_html_e( 'Donate to this plugin »', 'plugins-condition' ); ?></button> |
| 191 |
</div> |
| 192 |
|
| 193 |
<?php |
| 194 |
} |
| 195 |
|
| 196 |
/** ================================================== |
| 197 |
* Update wp_options table. |
| 198 |
* |
| 199 |
* @since 1.00 |
| 200 |
*/ |
| 201 |
private function options_updated() { |
| 202 |
|
| 203 |
if ( isset( $_POST['plg-settings-apply'] ) && ! empty( $_POST['plg-settings-apply'] ) ) { |
| 204 |
if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_settings' ) ) { |
| 205 |
if ( ! empty( $_POST['pc_notify_interval'] ) ) { |
| 206 |
do_action( 'plugins_condition_notify_cron_stop' ); |
| 207 |
update_option( 'plg_cond_notify_interval', intval( $_POST['pc_notify_interval'] ) ); |
| 208 |
do_action( 'plugins_condition_notify_cron_start' ); |
| 209 |
echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Settings', 'plugins-condition' ) . ' --> ' . __( 'Settings saved.', 'plugins-condition' ) ) . '</li></ul></div>'; |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
if ( isset( $_POST['plg-cache-remove'] ) && ! empty( $_POST['plg-cache-remove'] ) ) { |
| 215 |
if ( check_admin_referer( 'plg_cond_settings', 'pluginscondition_settings' ) ) { |
| 216 |
$del_cash_count = $this->delete_all_cash(); |
| 217 |
if ( 0 < $del_cash_count ) { |
| 218 |
echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Removed the cache.', 'plugins-condition' ) . '</li></ul></div>'; |
| 219 |
} else { |
| 220 |
echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No Cache', 'plugins-condition' ) . '</li></ul></div>'; |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
/** ================================================== |
| 227 |
* Delete all cache |
| 228 |
* |
| 229 |
* @return int $del_cash_count(int) |
| 230 |
* @since 1.00 |
| 231 |
*/ |
| 232 |
private function delete_all_cash() { |
| 233 |
|
| 234 |
global $wpdb; |
| 235 |
$search_transients = '%plg_cond_datas_%'; |
| 236 |
$del_transients = $wpdb->get_results( |
| 237 |
$wpdb->prepare( |
| 238 |
" |
| 239 |
SELECT option_name |
| 240 |
FROM {$wpdb->prefix}options |
| 241 |
WHERE option_name LIKE %s |
| 242 |
", |
| 243 |
$search_transients |
| 244 |
) |
| 245 |
); |
| 246 |
|
| 247 |
$del_cash_count = 0; |
| 248 |
foreach ( $del_transients as $del_transient ) { |
| 249 |
$transient = str_replace( '_transient_', '', $del_transient->option_name ); |
| 250 |
$value_del_cash = get_transient( $transient ); |
| 251 |
if ( false <> $value_del_cash ) { |
| 252 |
delete_transient( $transient ); |
| 253 |
++$del_cash_count; |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
return $del_cash_count; |
| 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 |
|