PHP Класс WXR_Importer, WordPress-Importer

Наследование: extends WP_Importer
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$base_url
$categories information to import from WXR file
$exists
$featured_images
$logger WP_Importer_Logger Logger instance.
$mapping NEW STYLE
$menu_item_orphans
$missing_menu_items
$processed_menu_items
$processed_posts
$processed_terms TODO: REMOVE THESE
$requires_remapping
$tags
$url_remap
$user_slug_override
$version string Defaults to 1.0 for compatibility. Typically overridden by a tag at the start of the file.

Открытые методы

Метод Описание
__construct ( array $options = [] ) Constructor
bump_request_timeout ( $val ) : integer Added to http_request_timeout filter to force timeout at 60 seconds during import
cmpr_strlen ( $a, $b ) return the difference in length between two strings
get_preliminary_information ( string $file ) The main controller for the actual import stage.
import ( string $file ) The main controller for the actual import stage.
is_valid_meta_key ( string $key ) : string | boolean Decide if the given meta key maps to information we will want to import
parse_authors ( string $file ) The main controller for the actual import stage.
remap_featured_images ( ) Update _thumbnail_id meta to new, imported attachment IDs
set_logger ( $logger )
set_user_mapping ( array $mapping ) Set the user mapping.
set_user_slug_overrides ( string[] $overrides ) Set the user slug overrides.
sort_comments_by_id ( array $a, array $b ) : integer Callback for usort to sort comments by ID

Защищенные методы

Метод Описание
comment_exists ( array $data ) : integer | boolean Does the comment exist?
fetch_remote_file ( string $url, array $post ) : array | WP_Error Attempt to download a remote file attachment
get_reader ( string $file ) : XMLReader | WP_Error Get a stream reader for the file.
import_end ( ) Performs post-import cleanup of files and the cache
import_start ( string $file ) Parses the WXR file and prepares us for the task of processing parsed data
log_error ( WP_Error $error ) Log an error instance to the logger.
mark_comment_exists ( array $data, integer $comment_id ) Mark the comment as existing.
mark_post_exists ( array $data, integer $post_id ) Mark the post as existing.
mark_term_exists ( array $data, integer $term_id ) Mark the term as existing.
max_attachment_size ( ) : integer Decide what the maximum file size for downloaded attachments is.
parse_author_node ( $node )
parse_category_node ( $node )
parse_comment_node ( DOMElement $node ) : array Parse a comment node into comment data.
parse_meta_node ( DOMElement $node ) : array | null Parse a meta node into meta data.
parse_post_node ( DOMElement $node ) : array | WP_Error Parse a post node into post data.
parse_term_node ( $node, $type = 'term' )
post_exists ( array $data ) : integer | boolean Does the post exist?
post_process ( )
post_process_comments ( $todo )
post_process_menu_item ( $post_id )
post_process_posts ( $todo )
prefill_existing_comments ( ) Prefill existing comment data.
prefill_existing_posts ( ) Prefill existing post data.
prefill_existing_terms ( ) Prefill existing term data.
process_attachment ( array $post, $meta, $remote_url ) : integer | WP_Error If fetching attachments is enabled then attempt to create a new attachment
process_author ( $data, $meta )
process_comments ( array $comments, integer $post_id, array $post, $post_exists = false ) : integer | WP_Error Process and import comment data.
process_menu_item_meta ( $post_id, $data, $meta ) Attempt to create a new menu item from import data
process_post ( $data, $meta, $comments, $terms ) Create new posts based on import information
process_post_meta ( array $meta, integer $post_id, array $post ) : integer | WP_Error Process and import post meta items.
process_term ( $data, $meta )
replace_attachment_urls_in_content ( ) Use stored mapping information to update old attachment URLs
term_exists ( array $data ) : integer | boolean Does the term exist?

Описание методов

__construct() публичный Метод

Constructor
public __construct ( array $options = [] )
$options array { @var bool $prefill_existing_posts Should we prefill `post_exists` calls? (True prefills and uses more memory, false checks once per imported post and takes longer. Default is true.) @var bool $prefill_existing_comments Should we prefill `comment_exists` calls? (True prefills and uses more memory, false checks once per imported comment and takes longer. Default is true.) @var bool $prefill_existing_terms Should we prefill `term_exists` calls? (True prefills and uses more memory, false checks once per imported term and takes longer. Default is true.) @var bool $update_attachment_guids Should attachment GUIDs be updated to the new URL? (True updates the GUID, which keeps compatibility with v1, false doesn't update, and allows deduplication and reimporting. Default is false.) @var bool $fetch_attachments Fetch attachments from the remote server. (True fetches and creates attachment posts, false skips attachments. Default is false.) @var bool $aggressive_url_search Should we search/replace for URLs aggressively? (True searches all posts' content for old URLs and replaces, false checks for `` only. Default is false.) @var int $default_author User ID to use if author is missing or invalid. (Default is null, which leaves posts unassigned.) }

