Пример #1
0
 public static function init()
 {
     //enqueue all watched meta fields if the entire post is enqueued
     add_action('lift_queue_entire_post', function ($post_id) {
         $post_type = get_post_type($post_id);
         $meta_keys = Lift_Post_Meta_Update_Watcher::get_watched_meta_keys($post_type);
         foreach ($meta_keys as $meta_key) {
             lift_queue_field_update($document_id, $meta_key, 'post');
         }
     });
     //handle meta updates
     add_action("update_post_meta", function ($meta_id, $post_id, $meta_key, $_meta_value) {
         $post_type = get_post_type($post_id);
         if (in_array($meta_key, Lift_Post_Meta_Update_Watcher::get_watched_meta_keys($post_type))) {
             lift_queue_field_update($post_id, $meta_key);
         }
     }, 10, 4);
     //handle meta adds
     add_action("add_post_meta", function ($post_id, $meta_key, $_meta_value) {
         $post_type = get_post_type($post_id);
         if (in_array($meta_key, Lift_Post_Meta_Update_Watcher::get_watched_meta_keys($post_type))) {
             lift_queue_field_update($post_id, 'post_meta_' . $meta_key, 'post');
         }
     }, 10, 3);
     add_action("delete_post_meta", function ($meta_ids, $post_id, $meta_key, $_meta_value) {
         $post_type = get_post_type($post_id);
         if (in_array($meta_key, Lift_Post_Meta_Update_Watcher::get_watched_meta_keys($post_type))) {
             lift_queue_field_update($post_id, 'post_meta_' . $meta_key, 'post');
         }
     }, 10, 4);
 }
 /**
  * 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();
 }