Skip to content

Commit

Permalink
UserSync now accepts a preconfigured wordpress client
Browse files Browse the repository at this point in the history
  • Loading branch information
beaucollins committed Jul 5, 2012
1 parent 6af457f commit ed305e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
15 changes: 15 additions & 0 deletions lib/wordpress-user-methods.js
@@ -0,0 +1,15 @@

module.exports = function( client ){

[ 'getUsers', 'getUser', 'newUser', 'editUser', 'deleteUser' ].forEach( function( method ){
client[method] = function(){
var args = Array.prototype.slice.call( arguments );
args.unshift( 'wp.' + method );
this.authenticatedCall.apply( this, args );
};
} );

return client;

};

27 changes: 16 additions & 11 deletions lib/wordpress-user-sync.js
Expand Up @@ -3,9 +3,6 @@ var wordpress = require('wordpress'),
url = require('url'),
queue = require('./queue');

// extend it with user management methods
require( 'wordpress/lib/wordpress-user-management' )( wordpress.Client );

module.exports = {
run : function( options, stream, callback ){
var client = new UserSync( options );
Expand Down Expand Up @@ -34,18 +31,26 @@ Arguments:
*/
var UserSync = module.exports.UserSync = function( settings ){

var settings = settings || {};
var settings = settings || {}, client;

settings.send_email = settings.send_email || true;

if( !settings.wordpress_api_url )
throw( "UserSync require the wordpress_api_url setting" );

var client = module.exports = wp = wordpress.createClient({
url: settings.wordpress_api_url,
username: settings.username,
password: settings.password
});
if ( settings.client ){
client = settings.client
} else {

if( !settings.wordpress_api_url ){ throw( "UserSync requires the wordpress_api_url setting" ); }

client = module.exports = wp = wordpress.createClient({
url: settings.wordpress_api_url,
username: settings.username,
password: settings.password
});
}

// extend it with user management methods
require( './wordpress-user-methods' )( client );

var operateOnUsers = function( jq_users, wp_users, callback ){
console.log("jQuery Users: ", wp_users.length);
Expand Down

0 comments on commit ed305e1

Please sign in to comment.