删除WordPress仪表板管理中的删除时未触发的POST挂钩

时间:2018-07-31 作者:bestprogrammerintheworld

我想做的是从自定义帖子类型中删除一些帖子bookitall_availabledate 从自定义帖子类型中删除帖子后bookitall_bookings 在管理仪表板中。

我正在使用delete\\u post挂钩:https://codex.wordpress.org/Plugin_API/Action_Reference/delete_post

Here\'s some relevant code: (如果需要更多,请告诉我)

public function __construct() 
    {                        
        add_action( \'init\', array( $this, \'loadlanguage\' ) );
    }


public function loadlanguage() 
{                 
    wp_enqueue_script( \'jquery\' );        

    wp_enqueue_style(
        \'bookitallcss\',
        plugins_url( \'/css/wibergsweb.css\', __FILE__)
    );      

    //Load (if there are any) translations
    $loaded_translation = load_plugin_textdomain( \'bookitall-wp\', false, 
    dirname( plugin_basename(__FILE__) ) . \'/lang/\' );
    $this->init();
    $this->admin_init();
}      

public function admin_init() {

    add_filter(\'manage_edit-bookitall_bookings_columns\', array($this, \'manage_allbookings_columns\') );
    add_filter(\'manage_bookitall_bookings_posts_custom_column\', array( $this, \'manage_allbookings_custom_fields\'), 10, 2);

    add_filter(\'manage_edit-bookitall_roomtypes_columns\', array($this, \'manage_allroomtypes_columns\') );
    add_filter(\'manage_bookitall_roomtypes_posts_custom_column\', array( $this, \'manage_allroomtypes_custom_fields\'), 10, 2);

    add_filter(\'manage_edit-bookitall_customers_columns\', array($this, \'manage_allcustomers_columns\') );
    add_filter(\'manage_bookitall_customers_posts_custom_column\', array( $this, \'manage_allcustomers_custom_fields\'), 10, 2);        

    add_filter(\'manage_edit-bookitall_available_columns\', array($this, \'manage_allavailable_columns\') );
    add_filter(\'manage_bookitall_available_posts_custom_column\', array( $this, \'manage_allavailable_custom_fields\'), 10, 2);        

    add_action( \'delete_post\', array( $this, \'bookings_sync\', 10 ) );

 }


//When removing a post from post type bookitall_bookings (bokningar)
public function bookings_sync ( $post_id ) {
    $post_type = get_post_type( $post_id );   
    wp_die(\'wow\');
    if ( $post_type != \'bookitall_bookings\' ) 
    {
        return;
    }

    //more code...
}
The issue is that function bookings_sync is not being fired? (wp\\u die(\'wow\')应该杀死Wordpress并退出一切?)

我也尝试过使用admin\\u init hook代替init hook,但仍然存在相同的问题。

我也尝试过从垃圾中永久删除帖子,但仍然不起作用。

Am I using wrong hook or what is going on? 请帮帮我:-)

1 个回复
SO网友:bestprogrammerintheworld

我真的找到了。“只是”输入错误。。。

add_action( \'delete_post\', array( $this, \'bookings_sync\', 10 ) );
应该是

add_action( \'delete_post\', array( $this, \'bookings_sync\'), 10 );

结束