Permalink
Browse files

A cleaner version that links "Edit" to the edit.php screen for the

post_type.
  • Loading branch information...
1 parent f9a351d commit c9693053feb9254357a3ac6577bb76b0894f5025 Gregory Cornelius committed Aug 1, 2012
Showing with 29 additions and 21 deletions.
  1. +29 −21 bu-versions.php
View
@@ -707,36 +707,46 @@ function admin_bar_menu() {
global $wp_admin_bar;
if(is_singular() && is_object( $wp_admin_bar ) ) {
+ if( is_preview() && isset( $_GET['version_id'] ) ) {
+ $post_id = (int) $_GET['version_id'];
+ $current_object = get_post( $post_id );
+ } else {
+ $current_object = get_queried_object();
+ }
- $wp_admin_bar->remove_menu('edit');
+ $current_post_type = get_post_type_object( $current_object->post_type );
- $current_object = get_queried_object();
if( ! isset( $current_object ) ) return;
- $current_post_type = get_post_type_object( $current_object->post_type );
+
$version = new BU_Version();
- if( $this->is_alt( $current_object->ID ) ) {
+ if( $this->is_alt( $current_object->post_type ) ) {
$version->get( $current_object->ID );
} else {
$version->get_version( $current_object->ID );
}
- if( $version->has_version() ) {
- if( current_user_can( $current_post_type->cap->edit_post, $current_object->ID ) ) {
- $wp_admin_bar->add_menu( array( 'id' => 'bu-edit', 'title' => _x( 'Edit', 'admin bar menu group label' ), 'href' => get_edit_post_link( $current_object->ID ) ) );
- $wp_admin_bar->add_menu( array( 'parent' => 'bu-edit', 'id' => 'bu-edit-original', 'title' => 'Edit Original', 'href' => $version->get_original_edit_url() ) );
- $wp_admin_bar->add_menu( array( 'parent' => 'bu-edit', 'id' => 'bu-edit-alt', 'title' => 'Edit Alternate Version', 'href' => $version->get_edit_url() ) );
- } else {
- $alternate_post_type = get_post_type_object( $version->post->post_type );
- if( current_user_can( $alternate_post_type->cap->edit_post, $version->post->ID ) ) {
- $wp_admin_bar->add_menu( array( 'id' => 'bu-edit', 'id' => 'bu-edit-alt', 'title' => 'Edit Alternate Version', 'href' => $version->get_edit_url() ) );
- }
- }
- } else {
- 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 ) && $post_type_object->show_ui ) {
- $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => _x( 'Edit', 'admin bar menu group label' ), 'href' => get_edit_post_link( $current_object->id ) ) );
- }
+ $wp_admin_bar->remove_menu('edit');
+ if( current_user_can( $current_post_type->cap->edit_posts ) ) {
+ $wp_admin_bar->add_menu( array( 'id' => 'bu-edit', 'title' => _x( 'Edit', 'admin bar menu group label' ), 'href' => admin_url( 'edit.php?post_type=' . $current_object->post_type ) ) );
+ }
+ //@todo need to deal with the menu changes in 3.4
+ $original_post_type = get_post_type_object( $version->original->post_type );
+ $alternate_post_type = get_post_type_object( $version->post->post_type );
+
+ // in this case we don't want to override the edit links
+ remove_filter('get_edit_post_link', array($this, 'override_edit_post_link'), 10, 3);
+
+ if( current_user_can( $original_post_type->cap->edit_post, $version->original->ID ) ) {
+
+ $wp_admin_bar->add_menu( array( 'parent' => 'bu-edit', 'id' => 'bu-edit-original', 'title' => 'Edit Original', 'href' => $version->get_original_edit_url() ) );
}
+
+ if( $version->has_version() && current_user_can( $alternate_post_type->cap->edit_post, $version->post->ID ) ) {
+ $wp_admin_bar->add_menu( array( 'parent' => 'bu-edit', 'id' => 'bu-edit-alt', 'title' => 'Edit Alternate Version', 'href' => $version->get_edit_url() ) );
+ }
+
+ add_filter('get_edit_post_link', array($this, 'override_edit_post_link'), 10, 3);
}
}
@@ -870,8 +880,6 @@ function has_version() {
return isset( $this->post );
}
-
-
function get_original_edit_url($context = null) {
return get_edit_post_link($this->original->ID, $context);
}

0 comments on commit c969305

Please sign in to comment.