bump_request_timeout() публичный Метод

Added to http_request_timeout filter to force timeout at 60 seconds during import
public bump_request_timeout ( $val ) : integer
Результат integer 60

cmpr_strlen() публичный Метод

return the difference in length between two strings
public cmpr_strlen ( $a, $b )

comment_exists() защищенный Метод

Does the comment exist?
protected comment_exists ( array $data ) : integer | boolean
$data array Comment data to check against.
Результат integer | boolean Existing comment ID if it exists, false otherwise.

fetch_remote_file() защищенный Метод

Attempt to download a remote file attachment
protected fetch_remote_file ( string $url, array $post ) : array | WP_Error
$url string URL of item to fetch
$post array Attachment details
Результат array | WP_Error Local file location details on success, WP_Error otherwise

get_preliminary_information() публичный Метод

The main controller for the actual import stage.
public get_preliminary_information ( string $file )
$file string Path to the WXR file for importing

get_reader() защищенный Метод

Get a stream reader for the file.
protected get_reader ( string $file ) : XMLReader | WP_Error
$file string Path to the XML file.
Результат XMLReader | WP_Error Reader instance on success, error otherwise.

import() публичный Метод

The main controller for the actual import stage.
public import ( string $file )
$file string Path to the WXR file for importing

import_end() защищенный Метод

Performs post-import cleanup of files and the cache
protected import_end ( )

import_start() защищенный Метод

Parses the WXR file and prepares us for the task of processing parsed data
protected import_start ( string $file )
$file string Path to the WXR file for importing

is_valid_meta_key() публичный Метод

Decide if the given meta key maps to information we will want to import
public is_valid_meta_key ( string $key ) : string | boolean
$key string The meta key to check
Результат string | boolean The key if we do want to import, false if not

log_error() защищенный Метод

Log an error instance to the logger.
protected log_error ( WP_Error $error )
$error WP_Error Error instance to log.

mark_comment_exists() защищенный Метод

Mark the comment as existing.
protected mark_comment_exists ( array $data, integer $comment_id )
$data array Comment data to mark as existing.
$comment_id integer Comment ID.

mark_post_exists() защищенный Метод

Mark the post as existing.
protected mark_post_exists ( array $data, integer $post_id )
$data array Post data to mark as existing.
$post_id integer Post ID.

mark_term_exists() защищенный Метод

Mark the term as existing.
protected mark_term_exists ( array $data, integer $term_id )
$data array Term data to mark as existing.
$term_id integer Term ID.

max_attachment_size() защищенный Метод

Default is 0 (unlimited), can be filtered via import_attachment_size_limit
protected max_attachment_size ( ) : integer
Результат integer Maximum attachment file size to import

parse_author_node() защищенный Метод

protected parse_author_node ( $node )

parse_authors() публичный Метод

The main controller for the actual import stage.
public parse_authors ( string $file )
$file string Path to the WXR file for importing

parse_category_node() защищенный Метод

protected parse_category_node ( $node )

parse_comment_node() защищенный Метод

Parse a comment node into comment data.
protected parse_comment_node ( DOMElement $node ) : array
$node DOMElement Parent node of comment data (typically `wp:comment`).
Результат array Comment data array.

parse_meta_node() защищенный Метод

Parse a meta node into meta data.
protected parse_meta_node ( DOMElement $node ) : array | null
$node DOMElement Parent node of meta data (typically `wp:postmeta` or `wp:commentmeta`).
Результат array | null Meta data array on success, or null on error.

parse_post_node() защищенный Метод

Parse a post node into post data.
protected parse_post_node ( DOMElement $node ) : array | WP_Error
$node DOMElement Parent node of post data (typically `item`).
Результат array | WP_Error Post data array on success, error otherwise.

parse_term_node() защищенный Метод

protected parse_term_node ( $node, $type = 'term' )

post_exists() защищенный Метод

Does the post exist?
protected post_exists ( array $data ) : integer | boolean
$data array Post data to check against.
Результат integer | boolean Existing post ID if it exists, false otherwise.

post_process() защищенный Метод

protected post_process ( )

post_process_comments() защищенный Метод

protected post_process_comments ( $todo )

post_process_menu_item() защищенный Метод

protected post_process_menu_item ( $post_id )

