| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
|
| 5 |
Plugin Name: JSON API User |
| 6 |
|
| 7 |
Plugin URI: http://www.parorrey.com/solutions/json-api-user/ |
| 8 |
|
| 9 |
Description: Extends the JSON API for RESTful user registration, authentication, password reset, Facebook Login, user meta and BuddyPress Profile related functions. A Pro version is also available. |
| 10 |
|
| 11 |
Version: 3.0.0 |
| 12 |
|
| 13 |
Author: Ali Qureshi |
| 14 |
|
| 15 |
Author URI: http://www.parorrey.com/ |
| 16 |
|
| 17 |
License: GPLv3 |
| 18 |
|
| 19 |
*/ |
| 20 |
|
| 21 |
define('JAU_VERSION', '3.0.0'); |
| 22 |
|
| 23 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 24 |
|
| 25 |
define('JSON_API_USER_HOME', dirname(__FILE__)); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
if (!is_plugin_active('json-api/json-api.php')) { |
| 30 |
|
| 31 |
add_action('admin_notices', 'pim_draw_notice_json_api'); |
| 32 |
|
| 33 |
return; |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
add_filter('json_api_controllers', 'pimJsonApiController'); |
| 40 |
|
| 41 |
add_filter('json_api_user_controller_path', 'setUserControllerPath'); |
| 42 |
|
| 43 |
add_action('init', 'json_api_user_checkAuthCookie', 100); |
| 44 |
|
| 45 |
load_plugin_textdomain('json-api-user', false, basename(dirname(__FILE__)) . '/languages'); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
function pim_draw_notice_json_api() { |
| 50 |
|
| 51 |
echo '<div id="message" class="error fade"><p style="line-height: 150%">'; |
| 52 |
|
| 53 |
_e('<strong>JSON API User</strong></a> requires the JSON API plugin to be activated. Please <a href="wordpress.org/plugins/json-api/">install / activate JSON API</a> first.', 'json-api-user'); |
| 54 |
|
| 55 |
echo '</p></div>'; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
function pimJsonApiController($aControllers) { |
| 62 |
|
| 63 |
$aControllers[] = 'User'; |
| 64 |
|
| 65 |
return $aControllers; |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
function setUserControllerPath($sDefaultPath) { |
| 72 |
|
| 73 |
return dirname(__FILE__) . '/controllers/User.php'; |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
function json_api_user_checkAuthCookie($sDefaultPath) { |
| 78 |
global $json_api; |
| 79 |
|
| 80 |
if ($json_api->query->cookie) { |
| 81 |
$user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in'); |
| 82 |
if ($user_id) { |
| 83 |
$user = get_userdata($user_id); |
| 84 |
|
| 85 |
wp_set_current_user($user->ID, $user->user_login); |
| 86 |
} |
| 87 |
} |
| 88 |
} |