Skip to content

Commit

Permalink
Merge pull request #133 from jtwiest/master
Browse files Browse the repository at this point in the history
Fixed do_shortcode error
  • Loading branch information
blobaugh committed Feb 8, 2014
2 parents 11ccb03 + a730638 commit f5929ce
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions modules/contact-form/grunion-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -572,7 +589,7 @@ function __construct( $attributes, $content = null ) {
} else {
$this->content = $content;
}

$this->parse_content( $content );
}

Expand Down Expand Up @@ -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
*
Expand Down

2 comments on commit f5929ce

@jacobischwartz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy moly this commit was over a year ago. I've been trying to use the contact form in a page template using do_shortcode. Any idea when 3.4 will be released?

@jeherve
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobischwartz That code was released in Jetpack 2.9, but it seems it was then reverted by mistake in 2e02580. I created #1692 so we can add it back to Jetpack.

Thanks for the report!

Please sign in to comment.