PHP Class WP_Import

Inheritance: extends WP_Importer
Mostra file Open project: lucatume/wp-browser Class Usage Examples

Public Properties

Property Type Description
$author_mapping
$authors
$base_url
$categories
$featured_images
$fetch_attachments
$id max. supported WXR version
$max_wxr_version
$menu_item_orphans
$missing_menu_items
$post_orphans
$posts
$processed_authors mappings from old information to new
$processed_menu_items
$processed_posts
$processed_terms
$tags
$terms
$url_remap
$version information to import from WXR file

Public Methods

Method Description
WP_Import ( )
allow_create_users ( ) : boolean Decide whether or not the importer is allowed to create users.
allow_fetch_attachments ( ) : boolean Decide whether or not the importer should attempt to download attachment files.
author_select ( integer $n, array $author ) Display import options for an individual author. That is, either create a new user based on import info or map to an existing user
backfill_attachment_urls ( ) Use stored mapping information to update old attachment URLs
backfill_parents ( ) Attempt to associate posts and menu items with previously missing parents
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
dispatch ( ) Registered callback function for the WordPress Importer
fetch_remote_file ( string $url, array $post ) : array | WP_Error Attempt to download a remote file attachment
footer ( ) Close div.wrap
get_author_mapping ( ) Map old author logins to local user IDs based on decisions made in import options form. Can map to an existing user, create a new user or falls back to the current user in case of error with either of the previous
get_authors_from_import ( array $import_data ) Retrieve authors from parsed WXR data
greet ( ) Display introductory text and file upload form
handle_upload ( ) : boolean Handles the WXR upload and initial parsing of the file to prepare for displaying author import options
header ( ) Display import page title
import ( string $file ) The main controller for the actual import stage.
import_end ( ) Performs post-import cleanup of files and the cache
import_options ( ) Display pre-import options, author importing/mapping and option to fetch attachments
import_start ( string $file ) Parses the WXR file and prepares us for the task of processing parsed data
is_valid_meta_key ( string $key ) : string | boolean Decide if the given meta key maps to information we will want to import
max_attachment_size ( ) : integer Decide what the maximum file size for downloaded attachments is.
parse ( string $file ) : array Parse a WXR file
process_attachment ( array $post, string $url ) : integer | WP_Error If fetching attachments is enabled then attempt to create a new attachment
process_categories ( ) Create new categories based on import information
process_menu_item ( array $item ) Attempt to create a new menu item from import data
process_posts ( ) Create new posts based on import information
process_tags ( ) Create new post tags based on import information
process_terms ( ) Create new terms based on import information
remap_featured_images ( ) Update _thumbnail_id meta to new, imported attachment IDs

Method Details

WP_Import() public method

public WP_Import ( )

allow_create_users() public method

Default is true, can be filtered via import_allow_create_users
public allow_create_users ( ) : boolean
return boolean True if creating users is allowed

allow_fetch_attachments() public method

Default is true, can be filtered via import_allow_fetch_attachments. The choice made at the import options screen must also be true, false here hides that checkbox.
public allow_fetch_attachments ( ) : boolean
return boolean True if downloading attachments is allowed

author_select() public method

Display import options for an individual author. That is, either create a new user based on import info or map to an existing user
public author_select ( integer $n, array $author )
$n integer Index for each author in the form
$author array Author information, e.g. login, display name, email

backfill_attachment_urls() public method

Use stored mapping information to update old attachment URLs

backfill_parents() public method

An imported post's parent may not have been imported when it was first created so try again. Similarly for child menu items and menu items which were missing the object (e.g. post) they represent in the menu
public backfill_parents ( )

bump_request_timeout() public method

Added to http_request_timeout filter to force timeout at 60 seconds during import
public bump_request_timeout ( $val ) : integer
return integer 60

cmpr_strlen() public method

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

dispatch() public method

Manages the three separate stages of the WXR import process
public dispatch ( )

fetch_remote_file() public method

Attempt to download a remote file attachment
public fetch_remote_file ( string $url, array $post ) : array | WP_Error
$url string URL of item to fetch
$post array Attachment details
return array | WP_Error Local file location details on success, WP_Error otherwise

get_author_mapping() public method

Map old author logins to local user IDs based on decisions made in import options form. Can map to an existing user, create a new user or falls back to the current user in case of error with either of the previous
public get_author_mapping ( )

get_authors_from_import() public method

Uses the provided author information from WXR 1.1 files or extracts info from each post for WXR 1.0 files
public get_authors_from_import ( array $import_data )
$import_data array Data returned by a WXR parser

greet() public method

Display introductory text and file upload form
public greet ( )

handle_upload() public method

Handles the WXR upload and initial parsing of the file to prepare for displaying author import options
public handle_upload ( ) : boolean
return boolean False if error uploading or invalid file, true otherwise

header() public method

Display import page title
public header ( )

import() public method

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

import_end() public method

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

import_options() public method

Display pre-import options, author importing/mapping and option to fetch attachments
public import_options ( )

import_start() public method

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

is_valid_meta_key() public method

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
return string | boolean The key if we do want to import, false if not

max_attachment_size() public method

Default is 0 (unlimited), can be filtered via import_attachment_size_limit
public max_attachment_size ( ) : integer
return integer Maximum attachment file size to import

parse() public method

Parse a WXR file
public parse ( string $file ) : array
$file string Path to WXR file for parsing
return array Information gathered from the WXR file

process_attachment() public method

If fetching attachments is enabled then attempt to create a new attachment
public process_attachment ( array $post, string $url ) : integer | WP_Error
$post array Attachment post details from WXR
$url string URL to fetch attachment from
return integer | WP_Error Post ID on success, WP_Error otherwise

process_categories() public method

Doesn't create a new category if its slug already exists
public process_categories ( )

process_menu_item() public method

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).
public process_menu_item ( array $item )
$item array Menu item details from WXR file

process_posts() public method

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.
public process_posts ( )

process_tags() public method

Doesn't create a tag if its slug already exists
public process_tags ( )

process_terms() public method

Doesn't create a term its slug already exists
public process_terms ( )

Property Details

$author_mapping public_oe property

public $author_mapping

$authors public_oe property

public $authors

$base_url public_oe property

public $base_url

$categories public_oe property

public $categories

$fetch_attachments public_oe property

public $fetch_attachments

$id public_oe property

max. supported WXR version
public $id

$max_wxr_version public_oe property

public $max_wxr_version

$menu_item_orphans public_oe property

public $menu_item_orphans

$missing_menu_items public_oe property

public $missing_menu_items

$post_orphans public_oe property

public $post_orphans

$posts public_oe property

public $posts

$processed_authors public_oe property

mappings from old information to new
public $processed_authors

$processed_menu_items public_oe property

public $processed_menu_items

$processed_posts public_oe property

public $processed_posts

$processed_terms public_oe property

public $processed_terms

$tags public_oe property

public $tags

$terms public_oe property

public $terms

$url_remap public_oe property

public $url_remap

$version public_oe property

information to import from WXR file
public $version