tomusborne / generateblocks

GenerateBlocks is a small collection of lightweight WordPress blocks that can accomplish nearly anything.
https://generateblocks.com
194 stars 19 forks source link

How to add post inline css to REST API #1075

Open stefaner1 opened 1 year ago

stefaner1 commented 1 year ago

Description

I'm trying to use REST API (wp-json) to get post content with inline css style, but I can't find any documentation about it. Please help. My current code only print html without inline css that is in Gutenberg. I would like to return generateblocks-inline-css and generate-style-inline-css in my REST API .

My code:

`function print1(){ $post_id = 3297; $content = get_the_content(null, true, $post_id); $blocks = parse_blocks( $content );

$html_output = '';

foreach($blocks as $block){ $html_output .= render_block($block); }

//convert relative url to absolute $home_url = get_home_url(); $html_output = str_replace('="/', '="'.$home_url.'/', $html_output);

// return rendered blocks as HTML return new WP_REST_Response($html_output, 200); }

add_action('rest_api_init', 'register_learndash_get_lessons_v2');

function register_learndash_get_lessons_v2(){ register_rest_route('ldlms/v2', '/course2', array( 'methods' => 'GET', 'callback' => 'print1', 'permission_callback' => function(){ return isset($_GET['access_key']) && $_GET['access_key'] === 'FBWhwxreFo46n0L69pZGh5'; }, )); } `