grunion_ajax_shortcode_to_json

The Jetpack by WordPress.com grunion ajax shortcode to json function.

Description

grunion_ajax_shortcode_to_json(); 

Usage

  1. if ( !function_exists( 'grunion_ajax_shortcode_to_json' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/contact-form/admin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = grunion_ajax_shortcode_to_json(); 
  7.  

Defined (1)

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

/modules/contact-form/admin.php  
  1. function grunion_ajax_shortcode_to_json() { 
  2. global $post, $grunion_form; 
  3.  
  4. check_ajax_referer( 'grunion_shortcode_to_json' ); 
  5.  
  6. if ( !isset( $_POST['content'] ) || !is_numeric( $_POST['post_id'] ) ) { 
  7. die( '-1' ); 
  8.  
  9. $content = stripslashes( $_POST['content'] ); 
  10.  
  11. // doesn't look like a post with a [contact-form] already. 
  12. if ( false === has_shortcode( $content, 'contact-form' ) ) { 
  13. die( '' ); 
  14.  
  15. $post = get_post( $_POST['post_id'] ); 
  16.  
  17. do_shortcode( $content ); 
  18.  
  19. $grunion = Grunion_Contact_Form::$last; 
  20.  
  21. $out = array( 
  22. 'to' => '',  
  23. 'subject' => '',  
  24. 'fields' => array(),  
  25. ); 
  26.  
  27. foreach ( $grunion->fields as $field ) { 
  28. $out['fields'][$field->get_attribute( 'id' )] = $field->attributes; 
  29.  
  30. $to = $grunion->get_attribute( 'to' ); 
  31. $subject = $grunion->get_attribute( 'subject' ); 
  32. foreach ( array( 'to', 'subject' ) as $attribute ) { 
  33. $value = $grunion->get_attribute( $attribute ); 
  34. if ( isset( $grunion->defaults[$attribute] ) && $value == $grunion->defaults[$attribute] ) { 
  35. $value = ''; 
  36. $out[$attribute] = $value; 
  37.  
  38. die( json_encode( $out ) );