Skip to content

Commit

Permalink
Keep $attributes as array until it's needed, perform checkings on fee…
Browse files Browse the repository at this point in the history
…dback meta data returned, filter empty values.
  • Loading branch information
eliorivero committed Feb 11, 2016
1 parent 7d5ba2d commit 44c8f20
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions modules/contact-form/grunion-contact-form.php
Expand Up @@ -198,12 +198,20 @@ function process_form_submission() {

// Get shortcode from post meta
$shortcode = get_post_meta( $_POST['contact-form-id'], '_g_feedback_shortcode', true );
// Get the attributes from post meta. $attributes not available here
$atts = get_post_meta( $_POST['contact-form-id'], '_g_feedback_shortcode_atts', true );

// Format it
if ( $shortcode != '' ) {
$shortcode = '[contact-form'.$atts.']' . $shortcode . '[/contact-form]';

// Get attributes from post meta.
$parameters = '';
$attributes = get_post_meta( $_POST['contact-form-id'], '_g_feedback_shortcode_atts', true );
if ( ! empty( $attributes ) && is_array( $attributes ) ) {
foreach( array_filter( $attributes ) as $param => $value ) {
$parameters .= " $param=\"$value\"";
}
}

$shortcode = '[contact-form' . $parameters . ']' . $shortcode . '[/contact-form]';
do_shortcode( $shortcode );

// Recreate form
Expand Down Expand Up @@ -971,19 +979,11 @@ static function store_shortcode( $content = null, $attributes = null ) {

$shortcode_meta = get_post_meta( $attributes['id'], '_g_feedback_shortcode', true );

// Iterate through $attributes and concatenate as a string.
$atts = ' ';
foreach ($attributes as $key => $value) {
if ( '' != $value ) {
$atts .= $key.'="'.$value.'" ';
} else {
$atts .= $key.' ';
}
}

if ( $shortcode_meta != '' or $shortcode_meta != $content ) {
update_post_meta( $attributes['id'], '_g_feedback_shortcode', $content );
update_post_meta( $attributes['id'], '_g_feedback_shortcode_atts', $atts ); // Save the atts string to post_meta for later use. $sttributes is not available later in do_shortcode situations.

// Save attributes to post_meta for later use. They're not available later in do_shortcode situations.
update_post_meta( $attributes['id'], '_g_feedback_shortcode_atts', $attributes );
}

}
Expand Down

0 comments on commit 44c8f20

Please sign in to comment.