A reddit user: willee_ asks a question [https://www.reddit.com/r/Wordpress/comments/3dared/accessing_wordpress_user_data_outside_wordpress/] How to access WordPress (user) data outside WordPress.
There were some nice suggestions and I wanted to add my take in this blog post.

An elegant solution would be to create a custom WordPress plugin that responds to a given request parameter.
The example below can used to make any data available to other apps.

For example: site.com/?my_cool_plugin[cmd]=users.load&my_cool_plugin[id]=123

Next, copy the following code into plugins/my_cool_plugin/my_cool_plugin.php.
Then activate it from WP Admin > Plugins

If you've noticed we're using an associative array 'my_cool_plugin' that will hold the command and any future parameters such as 'id' and 'cat_id' etc. The idea for that is the parameters won't conflict with other plugins' request variables.

[code]
<?php
/*
Plugin Name: My Cool Plugin
Plugin URI:  http://orbisius.com/products/
Description: Exposes some WordPress data to other apps.
Version:     1.0.0
Author:      Slavi Marinov | Orbisius
Author URI:  http://orbisius.com
Text Domain: my_cool_plugin
Domain Path: /lang
 */
add_action('init', 'my_cool_plugin_init');

function my_cool_plugin_init() {
    if ( ! isset( $_REQUEST['my_cool_plugin']['cmd'] ) ) {
       return ;
    }

    if ( $_REQUEST['my_cool_plugin']['cmd'] == 'users.load' ) {
        // do stuff.
    }
    
    exit;
}
[/code]

 

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer