Note: this plugin will not play nice with Keith McDuffee's category visibility plugin. Version: 0.1.6.5 Author: Ryan Poe Author URI: http://www.nmyworld.com/ */ if (!function_exists('ecg_is_applicable_page')) { function ecg_is_applicable_page() { foreach($_GET as $key => $val) { if($key == 'category_name' || $key == 'cat') return FALSE; /* We don't want categories filtered! */ if($key == 'name' || $key == 'p' || $key == 'pagename') return FALSE; /* Single pages. Kudos to najt (http://mahune.org/) */ if($key == 'monthnum' || $key == 'year') return TRUE; /* Month archives are filtered */ if($key == 'author_name') return TRUE; /* Author archives */ if($key == 'feed') return TRUE; /* Feeds */ if($key == 's') return TRUE; /* Searches */ } /* Show on all index.php pages that aren't above and all admin pages */ if (strpos($_SERVER['PHP_SELF'], 'index.php') !== FALSE) return TRUE; if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== FALSE) return TRUE; return FALSE; } } /* Only do anything if we're on the applicable pages */ if (ecg_is_applicable_page()) { /* Refreshes the list of categories if any changes are made to them */ if (!function_exists('ecg_refresh_categories')) { function ecg_refresh_categories() { global $wpdb, $__ecg_settings__, $table_prefix; $oldcats = $__ecg_settings__['cats']; $curcats = $wpdb->get_results('SELECT cat_ID, cat_name FROM ' . $table_prefix . 'categories'); $newcats = ''; if ($curcats) { foreach ($curcats as $cat) { if(!$__ecg_settings__['cats'][$cat->cat_ID]) { $newcats['cats'][$cat->cat_ID]['name'] = $cat->cat_name; $newcats['cats'][$cat->cat_ID]['home'] = TRUE; $newcats['cats'][$cat->cat_ID]['author'] = TRUE; $newcats['cats'][$cat->cat_ID]['search'] = TRUE; $newcats['cats'][$cat->cat_ID]['feed'] = TRUE; $newcats['cats'][$cat->cat_ID]['date'] = TRUE; } else { $newcats['cats'][$cat->cat_ID] = $__ecg_settings__['cats'][$cat->cat_ID]; } } /* If the new one's different, save it */ if ($newcats != $oldcats) { ecg_save_settings($newcats); } } else { $newcats['cats'] = ''; } } } /* Adds the AND's to the query's WHERE clause */ if (!function_exists('ecg_cat_where')) { function ecg_cat_where($query) { global $__ecg_settings__; if ($__ecg_settings__ !== FALSE) { $newquery = $query; foreach ($__ecg_settings__['cats'] as $cat_id => $cat_show_array) { if( !( ($cat_show_array['home'] && is_home()) || ($cat_show_array['author'] && is_author()) || ($cat_show_array['search'] && is_search()) || ($cat_show_array['feed'] && is_feed()) || ($cat_show_array['date'] && is_date()) )) { $newquery .= ' AND category_id <> ' . $cat_id . ' '; } } return $newquery; } return $query; } } /* Adds the JOIN clause to the query */ if (!function_exists('ecg_cat_join')) { function ecg_cat_join($query) { global $table_prefix; $newquery = $query . ' LEFT JOIN ' . $table_prefix . 'post2cat ON (' . $table_prefix . 'posts.ID = ' . $table_prefix . 'post2cat.post_id) '; return $newquery; } } /* Props to Brian "ColdForged" Dupuis */ if (!function_exists('ecg_get_settings')) { function ecg_get_settings() { $settings = get_settings('ecg_settings'); if ($settings === FALSE) ecg_refresh_categories(); $settings = get_settings('ecg_settings'); if (!is_array($settings)) { $settings = @ unserialize(stripslashes($settings)); } return $settings; } } /* Saves the settings array after serializing it */ if (!function_exists('ecg_save_settings')) { function ecg_save_settings($settings_array) { if(is_array($settings_array)) { $settings = @ serialize($settings_array); } update_option('ecg_settings', $settings); } } $__ecg_settings__ = ecg_get_settings(); /* Do stuff (we don't want these filters on any admin page but its own */ if (function_exists('add_filter') && strpos($_SERVER['PHP_SELF'], 'wp-admin') === FALSE) { add_filter('posts_join', 'ecg_cat_join'); add_filter('posts_where', 'ecg_cat_where'); } /* Add the menu item */ if (!function_exists('ecg_menus') && function_exists('add_action')) { function ecg_menus() { add_management_page('Category (in)Visibility', 'Category (in)Visibility', 9, basename(__FILE__), 'ecg_admin'); } add_action('admin_menu', 'ecg_menus'); } /* PLUGIN PAGE OUTPUT --------------------------------------------------------------*/ if ($_GET['page'] == basename(__FILE__)) { /* Displays the page */ if (!function_exists('ecg_render_page')) { function ecg_render_page() { global $__ecg_settings__; ?>
This list is an explanation of the above headings.
Now that you have your categories hidden from the pages you want, how do you display them? There are several different approaches to this (listed below):