因为本站近几篇文章都用到了这个函数,所以就整理了一下get_current_screen()。
当使用function add_action时;如果你需要判断当前的post type,可以使用该函数;
save_post有衍生的save_post_$post_type可以使用,但是delete_post并没有;
在新增或者删除一个alerts时,执行一个function; 当执行这两个事件时,print_r($_POST)输出为空,此时就用到了get_current_screen();
删除autosave事件见上一篇文章。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
add_action( 'save_post_alerts', 'updated_alerts_info' ); // save_post_alerts just work when update or publish or auto save an alert. function updated_alerts_info( $post_id ) { if(!empty($_POST)){ 判断仅仅是点了add new,而不是updated updated_alerts_zip($post_id); } } add_action('delete_post', 'delete_custom_alerts'); function delete_custom_alerts($post_id) { $screen = get_current_screen(); if ( 'alerts' == $screen->post_type ){ // 判断post type updated_alerts_zip($post_id); } } |