最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Unset actions for terms parent only

programmeradmin1浏览0评论

I'm trying to unseting actions for Parent terms only but unsetting the action "view" doesn't work. Terms is always clickable.

Here is what i'm trying to do :

Edit 'Code got malfunctions don't use it'

$user = wp_get_current_user();
if ( in_array( 'editor', (array) $user->roles ) ) {

    add_filter( 'tag_row_actions', 'remove_row_actions_term_parent', 10, 2 );
    function remove_row_actions_term_parent( $actions, $term ) {
        if ($term->parent == 0) {
            unset( $actions['delete'] );
            unset( $actions['trash'] );
            unset( $actions['edit'] );
            unset( $actions['view'] );
            unset( $actions['inline hide-if-no-js'] );
        }
        return $actions;
    }

    add_action( 'pre_delete_term', 'restrict_taxonomy_parent_deletion', 10, 2 );
    function restrict_taxonomy_parent_deletion( $term, $taxonomy ) {
        if ($term->parent == 0) {
            wp_die( 'Cette catégorie est protégée.' );
        }
    }

    add_action('edit_terms', 'restrict_taxonomy_parent_edit', 10, 2);
    function restrict_taxonomy_parent_edit( $term, $taxonomy ) {
        if ($term->parent == 0) {
            wp_die('Cette catégorie ne peut être modifiée');
        }
    }

    add_action( 'admin_head', function () {
        $current_screen = get_current_screen();

        // Hides the "Delete" link on all term edit page.
        if ( 'term' === $current_screen->base &&
        'category' === $current_screen->taxonomy ) :
        ?>
            <style>#delete-link { display: none !important; }</style>
        <?php
        endif;
    } );

    // Jquery Unset "-1" on <select></select> for add taxonomies. This will unset the possibility to add parent tax.

    add_action( 'admin_enqueue_scripts', 'load_custom_script' );
    function load_custom_script() {
        wp_enqueue_script('custom_js_script', get_stylesheet_directory_uri().'/js/admin-script.js', array('jquery'));
    }
}
// Jquery Unset "Aucun" on <select></select> for add taxonomies. This will unset the possibility to add parent tax.
jQuery(document).ready(function(){
    // Unset on cat page
    jQuery("#parent option[value='-1']").remove();
    // Unset on post-new page
    jQuery("#newcategory_parent option[value='-1']").remove();

});

I'm not sure if i'm doing the wright way, maybe is there another solution easier ?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论