コード例 #1
0
 /**
  * Migrate legacy image data.
  *
  * We used to store the full image model in the DB.
  * Now - just store the ID and fetch the data on output.
  * This is leaner and more flexible to changes.
  *
  * @subcommand migrate-legacy-image-data
  * @synopsis [--builder_id] [--post_type=<post>] [--dry_run]
  */
 public function migrate_legacy_image_data($args, $assoc_args)
 {
     $assoc_args = wp_parse_args($assoc_args, array('post_type' => 'post', 'dry_run' => false, 'builder_id' => 'ustwo-page-builder'));
     $plugin = Plugin::get_instance();
     $builder = $plugin->get_builder($assoc_args['builder_id']);
     if (!$builder) {
         return;
     }
     $query_args = array('post_type' => $assoc_args['post_type'], 'posts_per_page' => 50, 'post_status' => 'any', 'meta_key' => sprintf('%s-data', $assoc_args['builder_id']), 'meta_compare' => 'EXISTS');
     $page = 1;
     $more_posts = true;
     while ($more_posts) {
         $query_args['paged'] = $page;
         $query = new WP_Query($query_args);
         foreach ($query->posts as $post) {
             WP_CLI::line("Updating data for {$post->ID}");
             $modules = $builder->get_raw_data($post->ID);
             foreach ($modules as &$module) {
                 $module = $this->migrate_legacy_image_data_for_module($module);
             }
             $builder->save_data($post->ID, $modules);
         }
         $more_posts = $page < absint($query->max_num_pages);
         $page++;
     }
 }
コード例 #2
0
 * Version: 0.1
 * Author: Human Made Limited
 * Author URI: http://hmm.md
 * License: GPL v2 or later
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
namespace UsTwo\Page_Builder;

use WP_CLI;
define(__NAMESPACE__ . '\\PLUGIN_URL', plugins_url(null, __FILE__));
define(__NAMESPACE__ . '\\PLUGIN_DIR', __DIR__);
require __DIR__ . '/inc/class-plugin.php';
require __DIR__ . '/inc/class-builder.php';
require __DIR__ . '/inc/class-builder-post-meta.php';
add_action('init', function () {
    $plugin = Plugin::get_instance();
    $plugin->register_builder_post_meta('ustwo-page-builder', array('title' => __('Page Body Content'), 'api_prop' => 'page_builder', 'allowed_modules' => array('header', 'text', 'image', 'video', 'blockquote')));
}, 99999);
if (defined('WP_CLI') && WP_CLI) {
    require __DIR__ . '/inc/class-wp-cli.php';
    WP_CLI::add_command('ustwo-page-builder', '\\UsTwo\\Page_Builder\\CLI');
}