Skip to content

Instantly share code, notes, and snippets.

@Ahrengot
Last active February 3, 2017 09:23
Show Gist options
  • Save Ahrengot/78368050e8b108329240d81132d32f91 to your computer and use it in GitHub Desktop.
Save Ahrengot/78368050e8b108329240d81132d32f91 to your computer and use it in GitHub Desktop.
<?php
class AhrMovesNotificationsHandler {
public function __construct() {
add_action('rest_api_init', function() {
register_rest_route('moves/v1', '/notify', array(
'methods' => 'POST',
'callback' => array($this, 'on_receive_update'),
));
});
}
public function on_receive_update(WP_REST_Request $request) {
$json_body = $parameters = $request->get_json_params();
$json_body = (array) $json_body;
$json_body['created_at'] = date('r', time());
$json_body = (object) $json_body;
$filename = sprintf(
"%s/cache/user-updates/%s.txt",
dirname(__FILE__, 2),
date('j-M-Y H.i.s', time())
);
file_put_contents($filename, json_encode($json_body), LOCK_EX);
return $json_body;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment