-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
executable file
·61 lines (48 loc) · 1.71 KB
/
plugin.php
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
54
55
56
57
58
59
60
61
<?php
/*
Plugin Name: SRA JSON API
Plugin URI: http://www.fredbradley.co.uk/?utm_source=client&utm_medium=wordpress-plugin&utm_content=META&utm_campaign=wordpress-plugin
Description: A Custom built plugin that develops the SRA API
Version: 1.1
Author: Fred Bradley
Author URI: http://www.fredbradley.co.uk/?utm_source=client&utm_medium=wordpress-plugin&utm_content=META&utm_campaign=wordpress-plugin
License: GPL
Copyright: Fred Bradley
*/
class SRAAPI {
public $new_controllers = array();
function __construct() {
$this->new_controllers = array("stations", "invoices");
$this->controller_folder = plugin_dir_path(__FILE__).'/controllers';
add_filter('json_api_controllers', array($this,'add_controllers'));
add_filter('json_api_encode', array($this,'my_encode_kittens'));
// Add Controllers Paths
add_filter('json_api_stations_controller_path', array($this,'stations_controller_path'));
}
function controllers($controllers) {
add_filter('json_api_'.$controllers.'_controller_path', '');
}
function add_controllers($controllers) {
foreach ($this->new_controllers as $controller):
$controllers[] = $controller;
endforeach;
return $controllers;
}
function stations_controller_path($default_path) {
return dirname(__FILE__).'/controllers/controller.stations.php';
}
function my_encode_kittens($response) {
if (isset($response['posts'])) {
foreach ($response['posts'] as $post) {
$this->my_add_kittens($post); // Add kittens to each post
}
} else if (isset($response['post'])) {
$this->my_add_kittens($response['post']); // Add a kittens property
}
return $response;
}
function my_add_kittens(&$post) {
$post->kittens = 'Kittens!';
}
}
$myapi = new SRAAPI();