2

I'd like to create a dashboard of sorts of plugins I'm using on multiple sites. I'm able to use get_plugins() to gather the information I want within each site, but how can I make that data accessible from the outside? Is this possible? What would be the best way to go about it?

1 Answer 1

1

Before anything else:

Be really sure that your endpoint to retrieve this information is reasonably secure. (e.g. using SSL and some authentication like a password) Leaking the information which plugins are installed on a site might offer a point of attack for hackers.


I am not going to offer you a ready-made solution but outline two different approaches how to tackle this: Push and Pull. Push means that your sites report their plugins to the dashboard, while pull means your dashboards actively gets this information from your sites.

Also I am only going to show you the WP side of things. How you handle stuff for your dashboard is a completely separate issue and also probably not a good fit for this site.

So here we go:

Push

By using a WP-Cron you can schedule a site to do something in regular intervals. In our case we could for example schedule a task that gets the list of installed plugins and reports them to your dashboard (code hugely simplified):

// Add the action that does the actual reporting
add_action( 'hourly_report', 'report_plugins' );

// Schedule this action hourly
wp_schedule_event( time(), 'hourly', 'hourly_report' );

// This function does the actual work
function report_plugins(){

    //Get plugin data
    $plugins = get_plugins();

    //create the data you want to send using $plugins
    $args = ...

    // Post the data to your dashboard
    wp_remote_post( $dashboard_url, $args );
}

Pull

Another option is to create an AJAX endpoint to actively get the plugin-data from a site. This would roughly go along those lines (again code hugely simplified):

// Add the AJAX handler
add_action( 'wp_ajax_nopriv_plugin_data', 'return_plugin_data' );

function return_plugin_data(){
     //Again I want to emphasize that you need to ensure the user has the right to access this data.

     //Get plugin data
     $plugins = get_plugins();

     //Encode and return the plugin data
     echo json_encode($plugins);
     die();
}

I hope this helps to get you started, let me know if anything is unclear conceptionally.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.