1

I want to display on the dashboard for some users role (Admin, editor and auther) . a box with 10 last draft page and 10 last edit page.

For the 10 last edited page I use the custom below :

add_action( 'wp_dashboard_setup', 'admin_dashboard_last_edits_register' );

function admin_dashboard_last_edits_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( 'Recently edited Pursuits pages', 'admin-dashboard-last-edits' ), 'admin_dashboard_last_edits_dashboard_widget');
}

function admin_dashboard_last_edits_dashboard_widget() { 
  $posts = get_posts(
  array (
    'numberposts' => 10, 
    'post_type' => array ( 'page' ), 
    'orderby' => 'modified')
    );

  if ( $posts ) {
    $date_format = get_option( 'date_format' );
    echo '<ul>';
    foreach ( $posts as $post ) {
      printf( __( '<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>', 'admin-dashboard-last-edits' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo '</ul>';
  }

  else {
    printf( __( 'No edits found. <a href="%1$s">Write a new post</a>.', 'admin-dashboard-last-edits' ), esc_url( admin_url( 'post-new.php' ) ) );
  }

}

I want also to add the time of modification on every box.

  • What is your question? – WebElaine Jun 23 '17 at 18:33
  • I'm lookind for the code to add for have a box on dashboard with 10 last draft and an other with 10 last pending review – sampaii Jun 23 '17 at 22:27
1
#dahsboard BOXES

#Last edited pages

add_action( 'wp_dashboard_setup', 'admin_dashboard_last_edits_register' );

function admin_dashboard_last_edits_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( 'Last published pages ', 'admin-dashboard-last-edits' ), 'admin_dashboard_last_edits_dashboard_widget');
}

function admin_dashboard_last_edits_dashboard_widget() { 
  $posts = get_posts(
  array (
    'numberposts' => 10, 
    'post_type' => array ( 'page' ), 
    'orderby' => 'modified')
    );

  if ( $posts ) {
    $date_format = get_option( 'date_format' );
    echo '<ul>';
    foreach ( $posts as $post ) {
      printf( __( '<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>', 'admin-dashboard-last-edits' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo '</ul>';
  }

  else {
    printf( __( 'No edits found. <a href="%1$s">Write a new post</a>.', 'admin-dashboard-last-edits' ), esc_url( admin_url( 'post-new.php' ) ) );
  }

}

#Last draft pages

add_action( 'wp_dashboard_setup', 'admin_dashboard_last_draft_register' );

function admin_dashboard_last_draft_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( 'Last Draft Pages', 'admin-dashboard-last-draft' ), 'admin_dashboard_last_draft_dashboard_widget');
}

function admin_dashboard_last_draft_dashboard_widget() { 
  $posts = get_posts(
  array (
    'numberposts' => 10, 
    'post_status' => array('draft'),
    'post_type' => array ( 'page' ), 
    'orderby' => 'modified')
    );

  if ( $posts ) {
    $date_format = get_option( 'date_format' );
    echo '<ul>';
    foreach ( $posts as $post ) {
      printf( __( '<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>', 'admin-dashboard-last-edits' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo '</ul>';
  }

  else {
    printf( __( 'No edits found. <a href="%1$s">Write a new post</a>.', 'admin-dashboard-draft-edits' ), esc_url( admin_url( 'post-new.php' ) ) );
  }

}

#Last pending review pages

add_action( 'wp_dashboard_setup', 'admin_dashboard_last_pending_register' );

function admin_dashboard_last_pending_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( 'Last pending Review Pages', 'admin-dashboard-last-pending' ), 'admin_dashboard_last_pending_dashboard_widget');
}

function admin_dashboard_last_pending_dashboard_widget() { 
  $posts = get_posts(
  array (
    'numberposts' => 10, 
    'post_status' => array('pending'),
    'post_type' => array ( 'page' ), 
    'orderby' => 'modified')
    );

  if ( $posts ) {
    $date_format = get_option( 'date_format' );
    echo '<ul>';
    foreach ( $posts as $post ) {
      printf( __( '<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>', 'admin-dashboard-last-edits' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo '</ul>';
  }

  else {
    printf( __( 'No edits found. <a href="%1$s">Write a new post</a>.', 'admin-dashboard-pending-edits' ), esc_url( admin_url( 'post-new.php' ) ) );
  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.