Inheritances
Files
Overview
FRAMES
NO FRAMES

Class ImportPostWp

ImportPostWp
|- class ImportPostWp
Defined in line 38 of file ImportPostWp.class.php.
ImportPostWp
This class allows to import bulk posts into Wordpress from array
AuthorMario Spada
CopyrightCopyright (c) 2015 Mario Spada
Licensehttp://opensource.org/licenses/GPL-2.0 GNU Public License
PackageImportPostWp
Version0.1.0 2015/06/28

Summary

Instance fields
+ $debug Switch on debug
# $default_post_values Array containing the default field values
# $fields_list Array containing the list of the fields to insert
# $insert_errors Array containing each row number of the failed insert
# $nPosts The number of rows of data array
# $posts Array containing data
# $time_elapsed Total elapsed time in seconds
+ $time_zone Timezone as defined in http://php.net/manual/en/timezones.php
+ $wp_path Path of Wordpress root directory
Instance methods
+ __construct()
+ delete_posts() Delete all post of a specific category
+ get_data() Return data array
+ get_default_post_values() Return default values for the optional field list
+ get_elapsed_time() Get elapsed time
+ get_field_list() Return the field name list
+ get_insert_errors() Return an array of the not inserted rows
+ insert_posts() Insert all posts in Wordpress DB
# prepare_categories() Loop through data and search ID categories on WP database.
+ raw_insert_posts() Insert all posts in Wordpress DB
+ reset_time() reset elapsed time
+ set_default_comment_status() Set default values for the field 'comment_status'
+ set_default_ping_status() Set default values for the field 'ping_status'
+ set_default_post_author() Set default values for the field 'post_author'
+ set_default_post_status() Set default values for the field 'post_status'
+ set_default_post_type() Set default values for the field 'post_type'

Details

Instance fields

$debug
public $debug = false
Switch on debug
Var boolean
$default_post_values
protected $default_post_values = array('post_status' => 'publish', 'post_type'=> 'post', 'ping_status'=> 'closed', 'comment_status'=> 'closed', 'post_author'=> 1 )
Array containing the default field values
Var array
$fields_list
protected $fields_list = array('post_title','post_content','post_name', 'post_status','post_type','guid','post_excerpt', 'post_date','post_date_gmt','ping_status', 'comment_status','post_author','categories')
Array containing the list of the fields to insert
Var array
$insert_errors
protected $insert_errors = array()
Array containing each row number of the failed insert
Var array
$nPosts
protected $nPosts = 0
The number of rows of data array
Var int
$posts
protected $posts = array()
Array containing data
Var array
$time_elapsed
protected $time_elapsed = 0
Total elapsed time in seconds
Var int
$time_zone
public $time_zone = "Europe/Rome"
Timezone as defined in http://php.net/manual/en/timezones.php
Var string
$wp_path
public $wp_path = "."
Path of Wordpress root directory
Var string

Instance methods

__construct()
function __construct( $data
$wpPath = "."
)
Parameters
array $data data array
string $wpPath The path to Wordpress directory
delete_posts()
public function delete_posts( $cat)
Delete all post of a specific category. It cleans also all
relationship records.
Accept both category name or category ID
The number of affected record will twice the number of affected posts
Parameters
int|string $cat
Returns int number of affected records
get_data()
public function get_data( $print = false)
Return data array
If $print is true, prints out data array
Parameters
bool $print
Returns array
get_default_post_values()
public function get_default_post_values( $print = false)
Return default values for the optional field list
If $print is true, prints out array
Parameters
bool $print
Returns array
get_elapsed_time()
public function get_elapsed_time( )
Get elapsed time
get_field_list()
public function get_field_list( $print = false)
Return the field name list
If $print is true, prints out array
Parameters
bool $print
Returns array
get_insert_errors()
public function get_insert_errors( $print = false)
Return an array of the not inserted rows
If $print is true, prints out array
Parameters
bool $print
Returns array
insert_posts()
public function insert_posts( )
Insert all posts in Wordpress DB.
It uses native WP function: wp_insert_post
It is slow, but it performs a lot of security control before inserting
Returns int number of successfully inserted records
prepare_categories()
protected function prepare_categories( )
Loop through data and search ID categories on WP database.
If the category doesn't exist, it will be created.
Substitute all category string with IDs in the data array.
If empty category is provided, the value will be the ID of the default category
raw_insert_posts()
public function raw_insert_posts( )
Insert all posts in Wordpress DB.
It uses raw SQL queries
It is much faster than insert_posts, but it doesn't perform
security control before inserting
Returns int number of successfully inserted records
reset_time()
public function reset_time( )
reset elapsed time
set_default_comment_status()
public function set_default_comment_status( $val)
Set default values for the field 'comment_status'
Possible values: [ 'closed' | 'open' ]
default = 'closed'
Parameters
string $val
set_default_ping_status()
public function set_default_ping_status( $val)
Set default values for the field 'ping_status'
Possible values: [ 'closed' | 'open' ]
default = 'closed'
Parameters
string $val
set_default_post_author()
public function set_default_post_author( $val)
Set default values for the field 'post_author'
Possible values: [ ] // The user ID number of the author.
default = 1
Parameters
string $val
set_default_post_status()
public function set_default_post_status( $val)
Set default values for the field 'post_status'
Possible values: [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ]
default = 'publish'
Parameters
string $val
set_default_post_type()
public function set_default_post_type( $val)
Set default values for the field 'post_type'
Possible values: [ 'post' | 'page' | 'link' | 'nav_menu_item' | custom post type ]
default = 'post'
Parameters
string $val