WPCOM_JSON_API_Render_Shortcode_Endpoint

The Jetpack by WordPress.com WPCOM JSON API Render Shortcode Endpoint class.

Defined (1)

The class is defined in the following location(s).

/json-endpoints/class.wpcom-json-api-render-shortcode-endpoint.php  
  1. class WPCOM_JSON_API_Render_Shortcode_Endpoint extends WPCOM_JSON_API_Render_Endpoint { 
  2. // /sites/%s/shortcodes/render -> $blog_id 
  3. function callback( $path = '', $blog_id = 0 ) { 
  4. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); 
  5. if ( is_wp_error( $blog_id ) ) { 
  6. return $blog_id; 
  7.  
  8. if ( ! current_user_can( 'edit_posts' ) ) { 
  9. return new WP_Error( 'unauthorized', 'Your token must have permission to post on this blog.', 403 ); 
  10.  
  11. $args = $this->query_args(); 
  12. $shortcode = trim( $args['shortcode'] ); 
  13.  
  14. // Quick validation - shortcodes should always be enclosed in brackets [] 
  15. if ( ! wp_startswith( $shortcode, '[' ) || ! wp_endswith( $shortcode, ']' ) ) { 
  16. return new WP_Error( 'invalid_shortcode', 'The shortcode parameter must begin and end with square brackets.', 400 ); 
  17.  
  18. // Make sure only one shortcode is being rendered at a time 
  19. $pattern = get_shortcode_regex(); 
  20. preg_match_all( "/$pattern/s", $shortcode, $matches ); 
  21. if ( count( $matches[0] ) > 1 ) { 
  22. return new WP_Error( 'invalid_shortcode', 'Only one shortcode can be rendered at a time.', 400 ); 
  23.  
  24. $render = $this->process_render( array( $this, 'do_shortcode' ), $shortcode ); 
  25.  
  26. // if nothing happened, then the shortcode does not exist. 
  27. if ( $shortcode == $render['result'] ) { 
  28. return new WP_Error( 'invalid_shortcode', 'The requested shortcode does not exist.', 400 ); 
  29.  
  30. // our output for this endpoint.. 
  31. $return['shortcode'] = $shortcode; 
  32. $return['result'] = $render['result']; 
  33.  
  34. $return = $this->add_assets( $return, $render['loaded_scripts'], $render['loaded_styles'] ); 
  35.  
  36. return $return; 
  37.  
  38. function do_shortcode( $shortcode ) { 
  39. $result = do_shortcode( $shortcode ); 
  40. return $result; 
  41.