Ends in
00Days
00Hours
00Mins
00Secs
Save up to 50%

PrivateContent Plugin

API Documentation

Import / Export Class

Introduction

#

Defined in classes/users_import_export.php

PHP class managing users import and export: CSV and Excel files, PrivateContent-to-PrivateContent JSON files. It extends the main pc_users class.

The class is not loaded automatically: include its file before using it. Methods work with the data submitted by the related admin forms, then they are mostly useful to replicate those operations via code. To customize standard imports and exports, use their hooks (eg. pc_csv_export_fields_to_get or pc_csv_import_new_user).

include_once(PC_DIR .'/classes/users_import_export.php');
$ie = new pvtcont_users_import_export();

This class replaces the old $pc_users->export_users() method.

csv_export()

method#

Exports users data into a CSV or Excel file. Exported fields can be managed through pc_csv_export_fields_to_get and the users query through pc_csv_export_users_query.

Usage

csv_export($fdata)

Parameters

ParameterDescription
(array) $fdataexport options - check the table below

Export options

KeyDescription
pc_csv_exp_export_typecsv or excel
pc_csv_exp_user_statusesarray of statuses to export (1, 2, 3) or array('all')
pc_csv_exp_user_catsarray of user category IDs or array('all')
pc_selective_data_exparray of field IDs to export. Empty array to export everything

Return values

TypeDescription
(array)array('status' => 'success', 'filedata' => base64 encoded file) or array('status' => 'error', 'message' => ..)

Example

include_once(PC_DIR .'/classes/users_import_export.php');
$ie = new pvtcont_users_import_export();

$result = $ie->csv_export(array(
	'pc_csv_exp_export_type' 	=> 'csv',
	'pc_csv_exp_user_statuses' 	=> array(1),
	'pc_csv_exp_user_cats' 		=> array('all'),
	'pc_selective_data_exp' 	=> array('username', 'email'),
));

if($result['status'] == 'success') {
	$csv = base64_decode($result['filedata']);
}

pvtc_export()

method#

Exports users (data, meta and categories) into a JSON file, to be imported in another website running PrivateContent. Hooks: pc_pvtc_export_users_query, pc_pvtc_export_user_meta, pc_pvtc_export_user_data_array.

Usage

pvtc_export($fdata)

Parameters

ParameterDescription
(array) $fdataexport options: pc_pvtc_exp_user_statuses, pc_pvtc_exp_user_cats and pc_selective_data_exp (same values of csv_export())

Return values

TypeDescription
(array)array('status' => 'success', 'filedata' => ..) or array('status' => 'error', 'message' => ..)

$import_report

property#

Public property filled by import methods, available also inside import hooks through the class reference they pass.

KeyDescription
new_catscreated user categories
new_usersimported users
overridden_usersexisting users updated
discarded_usersskipped users
user_errorserrors found, per user

Let's get in touch!

Features list