Skip to content

Commit

Permalink
Merge pull request #1692 from jeherve/replay-133
Browse files Browse the repository at this point in the history
Contact Form: add a copy of th shortcode in post_meta
  • Loading branch information
samhotchkiss committed Mar 4, 2015
2 parents 27094b4 + d5293ef commit 2319754
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions modules/contact-form/grunion-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 2319754

Please sign in to comment.