| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
|
| 5 |
Plugin Name: JSON API Auth |
| 6 |
Plugin URI: http://www.parorrey.com/solutions/json-api-auth/ |
| 7 |
Description: Extends the JSON API Plugin for RESTful user authentiocation |
| 8 |
Version: 2.7.1 |
| 9 |
Author: Ali Qureshi |
| 10 |
Author URI: http://www.parorrey.com |
| 11 |
License: GPLv3 |
| 12 |
|
| 13 |
*/ |
| 14 |
|
| 15 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 16 |
|
| 17 |
define('JSON_API_AUTH_HOME', dirname(__FILE__)); |
| 18 |
|
| 19 |
function auth_action_links( $links ) { |
| 20 |
|
| 21 |
$links[] = '<a href="'. esc_url( get_admin_url(null, '/options-general.php?page=json-api') ) .'">JSON API</a>'; |
| 22 |
|
| 23 |
$links[] = '<a href="https://www.parorrey.com/solutions/json-api-user-plus/" target="_blank">' . __( 'Upgrade to User Plus', 'json-api-auth' ) . '</a>'; |
| 24 |
|
| 25 |
return $links; |
| 26 |
} |
| 27 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'auth_action_links', 10, 1 ); |
| 28 |
|
| 29 |
|
| 30 |
if (!(is_plugin_active('json-api/json-api.php') || is_plugin_active('json-api-master/json-api.php')) ) { |
| 31 |
|
| 32 |
add_action('admin_notices', 'pim_auth_draw_notice_json_api'); |
| 33 |
|
| 34 |
return; |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
add_filter('json_api_controllers', 'pimAuthJsonApiController'); |
| 39 |
|
| 40 |
add_filter('json_api_auth_controller_path', 'setAuthControllerPath'); |
| 41 |
|
| 42 |
add_action('init', 'json_api_auth_checkAuthCookie', 100); |
| 43 |
|
| 44 |
load_plugin_textdomain('json-api-auth', false, basename(dirname(__FILE__)) . '/languages'); |
| 45 |
|
| 46 |
function pim_auth_draw_notice_json_api() { |
| 47 |
|
| 48 |
echo '<div id="message" class="error fade"><p style="line-height: 150%">'; |
| 49 |
|
| 50 |
_e('<strong>JSON API Auth</strong></a> requires the JSON API plugin to be activated. Please <a href="https://github.com/PI-Media/json-api">install / activate JSON API</a> first from <a href="https://github.com/PI-Media/json-api" target="_blank">GitHub repository here</a>. <br>You can also upgrade to a pro verison <a href="http://www.parorrey.com/solutions/json-api-user-plus/" target="_blank">JSON API User Plus</a> for JSON API Auth.', 'json-api-auth'); |
| 51 |
|
| 52 |
echo '</p></div>'; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
function pimAuthJsonApiController($aControllers) { |
| 58 |
|
| 59 |
$aControllers[] = 'Auth'; |
| 60 |
return $aControllers; |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
function setAuthControllerPath($sDefaultPath) { |
| 66 |
|
| 67 |
return dirname(__FILE__) . '/controllers/Auth.php'; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
function json_api_auth_checkAuthCookie($sDefaultPath) { |
| 72 |
global $json_api; |
| 73 |
|
| 74 |
if ($json_api->query->cookie) { |
| 75 |
$user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in'); |
| 76 |
if ($user_id) { |
| 77 |
$user = get_userdata($user_id); |
| 78 |
|
| 79 |
wp_set_current_user($user->ID, $user->user_login); |
| 80 |
} |
| 81 |
} |
| 82 |
} |