예제 #1
0
    /**
     * Add the table IDs for an exported post (table) to the WP WXR export file.
     *
     * The table IDs for a table are exported in a faked post meta field.
     * As there's no action for adding extra data to the WXR export file, we hijack the `wxr_export_skip_postmeta` filter hook.
     *
     * @since 1.5.0
     *
     * @param bool     $skip     Whether to skip the current post meta. Default false.
     * @param string   $meta_key Current meta key.
     * @param stdClass $meta     Current meta object.
     */
    public function add_table_id_to_wp_export($skip, $meta_key, $meta)
    {
        // Bail if the exporter doesn't process a TablePress table right now.
        if ($this->table_options_field_name !== $meta_key) {
            return $skip;
        }
        // Find all table IDs that map to the post ID of the table that is currently being exported.
        $table_post = $this->tables->get('table_post');
        $table_ids = array_keys($table_post, (int) $meta->post_id, true);
        // Bail if no table IDs are mapped to this post ID.
        if (empty($table_ids)) {
            return $skip;
        }
        // Pretend that there is a `_tablepress_export_table_id` post meta field with the list of table IDs.
        $key = '_tablepress_export_table_id';
        $value = wxr_cdata(implode(',', $table_ids));
        // Hijack the filter and print extra XML code for our faked post meta field.
        echo <<<WXR
\t\t<wp:postmeta>
\t\t\t<wp:meta_key>{$key}</wp:meta_key>
\t\t\t<wp:meta_value>{$value}</wp:meta_value>
\t\t</wp:postmeta>

WXR;
        return $skip;
    }
예제 #2
0
 /**
  * Merge existing Plugin Options with default Plugin Options,
  * remove (no longer) existing options, e.g. after a plugin update.
  *
  * @since 1.0.0
  */
 public function merge_plugin_options_defaults()
 {
     $plugin_options = $this->plugin_options->get();
     // Remove old (i.e. no longer existing) Plugin Options.
     $plugin_options = array_intersect_key($plugin_options, $this->default_plugin_options);
     // Merge current into new Plugin Options.
     $plugin_options = array_merge($this->default_plugin_options, $plugin_options);
     $this->plugin_options->update($plugin_options);
 }
예제 #3
0
 /**
  * Invalidate all table output caches, e.g. after a plugin update
  * For TablePress pre-0.9-RC updates
  *
  * @since 0.9-RC
  */
 public function invalidate_table_output_caches_tp09()
 {
     $table_post = $this->tables->get('table_post');
     if (empty($table_post)) {
         return;
     }
     // go through all tables
     foreach ($table_post as $table_id => $post_id) {
         $caches_list_transient_name = 'tablepress_c_' . md5($table_id);
         $caches_list = get_transient($caches_list_transient_name);
         if (is_array($caches_list)) {
             foreach ($caches_list as $cache_transient_name => $dummy_value) {
                 delete_transient($cache_transient_name);
             }
         }
         delete_transient($caches_list_transient_name);
     }
 }