The get_importers() WordPress PHP function retrieves the list of registered importers on your WordPress site.
Usage
$importers = get_importers();
Parameters
- None
More information
See WordPress Developer Resources: get_importers()
Examples
Display a list of registered importers
This example retrieves the registered importers list and displays each importer’s name and description.
$importers = get_importers(); if (!empty($importers)) { echo "<ul>"; foreach ($importers as $importer_id => $importer_data) { echo "<li><strong>{$importer_data['name']}</strong>: {$importer_data['description']}</li>"; } echo "</ul>"; } else { echo "No importers found."; }
Check if a specific importer is registered
This example checks if a specific importer, such as the ‘rss’ importer, is registered on your site.
$importers = get_importers(); if (isset($importers['rss'])) { echo "RSS importer is registered."; } else { echo "RSS importer is not registered."; }
Run an importer if it is registered
This example checks if a specific importer, like the ‘wordpress’ importer, is registered, and runs the importer’s callback function if it exists.
$importers = get_importers(); if (isset($importers['wordpress'])) { call_user_func($importers['wordpress']['callback']); } else { echo "WordPress importer is not registered."; }
Register a new importer
This example registers a new custom importer called ‘my_custom_importer’ with a name, description, and callback function.
function my_custom_importer_callback() { // Your custom importer logic here } $importers = get_importers(); if (!isset($importers['my_custom_importer'])) { register_importer('my_custom_importer', 'My Custom Importer', 'A custom importer for my website', 'my_custom_importer_callback'); }
Unregister an importer
This example unregisters an existing importer, like the ‘wordpress’ importer, by removing it from the list of importers and updating the option in the database.
$importers = get_importers(); if (isset($importers['wordpress'])) { unset($importers['wordpress']); update_option('importers', $importers); echo "WordPress importer unregistered."; } else { echo "WordPress importer is not registered."; }