The „External files in the media library“ plugin offers a wealth of options for developers too. For example, it provides over 150 hooks that can be used to influence and extend the processes and capabilities of the plugin. It also offers REST API endpoints and supports the Ability API. The article here highlights these possibilities.
Hooks
The list of supported hooks can be viewed here at any time: https://github.com/threadi/external-files-in-media-library/blob/master/docs/hooks.md
REST API
The plugin provides a REST API endpoint that can be used to manage URLs in your own media library:
/wp-json/efml/v1/fileAuthentication with valid WordPress API access data of a user is required. The user must also have permissions to edit external URLs of the „External files in the media library“ plugin.
These endpoints have been available since version 5.0.0 of the plugin.
Add URL
Send a POST request to the above endpoint with the URL as the request parameter „url“. Optionally, „login“ and „password“ can also be specified for possible access data.
The feedback is a HTTPHTTP Hypertext Transfer Protocol-Status 200 in case of success and 400 in case of error.
Check whether URL exists in media library
Send a GET request to the above endpoint with the URL as the request parameter „url“.
The response is an HTTP status 200 if successful, 400 if no URL parameter was specified and 404 if the URL is not known.
Delete URL
Send a DELETE request to the above endpoint with the URL to be deleted as the GET parameter „url“.
The response is an HTTP status 200 if successful, 400 if no URL parameter was specified and 404 if the URL is not known.
Abilities API
WordPress„ own Abilities API enables plugins to make their capabilities known to other plugins and AIs. The “External files in the media library" plugin offers 2 points that can be used for this purpose.
This option has been available since version 5.1.0 of the plugin.
Add URL
This Ability has the following name:
'external-files-in-media-library/add'It requires the following parameters in this order:
- Attachment ID => should be 0 for a new attachment.
- URL => the URL to be added.
- Login => optional login required to access the URL
- Password => optional password required to access the URL
Example of use:
$ability = wp_get_ability( 'external-files-in-media-library/add' );
$inputs = array(
'attachment_id' => 0,
'url' => 'https://example.com/your/url/file.pdf',
);
$attachment_id = $ability->execute( $inputs );The response is the attachment ID of the created entry for the URL in the media library.
Delete URL
This Ability has the following name:
'external-files-in-media-library/delete'It only requires one parameter:
- URL => the URL to be removed from the media library.
The response is a Boolean value, where „true“ means that the URL has been successfully removed.
WP CLI
URLs in the media library can also be managed in this way. See the documentation: https://github.com/threadi/external-files-in-media-library/blob/master/docs/cli.md
Are you missing an interface?
Please contact the support forumsupport forum Forum for users of each plugin to ask questions and get help 🙂

Leave a Reply