-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplugin.php
62 lines (54 loc) · 1.62 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
62
<?php
/**
* Plugin Name: JSON REST API Subscriptions
* Plugin URI: http://www.taylorlovett.com
* Description: Enable webhooks style subscriptions for posts, pages, and custom post types via the JSON REST API.
* Author: Taylor Lovett
* Version: 1.0
* Text Domain: json-rest-api-subscriptions
* Author URI: http://www.taylorlovett.com
*/
/**
* Register routes for content types
*
* @since 1.0
*/
function jras_register_routes() {
global $wp_rest_server;
require_once( dirname( __FILE__ ) . '/lib/endpoints/class-jras-subscriptions-controller.php' );
$namespace_post_types = jras_subscription_namespace_post_types();
foreach ( $namespace_post_types as $namespace_post_type ) {
$controller = new JRAS_Subscriptions_Controller( $namespace_post_type['namespace'], $namespace_post_type['rest_base'] );
$controller->register_routes();
}
/**
* @todo: Support comments
*/
}
add_action( 'rest_api_init', 'jras_register_routes' );
/**
* Get available subscription post types
*
* @since 1.0
* @return array
*/
function jras_subscription_namespace_post_types() {
return apply_filters( 'jras_subscription_namespace_post_types', array(
array(
'namespace' => 'wp/v2',
'rest_base' => 'posts',
'post_type' => 'post',
),
array(
'namespace' => 'wp/v2',
'rest_base' => 'pages',
'post_type' => 'page',
),
) );
}
require_once( dirname( __FILE__ ) . '/lib/class-jras-subscriptions-cpt.php' );
require_once( dirname( __FILE__ ) . '/lib/class-jras-notifier.php' );
require_once( dirname( __FILE__ ) . '/lib/class-jras-listener.php' );
JRAS_Subscription_CPT::factory();
JRAS_Notifier::factory();
JRAS_Listener::factory();