| @@ -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.5.1 | |
| 5 | + Version: 2.3.1 | |
| 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,70 +9,9 @@ | ||
| 9 | 9 | License: GPLv2 |
| 10 | 10 | Text Domain: plf |
| 11 | 11 | Domain Path: /languages |
| 12 | 12 | */ |
| 13 | -defined( 'ABSPATH' ) || exit; | |
| 14 | 13 | |
| 15 | -/*************************************************************************** | |
| 16 | - * plugin activation / deactivation / uninstall | |
| 17 | - **************************************************************************/ | |
| 18 | -if(is_admin()){ | |
| 19 | - //deactivation | |
| 20 | - function plugin_load_filter_deactivation( $network_deactivating ) { | |
| 21 | - $act = false; | |
| 22 | - if (is_multisite()) { | |
| 23 | - if(! $network_deactivating){ | |
| 24 | - global $wpdb; | |
| 25 | - $current_blog_id = get_current_blog_id(); | |
| 26 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 27 | - foreach ( $blog_ids as $blog_id ) { | |
| 28 | - if($blog_id == $current_blog_id){ | |
| 29 | - //current site | |
| 30 | - } | |
| 31 | - else { | |
| 32 | - //other site active check | |
| 33 | - switch_to_blog( $blog_id ); | |
| 34 | - if ( is_plugin_active( plugin_basename( __FILE__ ))) | |
| 35 | - $act = true; | |
| 36 | - } | |
| 37 | - } | |
| 38 | - switch_to_blog( $current_blog_id ); | |
| 39 | - } | |
| 40 | - } | |
| 41 | - if($act === false){ | |
| 42 | - flush_rewrite_rules(); //options data 'rewrite_rules' clear for remake. | |
| 43 | - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 44 | - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); | |
| 45 | - } | |
| 46 | - } | |
| 47 | - } | |
| 48 | - register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' ); | |
| 49 | - | |
| 50 | - //uninstall | |
| 51 | - function plugin_load_filter_uninstall() { | |
| 52 | - | |
| 53 | - if ( !is_multisite()) { | |
| 54 | - delete_option('plf_queryvars'); | |
| 55 | - delete_option('plf_option' ); | |
| 56 | - } else { | |
| 57 | - global $wpdb; | |
| 58 | - $current_blog_id = get_current_blog_id(); | |
| 59 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
| 60 | - foreach ( $blog_ids as $blog_id ) { | |
| 61 | - switch_to_blog( $blog_id ); | |
| 62 | - delete_option('plf_queryvars'); | |
| 63 | - delete_option('plf_option' ); | |
| 64 | - } | |
| 65 | - switch_to_blog( $current_blog_id ); | |
| 66 | - } | |
| 67 | - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 68 | - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall'); | |
| 72 | - | |
| 73 | -} | |
| 74 | - | |
| 75 | 14 | $Plf_setting = new Plf_setting(); |
| 76 | 15 | |
| 77 | 16 | class Plf_setting { |
| 78 | 17 | |
| @@ -78,9 +17,9 @@ | ||
| 78 | 17 | |
| 79 | 18 | private $plugins_inf = ''; //active plugin/module infomation |
| 80 | 19 | private $filter = array(); //filter option data |
| 81 | 20 | private $tab_num = 0; |
| 82 | - | |
| 21 | + | |
| 83 | 22 | /*************************************************************************** |
| 84 | 23 | * Style Sheet |
| 85 | 24 | **************************************************************************/ |
| 86 | 25 | function plf_css() { ?> |
| @@ -127,9 +66,8 @@ | ||
| 127 | 66 | thead .device-type { background-color: oldlace;} |
| 128 | 67 | thead .tmpl-type { background-color: lavender;} |
| 129 | 68 | thead .pformat { background-color: honeydew;} |
| 130 | 69 | thead .tmpl-embed { background-color: lightyellow;} |
| 131 | - thead .tmpl-amp { background-color: #fff3b8;} | |
| 132 | 70 | thead .tmpl-custom { background-color: lavenderblush;} |
| 133 | 71 | thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px; max-width: 260px;} |
| 134 | 72 | thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;} |
| 135 | 73 | thead .filter-type, tbody .filter-type { min-width: 100px; max-width: 100px;} |
| @@ -155,9 +93,9 @@ | ||
| 155 | 93 | |
| 156 | 94 | public function __construct() { |
| 157 | 95 | |
| 158 | 96 | load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' ); |
| 159 | - | |
| 97 | + | |
| 160 | 98 | $this->filter = get_option('plf_option'); |
| 161 | 99 | //v2.3.0 option change |
| 162 | 100 | if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){ |
| 163 | 101 | $this->filter['optver'] = '2'; |
| @@ -178,14 +116,41 @@ | ||
| 178 | 116 | } |
| 179 | 117 | |
| 180 | 118 | if(is_admin()) { |
| 181 | 119 | add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 ); |
| 182 | - add_action( 'admin_init', array(&$this, 'action_posts')); | |
| 183 | 120 | add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 ); |
| 121 | + //plf-filter must-use plagin activete check | |
| 122 | + if(wp_mkdir_p( WPMU_PLUGIN_DIR )){ | |
| 123 | + if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 124 | + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); | |
| 125 | + } | |
| 126 | + else { | |
| 127 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); | |
| 128 | + $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false ); | |
| 129 | + $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false ); | |
| 130 | + if(version_compare( $dp['Version'], $sp['Version'], '!=')){ | |
| 131 | + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); | |
| 132 | + } | |
| 133 | + } | |
| 134 | + } | |
| 135 | + register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' ); | |
| 136 | + register_uninstall_hook(__FILE__, 'Plf_setting::uninstall'); | |
| 184 | 137 | } |
| 185 | 138 | add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter')); |
| 186 | 139 | } |
| 187 | 140 | |
| 141 | + //Plugin Deactivate | |
| 142 | + public static function deactivation() { | |
| 143 | + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 144 | + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); | |
| 145 | + } | |
| 146 | + } | |
| 147 | + //Plugin Uninstall | |
| 148 | + public static function uninstall() { | |
| 149 | + delete_option('plf_queryvars'); | |
| 150 | + delete_option('plf_option' ); | |
| 151 | + } | |
| 152 | + | |
| 188 | 153 | //Plugin Load Filter admin setting start |
| 189 | 154 | public function plf_admin_start() { |
| 190 | 155 | require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 191 | 156 | |
| @@ -219,8 +184,9 @@ | ||
| 219 | 184 | } |
| 220 | 185 | if ( empty( $this->plugins_inf ) ) |
| 221 | 186 | return; |
| 222 | 187 | |
| 188 | + $this->action_posts(); //POST, GET Request Action | |
| 223 | 189 | add_action('admin_menu', array(&$this, 'plf_option_menu')); |
| 224 | 190 | } |
| 225 | 191 | |
| 226 | 192 | //Plugins sub menu add |
| @@ -226,9 +192,8 @@ | ||
| 226 | 192 | //Plugins sub menu add |
| 227 | 193 | public function plf_option_menu() { |
| 228 | 194 | $page = add_plugins_page( 'Plugin Load Filter', __('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this,'plf_option_page')); |
| 229 | 195 | add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts')); |
| 230 | - add_action('admin_print_scripts-'.$page, array(&$this, 'deploy_mu_plugins')); | |
| 231 | 196 | } |
| 232 | 197 | |
| 233 | 198 | //Plugin Load Filter setting page script |
| 234 | 199 | function plf_scripts() { |
| @@ -238,40 +203,13 @@ | ||
| 238 | 203 | wp_enqueue_script( 'jquery-ui-tabs' ); |
| 239 | 204 | add_action( 'admin_head', array(&$this, 'plf_css' )); |
| 240 | 205 | add_action( 'admin_head', array(&$this, 'jquery_tab_css' )); |
| 241 | 206 | add_action( 'admin_footer', array(&$this, 'activetab_script' )); |
| 242 | - add_action( 'admin_notices', array(&$this, 'plf_notice')); | |
| 243 | 207 | } |
| 244 | - | |
| 245 | - //plf-filter.php mu-plugins module set | |
| 246 | - public function deploy_mu_plugins() { | |
| 247 | - if(wp_mkdir_p( WPMU_PLUGIN_DIR )){ | |
| 248 | - if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { | |
| 249 | - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); | |
| 250 | - } | |
| 251 | - else { | |
| 252 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); | |
| 253 | - $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false ); | |
| 254 | - $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false ); | |
| 255 | - if(version_compare( $dp['Version'], $sp['Version'], '!=')){ | |
| 256 | - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php'); | |
| 257 | - } | |
| 258 | - } | |
| 259 | - } | |
| 260 | - } | |
| 261 | - | |
| 262 | - //Notice Message display | |
| 263 | - public function plf_notice() { | |
| 264 | - $notice = get_transient('plf_notice'); | |
| 265 | - if(!empty($notice)){ | |
| 266 | - echo "<div class='message error'><p>Plugin Load Filter : $notice</p></div>"; | |
| 267 | - delete_transient('plf_notice'); | |
| 268 | - } | |
| 269 | - } | |
| 270 | 208 | |
| 271 | 209 | //plugin filter option action request (add, update, delete) |
| 272 | 210 | function action_posts() { |
| 273 | - if (current_user_can( 'activate_plugins' )) { | |
| 211 | + if (current_user_can( 'edit_plugins' )) { | |
| 274 | 212 | if( isset($_POST['edit_regist_filter']) ) { |
| 275 | 213 | if(isset($_POST['plfregist'])){ |
| 276 | 214 | check_admin_referer('plugin_load_filter'); |
| 277 | 215 | foreach( array('_admin', '_pagefilter') as $item){ |
| @@ -317,18 +255,8 @@ | ||
| 317 | 255 | } |
| 318 | 256 | else { |
| 319 | 257 | $this->filter['exclude'] = ''; |
| 320 | 258 | } |
| 321 | - $items = array( 'amp', 'url_1', 'url_2' ); | |
| 322 | - foreach ($items as $key) { | |
| 323 | - $url_key = (isset($_POST['plf_option'][$key]))? $_POST['plf_option'][$key] : ''; | |
| 324 | - if(empty($url_key) || preg_match('/\A([a-zA-Z0-9_\-]+)/u', $url_key)){ | |
| 325 | - $this->filter[$key] = $url_key; | |
| 326 | - } else { | |
| 327 | - $notice = __('There are invalid characters in AMP/URL Keyword. Use characters include Alphanumeric, Hyphens, Underscores.','plf'); | |
| 328 | - set_transient('plf_notice', $notice, 30); | |
| 329 | - } | |
| 330 | - } | |
| 331 | 259 | update_option('plf_option', $this->filter ); |
| 332 | 260 | } |
| 333 | 261 | header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); |
| 334 | 262 | exit; |
| @@ -338,11 +266,8 @@ | ||
| 338 | 266 | foreach( array('_admin', '_pagefilter') as $item){ |
| 339 | 267 | $this->filter[$item] = ''; |
| 340 | 268 | } |
| 341 | 269 | $this->filter['exclude'] = ''; |
| 342 | - $this->filter['amp'] = ''; | |
| 343 | - $this->filter['url_1'] = ''; | |
| 344 | - $this->filter['url_2'] = ''; | |
| 345 | 270 | update_option('plf_option', $this->filter ); |
| 346 | 271 | header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); |
| 347 | 272 | exit; |
| 348 | 273 | } |
| @@ -420,9 +345,9 @@ | ||
| 420 | 345 | } |
| 421 | 346 | static function altcheckbox($name, $value, $label = '') { |
| 422 | 347 | return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>"; |
| 423 | 348 | } |
| 424 | - | |
| 349 | + | |
| 425 | 350 | public function plfregist_item($key, $val) { |
| 426 | 351 | $p_name = $this->pluginkey_to_name($key); |
| 427 | 352 | $opt_name = "plfregist[$key]"; |
| 428 | 353 | ?> |
| @@ -514,29 +439,8 @@ | ||
| 514 | 439 | $html .= '</div>'; |
| 515 | 440 | echo $html; |
| 516 | 441 | ?> |
| 517 | 442 | </div> |
| 518 | - <div class="amp-url-pattern"> | |
| 519 | - <p><strong><?php _e( 'AMP / URL Page filter (Beta Test)', 'plf' ); ?></strong><br /> | |
| 520 | - <?php _e('Setting the keyword enables the filter. [Valid characters: alphanumeric characters, hyphens (-), underscores (_)]', 'plf'); ?><br /> | |
| 521 | - <?php _e('AMP / URL page judgment is done from REQUEST URI with regular expressions including setting keyword. <code>(/|&|\.|\?)keyword(/|&|=|\.|$)</code>', 'plf'); ?><br /> | |
| 522 | - <span style='background-color: #fbf7dc; padding: 2px;'> | |
| 523 | - <?php _e('*AMP page display requires AMP plugin or theme.', 'plf'); ?> | |
| 524 | - </span> | |
| 525 | - </p> | |
| 526 | - <?php | |
| 527 | - $items = array( 'amp' => __('AMP keyword (In many cases, it is identified with "amp")', 'plf'), 'url_1' => __('URL filter keyword-1', 'plf'), 'url_2' => __('URL filter keyword-2', 'plf') ); | |
| 528 | - $html = ""; | |
| 529 | - foreach ($items as $key => $label) { | |
| 530 | - $html .= "<div>"; | |
| 531 | - $val = (!empty($this->filter[$key]))? $this->filter[$key] : ''; | |
| 532 | - $html .= "<input id='plf_option[$key]' class='medium-text' type='text' name='plf_option[$key]' value='$val' />"; | |
| 533 | - $html .= "<label style='margin-left:10px;'>$label</label>"; | |
| 534 | - $html .= "</div>"; | |
| 535 | - } | |
| 536 | - echo $html; | |
| 537 | - ?> | |
| 538 | - </div> | |
| 539 | 443 | </div> |
| 540 | 444 | </div> |
| 541 | 445 | <?php |
| 542 | 446 | } |
| @@ -598,15 +502,8 @@ | ||
| 598 | 502 | if(function_exists('is_embed')){ |
| 599 | 503 | $title = __('WordPress Embed Content Card (API)', 'plf'); |
| 600 | 504 | echo "<th class='tmpl-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>"; |
| 601 | 505 | } |
| 602 | - $items = array( 'amp' => 'AMP filter', 'url_1' => 'URL filter1', 'url_2' => 'URL filter2' ); | |
| 603 | - foreach ($items as $key => $label) { | |
| 604 | - if(!empty($filter[$key])){ | |
| 605 | - $title = "$label Keyword : " . $filter[$key]; | |
| 606 | - echo "<th class='tmpl-type tmpl-amp'><span title='$title' style='font-size:xx-small'>{$filter[$key]}</span></th>"; | |
| 607 | - } | |
| 608 | - } | |
| 609 | 506 | $post_types = get_post_types( array('public' => true, '_builtin' => false) ); |
| 610 | 507 | foreach ( $post_types as $post_type ) { |
| 611 | 508 | if(!empty($post_type)){ |
| 612 | 509 | $title = __('Custom Post : ', 'plf') . $post_type; |
| @@ -638,13 +535,8 @@ | ||
| 638 | 535 | } |
| 639 | 536 | if(function_exists('is_embed')){ |
| 640 | 537 | $chklist[] = 'content-card'; |
| 641 | 538 | } |
| 642 | - foreach ($items as $key => $label) { | |
| 643 | - if(!empty($filter[$key])){ | |
| 644 | - $chklist[] = $key; | |
| 645 | - } | |
| 646 | - } | |
| 647 | 539 | $post_types = get_post_types( array('public' => true, '_builtin' => false) ); |
| 648 | 540 | foreach ( $post_types as $post_type ) { |
| 649 | 541 | $chklist[] = $post_type; |
| 650 | 542 | } |
| @@ -671,9 +563,8 @@ | ||
| 671 | 563 | } |
| 672 | 564 | |
| 673 | 565 | //Option Setting Form Display |
| 674 | 566 | public function plf_option_page() { |
| 675 | - $clear_dialog = __('Plugin Load Filter Settings\nClick OK to clear it.', 'plf'); | |
| 676 | 567 | ?> |
| 677 | 568 | <h2><?php _e('Plugin Load Filter Settings', 'plf'); ?></h2> |
| 678 | 569 | <p></p> |
| 679 | 570 | <div id="plf-setting-tabs"> |
| @@ -680,14 +571,14 @@ | ||
| 680 | 571 | <ul> |
| 681 | 572 | <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li> |
| 682 | 573 | <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li> |
| 683 | 574 | </ul> |
| 684 | - <form method="post" autocomplete="off"> | |
| 575 | + <form method="post" > | |
| 685 | 576 | <?php wp_nonce_field( 'plugin_load_filter'); ?> |
| 686 | 577 | <div id="plf-registration-tab" style="display : none;"> |
| 687 | 578 | <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?> |
| 688 | 579 | <p class="submit"> |
| 689 | - <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" /> | |
| 580 | + <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" /> | |
| 690 | 581 | <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry »', 'plf'); ?>" /> |
| 691 | 582 | </p> |
| 692 | 583 | </div> |
| 693 | 584 | <div id="plf-activation-tab" style="display : none;"> |
| @@ -700,9 +591,9 @@ | ||
| 700 | 591 | <p><?php _e('Select plugins to be activated for each page type by clicking on <span class="dashicons dashicons-admin-plugins"></span> mark from "page filter" registered plugins.', 'plf') ?><br /> |
| 701 | 592 | <?php _e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?> |
| 702 | 593 | </p> |
| 703 | 594 | <p class="submit"> |
| 704 | - <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php _e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" /> | |
| 595 | + <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php _e('Clear', 'plf'); ?>" /> | |
| 705 | 596 | <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php _e('Activate Plugin Entry »', 'plf'); ?>" /> |
| 706 | 597 | </p> |
| 707 | 598 | <?php |
| 708 | 599 | } |
| @@ -723,9 +614,9 @@ | ||
| 723 | 614 | * Meta box |
| 724 | 615 | * Individual of the plug-in filter meta box for Post/Page/CustomPost |
| 725 | 616 | **************************************************************************/ |
| 726 | 617 | function load_meta_boxes( $post_type, $post ) { |
| 727 | - if ( current_user_can('activate_plugins', $post->ID) ) { | |
| 618 | + if ( current_user_can('edit_plugins', $post->ID) ) { | |
| 728 | 619 | add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' ); |
| 729 | 620 | add_action( 'admin_head', array(&$this, 'plf_css' )); |
| 730 | 621 | add_action( 'admin_footer', array(&$this, 'plf_meta_script' )); |
| 731 | 622 | } |
| @@ -834,9 +725,9 @@ | ||
| 834 | 725 | //wp_ajax_plugin_load_filter called function |
| 835 | 726 | function plf_ajax_postidfilter() { |
| 836 | 727 | if ( isset($_POST['post_id']) ) { |
| 837 | 728 | $pid = (int) $_POST['post_id']; |
| 838 | - if ( !current_user_can( 'activate_plugins', $pid ) ) | |
| 729 | + if ( !current_user_can( 'edit_plugins', $pid ) ) | |
| 839 | 730 | wp_die( -1 ); |
| 840 | 731 | check_ajax_referer( "plugin_load_filter-$pid" ); |
| 841 | 732 | |
| 842 | 733 | $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); |