Created
August 30, 2017 10:58
-
-
Save Qubical/6f841ef9b70161206a04f513c54604f2 to your computer and use it in GitHub Desktop.
Wordpress: Dashboard 'At a glance' Custom Post Types & Associated Dashicons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* At a glance for custom post types | |
* @return [type] [description] | |
*/ | |
function qubical_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' ) ) { | |
$cpt_name = $post_type->name; | |
} | |
echo '<li class="'.$cpt_name.'-count"><tr><a href="edit.php?post_type='.$cpt_name.'"><td class="first b b-' . $post_type->name . '"></td>' . $num . ' <td class="t ' . $post_type->name . '">' . $text . '</td></a></tr></li>'; | |
} | |
$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->name, $taxonomy->labels->name , intval( $num_terms )); | |
if ( current_user_can( 'manage_categories' ) ) { | |
$cpt_tax = $taxonomy->name; | |
} | |
echo '<li class="post-count"><tr><a href="edit-tags.php?taxonomy='.$cpt_tax.'"><td class="first b b-' . $taxonomy->name . '"></td>' . $num . ' <td class="t ' . $taxonomy->name . '">' . $text . '</td></a></tr></li>'; | |
} | |
} | |
add_action( 'dashboard_glance_items' , 'qubical_right_now_content_table_end' ); | |
/** | |
* Add custom post types to the dashboard 'At a glance' | |
* @return string Custom style information for the admin head | |
*/ | |
function qubical_fix_glance_icon() { | |
$dashicons = array( | |
'dashicons-menu' => 'f333', | |
'dashicons-admin-site' => 'f319', | |
'dashicons-dashboard' => 'f226', | |
'dashicons-admin-post' => 'f109', | |
'dashicons-admin-media' => 'f104', | |
'dashicons-admin-links' => 'f103', | |
'dashicons-admin-page' => 'f105', | |
'dashicons-admin-comments' => 'f101', | |
'dashicons-admin-appearance' => 'f100', | |
'dashicons-admin-plugins' => 'f106', | |
'dashicons-admin-users' => 'f110', | |
'dashicons-admin-tools' => 'f107', | |
'dashicons-admin-settings' => 'f108', | |
'dashicons-admin-network' => 'f112', | |
'dashicons-admin-home' => 'f102', | |
'dashicons-admin-generic' => 'f111', | |
'dashicons-admin-collapse' => 'f148', | |
'dashicons-filter' => 'f536', | |
'dashicons-admin-customizer' => 'f540', | |
'dashicons-admin-multisite' => 'f541', | |
'dashicons-welcome-write-blog' => 'f119', | |
'dashicons-welcome-add-page' => 'f133', | |
'dashicons-welcome-view-site' => 'f115', | |
'dashicons-welcome-widgets-menus' => 'f116', | |
'dashicons-welcome-comments' => 'f117', | |
'dashicons-welcome-learn-more' => 'f118', | |
'dashicons-format-aside' => 'f123', | |
'dashicons-format-image' => 'f128', | |
'dashicons-format-gallery' => 'f161', | |
'dashicons-format-video' => 'f126', | |
'dashicons-format-status' => 'f130', | |
'dashicons-format-quote' => 'f122', | |
'dashicons-format-chat' => 'f125', | |
'dashicons-format-audio' => 'f127', | |
'dashicons-camera' => 'f306', | |
'dashicons-images-alt' => 'f232', | |
'dashicons-images-alt2' => 'f233', | |
'dashicons-video-alt' => 'f234', | |
'dashicons-video-alt2' => 'f235', | |
'dashicons-video-alt3' => 'f236', | |
'dashicons-media-archive' => 'f501', | |
'dashicons-media-audio' => 'f500', | |
'dashicons-media-code' => 'f499', | |
'dashicons-media-default' => 'f498', | |
'dashicons-media-document' => 'f497', | |
'dashicons-media-interactive' => 'f496', | |
'dashicons-media-spreadsheet' => 'f495', | |
'dashicons-media-text' => 'f491', | |
'dashicons-media-video' => 'f490', | |
'dashicons-playlist-audio' => 'f492', | |
'dashicons-playlist-video' => 'f493', | |
'dashicons-controls-play' => 'f522', | |
'dashicons-controls-pause' => 'f523', | |
'dashicons-controls-forward' => 'f519', | |
'dashicons-controls-skipforward' => 'f517', | |
'dashicons-controls-back' => 'f518', | |
'dashicons-controls-skipback' => 'f516', | |
'dashicons-controls-repeat' => 'f515', | |
'dashicons-controls-volumeon' => 'f521', | |
'dashicons-controls-volumeoff' => 'f520', | |
'dashicons-image-crop' => 'f165', | |
'dashicons-image-rotate' => 'f531', | |
'dashicons-image-rotate-left' => 'f166', | |
'dashicons-image-rotate-right' => 'f167', | |
'dashicons-image-flip-vertical' => 'f168', | |
'dashicons-image-flip-horizontal' => 'f169', | |
'dashicons-image-filter' => 'f533', | |
'dashicons-undo' => 'f171', | |
'dashicons-redo' => 'f172', | |
'dashicons-editor-bold' => 'f200', | |
'dashicons-editor-italic' => 'f201', | |
'dashicons-editor-ul' => 'f203', | |
'dashicons-editor-ol' => 'f204', | |
'dashicons-editor-quote' => 'f205', | |
'dashicons-editor-alignleft' => 'f206', | |
'dashicons-editor-aligncenter' => 'f207', | |
'dashicons-editor-alignright' => 'f208', | |
'dashicons-editor-insertmore' => 'f209', | |
'dashicons-editor-spellcheck' => 'f210', | |
'dashicons-editor-expand' => 'f211', | |
'dashicons-editor-contract' => 'f506', | |
'dashicons-editor-kitchensink' => 'f212', | |
'dashicons-editor-underline' => 'f213', | |
'dashicons-editor-justify' => 'f214', | |
'dashicons-editor-textcolor' => 'f215', | |
'dashicons-editor-paste-word' => 'f216', | |
'dashicons-editor-paste-text' => 'f217', | |
'dashicons-editor-removeformatting' => 'f218', | |
'dashicons-editor-video' => 'f219', | |
'dashicons-editor-customchar' => 'f220', | |
'dashicons-editor-outdent' => 'f221', | |
'dashicons-editor-indent' => 'f222', | |
'dashicons-editor-help' => 'f223', | |
'dashicons-editor-strikethrough' => 'f224', | |
'dashicons-editor-unlink' => 'f225', | |
'dashicons-editor-rtl' => 'f320', | |
'dashicons-editor-break' => 'f474', | |
'dashicons-editor-code' => 'f475', | |
'dashicons-editor-paragraph' => 'f476', | |
'dashicons-editor-table' => 'f535', | |
'dashicons-align-left' => 'f135', | |
'dashicons-align-right' => 'f136', | |
'dashicons-align-center' => 'f134', | |
'dashicons-align-none' => 'f138', | |
'dashicons-lock' => 'f160', | |
'dashicons-unlock' => 'f528', | |
'dashicons-calendar' => 'f145', | |
'dashicons-calendar-alt' => 'f508', | |
'dashicons-visibility' => 'f177', | |
'dashicons-hidden' => 'f530', | |
'dashicons-post-status' => 'f173', | |
'dashicons-edit' => 'f464', | |
'dashicons-trash' => 'f182', | |
'dashicons-sticky' => 'f537', | |
'dashicons-external' => 'f504', | |
'dashicons-arrow-up' => 'f142', | |
'dashicons-arrow-down' => 'f140', | |
'dashicons-arrow-right' => 'f139', | |
'dashicons-arrow-left' => 'f141', | |
'dashicons-arrow-up-alt' => 'f342', | |
'dashicons-arrow-down-alt' => 'f346', | |
'dashicons-arrow-right-alt' => 'f344', | |
'dashicons-arrow-left-alt' => 'f340', | |
'dashicons-arrow-up-alt2' => 'f343', | |
'dashicons-arrow-down-alt2' => 'f347', | |
'dashicons-arrow-right-alt2' => 'f345', | |
'dashicons-arrow-left-alt2' => 'f341', | |
'dashicons-sort' => 'f156', | |
'dashicons-leftright' => 'f229', | |
'dashicons-randomize' => 'f503', | |
'dashicons-list-view' => 'f163', | |
'dashicons-exerpt-view' => 'f164', | |
'dashicons-grid-view' => 'f509', | |
'dashicons-move' => 'f545', | |
'dashicons-share' => 'f237', | |
'dashicons-share-alt' => 'f240', | |
'dashicons-share-alt2' => 'f242', | |
'dashicons-twitter' => 'f301', | |
'dashicons-rss' => 'f303', | |
'dashicons-email' => 'f465', | |
'dashicons-email-alt' => 'f466', | |
'dashicons-facebook' => 'f304', | |
'dashicons-facebook-alt' => 'f305', | |
'dashicons-googleplus' => 'f462', | |
'dashicons-networking' => 'f325', | |
'dashicons-hammer' => 'f308', | |
'dashicons-art' => 'f309', | |
'dashicons-migrate' => 'f310', | |
'dashicons-performance' => 'f311', | |
'dashicons-universal-access' => 'f483', | |
'dashicons-universal-access-alt' => 'f507', | |
'dashicons-tickets' => 'f486', | |
'dashicons-nametag' => 'f484', | |
'dashicons-clipboard' => 'f481', | |
'dashicons-heart' => 'f487', | |
'dashicons-megaphone' => 'f488', | |
'dashicons-schedule' => 'f489', | |
'dashicons-wordpress' => 'f120', | |
'dashicons-wordpress-alt' => 'f324', | |
'dashicons-pressthis' => 'f157', | |
'dashicons-update' => 'f463', | |
'dashicons-screenoptions' => 'f180', | |
'dashicons-info' => 'f348', | |
'dashicons-cart' => 'f174', | |
'dashicons-feedback' => 'f175', | |
'dashicons-cloud' => 'f176', | |
'dashicons-translation' => 'f326', | |
'dashicons-tag' => 'f323', | |
'dashicons-category' => 'f318', | |
'dashicons-archive' => 'f480', | |
'dashicons-tagcloud' => 'f479', | |
'dashicons-text' => 'f478', | |
'dashicons-yes' => 'f147', | |
'dashicons-no' => 'f158', | |
'dashicons-no-alt' => 'f335', | |
'dashicons-plus' => 'f132', | |
'dashicons-plus-alt' => 'f502', | |
'dashicons-minus' => 'f460', | |
'dashicons-dismiss' => 'f153', | |
'dashicons-marker' => 'f159', | |
'dashicons-star-filled' => 'f155', | |
'dashicons-star-half' => 'f459', | |
'dashicons-star-empty' => 'f154', | |
'dashicons-flag' => 'f227', | |
'dashicons-warning' => 'f534', | |
'dashicons-location' => 'f230', | |
'dashicons-location-alt' => 'f231', | |
'dashicons-vault' => 'f178', | |
'dashicons-shield' => 'f332', | |
'dashicons-shield-alt' => 'f334', | |
'dashicons-sos' => 'f468', | |
'dashicons-search' => 'f179', | |
'dashicons-slides' => 'f181', | |
'dashicons-analytics' => 'f183', | |
'dashicons-chart-pie' => 'f184', | |
'dashicons-chart-bar' => 'f185', | |
'dashicons-chart-line' => 'f238', | |
'dashicons-chart-area' => 'f239', | |
'dashicons-groups' => 'f307', | |
'dashicons-businessman' => 'f338', | |
'dashicons-id' => 'f336', | |
'dashicons-id-alt' => 'f337', | |
'dashicons-products' => 'f312', | |
'dashicons-awards' => 'f313', | |
'dashicons-forms' => 'f314', | |
'dashicons-testimonial' => 'f473', | |
'dashicons-portfolio' => 'f322', | |
'dashicons-book' => 'f330', | |
'dashicons-book-alt' => 'f331', | |
'dashicons-download' => 'f316', | |
'dashicons-upload' => 'f317', | |
'dashicons-backup' => 'f321', | |
'dashicons-clock' => 'f469', | |
'dashicons-lightbulb' => 'f339', | |
'dashicons-microphone' => 'f482', | |
'dashicons-desktop' => 'f472', | |
'dashicons-laptop' => 'f547', | |
'dashicons-tablet' => 'f471', | |
'dashicons-smartphone' => 'f470', | |
'dashicons-phone' => 'f525', | |
'dashicons-index-card' => 'f510', | |
'dashicons-carrot' => 'f511', | |
'dashicons-building' => 'f512', | |
'dashicons-store' => 'f513', | |
'dashicons-album' => 'f514', | |
'dashicons-palmtree' => 'f527', | |
'dashicons-tickets-alt' => 'f524', | |
'dashicons-money' => 'f526', | |
'dashicons-smiley' => 'f328', | |
'dashicons-thumbs-up' => 'f529', | |
'dashicons-thumbs-down' => 'f542', | |
'dashicons-layout' => 'f538', | |
'dashicons-paperclip' => 'f546' | |
); | |
$args = array( | |
'public' => true , | |
'_builtin' => false | |
); | |
$output = 'object'; | |
$operator = 'and'; | |
$post_types = get_post_types( $args , $output , $operator ); | |
$style = '<style type="text/css">'; | |
foreach( $post_types as $post_type ) { | |
$style .= '#dashboard_right_now li.' . $post_type->name . '-count a:before, #dashboard_right_now span.' . $post_type->name . '-count:before { content: "\\' . $dashicons[$post_type->menu_icon] . '"; }'; | |
} | |
$style .= '</style>'; | |
echo $style; | |
} | |
add_action( 'admin_head', 'qubical_fix_glance_icon' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment