Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Form: add a copy of th shortcode in post_meta #1692

Merged
merged 1 commit into from
Mar 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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