I want to integrate a public API to a plugin that I develop.
The usual way other plugins integrate APIs is to define some functions that can be called by any theme or plugin.
However, I think this is a bad idea since it will cause errors when my API plugin is not active and I came up with the idea of using filters and actions for the API. Much like this:
// Get some user specific data from my plugin:
$data = false;
if ( apply_filters( 'mp:is-active' ) ) {
$data = apply_filters( 'mp:get-user-data' );
}
// Add a private notification for a single user:
do_action( 'mp:send-notification', $user_id, $message );
The question is:
I have never seen this kind of API in other plugins yet, so is there a good reason not to use it (e.g. bad performance, etc)
Or do you think this is a good way to go?