以下是网学网为您推荐的网络知识-WordPress给Admin Bar 添加删除链接,希望本篇文章对您学习有所帮助。
下面代码在 WordPress Admin Bar 增加一个当前日志的快速删除链接,复制到当前的主题的 functions.php 文件即可:
<?php
function my_add_admin_bar_trash_menu() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$current_object = get_queried_object();
if ( empty($current_object) )
return;
if ( !empty( $current_object->post_type ) &&
( $post_type_object = get_post_type_object( $current_object->post_type ) ) &&
current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
) {
$wp_admin_bar->add_menu(
array( ''id'' => ''delete'',
''title'' => __(''Move to Trash''),
''href'' => get_delete_post_link($current_object->term_id)
)
);
}
}
add_action( ''admin_bar_menu'', ''my_add_admin_bar_trash_menu'', 35 );
?>
Wordpress下载:
本文转自:http://fairyfish.net/m/add-a-delete-button-to-wordpress-admin-bar/