diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index f4c6b22..5f834d6 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -75,6 +75,7 @@ public function admin_menu() { add_menu_page( __( 'weDocs', 'wedocs' ), __( 'weDocs', 'wedocs' ), $capability, 'wedocs', [ $this, 'page_index' ], 'dashicons-media-document', $this->get_menu_position() ); add_submenu_page( 'wedocs', __( 'Docs', 'wedocs' ), __( 'Docs', 'wedocs' ), $capability, 'wedocs', [ $this, 'page_index' ] ); add_submenu_page( 'wedocs', __( 'Tags', 'wedocs' ), __( 'Tags', 'wedocs' ), 'manage_categories', 'edit-tags.php?taxonomy=doc_tag&post_type=docs' ); + add_submenu_page( 'wedocs', __( 'Latest', 'wedocs' ), __( 'Latest', 'wedocs' ), $capability, 'wedocs-latest', [ $this, 'latest_index' ] ); } /** @@ -107,6 +108,15 @@ public function page_index() { include __DIR__ . '/views/admin.php'; } + /** + * Latest Page handler. + * + * @return void + */ + public function latest_index(){ + include __DIR__ . '/views/latest.php'; + } + /** * Change the admin footer text on weDocs admin pages. * diff --git a/includes/Admin/views/latest.php b/includes/Admin/views/latest.php new file mode 100644 index 0000000..fe462f2 --- /dev/null +++ b/includes/Admin/views/latest.php @@ -0,0 +1,133 @@ +
+

+ + + + + +
+

+ display_name ); + } + + return $author_display_name; + } + + $args = array( + 'post_type' => 'docs', + 'posts_per_page' => 20, // Total number of posts to retrieve + 'post_status' => 'publish', + 'order' => 'DESC', + 'orderby' => 'modified', + ); + $recent_posts = get_posts( $args ); + + $list_items_markup = ''; + foreach ( $recent_posts as $post ) { + + $list_items_markup .= '
  • '; + + // title + $post_link = esc_url( get_permalink( $post ) ); + $title = get_the_title( $post ); + if ( ! $title ) { + $title = __( '(no title)' ); + } + $list_items_markup .= sprintf( + '%2$s', + $post_link, + $title + ); + + $list_items_markup .= '
    '; + + // info + // if modified,show (modified by $modified_author on date),or show (created by $post_author on date) + $is_modified = ( $post->post_date != $post->post_modified ) ? true : false; + + if ( $is_modified ) { + $author_display_name = my_get_the_modified_author( $post->ID ); + $byline = sprintf( __( 'modified by %1$s on %2$s' ), $author_display_name, $post->post_modified ); + } else { + $author_display_name = get_the_author_meta( 'display_name', $post->post_author ); + $byline = sprintf( __( 'created by %1$s on %2$s' ), $author_display_name, $post->post_date ); + } + $list_items_markup .= sprintf( '%1$s', esc_html( $byline ) ); + + $list_items_markup .= '
  • '; + } + + echo sprintf( + '
      %1$s
    ', + $list_items_markup + ); + + ?> +
    +

    + 'docs', + 'posts_per_page' => 20, + 'order' => 'DESC', + 'orderby' => 'modified', + ); + $recent_comments = get_comments( $args ); + + $list_items_markup = ''; + foreach ( $recent_comments as $comment ) { + + $list_items_markup .= '
  • '; + + // excerpt + $comment_link = esc_url( get_comment_link( $comment ) ); + $comment_content = get_comment_excerpt( $comment->comment_ID ); + var_dump( $comment_content ); + + $list_items_markup .= sprintf( + '%2$s', + $comment_link, + $comment_content + ); + + $list_items_markup .= '
    '; + + // info + // if reply,show ($comment_author replied $post_title on date),or show ($comment_author commented $post_title on date) + $is_reply = ( $comment->comment_parent != '0' ) ? true : false; + + $post_title = get_the_title( $comment->comment_post_ID ); + if ( $is_reply ) { + $list_items_markup .= sprintf( __( '%1$s replied %2$s on %3$s' ), $comment->comment_author, $post_title, $comment->comment_date ); + } else { + $list_items_markup .= sprintf( __( '%1$s commented %2$s on %3$s' ), $comment->comment_author, $post_title, $comment->comment_date ); + } + + $list_items_markup .= '
  • '; + } + + echo sprintf( + '
      %1$s
    ', + $list_items_markup + ); + + ?> +
    +