Skip to content
Docs
Get RestroPress

Function

Menu importer functions

Updated
On this page

Functions for the Switch to RestroPress importer (GloriaFood, WooCommerce-based plugins and CSV), including preview and undo.

7 functions. Each entry shows the signature, parameters, return value and where it is defined. Functions marked internal are hook callbacks, screen renderers and other plumbing that extensions normally do not call.

rpress_register_import_source()#

Registers a source for the Switch to RestroPress menu importer.

The id is passed through sanitize_key(); registration fails without a callable parse argument. Other args: label, description, accepts (allowed file extensions; empty means no upload, the source reads this site), available, detect, field_map, help and priority (default 50). Call it from the rpress_register_import_sources action.

rpress_register_import_source( $id, $args )

Parameters

ParameterTypeDefaultDescription
$idstringRequiredUnique source ID.
$argsarrayRequiredSource arguments. parse is required: a callable taking the file array (or null) and returning a model array or WP_Error.

Returns bool: True when registered, false when the id is empty or parse is missing or not callable.

Example

add_action( 'rpress_register_import_sources', function () {
	rpress_register_import_source( 'my-pos', array(
		'label'       => 'My POS',
		'description' => 'Menu export from My POS (.json).',
		'accepts'     => array( 'json' ),
		'parse'       => function ( $file ) {
			return array( 'categories' => array() );
		},
	) );
} );

Note: Registering the same id again replaces the earlier source.

Defined in includes/features/importer/loader.php, line 66.

rpress_unregister_import_source()#

Removes a registered import source.

rpress_unregister_import_source( $id )

Parameters

ParameterTypeDefaultDescription
$idstringRequiredSource ID.

Example

add_action( 'rpress_register_import_sources', function () {
	rpress_unregister_import_source( 'woocommerce' );
}, 20 );

Defined in includes/features/importer/loader.php, line 98.

rpress_get_import_sources()#

Returns all registered import sources sorted by priority.

On the first call after init it fires rpress_register_import_sources so sources can register. Filter the result with rpress_import_sources.

rpress_get_import_sources()

Returns array: Source argument arrays keyed by source ID.

Defined in includes/features/importer/loader.php, line 109.

rpress_import_source_available()#

Checks whether an import source can be used right now.

Uses the source's available callback; a source without one is always available.

rpress_import_source_available( $source )

Parameters

ParameterTypeDefaultDescription
$sourcearrayRequiredSource args as returned by rpress_get_import_sources().

Returns bool: True when usable.

Defined in includes/features/importer/loader.php, line 137.

rpress_importer_url()#

Returns the admin URL of the Switch to RestroPress screen.

Optionally preselects a source. Filter with rpress_importer_url.

rpress_importer_url( $source = '' )

Parameters

ParameterTypeDefaultDescription
$sourcestring''Source ID to preselect.

Returns string: Admin URL.

Example

$url = rpress_importer_url( 'gloriafood' );

Defined in includes/features/importer/loader.php, line 148.

rpress_importer_max_upload_size()#

Returns the maximum import file size in bytes.

The smaller of the WordPress upload limit and 10 MB; the second figure is filterable with rpress_importer_max_upload_size.

rpress_importer_max_upload_size()

Returns int: Size in bytes.

Defined in includes/features/importer/loader.php, line 165.

rpress_importer_register_core_sources()#

Registers the GloriaFood, WooCommerce and CSV import sources that ship with core.

Hooked to rpress_register_import_sources at priority 5.

rpress_importer_register_core_sources()

Internal. Defined in includes/features/importer/loader.php, line 177.

Was this page helpful?