get_col( "SELECT blog_id FROM $wpdb->blogs" ); foreach ( $blog_ids as $blog_id ) { if($blog_id == $current_blog_id){ //current site } else { //other site active check switch_to_blog( $blog_id ); if ( is_plugin_active( plugin_basename( __FILE__ ))) $act = true; } } switch_to_blog( $current_blog_id ); } } if($act === false){ if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); } } } register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' ); //uninstall function plugin_load_filter_uninstall() { if ( !is_multisite()) { delete_option('plf_queryvars'); delete_option('plf_option' ); } else { global $wpdb; $current_blog_id = get_current_blog_id(); $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); delete_option('plf_queryvars'); delete_option('plf_option' ); } switch_to_blog( $current_blog_id ); } if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) { @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' ); } } register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall'); } $Plf_setting = new Plf_setting(); class Plf_setting { private $plugins_inf = ''; //active plugin/module infomation private $filter = array(); //filter option data private $tab_num = 0; /*************************************************************************** * Style Sheet **************************************************************************/ function plf_css() { ?> filter = get_option('plf_option'); //v2.3.0 option change if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){ $this->filter['optver'] = '2'; if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){ //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile' if(!empty($this->filter['_pagefilter'])){ $this->filter['group']['desktop'] = $this->filter['_pagefilter']; $this->filter['group']['mobile'] = $this->filter['_pagefilter']; } if(!empty($this->filter['_desktop'])){ $this->filter['_desktop'] = null; } if(!empty($this->filter['_mobile'])){ $this->filter['_mobile'] = null; } } } if(is_admin()) { add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 ); add_action( 'admin_init', array(&$this, 'action_posts')); add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 ); } add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter')); } //Plugin Load Filter admin setting start public function plf_admin_start() { require_once(ABSPATH . 'wp-admin/includes/plugin.php'); $this->plugins_inf = get_plugins(); $packplug = array(); foreach ( $this->plugins_inf as $plugin_key => $a_plugin ) { if(is_plugin_inactive( $plugin_key )){ unset($this->plugins_inf[$plugin_key]); } } //jetpack active module if(method_exists('Jetpack', 'get_module')){ $modules = Jetpack::get_active_modules(); $modules = array_diff( $modules, array( 'vaultpress' ) ); foreach ( $modules as $key => $module_name ) { if(!empty($module_name)){ $module = Jetpack::get_module( $module_name ); if(!empty($module)) $this->plugins_inf['jetpack_module/' . $module_name] = $module; } } } //celtispack active module if(method_exists('Celtispack', 'get_module')){ $modules = Celtispack::get_active_modules(); foreach ( $modules as $key => $module_name ) { if(!empty($module_name)){ $this->plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name ); } } } if ( empty( $this->plugins_inf ) ) return; add_action('admin_menu', array(&$this, 'plf_option_menu')); } //Plugins sub menu add public function plf_option_menu() { $page = add_plugins_page( 'Plugin Load Filter', __('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this,'plf_option_page')); add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts')); } //Plugin Load Filter setting page script function plf_scripts() { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-widget' ); wp_enqueue_script( 'jquery-ui-tabs' ); add_action( 'admin_head', array(&$this, 'plf_css' )); add_action( 'admin_head', array(&$this, 'jquery_tab_css' )); add_action( 'admin_footer', array(&$this, 'activetab_script' )); } //plugin filter option action request (add, update, delete) function action_posts() { if (current_user_can( 'activate_plugins' )) { if( isset($_POST['edit_regist_filter']) ) { if(isset($_POST['plfregist'])){ check_admin_referer('plugin_load_filter'); foreach( array('_admin', '_pagefilter') as $item){ $plugins = array(); foreach ( $_POST['plfregist'] as $p_key => $val ) { if($val == $item) $plugins[$p_key] = $val; } if($item == '_pagefilter'){ //If all modules is specified filter, in some cases you want to deactivate plugin itself. $jbase = $cbase = ''; $jall = $call = true; foreach ( $_POST['plfregist'] as $p_key => $val ) { if(strpos($p_key, 'jetpack/') !== false) $jbase = $p_key; else if(strpos($p_key, 'celtispack/') !== false) $cbase = $p_key; else if(strpos($p_key, 'jetpack_module/') !== false){ if($val != '_pagefilter' && $val != '_admin'){ $jall = false; } } else if(strpos($p_key, 'celtispack_module/') !== false){ if($val != '_pagefilter' && $val != '_admin') $call = false; } } if(!empty($jbase) && $jall === false) unset($plugins[$jbase]); if(!empty($cbase) && $call === false) unset($plugins[$cbase]); } $option["plugins"] = implode(",", array_keys($plugins)); $this->filter[$item] = $option; } if(isset($_POST['plf_option']['exclude'])){ $exclude = array(); foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) { if(!empty($v)) $exclude[$ft] = true; } $this->filter['exclude'] = $exclude; } else { $this->filter['exclude'] = ''; } update_option('plf_option', $this->filter ); } header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); exit; } elseif( isset($_POST['clear_regist_filter']) ) { check_admin_referer('plugin_load_filter'); foreach( array('_admin', '_pagefilter') as $item){ $this->filter[$item] = ''; } $this->filter['exclude'] = ''; update_option('plf_option', $this->filter ); header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page')); exit; } else if(isset($_POST['edit_activate_page_filter']) ) { if(isset($_POST['plfactive'])){ check_admin_referer('plugin_load_filter'); $group = array_keys($_POST['plfactive']); foreach( $group as $item){ $plugins = array(); foreach ( $_POST['plfactive'][$item] as $p_key => $val ) { if($val == '1') $plugins[] = $p_key; } $option["plugins"] = implode(",", $plugins); $this->filter['group'][$item] = $option; } update_option('plf_option', $this->filter ); } header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1')); exit; } elseif( isset($_POST['clear_activate_page_filter']) ) { check_admin_referer('plugin_load_filter'); $group = array_keys($_POST['plfactive']); foreach( $group as $item){ $this->filter['group'][$item] = ''; } update_option('plf_option', $this->filter ); header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1')); exit; } if(!empty($_GET['action']) && $_GET['action']=='tab_1') { $this->tab_num = 1; } } } //Plugin or Module key to name // $type : list/smart/tree public function pluginkey_to_name( $infkey, $type='list') { $name = ''; if(strpos($infkey, 'jetpack_module/') !== false){ if(!empty($this->plugins_inf[$infkey]['name'])){ $m_mark = ($type !== 'list')? '-' : 'Jetpack-'; if($type === 'smart') { if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'jetpack/') === false) $name = $m_mark . $this->plugins_inf[$infkey]['name']; } else $name = $m_mark . $this->plugins_inf[$infkey]['name']; } } elseif(strpos($infkey, 'celtispack_module/') !== false){ if(!empty($this->plugins_inf[$infkey]['Name'])){ $m_mark = ($type !== 'list')? '-' : 'Celtispack-'; if($type === 'smart') { if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'celtispack/') === false) $name = $m_mark . $this->plugins_inf[$infkey]['Name']; } else $name = $m_mark . $this->plugins_inf[$infkey]['Name']; } } else { if(!empty($this->plugins_inf[$infkey]['Name'])) $name = $this->plugins_inf[$infkey]['Name']; } return($name); } //Checkbox static function checkbox($name, $value, $label = '') { return ""; } static function altcheckbox($name, $value, $label = '') { return ""; } public function plfregist_item($key, $val) { $p_name = $this->pluginkey_to_name($key); $opt_name = "plfregist[$key]"; ?> /> /> />
$val ) { $name = $this->pluginkey_to_name($p_key); if(!empty($name)) $plist[$p_key] = ''; } foreach( array('_admin', '_pagefilter') as $item){ $parr = (!empty($filter[$item]['plugins'])) ? array_map("trim", explode(',', $filter[$item]['plugins'])) : array(); foreach ( $plist as $p_key => $val ) { if(empty($val) && in_array($p_key, $parr)) $plist[$p_key] = $item; } } $jlist = $clist = array(); foreach ( $plist as $p_key => $val ) { if(strpos($p_key, 'jetpack_module/') !== false){ $jlist[$p_key] = $plist[$p_key]; unset($plist[$p_key]); } else if(strpos($p_key, 'celtispack_module/') !== false){ $clist[$p_key] = $plist[$p_key]; unset($plist[$p_key]); } } foreach ( $plist as $p_key => $val ) { $modules = array(); if(strpos($p_key, 'jetpack/') !== false) $modules = $jlist; else if(strpos($p_key, 'celtispack/') !== false) $modules = $clist; else $this->plfregist_item($p_key, $val); if(!empty($modules)){ echo ""; foreach ( $modules as $m_key => $val) { $this->plfregist_item($m_key, $val); } } } ?>

[ Admin Filter ]

[ Page Filter ]



'; $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' ); foreach ( $pformat as $type ) { $checked = (!empty($this->filter['exclude'][$type]))? $this->filter['exclude'][$type] : false; $label = "$type"; $html .= self::checkbox("plf_option[exclude][$type]", $checked, $label); } $html .= '
'; echo $html; ?>
pluginkey_to_name($p_key); echo "$p_name"; foreach($devlist as $devtype){ $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true; echo '' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '') . ''; } foreach($chklist as $pgtype){ $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true; echo '' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '') . ''; } echo ""; } } public function plfactive_table($plugins, $select_cvplugins, $filter) { if(empty($select_cvplugins)) return; ?>
$v) { if(!empty($v)){ $exclude[] = $type; } } } foreach ( $pformat as $type) { if(!in_array($type, $exclude)){ $title = __('Post : ', 'plf') . $type; $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type"; echo ''; } } if(function_exists('is_embed')){ $title = __('WordPress Embed Content Card (API)', 'plf'); echo ""; } $post_types = get_post_types( array('public' => true, '_builtin' => false) ); foreach ( $post_types as $post_type ) { if(!empty($post_type)){ $title = __('Custom Post : ', 'plf') . $post_type; echo ""; } } ?> $p_data ) { $p_name = $this->pluginkey_to_name($p_key); if(empty($p_name)) continue; if(strpos($p_key, 'jetpack_module/') !== false) $jmodules[] = $p_key; else if(strpos($p_key, 'celtispack_module/') !== false) $cmodules[] = $p_key; else $nplugins[] = $p_key; } $chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post'); foreach ( $pformat as $type) { if(!in_array($type, $exclude)){ $chklist[] = "post-$type"; } } if(function_exists('is_embed')){ $chklist[] = 'content-card'; } $post_types = get_post_types( array('public' => true, '_builtin' => false) ); foreach ( $post_types as $post_type ) { $chklist[] = $post_type; } foreach ( $nplugins as $p_key ) { if(strpos($p_key, 'jetpack/') !== false){ foreach ( $jmodules as $p_key ) { $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); } } else if(strpos($p_key, 'celtispack/') !== false){ foreach ( $cmodules as $p_key ) { $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); } } else { $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter); } } ?>

Desktop

Mobile

Home

Archive

Search

Attach

Page

Post

' . $type .'
Embed Content$post_type

ID) ) { add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' ); add_action( 'admin_head', array(&$this, 'plf_css' )); add_action( 'admin_footer', array(&$this, 'plf_meta_script' )); } } //Plugin pagefilter Selected Checkbox (plugin and modules list) // $p_key // $select_cvplugins : csv string : pagefilter selected plugins // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins function _pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ) { $html = ''; $selplugins = array_map("trim", explode(',', $select_cvplugins)); $device['desktop'] = $checked_arcvplugins['desktop']; $device['mobile'] = $checked_arcvplugins['mobile']; $devlist = array('desktop','mobile'); if(in_array( $p_key, $selplugins )){ $p_name = $this->pluginkey_to_name($p_key); $html .= "$p_name"; foreach($devlist as $devtype){ $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true; $html .= "" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '') . ''; } $html .= ""; } return $html; } //Plugin pagefilter Selected Checkbox (plugin and modules list) // $plugins : array : all active plugins // $select_cvplugins : csv string : pagefilter selected plugins // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_arcvplugins ) { if(empty($select_cvplugins)) return __('Page Filter is not registered', 'plf'); $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $nplugins = $jmodules = $cmodules = array(); foreach ( $plugins as $p_key => $p_data ) { $p_name = $this->pluginkey_to_name($p_key); if(empty($p_name)) continue; if(strpos($p_key, 'jetpack_module/') !== false) $jmodules[] = $p_key; else if(strpos($p_key, 'celtispack_module/') !== false) $cmodules[] = $p_key; else $nplugins[] = $p_key; } foreach ( $nplugins as $p_key ) { if(strpos($p_key, 'jetpack/') !== false){ foreach ( $jmodules as $p_key ) { $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); } } else if(strpos($p_key, 'celtispack/') !== false){ foreach ( $cmodules as $p_key ) { $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); } } else { $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ); } } $html .= ''; $html .= '
'. __('Plugins') . '
Desktop

Mobile
'; return $html; } function plf_meta_box( $post, $box ) { if(is_object($post)){ $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true ); //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile' if(!empty($myfilter['plugins'])){ $myfilter['desktop'] = $myfilter['plugins']; $myfilter['mobile'] = $myfilter['plugins']; unset($myfilter['plugins']); } $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => ''); $option = (!empty($myfilter))? $myfilter : $default; $option = wp_parse_args( $option, $default); $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID ); ?>
pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?>
'. __('Save') .'

'; ?>
filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array(); $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter']; if('default' == $option["filter"]){ delete_post_meta( $pid, '_plugin_load_filter'); } else { $plugins = array(); if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){ if(!empty($matches[1])){ foreach ($matches[1] as $plugin){ $plugins[] = $plugin; } $option["desktop"] = implode(",", $plugins); } } $plugins = array(); if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $_POST['mobile'], $matches)){ if(!empty($matches[1])){ foreach ($matches[1] as $plugin){ $plugins[] = $plugin; } $option["mobile"] = implode(",", $plugins); } } update_post_meta( $pid, '_plugin_load_filter', $option ); } $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); wp_send_json_success($html); } wp_die( 0 ); } /*************************************************************************** * Javascript **************************************************************************/ function activetab_script() { ?>