From e6d12c8904598433fead4a866f196633a2750c12 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Mar 2018 19:52:46 -0800 Subject: [PATCH] Add AMP Validation Errors to the Dashboard At a Glance widget --- includes/utils/class-amp-validation-utils.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/includes/utils/class-amp-validation-utils.php b/includes/utils/class-amp-validation-utils.php index e4809d9f623..1e80144a452 100644 --- a/includes/utils/class-amp-validation-utils.php +++ b/includes/utils/class-amp-validation-utils.php @@ -185,6 +185,8 @@ class AMP_Validation_Utils { public static function init() { if ( current_theme_supports( 'amp' ) ) { add_action( 'init', array( __CLASS__, 'register_post_type' ) ); + add_filter( 'dashboard_glance_items', array( __CLASS__, 'filter_dashboard_glance_items' ) ); + add_action( 'rightnow_end', array( __CLASS__, 'print_dashboard_glance_styles' ) ); } add_action( 'rest_api_init', array( __CLASS__, 'amp_rest_validation' ) ); @@ -232,6 +234,48 @@ public static function add_admin_menu_validation_status_count() { } } + /** + * Filter At a Glance items add AMP Validation Errors. + * + * @param array $items At a glance items. + * @return array Items. + */ + public static function filter_dashboard_glance_items( $items ) { + $counts = wp_count_posts( self::POST_TYPE_SLUG ); + if ( ! empty( $counts->publish ) ) { + $items[] = sprintf( + '%s', + admin_url( 'edit.php?post_type=' . self::POST_TYPE_SLUG ), + sprintf( + /* translators: %s is the validation error count */ + _n( '%s AMP Validation Error', '%s AMP Validation Errors', $counts->publish, 'amp' ), + $counts->publish + ) + ); + } + return $items; + } + + /** + * Print styles for the At a Glance widget. + */ + public static function print_dashboard_glance_styles() { + ?> + +