public static function init() { add_action('set_object_terms', function ($post_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) { $post_type = get_post_type($post_id); if (in_array($taxonomy, Lift_Taxonomy_Update_Watcher::get_watched_taxonomies($post_type))) { if ($append || array_diff($old_tt_ids, $tt_ids) || array_diff($tt_ids, $old_tt_ids)) { lift_queue_field_update($post_id, 'taxonomy_' . $taxonomy, 'post'); } } }, 10, 6); add_action('edited_term', function ($term_id, $tt_id, $taxonomy) { $watched_post_types = Lift_Post_Update_Watcher::get_watched_post_types(); $tax_obj = get_taxonomy($taxonomy); $post_types = array_intersect($watched_post_types, $tax_obj->object_type); foreach ($post_types as $post_type) { if (in_array($taxonomy, Lift_Taxonomy_Update_Watcher::get_watched_taxonomies($post_type))) { //we now have to update every post that has this term...dude, this sucks $post_ids = get_posts(array('fields' => 'ids', 'posts_per_page' => 999, 'post_type' => $post_type, 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_id)))); foreach ($post_id as $post_id) { lift_queue_field_update($post_id, 'taxonomy_' . $taxonomy, 'post'); } } } }, 10, 3); }
/** * Initializes needed post type for storage */ public static function init() { register_post_type(self::STORAGE_POST_TYPE, array('labels' => array('name' => 'Lift Queue', 'singular_name' => 'Queued Docs'), 'publicly_queryable' => false, 'public' => false, 'rewrite' => false, 'has_archive' => false, 'query_var' => false, 'taxonomies' => array(), 'show_ui' => defined('LIFT_QUEUE_DEBUG'), 'can_export' => false, 'show_in_nav_menus' => false, 'show_in_menu' => defined('LIFT_QUEUE_DEBUG'), 'show_in_admin_bar' => false, 'delete_with_user' => false)); add_action('shutdown', array(__CLASS__, '_save_updates')); Lift_Post_Update_Watcher::init(); Lift_Post_Meta_Update_Watcher::init(); Lift_Taxonomy_Update_Watcher::init(); }