stream
stream copied to clipboard
Add Stream REST API endpoint
And use it internally, e.g. Live updates.
See also: Stream's WP CLI support.
Any chance we can get this idea moving? Here is some quick demo code if it helps.
/**
* Imforza Rest Routes initialization class.
*/
class Stream_REST {
/**
* Create the rest API routes.
*
* @access public
* @return void
*/
public function __construct() {
add_action( 'rest_api_init', function(){
register_rest_route( 'stream/v1', 'settings', array(
'methods' => array('get', 'post', 'put', 'patch'),
'callback' => array( $this, 'settings' ),
// 'permission_callback' => array( $this, 'permission_check' ),
'args' => array(
'keep_records' => array(
'required' => false,
'default' => '',
'description' => 'Keep Records Indefinitely. Not recommended.',
'type' => 'bool',
),
'keep_records_for' => array(
'required' => false,
'default' => '30',
'description' => 'Maximum number of days to keep activity records.',
'type' => 'int',
),
'role_access' => array(
'required' => false,
'default' => '',
'description' => 'Users from the selected roles above will have permission to view Stream Records.',
'type' => 'string',
),
// Advanced Settings.
'akismet_tracking' => array(
'required' => false,
'default' => '',
'description' => '',
'type' => 'bool',
),
'comment_flood_tracking' => array(
'required' => false,
'default' => '',
'description' => '',
'type' => 'bool',
),
'wpcron_tracking' => array(
'required' => false,
'default' => '',
'description' => '',
'type' => 'bool',
),
),
));
});
add_action( 'rest_api_init', function(){
register_rest_route( 'stream/v1', 'stream', array(
'methods' => 'get',
'callback' => array( $this, 'get_stream' ),
// 'permission_callback' => array( $this, 'permission_check' ),
));
});
add_action( 'rest_api_init', function(){
register_rest_route( 'stream/v1', 'resetdb', array(
'methods' => 'delete',
'callback' => array( $this, 'reset_stream_db' ),
// 'permission_callback' => array( $this, 'permission_check' ),
));
});
add_action( 'rest_api_init', function(){
register_rest_route( 'stream/v1', 'excludes', array(
'methods' => array('get', 'post', 'delete'),
'callback' => array( $this, 'excludes' ),
// 'permission_callback' => array( $this, 'permission_check' ),
));
});
}
/**
* get_stream function.
*
* @access public
* @return void
*/
public function get_stream() {
$stream_json = '';
return rest_ensure_response( $stream_json );
}
/**
* Check whether the function is allowed to be run.
*
* Must have either capabilities to enact action, or a valid nonce.
*
* @param [type] $data [description]
* @return [type] [description]
*/
public function permission_check( $data ) {
if ( ! current_user_can( 'manage_options' ) ) {
return new WP_Error( 'forbidden', 'You are not allowed to do that.', array( 'status' => 403 ) );
}
return true;
}
}
new Stream_REST();
+1 for this.
Something to bear in mind is that the REST API will support multisite shortly, and I'd love to see this functionality in Stream also support that. Definitely a major use case for us.
I'm all for this as well. Will see how we can get some traction on it.
+💯 for this 😀
+💯 for sure; for this to also work with multisite would be super great
will the REST API endpoint ever find it's way into the plugin? would really appreciate it!
As far as I can tell over the past months/year, work on this plugin has ground to a screeching halt.
Not sure what it would take for someone to pick up interest again. Is there something better out there that people are already gravitating to?
@kasparsd while I do agree that adding REST API endpoints has true merit, I feel it is a much larger lift than just adding endpoints. With the ability to build with React, it would be much more beneficial to build out a new version of Stream, which exposes endpoints, and rebuild the UI in React.
In short, add REST API endpoints, but as a bigger picture project with the idea of reworking the UI of the plugin as a whole.