Esempio n. 1
0
 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);
 }
 /**
  * used by queue_all cron job to process the queue of all posts
  *
  * @global object $wpdb
  */
 public static function process_queue_all()
 {
     global $wpdb;
     $id_from = get_option(self::QUEUE_ALL_MARKER_OPTION);
     if (!$id_from) {
         wp_clear_scheduled_hook(self::QUEUE_ALL_CRON_HOOK);
         return;
     }
     $post_types = Lift_Search::get_indexed_post_types();
     $query = new WP_Query();
     $alter_query = function ($where, $wp_query) use($query, $id_from) {
         global $wpdb;
         if ($wp_query === $query) {
             //make sure we're not messing with any other queries
             //making sure all post_statii are used since wp_query overrides the requested statii
             $where = $wpdb->prepare(" AND {$wpdb->posts}.post_type in ('" . implode("','", $wp_query->get('post_type')) . "') " . "AND {$wpdb->posts}.ID > %d " . "AND {$wpdb->posts}.post_status <> 'auto-draft'", $id_from);
         }
         return $where;
     };
     add_filter('posts_where', $alter_query, 10, 2);
     $posts = $query->query(array('suppress_filters' => false, 'post_type' => $post_types, 'orderby' => 'ID', 'order' => 'ASC', 'post_status' => array_diff(get_post_stati(), array('auto-draft')), 'posts_per_page' => self::get_queue_all_set_size()));
     remove_filter('posts_where', $alter_query);
     if (empty($posts)) {
         wp_clear_scheduled_hook(self::QUEUE_ALL_CRON_HOOK);
         delete_option(self::QUEUE_ALL_MARKER_OPTION);
         return;
     }
     foreach ($posts as $post) {
         Lift_Post_Update_Watcher::queue_entire_post($post->ID);
     }
     $new_id_from = end($posts)->ID;
     update_option(self::QUEUE_ALL_MARKER_OPTION, $new_id_from);
 }
 /**
  * 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();
 }