| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | Plugin Name: JSON API Auth |
| 6 | 6 | Plugin URI: http://www.parorrey.com/solutions/json-api-auth/ |
| 7 | 7 | Description: Extends the JSON API Plugin for RESTful user authentiocation |
| 8 | - Version: 1.4 | |
| 8 | + Version: 1.7 | |
| 9 | 9 | Author: Ali Qureshi |
| 10 | 10 | Author URI: http://www.parorrey.com |
| 11 | 11 | License: GPLv3 |
| 12 | 12 | |
| @@ -27,8 +27,10 @@ | ||
| 27 | 27 | add_filter('json_api_controllers', 'pimAuthJsonApiController'); |
| 28 | 28 | |
| 29 | 29 | add_filter('json_api_auth_controller_path', 'setAuthControllerPath'); |
| 30 | 30 | |
| 31 | +add_action('init', 'json_api_auth_checkAuthCookie', 100); | |
| 32 | + | |
| 31 | 33 | load_plugin_textdomain('json-api-auth', false, basename(dirname(__FILE__)) . '/languages'); |
| 32 | 34 | |
| 33 | 35 | function pim_auth_draw_notice_json_api() { |
| 34 | 36 | |
| @@ -33,9 +35,9 @@ | ||
| 33 | 35 | function pim_auth_draw_notice_json_api() { |
| 34 | 36 | |
| 35 | 37 | echo '<div id="message" class="error fade"><p style="line-height: 150%">'; |
| 36 | 38 | |
| 37 | - _e('<strong>JSON API Auth</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'); | |
| 39 | + _e('<strong>JSON API Auth</strong></a> requires the JSON API plugin to be activated. Please <a href="https://wordpress.org/plugins/json-api/">install / activate JSON API</a> first.', 'json-api-user'); | |
| 38 | 40 | |
| 39 | 41 | echo '</p></div>'; |
| 40 | 42 | |
| 41 | 43 | } |
| @@ -52,5 +54,18 @@ | ||
| 52 | 54 | function setAuthControllerPath($sDefaultPath) { |
| 53 | 55 | |
| 54 | 56 | return dirname(__FILE__) . '/controllers/Auth.php'; |
| 55 | 57 | |
| 58 | +} | |
| 59 | + | |
| 60 | +function json_api_auth_checkAuthCookie($sDefaultPath) { | |
| 61 | + global $json_api; | |
| 62 | + | |
| 63 | + if ($json_api->query->cookie) { | |
| 64 | + $user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in'); | |
| 65 | + if ($user_id) { | |
| 66 | + $user = get_userdata($user_id); | |
| 67 | + | |
| 68 | + wp_set_current_user($user->ID, $user->user_login); | |
| 69 | + } | |
| 70 | + } | |
| 56 | 71 | } |