Skip to content

Instantly share code, notes, and snippets.

@phpmaps
Created February 6, 2015 06:32

Revisions

  1. Doug Carroll created this gist Feb 6, 2015.
    57 changes: 57 additions & 0 deletions list_terms_exclusions
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    <?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;
    }