LearnDash: Ungraded Essays Dashboard Widget
Adds a dashboard widget that shows how many essay submissions are waiting to be graded, with a link straight to the list.
Opens WPIDE on
Code
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
return;
}
add_action( 'wp_dashboard_setup', function () {
if ( ! current_user_can( 'edit_others_posts' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_ld_essays', 'Essays to grade', function () {
$count = get_transient( 'wpide_ld_ungraded' );
if ( false === $count ) {
$query = new WP_Query( array(
'post_type' => 'sfwd-essays',
'post_status' => 'not_graded',
'posts_per_page' => 1,
'fields' => 'ids',
) );
$count = (int) $query->found_posts;
set_transient( 'wpide_ld_ungraded', $count, 15 * MINUTE_IN_SECONDS );
}
if ( ! $count ) {
echo '<p>All caught up: no essays are waiting.</p>';
return;
}
printf(
'<p style="font-size:1.4em;margin:0 0 .5em"><strong>%1$s</strong> waiting</p><p><a class="button" href="%2$s">Grade essays</a></p>',
esc_html( number_format_i18n( $count ) ),
esc_url( admin_url( 'edit.php?post_type=sfwd-essays&post_status=not_graded' ) )
);
} );
} );
add_action( 'save_post_sfwd-essays', function () {
delete_transient( 'wpide_ld_ungraded' );
} );
Notes
Visible to users who can edit others' posts. The count is cached for 15 minutes.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.