-
Notifications
You must be signed in to change notification settings - Fork 6
/
wordpress.js
53 lines (46 loc) · 1.72 KB
/
wordpress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
if(typeof WordPress === 'undefined') {
WordPress = {};
}
Accounts.oauth.registerService('wordpress');
WordPress.authServer = function() {
// Retrieve URL from ServiceConfiguration. Should be stored when client is first run.
var wpConfig = ServiceConfiguration.configurations.findOne({ service: 'wordpress' });
if(wpConfig && wpConfig.hasOwnProperty('authServerURL')) {
var serverUrl = wpConfig.authServerURL;
var schemaPos = serverUrl.indexOf('://');
// Confirm schema is https:// and insert schema if it's missing
if(schemaPos > -1) {
if(serverUrl.substring(0, schemaPos).toLowerCase() !== 'https') {
var errMsg = "Auth server isn't SSL - " + serverUrl;
if(Meteor.isClient) {
alert(errMsg);
}
throw new Error(errMsg);
}
return serverUrl;
}
return 'https://' + serverUrl;
} else {
// authServerUrl is not configured
throw new ServiceConfiguration.ConfigError();
}
};
if(Meteor.isClient) {
Meteor.loginWithWordPress = function(options, callback) {
// support a callback without options
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
var credentialRequestCompleteCallback = Accounts.oauth.credentialRequestCompleteHandler(callback);
WordPress.requestCredential(options, credentialRequestCompleteCallback);
};
} else {
Accounts.addAutopublishFields({
forLoggedInUser: [ 'services.wordpress' ],
forOtherUsers: [
'services.wordpress.id',
'services.wordpress.display_name'
]
});
}