Skip to content

Commit

Permalink
Add edit page link to admin bar for archive page
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Jun 7, 2019
1 parent a075d59 commit aa63a6d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
Binary file modified languages/types-de_DE.mo
Binary file not shown.
10 changes: 7 additions & 3 deletions languages/types-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-21T13:47:51+01:00\n"
"PO-Revision-Date: 2019-02-21 13:48+0100\n"
"POT-Creation-Date: 2019-06-07T11:12:23+02:00\n"
"PO-Revision-Date: 2019-06-07 11:12+0200\n"
"Last-Translator: Lukas Gächter <lukas.gaechter@mind.ch>\n"
"Language-Team: \n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
"X-Generator: Poedit 2.2.3\n"
"X-Domain: mind/types\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: lib/Post_Type_Page.php:154
msgid "Edit page for %s"
msgstr "Seite für %s bearbeiten"

#. translators: %s: Singular taxonomy name
#. translators: %s: Singular post type name
#: lib/Taxonomy_Labels.php:87 lib/Post_Type_Labels.php:90
Expand Down
6 changes: 5 additions & 1 deletion languages/types.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2019-02-21T13:47:51+01:00\n"
"POT-Creation-Date: 2019-06-07T11:12:23+02:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.1.0\n"
"X-Domain: mind/types\n"

#: lib/Post_Type_Page.php:154
msgid "Edit page for %s"
msgstr ""

#. translators: %s: Singular taxonomy name
#. translators: %s: Singular post type name
#: lib/Taxonomy_Labels.php:87
Expand Down
32 changes: 32 additions & 0 deletions lib/Post_Type_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function init() {
if ( ! $this->args['is_singular_public'] ) {
add_action( 'template_redirect', [ $this, 'template_redirect' ] );
}

if ( ! is_admin() ) {
add_action( 'admin_bar_menu', [ $this, 'add_page_edit_link' ], 80 );
}
}

/**
Expand Down Expand Up @@ -122,4 +126,32 @@ public function filter_wp_nav_menu_objects( $menu_items ) {

return $menu_items;
}

/**
* Adds a page edit link for the page that acts as the archive to the admin bar.
*
* @see wp_admin_bar_edit_menu()
*
* @since 2.3.2
* @param \WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
*/
public function add_page_edit_link( $wp_admin_bar ) {
$object = get_queried_object();

if ( empty( $object )
|| ! $object instanceof \WP_Post_Type
|| $object->name !== $this->post_type
|| ! $object->show_in_admin_bar
|| ! current_user_can( 'edit_pages', $this->post_id )
) {
return;
}

$wp_admin_bar->add_menu( [
'id' => 'edit',
/* translators: Plural name of the post type */
'title' => sprintf( __( 'Edit page for %s', 'mind/types' ), $object->labels->name ),
'href' => get_edit_post_link( $this->post_id ),
] );
}
}

0 comments on commit aa63a6d

Please sign in to comment.