有时候我们需要在前台进行一些快捷操作时,通过前台工具栏来实现会比较方便,比如说前台快速审核文章等,这里通过一段代码放入funcitons.php内来实现这个功能,具体的功能是添加一个按钮到前台内容预览页的顶部Admin bar,实现文章状态的快速改变。
直接上代码:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28  | 
						//前台工具栏提交审核 add_action('admin_bar_menu',function ($admin_bar){     if(is_singular()){         global $post;         if ($post->post_status == 'draft' && current_user_can('edit_post', $post->ID)) {             $args    = array(                 'id'    => 'wb-pending',                 'title' => '<span class="ab-icon dashicons dashicons-upload"></span> 提交审核',                 'href'  => esc_url(home_url('?wbaction=pending&pid='.$post->ID)),             );             $admin_bar->add_node($args);         }     } },100,1); //处理前台工具栏操作 add_action('init',function (){     if(isset($_GET['wbaction']) && $_GET['wbaction'] == 'pending' && isset($_GET['pid']) && $_GET['pid']){         $postid = absint($_GET['pid']);         if(current_user_can('edit_post', $postid)){             wp_update_post(array(                 'ID' => $postid,                 'post_status' => 'pending',             ));         }         wp_redirect(get_preview_post_link( $postid ));     } });  | 
					
这里主要提供了一个思路以及示例代码,如需其他功能可以按照类似思路来实现。
