Skip to content

Instantly share code, notes, and snippets.

@hssktm
Created October 5, 2024 19:07
Show Gist options
  • Save hssktm/ef456912bb6c66129c215578634a4d3b to your computer and use it in GitHub Desktop.
Save hssktm/ef456912bb6c66129c215578634a4d3b to your computer and use it in GitHub Desktop.
EndPoint Api Template Oxygen Builder
add_action('rest_api_init', function () {
register_rest_route('api-oxygen/v1', '/oxygen-content/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'call_oxygen_content_api',
));
});
function call_oxygen_content_api($data) {
$post_id = $data['id'];
if ($post_id != 13) {
return new WP_Error('forbidden', 'You do not have access to this page.', array('status' => 403));
}
$post = get_post($post_id);
if (!$post) { return new WP_Error('no_post', 'Post not found', array('status' => 404)); }
$shortcodes = get_post_meta($post_id, '_ct_builder_shortcodes', true);
if (!$shortcodes) {return new WP_Error('no_content', 'No Oxygen content found', array('status' => 404)); }
$rendered_content = do_shortcode($shortcodes);
$css_url = home_url('/wp-content/uploads/oxygen/css/' . $post_id . '.css');
return array(
'title' => $post->post_title,
'content' => $rendered_content,
'css_url' => $css_url,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment