当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Import::get_authors_from_import方法代码示例

本文整理汇总了PHP中WP_Import::get_authors_from_import方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Import::get_authors_from_import方法的具体用法?PHP WP_Import::get_authors_from_import怎么用?PHP WP_Import::get_authors_from_import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Import的用法示例。


在下文中一共展示了WP_Import::get_authors_from_import方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:63,代码来源:import.php

示例2: do_import_posts

 protected function do_import_posts($cfg, $import_options = array('current_user' => true))
 {
     $file = $cfg['file'];
     $import_adventure_data = false;
     // $GLOBALS['wp_import'] is required for vafpress
     if (!empty($GLOBALS['wp_import'])) {
         $import = $GLOBALS['wp_import'];
     } else {
         $GLOBALS['wp_import'] = $import = new WP_Import();
     }
     // authors processing [start]
     $mapping_uid = get_current_user_id();
     if (empty($import_options['current_user'])) {
         $mapping_uid = 0;
         if (empty($import_options['another_user'])) {
             throw new Exception('Please enter username for an author.');
         } else {
             $another_username = $import_options['another_user'];
             $existing_user = get_user_by('login', $another_username);
             if ($existing_user) {
                 $mapping_uid = $existing_user->ID;
             } else {
                 $mapping_uid = wp_create_user($another_username, wp_generate_password());
                 if (is_wp_error($mapping_uid)) {
                     throw new Exception(sprintf('Can not create new user "%s": %s.', $another_username, $mapping_uid->get_error_message()));
                 }
             }
         }
     }
     $file_authors = array();
     if (isset($this->file_authors_cache[$file])) {
         $file_authors = $this->file_authors_cache[$file];
     } else {
         // retrivind author list from data file
         if (isset($_POST['imported_authors'])) {
             unset($_POST['imported_authors']);
         }
         $import_data = $import->parse($file);
         if (is_wp_error($import_data)) {
             throw new Exception(sprintf('Unexpected import error: %s.', esc_html($import_data->get_error_message())));
         }
         $import->get_authors_from_import($import_data);
         $this->file_authors_cache[$file] = $file_authors = $import->authors;
     }
     $authors_mapping = array();
     if ($file_authors) {
         foreach ($file_authors as $_login => $_details) {
             $authors_mapping[sanitize_user($_login, true)] = $mapping_uid;
         }
     }
     $import->author_mapping = $authors_mapping;
     // authors processing [end]
     $this->filter_types_only = empty($import_options['allowed_types']) ? array() : (array) $import_options['allowed_types'];
     $filter_posts_hook = array($this, 'filter_wp_import_posts');
     add_filter('wp_import_posts', $filter_posts_hook);
     if (!$this->filter_types_only || in_array('post', $this->filter_types_only)) {
         $this->allow_categories_import = true;
     }
     $filter_categories_hook = array($this, 'filter_wp_import_categories');
     add_filter('wp_import_categories', $filter_categories_hook);
     if (!$this->filter_types_only || in_array('product', $this->filter_types_only)) {
         $this->allow_product_terms = true;
         $import_adventure_data = !empty($cfg['file_adventure_addons']);
     }
     $filter_terms_hook = array($this, 'filter_wp_import_terms');
     add_filter('wp_import_terms', $filter_terms_hook);
     $filter_postmeta_key = array($this, 'filter_wp_postmeta_key');
     add_filter('import_post_meta_key', $filter_postmeta_key, 20, 3);
     ob_start();
     $import->fetch_attachments = false;
     $import->import($file);
     if ($import_adventure_data) {
         $this->do_import_adventure_data($cfg['file_adventure_addons']);
     }
     $output = ob_get_clean();
     remove_filter('wp_import_posts', $filter_posts_hook);
     remove_filter('wp_import_categories', $filter_categories_hook);
     remove_filter('wp_import_terms', $filter_terms_hook);
     remove_filter('import_post_meta_key', $filter_postmeta_key, 20);
     return $output;
 }
开发者ID:j-kenneth,项目名称:Expeero,代码行数:81,代码来源:demo-data-import.php


注:本文中的WP_Import::get_authors_from_import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。