themehybrid / hybrid-core

Official repository for the Hybrid Core WordPress development framework.
GNU General Public License v2.0
689 stars 144 forks source link

Feature Request: View Term / Edit Term links #143

Open sharmashivanand opened 7 years ago

sharmashivanand commented 7 years ago

I find it tremendously helpful to have an 'Edit Term' link on the taxonomy / tag / cat archive view.

Also I find it very helpful to have a 'View Term' link on the tax / tag / cat edit screen.

Not sure if it will make it to the code but I believe it's one of those small utility things which make HC special.

Display Term Edit Link on Archive Title / header (insert own hook)

add_action( 'hyper_archive_title', 'hyper_edit_term_link' );

function hyper_edit_term_link( $text = null, $before = '', $after = '', $id = 0, $class = 'term-edit-link' ) {

    $term = get_queried_object();

    if ( ! $url = get_edit_tag_link( $term, $term->taxonomy ) ) {
        return;
    }

    if ( empty( $text ) ) {
        $text = __( 'Edit Term' );
    }

    $link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>';

    echo $before . apply_filters( 'edit_term_link', $link, $term->ID, $text ) . $after;
}

Display View Term link on the edit screen:

add_action('load-edit-tags.php','hyperland_add_view_link');

function hyperland_add_view_link() {
    $screen = get_current_screen(); 
    add_action( "{$screen->taxonomy}_term_edit_form_top", 'hyperland_display_term_view_link', 10 ,2 );
}

function hyperland_display_term_view_link( $tag, $taxonomy ) {
    echo '<h3><a href="'. get_term_link( $tag ) . '">View</a></h3>';
}
justintadlock commented 7 years ago

This is really two different enhancements.

Edit Link:

The first is an edit term link. I'm not sure what advantages this has over the core WP edit_term_link() function other than the addition of a class attribute. See: https://developer.wordpress.org/reference/functions/edit_term_link/

If the functionality didn't already exist, I think that'd be a good addition to HC.

View Link:

The second enhancement is to the core WP admin. It's not directly related to theme development. It would also fall under plugin territory under the WordPress.org theme review guidelines. So, it's probably going to be a non-starter for that reason alone.

sharmashivanand commented 7 years ago

So get_edit_term_link outputs something like https://www.example.com/wp-admin/term.php?taxonomy&tag_ID=14&post_type=post

As against get_edit_tag_link which gives https://www.example.com/wp-admin/term.php?taxonomy=category&tag_ID=14&post_type=post

The difference is that the previous link breaks functionality (Yoast meta box on terms and other meta boxes were missing (unless taxonomy=category is present in the url) ). You can try that on any test installation to see if the HC layout meta boxes appear on the term edit screen.

Currently I'm putting the Term Edit Link in the theme and the View Link in a plugin.

Rarst commented 7 years ago

So get_edit_term_link outputs something like https://www.example.com/wp-admin/term.php?taxonomy&tag_ID=14&post_type=post

This looks like a core bug, it says to default to the taxonomy of the object but it never adds taxonomy to URL unless argument is passed explicitly. Should be reported on trac rather than re-invented. :)

justintadlock commented 7 years ago

Yep, that should be reported here: https://core.trac.wordpress.org

sharmashivanand commented 7 years ago

Guess we found a bug during a feature request :)

BTW do you find the utility of having the Edit Term link useful? (It's easy to change the layout, access the Yoast metabox etc. so I thought why not suggest it)

justintadlock commented 7 years ago

I think the edit term link can be useful. I use the WP toolbar on the front end myself, which shows the edit link. But, for people who don't, it could be a welcome addition in a theme.