Esempio n. 1
0
 /**
  * Load the IDs of all tables that can be loaded from the database.
  *
  * @since 1.0.0
  *
  * @param bool $prime_meta_cache Optional. Whether the prime the post meta cache when loading the posts.
  * @param bool $run_filter       Optional. Whether to run a filter on the list of table IDs.
  * @return array Array of table IDs.
  */
 public function load_all($prime_meta_cache = true, $run_filter = true)
 {
     $table_post = $this->tables->get('table_post');
     if (empty($table_post)) {
         return array();
     }
     // Load all table posts with one query, to prime the cache.
     $this->model_post->load_posts(array_values($table_post), $prime_meta_cache);
     // This loop now uses the WP cache.
     $table_ids = array();
     foreach ($table_post as $table_id => $post_id) {
         $table_id = (string) $table_id;
         // Load table without data and options to save memory.
         $table = $this->load($table_id, false, false);
         // Skip tables that could not be loaded properly.
         if (!is_wp_error($table)) {
             $table_ids[] = $table_id;
         }
     }
     if ($run_filter) {
         /**
          * Filter all table IDs that are loaded.
          *
          * @since 1.4.0
          *
          * @param array $table_ids The table IDs that are loaded.
          */
         $table_ids = apply_filters('tablepress_load_all_tables', $table_ids);
     }
     return $table_ids;
 }
Esempio n. 2
0
 /**
  * Merge existing Table Options with default Table Options,
  * remove (no longer) existing options, after a table scheme change,
  * for all tables
  *
  * @since 1.0.0
  */
 public function merge_table_options_defaults()
 {
     $table_post = $this->tables->get('table_post');
     if (empty($table_post)) {
         return;
     }
     // load all table posts with one query, to prime the cache
     $this->model_post->load_posts(array_values($table_post), true);
     // get default Table with default Table Options
     $default_table = $this->get_table_template();
     // go through all tables (this loop now uses the WP cache)
     foreach ($table_post as $table_id => $post_id) {
         $table_options = $this->_get_table_options($post_id);
         // remove old (i.e. no longer existing) Table Options:
         $table_options = array_intersect_key($table_options, $default_table['options']);
         // merge into new Table Options:
         $table_options = array_merge($default_table['options'], $table_options);
         $this->_update_table_options($post_id, $table_options);
     }
 }