├── README.md ├── bb-rest.php ├── classes └── class-fl-builder-rest.php └── routes ├── content.php ├── css.php └── js.php /README.md: -------------------------------------------------------------------------------- 1 | # Beaver Builder Rest 2 | 3 | The Beaver Builder Rest plugin allows you to access rendered HTML, JS and CSS produced on a page or post. You can use the data to display your pages in remote apps. 4 | 5 | # Endpoints 6 | 7 | * `/wp-json/fl-builder/v1/` 8 | 9 | Return json oject `ID,HTML,CSS,JS`. 10 | 11 | * `/wp-json/fl-builder/v1/css/` 12 | 13 | Returns CSS for page ID 2 14 | 15 | * `/wp-json/fl-builder/v1/js/` 16 | 17 | Returns JS for page ID 2 18 | 19 | -------------------------------------------------------------------------------- /bb-rest.php: -------------------------------------------------------------------------------- 1 | get_param( 'id' )){ 14 | $request_param_id = $request->get_param( 'id' ); 15 | $post = get_post( $request_param_id ); 16 | return $post->ID; 17 | } 18 | } 19 | 20 | static function strip_spaces( $txt ) { 21 | return preg_replace('/[\n\r\t\s]/', '', $txt ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /routes/content.php: -------------------------------------------------------------------------------- 1 | \d+)', array( 7 | 'methods' => WP_REST_Server::READABLE, 8 | 'callback' => array( __CLASS__, 'callback' ) 9 | ) ); 10 | }); 11 | } 12 | static function callback( $request ){ 13 | 14 | $post_id = FL_Rest::get_id( $request ); 15 | 16 | ob_start(); 17 | 18 | FLBuilder::render_content_by_id( $post_id ); 19 | 20 | $content = ob_get_clean(); 21 | 22 | $output = new stdClass; 23 | 24 | $output->id = $post_id; 25 | $output->html = $content; 26 | $output->css = FLBuilder::render_css( false ); 27 | $output->js = FLBuilder::render_js( false ); 28 | return $output; 29 | } 30 | } 31 | FL_Rest_Content::init(); 32 | -------------------------------------------------------------------------------- /routes/css.php: -------------------------------------------------------------------------------- 1 | \d+)', array( 7 | 'methods' => WP_REST_Server::READABLE, 8 | 'callback' => array( __CLASS__, 'callback' ) 9 | ) ); 10 | }); 11 | } 12 | static function callback( $request ){ 13 | 14 | $post_id = FL_Rest::get_id( $request ); 15 | 16 | return FL_Rest::strip_spaces( FLBuilder::render_css( false ) ); 17 | } 18 | } 19 | FL_Rest_CSS::init(); 20 | -------------------------------------------------------------------------------- /routes/js.php: -------------------------------------------------------------------------------- 1 | \d+)', array( 7 | 'methods' => WP_REST_Server::READABLE, 8 | 'callback' => array( __CLASS__, 'callback' ) 9 | ) ); 10 | }); 11 | } 12 | static function callback( $request ){ 13 | 14 | $post_id = FL_Rest::get_id( $request ); 15 | 16 | return FL_Rest::strip_spaces( FLBuilder::render_js( false ) ); 17 | } 18 | } 19 | FL_Rest_JS::init(); 20 | --------------------------------------------------------------------------------