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