From d5293efdc0548ed7004b8ffbae23ef701ae71016 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 27 Feb 2015 17:59:22 +0100 Subject: [PATCH] Contact Form: add a copy of th shortcode in post_meta This commit replays a73063868c3c54c29d82766d4375173a3fb7872e, that was reverted by accident during a merge in 2e0258037fb609ad5ab6c055e1f03aacd8f37992 --- modules/contact-form/grunion-contact-form.php | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/modules/contact-form/grunion-contact-form.php b/modules/contact-form/grunion-contact-form.php index 16f06aa3172e5..e0cd55d26276c 100644 --- a/modules/contact-form/grunion-contact-form.php +++ b/modules/contact-form/grunion-contact-form.php @@ -182,8 +182,25 @@ function process_form_submission() { $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 shortcode 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; @@ -917,12 +934,37 @@ 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. Grunion_Contact_Form_Plugin::$using_contact_form_field = false; } + /** + * 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 *