示例#1
0
 /**
  * Remove the `_tablepress_export_table_id` post meta field from the fields that are imported during a WP WXR import.
  *
  * @since 1.5.0
  *
  * @param array $postmeta Post meta fields for the post.
  * @param int   $post_id  Post ID.
  * @param array $post     Post.
  * @return array Modified post meta fields.
  */
 public function prevent_table_id_post_meta_import_on_wp_import(array $postmeta, $post_id, array $post)
 {
     // Bail if the post is not a TablePress table.
     if ($this->model_post->get_post_type() !== $post['post_type']) {
         return $postmeta;
     }
     // Remove the `_tablepress_export_table_id` post meta field from the post meta fields.
     foreach ($postmeta as $index => $meta) {
         if ('_tablepress_export_table_id' === $meta['key']) {
             unset($postmeta[$index]);
         }
     }
     return $postmeta;
 }
示例#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);
     }
 }