This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('init', 'my_wpcf7_shortcode'); | |
function my_wpcf7_shortcode(){ | |
wpcf7_add_shortcode('my_shortcode', 'my_wpcf7_shortcode_handler', true); | |
} | |
function my_wpcf7_shortcode_handler( $tag ) { | |
$tag = new WPCF7_Shortcode( $tag ); | |
if ( empty( $tag->name ) ) | |
return ''; | |
$args = array( | |
'size' => $tag->get_size_option( '40' ), | |
'maxlength' => $tag->get_maxlength_option(), | |
'class' => $tag->get_class_option( wpcf7_form_controls_class( $tag->type, $tag->name ) ), | |
'id' => $tag->get_option( 'id', 'id', true ), | |
'tabindex' => $tag->get_option( 'tabindex', 'int', true ), | |
'pre' => $tag->get_option( 'pre', '.*', true ), | |
'post' => $tag->get_option( 'post', '.*', true ), | |
); | |
$defaults = array( | |
'size' => '40', | |
'maxlength' => '40', | |
'class' => $tag->name, | |
'id' => $tag->name, | |
'tabindex' => 0, | |
'pre' => '<span class="wpcf7-form-control-wrap">', | |
'post' => '</span>', | |
); | |
wp_parse_args( $args, $defaults ); | |
$value = ''; | |
if ( wpcf7_is_posted() && isset($_POST[$tag->name]) ) | |
$value = stripslashes_deep( $_POST[$tag->name] ); | |
return sprintf( | |
$args['pre'] . '<input type="%2$s" name="%1$s" value="%3$s" />' . $args['post'], | |
$tag->name, | |
$tag->type, | |
esc_attr($value) | |
); | |
} |
バリデーションとかは入れてません
コメントを残す