Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Activate REST API for WordPress.
<?php
/*
Plugin Name: Activate REST API
Plugin URI: https://wordpress.org/plugins/enable-anonymous-rest-comment/
Description: Enable comments via rest api without login. Give front-end raw HTML via REST API.
Version: 0.2
Author: Cooler
Author URI: https://gist.github.com/rikakomoe/ec905d5378fbfbdd585ab63dfd39c609
License: Unlicense
License URI: https://unlicense.org/
*/
add_filter( 'rest_allow_anonymous_comments', '__return_true' );
add_action( 'rest_api_init', function () {
register_rest_field(
'page',
'content',
array(
'get_callback' => 'compasshb_do_shortcodes',
'update_callback' => null,
'schema' => null,
)
);
});
function compasshb_do_shortcodes( $object, $field_name, $request ) {
WPBMap::addAllMappedShortcodes(); // This does all the work
global $post;
$post = get_post ($object['id']);
$output['rendered'] = apply_filters( 'the_content', $post->post_content );
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.