| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: plugin load filter |
| 4 | 4 | Description: Dynamically activate the selected plugins for each page. Response will be faster by filtering plugins. |
| 5 | - Version: 2.1.0 | |
| 5 | + Version: 2.4.0 | |
| 6 | 6 | Plugin URI: http://celtislab.net/wp_plugin_load_filter |
| 7 | 7 | Author: enomoto@celtislab |
| 8 | 8 | Author URI: http://celtislab.net/ |
| 9 | 9 | License: GPLv2 |
| @@ -9,9 +9,87 @@ | ||
| 9 | 9 | License: GPLv2 |
| 10 | 10 | Text Domain: plf |
| 11 | 11 | Domain Path: /languages |
| 12 | 12 | */ |
| 13 | +defined( 'ABSPATH' ) || exit; | |
| 13 | 14 | |
| 15 | +/*************************************************************************** | |
| 16 | + * plugin activation / deactivation / uninstall | |
| 17 | + **************************************************************************/ | |
| 18 | +if(is_admin()){ | |
| 19 | + function plugin_load_filter_activation( $network_wide ) { | |
| 20 | + //plf-filter must-use plagin activete check | |
| 21 | + if(wp_mkdir_p( WPMU_PLUGIN_DIR )){ | |
| 22 | + if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 23 | + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); | |
| 24 | + } | |
| 25 | + else { | |
| 26 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); | |
| 27 | + $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false ); | |
| 28 | + $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false ); | |
| 29 | + if(version_compare( $dp['Version'], $sp['Version'], '!=')){ | |
| 30 | + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); | |
| 31 | + } | |
| 32 | + } | |
| 33 | + } | |
| 34 | + } | |
| 35 | + register_activation_hook( __FILE__, 'plugin_load_filter_activation' ); | |
| 36 | + | |
| 37 | + //deactivation | |
| 38 | + function plugin_load_filter_deactivation( $network_deactivating ) { | |
| 39 | + $act = false; | |
| 40 | + if (is_multisite()) { | |
| 41 | + if(! $network_deactivating){ | |
| 42 | + global $wpdb; | |
| 43 | + $current_blog_id = get_current_blog_id(); | |
| 44 | + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 45 | + foreach ( $blog_ids as $blog_id ) { | |
| 46 | + if($blog_id == $current_blog_id){ | |
| 47 | + //current site | |
| 48 | + } | |
| 49 | + else { | |
| 50 | + //other site active check | |
| 51 | + switch_to_blog( $blog_id ); | |
| 52 | + if ( is_plugin_active( plugin_basename( __FILE__ ))) | |
| 53 | + $act = true; | |
| 54 | + } | |
| 55 | + } | |
| 56 | + switch_to_blog( $current_blog_id ); | |
| 57 | + } | |
| 58 | + } | |
| 59 | + if($act === false){ | |
| 60 | + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 61 | + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | + register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' ); | |
| 66 | + | |
| 67 | + //uninstall | |
| 68 | + function plugin_load_filter_uninstall() { | |
| 69 | + | |
| 70 | + if ( !is_multisite()) { | |
| 71 | + delete_option('plf_queryvars'); | |
| 72 | + delete_option('plf_option' ); | |
| 73 | + } else { | |
| 74 | + global $wpdb; | |
| 75 | + $current_blog_id = get_current_blog_id(); | |
| 76 | + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 77 | + foreach ( $blog_ids as $blog_id ) { | |
| 78 | + switch_to_blog( $blog_id ); | |
| 79 | + delete_option('plf_queryvars'); | |
| 80 | + delete_option('plf_option' ); | |
| 81 | + } | |
| 82 | + switch_to_blog( $current_blog_id ); | |
| 83 | + } | |
| 84 | + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 85 | + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall'); | |
| 89 | + | |
| 90 | +} | |
| 91 | + | |
| 14 | 92 | $Plf_setting = new Plf_setting(); |
| 15 | 93 | |
| 16 | 94 | class Plf_setting { |
| 17 | 95 | |
| @@ -23,11 +101,17 @@ | ||
| 23 | 101 | * Style Sheet |
| 24 | 102 | **************************************************************************/ |
| 25 | 103 | function plf_css() { ?> |
| 26 | 104 | <style type="text/css"> |
| 27 | - .plugins-list { max-width : 480px; min-height: 80px; max-height: 320px; overflow: auto; border: 1px solid #CEE1EF; padding:0.5em 0.5em;} | |
| 28 | - ul.plugins-list ul { margin-left: 20px; } | |
| 29 | - ul.plugins-list li { margin: 0; padding: 0; line-height: 22px; word-wrap: break-word;} | |
| 105 | + #activation-table { margin-top: 10px; border: 1px solid #eee;} | |
| 106 | + #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;} | |
| 107 | + thead .plugins-name { background-color: aliceblue;} | |
| 108 | + thead .device-type { background-color: oldlace;} | |
| 109 | + thead .plugins-name, tbody .plugins-name { min-width: 172px; max-width: 172px;} | |
| 110 | + thead .device-type, tbody .device-type { min-width: 36px; max-width: 36px; padding: 0;} | |
| 111 | + .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;} | |
| 112 | + .device-type label { color: whitesmoke; margin-left: -28px; } | |
| 113 | + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; } | |
| 30 | 114 | </style> |
| 31 | 115 | <?php } |
| 32 | 116 | |
| 33 | 117 | function jquery_tab_css() { ?> |
| @@ -49,17 +133,39 @@ | ||
| 49 | 133 | .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; } |
| 50 | 134 | .ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited { color: #ffffff; text-decoration: none; } |
| 51 | 135 | .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; } |
| 52 | 136 | |
| 53 | - #registration-table input[type=radio], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;} | |
| 54 | - .dashicons:before { font-size: 24px; } | |
| 55 | - .radio-green label, .radio-red label, .altcheckbox label { color: #ddd; margin-left: -28px; } | |
| 137 | + #wrap_registration-table, #wrap_activation-table { overflow-x:auto;} | |
| 138 | + #registration-table input[type=radio], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;} | |
| 139 | + thead, tbody { display: block;} | |
| 140 | + .plugins-table-body { overflow-y:scroll; height:500px; } | |
| 141 | + .widefat td, .widefat th { padding: 8px 4px;} | |
| 142 | + thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;} | |
| 143 | + .filter-none, .filter-admin, .filter-tmpl { background-color: oldlace;} | |
| 144 | + thead .device-type { background-color: oldlace;} | |
| 145 | + thead .tmpl-type { background-color: lavender;} | |
| 146 | + thead .pformat { background-color: honeydew;} | |
| 147 | + thead .tmpl-embed { background-color: lightyellow;} | |
| 148 | + thead .tmpl-custom { background-color: lavenderblush;} | |
| 149 | + thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px; max-width: 260px;} | |
| 150 | + thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;} | |
| 151 | + thead .filter-type, tbody .filter-type { min-width: 100px; max-width: 100px;} | |
| 152 | + thead .device-type, tbody .device-type, thead .tmpl-type, tbody .tmpl-type { min-width: 40px; max-width: 40px; } | |
| 153 | + .filter-description { padding: 0 10px 20px 10px;} | |
| 154 | + .exclude-pformat { padding: 16px 0 20px} | |
| 155 | + .exclude-pformat label { white-space:nowrap;} | |
| 156 | + .exclude-pformat span { margin-right: 12px; } | |
| 157 | + .dashicons:before { font-size: 24px; } | |
| 158 | + .radio-green label, .radio-red label, .tmpl-type label { color: #ddd; margin-left: -28px; } | |
| 56 | 159 | .radio-green input[type="radio"]:checked + label { color: #339966; } |
| 57 | 160 | .radio-red input[type="radio"]:checked + label { color: #ff0000; } |
| 58 | - .altcheckbox input[type="checkbox"]:checked + label { color: #339966; } | |
| 161 | + .tmpl-type input[type="checkbox"]:checked + label { color: #339966; } | |
| 162 | + .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;} | |
| 163 | + .device-type label { color: whitesmoke; margin-left: -28px; } | |
| 164 | + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; } | |
| 59 | 165 | </style> |
| 60 | 166 | <?php } |
| 61 | - | |
| 167 | + | |
| 62 | 168 | /*************************************************************************** |
| 63 | 169 | * Plugin Load Filter Option Setting |
| 64 | 170 | **************************************************************************/ |
| 65 | 171 | |
| @@ -67,47 +173,35 @@ | ||
| 67 | 173 | |
| 68 | 174 | load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' ); |
| 69 | 175 | |
| 70 | 176 | $this->filter = get_option('plf_option'); |
| 177 | + //v2.3.0 option change | |
| 178 | + if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){ | |
| 179 | + $this->filter['optver'] = '2'; | |
| 180 | + | |
| 181 | + if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){ | |
| 182 | + //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile' | |
| 183 | + if(!empty($this->filter['_pagefilter'])){ | |
| 184 | + $this->filter['group']['desktop'] = $this->filter['_pagefilter']; | |
| 185 | + $this->filter['group']['mobile'] = $this->filter['_pagefilter']; | |
| 186 | + } | |
| 187 | + if(!empty($this->filter['_desktop'])){ | |
| 188 | + $this->filter['_desktop'] = null; | |
| 189 | + } | |
| 190 | + if(!empty($this->filter['_mobile'])){ | |
| 191 | + $this->filter['_mobile'] = null; | |
| 192 | + } | |
| 193 | + } | |
| 194 | + } | |
| 195 | + | |
| 71 | 196 | if(is_admin()) { |
| 72 | 197 | add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 ); |
| 73 | - add_action( 'update_option_plf_option', array(&$this, 'plf_transient_clear') ); | |
| 74 | - add_action( 'update_option_active_plugins', array(&$this, 'plf_transient_clear') ); | |
| 75 | - add_action( 'update_option_jetpack_active_modules', array(&$this, 'plf_transient_clear') ); | |
| 76 | - add_action( 'update_option_celtispack_active_modules', array(&$this, 'plf_transient_clear') ); | |
| 198 | + add_action( 'admin_init', array(&$this, 'action_posts')); | |
| 77 | 199 | add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 ); |
| 78 | - //plf-filter must-use plagin activete check | |
| 79 | - if(wp_mkdir_p( WPMU_PLUGIN_DIR )){ | |
| 80 | - if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 81 | - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); | |
| 82 | - } | |
| 83 | - } | |
| 84 | - register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' ); | |
| 85 | - register_uninstall_hook(__FILE__, 'Plf_setting::uninstall'); | |
| 86 | 200 | } |
| 87 | - add_action( 'save_post', array(&$this, 'plf_transient_clear') ); | |
| 88 | - add_action( 'deleted_post', array(&$this, 'plf_transient_clear') ); | |
| 89 | 201 | add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter')); |
| 90 | 202 | } |
| 91 | 203 | |
| 92 | - //Plugin Deactivate | |
| 93 | - public static function deactivation() { | |
| 94 | - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 95 | - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); | |
| 96 | - } | |
| 97 | - } | |
| 98 | - //Plugin Uninstall | |
| 99 | - public static function uninstall() { | |
| 100 | - delete_option('plf_queryvars'); | |
| 101 | - delete_option('plf_option' ); | |
| 102 | - } | |
| 103 | - | |
| 104 | - //Disable the transient cache by changing the update time | |
| 105 | - public function plf_transient_clear() { | |
| 106 | - $this->filter['updated'] = strtotime("now"); | |
| 107 | - update_option('plf_option', $this->filter ); | |
| 108 | - } | |
| 109 | - | |
| 110 | 204 | //Plugin Load Filter admin setting start |
| 111 | 205 | public function plf_admin_start() { |
| 112 | 206 | require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 113 | 207 | |
| @@ -141,9 +235,8 @@ | ||
| 141 | 235 | } |
| 142 | 236 | if ( empty( $this->plugins_inf ) ) |
| 143 | 237 | return; |
| 144 | 238 | |
| 145 | - $this->action_posts(); //POST, GET Request Action | |
| 146 | 239 | add_action('admin_menu', array(&$this, 'plf_option_menu')); |
| 147 | 240 | } |
| 148 | 241 | |
| 149 | 242 | //Plugins sub menu add |
| @@ -164,13 +257,13 @@ | ||
| 164 | 257 | } |
| 165 | 258 | |
| 166 | 259 | //plugin filter option action request (add, update, delete) |
| 167 | 260 | function action_posts() { |
| 168 | - if (current_user_can( 'edit_plugins' )) { | |
| 261 | + if (current_user_can( 'activate_plugins' )) { | |
| 169 | 262 | if( isset($_POST['edit_regist_filter']) ) { |
| 170 | 263 | if(isset($_POST['plfregist'])){ |
| 171 | 264 | check_admin_referer('plugin_load_filter'); |
| 172 | - foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){ | |
| 265 | + foreach( array('_admin', '_pagefilter') as $item){ | |
| 173 | 266 | $plugins = array(); |
| 174 | 267 | foreach ( $_POST['plfregist'] as $p_key => $val ) { |
| 175 | 268 | if($val == $item) |
| 176 | 269 | $plugins[$p_key] = $val; |
| @@ -201,9 +294,19 @@ | ||
| 201 | 294 | } |
| 202 | 295 | $option["plugins"] = implode(",", array_keys($plugins)); |
| 203 | 296 | $this->filter[$item] = $option; |
| 204 | 297 | } |
| 205 | - $this->filter['updated'] = strtotime("now"); | |
| 298 | + if(isset($_POST['plf_option']['exclude'])){ | |
| 299 | + $exclude = array(); | |
| 300 | + foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) { | |
| 301 | + if(!empty($v)) | |
| 302 | + $exclude[$ft] = true; | |
| 303 | + } | |
| 304 | + $this->filter['exclude'] = $exclude; | |
| 305 | + } | |
| 306 | + else { | |
| 307 | + $this->filter['exclude'] = ''; | |
| 308 | + } | |
| 206 | 309 | update_option('plf_option', $this->filter ); |
| 207 | 310 | } |
| 208 | 311 | header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); |
| 209 | 312 | exit; |
| @@ -209,12 +312,12 @@ | ||
| 209 | 312 | exit; |
| 210 | 313 | } |
| 211 | 314 | elseif( isset($_POST['clear_regist_filter']) ) { |
| 212 | 315 | check_admin_referer('plugin_load_filter'); |
| 213 | - foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){ | |
| 316 | + foreach( array('_admin', '_pagefilter') as $item){ | |
| 214 | 317 | $this->filter[$item] = ''; |
| 215 | 318 | } |
| 216 | - $this->filter['updated'] = strtotime("now"); | |
| 319 | + $this->filter['exclude'] = ''; | |
| 217 | 320 | update_option('plf_option', $this->filter ); |
| 218 | 321 | header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); |
| 219 | 322 | exit; |
| 220 | 323 | } |
| @@ -230,9 +333,8 @@ | ||
| 230 | 333 | } |
| 231 | 334 | $option["plugins"] = implode(",", $plugins); |
| 232 | 335 | $this->filter['group'][$item] = $option; |
| 233 | 336 | } |
| 234 | - $this->filter['updated'] = strtotime("now"); | |
| 235 | 337 | update_option('plf_option', $this->filter ); |
| 236 | 338 | } |
| 237 | 339 | header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1')); |
| 238 | 340 | exit; |
| @@ -242,9 +344,8 @@ | ||
| 242 | 344 | $group = array_keys($_POST['plfactive']); |
| 243 | 345 | foreach( $group as $item){ |
| 244 | 346 | $this->filter['group'][$item] = ''; |
| 245 | 347 | } |
| 246 | - $this->filter['updated'] = strtotime("now"); | |
| 247 | 348 | update_option('plf_option', $this->filter ); |
| 248 | 349 | header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1')); |
| 249 | 350 | exit; |
| 250 | 351 | } |
| @@ -295,72 +396,17 @@ | ||
| 295 | 396 | static function altcheckbox($name, $value, $label = '') { |
| 296 | 397 | return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>"; |
| 297 | 398 | } |
| 298 | 399 | |
| 299 | - //Plugin pagefilter Selected Checkbox (plugin and modules list) | |
| 300 | - // $plugins : array : all active plugins | |
| 301 | - // $select_cvplugins : csv string : pagefilter selected plugins | |
| 302 | - // $checked_cvplugins : csv string : checked plugins | |
| 303 | - function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_cvplugins ) { | |
| 304 | - | |
| 305 | - if(empty($select_cvplugins)) | |
| 306 | - return __('Page Filter is not registered', 'plf'); | |
| 307 | - | |
| 308 | - $nplugins = $jmodules = $cmodules = array(); | |
| 309 | - foreach ( $plugins as $p_key => $p_data ) { | |
| 310 | - $p_name = $this->pluginkey_to_name($p_key); | |
| 311 | - if(empty($p_name)) | |
| 312 | - continue; | |
| 313 | - if(strpos($p_key, 'jetpack_module/') !== false) | |
| 314 | - $jmodules[] = $p_key; | |
| 315 | - else if(strpos($p_key, 'celtispack_module/') !== false) | |
| 316 | - $cmodules[] = $p_key; | |
| 317 | - else | |
| 318 | - $nplugins[] = $p_key; | |
| 319 | - } | |
| 320 | - $selplugins = array_map("trim", explode(',', $select_cvplugins)); | |
| 321 | - $chkplugins = array_map("trim", explode(',', $checked_cvplugins)); | |
| 322 | - $html = '<ul class="plugins-list">'; | |
| 323 | - foreach ( $nplugins as $p_key ) { | |
| 324 | - if(strpos($p_key, 'jetpack/') !== false){ | |
| 325 | - foreach ( $jmodules as $p_key ) { | |
| 326 | - if(in_array( $p_key, $selplugins )){ | |
| 327 | - $p_name = $this->pluginkey_to_name($p_key); | |
| 328 | - $checked = in_array( $p_key, $chkplugins ) ? true : false; | |
| 329 | - $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>'; | |
| 330 | - } | |
| 331 | - } | |
| 332 | - } | |
| 333 | - else if(strpos($p_key, 'celtispack/') !== false){ | |
| 334 | - foreach ( $cmodules as $p_key ) { | |
| 335 | - if(in_array( $p_key, $selplugins )){ | |
| 336 | - $p_name = $this->pluginkey_to_name($p_key); | |
| 337 | - $checked = in_array( $p_key, $chkplugins ) ? true : false; | |
| 338 | - $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>'; | |
| 339 | - } | |
| 340 | - } | |
| 341 | - } | |
| 342 | - else if(in_array( $p_key, $selplugins )) { | |
| 343 | - $p_name = $this->pluginkey_to_name($p_key); | |
| 344 | - $checked = in_array( $p_key, $chkplugins ) ? true : false; | |
| 345 | - $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>'; | |
| 346 | - } | |
| 347 | - } | |
| 348 | - $html .= '</ul>'; | |
| 349 | - return $html; | |
| 350 | - } | |
| 351 | - | |
| 352 | 400 | public function plfregist_item($key, $val) { |
| 353 | 401 | $p_name = $this->pluginkey_to_name($key); |
| 354 | 402 | $opt_name = "plfregist[$key]"; |
| 355 | 403 | ?> |
| 356 | 404 | <tr id="plfregist_<?php echo $key; ?>"> |
| 357 | - <td><?php echo $p_name; ?></td> | |
| 358 | - <td class="radio-green"><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 359 | - <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 360 | - <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_desktop" <?php checked('_desktop', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 361 | - <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_mobile" <?php checked('_mobile', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 362 | - <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 405 | + <td class="filter-plugins-name"><?php echo $p_name; ?></td> | |
| 406 | + <td class="radio-green filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 407 | + <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 408 | + <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td> | |
| 363 | 409 | </tr> |
| 364 | 410 | <?php |
| 365 | 411 | } |
| 366 | 412 | |
| @@ -366,19 +412,18 @@ | ||
| 366 | 412 | |
| 367 | 413 | //Filterring plugins select |
| 368 | 414 | public function plfregist_table($plugins, $filter) { |
| 369 | 415 | ?> |
| 416 | + <div id="wrap_registration-table"> | |
| 370 | 417 | <table id="registration-table" class="widefat"> |
| 371 | 418 | <thead> |
| 372 | - <tr><th ><?php _e('Plugins'); ?></th> | |
| 373 | - <th ><?php _e('Normal Load', 'plf'); ?></th> | |
| 374 | - <th ><?php _e('Admin', 'plf'); ?></th> | |
| 375 | - <th ><?php _e('Desktop', 'plf'); ?></th> | |
| 376 | - <th ><?php _e('Mobile', 'plf'); ?></th> | |
| 377 | - <th ><?php _e('Page Filter', 'plf'); ?></th> | |
| 419 | + <tr><th class="filter-plugins-name"><?php _e('Plugins'); ?></th> | |
| 420 | + <th class="filter-type filter-none"><?php _e('Normal Load', 'plf'); ?></th> | |
| 421 | + <th class="filter-type filter-admin"><?php _e('Admin Filter', 'plf'); ?></th> | |
| 422 | + <th class="filter-type filter-tmpl"><?php _e('Page Filter', 'plf'); ?></th> | |
| 378 | 423 | </tr> |
| 379 | 424 | </thead> |
| 380 | - <tbody> | |
| 425 | + <tbody class="plugins-table-body"> | |
| 381 | 426 | <?php |
| 382 | 427 | //plugins filter registoration table |
| 383 | 428 | $plist = array(); |
| 384 | 429 | foreach ( $plugins as $p_key => $val ) { |
| @@ -385,9 +430,9 @@ | ||
| 385 | 430 | $name = $this->pluginkey_to_name($p_key); |
| 386 | 431 | if(!empty($name)) |
| 387 | 432 | $plist[$p_key] = ''; |
| 388 | 433 | } |
| 389 | - foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){ | |
| 434 | + foreach( array('_admin', '_pagefilter') as $item){ | |
| 390 | 435 | $parr = (!empty($filter[$item]['plugins'])) ? array_map("trim", explode(',', $filter[$item]['plugins'])) : array(); |
| 391 | 436 | foreach ( $plist as $p_key => $val ) { |
| 392 | 437 | if(empty($val) && in_array($p_key, $parr)) |
| 393 | 438 | $plist[$p_key] = $item; |
| @@ -421,47 +466,105 @@ | ||
| 421 | 466 | } |
| 422 | 467 | ?> |
| 423 | 468 | </tbody> |
| 424 | 469 | </table> |
| 470 | + <br /> | |
| 471 | + <p><strong>[ Admin Filter ]</strong></p> | |
| 472 | + <div class="filter-description"><?php _e('Plugins to be used only in admin mode.', 'plf'); ?></div> | |
| 473 | + <p><strong>[ Page Filter ]</strong></p> | |
| 474 | + <div class="filter-description"> | |
| 475 | + <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br /> | |
| 476 | + <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?> | |
| 477 | + <div class="exclude-pformat"> | |
| 478 | + <p><strong><?php _e( 'Exclude Post Format Type', 'plf' ); ?></strong><br /> | |
| 479 | + <?php _e('Choose Post Format Type you are not using. To exclude from Page Filter item subject.', 'plf'); ?> | |
| 480 | + </p> | |
| 481 | + <?php | |
| 482 | + $html = '<div>'; | |
| 483 | + $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' ); | |
| 484 | + foreach ( $pformat as $type ) { | |
| 485 | + $checked = (!empty($this->filter['exclude'][$type]))? $this->filter['exclude'][$type] : false; | |
| 486 | + $label = "<span>$type</span>"; | |
| 487 | + $html .= self::checkbox("plf_option[exclude][$type]", $checked, $label); | |
| 488 | + } | |
| 489 | + $html .= '</div>'; | |
| 490 | + echo $html; | |
| 491 | + ?> | |
| 492 | + </div> | |
| 493 | + </div> | |
| 494 | + </div> | |
| 425 | 495 | <?php |
| 426 | 496 | } |
| 427 | 497 | |
| 428 | 498 | //Activate plugins select from Page Filter |
| 499 | + public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) { | |
| 500 | + | |
| 501 | + $selplugins = array_map("trim", explode(',', $select_cvplugins)); | |
| 502 | + $devlist = array('desktop','mobile'); | |
| 503 | + if(in_array( $p_key, $selplugins )){ | |
| 504 | + $p_name = $this->pluginkey_to_name($p_key); | |
| 505 | + echo "<tr><td class='plugins-name'>$p_name</td>"; | |
| 506 | + foreach($devlist as $devtype){ | |
| 507 | + $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true; | |
| 508 | + echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>'; | |
| 509 | + } | |
| 510 | + foreach($chklist as $pgtype){ | |
| 511 | + $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true; | |
| 512 | + echo '<td class="tmpl-type">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>'; | |
| 513 | + } | |
| 514 | + echo "</tr>"; | |
| 515 | + } | |
| 516 | + } | |
| 517 | + | |
| 429 | 518 | public function plfactive_table($plugins, $select_cvplugins, $filter) { |
| 430 | 519 | if(empty($select_cvplugins)) |
| 431 | 520 | return; |
| 432 | 521 | |
| 433 | 522 | ?> |
| 523 | + <div id="wrap_activation-table"> | |
| 434 | 524 | <table id="activation-table" class="widefat"> |
| 435 | 525 | <thead> |
| 436 | - <tr><th ><?php _e('Plugins'); ?></th> | |
| 437 | - <th ><span title="<?php _e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th> | |
| 438 | - <th ><span title="<?php _e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th> | |
| 439 | - <th ><span title="<?php _e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th> | |
| 440 | - <th ><span title="<?php _e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th> | |
| 441 | - <th ><span title="<?php _e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th> | |
| 442 | - <th ><span title="<?php _e('Post : Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th> | |
| 443 | - <th ><span title="<?php _e('Post : Image', 'plf'); ?>" class="dashicons dashicons-format-image"></span><br /><span style="font-size:xx-small">Image</span></th> | |
| 444 | - <th ><span title="<?php _e('Post : Gallery', 'plf'); ?>" class="dashicons dashicons-format-gallery"></span><br /><span style="font-size:xx-small">Gallery</span></th> | |
| 445 | - <th ><span title="<?php _e('Post : Video', 'plf'); ?>" class="dashicons dashicons-format-video"></span><br /><span style="font-size:xx-small">Video</span></th> | |
| 446 | - <th ><span title="<?php _e('Post : Audio', 'plf'); ?>" class="dashicons dashicons-format-audio"></span><br /><span style="font-size:xx-small">Audio</span></th> | |
| 447 | - <th ><span title="<?php _e('Post : Aside', 'plf'); ?>" class="dashicons dashicons-format-aside"></span><br /><span style="font-size:xx-small">Aside</span></th> | |
| 448 | - <th ><span title="<?php _e('Post : Quote', 'plf'); ?>" class="dashicons dashicons-format-quote"></span><br /><span style="font-size:xx-small">Quote</span></th> | |
| 449 | - <th ><span title="<?php _e('Post : Link', 'plf'); ?>" class="dashicons dashicons-admin-links"></span><br /><span style="font-size:xx-small">Link</span></th> | |
| 450 | - <th ><span title="<?php _e('Post : Status', 'plf'); ?>" class="dashicons dashicons-format-status"></span><br /><span style="font-size:xx-small">Status</span></th> | |
| 451 | - <th ><span title="<?php _e('Post : Chat', 'plf'); ?>" class="dashicons dashicons-format-chat"></span><br /><span style="font-size:xx-small">Chat</span></th> | |
| 526 | + <tr><th class="plugins-name"><?php _e('Plugins'); ?></th> | |
| 527 | + <th class="device-type"><span title="<?php _e('Desktop Device', 'plf'); ?>" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th> | |
| 528 | + <th class="device-type"><span title="<?php _e('Mobile Device', 'plf'); ?>" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th> | |
| 529 | + <th class="tmpl-type"><span title="<?php _e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th> | |
| 530 | + <th class="tmpl-type"><span title="<?php _e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th> | |
| 531 | + <th class="tmpl-type"><span title="<?php _e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th> | |
| 532 | + <th class="tmpl-type"><span title="<?php _e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th> | |
| 533 | + <th class="tmpl-type"><span title="<?php _e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th> | |
| 534 | + <th class="tmpl-type pformat"><span title="<?php _e('Post : ', 'plf'); _e('Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th> | |
| 452 | 535 | <?php |
| 536 | + $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' ); | |
| 537 | + $exclude = array(); | |
| 538 | + if(!empty($filter['exclude'])){ | |
| 539 | + foreach ( $filter['exclude'] as $type => $v) { | |
| 540 | + if(!empty($v)){ | |
| 541 | + $exclude[] = $type; | |
| 542 | + } | |
| 543 | + } | |
| 544 | + } | |
| 545 | + foreach ( $pformat as $type) { | |
| 546 | + if(!in_array($type, $exclude)){ | |
| 547 | + $title = __('Post : ', 'plf') . $type; | |
| 548 | + $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type"; | |
| 549 | + echo '<th class="tmpl-type pformat"><span title="' . $title . '" class="dashicons ' . $icon .'"></span><br /><span style="font-size:xx-small">' . $type .'</span></th>'; | |
| 550 | + } | |
| 551 | + } | |
| 552 | + if(function_exists('is_embed')){ | |
| 553 | + $title = __('WordPress Embed Content Card (API)', 'plf'); | |
| 554 | + echo "<th class='tmpl-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>"; | |
| 555 | + } | |
| 453 | 556 | $post_types = get_post_types( array('public' => true, '_builtin' => false) ); |
| 454 | 557 | foreach ( $post_types as $post_type ) { |
| 455 | 558 | if(!empty($post_type)){ |
| 456 | 559 | $title = __('Custom Post : ', 'plf') . $post_type; |
| 457 | - echo "<th ><span title='$title' style='font-size:xx-small'>$post_type</span></th>"; | |
| 560 | + echo "<th class='tmpl-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>"; | |
| 458 | 561 | } |
| 459 | 562 | } |
| 460 | 563 | ?> |
| 461 | 564 | </tr> |
| 462 | 565 | </thead> |
| 463 | - <tbody> | |
| 566 | + <tbody class="plugins-table-body"> | |
| 464 | 567 | <?php |
| 465 | 568 | $nplugins = $jmodules = $cmodules = $allmodule = array(); |
| 466 | 569 | foreach ( $plugins as $p_key => $p_data ) { |
| 467 | 570 | $p_name = $this->pluginkey_to_name($p_key); |
| @@ -473,11 +576,17 @@ | ||
| 473 | 576 | $cmodules[] = $p_key; |
| 474 | 577 | else |
| 475 | 578 | $nplugins[] = $p_key; |
| 476 | 579 | } |
| 477 | - $selplugins = array_map("trim", explode(',', $select_cvplugins)); | |
| 478 | - $chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post', | |
| 479 | - 'post-image', 'post-gallery', 'post-video', 'post-audio', 'post-aside', 'post-quote', 'post-link', 'post-status', 'post-chat'); | |
| 580 | + $chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post'); | |
| 581 | + foreach ( $pformat as $type) { | |
| 582 | + if(!in_array($type, $exclude)){ | |
| 583 | + $chklist[] = "post-$type"; | |
| 584 | + } | |
| 585 | + } | |
| 586 | + if(function_exists('is_embed')){ | |
| 587 | + $chklist[] = 'content-card'; | |
| 588 | + } | |
| 480 | 589 | $post_types = get_post_types( array('public' => true, '_builtin' => false) ); |
| 481 | 590 | foreach ( $post_types as $post_type ) { |
| 482 | 591 | $chklist[] = $post_type; |
| 483 | 592 | } |
| @@ -483,45 +592,24 @@ | ||
| 483 | 592 | } |
| 484 | 593 | foreach ( $nplugins as $p_key ) { |
| 485 | 594 | if(strpos($p_key, 'jetpack/') !== false){ |
| 486 | 595 | foreach ( $jmodules as $p_key ) { |
| 487 | - if(in_array( $p_key, $selplugins )){ | |
| 488 | - $p_name = $this->pluginkey_to_name($p_key); | |
| 489 | - echo "<tr><td>$p_name</td>"; | |
| 490 | - foreach($chklist as $pgtype){ | |
| 491 | - $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true; | |
| 492 | - echo '<td class="altcheckbox">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>'; | |
| 493 | - } | |
| 494 | - echo "</tr>"; | |
| 495 | - } | |
| 596 | + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); | |
| 496 | 597 | } |
| 497 | 598 | } |
| 498 | 599 | else if(strpos($p_key, 'celtispack/') !== false){ |
| 499 | 600 | foreach ( $cmodules as $p_key ) { |
| 500 | - if(in_array( $p_key, $selplugins )){ | |
| 501 | - $p_name = $this->pluginkey_to_name($p_key); | |
| 502 | - echo "<tr><td>$p_name</td>"; | |
| 503 | - foreach($chklist as $pgtype){ | |
| 504 | - $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true; | |
| 505 | - echo '<td class="altcheckbox">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>'; | |
| 506 | - } | |
| 507 | - echo "</tr>"; | |
| 508 | - } | |
| 601 | + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); | |
| 509 | 602 | } |
| 510 | 603 | } |
| 511 | - else if(in_array( $p_key, $selplugins )) { | |
| 512 | - $p_name = $this->pluginkey_to_name($p_key); | |
| 513 | - echo "<tr><td>$p_name</td>"; | |
| 514 | - foreach($chklist as $pgtype){ | |
| 515 | - $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true; | |
| 516 | - echo '<td class="altcheckbox">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>'; | |
| 517 | - } | |
| 518 | - echo "</tr>"; | |
| 604 | + else { | |
| 605 | + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); | |
| 519 | 606 | } |
| 520 | 607 | } |
| 521 | 608 | ?> |
| 522 | 609 | </tbody> |
| 523 | 610 | </table> |
| 611 | + </div> | |
| 524 | 612 | <?php |
| 525 | 613 | } |
| 526 | 614 | |
| 527 | 615 | //Option Setting Form Display |
| @@ -533,30 +621,18 @@ | ||
| 533 | 621 | <ul> |
| 534 | 622 | <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li> |
| 535 | 623 | <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li> |
| 536 | 624 | </ul> |
| 537 | - <form method="post" > | |
| 625 | + <form method="post" autocomplete="off"> | |
| 538 | 626 | <?php wp_nonce_field( 'plugin_load_filter'); ?> |
| 539 | - <div id="plf-registration-tab" > | |
| 627 | + <div id="plf-registration-tab" style="display : none;"> | |
| 540 | 628 | <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?> |
| 541 | - <br /> | |
| 542 | - <p><?php _e('If you want to filter the loading of plugins, click select <span class="dashicons dashicons-admin-plugins"></span> mark of the filter type.', 'plf') ?></p> | |
| 543 | - <p><strong>[ Admin Filter ]</strong><br /> | |
| 544 | - <?php _e('Plugins to be used only in admin mode.', 'plf'); ?><br /> | |
| 545 | - </p> | |
| 546 | - <p><strong>[ Desktop/Mobile Filter ]</strong><br /> | |
| 547 | - <?php _e('Plugins to be used only in desktop/moble device. (wp_is_mobile function use)', 'plf'); ?><br /> | |
| 548 | - </p> | |
| 549 | - <p><strong>[ Page Filter ]</strong><br /> | |
| 550 | - <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br /> | |
| 551 | - <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?><br /> | |
| 552 | - </p> | |
| 553 | 629 | <p class="submit"> |
| 554 | 630 | <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" /> |
| 555 | 631 | <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry »', 'plf'); ?>" /> |
| 556 | 632 | </p> |
| 557 | 633 | </div> |
| 558 | - <div id="plf-activation-tab" > | |
| 634 | + <div id="plf-activation-tab" style="display : none;"> | |
| 559 | 635 | <?php |
| 560 | 636 | $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); |
| 561 | 637 | if(!empty($pgfilter)){ |
| 562 | 638 | $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter); |
| @@ -588,30 +664,108 @@ | ||
| 588 | 664 | * Meta box |
| 589 | 665 | * Individual of the plug-in filter meta box for Post/Page/CustomPost |
| 590 | 666 | **************************************************************************/ |
| 591 | 667 | function load_meta_boxes( $post_type, $post ) { |
| 592 | - if ( current_user_can('edit_plugins', $post->ID) ) { | |
| 593 | - add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' ); | |
| 668 | + if ( current_user_can('activate_plugins', $post->ID) ) { | |
| 669 | + add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' ); | |
| 594 | 670 | add_action( 'admin_head', array(&$this, 'plf_css' )); |
| 595 | 671 | add_action( 'admin_footer', array(&$this, 'plf_meta_script' )); |
| 596 | 672 | } |
| 597 | 673 | } |
| 598 | 674 | |
| 675 | + //Plugin pagefilter Selected Checkbox (plugin and modules list) | |
| 676 | + // $p_key | |
| 677 | + // $select_cvplugins : csv string : pagefilter selected plugins | |
| 678 | + // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins | |
| 679 | + function _pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ) { | |
| 680 | + | |
| 681 | + $html = ''; | |
| 682 | + $selplugins = array_map("trim", explode(',', $select_cvplugins)); | |
| 683 | + $device['desktop'] = $checked_arcvplugins['desktop']; | |
| 684 | + $device['mobile'] = $checked_arcvplugins['mobile']; | |
| 685 | + $devlist = array('desktop','mobile'); | |
| 686 | + if(in_array( $p_key, $selplugins )){ | |
| 687 | + $p_name = $this->pluginkey_to_name($p_key); | |
| 688 | + $html .= "<tr><td class='plugins-name'>$p_name</td>"; | |
| 689 | + foreach($devlist as $devtype){ | |
| 690 | + $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true; | |
| 691 | + $html .= "<td class='device-type $devtype'>" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>'; | |
| 692 | + } | |
| 693 | + $html .= "</tr>"; | |
| 694 | + } | |
| 695 | + return $html; | |
| 696 | + } | |
| 697 | + | |
| 698 | + //Plugin pagefilter Selected Checkbox (plugin and modules list) | |
| 699 | + // $plugins : array : all active plugins | |
| 700 | + // $select_cvplugins : csv string : pagefilter selected plugins | |
| 701 | + // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins | |
| 702 | + function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_arcvplugins ) { | |
| 703 | + | |
| 704 | + if(empty($select_cvplugins)) | |
| 705 | + return __('Page Filter is not registered', 'plf'); | |
| 706 | + | |
| 707 | + $html = '<table id="activation-table">'; | |
| 708 | + $html .= '<thead>'; | |
| 709 | + $html .= '<tr><th class="plugins-name">'. __('Plugins') . '</th>'; | |
| 710 | + $html .= '<th class="device-type"><span title="'. __('Desktop Device', 'plf'). '" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>'; | |
| 711 | + $html .= '<th class="device-type"><span title="'. __('Mobile Device', 'plf'). '" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>'; | |
| 712 | + $html .= '</tr>'; | |
| 713 | + $html .= '</thead>'; | |
| 714 | + $html .= '<tbody class="plugins-table-body meta-boxes-plugins-table">'; | |
| 715 | + $nplugins = $jmodules = $cmodules = array(); | |
| 716 | + foreach ( $plugins as $p_key => $p_data ) { | |
| 717 | + $p_name = $this->pluginkey_to_name($p_key); | |
| 718 | + if(empty($p_name)) | |
| 719 | + continue; | |
| 720 | + if(strpos($p_key, 'jetpack_module/') !== false) | |
| 721 | + $jmodules[] = $p_key; | |
| 722 | + else if(strpos($p_key, 'celtispack_module/') !== false) | |
| 723 | + $cmodules[] = $p_key; | |
| 724 | + else | |
| 725 | + $nplugins[] = $p_key; | |
| 726 | + } | |
| 727 | + | |
| 728 | + foreach ( $nplugins as $p_key ) { | |
| 729 | + if(strpos($p_key, 'jetpack/') !== false){ | |
| 730 | + foreach ( $jmodules as $p_key ) { | |
| 731 | + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); | |
| 732 | + } | |
| 733 | + } | |
| 734 | + else if(strpos($p_key, 'celtispack/') !== false){ | |
| 735 | + foreach ( $cmodules as $p_key ) { | |
| 736 | + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); | |
| 737 | + } | |
| 738 | + } | |
| 739 | + else { | |
| 740 | + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); | |
| 741 | + } | |
| 742 | + } | |
| 743 | + $html .= '</tbody>'; | |
| 744 | + $html .= '</table>'; | |
| 745 | + return $html; | |
| 746 | + } | |
| 747 | + | |
| 599 | 748 | function plf_meta_box( $post, $box ) { |
| 600 | 749 | if(is_object($post)){ |
| 601 | - $default = array( 'filter' => 'default', 'plugins' => ''); | |
| 602 | 750 | $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true ); |
| 751 | + //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile' | |
| 752 | + if(!empty($myfilter['plugins'])){ | |
| 753 | + $myfilter['desktop'] = $myfilter['plugins']; | |
| 754 | + $myfilter['mobile'] = $myfilter['plugins']; | |
| 755 | + unset($myfilter['plugins']); | |
| 756 | + } | |
| 757 | + $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => ''); | |
| 603 | 758 | $option = (!empty($myfilter))? $myfilter : $default; |
| 604 | 759 | $option = wp_parse_args( $option, $default); |
| 760 | + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); | |
| 605 | 761 | $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID ); |
| 606 | - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); | |
| 607 | 762 | ?> |
| 608 | 763 | <div id="plugin-filter-select"> |
| 609 | 764 | <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label> |
| 610 | 765 | <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Activate Plugins', 'plf'); ?></label> |
| 611 | - <br /> | |
| 612 | 766 | <div id="page-filter-stat"> |
| 613 | - <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); ?> | |
| 767 | + <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?> | |
| 614 | 768 | </div> |
| 615 | 769 | <?php echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. __('Save') .'</a></p>'; ?> |
| 616 | 770 | </div> |
| 617 | 771 | <?php |
| @@ -621,33 +775,40 @@ | ||
| 621 | 775 | //wp_ajax_plugin_load_filter called function |
| 622 | 776 | function plf_ajax_postidfilter() { |
| 623 | 777 | if ( isset($_POST['post_id']) ) { |
| 624 | 778 | $pid = (int) $_POST['post_id']; |
| 625 | - if ( !current_user_can( 'edit_plugins', $pid ) ) | |
| 779 | + if ( !current_user_can( 'activate_plugins', $pid ) ) | |
| 626 | 780 | wp_die( -1 ); |
| 627 | 781 | check_ajax_referer( "plugin_load_filter-$pid" ); |
| 628 | 782 | |
| 783 | + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); | |
| 629 | 784 | $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter']; |
| 630 | - $option["plugins"] = ''; | |
| 631 | - if('default' == $option["filter"]) | |
| 785 | + if('default' == $option["filter"]){ | |
| 632 | 786 | delete_post_meta( $pid, '_plugin_load_filter'); |
| 787 | + } | |
| 633 | 788 | else { |
| 634 | 789 | $plugins = array(); |
| 635 | - if( preg_match_all('/plf_option\[plugins\]\[(.+?)\]/u', $_POST['plugins'], $matches)){ | |
| 790 | + if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){ | |
| 636 | 791 | if(!empty($matches[1])){ |
| 637 | 792 | foreach ($matches[1] as $plugin){ |
| 638 | 793 | $plugins[] = $plugin; |
| 639 | 794 | } |
| 640 | - $option["plugins"] = implode(",", $plugins); | |
| 795 | + $option["desktop"] = implode(",", $plugins); | |
| 641 | 796 | } |
| 642 | 797 | } |
| 798 | + $plugins = array(); | |
| 799 | + if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $_POST['mobile'], $matches)){ | |
| 800 | + if(!empty($matches[1])){ | |
| 801 | + foreach ($matches[1] as $plugin){ | |
| 802 | + $plugins[] = $plugin; | |
| 803 | + } | |
| 804 | + $option["mobile"] = implode(",", $plugins); | |
| 805 | + } | |
| 806 | + } | |
| 643 | 807 | update_post_meta( $pid, '_plugin_load_filter', $option ); |
| 644 | 808 | } |
| 645 | - //transient cache clear | |
| 646 | - $this->plf_transient_clear(); | |
| 647 | 809 | |
| 648 | - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); | |
| 649 | - $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); | |
| 810 | + $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); | |
| 650 | 811 | wp_send_json_success($html); |
| 651 | 812 | } |
| 652 | 813 | wp_die( 0 ); |
| 653 | 814 | } |
| @@ -665,13 +826,8 @@ | ||
| 665 | 826 | <?php } |
| 666 | 827 | |
| 667 | 828 | function plf_meta_script() { ?> |
| 668 | 829 | <script type='text/javascript' > |
| 669 | - WPAddPagePluginLoadFilter = function(nonce){ | |
| 670 | - jQuery.ajax({ type: 'POST', url: ajaxurl, | |
| 671 | - data: {action: "plugin_load_filter", post_id : jQuery( '#post_ID' ).val(), _ajax_nonce: nonce, filter: jQuery("input[name='pagefilter']:checked").val(), plugins: jQuery('.plugins-list li input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), }, dataType: 'json', | |
| 672 | - success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); } | |
| 673 | - }); | |
| 674 | - return false; }; | |
| 830 | + WPAddPagePluginLoadFilter = function(nonce){ jQuery.ajax({ type: 'POST', url: ajaxurl, data: { action: "plugin_load_filter", post_id : jQuery( '#post_ID' ).val(), _ajax_nonce: nonce, filter: jQuery("input[name='pagefilter']:checked").val(), desktop: jQuery('.meta-boxes-plugins-table td.desktop input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), mobile: jQuery('.meta-boxes-plugins-table td.mobile input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),}, dataType: 'json', success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); }}); return false; }; | |
| 675 | 831 | </script> |
| 676 | 832 | <?php } |
| 677 | 833 | } |