https://github.com/PressForward/pressforward
Tip revision: f5a553d2ad3be379f0270967e8610ba3be940f47 authored by Aram Zucker-Scharff on 25 February 2017, 06:13:05 UTC
Merge pull request #886 from mAAdhaTTah/issue/delay-init
Merge pull request #886 from mAAdhaTTah/issue/delay-init
Tip revision: f5a553d
PF_REST_Controller.php
<?php
// Test with ngrok: ./ngrok http –host-header=rewrite local.wordpress.dev:80
class PF_REST_Controller extends WP_REST_Controller {
/**
* Register the routes for the objects of the controller.
*/
public function register_routes() {
$version = '1';
$namespace = 'pf/v' . $version;
$base = 'status';
register_rest_route( $namespace, '/' . $base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_pf_status' ),
'priority' => 10,
),
));
}
public function get_pf_status() {
$pf = pressforward( 'modules' );
$active_modules = array();
foreach ( $pf->modules as $module_id => $module ) {
$enabled = get_option( PF_SLUG . '_' . $module_id . '_enable' );
if ( ! in_array( $enabled, array( 'yes', 'no' ) ) ) {
$enabled = 'yes';
}
if ( 'yes' == $enabled ) {
$active_modules[] = $module_id;
}
}
$data = array(
'status' => 'PressForward running.',
'version' => PF_VERSION,
'active_modules' => $active_modules,
);
return new WP_REST_Response( $data, 200 );
}
}
function activate_pf_rest_controller() {
$controller = new PF_REST_Controller;
$controller->register_routes();
}
add_action( 'rest_api_init', 'activate_pf_rest_controller', 11 );