本文整理汇总了PHP中WP_Import类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Import类的具体用法?PHP WP_Import怎么用?PHP WP_Import使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Import类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_demo_data
public function set_demo_data($file)
{
if (!defined('WP_LOAD_IMPORTERS')) {
define('WP_LOAD_IMPORTERS', true);
}
require_once ABSPATH . 'wp-admin/includes/import.php';
$importer_error = false;
if (!class_exists('WP_Importer')) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if (file_exists($class_wp_importer)) {
require_once $class_wp_importer;
} else {
$importer_error = true;
}
}
if (!class_exists('WP_Import')) {
$class_wp_import = dirname(__FILE__) . '/wordpress-importer.php';
if (file_exists($class_wp_import)) {
require_once $class_wp_import;
} else {
$importer_error = true;
}
}
if ($importer_error) {
die("Error on import");
} else {
if (!is_file($file)) {
echo "The XML file containing the dummy content is not available or could not be read .. You might want to try to set the file permission to chmod 755.<br/>If this doesn't work please use the Wordpress importer and import the XML file (should be located in your download .zip: Sample Content folder) manually ";
} else {
$wp_import = new WP_Import();
$wp_import->fetch_attachments = true;
$wp_import->import($file);
}
}
}
示例2: kt_importer_content_callback
function kt_importer_content_callback()
{
$this->demoid = sanitize_title($_POST['demo']);
$count = isset($_POST['count']) ? intval($_POST['count']) : 0;
if ($count) {
if (!defined('WP_LOAD_IMPORTERS')) {
define('WP_LOAD_IMPORTERS', true);
}
require_once ABSPATH . 'wp-admin/includes/import.php';
if (!class_exists('WP_Importer')) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
require_once $class_wp_importer;
}
if (!class_exists('WP_Import')) {
$class_wp_import = dirname(__FILE__) . '/includes/wordpress-importer.php';
require_once $class_wp_import;
}
$this->content_file_name = $this->kt_importer_dir . $this->demoid . '/content_' . $count . '.xml';
if (!is_file($this->content_file_name)) {
echo "The XML file containing the dummy content is not available or could not be read .. You might want to try to set the file permission to chmod 755.<br/>If this doesn't work please use the Wordpress importer and import the XML file (should be located in your download .zip: Sample Content folder) manually ";
} else {
$wp_import = new WP_Import();
$wp_import->fetch_attachments = true;
$returned_value = $wp_import->import($this->content_file_name);
if (is_wp_error($returned_value)) {
echo "An Error Occurred During Import";
}
}
} else {
//Content imported successfully
do_action('kt_importer_after_content_import', $this->demoid);
}
wp_die();
// this is required to terminate immediately and return a proper response
}
示例3: vibe_import
/**
* FILE: vibeimport.php
* Author: Mr.Vibe
* Credits: www.VibeThemes.com
* Project: WPLMS
*/
function vibe_import($file)
{
require_once ABSPATH . 'wp-admin/includes/import.php';
$file_path = apply_filters('wplms_setup_import_file_path', VIBE_PATH . "/setup/data/{$file}.xml", $file);
if (!class_exists('WP_Import')) {
require_once 'wordpress-importer.php';
}
if (class_exists('WP_Import')) {
if (file_exists($file_path)) {
do_action('wplms_before_sample_data_import', $file);
$WP_Import = new WP_Import();
if (!function_exists('wp_insert_category')) {
include ABSPATH . 'wp-admin/includes/taxonomy.php';
}
if (!function_exists('post_exists')) {
include ABSPATH . 'wp-admin/includes/post.php';
}
if (!function_exists('comment_exists')) {
include ABSPATH . 'wp-admin/includes/comment.php';
}
$WP_Import->fetch_attachments = true;
$WP_Import->allow_fetch_attachments();
$WP_Import->import($file_path);
_e('Import Complete !', 'vibe');
echo '<a href="' . admin_url('options-permalink.php') . '" target="_blank" class="button button-primary" style="margin-top:15px;">' . __('Save Permalinks', 'vibe') . '</a><br />';
echo '<a href="' . admin_url('options-general.php?page=bp-components') . '" target="_blank" class="button button-primary" style="margin-top:15px;">' . __('Save Components', 'vibe') . '</a>';
do_action('wplms_after_sample_data_import', $file);
} else {
echo __("Unable to locate Sample Data file.", 'vibe');
}
} else {
echo __("Couldn't install the test demo data as we were unable to use the WP_Import class.", "vibe");
}
}
示例4: _import_wp
/**
* Import a WXR file.
*
* The $users parameter provides information on how users specified in the import
* file should be imported. Each key is a user login name and indicates if the user
* should be mapped to an existing user, created as a new user with a particular login
* or imported with the information held in the WXR file. An example of this:
*
* <code>
* $users = array(
* 'alice' => 1, // alice will be mapped to user ID 1
* 'bob' => 'john', // bob will be transformed into john
* 'eve' => false // eve will be imported as is
* );</code>
*
* @param string $filename Full path of the file to import
* @param array $users User import settings
* @param bool $fetch_files Whether or not do download remote attachments
*/
protected function _import_wp($filename, $users = array(), $fetch_files = true)
{
$importer = new WP_Import();
$file = realpath($filename);
assert('!empty($file)');
assert('is_file($file)');
$authors = $mapping = $new = array();
$i = 0;
// each user is either mapped to a given ID, mapped to a new user
// with given login or imported using details in WXR file
foreach ($users as $user => $map) {
$authors[$i] = $user;
if (is_int($map)) {
$mapping[$i] = $map;
} else {
if (is_string($map)) {
$new[$i] = $map;
}
}
$i++;
}
$_POST = array('imported_authors' => $authors, 'user_map' => $mapping, 'user_new' => $new);
ob_start();
$importer->fetch_attachments = $fetch_files;
$importer->import($file);
ob_end_clean();
$_POST = array();
}
示例5: us_dataImport
function us_dataImport()
{
if (!defined('WP_LOAD_IMPORTERS')) {
define('WP_LOAD_IMPORTERS', true);
}
require_once get_template_directory() . '/vendor/wordpress-importer/wordpress-importer.php';
if (!is_file(get_template_directory() . '/xml/demo_data.xml')) {
echo "Automatic import failed. Please use the wordpress importer and import the XML file (Astra/xml/demo_data.xml) manually.";
} else {
$wp_import = new WP_Import();
$wp_import->fetch_attachments = true;
$wp_import->import(get_template_directory() . '/xml/demo_data.xml');
// Set menu
$locations = get_theme_mod('nav_menu_locations');
$menus = wp_get_nav_menus();
if (!empty($menus)) {
foreach ($menus as $menu) {
if (is_object($menu) && $menu->name == 'Astra Main Menu') {
$locations['astra_main_menu'] = $menu->term_id;
}
if (is_object($menu) && $menu->name == 'Astra Footer Menu') {
$locations['astra_footer_menu'] = $menu->term_id;
}
}
}
set_theme_mod('nav_menu_locations', $locations);
}
die;
}
示例6: thb_import_data
function thb_import_data()
{
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
$importerError = false;
$file = get_template_directory() . "/inc/democontent/demo-content.xml";
if (!class_exists('WP_Importer')) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if (file_exists($class_wp_importer)) {
require_once $class_wp_importer;
} else {
$importerError = true;
}
}
if ($importerError !== false) {
echo "The Auto importing script could not be loaded. Please use the wordpress importer and import the XML file that is located in your themes folder manually.";
} else {
if (class_exists('WP_Importer')) {
try {
$importer = new WP_Import();
$importer->fetch_attachments = true;
$importer->import($file);
thb_update_options();
thb_update_menus('Main Menu', 'nav-menu');
thb_import_theme_options();
// thb_update_widgets();
die('Success!');
} catch (Exception $e) {
echo "Error while importing";
}
}
}
die;
}
示例7: import_wxr
/**
* Import a WXR file
*/
private function import_wxr($file, $args)
{
$wp_import = new WP_Import();
$import_data = $wp_import->parse($file);
if (is_wp_error($import_data)) {
return $import_data;
}
// Prepare the data to be used in process_author_mapping();
$wp_import->get_authors_from_import($import_data);
$author_data = array();
foreach ($wp_import->authors as $wxr_author) {
$author = new \stdClass();
// Always in the WXR
$author->user_login = $wxr_author['author_login'];
// Should be in the WXR; no guarantees
if (isset($wxr_author['author_email'])) {
$author->user_email = $wxr_author['author_email'];
}
if (isset($wxr_author['author_display_name'])) {
$author->display_name = $wxr_author['author_display_name'];
}
if (isset($wxr_author['author_first_name'])) {
$author->first_name = $wxr_author['author_first_name'];
}
if (isset($wxr_author['author_last_name'])) {
$author->last_name = $wxr_author['author_last_name'];
}
$author_data[] = $author;
}
// Build the author mapping
$author_mapping = $this->process_author_mapping($args['authors'], $author_data);
if (is_wp_error($author_mapping)) {
return $author_mapping;
}
$author_in = wp_list_pluck($author_mapping, 'old_user_login');
$author_out = wp_list_pluck($author_mapping, 'new_user_login');
// $user_select needs to be an array of user IDs
$user_select = array();
$invalid_user_select = array();
foreach ($author_out as $author_login) {
$user = get_user_by('login', $author_login);
if ($user) {
$user_select[] = $user->ID;
} else {
$invalid_user_select[] = $author_login;
}
}
if (!empty($invalid_user_select)) {
return new WP_Error('invalid-author-mapping', sprintf("These user_logins are invalid: %s", implode(',', $invalid_user_select)));
}
// Drive the import
$wp_import->fetch_attachments = !in_array('attachment', $args['skip']);
$_GET = array('import' => 'wordpress', 'step' => 2);
$_POST = array('imported_authors' => $author_in, 'user_map' => $user_select, 'fetch_attachments' => $wp_import->fetch_attachments);
if (in_array('image_resize', $args['skip'])) {
add_filter('intermediate_image_sizes_advanced', array($this, 'filter_set_image_sizes'));
}
$wp_import->import($file);
return true;
}
示例8: cmo_import_xml
function cmo_import_xml($demo_xml_file)
{
if (function_exists('check_ajax_referer')) {
check_ajax_referer(DEMO_IMPORTER_NONCE, 'security');
}
header('Content-type: text/html; charset=utf-8');
define('WP_LOAD_IMPORTERS', true);
require_once ABSPATH . 'wp-admin/includes/import.php';
$import_error = false;
if (!class_exists('WP_Importer')) {
$wp_importer_file = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if (file_exists($wp_importer_file)) {
require_once $wp_importer_file;
} else {
$import_error = true;
}
}
if (!class_exists('WP_Import')) {
require_once 'wordpress-importer/wordpress-importer.php';
}
if ($import_error || !class_exists('WP_Import')) {
ajax_finish(false, __('Failed to load importer php files. Use WordPress Importer plugin to manually load demo content xml file.', 'cumulo'));
}
if (!is_file($demo_xml_file)) {
ajax_finish(true, "done");
}
$wp_import = new WP_Import();
$wp_import->fetch_attachments = true;
set_time_limit(0);
ob_start();
$wp_import->import($demo_xml_file);
ob_get_clean();
ajax_finish(true, "done");
}
示例9: etheme_import_data
function etheme_import_data()
{
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
$importerError = false;
$file = get_template_directory() . "/code/dummy/Dummy.xml";
//check if wp_importer, the base importer class is available, otherwise include it
if (!class_exists('WP_Importer')) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if (file_exists($class_wp_importer)) {
require_once $class_wp_importer;
} else {
$importerError = true;
}
}
if ($importerError !== false) {
echo "The Auto importing script could not be loaded. Please use the wordpress importer and import the XML file that is located in your themes folder manually.";
} else {
if (class_exists('WP_Importer')) {
try {
$importer = new WP_Import();
$importer->fetch_attachments = true;
$importer->import($file);
etheme_update_options();
etheme_update_widgets();
etheme_update_menus();
} catch (Exception $e) {
echo "Error while importing";
}
}
}
die;
}
示例10: vibe_import
/**
* FILE: vibeimport.php
* Author: Mr.Vibe
* Credits: www.VibeThemes.com
* Project: WPLMS
*/
function vibe_import($file)
{
require_once ABSPATH . 'wp-admin/includes/import.php';
$file_path = apply_filters('wplms_setup_import_file_path', VIBE_PATH . "/setup/data/{$file}.xml", $file);
if (!class_exists('WP_Import')) {
require_once 'wordpress-importer.php';
}
if (class_exists('WP_Import')) {
if (file_exists($file_path)) {
do_action('wplms_before_sample_data_import', $file);
$WP_Import = new WP_Import();
if (!function_exists('wp_insert_category')) {
include ABSPATH . 'wp-admin/includes/taxonomy.php';
}
if (!function_exists('post_exists')) {
include ABSPATH . 'wp-admin/includes/post.php';
}
if (!function_exists('comment_exists')) {
include ABSPATH . 'wp-admin/includes/comment.php';
}
$WP_Import->fetch_attachments = true;
$WP_Import->allow_fetch_attachments();
$WP_Import->import($file_path);
do_action('wplms_after_sample_data_import', $file);
_e('Import Complete !', 'vibe');
} else {
echo __("Unable to locate Sample Data file.", 'vibe');
}
} else {
echo __("Couldn't install the test demo data as we were unable to use the WP_Import class.", "vibe");
}
}
示例11: import_content
function import_content($folder = '', $file = 'content.xml.gz')
{
$import = new WP_Import();
$xml = get_template_directory() . '/library/import/files/' . $folder . '/' . $file;
$import->fetch_attachments = $_POST && key_exists('attachments', $_POST) && $_POST['attachments'] ? true : false;
ob_start();
$import->import($xml);
ob_end_clean();
}
示例12: import_content
/** ---------------------------------------------------------------------------
* Import | Content
* ---------------------------------------------------------------------------- */
function import_content($file = 'all.xml.gz')
{
$import = new WP_Import();
$xml = LIBS_DIR . '/importer/demo/' . $file;
// print_r($xml);
$import->fetch_attachments = $_POST && key_exists('attachments', $_POST) && $_POST['attachments'] ? true : false;
ob_start();
$import->import($xml);
ob_end_clean();
}
示例13: mtc_importer
function mtc_importer()
{
global $wpdb;
if (current_user_can('manage_options') && isset($_GET['import_data_content'])) {
if (!defined('WP_LOAD_IMPORTERS')) {
define('WP_LOAD_IMPORTERS', true);
}
// we are loading importers
if (!class_exists('WP_Importer')) {
// if main importer class doesn't exist
$wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
include $wp_importer;
}
if (!class_exists('WP_Import')) {
// if WP importer doesn't exist
$wp_import = get_template_directory() . '/admin/library/plugins/importer/wordpress-importer.php';
include $wp_import;
}
if (class_exists('WP_Importer') && class_exists('WP_Import')) {
// check for main import class and wp import class
$importer = new WP_Import();
$import_message = array();
/* First Import Posts, Pages, Portfolio Content, FAQ, Images, Menus */
$import_message[] = 'First Import Posts, Pages, Portfolio Content, FAQ, Images, Menus';
$theme_xml = get_template_directory() . '/admin/library/plugins/importer/data/bzine.xml.gz';
$importer->fetch_attachments = true;
ob_start();
$importer->import($theme_xml);
ob_end_clean();
/* Import Theme Options */
$import_message[] = 'Import Theme Options';
$theme_options_txt = get_template_directory_uri() . '/admin/library/plugins/importer/data/theme_options.txt';
// theme options data file
$theme_options_txt = wp_remote_get($theme_options_txt);
$data = unserialize(base64_decode($theme_options_txt['body']));
update_option(OPTIONS, $data);
// update theme options
/* Add data to widgets */
$import_message[] = 'Add data to widgets';
$widgets_json = get_template_directory_uri() . '/admin/library/plugins/importer/data/bzine_widget.json';
// widgets data file
$widgets_json = wp_remote_get($widgets_json);
$widget_data = $widgets_json['body'];
$widget_data = json_decode($widget_data, true);
update_option('sidebars_widgets', $widget_data['setting']);
foreach ($widget_data['data'] as $key => $widget) {
$dada = serialize($widget);
update_option($key, $widget);
}
// finally redirect to success page
wp_redirect(admin_url('themes.php?page=optionsframework&imported=success#of-option-generaloptions'));
}
}
}
示例14: import_xml
function import_xml()
{
$xml_file = get_template_directory() . '/framework/importer/data/sample-data.xml.gz';
if (file_exists($xml_file)) {
$importer = new WP_Import();
$importer->fetch_attachments = true;
ob_start();
$importer->import($xml_file);
ob_end_clean();
}
}
示例15: etheme_import_data
function etheme_import_data()
{
//delete_option('demo_data_installed');die();
if (!isset($_POST['version'])) {
$style = 'e-commerce';
} else {
$style = $_POST['version'];
}
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
$importerError = false;
$demo_data_installed = get_option('demo_data_installed');
switch ($style) {
case 'e-commerce':
$file = get_template_directory() . "/framework/dummy/Dummy.xml";
break;
case 'corporate':
$file = get_template_directory() . "/framework/dummy/Dummy_corpo.xml";
break;
default:
$file = get_template_directory() . "/framework/dummy/Dummy_corpo.xml";
}
//check if wp_importer, the base importer class is available, otherwise include it
if (!class_exists('WP_Importer')) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if (file_exists($class_wp_importer)) {
require_once $class_wp_importer;
} else {
$importerError = true;
}
}
if ($importerError !== false) {
echo "The Auto importing script could not be loaded. Please use the wordpress importer and import the XML file that is located in your themes folder manually.";
} else {
if (class_exists('WP_Importer')) {
try {
if ($demo_data_installed != 'yes') {
$importer = new WP_Import();
$importer->fetch_attachments = true;
$importer->import($file);
}
etheme_update_options($style);
etheme_update_menus();
die('Success!');
} catch (Exception $e) {
echo "Error while importing";
}
}
}
die;
}