| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\DashboardWidgets; |
| 4 |
|
| 5 |
// no direct access allowed |
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* Recent Posts Dashboard Widget |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
/** |
| 16 |
* WPAdminify |
| 17 |
* |
| 18 |
* @author Jewel Theme <support@jeweltheme.com> |
| 19 |
*/ |
| 20 |
class Adminify_RecentPosts { |
| 21 |
|
| 22 |
public function __construct() { |
| 23 |
add_action( 'wp_dashboard_setup', [ $this, 'jltwp_adminify_recent_posts_widget_register' ] ); |
| 24 |
} |
| 25 |
public function jltwp_adminify_recent_posts_widget_register() { |
| 26 |
wp_add_dashboard_widget( |
| 27 |
'jltwp_adminify_dash_recent_posts', |
| 28 |
esc_html__( 'Recent Posts - Adminify', 'adminify' ), |
| 29 |
[ $this, 'jltwp_adminify_recent_posts_widget' ] |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
public function jltwp_adminify_recent_posts_widget() { |
| 34 |
$args = [ |
| 35 |
'post_type' => 'post', |
| 36 |
'post_status' => 'publish', |
| 37 |
'posts_per_page' => 6, |
| 38 |
'orderby' => 'date', |
| 39 |
'ignore_sticky_posts' => 1, |
| 40 |
'tax_query' => [], |
| 41 |
]; |
| 42 |
?> |
| 43 |
|
| 44 |
<div class="jltwp-adminify-list"> |
| 45 |
<?php |
| 46 |
$adminify_dash_recent_posts = new \WP_Query( $args ); |
| 47 |
if ( $adminify_dash_recent_posts->have_posts() ) { |
| 48 |
?> |
| 49 |
|
| 50 |
<div class="wp-adminify-recent-posts"> |
| 51 |
<table class="adminify-recent-posts-table"> |
| 52 |
<tr> |
| 53 |
<th><?php echo esc_html__( 'Post Title', 'adminify' ); ?></th> |
| 54 |
<th><?php echo esc_html__( 'Author', 'adminify' ); ?></th> |
| 55 |
<th><?php echo esc_html__( 'Category', 'adminify' ); ?></th> |
| 56 |
<th> |
| 57 |
<img src="<?php echo esc_url( WP_ADMINIFY_ASSETS_IMAGE ); ?>widgets/comment.svg" alt="Icon"> |
| 58 |
</th> |
| 59 |
</tr> |
| 60 |
|
| 61 |
<?php |
| 62 |
while ( $adminify_dash_recent_posts->have_posts() ) { |
| 63 |
$adminify_dash_recent_posts->the_post(); |
| 64 |
|
| 65 |
$post_title = get_the_title(); |
| 66 |
$edit_url = admin_url( 'post.php?post=' . get_the_ID() . '&action=edit' ); |
| 67 |
$image_id = get_post_thumbnail_id(); |
| 68 |
$thumb_image = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID(), [ 36, 36 ] ) ); |
| 69 |
$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true ); |
| 70 |
?> |
| 71 |
|
| 72 |
<tr> |
| 73 |
<td> |
| 74 |
<div class="media"> |
| 75 |
|
| 76 |
<?php if ( has_post_thumbnail() ) { ?> |
| 77 |
<a href="<?php echo esc_url( $edit_url ); ?>"> |
| 78 |
<div class="media-left adminify-author-avatar image is-36x36"> |
| 79 |
<img src="<?php echo esc_url( $thumb_image ); ?>" alt="<?php echo esc_attr( $image_alt ); ?>"> |
| 80 |
</div> |
| 81 |
</a> |
| 82 |
<?php } ?> |
| 83 |
|
| 84 |
<div class="content-body"> |
| 85 |
<a href="<?php echo esc_url( $edit_url ); ?>" class="adminify-post-title is-inline-block is-capitalized"> |
| 86 |
<?php echo esc_html( get_the_title() ); ?> |
| 87 |
</a> |
| 88 |
<span class="adminify-post-time"> |
| 89 |
<time datetime="<?php echo get_the_date(); ?>"><?php echo get_the_date(); ?></time> |
| 90 |
</span> |
| 91 |
</div> |
| 92 |
</div> |
| 93 |
</td> |
| 94 |
<td> |
| 95 |
<h5 class="adminify-author-name is-capitalized"> |
| 96 |
<?php echo '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" rel="author" target="_blank">' . esc_html( get_the_author() ) . '</a>'; ?> |
| 97 |
</h5> |
| 98 |
</td> |
| 99 |
<td> |
| 100 |
<?php |
| 101 |
$categories_list = get_the_category_list( __( ', ', 'adminify' ) ); |
| 102 |
if ( $categories_list ) { |
| 103 |
printf( |
| 104 |
/* translators: %s: List of categories. */ |
| 105 |
'<div class="adminify-post-category">' . esc_html__( '%s', 'adminify' ) . ' </div>', |
| 106 |
$categories_list // phpcs:ignore WordPress.Security.EscapeOutput |
| 107 |
); |
| 108 |
} |
| 109 |
?> |
| 110 |
</td> |
| 111 |
<td> |
| 112 |
<div class="adminify-post-comments"> |
| 113 |
<span class="adminify-post-counter"> |
| 114 |
<?php comments_number( esc_html__( '0', 'adminify' ), esc_html__( '1', 'adminify' ), esc_html__( '%', 'adminify' ) ); ?> |
| 115 |
</span> |
| 116 |
</div> |
| 117 |
</td> |
| 118 |
</tr> |
| 119 |
|
| 120 |
<?php } ?> |
| 121 |
</table> |
| 122 |
</div> |
| 123 |
|
| 124 |
<?php |
| 125 |
wp_reset_postdata(); |
| 126 |
} |
| 127 |
?> |
| 128 |
</div> |
| 129 |
<?php |
| 130 |
|
| 131 |
} |
| 132 |
} |
| 133 |
|