cleverness
2/14/2016 - 8:54 PM

Add category to dashboard widget

Add category to dashboard widget

<?php
/*
Plugin Name: Post Planner Mods
Version: 1.0
Description: Post Planner Plugin Modifications
Author: C.M. Kendrick
Author URI: http://seaserpentstudio.com
Plugin URI: http://seaserpentstudio.com/post-planner
*/

add_action( 'post_planner_dashboard_heading', 'post_planner_dashboard_headings' );
function post_planner_dashboard_headings() {
	echo '<th>' . esc_html__( 'Category', 'post-planner' ) . '</th>';
}

add_action( 'post_planner_dashboard_data', 'post_planner_dashboard', 10, 1 );
function post_planner_dashboard( $id ) {

	$terms = get_the_terms( $id, 'plannercategories' );

	if ( $terms && ! is_wp_error( $terms ) ) {

		$categories = array();

		foreach ( $terms as $term ) {
			$categories[] = $term->name;
		}

		$cats = implode( ', ', $categories );

	} else {
		$cats = '';
	}
	echo '<td>' . esc_html( $cats ) . '</td>';
}