function grunion_ajax_shortcode() { check_ajax_referer( 'grunion_shortcode' ); $atts = ''; if ( trim( $_POST['subject'] ) ) $atts .= ' subject="'.grunion_esc_attr($_POST['subject']).'"'; if ( trim( $_POST['to'] ) ) $atts .= ' to="'.grunion_esc_attr($_POST['to']).'"'; $shortcode = '[contact-form'.$atts.']'; $shortcode .= "\n"; if ( is_array( $_POST['fields'] ) ) { usort( $_POST['fields'], 'grunion_sort_objects' ); foreach ( $_POST['fields'] as $field ) { $req = $opts = ''; if ( $field['required'] == 'true' ) $req = ' required="true"'; if ( isset( $field['options'] ) && $field['options'] ) { $opts = ' options="'; foreach ( $field['options'] as $option ) { $option = wp_kses( $option, array() ); $option = grunion_esc_attr( $option ); # we need to be very specific about how we # encode these values $option = str_replace( ',', ',', $option ); $option = str_replace( '"', '"', $option ); $option = str_replace( "'", ''', $option ); $option = str_replace( '&', '&', $option ); $opts .= $option . ','; } $opts = rtrim( $opts, ',' ) . '"'; } $field['label'] = wp_kses( $field['label'], array() ); $field['label'] = str_replace( '"', '"', $field['label'] ); $shortcode .= '[contact-field label="'. $field['label'] .'" type="'.grunion_esc_attr($field['type']).'"' . $req . $opts .' /]'."\n"; } } $shortcode .= '[/contact-form]'; die( "\n$shortcode\n" ); }
function grunion_ajax_shortcode() { check_ajax_referer('grunion_shortcode'); $atts = ''; if (trim($_POST['subject'])) { $atts .= ' subject="' . grunion_esc_attr($_POST['subject']) . '"'; } if (trim($_POST['to'])) { $atts .= ' to="' . grunion_esc_attr($_POST['to']) . '"'; } $shortcode = '[contact-form' . $atts . ']'; $shortcode .= "\n"; if (is_array($_POST['fields'])) { usort($_POST['fields'], 'grunion_sort_objects'); foreach ($_POST['fields'] as $field) { $req = $opts = ''; if ($field['required'] == 'true') { $req = ' required="true"'; } if ($field['options']) { $opts = ' options="' . grunion_esc_attr(join(',', $field['options'])) . '"'; } $shortcode .= '[contact-field label="' . grunion_esc_attr($field['label']) . '" type="' . grunion_esc_attr($field['type']) . '"' . $req . $opts . ' /]' . "\n"; } } $shortcode .= '[/contact-form]'; die("\n{$shortcode}\n"); }