# json-api-auth/trunk/json-api-auth.php

JSON API Auth, version trunk. 91 lines.

- Page: https://pluginprobe.com/plugins/json-api-auth/trunk/code/json-api-auth.php
- Raw: https://pluginprobe.com/plugins/json-api-auth/trunk/raw/json-api-auth.php
- Modified: 2026-09-07T22:12:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/json-api-auth/trunk/code/json-api-auth.php#L10-L20`.

```php
<?php

/*

  Plugin Name: JSON API Auth  
  Plugin URI: http://www.parorrey.com/solutions/json-api-auth/
  Description: Extends the JSON API Plugin for RESTful user authentication
  Version: 3.1.2
  Requires at least: 3.0.1
  Requires PHP: 7.4
  Tested up to: 7.1
  Author: Ali Qureshi
  Author URI: http://www.parorrey.com
  License: GPLv3
  
 */

include_once(ABSPATH . 'wp-admin/includes/plugin.php');

define('JSON_API_AUTH_HOME', dirname(__FILE__));

function auth_action_links($links)
{

  $links[] = '<a href="' . esc_url(get_admin_url(null, '/options-general.php?page=json-api')) . '">JSON API</a>';

  $links[] = '<a href="https://www.parorrey.com/solutions/json-api-user-plus/" target="_blank">' . __('Upgrade to User Plus', 'json-api-auth') . '</a>';

  return $links;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'auth_action_links', 10, 1);


if (!(is_plugin_active('json-api/json-api.php') || is_plugin_active('json-api-master/json-api.php'))) {

  add_action('admin_notices', 'pim_auth_draw_notice_json_api');

  return;

}

add_filter('json_api_controllers', 'pimAuthJsonApiController');

add_filter('json_api_auth_controller_path', 'setAuthControllerPath');

add_action('init', 'json_api_auth_checkAuthCookie', 100);

load_plugin_textdomain('json-api-auth', false, basename(dirname(__FILE__)) . '/languages');

function pim_auth_draw_notice_json_api()
{

  echo '<div id="message" class="error fade"><p style="line-height: 150%">';

  _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');

  echo '</p></div>';

}


function pimAuthJsonApiController($aControllers)
{

  $aControllers[] = 'Auth';
  return $aControllers;

}


function setAuthControllerPath($sDefaultPath)
{

  return dirname(__FILE__) . '/controllers/Auth.php';

}

function json_api_auth_checkAuthCookie($sDefaultPath)
{
  global $json_api;

  if ( isset( $json_api->query->cookie ) && $json_api->query->cookie ) {
    $user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');
    if ($user_id) {
      $user = get_userdata($user_id);

      wp_set_current_user($user->ID, $user->user_login);
    }
  }
}

```
