Created
February 6, 2015 06:32
-
-
Save phpmaps/e4e986108bace1a24bfa to your computer and use it in GitHub Desktop.
list_terms_exclusions plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Pancake v. 1.1 | |
Plugin URI: http://phpmaps.github.io/me/ | |
Description: Hides wordpress categories that Johnny finds annoying when working in the admin! | |
Version: 1.1 rev 1 (Sea Gull) | |
Author: Doogs | |
Author URI: http://phpmaps.github.io/me/ | |
*/ | |
/* | |
Example CSV | |
1,Uncategorized | |
2,Blogroll | |
*/ | |
add_action( 'admin_init', 'isAdminInit' ); | |
define('PANCAKE_PLUGIN_DIR', plugin_dir_path(__FILE__)); | |
define('PLUGIN_URL', WP_PLUGIN_URL."/".dirname(plugin_basename(__FILE__))); | |
function readCsvToArray($fullpath) | |
{ | |
$file = fopen($fullpath, 'r'); | |
$records = array(); | |
while (($line = fgetcsv($file)) !== FALSE) { | |
$records[] = $line[0]; | |
} | |
fclose($file); | |
return $records; | |
} | |
function isAdminInit() | |
{ | |
add_filter( 'list_terms_exclusions', 'doCategoryExclusions', 10, 2 ); | |
} | |
function doCategoryExclusions($exclusions,$args) | |
{ | |
$where = array(); | |
$csv = PANCAKE_PLUGIN_DIR . "terms.csv"; | |
$terms = readCsvToArray($csv); | |
$exclusions = " AND ( t.term_id NOT IN (" . implode( ",", $terms ) . ") )"; | |
return $exclusions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment