Category: WordPress Plugin Development

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]

 

Join our mailing list

Get important news about cool products we release and invitations to beta test new products

Find out the Social networks we're on

Black and Cyber Monday Deal: Use BF24 code at checkout for 40% off