Adds shortcuts from taxonomy templates to admin #832. Separates admin bar items logic in its own class.
This commit is contained in:
parent
21144997d3
commit
2360f8f188
|
@ -0,0 +1,32 @@
|
|||
/* Styles Tainacan links in the WordPress admin top bar */
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomies-edition-link a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomy-edition-link a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomies-edition-link a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-repository-items-edition-link a {
|
||||
background-color: #1d3968;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-tainacan-item-edition-link a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collection-edition-link a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collections-edition-link a {
|
||||
background-color: #187181;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomies-edition-link a::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomy-edition-link a::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomies-edition-link a::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-item-edition-link a::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collection-edition-link a::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collections-edition-link a::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-repository-items-edition-link a::before {
|
||||
color: white;
|
||||
content: '\f464';
|
||||
top: 2px;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomies-edition-link:hover a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomy-edition-link:hover a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-taxonomies-edition-link:hover a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-item-edition-link:hover a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collection-edition-link:hover a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collections-edition-link:hover a,
|
||||
#wpadminbar #wp-admin-bar-tainacan-repository-items-edition-link:hover a {
|
||||
color: white;
|
||||
}
|
|
@ -24,11 +24,4 @@
|
|||
[data-module="dynamic-items-list"]:not(.has-mounted) {
|
||||
min-height: 360px; }
|
||||
|
||||
/* Admin menu links */
|
||||
#wpadminbar #wp-admin-bar-tainacan-item-edition-link > .ab-item::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collection-edition-link > .ab-item::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collections-edition-link > .ab-item::before {
|
||||
content: '\f464';
|
||||
top: 2px; }
|
||||
|
||||
/*# sourceMappingURL=tainacan-gutenberg-block-common-theme-styles.css.map */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"version": 3,
|
||||
"mappings": "AACA;;;;;;sDAMuD;EACnD,gBAAgB,EAAE,OAAO;EACzB,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,GAAG;;AAEtB;gDACiD;EAC7C,UAAU,EAAE,IAAI;;AAEpB;;;;2DAI4D;EACxD,UAAU,EAAE,KAAK;;AAErB;oDACqD;EACjD,UAAU,EAAE,KAAK;;AAGrB,sBAAsB;AACtB;;8EAE+E;EAC3E,OAAO,EAAE,OAAO;EAChB,GAAG,EAAE,GAAG",
|
||||
"mappings": "AACA;;;;;;sDAMuD;EACnD,gBAAgB,EAAE,OAAO;EACzB,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,GAAG;;AAEtB;gDACiD;EAC7C,UAAU,EAAE,IAAI;;AAEpB;;;;2DAI4D;EACxD,UAAU,EAAE,KAAK;;AAErB;oDACqD;EACjD,UAAU,EAAE,KAAK",
|
||||
"sources": ["../../views/gutenberg-blocks/scss/gutenberg-blocks-theme-style.scss"],
|
||||
"names": [],
|
||||
"file": "tainacan-gutenberg-block-common-theme-styles.css"
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
namespace Tainacan;
|
||||
|
||||
class Admin_Bar_Items {
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'admin_bar_menu', array($this, 'add_admin_bar_items'), 500 );
|
||||
add_action( 'init', array($this, 'add_admin_bar_items_styles') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Color to style the admin bar items
|
||||
*/
|
||||
function add_admin_bar_items_styles() {
|
||||
global $TAINACAN_BASE_URL;
|
||||
|
||||
if ( is_user_logged_in() )
|
||||
wp_enqueue_style( 'tainacan-admin-bar', $TAINACAN_BASE_URL . '/assets/css/tainacan-admin-bar.css', [], TAINACAN_VERSION );
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Adds Edit links to Tainacan item and collection pages
|
||||
*/
|
||||
function add_admin_bar_items ( \WP_Admin_Bar $admin_bar ) {
|
||||
|
||||
// No need to add this shortcuts on the admin
|
||||
if ( !is_admin() && is_user_logged_in() ) {
|
||||
|
||||
// We should only do this in singular pages, as the items list also return the first item on loop
|
||||
if ( is_singular() ) {
|
||||
|
||||
$item = tainacan_get_item();
|
||||
|
||||
// There should exist a Tainacan item and the user should have permission for this
|
||||
if ( isset($item) && $item->can_edit() ) {
|
||||
|
||||
$url = $item->get_edit_url();
|
||||
|
||||
// The item edition link must be valid!
|
||||
if ( $url ) {
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-item-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit item', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit this item on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
}
|
||||
|
||||
} else {
|
||||
$post = get_queried_object();
|
||||
|
||||
// Is it a taxonomy-post-type post?
|
||||
if ( property_exists($post, 'post_type') && $post->post_type == Entities\Taxonomy::$post_type && current_user_can('edit_posts', $post->ID) ) {
|
||||
|
||||
$url = admin_url( '?page=tainacan_admin#/taxonomies/' . $post->ID );
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-taxonomy-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit taxonomy', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit this taxonomy on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
// In the term items list, display a link to the single taxonomy
|
||||
else if ( is_tax() ) {
|
||||
|
||||
$term = get_queried_object();
|
||||
|
||||
if ( isset($term->taxonomy) ) {
|
||||
$prefix = substr( $term->taxonomy, 0, strlen( Entities\Taxonomy::$db_identifier_prefix ) );
|
||||
|
||||
if ( $prefix == Entities\Taxonomy::$db_identifier_prefix ) {
|
||||
|
||||
$tax_id = \Tainacan\Repositories\Taxonomies::get_instance()->get_id_by_db_identifier($term->taxonomy);
|
||||
|
||||
if ( $tax_id && current_user_can( 'edit_posts', $tax_id ) ) {
|
||||
$url = admin_url( '?page=tainacan_admin#/taxonomies/' . $tax_id);
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-taxonomy-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit taxonomy', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit this taxonomy on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// In the collection and items list, we can also display links
|
||||
else if ( is_archive() ) {
|
||||
|
||||
$collection = tainacan_get_collection();
|
||||
|
||||
// There should exist a Tainacan collection and the user should have permission for edit it
|
||||
if ( $collection && $collection->can_edit() ) {
|
||||
|
||||
$url = admin_url( '?page=tainacan_admin#/collections/' . $collection->get_ID() . '/settings' );
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-collection-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit collection', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit this collection on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
|
||||
// If no single collection is found, we may be in a collections list
|
||||
} else if ( is_post_type_archive('tainacan-collection') ) {
|
||||
|
||||
$url = admin_url( '?page=tainacan_admin#/collections/' );
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-collections-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit collections', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit the collections on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
|
||||
} else if ( is_post_type_archive('tainacan-taxonomy') ) {
|
||||
|
||||
$url = admin_url( '?page=tainacan_admin#/taxonomies/' );
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-taxonomies-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit taxonomies', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit the taxonomies on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
} else {
|
||||
|
||||
global $wp_query;
|
||||
if ( $wp_query->get( 'tainacan_repository_archive' ) == 1 ) {
|
||||
|
||||
$url = admin_url( '?page=tainacan_admin#/items/' );
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-repository-items-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit items', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit the items on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -170,6 +170,7 @@ $Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance();
|
|||
|
||||
require_once(__DIR__ . '/../views/gutenberg-blocks/class-tainacan-gutenberg-block.php');
|
||||
|
||||
$Tainacan_Admin_Bar_Items = new \Tainacan\Admin_Bar_Items();
|
||||
$Tainacan_Search_Engine = new \Tainacan\Search_Engine();
|
||||
$Tainacan_Elastic_press = \Tainacan\Elastic_Press::get_instance();
|
||||
|
||||
|
|
|
@ -58,85 +58,6 @@ add_filter( 'wp_untrash_post_status', function( $new_status, $post_id, $previous
|
|||
return $previous_status;
|
||||
}, 10, 3 );
|
||||
|
||||
/*
|
||||
*
|
||||
* Adds Edit links to Tainacan item and collection pages
|
||||
*/
|
||||
function tainacan_add_admin_bar_items ( WP_Admin_Bar $admin_bar ) {
|
||||
|
||||
// No need to add this shortcuts on the admin
|
||||
if ( !is_admin() ) {
|
||||
|
||||
// We should only do this in singular pages, as the items list also return the first item on loop
|
||||
if ( is_singular() ) {
|
||||
|
||||
$item = tainacan_get_item();
|
||||
|
||||
// There should exist a Tainacan item and the user should have permission for this
|
||||
if ( isset($item) && $item->can_edit() ) {
|
||||
|
||||
$url = $item->get_edit_url();
|
||||
|
||||
// The item edition link must be valid!
|
||||
if ( $url ) {
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-item-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit item', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit this item on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// In the collection and items list, we can also display links
|
||||
else if ( is_archive() ) {
|
||||
|
||||
$collection = tainacan_get_collection();
|
||||
|
||||
// There should exist a Tainacan collection and the user should have permission for edit it
|
||||
if ( $collection && $collection->can_edit() ) {
|
||||
|
||||
$url = admin_url( '?page=tainacan_admin#/collections/' . $collection->get_ID() . '/settings' );
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-collection-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit collection', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit this collection on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
|
||||
// If no single collection is found, we may be in a collections list
|
||||
} else if ( is_post_type_archive('tainacan-collection') ) {
|
||||
|
||||
$url = admin_url( '?page=tainacan_admin#/collections/' );
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'tainacan-collections-edition-link',
|
||||
'parent' => null,
|
||||
'group' => null,
|
||||
'title' => __( 'Edit collections', 'tainacan' ),
|
||||
'href' => $url,
|
||||
'meta' => [
|
||||
'title' => __( 'Edit the collections on Tainacan Admin', 'tainacan' )
|
||||
]
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'admin_bar_menu', 'tainacan_add_admin_bar_items', 500 );
|
||||
|
||||
function wp_kses_tainacan($content, $context='tainacan_content') {
|
||||
$allowed_html = wp_kses_allowed_html($context);
|
||||
return wp_kses($content, $allowed_html);
|
||||
|
|
|
@ -24,12 +24,4 @@
|
|||
[data-module="facets-list"]:not(.has-mounted),
|
||||
[data-module="dynamic-items-list"]:not(.has-mounted) {
|
||||
min-height: 360px;
|
||||
}
|
||||
|
||||
/* Admin menu links */
|
||||
#wpadminbar #wp-admin-bar-tainacan-item-edition-link > .ab-item::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collection-edition-link > .ab-item::before,
|
||||
#wpadminbar #wp-admin-bar-tainacan-collections-edition-link > .ab-item::before {
|
||||
content: '\f464';
|
||||
top: 2px;
|
||||
}
|
Loading…
Reference in New Issue