对于多用户投稿的WordPress站点,免不了要对用户提交的文章进行审核,但是每次都要点击进入文章列表查看是否有文章待审,是不是很麻烦?其实,我们可以在WordPress仪表盘直接显示待审的文章列表,登录以后一眼就可以看到了。

要做到这个,只需要将下面的代码添加到当前主题的 functions.php 文件即可:
/**
* WordPress <a href="https://www.wpdaxue.com/tag/%e4%bb%aa%e8%a1%a8%e7%9b%98" title="查看与【仪表盘】相关的文章" target="_blank" rel="noopener">仪表盘</a>显示待审核的文章列表
* http://blog.wpjam.com/m/pending-posts-dashboard-widget/
*/
add_action('wp_dashboard_setup', 'wpjam_modify_dashboard_widgets' );
function wpjam_modify_dashboard_widgets() {
global $wp_meta_boxes;
if(current_user_can('manage_options')){ //只有管理员才能看到
add_meta_box( 'pending_posts_dashboard_widget', '待审文章', 'pending_posts_dashboard_widget_function','dashboard', 'normal', 'core' );
}
}
function pending_posts_dashboard_widget_function() {
global $wpdb;
$pending_posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_status = 'pending' ORDER BY post_modified DESC");
if($pending_posts){ //判断是否有待审文章
echo '<ul>';
foreach ($pending_posts as $pending_post){
echo '<li><a href="'.admin_url().'post.php?post='.$pending_post->ID.'&action=edit">'.$pending_post->post_title.'</a></li>';
}
echo '</ul>';
}else echo '目前没有待审文章';
} |
/**
* WordPress <a href="https://www.wpdaxue.com/tag/%e4%bb%aa%e8%a1%a8%e7%9b%98" title="查看与【仪表盘】相关的文章" target="_blank" rel="noopener">仪表盘</a>显示待审核的文章列表
* http://blog.wpjam.com/m/pending-posts-dashboard-widget/
*/
add_action('wp_dashboard_setup', 'wpjam_modify_dashboard_widgets' );
function wpjam_modify_dashboard_widgets() {
global $wp_meta_boxes;
if(current_user_can('manage_options')){ //只有管理员才能看到
add_meta_box( 'pending_posts_dashboard_widget', '待审文章', 'pending_posts_dashboard_widget_function','dashboard', 'normal', 'core' );
}
}
function pending_posts_dashboard_widget_function() {
global $wpdb;
$pending_posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_status = 'pending' ORDER BY post_modified DESC");
if($pending_posts){ //判断是否有待审文章
echo '<ul>';
foreach ($pending_posts as $pending_post){
echo '<li><a href="'.admin_url().'post.php?post='.$pending_post->ID.'&action=edit">'.$pending_post->post_title.'</a></li>';
}
echo '</ul>';
}else echo '目前没有待审文章';
}
代码来自:我爱水煮鱼 http://blog.wpjam.com/m/pending-posts-dashboard-widget/,倡萌在源代码添加了一个判断是否有待审文章,如果没有,显示提示文字。
来源:
https://www.wpdaxue.com/pending-posts-dashboard-widget.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32438.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57