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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 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 –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 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' ); |