| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: plugin load filter |
| 4 |
Description: Dynamically activate the selected plugins for each page. Response will be faster by filtering plugins. |
| 5 |
Version: 4.3.0 |
| 6 |
Plugin URI: https://celtislab.net/en/wp-plugin-load-filter |
| 7 |
Author: enomoto@celtislab |
| 8 |
Author URI: https://celtislab.net/ |
| 9 |
Requires at least: 6.0 |
| 10 |
Tested up to: 6.8 |
| 11 |
Requires PHP: 8.1 |
| 12 |
License: GPLv2 |
| 13 |
Text Domain: plf |
| 14 |
Domain Path: /languages |
| 15 |
*/ |
| 16 |
|
| 17 |
defined( 'ABSPATH' ) || exit; |
| 18 |
|
| 19 |
/*************************************************************************** |
| 20 |
* plugin activation / deactivation / uninstall |
| 21 |
**************************************************************************/ |
| 22 |
if(is_admin()){ |
| 23 |
//deactivation |
| 24 |
function plugin_load_filter_deactivation( $network_deactivating ) { |
| 25 |
$act = false; |
| 26 |
if (is_multisite()) { |
| 27 |
if(! $network_deactivating){ |
| 28 |
global $wpdb; |
| 29 |
$current_blog_id = get_current_blog_id(); |
| 30 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 31 |
foreach ( $blog_ids as $blog_id ) { |
| 32 |
if($blog_id == $current_blog_id){ |
| 33 |
//current site |
| 34 |
} |
| 35 |
else { |
| 36 |
//other site active check |
| 37 |
switch_to_blog( $blog_id ); |
| 38 |
if ( is_plugin_active( plugin_basename( __FILE__ ))) |
| 39 |
$act = true; |
| 40 |
} |
| 41 |
} |
| 42 |
switch_to_blog( $current_blog_id ); |
| 43 |
} |
| 44 |
} |
| 45 |
if($act === false){ |
| 46 |
flush_rewrite_rules(); //options data 'rewrite_rules' clear for remake. |
| 47 |
if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { |
| 48 |
@unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' ); |
| 53 |
|
| 54 |
//uninstall |
| 55 |
function plugin_load_filter_uninstall() { |
| 56 |
|
| 57 |
if ( !is_multisite()) { |
| 58 |
delete_option('plf_queryvars'); |
| 59 |
delete_option('plf_option' ); |
| 60 |
delete_option('plf_addon_options'); |
| 61 |
} else { |
| 62 |
global $wpdb; |
| 63 |
$current_blog_id = get_current_blog_id(); |
| 64 |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 65 |
foreach ( $blog_ids as $blog_id ) { |
| 66 |
switch_to_blog( $blog_id ); |
| 67 |
delete_option('plf_queryvars'); |
| 68 |
delete_option('plf_option' ); |
| 69 |
delete_option('plf_addon_options'); |
| 70 |
} |
| 71 |
switch_to_blog( $current_blog_id ); |
| 72 |
} |
| 73 |
if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { |
| 74 |
@unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); |
| 75 |
} |
| 76 |
} |
| 77 |
register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall'); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
$Plf_setting = new Plf_setting(); |
| 82 |
|
| 83 |
class Plf_setting { |
| 84 |
|
| 85 |
static $plugins_inf = ''; //active plugin/module infomation |
| 86 |
static $filter = array(); //filter option data |
| 87 |
private $tab_num = 0; |
| 88 |
|
| 89 |
/*************************************************************************** |
| 90 |
* Style Sheet |
| 91 |
**************************************************************************/ |
| 92 |
function plf_css() { ?> |
| 93 |
<style type="text/css"> |
| 94 |
#plugin-filter-select {margin-top: 12px;} |
| 95 |
#plugin-filter-select p {margin: 1em 0;} |
| 96 |
#page-filter-stat { margin-top: 12px;} |
| 97 |
#activation-table { padding-bottom: 8px; border: 1px solid #eee;} |
| 98 |
#activation-table th { text-align: center;} |
| 99 |
#activation-table td { font-size: 97%;} |
| 100 |
#activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;} |
| 101 |
#plf-post-locale-select { margin-top: 16px;} |
| 102 |
thead .plugins-name { background-color: aliceblue;} |
| 103 |
thead .device-type { background-color: oldlace;} |
| 104 |
thead .plugins-name, tbody .plugins-name { min-width: 144px; max-width: 200px; padding: 3px 3px 3px 5px;} |
| 105 |
thead .device-type, tbody .device-type { min-width: 40px; max-width: 40px; text-align: center; padding: 5px 1px 2px;} |
| 106 |
.dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;} |
| 107 |
.device-type label { color: whitesmoke; } |
| 108 |
input.altcheckbox[type="checkbox"] { -webkit-appearance: none; appearance: none; position: absolute;} |
| 109 |
.device-type input.altcheckbox[type="checkbox"]:checked + span.dashicons-yes:before { background-color: yellowgreen; } |
| 110 |
.plf-option-info { font-size:12px; margin:10px 0; padding:3px; background-color:#fff8e5;} |
| 111 |
.edit-post-locale-link span.dashicons { width: 0.8em; height: 0.8em; margin: -0.4em 0.1em 0; vertical-align: middle; text-decoration: initial;} |
| 112 |
</style> |
| 113 |
<?php } |
| 114 |
|
| 115 |
function jquery_tab_css() { ?> |
| 116 |
<style type="text/css"> |
| 117 |
.ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.5; text-decoration: none; font-size: 100%; list-style: none; } |
| 118 |
.ui-helper-clearfix:before, .ui-helper-clearfix:after { content: ""; display: table; } |
| 119 |
.ui-helper-clearfix:after { clear: both; } |
| 120 |
.ui-helper-clearfix { zoom: 1; } |
| 121 |
.ui-tabs { position: relative; padding: .2em; zoom: 1; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */ |
| 122 |
.ui-tabs .ui-tabs-nav { margin: 1px 8px; padding: .2em .2em; } |
| 123 |
.ui-tabs .ui-tabs-nav li { list-style: none; float: left; position: relative; top: 0; margin: 1px .3em 0 0; border-bottom: 0; padding: 0; white-space: nowrap; } |
| 124 |
.ui-tabs .ui-tabs-nav li a { float: left; text-decoration: none; } |
| 125 |
.ui-tabs .ui-tabs-nav li.ui-tabs-active { margin-bottom: -1px; padding-bottom: 1px; } |
| 126 |
.ui-tabs .ui-tabs-panel { display: block; border-width: 0; background: none; } |
| 127 |
.ui-tabs .ui-tabs-nav a { margin: 8px 10px; } |
| 128 |
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #dddddd; background-color: #f4f4f4; font-weight: bold; color: #0073ea; } |
| 129 |
.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #0073ea; text-decoration: none; } |
| 130 |
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus { border: 1px solid #0073ea; background-color: #0073ea; font-weight: bold; color: #ffffff; } |
| 131 |
.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #dddddd; background-color: #0073ea; font-weight: bold; color: #ffffff; } |
| 132 |
.ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited { color: #ffffff; text-decoration: none; } |
| 133 |
.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; } |
| 134 |
|
| 135 |
#wrap_registration-table, #wrap_activation-table { overflow:auto; height:600px; position: relative;} |
| 136 |
#registration-table input[type=radio], #registration-table input[type=checkbox], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;} |
| 137 |
#registration-table th {text-align: center;} |
| 138 |
thead, tbody { display: block;} |
| 139 |
.widefat * { word-wrap: break-word !important;} |
| 140 |
.widefat thead { position:sticky; top:0px; z-index:1;} |
| 141 |
.widefat tr:first-of-type th:first-of-type {position: sticky; left: 0px; text-align: left; background-color: aliceblue; z-index:3;} |
| 142 |
.widefat th { padding: 8px;} |
| 143 |
.widefat td { padding: 8px;} |
| 144 |
.widefat td:first-of-type { position: sticky; left: 0px; text-align: left; background-color: white;} |
| 145 |
thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;} |
| 146 |
thead .urlfilter { background-color: lavenderblush;} |
| 147 |
.filter-none, .filter-admin, .filter-tmpl { background-color: honeydew;} |
| 148 |
thead .device-type { background-color: oldlace;} |
| 149 |
thead .ckbox-type { background-color: lavender;} |
| 150 |
thead .pformat { background-color: honeydew;} |
| 151 |
thead .tmpl-embed { background-color: lightyellow;} |
| 152 |
thead .tmpl-custom { background-color: lavenderblush;} |
| 153 |
thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 240px; max-width: 240px;} |
| 154 |
thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;} |
| 155 |
thead .device-type, tbody .device-type, thead .ckbox-type, tbody .ckbox-type, thead .deny-type, tbody .deny-type { min-width: 40px; max-width: 40px; text-align: center;} |
| 156 |
thead .filter-type, tbody .filter-type { min-width: 56px; max-width: 56px; text-align:center;} |
| 157 |
.urlfilter-description { padding: 0 10px 15px;} |
| 158 |
.grid-row { display: flex; flex-flow: row wrap;} |
| 159 |
.filter-description { padding: 0 10px; width:62%;} |
| 160 |
.side-info { width: 30%; padding-left: 24px;} |
| 161 |
.exclude-pformat { padding: 5px 0 20px} |
| 162 |
.exclude-pformat label { white-space:nowrap;} |
| 163 |
.exclude-pformat span { margin-right: 12px; } |
| 164 |
.dashicons:before { font-size: 24px; } |
| 165 |
.radio-green label, .radio-red label { color: #ddd; margin-left: -32px; } |
| 166 |
.ckbox-type label { color: #ddd;} |
| 167 |
.radio-green input[type="radio"]:checked + span { color: #8bc34a; } |
| 168 |
.radio-red input[type="radio"]:checked + span { color: tomato; } |
| 169 |
.ckbox-type input[type="checkbox"]:checked + span { color: #4caf50; } |
| 170 |
/* .dashicons-dismiss:before { background-color: yellowgreen; font-size: 20px; border-radius: 12px; } */ |
| 171 |
.deny-type label { color: #4caf50;} |
| 172 |
.deny-type input.altcheckbox[type="checkbox"]:checked + span { color: #ddd; } |
| 173 |
.dashicons-yes:before { font-size: 20px; border: 1px solid #eee; } |
| 174 |
.device-type input.altcheckbox[type="checkbox"]:checked + span.dashicons-yes:before { background-color: yellowgreen; } |
| 175 |
.option-item { margin-bottom: 28px; } |
| 176 |
</style> |
| 177 |
<?php } |
| 178 |
|
| 179 |
/*************************************************************************** |
| 180 |
* Plugin Load Filter Option Setting |
| 181 |
**************************************************************************/ |
| 182 |
|
| 183 |
public function __construct() { |
| 184 |
|
| 185 |
add_action('init', function(){ load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' ); }, 1); |
| 186 |
|
| 187 |
self::$filter = get_option('plf_option', array()); |
| 188 |
if(empty(self::$filter['optver']) || self::$filter['optver'] < '2'){ |
| 189 |
self::$filter['optver'] = '2'; |
| 190 |
//ここにデータフォーマットが変わった場合の変換処理を記述 |
| 191 |
} |
| 192 |
if(!empty(self::$filter['language'])){ |
| 193 |
add_action( 'wp_head', array('Plf_setting', 'altenate_hreflang') ); |
| 194 |
} |
| 195 |
|
| 196 |
if(is_admin()) { |
| 197 |
add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 ); |
| 198 |
add_action( 'admin_init', array(&$this, 'action_posts')); |
| 199 |
add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 ); |
| 200 |
} |
| 201 |
add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter')); |
| 202 |
} |
| 203 |
|
| 204 |
//Plugin Load Filter admin setting start |
| 205 |
public function plf_admin_start() { |
| 206 |
require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 207 |
|
| 208 |
self::$plugins_inf = get_plugins(); |
| 209 |
//Ver4.0.0 でしか呼び出せないメソッドを呼び出さないよう新設した switch_theme があるかどうかで判定 |
| 210 |
if(method_exists('Plf_filter', 'switch_theme')){ |
| 211 |
if(class_exists('Plf_filter')){ |
| 212 |
if ( is_multisite() ) |
| 213 |
remove_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins')); |
| 214 |
remove_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins')); |
| 215 |
} |
| 216 |
foreach ( self::$plugins_inf as $plugin_key => $a_plugin ) { |
| 217 |
if(is_plugin_inactive( $plugin_key )){ |
| 218 |
unset(self::$plugins_inf[$plugin_key]); |
| 219 |
} |
| 220 |
} |
| 221 |
if(class_exists('Plf_filter')){ |
| 222 |
if ( is_multisite() ) |
| 223 |
add_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins')); |
| 224 |
add_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins')); |
| 225 |
} |
| 226 |
|
| 227 |
//jetpack active module |
| 228 |
if(method_exists('Jetpack', 'get_module')){ |
| 229 |
if(class_exists('Plf_filter')){ |
| 230 |
remove_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules')); |
| 231 |
} |
| 232 |
$modules = Jetpack::get_active_modules(); |
| 233 |
$modules = array_diff( $modules, array( 'vaultpress' ) ); |
| 234 |
foreach ( $modules as $key => $module_name ) { |
| 235 |
if(!empty($module_name)){ |
| 236 |
$module = Jetpack::get_module( $module_name ); |
| 237 |
if(!empty($module)) |
| 238 |
self::$plugins_inf['jetpack_module/' . $module_name] = $module; |
| 239 |
} |
| 240 |
} |
| 241 |
if(class_exists('Plf_filter')){ |
| 242 |
add_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules')); |
| 243 |
} |
| 244 |
} |
| 245 |
//celtispack active module |
| 246 |
if(method_exists('Celtispack', 'get_module')){ |
| 247 |
if(class_exists('Plf_filter')){ |
| 248 |
remove_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules')); |
| 249 |
} |
| 250 |
$modules = Celtispack::get_active_modules(); |
| 251 |
foreach ( $modules as $key => $module_name ) { |
| 252 |
if(!empty($module_name)){ |
| 253 |
self::$plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name ); |
| 254 |
} |
| 255 |
} |
| 256 |
if(class_exists('Plf_filter')){ |
| 257 |
add_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules')); |
| 258 |
} |
| 259 |
} |
| 260 |
if ( empty( self::$plugins_inf ) ) |
| 261 |
return; |
| 262 |
} |
| 263 |
|
| 264 |
add_action('admin_menu', array(&$this, 'plf_option_menu')); |
| 265 |
} |
| 266 |
|
| 267 |
static function get_plugins_inf() { |
| 268 |
$inf = (!empty(self::$plugins_inf))? self::$plugins_inf : false; |
| 269 |
return $inf; |
| 270 |
} |
| 271 |
|
| 272 |
//Plugins sub menu add |
| 273 |
public function plf_option_menu() { |
| 274 |
if(current_user_can( 'activate_plugins' )){ |
| 275 |
$page = add_menu_page( 'Plugin Load FIlter Settings', esc_html__('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this, 'plf_option_page'), 'dashicons-filter', '65.1'); |
| 276 |
add_submenu_page( 'plugin_load_filter_admin_manage_page', 'Plugin Load FIlter Settings', esc_html__('General Settings', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this, 'plf_option_page') ); |
| 277 |
add_action( 'admin_print_scripts-'.$page, array(&$this, 'plf_scripts') ); |
| 278 |
add_action( 'admin_print_scripts-'.$page, array(&$this, 'deploy_mu_plugins')); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
//Plugin Load Filter setting page script |
| 283 |
function plf_scripts() { |
| 284 |
wp_enqueue_script( 'jquery' ); |
| 285 |
wp_enqueue_script( 'jquery-ui-core' ); |
| 286 |
wp_enqueue_script( 'jquery-ui-widget' ); |
| 287 |
wp_enqueue_script( 'jquery-ui-tabs' ); |
| 288 |
add_action( 'admin_head', array(&$this, 'plf_css' )); |
| 289 |
add_action( 'admin_head', array(&$this, 'jquery_tab_css' )); |
| 290 |
add_action( 'admin_footer', array(&$this, 'activetab_script' )); |
| 291 |
add_action( 'admin_notices', array('Plf_setting', 'plf_notice')); |
| 292 |
} |
| 293 |
|
| 294 |
//plf-filter.php mu-plugins module set |
| 295 |
public function deploy_mu_plugins() { |
| 296 |
if(wp_mkdir_p( WPMU_PLUGIN_DIR )){ |
| 297 |
if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { |
| 298 |
@copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); |
| 299 |
} |
| 300 |
else { |
| 301 |
require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 302 |
$dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false ); |
| 303 |
$sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false ); |
| 304 |
if(version_compare( $dp['Version'], $sp['Version'], '!=')){ |
| 305 |
@copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
//Notice Message display |
| 312 |
static function plf_notice() { |
| 313 |
$notice = get_transient('plf_notice'); |
| 314 |
if(!empty($notice)){ |
| 315 |
echo '<div class="notice notice-warning"><p>Plugin Load Filter : ' . $notice . '</p></div>'; |
| 316 |
delete_transient('plf_notice'); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
//plugin filter option action request (add, update, delete) |
| 321 |
function action_posts() { |
| 322 |
if (current_user_can( 'activate_plugins' )) { |
| 323 |
if( isset($_POST['edit_regist_filter']) ) { |
| 324 |
if(isset($_POST['plfregist'])){ |
| 325 |
check_admin_referer('plugin_load_filter'); |
| 326 |
//url filter |
| 327 |
$groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array(); |
| 328 |
if(!empty($groupkeys) && isset($_POST['plfurlkey'])){ |
| 329 |
$urlkeys = array_keys($_POST['plfurlkey']); |
| 330 |
foreach( $groupkeys as $item){ |
| 331 |
if(empty( $_POST['plfurlkey'][$item])){ |
| 332 |
self::$filter['plfurlkey'][$item]['plugins'] = ''; |
| 333 |
} else { |
| 334 |
$plugins = array(); |
| 335 |
foreach ( $_POST['plfurlkey'][$item] as $p_key => $val ) { |
| 336 |
if($val == '1') |
| 337 |
$plugins[] = $p_key; |
| 338 |
} |
| 339 |
$option["plugins"] = implode(",", $plugins); |
| 340 |
self::$filter['plfurlkey'][$item] = $option; |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
//page type filter |
| 345 |
foreach( array('_admin', '_pagefilter') as $item){ |
| 346 |
$plugins = array(); |
| 347 |
foreach ( $_POST['plfregist'] as $p_key => $val ) { |
| 348 |
if($val == $item) |
| 349 |
$plugins[$p_key] = $val; |
| 350 |
} |
| 351 |
if($item == '_pagefilter'){ |
| 352 |
//If all modules is specified filter, in some cases you want to deactivate plugin itself. |
| 353 |
$jbase = $cbase = ''; |
| 354 |
$jall = $call = true; |
| 355 |
foreach ( $_POST['plfregist'] as $p_key => $val ) { |
| 356 |
if(strpos($p_key, 'jetpack/') !== false) |
| 357 |
$jbase = $p_key; |
| 358 |
else if(strpos($p_key, 'celtispack/') !== false) |
| 359 |
$cbase = $p_key; |
| 360 |
else if(strpos($p_key, 'jetpack_module/') !== false){ |
| 361 |
if($val != '_pagefilter' && $val != '_admin'){ |
| 362 |
$jall = false; |
| 363 |
} |
| 364 |
} |
| 365 |
else if(strpos($p_key, 'celtispack_module/') !== false){ |
| 366 |
if($val != '_pagefilter' && $val != '_admin') |
| 367 |
$call = false; |
| 368 |
} |
| 369 |
} |
| 370 |
if(!empty($jbase) && $jall === false) |
| 371 |
unset($plugins[$jbase]); |
| 372 |
if(!empty($cbase) && $call === false) |
| 373 |
unset($plugins[$cbase]); |
| 374 |
} |
| 375 |
$option["plugins"] = implode(",", array_keys($plugins)); |
| 376 |
self::$filter[$item] = $option; |
| 377 |
} |
| 378 |
//exclude option |
| 379 |
if(isset($_POST['plf_option']['exclude'])){ |
| 380 |
$exclude = array(); |
| 381 |
foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) { |
| 382 |
if(!empty($v)) |
| 383 |
$exclude[$ft] = true; |
| 384 |
} |
| 385 |
self::$filter['exclude'] = $exclude; |
| 386 |
} else { |
| 387 |
self::$filter['exclude'] = array(); |
| 388 |
} |
| 389 |
|
| 390 |
//admin bar (filtered stat) |
| 391 |
self::$filter['admin_bar'] = (isset($_POST['plf_option']['admin_bar']))? 1 : 0; |
| 392 |
|
| 393 |
//Language option |
| 394 |
self::$filter['language'] = (isset($_POST['plf_option']['language']))? 1 : 0; |
| 395 |
|
| 396 |
//Ajax acceleration plugin filter (for plugin developers) |
| 397 |
self::$filter['ajax_accelfilter'] = (isset($_POST['plf_option']['ajax_accelfilter']))? 1 : 0; |
| 398 |
|
| 399 |
update_option('plf_option', self::$filter, 'no' ); |
| 400 |
} |
| 401 |
header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); |
| 402 |
exit; |
| 403 |
|
| 404 |
} elseif( isset($_POST['clear_regist_filter']) ) { |
| 405 |
check_admin_referer('plugin_load_filter'); |
| 406 |
if(!empty(self::$filter['plfurlkey'])){ |
| 407 |
foreach (self::$filter['plfurlkey'] as $key => $val) { |
| 408 |
unset(self::$filter['plfurlkey'][$key]); |
| 409 |
} |
| 410 |
} |
| 411 |
foreach( array('_admin', '_pagefilter') as $item){ |
| 412 |
self::$filter[$item] = array(); |
| 413 |
} |
| 414 |
self::$filter['exclude'] = array(); |
| 415 |
|
| 416 |
//old data unset |
| 417 |
if(isset(self::$filter['urlkey'])){ |
| 418 |
unset(self::$filter['urlkey']); |
| 419 |
} |
| 420 |
if(isset(self::$filter['urlkeylist'])){ |
| 421 |
unset(self::$filter['urlkeylist']); |
| 422 |
} |
| 423 |
|
| 424 |
self::$filter['admin_bar'] = 0; |
| 425 |
self::$filter['language'] = 0; |
| 426 |
self::$filter['ajax_accelfilter'] = 0; |
| 427 |
update_option('plf_option', self::$filter, 'no' ); |
| 428 |
header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); |
| 429 |
exit; |
| 430 |
|
| 431 |
} else if(isset($_POST['edit_activate_page_filter']) ) { |
| 432 |
if(isset($_POST['plfactive'])){ |
| 433 |
check_admin_referer('plugin_load_filter'); |
| 434 |
self::$filter['group'] = array(); |
| 435 |
$group = array_keys($_POST['plfactive']); |
| 436 |
foreach( $group as $item){ |
| 437 |
$plugins = array(); |
| 438 |
foreach ( $_POST['plfactive'][$item] as $p_key => $val ) { |
| 439 |
if($val == '1') |
| 440 |
$plugins[] = $p_key; |
| 441 |
} |
| 442 |
$option["plugins"] = implode(",", $plugins); |
| 443 |
self::$filter['group'][$item] = $option; |
| 444 |
} |
| 445 |
update_option('plf_option', self::$filter, 'no' ); |
| 446 |
} |
| 447 |
header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1')); |
| 448 |
exit; |
| 449 |
|
| 450 |
} elseif( isset($_POST['clear_activate_page_filter']) ) { |
| 451 |
check_admin_referer('plugin_load_filter'); |
| 452 |
self::$filter['group'] = array(); |
| 453 |
update_option('plf_option', self::$filter, 'no' ); |
| 454 |
header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1')); |
| 455 |
exit; |
| 456 |
} |
| 457 |
if(!empty($_GET['action']) && $_GET['action']=='tab_1') { |
| 458 |
$this->tab_num = 1; |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
//Plugin or Module key to name |
| 464 |
// $type : list/smart/tree |
| 465 |
static function pluginkey_to_name( $infkey, $type='list') { |
| 466 |
$name = ''; |
| 467 |
if(strpos($infkey, 'jetpack_module/') !== false){ |
| 468 |
if(!empty(self::$plugins_inf[$infkey]['name'])){ |
| 469 |
$m_mark = ($type !== 'list')? '-' : 'Jetpack-'; |
| 470 |
if($type === 'smart') { |
| 471 |
if(empty(self::$filter['_pagefilter']['plugins']) || strpos(self::$filter['_pagefilter']['plugins'], 'jetpack/') === false) |
| 472 |
$name = $m_mark . self::$plugins_inf[$infkey]['name']; |
| 473 |
} else { |
| 474 |
$name = $m_mark . self::$plugins_inf[$infkey]['name']; |
| 475 |
} |
| 476 |
} |
| 477 |
} elseif(strpos($infkey, 'celtispack_module/') !== false){ |
| 478 |
if(!empty(self::$plugins_inf[$infkey]['Name'])){ |
| 479 |
$m_mark = ($type !== 'list')? '-' : 'Celtispack-'; |
| 480 |
if($type === 'smart') { |
| 481 |
if(empty(self::$filter['_pagefilter']['plugins']) || strpos(self::$filter['_pagefilter']['plugins'], 'celtispack/') === false) |
| 482 |
$name = $m_mark . self::$plugins_inf[$infkey]['Name']; |
| 483 |
} else { |
| 484 |
$name = $m_mark . self::$plugins_inf[$infkey]['Name']; |
| 485 |
} |
| 486 |
} |
| 487 |
} else { |
| 488 |
if(!empty(self::$plugins_inf[$infkey]['Name'])) |
| 489 |
$name = self::$plugins_inf[$infkey]['Name']; |
| 490 |
} |
| 491 |
return($name); |
| 492 |
} |
| 493 |
|
| 494 |
//Checkbox |
| 495 |
static function checkbox($name, $value, $label = '') { |
| 496 |
return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>"; |
| 497 |
} |
| 498 |
static function altcheckbox($name, $value, $label = '') { |
| 499 |
//return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>"; |
| 500 |
return "<label><input type='checkbox' name='$name' class='altcheckbox' value='1' " . checked( $value, 1, false ). "/> $label</label>"; |
| 501 |
} |
| 502 |
|
| 503 |
//dropdown list |
| 504 |
static function dropdown($name, $items, $selected, $args = null) { |
| 505 |
$defaults = array( |
| 506 |
'id' => $name, |
| 507 |
'none' => false, |
| 508 |
'class' => null, |
| 509 |
'multiple' => false, |
| 510 |
'select_attr' => "" |
| 511 |
); |
| 512 |
|
| 513 |
if (!is_array($items)) |
| 514 |
return; |
| 515 |
|
| 516 |
if (empty($items)) |
| 517 |
$items = array(); |
| 518 |
|
| 519 |
// Items is in key => value format. If value is itself an array, use only the 1st column |
| 520 |
foreach ($items as $key => &$value) { |
| 521 |
if (is_array($value)) |
| 522 |
$value = array_shift($value); |
| 523 |
} |
| 524 |
|
| 525 |
extract(wp_parse_args($args, $defaults)); |
| 526 |
|
| 527 |
// If 'none' arg provided, prepend a blank entry |
| 528 |
if ($none) { |
| 529 |
if ($none === true) |
| 530 |
$none = ' '; |
| 531 |
$items = array('' => $none) + $items; // Note that array_merge() won't work because it renumbers indexes! |
| 532 |
} |
| 533 |
|
| 534 |
if (!$id) |
| 535 |
$id = $name; |
| 536 |
|
| 537 |
$name = ($name) ? "name='$name'" : ""; |
| 538 |
$id = ($id) ? "id='$id'" : ""; |
| 539 |
$class = ($class) ? "class='$class'" : ""; |
| 540 |
$multiple = ($multiple) ? "multiple='multiple'" : ""; |
| 541 |
|
| 542 |
$html = "<select $name $id $class $multiple $select_attr>"; |
| 543 |
|
| 544 |
foreach ((array) $items as $key => $label) { |
| 545 |
$key = esc_attr($key); |
| 546 |
$label = esc_attr($label); |
| 547 |
|
| 548 |
$html .= "<option value='$key' " . selected($selected, $key, false) . ">$label</option>"; |
| 549 |
} |
| 550 |
$html .= "</select>"; |
| 551 |
return $html; |
| 552 |
} |
| 553 |
|
| 554 |
//安� |
| 555 |
�な文字列から指定タグのみデコード(既存の翻訳ファイルへ影響せずにエスケープするために使用) |
| 556 |
//<strong>Type</strong> -> <strong>Type</strong> |
| 557 |
static function decode_safe_tag( $tag, $safe_str ) { |
| 558 |
$safe_str = preg_replace_callback( "|<($tag.*)>(.*)</($tag)>|im", function($matches){ |
| 559 |
$tag_attrs = str_replace( '"', '"', $matches[1]); |
| 560 |
return '<' . $tag_attrs . '>' . $matches[2] . '</' . $matches[3] . '>'; |
| 561 |
}, $safe_str); |
| 562 |
return $safe_str; |
| 563 |
} |
| 564 |
|
| 565 |
public function plfregist_item($key, $chklist, $filter) { |
| 566 |
$p_name = self::pluginkey_to_name($key); |
| 567 |
$opt_name = "plfregist[$key]"; |
| 568 |
?> |
| 569 |
<tr id="plfregist_<?php echo $key; ?>"> |
| 570 |
<td class="filter-plugins-name"><?php echo $p_name; ?></td> |
| 571 |
<?php |
| 572 |
foreach($chklist as $urlkey){ |
| 573 |
$checked = (empty($filter['plfurlkey'][$urlkey]['plugins']) || false === strpos($filter['plfurlkey'][$urlkey]['plugins'], $key))? false : true; |
| 574 |
echo '<td class="deny-type filter-type">' . self::altcheckbox("plfurlkey[$urlkey][$key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>'; |
| 575 |
} |
| 576 |
$radio = ''; |
| 577 |
if(!empty($filter['_admin']['plugins']) && false !== strpos($filter['_admin']['plugins'], $key)) |
| 578 |
$radio = '_admin'; |
| 579 |
else if(!empty($filter['_pagefilter']['plugins']) && false !== strpos($filter['_pagefilter']['plugins'], $key)) |
| 580 |
$radio = '_pagefilter'; |
| 581 |
?> |
| 582 |
<td class="radio-green filter-type"><label><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td> |
| 583 |
<td class="radio-red filter-type"><label><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td> |
| 584 |
<td class="radio-red filter-type"><label><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td> |
| 585 |
</tr> |
| 586 |
<?php |
| 587 |
} |
| 588 |
|
| 589 |
//Filterring plugins select |
| 590 |
public function plfregist_table($plugins, $filter) { |
| 591 |
?> |
| 592 |
<div id="wrap_registration-table"> |
| 593 |
<table id="registration-table" class="widefat"> |
| 594 |
<thead> |
| 595 |
<?php |
| 596 |
$groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array(); |
| 597 |
$urlnum = count($groupkeys); |
| 598 |
?> |
| 599 |
<tr> |
| 600 |
<th class="filter-plugins-name" rowspan="2"><?php esc_html_e('Plugins'); ?></th> |
| 601 |
<?php if($urlnum > 0) { ?> |
| 602 |
<th class="filter-type urlfilter" colspan="<?php echo $urlnum; ?>" style="font-weight:bold; font-size:smaller;"><?php esc_html_e('URL Group Filter', 'plf'); ?></th> |
| 603 |
<?php } ?> |
| 604 |
<th class="filter-type filter-tmpl" colspan="3" style="font-weight:bold; font-size:smaller;"><?php esc_html_e('Page Type Filter', 'plf'); ?></th> |
| 605 |
</tr> |
| 606 |
<tr> |
| 607 |
<?php //Addon URL filter group key |
| 608 |
if($urlnum > 0) { |
| 609 |
foreach ( $groupkeys as $v) { |
| 610 |
$_flt = (method_exists('Plf_filter', 'get_slug_filter'))? Plf_filter::get_slug_filter( $v ) : array(); |
| 611 |
$hint = ''; |
| 612 |
foreach ($_flt as $_v) { |
| 613 |
$hint .= '[' . $_v['slug'] . '] ' . $_v['summary'] . PHP_EOL; |
| 614 |
|
| 615 |
if((int)$_v['targetpage'] === 1) { |
| 616 |
$post_type = (!empty($_v['post_type']))? $_v['post_type'] : ''; |
| 617 |
$taxonomy = ''; |
| 618 |
if(!empty($_v['taxonomies']) && !empty($_v['term'])){ |
| 619 |
$taxonomy = " : {$_v['taxonomies']}({$_v['term']})"; |
| 620 |
} |
| 621 |
if(!empty($post_type)){ |
| 622 |
$hint .= 'Singular (' . $post_type . ')' . $taxonomy . PHP_EOL; |
| 623 |
} else { |
| 624 |
$hint .= 'Singular ' . $taxonomy . PHP_EOL; |
| 625 |
} |
| 626 |
} elseif((int)$_v['targetpage'] === 2) { |
| 627 |
if(!empty($_v['ajax_action'])){ |
| 628 |
$hint .= 'Ajax request (' . $_v['ajax_action'] . ')' . PHP_EOL; |
| 629 |
} else { |
| 630 |
$hint .= 'Ajax request' . PHP_EOL; |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
$hint .= 'url filter : '; |
| 635 |
$urlkey = (!empty($_v['url_path']))? array_filter( array_map("trim", explode(PHP_EOL, $_v['url_path']))) : array(); |
| 636 |
if(!empty($urlkey)){ |
| 637 |
foreach ($urlkey as $key) { |
| 638 |
$hint .= $key . ' '; |
| 639 |
} |
| 640 |
} |
| 641 |
$urlkey = (!empty($_v['url_q_and']))? array_filter( array_map("trim", explode(PHP_EOL, $_v['url_q_and']))) : array(); |
| 642 |
if(!empty($urlkey)){ |
| 643 |
foreach ($urlkey as $key) { |
| 644 |
$hint .= ' AND ' . $key; |
| 645 |
} |
| 646 |
} |
| 647 |
$urlkey = (!empty($filter['url_q_not']))? array_filter( array_map("trim", explode(PHP_EOL, $filter['url_q_not']))) : array(); |
| 648 |
if(!empty($urlkey)){ |
| 649 |
foreach ($urlkey as $key) { |
| 650 |
$hint .= ' NOT ' . $key; |
| 651 |
} |
| 652 |
} |
| 653 |
$hint .= PHP_EOL . PHP_EOL; |
| 654 |
} |
| 655 |
echo "<th class='filter-type urlfilter'><span title='$hint' style='font-size:smaller'>{$v}</span></th>"; |
| 656 |
} |
| 657 |
} ?> |
| 658 |
<th class="filter-type filter-none"><span style="font-size:smaller"><?php esc_html_e('Normal', 'plf'); ?></span></th> |
| 659 |
<th class="filter-type filter-admin"><span style="font-size:smaller"><?php esc_html_e('Admin Type', 'plf'); ?></span></th> |
| 660 |
<th class="filter-type filter-tmpl"><span style="font-size:smaller"><?php esc_html_e('Page Type', 'plf'); ?></span></th> |
| 661 |
</tr> |
| 662 |
</thead> |
| 663 |
<tbody class="plugins-table-body"> |
| 664 |
<?php |
| 665 |
//plugins filter registoration table |
| 666 |
$plist = array(); |
| 667 |
foreach ( $plugins as $p_key => $val ) { |
| 668 |
$name = self::pluginkey_to_name($p_key); |
| 669 |
if(!empty($name)) |
| 670 |
$plist[$p_key] = ''; |
| 671 |
} |
| 672 |
$jlist = $clist = array(); |
| 673 |
foreach ( $plist as $p_key => $val ) { |
| 674 |
if(strpos($p_key, 'jetpack_module/') !== false){ |
| 675 |
$jlist[$p_key] = $plist[$p_key]; |
| 676 |
unset($plist[$p_key]); |
| 677 |
} |
| 678 |
else if(strpos($p_key, 'celtispack_module/') !== false){ |
| 679 |
$clist[$p_key] = $plist[$p_key]; |
| 680 |
unset($plist[$p_key]); |
| 681 |
} |
| 682 |
} |
| 683 |
//Addon URL filter group key |
| 684 |
$chklist = array(); |
| 685 |
if($urlnum > 0) { |
| 686 |
foreach ( $groupkeys as $key) { |
| 687 |
$chklist[] = $key; |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
foreach ( $plist as $p_key => $val ) { |
| 692 |
$modules = array(); |
| 693 |
if(strpos($p_key, 'jetpack/') !== false) |
| 694 |
$modules = $jlist; |
| 695 |
else if(strpos($p_key, 'celtispack/') !== false) |
| 696 |
$modules = $clist; |
| 697 |
else |
| 698 |
$this->plfregist_item($p_key, $chklist, $filter); |
| 699 |
if(!empty($modules)){ |
| 700 |
echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>"; |
| 701 |
foreach ( $modules as $m_key => $val) { |
| 702 |
$this->plfregist_item($m_key, $chklist, $filter); |
| 703 |
} |
| 704 |
} |
| 705 |
} |
| 706 |
?> |
| 707 |
</tbody> |
| 708 |
</table> |
| 709 |
</div> |
| 710 |
<p></p> |
| 711 |
<div class="grid-row"> |
| 712 |
<div class="filter-description"> |
| 713 |
<p><strong>[ <?php esc_html_e('Page Type Filter', 'plf'); ?> ]</strong></p> |
| 714 |
<?php echo self::decode_safe_tag( 'strong', esc_html__('<strong>Normal</strong> - Exclude plugin from Page Type filter', 'plf')); ?><br /> |
| 715 |
<?php echo self::decode_safe_tag( 'strong', esc_html__('<strong>Admin Type</strong> - If you only use plugins for Admin pages.', 'plf')); ?><br /> |
| 716 |
<?php echo self::decode_safe_tag( 'strong', esc_html__('<strong>Page Type</strong> - If you want to activate or deactivate plugins for each Page Type and Single page.', 'plf')); ?> |
| 717 |
<p> |
| 718 |
<?php |
| 719 |
$checked = (!empty(self::$filter['admin_bar']))? self::$filter['admin_bar'] : false; |
| 720 |
echo '<span class="admin-bar-option">' . self::checkbox("plf_option[admin_bar]", $checked, esc_html__('Add a link to admin bar for displaying the plugins filtered status', 'plf') ) . '</span>'; |
| 721 |
?> |
| 722 |
</p> |
| 723 |
<p><?php esc_html_e('* Plugins with `Page Type Filter` selected are blocked, but you can Activate it for various Page type in the `Page Type Activation` and Single Page setting.', 'plf'); ?></p> |
| 724 |
|
| 725 |
<div class="exclude-pformat"> |
| 726 |
<p><?php echo self::decode_safe_tag( 'strong', esc_html__('<strong>Exclude Post Format Type</strong> - Choose Post Format Type you are not using. To exclude from Page Type item subject.', 'plf')); ?></p> |
| 727 |
<?php |
| 728 |
$html = '<div>'; |
| 729 |
$pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' ); |
| 730 |
foreach ( $pformat as $type ) { |
| 731 |
$checked = (!empty(self::$filter['exclude'][$type]))? self::$filter['exclude'][$type] : false; |
| 732 |
$label = "<span>$type</span>"; |
| 733 |
$html .= self::checkbox("plf_option[exclude][$type]", $checked, $label); |
| 734 |
} |
| 735 |
$html .= '</div>'; |
| 736 |
echo $html; |
| 737 |
?> |
| 738 |
</div> |
| 739 |
<p><strong>[ <?php esc_html_e('Ajax acceleration filter (Features for plugin developers)', 'plf'); ?> ]</strong></p> |
| 740 |
<p><?php esc_html_e('If you are implementing Ajax requests in your plugin development, you can deactivate unnecessary plugins and speed up Ajax by setting the plugin slugs to be activated to `_ajax_plf` in the request data.','plf'); ?></p> |
| 741 |
<?php |
| 742 |
$checked = (!empty(self::$filter['ajax_accelfilter']))? self::$filter['ajax_accelfilter'] : false; |
| 743 |
echo '<div class="option-item">' . self::checkbox("plf_option[ajax_accelfilter]", $checked, esc_html__('Ajax acceleration filter', 'plf') ) . '</div>'; |
| 744 |
?> |
| 745 |
<p><strong>[ <?php esc_html_e('Post Language Locale', 'plf'); ?> ]</strong></p> |
| 746 |
<p><?php esc_html_e('A very simple multilingual feature that uses MO translation files for the selected locale per Post/Page editing screen.','plf'); ?></p> |
| 747 |
<?php |
| 748 |
$checked = (!empty(self::$filter['language']))? self::$filter['language'] : false; |
| 749 |
echo '<div class="option-item">' . self::checkbox("plf_option[language]", $checked, esc_html__('Language switching per post', 'plf') ) . '</div>'; |
| 750 |
?> |
| 751 |
</div> |
| 752 |
<div class="side-info"> |
| 753 |
<?php if(! is_plugin_active('plugin-load-filter-addon/plugin-load-filter-addon.php')){ ?> |
| 754 |
<div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" > |
| 755 |
<p><strong><?php esc_html_e('Introduction of Addon', 'plf'); ?></strong></p> |
| 756 |
<p><?php esc_html_e('Thank you for using Plugin Load Filter. We offer URL filtering as Addon. Please consider using Addon!', 'plf'); ?></p> |
| 757 |
<p><?php esc_html_e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/wp-plugin-load-filter-addon/"> Plugin Load Filter Addon</a></p> |
| 758 |
</div> |
| 759 |
<?php } ?> |
| 760 |
<?php if(! is_plugin_active('realtime-img-optimizer/realtime-img-optimizer.php')){ ?> |
| 761 |
<div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" > |
| 762 |
<p><strong><?php esc_html_e('Introduction of Realtime Image Optimizer', 'plf'); ?></strong></p> |
| 763 |
<p><?php esc_html_e('We sell Image Optimization plugin. Reduce and speed up data size by converting to WebP / AVIF.', 'plf'); ?></p> |
| 764 |
<p><?php esc_html_e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/wp-realtime-image-optimizer/"> Realtime Image Optimizer</a></p> |
| 765 |
</div> |
| 766 |
<?php } ?> |
| 767 |
</div> |
| 768 |
</div> |
| 769 |
<?php |
| 770 |
} |
| 771 |
|
| 772 |
//Activate plugins select from Page Filter |
| 773 |
public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) { |
| 774 |
|
| 775 |
$selplugins = array_map("trim", explode(',', $select_cvplugins)); |
| 776 |
$devlist = array('desktop','mobile'); |
| 777 |
if(in_array( $p_key, $selplugins )){ |
| 778 |
$p_name = self::pluginkey_to_name($p_key); |
| 779 |
echo "<tr><td class='plugins-name'>$p_name</td>"; |
| 780 |
foreach($devlist as $devtype){ |
| 781 |
$checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true; |
| 782 |
echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>'; |
| 783 |
} |
| 784 |
foreach($chklist as $pgtype){ |
| 785 |
$checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true; |
| 786 |
echo '<td class="ckbox-type">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>'; |
| 787 |
} |
| 788 |
echo "</tr>"; |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
public function plfactive_table($plugins, $select_cvplugins, $filter) { |
| 793 |
if(empty($select_cvplugins)) |
| 794 |
return; |
| 795 |
|
| 796 |
?> |
| 797 |
<div id="wrap_activation-table"> |
| 798 |
<table id="activation-table" class="widefat"> |
| 799 |
<thead> |
| 800 |
<tr><th class="plugins-name"><?php esc_html_e('Plugins'); ?></th> |
| 801 |
<th class="device-type"><span title="<?php esc_html_e('Desktop Device', 'plf'); ?>" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th> |
| 802 |
<th class="device-type"><span title="<?php esc_html_e('Mobile Device', 'plf'); ?>" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th> |
| 803 |
<th class="ckbox-type"><span title="<?php esc_html_e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th> |
| 804 |
<th class="ckbox-type"><span title="<?php esc_html_e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th> |
| 805 |
<th class="ckbox-type"><span title="<?php esc_html_e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th> |
| 806 |
<th class="ckbox-type"><span title="<?php esc_html_e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th> |
| 807 |
<th class="ckbox-type"><span title="<?php esc_html_e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th> |
| 808 |
<th class="ckbox-type pformat"><span title="<?php esc_html_e('Post : ', 'plf'); esc_html_e('Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th> |
| 809 |
<?php |
| 810 |
$pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' ); |
| 811 |
$exclude = array(); |
| 812 |
if(!empty($filter['exclude'])){ |
| 813 |
foreach ( $filter['exclude'] as $type => $v) { |
| 814 |
if(!empty($v)){ |
| 815 |
$exclude[] = $type; |
| 816 |
} |
| 817 |
} |
| 818 |
} |
| 819 |
foreach ( $pformat as $type) { |
| 820 |
if(!in_array($type, $exclude)){ |
| 821 |
$title = esc_html__('Post : ', 'plf') . $type; |
| 822 |
$icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type"; |
| 823 |
echo '<th class="ckbox-type pformat"><span title="' . $title . '" class="dashicons ' . $icon .'"></span><br /><span style="font-size:xx-small">' . $type .'</span></th>'; |
| 824 |
} |
| 825 |
} |
| 826 |
if(function_exists('is_embed')){ |
| 827 |
$title = esc_html__('WordPress Embed Content Card (API)', 'plf'); |
| 828 |
echo "<th class='ckbox-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>"; |
| 829 |
} |
| 830 |
$post_types = get_post_types( array('public' => true, '_builtin' => false) ); |
| 831 |
foreach ( $post_types as $post_type ) { |
| 832 |
if(!empty($post_type)){ |
| 833 |
$title = esc_html__('Custom Post : ', 'plf') . $post_type; |
| 834 |
echo "<th class='ckbox-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>"; |
| 835 |
} |
| 836 |
} |
| 837 |
?> |
| 838 |
</tr> |
| 839 |
</thead> |
| 840 |
<tbody class="plugins-table-body"> |
| 841 |
<?php |
| 842 |
$nplugins = $jmodules = $cmodules = $allmodule = array(); |
| 843 |
foreach ( $plugins as $p_key => $p_data ) { |
| 844 |
$p_name = self::pluginkey_to_name($p_key); |
| 845 |
if(empty($p_name)) |
| 846 |
continue; |
| 847 |
if(strpos($p_key, 'jetpack_module/') !== false) |
| 848 |
$jmodules[] = $p_key; |
| 849 |
else if(strpos($p_key, 'celtispack_module/') !== false) |
| 850 |
$cmodules[] = $p_key; |
| 851 |
else |
| 852 |
$nplugins[] = $p_key; |
| 853 |
} |
| 854 |
$chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post'); |
| 855 |
foreach ( $pformat as $type) { |
| 856 |
if(!in_array($type, $exclude)){ |
| 857 |
$chklist[] = "post-$type"; |
| 858 |
} |
| 859 |
} |
| 860 |
if(function_exists('is_embed')){ |
| 861 |
$chklist[] = 'content-card'; |
| 862 |
} |
| 863 |
$post_types = get_post_types( array('public' => true, '_builtin' => false) ); |
| 864 |
foreach ( $post_types as $post_type ) { |
| 865 |
$chklist[] = $post_type; |
| 866 |
} |
| 867 |
foreach ( $nplugins as $p_key ) { |
| 868 |
if(strpos($p_key, 'jetpack/') !== false){ |
| 869 |
foreach ( $jmodules as $p_key ) { |
| 870 |
$this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); |
| 871 |
} |
| 872 |
} |
| 873 |
else if(strpos($p_key, 'celtispack/') !== false){ |
| 874 |
foreach ( $cmodules as $p_key ) { |
| 875 |
$this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); |
| 876 |
} |
| 877 |
} |
| 878 |
else { |
| 879 |
$this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); |
| 880 |
} |
| 881 |
} |
| 882 |
?> |
| 883 |
</tbody> |
| 884 |
</table> |
| 885 |
</div> |
| 886 |
<?php |
| 887 |
} |
| 888 |
|
| 889 |
//Option Setting Form Display |
| 890 |
public function plf_option_page() { |
| 891 |
$clear_dialog = esc_html__('Plugin Load Filter Settings\nClick OK to clear it.', 'plf'); |
| 892 |
?> |
| 893 |
<h2><?php esc_html_e('Plugin Load Filter Settings', 'plf'); ?></h2> |
| 894 |
<p></p> |
| 895 |
<div id="plf-setting-tabs"> |
| 896 |
<ul> |
| 897 |
<li><a href="#plf-registration-tab" ><?php esc_html_e('Filter Registration', 'plf'); ?></a></li> |
| 898 |
<li><a href="#plf-activation-tab" ><?php esc_html_e('Page Type Activation', 'plf'); ?></a></li> |
| 899 |
</ul> |
| 900 |
<div id="plf-registration-tab" style="display : none;"> |
| 901 |
<form method="post" autocomplete="off"> |
| 902 |
<?php wp_nonce_field( 'plugin_load_filter'); ?> |
| 903 |
<?php $this->plfregist_table(self::$plugins_inf, self::$filter); ?> |
| 904 |
<p class="submit"> |
| 905 |
<input type="submit" class="button-primary" name="clear_regist_filter" value="<?php esc_html_e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" /> |
| 906 |
<input type="submit" class="button-primary" name="edit_regist_filter" value="<?php esc_html_e('Filter Entry »', 'plf'); ?>" /> |
| 907 |
</p> |
| 908 |
</form> |
| 909 |
</div> |
| 910 |
<div id="plf-activation-tab" style="display : none;"> |
| 911 |
<form method="post" autocomplete="off"> |
| 912 |
<?php wp_nonce_field( 'plugin_load_filter'); ?> |
| 913 |
<?php |
| 914 |
$pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array(); |
| 915 |
if(!empty($pgfilter)){ |
| 916 |
$this->plfactive_table(self::$plugins_inf, $pgfilter, self::$filter); |
| 917 |
?> |
| 918 |
<br /> |
| 919 |
<p><?php |
| 920 |
echo self::decode_safe_tag( 'span', esc_html__('Select plugins to be activated for each page type by clicking on <span class="dashicons dashicons-admin-plugins"></span> mark from "page type filter" registered plugins.', 'plf')); |
| 921 |
?><br /> |
| 922 |
<?php esc_html_e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?> |
| 923 |
</p> |
| 924 |
<p class="submit"> |
| 925 |
<input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php esc_html_e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" /> |
| 926 |
<input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php esc_html_e('Activate Plugin Entry »', 'plf'); ?>" /> |
| 927 |
</p> |
| 928 |
<?php |
| 929 |
} else { |
| 930 |
?> |
| 931 |
<br /> |
| 932 |
<p><span style="color: #ff0000;"><?php esc_html_e('Page Filter is not registered', 'plf') ?></span></p> |
| 933 |
<?php |
| 934 |
} |
| 935 |
?> |
| 936 |
</form> |
| 937 |
</div> |
| 938 |
</div> |
| 939 |
<?php |
| 940 |
} |
| 941 |
|
| 942 |
/*************************************************************************** |
| 943 |
* Meta box |
| 944 |
* Individual of the plug-in filter meta box for Post/Page/CustomPost |
| 945 |
**************************************************************************/ |
| 946 |
function load_meta_boxes( $post_type, $post ) { |
| 947 |
if ( current_user_can('activate_plugins', $post->ID) ) { |
| 948 |
add_meta_box( 'pluginfilterdiv', esc_html__( 'Plugin Load Filter', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' ); |
| 949 |
//add_action( 'admin_head', array(&$this, 'plf_css' )); |
| 950 |
add_action( 'admin_footer', array(&$this, 'plf_meta_script' )); |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
//Plugin pagefilter Selected Checkbox (plugin and modules list) |
| 955 |
// $p_key |
| 956 |
// $select_cvplugins : csv string : pagefilter selected plugins |
| 957 |
// $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins |
| 958 |
function _pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ) { |
| 959 |
|
| 960 |
$html = ''; |
| 961 |
$selplugins = array_map("trim", explode(',', $select_cvplugins)); |
| 962 |
$device['desktop'] = $checked_arcvplugins['desktop']; |
| 963 |
$device['mobile'] = $checked_arcvplugins['mobile']; |
| 964 |
$devlist = array('desktop','mobile'); |
| 965 |
if(in_array( $p_key, $selplugins )){ |
| 966 |
$p_name = self::pluginkey_to_name($p_key); |
| 967 |
$html .= "<tr><td class='plugins-name'>$p_name</td>"; |
| 968 |
foreach($devlist as $devtype){ |
| 969 |
$checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true; |
| 970 |
$html .= "<td class='device-type $devtype'>" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>'; |
| 971 |
} |
| 972 |
$html .= "</tr>"; |
| 973 |
} |
| 974 |
return $html; |
| 975 |
} |
| 976 |
|
| 977 |
//Plugin pagefilter Selected Checkbox (plugin and modules list) |
| 978 |
// $plugins : array : all active plugins |
| 979 |
// $select_cvplugins : csv string : pagefilter selected plugins |
| 980 |
// $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins |
| 981 |
function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_arcvplugins ) { |
| 982 |
|
| 983 |
if(empty($select_cvplugins)) |
| 984 |
return esc_html__('Page Filter is not registered', 'plf'); |
| 985 |
|
| 986 |
$html = '<table id="activation-table">'; |
| 987 |
$html .= '<thead>'; |
| 988 |
$html .= '<tr><th class="plugins-name">'. esc_html__('Plugins') . '</th>'; |
| 989 |
$html .= '<th class="device-type"><span title="'. esc_html__('Desktop Device', 'plf'). '" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>'; |
| 990 |
$html .= '<th class="device-type"><span title="'. esc_html__('Mobile Device', 'plf'). '" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>'; |
| 991 |
$html .= '</tr>'; |
| 992 |
$html .= '</thead>'; |
| 993 |
$html .= '<tbody class="plugins-table-body meta-boxes-plugins-table">'; |
| 994 |
$nplugins = $jmodules = $cmodules = array(); |
| 995 |
foreach ( $plugins as $p_key => $p_data ) { |
| 996 |
$p_name = self::pluginkey_to_name($p_key); |
| 997 |
if(empty($p_name)) |
| 998 |
continue; |
| 999 |
if(strpos($p_key, 'jetpack_module/') !== false) |
| 1000 |
$jmodules[] = $p_key; |
| 1001 |
else if(strpos($p_key, 'celtispack_module/') !== false) |
| 1002 |
$cmodules[] = $p_key; |
| 1003 |
else |
| 1004 |
$nplugins[] = $p_key; |
| 1005 |
} |
| 1006 |
|
| 1007 |
foreach ( $nplugins as $p_key ) { |
| 1008 |
if(strpos($p_key, 'jetpack/') !== false){ |
| 1009 |
foreach ( $jmodules as $p_key ) { |
| 1010 |
$html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); |
| 1011 |
} |
| 1012 |
} |
| 1013 |
else if(strpos($p_key, 'celtispack/') !== false){ |
| 1014 |
foreach ( $cmodules as $p_key ) { |
| 1015 |
$html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
else { |
| 1019 |
$html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); |
| 1020 |
} |
| 1021 |
} |
| 1022 |
$html .= '</tbody>'; |
| 1023 |
$html .= '</table>'; |
| 1024 |
return $html; |
| 1025 |
} |
| 1026 |
|
| 1027 |
//get_locale に加えたフィルターフックを外してサイトのロケールを取得 |
| 1028 |
static function get_site_locale(){ |
| 1029 |
global $locale; |
| 1030 |
if(class_exists('Plf_filter')){ |
| 1031 |
remove_filter( 'locale', array('Plf_filter', 'post_locale') ); |
| 1032 |
$locale = null; |
| 1033 |
$site_locale = get_locale(); |
| 1034 |
add_filter( 'locale', array('Plf_filter', 'post_locale') ); |
| 1035 |
} else { |
| 1036 |
$locale = null; |
| 1037 |
$site_locale = get_locale(); |
| 1038 |
} |
| 1039 |
return $site_locale; |
| 1040 |
} |
| 1041 |
|
| 1042 |
function plf_meta_box( $post, $box ) { |
| 1043 |
if(is_object($post)){ |
| 1044 |
$myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true ); |
| 1045 |
//ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile' |
| 1046 |
if(is_array($myfilter) && !empty($myfilter['plugins'])){ |
| 1047 |
$myfilter['desktop'] = $myfilter['plugins']; |
| 1048 |
$myfilter['mobile'] = $myfilter['plugins']; |
| 1049 |
unset($myfilter['plugins']); |
| 1050 |
} |
| 1051 |
$default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => ''); |
| 1052 |
$option = (!empty($myfilter) && is_array($myfilter))? $myfilter : $default; |
| 1053 |
$option = wp_parse_args( $option, $default); |
| 1054 |
$pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array(); |
| 1055 |
$ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID ); |
| 1056 |
$this->plf_css(); |
| 1057 |
?> |
| 1058 |
<div id="plugin-filter-select"> |
| 1059 |
<p><?php esc_html_e( 'Plugin filter for Single post', 'plf' ); ?></p> |
| 1060 |
<label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php esc_html_e('Not Use', 'plf' ); ?></label> |
| 1061 |
<label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php esc_html_e('Use', 'plf'); ?></label> |
| 1062 |
<div id="page-filter-stat"> |
| 1063 |
<?php echo $this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option ); ?> |
| 1064 |
</div> |
| 1065 |
<div class="plf-option-info"><?php esc_html_e('Plugin Activate/Deactivate filter for this Post only', 'plf'); ?></div> |
| 1066 |
<?php |
| 1067 |
$c_locale = $o_post_id = ''; |
| 1068 |
$languages = array(); |
| 1069 |
$locale_mode = 'style="display:none;"'; |
| 1070 |
if(!empty(self::$filter['language'])){ |
| 1071 |
$languages = get_available_languages(); |
| 1072 |
$site_locale = self::get_site_locale(); |
| 1073 |
//bogo と同じ _locale ポストメタデータ採用 |
| 1074 |
$c_locale = get_post_meta( $post->ID, '_locale', true ); |
| 1075 |
if(empty($c_locale)){ |
| 1076 |
$c_locale = $site_locale; |
| 1077 |
} |
| 1078 |
if ( ! in_array( $c_locale, $languages ) ) { |
| 1079 |
$c_locale = ''; |
| 1080 |
} |
| 1081 |
$o_post_id = get_post_meta( $post->ID, '_original_post_id', true ); |
| 1082 |
$o_post_id = (is_numeric($o_post_id))? $o_post_id : ''; |
| 1083 |
$locale_mode = ''; |
| 1084 |
} |
| 1085 |
echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. esc_html__('Save') .'</a></p>'; |
| 1086 |
?> |
| 1087 |
<hr> |
| 1088 |
<div id="plf-post-locale-select" <?php echo $locale_mode; ?>> |
| 1089 |
<p><?php esc_html_e( 'Language of this post', 'plf' ); ?> <span class="dashicons dashicons-translation" aria-hidden="true"></span></p> |
| 1090 |
<?php |
| 1091 |
wp_dropdown_languages( |
| 1092 |
array( |
| 1093 |
'name' => 'plf_locale', |
| 1094 |
'id' => 'plf_locale', |
| 1095 |
'selected' => $c_locale, |
| 1096 |
'languages' => $languages, |
| 1097 |
'show_available_translations' => false, |
| 1098 |
) |
| 1099 |
); |
| 1100 |
?> |
| 1101 |
<p><?php esc_html_e( 'Original post ID for hreflang', 'plf' ); ?></p> |
| 1102 |
<input type="text" id="plf_original_post_id" name="plf_original_post_id" size="8" value="<?php echo $o_post_id; ?>" /> |
| 1103 |
<div class="hflang-group-edit-lonk"> |
| 1104 |
<?php |
| 1105 |
$id = (is_numeric($o_post_id))? $o_post_id : $post->ID; |
| 1106 |
global $wpdb; |
| 1107 |
$ids = $wpdb->get_row($wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_original_post_id' AND meta_value = %d", $id ), ARRAY_N); |
| 1108 |
if(is_array($ids)){ |
| 1109 |
if(!in_array((string)$id, $ids)){ |
| 1110 |
$ids[] = (string)$id; |
| 1111 |
} |
| 1112 |
if(count($ids) > 1){ |
| 1113 |
foreach ($ids as $v) { |
| 1114 |
if( $post->ID != $v){ |
| 1115 |
$l = get_post_meta( $v, '_locale', true ); |
| 1116 |
if(empty($l)){ |
| 1117 |
$l = $site_locale; |
| 1118 |
} |
| 1119 |
$url = get_edit_post_link( $v ); |
| 1120 |
if(!empty($url)){ |
| 1121 |
echo '<p><a class="edit-post-locale-link" target="_blank" href="' . $url .'" rel="external noreferrer noopener">' . esc_html__('Edit Post') . " ($l) " . '<span class="dashicons dashicons-external" aria-hidden="true"></span></a></p>'; |
| 1122 |
} |
| 1123 |
} |
| 1124 |
} |
| 1125 |
} |
| 1126 |
} |
| 1127 |
?> |
| 1128 |
</div> |
| 1129 |
<div class="plf-option-info"><?php esc_html_e('Use MO translation file for the selected locale. When Original Post ID is registered, posts with the same Original Post ID are treated as `hreflang` metadata group.', 'plf'); ?></div> |
| 1130 |
<?php echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. esc_html__('Save') .'</a></p>'; ?> |
| 1131 |
</div> |
| 1132 |
</div> |
| 1133 |
<?php |
| 1134 |
} |
| 1135 |
} |
| 1136 |
|
| 1137 |
//wp_ajax_plugin_load_filter called function |
| 1138 |
function plf_ajax_postidfilter() { |
| 1139 |
if ( isset($_POST['post_id']) ) { |
| 1140 |
$pid = (int) $_POST['post_id']; |
| 1141 |
if ( !current_user_can( 'activate_plugins', $pid ) ) |
| 1142 |
wp_die( -1 ); |
| 1143 |
check_ajax_referer( "plugin_load_filter-$pid" ); |
| 1144 |
|
| 1145 |
if(!empty(self::$filter['language'])){ |
| 1146 |
if(isset($_POST['locale'])){ |
| 1147 |
$s_locale = (!empty($_POST['locale']))? $_POST['locale'] : 'en_US'; |
| 1148 |
$languages = get_available_languages(); |
| 1149 |
$languages[] = 'en_US'; //add WP default locale |
| 1150 |
if ( in_array( $s_locale, $languages ) ) { |
| 1151 |
$g_locale = get_post_meta( $pid, '_locale', true ); |
| 1152 |
global $locale; |
| 1153 |
if(class_exists('Plf_filter')){ |
| 1154 |
remove_filter( 'locale', array('Plf_filter', 'post_locale') ); |
| 1155 |
$locale = null; |
| 1156 |
$o_locale = get_locale(); |
| 1157 |
add_filter( 'locale', array('Plf_filter', 'post_locale') ); |
| 1158 |
} else { |
| 1159 |
$locale = null; |
| 1160 |
$o_locale = get_locale(); |
| 1161 |
} |
| 1162 |
if($s_locale !== $g_locale){ |
| 1163 |
if($s_locale === $o_locale){ |
| 1164 |
delete_post_meta( $pid, '_locale'); |
| 1165 |
} else { |
| 1166 |
update_post_meta( $pid, '_locale', $s_locale ); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
} |
| 1170 |
} |
| 1171 |
if(isset($_POST['original_post_id'])){ |
| 1172 |
if(empty($_POST['original_post_id'])){ |
| 1173 |
delete_post_meta( $pid, '_original_post_id'); |
| 1174 |
} elseif(preg_match( '/([0-9]+)?/', $_POST['original_post_id'], $match )){ |
| 1175 |
$o_id = (int)$match[1]; |
| 1176 |
$post = get_post($o_id); |
| 1177 |
if(is_object($post)){ |
| 1178 |
$g_id = get_post_meta( $pid, '_original_post_id', true ); |
| 1179 |
if($o_id !== $g_id){ |
| 1180 |
update_post_meta( $pid, '_original_post_id', $o_id ); |
| 1181 |
} |
| 1182 |
} |
| 1183 |
} |
| 1184 |
} |
| 1185 |
} |
| 1186 |
$pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array(); |
| 1187 |
$option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter']; |
| 1188 |
if('default' == $option["filter"]){ |
| 1189 |
delete_post_meta( $pid, '_plugin_load_filter'); |
| 1190 |
} else { |
| 1191 |
$plugins = array(); |
| 1192 |
if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){ |
| 1193 |
if(!empty($matches[1])){ |
| 1194 |
foreach ($matches[1] as $plugin){ |
| 1195 |
$plugins[] = $plugin; |
| 1196 |
} |
| 1197 |
$option["desktop"] = implode(",", $plugins); |
| 1198 |
} |
| 1199 |
} |
| 1200 |
$plugins = array(); |
| 1201 |
if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $_POST['mobile'], $matches)){ |
| 1202 |
if(!empty($matches[1])){ |
| 1203 |
foreach ($matches[1] as $plugin){ |
| 1204 |
$plugins[] = $plugin; |
| 1205 |
} |
| 1206 |
$option["mobile"] = implode(",", $plugins); |
| 1207 |
} |
| 1208 |
} |
| 1209 |
update_post_meta( $pid, '_plugin_load_filter', $option ); |
| 1210 |
} |
| 1211 |
|
| 1212 |
$html = $this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option ); |
| 1213 |
wp_send_json_success($html); |
| 1214 |
} |
| 1215 |
wp_die( 0 ); |
| 1216 |
} |
| 1217 |
|
| 1218 |
//alternate hreflang meta tag |
| 1219 |
static function altenate_hreflang() { |
| 1220 |
if ( is_singular() ) { |
| 1221 |
global $post, $wpdb; |
| 1222 |
$pid = $post->ID; |
| 1223 |
$oid = get_post_meta( $pid, '_original_post_id', true ); |
| 1224 |
$oid = (is_numeric($oid))? $oid : $pid; |
| 1225 |
$ids = $wpdb->get_row($wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_original_post_id' AND meta_value = %d", $oid ), ARRAY_N); |
| 1226 |
if(is_array($ids)){ |
| 1227 |
if(!in_array((string)$oid, $ids)){ |
| 1228 |
$ids[] = (string)$oid; |
| 1229 |
} |
| 1230 |
if(count($ids) > 1){ |
| 1231 |
$site_locale = self::get_site_locale(); |
| 1232 |
foreach ($ids as $id) { |
| 1233 |
$l = get_post_meta( $id, '_locale', true ); |
| 1234 |
if(empty($l)){ |
| 1235 |
$l = $site_locale; |
| 1236 |
} |
| 1237 |
$url = get_permalink( $id ); |
| 1238 |
echo '<link rel="alternate" hreflang="' . esc_attr($l) . '" href="' . esc_url($url) .'" />' . PHP_EOL; |
| 1239 |
} |
| 1240 |
} |
| 1241 |
} |
| 1242 |
} |
| 1243 |
} |
| 1244 |
|
| 1245 |
/*************************************************************************** |
| 1246 |
* Javascript |
| 1247 |
**************************************************************************/ |
| 1248 |
function activetab_script() { ?> |
| 1249 |
<script type='text/javascript' > |
| 1250 |
/* <![CDATA[ */ |
| 1251 |
var plf_activetab = <?php echo $this->tab_num; ?> |
| 1252 |
/* ]]> */ |
| 1253 |
jQuery(document).ready(function ($) { |
| 1254 |
plf_setting_tabs(); |
| 1255 |
function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); } |
| 1256 |
}); |
| 1257 |
</script> |
| 1258 |
<?php } |
| 1259 |
|
| 1260 |
function plf_meta_script() { |
| 1261 |
$reload_dialog = esc_html__('Plugin Load Filter setting has been updated.\nClick OK to reload the page.', 'plf'); |
| 1262 |
?> |
| 1263 |
<script type='text/javascript' > |
| 1264 |
WPAddPagePluginLoadFilter = function(nonce){ |
| 1265 |
jQuery.ajax({ |
| 1266 |
type: 'POST', |
| 1267 |
url: ajaxurl, |
| 1268 |
data: { |
| 1269 |
action: "plugin_load_filter", |
| 1270 |
post_id : jQuery( '#post_ID' ).val(), |
| 1271 |
_ajax_nonce: nonce, |
| 1272 |
locale: jQuery("select[name='plf_locale']").val(), |
| 1273 |
original_post_id: jQuery("input[name='plf_original_post_id']").val(), |
| 1274 |
filter: jQuery("input[name='pagefilter']:checked").val(), |
| 1275 |
desktop: jQuery('.meta-boxes-plugins-table td.desktop input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), |
| 1276 |
mobile: jQuery('.meta-boxes-plugins-table td.mobile input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), |
| 1277 |
}, |
| 1278 |
dataType: 'json', |
| 1279 |
}).then( |
| 1280 |
function (response, dataType) { |
| 1281 |
jQuery('#page-filter-stat').html(response.data); |
| 1282 |
if(window.confirm('<?php echo $reload_dialog; ?>')){ |
| 1283 |
location.reload(); |
| 1284 |
} |
| 1285 |
}, |
| 1286 |
function () { /* alert("ajax error"); */ } |
| 1287 |
); |
| 1288 |
}; |
| 1289 |
</script> |
| 1290 |
<?php } |
| 1291 |
} |
| 1292 |
|