Last active
November 10, 2018 19:24
-
-
Save satouriko/ec905d5378fbfbdd585ab63dfd39c609 to your computer and use it in GitHub Desktop.
Activate REST API for WordPress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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