自定义帖子类型,隐藏或禁用发布元框中的回收站按钮

时间:2016-08-27 作者:poashoas

enter image description here

我一直在为我的主题添加帖子类型,如何隐藏/禁用“移动到垃圾桶”按钮?以下是我目前的代码:

$labels = array(
        \'name\'                       => _x( \'Inhoud\', \'taxonomy general name\' ),
        \'singular_name\'              => _x( \'Inhoud\', \'taxonomy singular name\' ),
        \'search_items\'               => __( \'Zoek Inhoud\' ),
        // \'popular_items\'              => __( \'Popular Writers\' ),
        \'all_items\'                  => __( \'Alle Inhoud\' ),
        \'parent_item\'                => null,
        \'parent_item_colon\'          => null,
        \'edit_item\'                  => __( \'Wijzig Inhoud\' ),
        \'update_item\'                => __( \'Update Inhoud\' ),
        \'add_new_item\'               => __( \'Toevoegen Nieuwe Inhoud\' ),
        // \'new_item_name\'              => __( \'Nieuwe Evenement Naam\' ),
        // \'separate_items_with_commas\' => __( \'Separate writers with commas\' ),
        // \'add_or_remove_items\'        => __( \'Add or remove writers\' ),
        // \'choose_from_most_used\'      => __( \'Choose from the most used writers\' ),
        \'not_found\'                  => __( \'Geen inhoud gevonden.\' ),
        \'menu_name\'                  => __( \'Inhoud\' ),
    );

    $args = array(
        \'hierarchical\'      => false,
        \'labels\'            => $labels,
        \'show_ui\'           => true,
        //\'show_admin_column\'     => true,
        //\'update_count_callback\' => \'_update_post_term_count\',
    \'menu_position\'     => 7,
    \'menu_icon\'         => \'dashicons-admin-post\',
    \'show_in_menu\'      => true,
    \'show_in_nav_menus\' => false,
    \'show_in_admin_bar\' => false,
        // \'query_var\'         => true,
        // \'rewrite\'           => array( \'slug\' => \'inhoud\' ),
    \'capabilities\'      => array( 
                            \'create_posts\'  => \'do_not_allow\',
                            //\'edit_post\'   => \'true\',
                            //\'delete_posts\'   => \'do_not_allow\'
                          ),
    \'supports\'          => array( ),
    \'map_meta_cap\'      => array(\'delete_post\' => false),
    \'has_archive\'       => true,
    \'public\'            => true
    );

    register_post_type( \'inhoud\', $args );

2 个回复
最合适的回答,由SO网友:Bhagchandani 整理而成

您可以通过在管理区域中添加css来隐藏“移动到垃圾箱”按钮。在中尝试以下代码functions.php 文件:

function my_custom_admin_styles() {
?>
    <style type="text/css">
      .post-type-inhoud form #delete-action{
           display:none;
       }
     </style>
<?php
}
add_action(\'admin_head\', \'my_custom_admin_styles\');

SO网友:Ethan O\'Sullivan

测试了由提供的代码user3888958, 但对我不起作用。以下是我自己的版本,其中隐藏了“移动到垃圾桶”链接:

add_action( \'admin_head\', \'wpse_237305_disable_trash\' );

function wpse_237305_disable_trash() {
    global $pagenow;

    if ( $pagenow == \'post.php\' ) {
        ?>
        <script type="text/javascript">
            jQuery( document ).ready( function( $ ) {
                $( \'#delete-action\' ).remove();
            } );
        </script>
        <?php
    }
}

结果

enter image description here

相关推荐

Wp_trash_post挂钩-使用wp_die时的页面更新问题

我正在构建一个插件,在某些情况下可以防止某些帖子被放入垃圾箱。为此,我使用“wp\\u trash\\u post”。在回调函数中,我执行逻辑来检查帖子是否可以放入垃圾箱。如果不能,则调用wp\\u die()。简化的代码如下所示:add_action( \'wp_trash_post\', \'check_delete_posts\' ); function check_delete_posts( $post_id ) { $check = false;