From a73063868c3c54c29d82766d4375173a3fb7872e Mon Sep 17 00:00:00 2001 From: jtwiest Date: Sat, 25 Jan 2014 13:29:11 -0800 Subject: [PATCH] do_shortcode error --- modules/contact-form/grunion-contact-form.php | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/modules/contact-form/grunion-contact-form.php b/modules/contact-form/grunion-contact-form.php index cd5c40020e3df..c8ae35d344dd1 100644 --- a/modules/contact-form/grunion-contact-form.php +++ b/modules/contact-form/grunion-contact-form.php @@ -170,11 +170,28 @@ function process_form_submission() { // Process the content to populate Grunion_Contact_Form::$last apply_filters( 'the_content', $post->post_content ); } - + $form = Grunion_Contact_Form::$last; - - if ( ! $form ) - return false; + + // No form may mean user is using do_shortcode, grab the form using the stored post meta + if ( !$form ) { + + // Get short code from post meta + $shortcode = get_post_meta( $_POST['contact-form-id'], '_g_feedback_shortcode', true ); + + // Format it + if ( $shortcode != '' ) { + $shortcode = '[contact-form]' . $shortcode . '[/contact-form]'; + do_shortcode( $shortcode ); + + // Recreate form + $form = Grunion_Contact_Form::$last; + } + + if ( ! $form ) { + return false; + } + } if ( is_wp_error( $form->errors ) && $form->errors->get_error_codes() ) return $form->errors; @@ -572,7 +589,7 @@ function __construct( $attributes, $content = null ) { } else { $this->content = $content; } - + $this->parse_content( $content ); } @@ -762,12 +779,38 @@ function __construct( $attributes, $content = null ) { [contact-field label="' . __( 'Message', 'jetpack' ) . '" type="textarea" /]'; $this->parse_content( $default_form ); + + // Store the shortcode + $this->store_shortcode( $default_form, $attributes ); + } else { + + // Store the shortcode + $this->store_shortcode( $content, $attributes ); } // $this->body and $this->fields have been setup. We no longer need the contact-field shortcode. remove_shortcode( 'contact-field' ); } + /** + * Store shortcode content for recall later + * - used to receate shortcode when user uses do_shortcode + * + * @param string $content + */ + static function store_shortcode( $content = null, $attributes = null ) { + + if ( $content != null and isset ( $attributes['id'] ) ) { + + $shortcode_meta = get_post_meta( $attributes['id'], '_g_feedback_shortcode', true ); + + if ( $shortcode_meta != '' or $shortcode_meta != $content ) { + update_post_meta( $attributes['id'], '_g_feedback_shortcode', $content ); + } + + } + } + /** * Toggle for printing the grunion.css stylesheet *