禁用一种自定义帖子类型的WordPress垃圾



是否可以禁用一种自定义帖子类型的WordPress垃圾功能?

目标是具有与define('empty_trash_days',0)的功能相同的功能 - 永久填写删除 - 除了一个cpt,而不是网站范围内。

谢谢,

tim

虽然我无法提出一种特别优雅的方法来做到这一点,但我能够使用wp_trash_post操作绕过垃圾。

<?php
function directory_skip_trash($post_id) {
    if (get_post_type($post_id) == 'directory') {
        // Force delete
        wp_delete_post( $post_id, true );
    }
} 
add_action('wp_trash_post', 'directory_skip_trash');

本质上是当帖子被丢弃时,您可以将其再次用$ force_delete参数设置为true。

可以通过找到在此cpt中更改整个admin ui中"垃圾"一词的方法来改进该解决方案,但是对于我的特定用例,这足够好。

我无法为我提供wp_trash_post操作工作,因此我使用了另一种方法,用删除链接代替了垃圾链接。

post_row_actions过滤帖子列表表上的行动作链接的数组。

<?php
function replace_trash_with_delete( $actions, $post ) {
    if( 'directory' === $post->post_type ){ // Replace 'directory' with your post type
        unset( $actions['trash'] ); // Removes the trash link 
        $deleteUrl = esc_url( get_delete_post_link( $post->ID, '', true ) ) ;
        $deleteLink = '<a rel="nofollow" href="' . $deleteUrl . '">' . __('Delete') .'</a>'; // Creates the new delete link
        $actions = 
            array_slice( $actions, 0, 1, true ) +
            array( 'delete' => $deleteLink ) +
            array_slice( $actions, 1, count( $actions ) - 1, true ); // Adds the delete link to the array of links
    }
} 
add_filter( 'post_row_actions','replace_trash_with_delete', 10, 2 ); 

最新更新