post_process_posts() защищенный Метод

protected post_process_posts ( $todo )

prefill_existing_comments() защищенный Метод

Prefill existing comment data.
См. также: self::prefill_existing_posts() for justification of why this exists.

prefill_existing_posts() защищенный Метод

This preloads all GUIDs into memory, allowing us to avoid hitting the database when we need to check for existence. With larger imports, this becomes prohibitively slow to perform SELECT queries on each. By preloading all this data into memory, it's a constant-time lookup in PHP instead. However, this does use a lot more memory, so for sites doing small imports onto a large site, it may be a better tradeoff to use on-the-fly checking instead.
protected prefill_existing_posts ( )

prefill_existing_terms() защищенный Метод

Prefill existing term data.
См. также: self::prefill_existing_posts() for justification of why this exists.
protected prefill_existing_terms ( )

process_attachment() защищенный Метод

If fetching attachments is enabled then attempt to create a new attachment
protected process_attachment ( array $post, $meta, $remote_url ) : integer | WP_Error
$post array Attachment post details from WXR
Результат integer | WP_Error Post ID on success, WP_Error otherwise

process_author() защищенный Метод

protected process_author ( $data, $meta )

process_comments() защищенный Метод

Process and import comment data.
protected process_comments ( array $comments, integer $post_id, array $post, $post_exists = false ) : integer | WP_Error
$comments array List of comment data arrays.
$post_id integer Post to associate with.
$post array Post data.
Результат integer | WP_Error Number of comments imported on success, error otherwise.

process_menu_item_meta() защищенный Метод

Fails for draft, orphaned menu items and those without an associated nav_menu or an invalid nav_menu term. If the post type or term object which the menu item represents doesn't exist then the menu item will not be imported (waits until the end of the import to retry again before discarding).
protected process_menu_item_meta ( $post_id, $data, $meta )

process_post() защищенный Метод

Posts marked as having a parent which doesn't exist will become top level items. Doesn't create a new post if: the post type doesn't exist, the given post ID is already noted as imported or a post with the same title and date already exists. Note that new/updated terms, comments and meta are imported for the last of the above.
protected process_post ( $data, $meta, $comments, $terms )

process_post_meta() защищенный Метод

Process and import post meta items.
protected process_post_meta ( array $meta, integer $post_id, array $post ) : integer | WP_Error
$meta array List of meta data arrays
$post_id integer Post to associate with
$post array Post data
Результат integer | WP_Error Number of meta items imported on success, error otherwise.

process_term() защищенный Метод

protected process_term ( $data, $meta )

replace_attachment_urls_in_content() защищенный Метод

Use stored mapping information to update old attachment URLs

set_logger() публичный Метод

public set_logger ( $logger )

set_user_mapping() публичный Метод

Set the user mapping.
public set_user_mapping ( array $mapping )
$mapping array List of map arrays (containing `old_slug`, `old_id`, `new_id`)

set_user_slug_overrides() публичный Метод

Allows overriding the slug in the import with a custom/renamed version.
public set_user_slug_overrides ( string[] $overrides )
$overrides string[] Map of old slug to new slug.

sort_comments_by_id() публичный статический Метод

Callback for usort to sort comments by ID
public static sort_comments_by_id ( array $a, array $b ) : integer
$a array Comment data for the first comment
$b array Comment data for the second comment
Результат integer

term_exists() защищенный Метод

Does the term exist?
protected term_exists ( array $data ) : integer | boolean
$data array Term data to check against.
Результат integer | boolean Existing term ID if it exists, false otherwise.

Описание свойств

$base_url защищенное свойство

protected $base_url

$categories защищенное свойство

information to import from WXR file
protected $categories

$exists защищенное свойство

protected $exists

$logger защищенное свойство

Logger instance.
protected WP_Importer_Logger $logger
Результат WP_Importer_Logger

$mapping защищенное свойство

NEW STYLE
protected $mapping

$menu_item_orphans защищенное свойство

protected $menu_item_orphans

$missing_menu_items защищенное свойство

protected $missing_menu_items

$processed_menu_items защищенное свойство

protected $processed_menu_items

$processed_posts защищенное свойство

protected $processed_posts

$processed_terms защищенное свойство

TODO: REMOVE THESE
protected $processed_terms

$requires_remapping защищенное свойство

protected $requires_remapping

$tags защищенное свойство

protected $tags

$url_remap защищенное свойство

protected $url_remap

$user_slug_override защищенное свойство

protected $user_slug_override

$version защищенное свойство

Defaults to 1.0 for compatibility. Typically overridden by a tag at the start of the file.
protected string $version
Результат string