Skip to content

Instantly share code, notes, and snippets.

@phpmaps
Created February 6, 2015 06:32
Show Gist options
  • Save phpmaps/e4e986108bace1a24bfa to your computer and use it in GitHub Desktop.
Save phpmaps/e4e986108bace1a24bfa to your computer and use it in GitHub Desktop.
list_terms_exclusions plugin
<?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