Custom Right Now Dashboard Widget

The first example replaces the widget contents with whatever you define.  You will need to define variables according to slug.

The second example simply adds all registered Custom Post Types, Tags, Taxonomies and Categories to the list in the WordPress dashboard widget, which can be too much for some larger sites.  Still, it may prove helpful in circumstances where site managers need quick and easy access to all content types.

Add to functions.php file or plugin.

function wp_dashboard_right_now_custom() {
	global $wp_registered_sidebars;

	$num_posts = wp_count_posts( 'post' );
	$num_slides = wp_count_posts( 'slide' );
	$num_events = wp_count_posts( 'tribe_events' );
	$num_sermons = wp_count_posts( 'sermons' );
	$num_pages = wp_count_posts( 'page' );

	echo "\n\t".'<div class="table table_content" style="width:45%; float:left; margin-bottom:25px;">';
	echo "\n\t".'<p class="sub" style="padding: 5px 0 5px 15px; color: #8F8F8F; font-size: 14px; border-bottom: #ECECEC 1px solid;">' . __('Content') . '</p>'."\n\t".'<table>';
	echo "\n\t".'<tr class="first">';

	// Pages
	$num = number_format_i18n( $num_pages->publish );
	$text = _n( 'Static Page', 'Static Pages', $num_pages->publish );
	if ( current_user_can( 'edit_pages' ) ) {
		$num = "<a href='edit.php?post_type=page'>$num</a>";
		$text = "<a href='edit.php?post_type=page'>$text</a>";
	}
	echo '<td class="first b b_pages" style="font-size:21px; text-align:right; padding:6px 4px; font-family: Georgia,Times New Roman,Bitstream Charter,Times,serif;">' . $num . '</td>';
	echo '<td class="t pages" style="padding-top:5px;">' . $text . '</td>';

	echo '</tr><tr>';

	// Home Slides
	$num = number_format_i18n( $num_slides->publish );
	$text = _n( 'Home Slide', 'Home Slides', intval($num_slides->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=slide'>$num</a>";
		$text = "<a href='edit.php?post_type=slide'>$text</a>";
	}
	echo '<td class="first b b-slide" style="font-size:21px; text-align:right; padding:6px 4px; font-family: Georgia,Times New Roman,Bitstream Charter,Times,serif;">' . $num . '</td>';
	echo '<td class="t slide" style="padding-top:5px;">' . $text . '</td>';

	echo '</tr><tr>';

	// Posts
	$num = number_format_i18n( $num_posts->publish );
	$text = _n( 'Featured Post', 'Featured Posts', intval($num_posts->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php'>$num</a>";
		$text = "<a href='edit.php'>$text</a>";
	}
	echo '<td class="first b b-posts" style="font-size:21px; text-align:right; padding:6px 4px; font-family: Georgia,Times New Roman,Bitstream Charter,Times,serif;">' . $num . '</td>';
	echo '<td class="t posts" style="padding-top:5px;">' . $text . '</td>';

	echo '</tr><tr>';

	// Sermons
	$num = number_format_i18n( $num_sermons->publish );
	$text = _n( 'Sermon', 'Sermons', intval($num_sermons->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=sermons'>$num</a>";
		$text = "<a href='edit.php?post_type=sermons'>$text</a>";
	}
	echo '<td class="first b b-slide" style="font-size:21px; text-align:right; padding:6px 4px; font-family: Georgia,Times New Roman,Bitstream Charter,Times,serif;">' . $num . '</td>';
	echo '<td class="t slide" style="padding-top:5px;">' . $text . '</td>';

	echo '</tr><tr>';

	// Events
	$num = number_format_i18n( $num_events->publish );
	$text = _n( 'Event', 'Events', intval($num_events->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php?post_type=tribe_events'>$num</a>";
		$text = "<a href='edit.php?post_type=tribe_events'>$text</a>";
	}
	echo '<td class="first b b-slide" style="font-size:21px; text-align:right; padding:6px 4px; font-family: Georgia,Times New Roman,Bitstream Charter,Times,serif;">' . $num . '</td>';
	echo '<td class="t slide" style="padding-top:5px;">' . $text . '</td>';

	echo '</tr><tr>';

	echo "</tr>";
	do_action('right_now_table_end');
	do_action('right_now_discussion_table_end');
	echo "\n\t</table>\n\t</div>";

	echo "\n\t".'<div class="table table_content" style="width:45%; float:right;">';
	echo "\n\t".'<p class="sub" style="padding: 5px 0 5px 15px; color: #8F8F8F; font-size: 14px; border-bottom: #ECECEC 1px solid;">' . __('Site Stats') . '</p>'."\n\t".'<table>';
	echo "\n\t".'<tr class="first">';

//
//
//

	echo "</tr>";
	do_action('right_now_table_end');
	do_action('right_now_discussion_table_end');
	echo "\n\t</table>\n\t</div>";

	echo "\n\t".'<div class="versions" style="clear:both;">';
	$ct = current_theme_info();

	echo "\n\t<p>";

	// Check if search engines are blocked.
	if ( !is_network_admin() && !is_user_admin() && current_user_can('manage_options') && '1' != get_option('blog_public') ) {
		$title = apply_filters('privacy_on_link_title', __('Your site is asking search engines not to index its content') );
		$content = apply_filters('privacy_on_link_text', __('Search Engines Blocked. Only admin can change this setting.') );

		echo "<p><a href='options-privacy.php' title='$title'>$content</a></p>";
	}

	echo "\n\t".'<br class="clear" /></div>';
	do_action( 'rightnow_end' );
	do_action( 'activity_box_end' );
}

// Create the function use in the action hook

function example_add_dashboard_widgets() {
	wp_add_dashboard_widget('right_now', 'Your Content Dashboard at a Glance', 'wp_dashboard_right_now_custom');

} 

// Hook into the 'wp_dashboard_setup' action to register our other functions

add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );

– or –

function wph_right_now_content_table_end() {
    $args = array(
        'public' => true ,
        '_builtin' => false
    );

    $output = 'object';
    $operator = 'and';
    $post_types = get_post_types( $args , $output , $operator );
    foreach( $post_types as $post_type ) {
        $num_posts = wp_count_posts( $post_type->name );
        $num = number_format_i18n( $num_posts->publish );
        $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
        if ( current_user_can( 'edit_posts' ) ) {
            $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
            $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
        }
    echo '<tr><td class="first num b b-' . $post_type->name . '">' . $num . '</td>';
    echo '<td class="text t ' . $post_type->name . '">' . $text . '</td></tr>';
    }

    $taxonomies = get_taxonomies( $args , $output , $operator ); 
    foreach( $taxonomies as $taxonomy ) {
        $num_terms  = wp_count_terms( $taxonomy->name );
        $num = number_format_i18n( $num_terms );
        $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ));
        if ( current_user_can( 'manage_categories' ) ) {
            $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
            $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
        }
        echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
        echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
    }
}

add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );

 

Dave Winter focuses in WordPress UI Design and WordPress Plugin Development (some have labelled him a fanatic) but has hands in many other projects, including photography and music. He's never far from a computer... or an iPad (for testing purposes, of course). If you've been to a WordCamp in Southern California, he probably already knows who you are (or maybe not - he's terrible with names). Dave currently teaches courses at California State University, Long Beach alongside his small business at dauid.us (and his students think he's pretty boss).
© 2008-2020, dauid.us