PDF rausgenommen
This commit is contained in:
@ -0,0 +1,282 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [acceptance]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_acceptance', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_acceptance() {
|
||||
wpcf7_add_form_tag( 'acceptance',
|
||||
'wpcf7_acceptance_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_acceptance_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'invert' ) ) {
|
||||
$class .= ' invert';
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'optional' ) ) {
|
||||
$class .= ' optional';
|
||||
}
|
||||
|
||||
$atts = array(
|
||||
'class' => trim( $class ),
|
||||
);
|
||||
|
||||
$item_atts = array();
|
||||
|
||||
$item_atts['type'] = 'checkbox';
|
||||
$item_atts['name'] = $tag->name;
|
||||
$item_atts['value'] = '1';
|
||||
$item_atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
$item_atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
if ( $tag->has_option( 'default:on' ) ) {
|
||||
$item_atts['checked'] = 'checked';
|
||||
}
|
||||
|
||||
$item_atts['class'] = $tag->get_class_option();
|
||||
$item_atts['id'] = $tag->get_id_option();
|
||||
|
||||
$item_atts = wpcf7_format_atts( $item_atts );
|
||||
|
||||
$content = empty( $tag->content )
|
||||
? (string) reset( $tag->values )
|
||||
: $tag->content;
|
||||
|
||||
$content = trim( $content );
|
||||
|
||||
if ( $content ) {
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-list-item"><label><input %1$s /><span class="wpcf7-list-item-label">%2$s</span></label></span>',
|
||||
$item_atts, $content );
|
||||
} else {
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-list-item"><input %1$s /></span>',
|
||||
$item_atts );
|
||||
}
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $html, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_acceptance',
|
||||
'wpcf7_acceptance_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_acceptance_validation_filter( $result, $tag ) {
|
||||
if ( ! wpcf7_acceptance_as_validation() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'optional' ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$name = $tag->name;
|
||||
$value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
|
||||
|
||||
$invert = $tag->has_option( 'invert' );
|
||||
|
||||
if ( $invert and $value
|
||||
or ! $invert and ! $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'accept_terms' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Acceptance filter */
|
||||
|
||||
add_filter( 'wpcf7_acceptance', 'wpcf7_acceptance_filter', 10, 2 );
|
||||
|
||||
function wpcf7_acceptance_filter( $accepted, $submission ) {
|
||||
$tags = wpcf7_scan_form_tags( array( 'type' => 'acceptance' ) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
|
||||
|
||||
$content = empty( $tag->content )
|
||||
? (string) reset( $tag->values )
|
||||
: $tag->content;
|
||||
|
||||
$content = trim( $content );
|
||||
|
||||
if ( $value and $content ) {
|
||||
$submission->add_consent( $name, $content );
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'optional' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$invert = $tag->has_option( 'invert' );
|
||||
|
||||
if ( $invert and $value
|
||||
or ! $invert and ! $value ) {
|
||||
$accepted = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $accepted;
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_form_class_attr',
|
||||
'wpcf7_acceptance_form_class_attr', 10, 1 );
|
||||
|
||||
function wpcf7_acceptance_form_class_attr( $class ) {
|
||||
if ( wpcf7_acceptance_as_validation() ) {
|
||||
return $class . ' wpcf7-acceptance-as-validation';
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
function wpcf7_acceptance_as_validation() {
|
||||
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $contact_form->is_true( 'acceptance_as_validation' );
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_mail_tag_replaced_acceptance',
|
||||
'wpcf7_acceptance_mail_tag', 10, 4 );
|
||||
|
||||
function wpcf7_acceptance_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
|
||||
$form_tag = $mail_tag->corresponding_form_tag();
|
||||
|
||||
if ( ! $form_tag ) {
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
if ( ! empty( $submitted ) ) {
|
||||
$replaced = __( 'Consented', 'contact-form-7' );
|
||||
} else {
|
||||
$replaced = __( 'Not consented', 'contact-form-7' );
|
||||
}
|
||||
|
||||
$content = empty( $form_tag->content )
|
||||
? (string) reset( $form_tag->values )
|
||||
: $form_tag->content;
|
||||
|
||||
if ( ! $html ) {
|
||||
$content = wp_strip_all_tags( $content );
|
||||
}
|
||||
|
||||
$content = trim( $content );
|
||||
|
||||
if ( $content ) {
|
||||
/* translators: 1: 'Consented' or 'Not consented', 2: conditions */
|
||||
$replaced = sprintf(
|
||||
_x( '%1$s: %2$s', 'mail output for acceptance checkboxes',
|
||||
'contact-form-7' ),
|
||||
$replaced,
|
||||
$content );
|
||||
}
|
||||
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_acceptance', 35, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_acceptance() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'acceptance', __( 'acceptance', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_acceptance' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_acceptance( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'acceptance';
|
||||
|
||||
$description = __( "Generate a form-tag for an acceptance checkbox. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/acceptance-checkbox/', 'contact-form-7' ), __( 'Acceptance Checkbox', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-content' ); ?>"><?php echo esc_html( __( 'Condition', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="content" class="oneline large-text" id="<?php echo esc_attr( $args['content'] . '-content' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="optional" class="option" checked="checked" /> <?php echo esc_html( __( 'Make this checkbox optional', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
** Akismet Filter
|
||||
** Akismet API: http://akismet.com/development/api/
|
||||
**/
|
||||
|
||||
add_filter( 'wpcf7_spam', 'wpcf7_akismet', 10, 1 );
|
||||
|
||||
function wpcf7_akismet( $spam ) {
|
||||
if ( $spam ) {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
if ( ! wpcf7_akismet_is_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $params = wpcf7_akismet_submitted_params() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$c = array();
|
||||
|
||||
$c['comment_author'] = $params['author'];
|
||||
$c['comment_author_email'] = $params['author_email'];
|
||||
$c['comment_author_url'] = $params['author_url'];
|
||||
$c['comment_content'] = $params['content'];
|
||||
|
||||
$c['blog'] = get_option( 'home' );
|
||||
$c['blog_lang'] = get_locale();
|
||||
$c['blog_charset'] = get_option( 'blog_charset' );
|
||||
$c['user_ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
$c['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$c['referrer'] = $_SERVER['HTTP_REFERER'];
|
||||
|
||||
// http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/
|
||||
$c['comment_type'] = 'contact-form';
|
||||
|
||||
if ( $permalink = get_permalink() ) {
|
||||
$c['permalink'] = $permalink;
|
||||
}
|
||||
|
||||
$ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
|
||||
|
||||
foreach ( $_SERVER as $key => $value ) {
|
||||
if ( ! in_array( $key, (array) $ignore ) ) {
|
||||
$c["$key"] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return wpcf7_akismet_comment_check( $c );
|
||||
}
|
||||
|
||||
function wpcf7_akismet_is_available() {
|
||||
if ( is_callable( array( 'Akismet', 'get_api_key' ) ) ) {
|
||||
return (bool) Akismet::get_api_key();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function wpcf7_akismet_submitted_params() {
|
||||
$params = array(
|
||||
'author' => '',
|
||||
'author_email' => '',
|
||||
'author_url' => '',
|
||||
'content' => '',
|
||||
);
|
||||
|
||||
$has_akismet_option = false;
|
||||
|
||||
foreach ( (array) $_POST as $key => $val ) {
|
||||
if ( '_wpcf7' == substr( $key, 0, 6 )
|
||||
or '_wpnonce' == $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( is_array( $val ) ) {
|
||||
$val = implode( ', ', wpcf7_array_flatten( $val ) );
|
||||
}
|
||||
|
||||
$val = trim( $val );
|
||||
|
||||
if ( 0 == strlen( $val ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $tags = wpcf7_scan_form_tags( array( 'name' => $key ) ) ) {
|
||||
$tag = $tags[0];
|
||||
|
||||
$akismet = $tag->get_option( 'akismet',
|
||||
'(author|author_email|author_url)', true );
|
||||
|
||||
if ( $akismet ) {
|
||||
$has_akismet_option = true;
|
||||
|
||||
if ( 'author' == $akismet ) {
|
||||
$params[$akismet] = trim( $params[$akismet] . ' ' . $val );
|
||||
continue;
|
||||
} elseif ( '' == $params[$akismet] ) {
|
||||
$params[$akismet] = $val;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$params['content'] .= "\n\n" . $val;
|
||||
}
|
||||
|
||||
if ( ! $has_akismet_option ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$params['content'] = trim( $params['content'] );
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
function wpcf7_akismet_comment_check( $comment ) {
|
||||
$spam = false;
|
||||
$query_string = wpcf7_build_query( $comment );
|
||||
|
||||
if ( is_callable( array( 'Akismet', 'http_post' ) ) ) {
|
||||
$response = Akismet::http_post( $query_string, 'comment-check' );
|
||||
} else {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
if ( 'true' == $response[1] ) {
|
||||
$spam = true;
|
||||
}
|
||||
|
||||
if ( $submission = WPCF7_Submission::get_instance() ) {
|
||||
$submission->akismet = array( 'comment' => $comment, 'spam' => $spam );
|
||||
}
|
||||
|
||||
return apply_filters( 'wpcf7_akismet_comment_check', $spam, $comment );
|
||||
}
|
@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [checkbox], [checkbox*], and [radio]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_checkbox', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_checkbox() {
|
||||
wpcf7_add_form_tag( array( 'checkbox', 'checkbox*', 'radio' ),
|
||||
'wpcf7_checkbox_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'selectable-values' => true,
|
||||
'multiple-controls-container' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_checkbox_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$label_first = $tag->has_option( 'label_first' );
|
||||
$use_label_element = $tag->has_option( 'use_label_element' );
|
||||
$exclusive = $tag->has_option( 'exclusive' );
|
||||
$free_text = $tag->has_option( 'free_text' );
|
||||
$multiple = false;
|
||||
|
||||
if ( 'checkbox' == $tag->basetype ) {
|
||||
$multiple = ! $exclusive;
|
||||
} else { // radio
|
||||
$exclusive = false;
|
||||
}
|
||||
|
||||
if ( $exclusive ) {
|
||||
$class .= ' wpcf7-exclusive-checkbox';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
|
||||
$tabindex = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
if ( false !== $tabindex ) {
|
||||
$tabindex = (int) $tabindex;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$count = 0;
|
||||
|
||||
if ( $data = (array) $tag->get_data_option() ) {
|
||||
if ( $free_text ) {
|
||||
$tag->values = array_merge(
|
||||
array_slice( $tag->values, 0, -1 ),
|
||||
array_values( $data ),
|
||||
array_slice( $tag->values, -1 ) );
|
||||
$tag->labels = array_merge(
|
||||
array_slice( $tag->labels, 0, -1 ),
|
||||
array_values( $data ),
|
||||
array_slice( $tag->labels, -1 ) );
|
||||
} else {
|
||||
$tag->values = array_merge( $tag->values, array_values( $data ) );
|
||||
$tag->labels = array_merge( $tag->labels, array_values( $data ) );
|
||||
}
|
||||
}
|
||||
|
||||
$values = $tag->values;
|
||||
$labels = $tag->labels;
|
||||
|
||||
$default_choice = $tag->get_default_option( null, array(
|
||||
'multiple' => $multiple,
|
||||
) );
|
||||
|
||||
$hangover = wpcf7_get_hangover( $tag->name, $multiple ? array() : '' );
|
||||
|
||||
foreach ( $values as $key => $value ) {
|
||||
if ( $hangover ) {
|
||||
$checked = in_array( $value, (array) $hangover, true );
|
||||
} else {
|
||||
$checked = in_array( $value, (array) $default_choice, true );
|
||||
}
|
||||
|
||||
if ( isset( $labels[$key] ) ) {
|
||||
$label = $labels[$key];
|
||||
} else {
|
||||
$label = $value;
|
||||
}
|
||||
|
||||
$item_atts = array(
|
||||
'type' => $tag->basetype,
|
||||
'name' => $tag->name . ( $multiple ? '[]' : '' ),
|
||||
'value' => $value,
|
||||
'checked' => $checked ? 'checked' : '',
|
||||
'tabindex' => false !== $tabindex ? $tabindex : '',
|
||||
);
|
||||
|
||||
$item_atts = wpcf7_format_atts( $item_atts );
|
||||
|
||||
if ( $label_first ) { // put label first, input last
|
||||
$item = sprintf(
|
||||
'<span class="wpcf7-list-item-label">%1$s</span><input %2$s />',
|
||||
esc_html( $label ), $item_atts );
|
||||
} else {
|
||||
$item = sprintf(
|
||||
'<input %2$s /><span class="wpcf7-list-item-label">%1$s</span>',
|
||||
esc_html( $label ), $item_atts );
|
||||
}
|
||||
|
||||
if ( $use_label_element ) {
|
||||
$item = '<label>' . $item . '</label>';
|
||||
}
|
||||
|
||||
if ( false !== $tabindex
|
||||
and 0 < $tabindex ) {
|
||||
$tabindex += 1;
|
||||
}
|
||||
|
||||
$class = 'wpcf7-list-item';
|
||||
$count += 1;
|
||||
|
||||
if ( 1 == $count ) {
|
||||
$class .= ' first';
|
||||
}
|
||||
|
||||
if ( count( $values ) == $count ) { // last round
|
||||
$class .= ' last';
|
||||
|
||||
if ( $free_text ) {
|
||||
$free_text_name = sprintf(
|
||||
'_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name );
|
||||
|
||||
$free_text_atts = array(
|
||||
'name' => $free_text_name,
|
||||
'class' => 'wpcf7-free-text',
|
||||
'tabindex' => false !== $tabindex ? $tabindex : '',
|
||||
);
|
||||
|
||||
if ( wpcf7_is_posted()
|
||||
and isset( $_POST[$free_text_name] ) ) {
|
||||
$free_text_atts['value'] = wp_unslash(
|
||||
$_POST[$free_text_name] );
|
||||
}
|
||||
|
||||
$free_text_atts = wpcf7_format_atts( $free_text_atts );
|
||||
|
||||
$item .= sprintf( ' <input type="text" %s />', $free_text_atts );
|
||||
|
||||
$class .= ' has-free-text';
|
||||
}
|
||||
}
|
||||
|
||||
$item = '<span class="' . esc_attr( $class ) . '">' . $item . '</span>';
|
||||
$html .= $item;
|
||||
}
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $html, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_checkbox',
|
||||
'wpcf7_checkbox_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_checkbox*',
|
||||
'wpcf7_checkbox_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_radio',
|
||||
'wpcf7_checkbox_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_checkbox_validation_filter( $result, $tag ) {
|
||||
$name = $tag->name;
|
||||
$is_required = $tag->is_required() || 'radio' == $tag->type;
|
||||
$value = isset( $_POST[$name] ) ? (array) $_POST[$name] : array();
|
||||
|
||||
if ( $is_required and empty( $value ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Adding free text field */
|
||||
|
||||
add_filter( 'wpcf7_posted_data', 'wpcf7_checkbox_posted_data', 10, 1 );
|
||||
|
||||
function wpcf7_checkbox_posted_data( $posted_data ) {
|
||||
$tags = wpcf7_scan_form_tags(
|
||||
array( 'type' => array( 'checkbox', 'checkbox*', 'radio' ) ) );
|
||||
|
||||
if ( empty( $tags ) ) {
|
||||
return $posted_data;
|
||||
}
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( ! isset( $posted_data[$tag->name] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$posted_items = (array) $posted_data[$tag->name];
|
||||
|
||||
if ( $tag->has_option( 'free_text' ) ) {
|
||||
if ( WPCF7_USE_PIPE ) {
|
||||
$values = $tag->pipes->collect_afters();
|
||||
} else {
|
||||
$values = $tag->values;
|
||||
}
|
||||
|
||||
$last = array_pop( $values );
|
||||
$last = html_entity_decode( $last, ENT_QUOTES, 'UTF-8' );
|
||||
|
||||
if ( in_array( $last, $posted_items ) ) {
|
||||
$posted_items = array_diff( $posted_items, array( $last ) );
|
||||
|
||||
$free_text_name = sprintf(
|
||||
'_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name );
|
||||
|
||||
$free_text = $posted_data[$free_text_name];
|
||||
|
||||
if ( ! empty( $free_text ) ) {
|
||||
$posted_items[] = trim( $last . ' ' . $free_text );
|
||||
} else {
|
||||
$posted_items[] = $last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$posted_data[$tag->name] = $posted_items;
|
||||
}
|
||||
|
||||
return $posted_data;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init',
|
||||
'wpcf7_add_tag_generator_checkbox_and_radio', 30, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_checkbox_and_radio() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'checkbox', __( 'checkboxes', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_checkbox' );
|
||||
$tag_generator->add( 'radio', __( 'radio buttons', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_checkbox' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_checkbox( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = $args['id'];
|
||||
|
||||
if ( 'radio' != $type ) {
|
||||
$type = 'checkbox';
|
||||
}
|
||||
|
||||
if ( 'checkbox' == $type ) {
|
||||
$description = __( "Generate a form-tag for a group of checkboxes. For more details, see %s.", 'contact-form-7' );
|
||||
} elseif ( 'radio' == $type ) {
|
||||
$description = __( "Generate a form-tag for a group of radio buttons. For more details, see %s.", 'contact-form-7' );
|
||||
}
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/checkboxes-radio-buttons-and-menus/', 'contact-form-7' ), __( 'Checkboxes, Radio Buttons and Menus', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<?php if ( 'checkbox' == $type ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
|
||||
<textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea>
|
||||
<label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One option per line.", 'contact-form-7' ) ); ?></span></label><br />
|
||||
<label><input type="checkbox" name="label_first" class="option" /> <?php echo esc_html( __( 'Put a label first, a checkbox last', 'contact-form-7' ) ); ?></label><br />
|
||||
<label><input type="checkbox" name="use_label_element" class="option" /> <?php echo esc_html( __( 'Wrap each item with label element', 'contact-form-7' ) ); ?></label>
|
||||
<?php if ( 'checkbox' == $type ) : ?>
|
||||
<br /><label><input type="checkbox" name="exclusive" class="option" /> <?php echo esc_html( __( 'Make checkboxes exclusive', 'contact-form-7' ) ); ?></label>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,677 @@
|
||||
<?php
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_constant_contact_register_service', 10, 0 );
|
||||
|
||||
function wpcf7_constant_contact_register_service() {
|
||||
$integration = WPCF7_Integration::get_instance();
|
||||
|
||||
$integration->add_category( 'email_marketing',
|
||||
__( 'Email Marketing', 'contact-form-7' ) );
|
||||
|
||||
$service = WPCF7_ConstantContact::get_instance();
|
||||
$integration->add_service( 'constant_contact', $service );
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_submit', 'wpcf7_constant_contact_submit', 10, 2 );
|
||||
|
||||
function wpcf7_constant_contact_submit( $contact_form, $result ) {
|
||||
$service = WPCF7_ConstantContact::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $contact_form->in_demo_mode() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$do_submit = true;
|
||||
|
||||
if ( empty( $result['status'] )
|
||||
or ! in_array( $result['status'], array( 'mail_sent' ) ) ) {
|
||||
$do_submit = false;
|
||||
}
|
||||
|
||||
$do_submit = apply_filters( 'wpcf7_constant_contact_submit',
|
||||
$do_submit, $contact_form, $result );
|
||||
|
||||
if ( ! $do_submit ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
|
||||
$consented = true;
|
||||
|
||||
foreach ( $contact_form->scan_form_tags( 'feature=name-attr' ) as $tag ) {
|
||||
if ( $tag->has_option( 'consent_for:constant_contact' )
|
||||
and null == $submission->get_posted_data( $tag->name ) ) {
|
||||
$consented = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $consented ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request_builder_class_name = apply_filters(
|
||||
'wpcf7_constant_contact_contact_post_request_builder',
|
||||
'WPCF7_ConstantContact_ContactPostRequest'
|
||||
);
|
||||
|
||||
if ( ! class_exists( $request_builder_class_name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request_builder = new $request_builder_class_name;
|
||||
$request_builder->build( $submission );
|
||||
|
||||
if ( ! $request_builder->is_valid() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $email = $request_builder->get_email_address()
|
||||
and $service->email_exists( $email ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$service->create_contact( $request_builder->to_array() );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WPCF7_Service_OAuth2' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
class WPCF7_ConstantContact extends WPCF7_Service_OAuth2 {
|
||||
|
||||
const service_name = 'constant_contact';
|
||||
const authorization_endpoint = 'https://api.cc.email/v3/idfed';
|
||||
const token_endpoint = 'https://idfed.constantcontact.com/as/token.oauth2';
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if ( empty( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$this->authorization_endpoint = self::authorization_endpoint;
|
||||
$this->token_endpoint = self::token_endpoint;
|
||||
|
||||
$option = (array) WPCF7::get_option( self::service_name );
|
||||
|
||||
if ( isset( $option['client_id'] ) ) {
|
||||
$this->client_id = $option['client_id'];
|
||||
}
|
||||
|
||||
if ( isset( $option['client_secret'] ) ) {
|
||||
$this->client_secret = $option['client_secret'];
|
||||
}
|
||||
|
||||
if ( isset( $option['access_token'] ) ) {
|
||||
$this->access_token = $option['access_token'];
|
||||
}
|
||||
|
||||
if ( isset( $option['refresh_token'] ) ) {
|
||||
$this->refresh_token = $option['refresh_token'];
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_admin_init', array( $this, 'auth_redirect' ) );
|
||||
}
|
||||
|
||||
public function auth_redirect() {
|
||||
$auth = isset( $_GET['auth'] ) ? trim( $_GET['auth'] ) : '';
|
||||
$code = isset( $_GET['code'] ) ? trim( $_GET['code'] ) : '';
|
||||
|
||||
if ( self::service_name === $auth and $code
|
||||
and current_user_can( 'wpcf7_manage_integration' ) ) {
|
||||
$redirect_to = add_query_arg(
|
||||
array(
|
||||
'service' => self::service_name,
|
||||
'action' => 'auth_redirect',
|
||||
'code' => $code,
|
||||
),
|
||||
menu_page_url( 'wpcf7-integration', false )
|
||||
);
|
||||
|
||||
wp_safe_redirect( $redirect_to );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
protected function save_data() {
|
||||
$option = array_merge(
|
||||
(array) WPCF7::get_option( self::service_name ),
|
||||
array(
|
||||
'client_id' => $this->client_id,
|
||||
'client_secret' => $this->client_secret,
|
||||
'access_token' => $this->access_token,
|
||||
'refresh_token' => $this->refresh_token,
|
||||
)
|
||||
);
|
||||
|
||||
WPCF7::update_option( self::service_name, $option );
|
||||
}
|
||||
|
||||
protected function reset_data() {
|
||||
$this->client_id = '';
|
||||
$this->client_secret = '';
|
||||
$this->access_token = '';
|
||||
$this->refresh_token = '';
|
||||
|
||||
$this->save_data();
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return __( 'Constant Contact', 'contact-form-7' );
|
||||
}
|
||||
|
||||
public function get_categories() {
|
||||
return array( 'email_marketing' );
|
||||
}
|
||||
|
||||
public function icon() {
|
||||
}
|
||||
|
||||
public function link() {
|
||||
echo sprintf( '<a href="%1$s">%2$s</a>',
|
||||
'https://constant-contact.evyy.net/c/1293104/205991/3411',
|
||||
'constantcontact.com'
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_redirect_uri() {
|
||||
return admin_url( '/?auth=' . self::service_name );
|
||||
}
|
||||
|
||||
protected function menu_page_url( $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
$url = menu_page_url( 'wpcf7-integration', false );
|
||||
$url = add_query_arg( array( 'service' => self::service_name ), $url );
|
||||
|
||||
if ( ! empty( $args) ) {
|
||||
$url = add_query_arg( $args, $url );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function load( $action = '' ) {
|
||||
parent::load( $action );
|
||||
|
||||
if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
|
||||
check_admin_referer( 'wpcf7-constant-contact-setup' );
|
||||
|
||||
if ( ! empty( $_POST['reset'] ) ) {
|
||||
$this->reset_data();
|
||||
} else {
|
||||
$this->client_id = isset( $_POST['client_id'] )
|
||||
? trim( $_POST['client_id'] ) : '';
|
||||
|
||||
$this->client_secret = isset( $_POST['client_secret'] )
|
||||
? trim( $_POST['client_secret'] ) : '';
|
||||
|
||||
$this->save_data();
|
||||
$this->authorize( 'contact_data' );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $this->menu_page_url( 'action=setup' ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function email_exists( $email ) {
|
||||
$endpoint = add_query_arg(
|
||||
array( 'email' => $email ),
|
||||
'https://api.cc.email/v3/contacts'
|
||||
);
|
||||
|
||||
$request = array(
|
||||
'method' => 'GET',
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'Authorization' => $this->get_http_authorization_header( 'bearer' ),
|
||||
),
|
||||
);
|
||||
|
||||
$response = $this->remote_request( esc_url_raw( $endpoint ), $request );
|
||||
|
||||
if ( WP_DEBUG
|
||||
and 400 <= (int) wp_remote_retrieve_response_code( $response ) ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
|
||||
$response_body = wp_remote_retrieve_body( $response );
|
||||
|
||||
if ( empty( $response_body ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response_body = json_decode( $response_body, true );
|
||||
|
||||
return ! empty( $response_body['contacts'] );
|
||||
}
|
||||
|
||||
public function create_contact( $properties ) {
|
||||
$endpoint = 'https://api.cc.email/v3/contacts';
|
||||
|
||||
$request = array(
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'Authorization' => $this->get_http_authorization_header( 'bearer' ),
|
||||
),
|
||||
'body' => json_encode( $properties ),
|
||||
);
|
||||
|
||||
$response = $this->remote_request( esc_url_raw( $endpoint ), $request );
|
||||
|
||||
if ( WP_DEBUG
|
||||
and 400 <= (int) wp_remote_retrieve_response_code( $response ) ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
}
|
||||
|
||||
public function display( $action = '' ) {
|
||||
echo '<p>' . sprintf(
|
||||
esc_html( __( 'The Constant Contact integration module allows you to send contact data collected through your contact forms to the Constant Contact API. You can create reliable email subscription services in a few easy steps. For details, see %s.', 'contact-form-7' ) ),
|
||||
wpcf7_link(
|
||||
__(
|
||||
'https://contactform7.com/constant-contact-integration/',
|
||||
'contact-form-7'
|
||||
),
|
||||
__( 'Constant Contact Integration', 'contact-form-7' )
|
||||
)
|
||||
) . '</p>';
|
||||
|
||||
if ( $this->is_active() or 'setup' == $action ) {
|
||||
$this->display_setup();
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<p><a href="%1$s" class="button">%2$s</a></p>',
|
||||
esc_url( $this->menu_page_url( 'action=setup' ) ),
|
||||
esc_html( __( 'Setup Integration', 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function display_setup() {
|
||||
?>
|
||||
<form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
|
||||
<?php wp_nonce_field( 'wpcf7-constant-contact-setup' ); ?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="client_id"><?php echo esc_html( __( 'API Key', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><?php
|
||||
if ( $this->is_active() ) {
|
||||
echo esc_html( $this->client_id );
|
||||
echo sprintf(
|
||||
'<input type="hidden" value="%1$s" id="client_id" name="client_id" />',
|
||||
esc_attr( $this->client_id )
|
||||
);
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<input type="text" aria-required="true" value="%1$s" id="client_id" name="client_id" class="regular-text code" />',
|
||||
esc_attr( $this->client_id )
|
||||
);
|
||||
}
|
||||
?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="client_secret"><?php echo esc_html( __( 'App Secret', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><?php
|
||||
if ( $this->is_active() ) {
|
||||
echo esc_html( wpcf7_mask_password( $this->client_secret ) );
|
||||
echo sprintf(
|
||||
'<input type="hidden" value="%1$s" id="client_secret" name="client_secret" />',
|
||||
esc_attr( $this->client_secret )
|
||||
);
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<input type="text" aria-required="true" value="%1$s" id="client_secret" name="client_secret" class="regular-text code" />',
|
||||
esc_attr( $this->client_secret )
|
||||
);
|
||||
}
|
||||
?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="redirect_uri"><?php echo esc_html( __( 'Redirect URI', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><?php
|
||||
echo sprintf(
|
||||
'<input type="text" value="%1$s" id="redirect_uri" name="redirect_uri" class="large-text code" readonly="readonly" onfocus="this.select();" style="font-size: 11px;" />',
|
||||
$this->get_redirect_uri()
|
||||
);
|
||||
?>
|
||||
<p class="description"><?php echo esc_html( __( "Set this URL as the redirect URI.", 'contact-form-7' ) ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
if ( $this->is_active() ) {
|
||||
submit_button(
|
||||
_x( 'Remove Keys', 'API keys', 'contact-form-7' ),
|
||||
'small', 'reset'
|
||||
);
|
||||
} else {
|
||||
submit_button( __( 'Connect to the Constant Contact API', 'contact-form-7' ) );
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WPCF7_ConstantContact_ContactPostRequest {
|
||||
|
||||
private $email_address;
|
||||
private $first_name;
|
||||
private $last_name;
|
||||
private $job_title;
|
||||
private $company_name;
|
||||
private $create_source;
|
||||
private $birthday_month;
|
||||
private $birthday_day;
|
||||
private $anniversary;
|
||||
private $custom_fields = array();
|
||||
private $phone_numbers = array();
|
||||
private $street_addresses = array();
|
||||
private $list_memberships = array();
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function build( WPCF7_Submission $submission ) {
|
||||
$this->set_create_source( 'Contact' );
|
||||
|
||||
$posted_data = (array) $submission->get_posted_data();
|
||||
|
||||
if ( isset( $posted_data['your-first-name'] ) ) {
|
||||
$this->set_first_name( $posted_data['your-first-name'] );
|
||||
}
|
||||
|
||||
if ( isset( $posted_data['your-last-name'] ) ) {
|
||||
$this->set_last_name( $posted_data['your-last-name'] );
|
||||
}
|
||||
|
||||
if ( ! ( $this->first_name || $this->last_name )
|
||||
and isset( $posted_data['your-name'] ) ) {
|
||||
$your_name = preg_split( '/[\s]+/', $posted_data['your-name'], 2 );
|
||||
$this->set_first_name( array_shift( $your_name ) );
|
||||
$this->set_last_name( array_shift( $your_name ) );
|
||||
}
|
||||
|
||||
if ( isset( $posted_data['your-email'] ) ) {
|
||||
$this->set_email_address( $posted_data['your-email'], 'implicit' );
|
||||
}
|
||||
|
||||
if ( isset( $posted_data['your-job-title'] ) ) {
|
||||
$this->set_job_title( $posted_data['your-job-title'] );
|
||||
}
|
||||
|
||||
if ( isset( $posted_data['your-company-name'] ) ) {
|
||||
$this->set_company_name( $posted_data['your-company-name'] );
|
||||
}
|
||||
|
||||
if ( isset( $posted_data['your-birthday-month'] )
|
||||
and isset( $posted_data['your-birthday-day'] ) ) {
|
||||
$this->set_birthday(
|
||||
$posted_data['your-birthday-month'],
|
||||
$posted_data['your-birthday-day']
|
||||
);
|
||||
} elseif ( isset( $posted_data['your-birthday'] ) ) {
|
||||
$date = trim( $posted_data['your-birthday'] );
|
||||
|
||||
if ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})$/', $date, $matches ) ) {
|
||||
$this->set_birthday( $matches[2], $matches[3] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $posted_data['your-anniversary'] ) ) {
|
||||
$this->set_anniversary( $posted_data['your-anniversary'] );
|
||||
}
|
||||
|
||||
if ( isset( $posted_data['your-phone-number'] ) ) {
|
||||
$this->add_phone_number( $posted_data['your-phone-number'] );
|
||||
}
|
||||
|
||||
$this->add_street_address(
|
||||
isset( $posted_data['your-address-street'] )
|
||||
? $posted_data['your-address-street'] : '',
|
||||
isset( $posted_data['your-address-city'] )
|
||||
? $posted_data['your-address-city'] : '',
|
||||
isset( $posted_data['your-address-state'] )
|
||||
? $posted_data['your-address-state'] : '',
|
||||
isset( $posted_data['your-address-postal-code'] )
|
||||
? $posted_data['your-address-postal-code'] : '',
|
||||
isset( $posted_data['your-address-country'] )
|
||||
? $posted_data['your-address-country'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
public function is_valid() {
|
||||
return $this->create_source
|
||||
&& ( $this->email_address || $this->first_name || $this->last_name );
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
$output = array(
|
||||
'email_address' => $this->email_address,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'job_title' => $this->job_title,
|
||||
'company_name' => $this->company_name,
|
||||
'create_source' => $this->create_source,
|
||||
'birthday_month' => $this->birthday_month,
|
||||
'birthday_day' => $this->birthday_day,
|
||||
'anniversary' => $this->anniversary,
|
||||
'custom_fields' => $this->custom_fields,
|
||||
'phone_numbers' => $this->phone_numbers,
|
||||
'street_addresses' => $this->street_addresses,
|
||||
'list_memberships' => $this->list_memberships,
|
||||
);
|
||||
|
||||
return array_filter( $output );
|
||||
}
|
||||
|
||||
public function get_email_address() {
|
||||
if ( isset( $this->email_address['address'] ) ) {
|
||||
return $this->email_address['address'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function set_email_address( $address, $permission_to_send = '' ) {
|
||||
if ( ! wpcf7_is_email( $address )
|
||||
or 80 < $this->strlen( $address ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$types_of_permission = array(
|
||||
'implicit', 'explicit', 'deprecate', 'pending',
|
||||
'unsubscribe', 'temp_hold', 'not_set',
|
||||
);
|
||||
|
||||
if ( ! in_array( $permission_to_send, $types_of_permission ) ) {
|
||||
$permission_to_send = 'implicit';
|
||||
}
|
||||
|
||||
return $this->email_address = array(
|
||||
'address' => $address,
|
||||
'permission_to_send' => $permission_to_send,
|
||||
);
|
||||
}
|
||||
|
||||
public function set_first_name( $first_name ) {
|
||||
$first_name = trim( $first_name );
|
||||
|
||||
if ( empty( $first_name )
|
||||
or 50 < $this->strlen( $first_name ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->first_name = $first_name;
|
||||
}
|
||||
|
||||
public function set_last_name( $last_name ) {
|
||||
$last_name = trim( $last_name );
|
||||
|
||||
if ( empty( $last_name )
|
||||
or 50 < $this->strlen( $last_name ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->last_name = $last_name;
|
||||
}
|
||||
|
||||
public function set_job_title( $job_title ) {
|
||||
$job_title = trim( $job_title );
|
||||
|
||||
if ( empty( $job_title )
|
||||
or 50 < $this->strlen( $job_title ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->job_title = $job_title;
|
||||
}
|
||||
|
||||
public function set_company_name( $company_name ) {
|
||||
$company_name = trim( $company_name );
|
||||
|
||||
if ( empty( $company_name )
|
||||
or 50 < $this->strlen( $company_name ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->company_name = $company_name;
|
||||
}
|
||||
|
||||
public function set_create_source( $create_source ) {
|
||||
if ( ! in_array( $create_source, array( 'Contact', 'Account' ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->create_source = $create_source;
|
||||
}
|
||||
|
||||
public function set_birthday( $month, $day ) {
|
||||
$month = (int) $month;
|
||||
$day = (int) $day;
|
||||
|
||||
if ( $month < 1 || 12 < $month
|
||||
or $day < 1 || 31 < $day ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->birthday_month = $month;
|
||||
$this->birthday_day = $day;
|
||||
|
||||
return array( $this->birthday_month, $this->birthday_day );
|
||||
}
|
||||
|
||||
public function set_anniversary( $anniversary ) {
|
||||
$pattern = sprintf(
|
||||
'#^(%s)$#',
|
||||
implode( '|', array(
|
||||
'\d{1,2}/\d{1,2}/\d{4}',
|
||||
'\d{4}/\d{1,2}/\d{1,2}',
|
||||
'\d{4}-\d{1,2}-\d{1,2}',
|
||||
'\d{1,2}-\d{1,2}-\d{4}',
|
||||
) )
|
||||
);
|
||||
|
||||
if ( ! preg_match( $pattern, $anniversary ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->anniversary = $anniversary;
|
||||
}
|
||||
|
||||
public function add_custom_field( $custom_field_id, $value ) {
|
||||
$uuid_pattern = '/^[0-9a-f-]+$/i';
|
||||
|
||||
$value = trim( $value );
|
||||
|
||||
if ( 25 <= count( $this->custom_fields )
|
||||
or ! preg_match( $uuid_pattern, $custom_field_id )
|
||||
or 255 < $this->strlen( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->custom_fields[] = array(
|
||||
'custom_field_id' => $custom_field_id,
|
||||
'value' => $value,
|
||||
);
|
||||
}
|
||||
|
||||
public function add_phone_number( $phone_number, $kind = 'home' ) {
|
||||
$phone_number = trim( $phone_number );
|
||||
|
||||
if ( 2 <= count( $this->phone_numbers )
|
||||
or ! wpcf7_is_tel( $phone_number )
|
||||
or 25 < $this->strlen( $phone_number )
|
||||
or ! in_array( $kind, array( 'home', 'work', 'other' ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->phone_numbers[] = array(
|
||||
'phone_number' => $phone_number,
|
||||
'kind' => $kind,
|
||||
);
|
||||
}
|
||||
|
||||
public function add_street_address( $street, $city, $state, $postal_code, $country, $kind = 'home' ) {
|
||||
$street = trim( $street );
|
||||
$city = trim( $city );
|
||||
$state = trim( $state );
|
||||
$postal_code = trim( $postal_code );
|
||||
$country = trim( $country );
|
||||
|
||||
if ( ! ( $street || $city || $state || $postal_code || $country )
|
||||
or 1 <= count( $this->street_addresses )
|
||||
or ! in_array( $kind, array( 'home', 'work', 'other' ) )
|
||||
or 255 < $this->strlen( $street )
|
||||
or 50 < $this->strlen( $city )
|
||||
or 50 < $this->strlen( $state )
|
||||
or 50 < $this->strlen( $postal_code )
|
||||
or 50 < $this->strlen( $country ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->street_addresses[] = array(
|
||||
'kind' => $kind,
|
||||
'street' => $street,
|
||||
'city' => $city,
|
||||
'state' => $state,
|
||||
'postal_code' => $postal_code,
|
||||
'country' => $country,
|
||||
);
|
||||
}
|
||||
|
||||
public function add_list_membership( $list_id ) {
|
||||
$uuid_pattern = '/^[0-9a-f-]+$/i';
|
||||
|
||||
if ( 50 <= count( $this->list_memberships )
|
||||
or ! preg_match( $uuid_pattern, $list_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->list_memberships[] = $list_id;
|
||||
}
|
||||
|
||||
protected function strlen( $string ) {
|
||||
return wpcf7_count_code_units( stripslashes( $string ) );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [count], Twitter-like character count
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_count', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_count() {
|
||||
wpcf7_add_form_tag( 'count',
|
||||
'wpcf7_count_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'zero-controls-container' => true,
|
||||
'not-for-mail' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_count_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$targets = wpcf7_scan_form_tags( array( 'name' => $tag->name ) );
|
||||
$maxlength = $minlength = null;
|
||||
|
||||
while ( $targets ) {
|
||||
$target = array_shift( $targets );
|
||||
|
||||
if ( 'count' != $target->type ) {
|
||||
$maxlength = $target->get_maxlength_option();
|
||||
$minlength = $target->get_minlength_option();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $maxlength and $minlength
|
||||
and $maxlength < $minlength ) {
|
||||
$maxlength = $minlength = null;
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'down' ) ) {
|
||||
$value = (int) $maxlength;
|
||||
$class = 'wpcf7-character-count down';
|
||||
} else {
|
||||
$value = '0';
|
||||
$class = 'wpcf7-character-count up';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['data-target-name'] = $tag->name;
|
||||
$atts['data-starting-value'] = $value;
|
||||
$atts['data-current-value'] = $value;
|
||||
$atts['data-maximum-value'] = $maxlength;
|
||||
$atts['data-minimum-value'] = $minlength;
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf( '<span %1$s>%2$s</span>', $atts, $value );
|
||||
|
||||
return $html;
|
||||
}
|
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for the following types of tags:
|
||||
** [date] and [date*] # Date
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_date', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_date() {
|
||||
wpcf7_add_form_tag( array( 'date', 'date*' ),
|
||||
'wpcf7_date_form_tag_handler', array( 'name-attr' => true ) );
|
||||
}
|
||||
|
||||
function wpcf7_date_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
$class .= ' wpcf7-validates-as-date';
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
$atts['min'] = $tag->get_date_option( 'min' );
|
||||
$atts['max'] = $tag->get_date_option( 'max' );
|
||||
$atts['step'] = $tag->get_option( 'step', 'int', true );
|
||||
|
||||
if ( $tag->has_option( 'readonly' ) ) {
|
||||
$atts['readonly'] = 'readonly';
|
||||
}
|
||||
|
||||
if ( $tag->is_required() ) {
|
||||
$atts['aria-required'] = 'true';
|
||||
}
|
||||
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$value = (string) reset( $tag->values );
|
||||
|
||||
if ( $tag->has_option( 'placeholder' )
|
||||
or $tag->has_option( 'watermark' ) ) {
|
||||
$atts['placeholder'] = $value;
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$value = $tag->get_default_option( $value );
|
||||
|
||||
$value = wpcf7_get_hangover( $tag->name, $value );
|
||||
|
||||
$atts['value'] = $value;
|
||||
|
||||
if ( wpcf7_support_html5() ) {
|
||||
$atts['type'] = $tag->basetype;
|
||||
} else {
|
||||
$atts['type'] = 'text';
|
||||
}
|
||||
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_date', 'wpcf7_date_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_date*', 'wpcf7_date_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_date_validation_filter( $result, $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
$min = $tag->get_date_option( 'min' );
|
||||
$max = $tag->get_date_option( 'max' );
|
||||
|
||||
$value = isset( $_POST[$name] )
|
||||
? trim( strtr( (string) $_POST[$name], "\n", " " ) )
|
||||
: '';
|
||||
|
||||
if ( $tag->is_required() and '' == $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
} elseif ( '' != $value and ! wpcf7_is_date( $value ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_date' ) );
|
||||
} elseif ( '' != $value and ! empty( $min ) and $value < $min ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'date_too_early' ) );
|
||||
} elseif ( '' != $value and ! empty( $max ) and $max < $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'date_too_late' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_date_messages', 10, 1 );
|
||||
|
||||
function wpcf7_date_messages( $messages ) {
|
||||
return array_merge( $messages, array(
|
||||
'invalid_date' => array(
|
||||
'description' => __( "Date format that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' => __( "The date format is incorrect.", 'contact-form-7' )
|
||||
),
|
||||
|
||||
'date_too_early' => array(
|
||||
'description' => __( "Date is earlier than minimum limit", 'contact-form-7' ),
|
||||
'default' => __( "The date is before the earliest one allowed.", 'contact-form-7' )
|
||||
),
|
||||
|
||||
'date_too_late' => array(
|
||||
'description' => __( "Date is later than maximum limit", 'contact-form-7' ),
|
||||
'default' => __( "The date is after the latest one allowed.", 'contact-form-7' )
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_date', 19, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_date() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'date', __( 'date', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_date' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_date( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'date';
|
||||
|
||||
$description = __( "Generate a form-tag for a date input field. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/date-field/', 'contact-form-7' ), __( 'Date Field', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></legend>
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Min', 'contact-form-7' ) ); ?>
|
||||
<input type="date" name="min" class="date option" />
|
||||
</label>
|
||||
–
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Max', 'contact-form-7' ) ); ?>
|
||||
<input type="date" name="max" class="date option" />
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,465 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [file] and [file*]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_file', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_file() {
|
||||
wpcf7_add_form_tag( array( 'file', 'file*' ),
|
||||
'wpcf7_file_form_tag_handler', array( 'name-attr' => true ) );
|
||||
}
|
||||
|
||||
function wpcf7_file_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['size'] = $tag->get_size_option( '40' );
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
$atts['accept'] = wpcf7_acceptable_filetypes(
|
||||
$tag->get_option( 'filetypes' ), 'attr' );
|
||||
|
||||
if ( $tag->is_required() ) {
|
||||
$atts['aria-required'] = 'true';
|
||||
}
|
||||
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$atts['type'] = 'file';
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Encode type filter */
|
||||
|
||||
add_filter( 'wpcf7_form_enctype', 'wpcf7_file_form_enctype_filter', 10, 1 );
|
||||
|
||||
function wpcf7_file_form_enctype_filter( $enctype ) {
|
||||
$multipart = (bool) wpcf7_scan_form_tags(
|
||||
array( 'type' => array( 'file', 'file*' ) ) );
|
||||
|
||||
if ( $multipart ) {
|
||||
$enctype = 'multipart/form-data';
|
||||
}
|
||||
|
||||
return $enctype;
|
||||
}
|
||||
|
||||
|
||||
/* Validation + upload handling filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_file', 'wpcf7_file_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_file*', 'wpcf7_file_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_file_validation_filter( $result, $tag ) {
|
||||
$name = $tag->name;
|
||||
$id = $tag->get_id_option();
|
||||
|
||||
$file = isset( $_FILES[$name] ) ? $_FILES[$name] : null;
|
||||
|
||||
if ( $file['error'] and UPLOAD_ERR_NO_FILE != $file['error'] ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'upload_failed_php_error' ) );
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( empty( $file['tmp_name'] ) and $tag->is_required() ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( ! is_uploaded_file( $file['tmp_name'] ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* File type validation */
|
||||
|
||||
$file_type_pattern = wpcf7_acceptable_filetypes(
|
||||
$tag->get_option( 'filetypes' ), 'regex' );
|
||||
|
||||
$file_type_pattern = '/\.(' . $file_type_pattern . ')$/i';
|
||||
|
||||
if ( ! preg_match( $file_type_pattern, $file['name'] ) ) {
|
||||
$result->invalidate( $tag,
|
||||
wpcf7_get_message( 'upload_file_type_invalid' ) );
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* File size validation */
|
||||
|
||||
$allowed_size = 1048576; // default size 1 MB
|
||||
|
||||
if ( $file_size_a = $tag->get_option( 'limit' ) ) {
|
||||
$limit_pattern = '/^([1-9][0-9]*)([kKmM]?[bB])?$/';
|
||||
|
||||
foreach ( $file_size_a as $file_size ) {
|
||||
if ( preg_match( $limit_pattern, $file_size, $matches ) ) {
|
||||
$allowed_size = (int) $matches[1];
|
||||
|
||||
if ( ! empty( $matches[2] ) ) {
|
||||
$kbmb = strtolower( $matches[2] );
|
||||
|
||||
if ( 'kb' == $kbmb ) {
|
||||
$allowed_size *= 1024;
|
||||
} elseif ( 'mb' == $kbmb ) {
|
||||
$allowed_size *= 1024 * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $file['size'] > $allowed_size ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'upload_file_too_large' ) );
|
||||
return $result;
|
||||
}
|
||||
|
||||
wpcf7_init_uploads(); // Confirm upload dir
|
||||
$uploads_dir = wpcf7_upload_tmp_dir();
|
||||
$uploads_dir = wpcf7_maybe_add_random_dir( $uploads_dir );
|
||||
|
||||
$filename = $file['name'];
|
||||
$filename = wpcf7_canonicalize( $filename, 'as-is' );
|
||||
$filename = wpcf7_antiscript_file_name( $filename );
|
||||
|
||||
$filename = apply_filters( 'wpcf7_upload_file_name', $filename,
|
||||
$file['name'], $tag );
|
||||
|
||||
$filename = wp_unique_filename( $uploads_dir, $filename );
|
||||
$new_file = path_join( $uploads_dir, $filename );
|
||||
|
||||
if ( false === @move_uploaded_file( $file['tmp_name'], $new_file ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'upload_failed' ) );
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Make sure the uploaded file is only readable for the owner process
|
||||
chmod( $new_file, 0400 );
|
||||
|
||||
if ( $submission = WPCF7_Submission::get_instance() ) {
|
||||
$submission->add_uploaded_file( $name, $new_file );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_file_messages', 10, 1 );
|
||||
|
||||
function wpcf7_file_messages( $messages ) {
|
||||
return array_merge( $messages, array(
|
||||
'upload_failed' => array(
|
||||
'description' => __( "Uploading a file fails for any reason", 'contact-form-7' ),
|
||||
'default' => __( "There was an unknown error uploading the file.", 'contact-form-7' )
|
||||
),
|
||||
|
||||
'upload_file_type_invalid' => array(
|
||||
'description' => __( "Uploaded file is not allowed for file type", 'contact-form-7' ),
|
||||
'default' => __( "You are not allowed to upload files of this type.", 'contact-form-7' )
|
||||
),
|
||||
|
||||
'upload_file_too_large' => array(
|
||||
'description' => __( "Uploaded file is too large", 'contact-form-7' ),
|
||||
'default' => __( "The file is too big.", 'contact-form-7' )
|
||||
),
|
||||
|
||||
'upload_failed_php_error' => array(
|
||||
'description' => __( "Uploading a file fails for PHP error", 'contact-form-7' ),
|
||||
'default' => __( "There was an error uploading the file.", 'contact-form-7' )
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_file', 50, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_file() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'file', __( 'file', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_file' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_file( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'file';
|
||||
|
||||
$description = __( "Generate a form-tag for a file uploading field. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/file-uploading-and-attachment/', 'contact-form-7' ), __( 'File Uploading and Attachment', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-limit' ); ?>"><?php echo esc_html( __( "File size limit (bytes)", 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="limit" class="filesize oneline option" id="<?php echo esc_attr( $args['content'] . '-limit' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>"><?php echo esc_html( __( 'Acceptable file types', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="filetypes" class="filetype oneline option" id="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To attach the file uploaded through this field to mail, you need to insert the corresponding mail-tag (%s) into the File Attachments field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/* Warning message */
|
||||
|
||||
add_action( 'wpcf7_admin_warnings',
|
||||
'wpcf7_file_display_warning_message', 10, 3 );
|
||||
|
||||
function wpcf7_file_display_warning_message( $page, $action, $object ) {
|
||||
if ( $object instanceof WPCF7_ContactForm ) {
|
||||
$contact_form = $object;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$has_tags = (bool) $contact_form->scan_form_tags(
|
||||
array( 'type' => array( 'file', 'file*' ) ) );
|
||||
|
||||
if ( ! $has_tags ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uploads_dir = wpcf7_upload_tmp_dir();
|
||||
wpcf7_init_uploads();
|
||||
|
||||
if ( ! is_dir( $uploads_dir )
|
||||
or ! wp_is_writable( $uploads_dir ) ) {
|
||||
$message = sprintf( __( 'This contact form contains file uploading fields, but the temporary folder for the files (%s) does not exist or is not writable. You can create the folder or change its permission manually.', 'contact-form-7' ), $uploads_dir );
|
||||
|
||||
echo sprintf( '<div class="notice notice-warning"><p>%s</p></div>',
|
||||
esc_html( $message ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* File uploading functions */
|
||||
|
||||
function wpcf7_acceptable_filetypes( $types = 'default', $format = 'regex' ) {
|
||||
if ( 'default' === $types
|
||||
or empty( $types ) ) {
|
||||
$types = array(
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'ppt',
|
||||
'pptx',
|
||||
'odt',
|
||||
'avi',
|
||||
'ogg',
|
||||
'm4a',
|
||||
'mov',
|
||||
'mp3',
|
||||
'mp4',
|
||||
'mpg',
|
||||
'wav',
|
||||
'wmv',
|
||||
);
|
||||
} else {
|
||||
$types_tmp = (array) $types;
|
||||
$types = array();
|
||||
|
||||
foreach ( $types_tmp as $val ) {
|
||||
if ( is_string( $val ) ) {
|
||||
$val = preg_split( '/[\s|,]+/', $val );
|
||||
}
|
||||
|
||||
$types = array_merge( $types, (array) $val );
|
||||
}
|
||||
}
|
||||
|
||||
$types = array_unique( array_filter( $types ) );
|
||||
|
||||
$output = '';
|
||||
|
||||
foreach ( $types as $type ) {
|
||||
$type = trim( $type, ' ,.|' );
|
||||
$type = str_replace(
|
||||
array( '.', '+', '*', '?' ),
|
||||
array( '\.', '\+', '\*', '\?' ),
|
||||
$type );
|
||||
|
||||
if ( '' === $type ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'attr' === $format
|
||||
or 'attribute' === $format ) {
|
||||
$output .= sprintf( '.%s', $type );
|
||||
$output .= ',';
|
||||
} else {
|
||||
$output .= $type;
|
||||
$output .= '|';
|
||||
}
|
||||
}
|
||||
|
||||
return trim( $output, ' ,|' );
|
||||
}
|
||||
|
||||
function wpcf7_init_uploads() {
|
||||
$dir = wpcf7_upload_tmp_dir();
|
||||
wp_mkdir_p( $dir );
|
||||
|
||||
$htaccess_file = path_join( $dir, '.htaccess' );
|
||||
|
||||
if ( file_exists( $htaccess_file ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $handle = fopen( $htaccess_file, 'w' ) ) {
|
||||
fwrite( $handle, "Deny from all\n" );
|
||||
fclose( $handle );
|
||||
}
|
||||
}
|
||||
|
||||
function wpcf7_maybe_add_random_dir( $dir ) {
|
||||
do {
|
||||
$rand_max = mt_getrandmax();
|
||||
$rand = zeroise( mt_rand( 0, $rand_max ), strlen( $rand_max ) );
|
||||
$dir_new = path_join( $dir, $rand );
|
||||
} while ( file_exists( $dir_new ) );
|
||||
|
||||
if ( wp_mkdir_p( $dir_new ) ) {
|
||||
return $dir_new;
|
||||
}
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
function wpcf7_upload_tmp_dir() {
|
||||
if ( defined( 'WPCF7_UPLOADS_TMP_DIR' ) ) {
|
||||
return WPCF7_UPLOADS_TMP_DIR;
|
||||
} else {
|
||||
return path_join( wpcf7_upload_dir( 'dir' ), 'wpcf7_uploads' );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'template_redirect', 'wpcf7_cleanup_upload_files', 20, 0 );
|
||||
|
||||
function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
|
||||
if ( is_admin()
|
||||
or 'GET' != $_SERVER['REQUEST_METHOD']
|
||||
or is_robots()
|
||||
or is_feed()
|
||||
or is_trackback() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dir = trailingslashit( wpcf7_upload_tmp_dir() );
|
||||
|
||||
if ( ! is_dir( $dir )
|
||||
or ! is_readable( $dir )
|
||||
or ! wp_is_writable( $dir ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$seconds = absint( $seconds );
|
||||
$max = absint( $max );
|
||||
$count = 0;
|
||||
|
||||
if ( $handle = opendir( $dir ) ) {
|
||||
while ( false !== ( $file = readdir( $handle ) ) ) {
|
||||
if ( '.' == $file
|
||||
or '..' == $file
|
||||
or '.htaccess' == $file ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$mtime = filemtime( path_join( $dir, $file ) );
|
||||
|
||||
if ( $mtime and time() < $mtime + $seconds ) { // less than $seconds old
|
||||
continue;
|
||||
}
|
||||
|
||||
wpcf7_rmdir_p( path_join( $dir, $file ) );
|
||||
$count += 1;
|
||||
|
||||
if ( $max <= $count ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
closedir( $handle );
|
||||
}
|
||||
}
|
@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
** Module for Flamingo plugin.
|
||||
** http://wordpress.org/extend/plugins/flamingo/
|
||||
**/
|
||||
|
||||
add_action( 'wpcf7_submit', 'wpcf7_flamingo_submit', 10, 2 );
|
||||
|
||||
function wpcf7_flamingo_submit( $contact_form, $result ) {
|
||||
if ( ! class_exists( 'Flamingo_Contact' )
|
||||
or ! class_exists( 'Flamingo_Inbound_Message' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $contact_form->in_demo_mode() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cases = (array) apply_filters( 'wpcf7_flamingo_submit_if',
|
||||
array( 'spam', 'mail_sent', 'mail_failed' ) );
|
||||
|
||||
if ( empty( $result['status'] )
|
||||
or ! in_array( $result['status'], $cases ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
|
||||
if ( ! $submission
|
||||
or ! $posted_data = $submission->get_posted_data() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $submission->get_meta( 'do_not_store' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fields_senseless =
|
||||
$contact_form->scan_form_tags( array( 'feature' => 'do-not-store' ) );
|
||||
|
||||
$exclude_names = array();
|
||||
|
||||
foreach ( $fields_senseless as $tag ) {
|
||||
$exclude_names[] = $tag['name'];
|
||||
}
|
||||
|
||||
$exclude_names[] = 'g-recaptcha-response';
|
||||
|
||||
foreach ( $posted_data as $key => $value ) {
|
||||
if ( '_' == substr( $key, 0, 1 )
|
||||
or in_array( $key, $exclude_names ) ) {
|
||||
unset( $posted_data[$key] );
|
||||
}
|
||||
}
|
||||
|
||||
$email = wpcf7_flamingo_get_value( 'email', $contact_form );
|
||||
$name = wpcf7_flamingo_get_value( 'name', $contact_form );
|
||||
$subject = wpcf7_flamingo_get_value( 'subject', $contact_form );
|
||||
|
||||
$meta = array();
|
||||
|
||||
$special_mail_tags = array( 'serial_number', 'remote_ip',
|
||||
'user_agent', 'url', 'date', 'time', 'post_id', 'post_name',
|
||||
'post_title', 'post_url', 'post_author', 'post_author_email',
|
||||
'site_title', 'site_description', 'site_url', 'site_admin_email',
|
||||
'user_login', 'user_email', 'user_display_name' );
|
||||
|
||||
foreach ( $special_mail_tags as $smt ) {
|
||||
$meta[$smt] = apply_filters( 'wpcf7_special_mail_tags', '',
|
||||
sprintf( '_%s', $smt ), false );
|
||||
}
|
||||
|
||||
$akismet = isset( $submission->akismet )
|
||||
? (array) $submission->akismet : null;
|
||||
|
||||
if ( 'mail_sent' == $result['status'] ) {
|
||||
$flamingo_contact = Flamingo_Contact::add( array(
|
||||
'email' => $email,
|
||||
'name' => $name,
|
||||
) );
|
||||
}
|
||||
|
||||
$post_meta = get_post_meta( $contact_form->id(), '_flamingo', true );
|
||||
|
||||
$channel_id = isset( $post_meta['channel'] )
|
||||
? (int) $post_meta['channel']
|
||||
: wpcf7_flamingo_add_channel(
|
||||
$contact_form->name(), $contact_form->title() );
|
||||
|
||||
if ( $channel_id ) {
|
||||
if ( ! isset( $post_meta['channel'] )
|
||||
or $post_meta['channel'] !== $channel_id ) {
|
||||
$post_meta = empty( $post_meta ) ? array() : (array) $post_meta;
|
||||
$post_meta = array_merge( $post_meta, array(
|
||||
'channel' => $channel_id,
|
||||
) );
|
||||
|
||||
update_post_meta( $contact_form->id(), '_flamingo', $post_meta );
|
||||
}
|
||||
|
||||
$channel = get_term( $channel_id,
|
||||
Flamingo_Inbound_Message::channel_taxonomy );
|
||||
|
||||
if ( ! $channel or is_wp_error( $channel ) ) {
|
||||
$channel = 'contact-form-7';
|
||||
} else {
|
||||
$channel = $channel->slug;
|
||||
}
|
||||
} else {
|
||||
$channel = 'contact-form-7';
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'channel' => $channel,
|
||||
'subject' => $subject,
|
||||
'from' => trim( sprintf( '%s <%s>', $name, $email ) ),
|
||||
'from_name' => $name,
|
||||
'from_email' => $email,
|
||||
'fields' => $posted_data,
|
||||
'meta' => $meta,
|
||||
'akismet' => $akismet,
|
||||
'spam' => ( 'spam' == $result['status'] ),
|
||||
'consent' => $submission->collect_consent(),
|
||||
);
|
||||
|
||||
$flamingo_inbound = Flamingo_Inbound_Message::add( $args );
|
||||
|
||||
$result += array(
|
||||
'flamingo_contact_id' =>
|
||||
empty( $flamingo_contact ) ? 0 : absint( $flamingo_contact->id ),
|
||||
'flamingo_inbound_id' =>
|
||||
empty( $flamingo_inbound ) ? 0 : absint( $flamingo_inbound->id ),
|
||||
);
|
||||
|
||||
do_action( 'wpcf7_after_flamingo', $result );
|
||||
}
|
||||
|
||||
function wpcf7_flamingo_get_value( $field, $contact_form ) {
|
||||
if ( empty( $field )
|
||||
or empty( $contact_form ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$value = '';
|
||||
|
||||
if ( in_array( $field, array( 'email', 'name', 'subject' ) ) ) {
|
||||
$templates = $contact_form->additional_setting( 'flamingo_' . $field );
|
||||
|
||||
if ( empty( $templates[0] ) ) {
|
||||
$template = sprintf( '[your-%s]', $field );
|
||||
} else {
|
||||
$template = trim( wpcf7_strip_quote( $templates[0] ) );
|
||||
}
|
||||
|
||||
$value = wpcf7_mail_replace_tags( $template );
|
||||
}
|
||||
|
||||
$value = apply_filters( 'wpcf7_flamingo_get_value', $value,
|
||||
$field, $contact_form );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function wpcf7_flamingo_add_channel( $slug, $name = '' ) {
|
||||
if ( ! class_exists( 'Flamingo_Inbound_Message' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parent = term_exists( 'contact-form-7',
|
||||
Flamingo_Inbound_Message::channel_taxonomy );
|
||||
|
||||
if ( ! $parent ) {
|
||||
$parent = wp_insert_term( __( 'Contact Form 7', 'contact-form-7' ),
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
array( 'slug' => 'contact-form-7' ) );
|
||||
|
||||
if ( is_wp_error( $parent ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$parent = (int) $parent['term_id'];
|
||||
|
||||
if ( ! is_taxonomy_hierarchical( Flamingo_Inbound_Message::channel_taxonomy ) ) {
|
||||
// backward compat for Flamingo 1.0.4 and lower
|
||||
return $parent;
|
||||
}
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
$name = $slug;
|
||||
}
|
||||
|
||||
$channel = term_exists( $slug,
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
$parent );
|
||||
|
||||
if ( ! $channel ) {
|
||||
$channel = wp_insert_term( $name,
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
array( 'slug' => $slug, 'parent' => $parent ) );
|
||||
|
||||
if ( is_wp_error( $channel ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) $channel['term_id'];
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_after_update', 'wpcf7_flamingo_update_channel', 10, 1 );
|
||||
|
||||
function wpcf7_flamingo_update_channel( $contact_form ) {
|
||||
if ( ! class_exists( 'Flamingo_Inbound_Message' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$post_meta = get_post_meta( $contact_form->id(), '_flamingo', true );
|
||||
|
||||
$channel = isset( $post_meta['channel'] )
|
||||
? get_term( $post_meta['channel'],
|
||||
Flamingo_Inbound_Message::channel_taxonomy )
|
||||
: get_term_by( 'slug', $contact_form->name(),
|
||||
Flamingo_Inbound_Message::channel_taxonomy );
|
||||
|
||||
if ( ! $channel or is_wp_error( $channel ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $channel->name !== wp_unslash( $contact_form->title() ) ) {
|
||||
wp_update_term( $channel->term_id,
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
array(
|
||||
'name' => $contact_form->title(),
|
||||
'slug' => $contact_form->name(),
|
||||
'parent' => $channel->parent,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_special_mail_tags', 'wpcf7_flamingo_serial_number', 10, 3 );
|
||||
|
||||
function wpcf7_flamingo_serial_number( $output, $name, $html ) {
|
||||
if ( '_serial_number' != $name ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Flamingo_Inbound_Message' )
|
||||
or ! method_exists( 'Flamingo_Inbound_Message', 'count' ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ( ! $contact_form = WPCF7_ContactForm::get_current() ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$post_meta = get_post_meta( $contact_form->id(), '_flamingo', true );
|
||||
|
||||
$channel_id = isset( $post_meta['channel'] )
|
||||
? (int) $post_meta['channel']
|
||||
: wpcf7_flamingo_add_channel(
|
||||
$contact_form->name(), $contact_form->title() );
|
||||
|
||||
if ( $channel_id ) {
|
||||
return 1 + (int) Flamingo_Inbound_Message::count(
|
||||
array( 'channel_id' => $channel_id ) );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_hidden', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_hidden() {
|
||||
wpcf7_add_form_tag( 'hidden',
|
||||
'wpcf7_hidden_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'display-hidden' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_hidden_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
|
||||
$value = (string) reset( $tag->values );
|
||||
$value = $tag->get_default_option( $value );
|
||||
$atts['value'] = $value;
|
||||
|
||||
$atts['type'] = 'hidden';
|
||||
$atts['name'] = $tag->name;
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf( '<input %s />', $atts );
|
||||
return $html;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
** Retrieve list data from the Listo plugin.
|
||||
** Listo http://wordpress.org/plugins/listo/
|
||||
**/
|
||||
|
||||
add_filter( 'wpcf7_form_tag_data_option', 'wpcf7_listo', 10, 3 );
|
||||
|
||||
function wpcf7_listo( $data, $options, $args ) {
|
||||
if ( ! function_exists( 'listo' ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
$contact_form = wpcf7_get_current_contact_form();
|
||||
$args['locale'] = $contact_form->locale();
|
||||
|
||||
foreach ( (array) $options as $option ) {
|
||||
$option = explode( '.', $option );
|
||||
$type = $option[0];
|
||||
$args['group'] = isset( $option[1] ) ? $option[1] : null;
|
||||
|
||||
if ( $list = listo( $type, $args ) ) {
|
||||
$data = array_merge( (array) $data, $list );
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for the following types of tags:
|
||||
** [number] and [number*] # Number
|
||||
** [range] and [range*] # Range
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_number', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_number() {
|
||||
wpcf7_add_form_tag( array( 'number', 'number*', 'range', 'range*' ),
|
||||
'wpcf7_number_form_tag_handler', array( 'name-attr' => true ) );
|
||||
}
|
||||
|
||||
function wpcf7_number_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
$class .= ' wpcf7-validates-as-number';
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
$atts['min'] = $tag->get_option( 'min', 'signed_int', true );
|
||||
$atts['max'] = $tag->get_option( 'max', 'signed_int', true );
|
||||
$atts['step'] = $tag->get_option( 'step', 'int', true );
|
||||
|
||||
if ( $tag->has_option( 'readonly' ) ) {
|
||||
$atts['readonly'] = 'readonly';
|
||||
}
|
||||
|
||||
if ( $tag->is_required() ) {
|
||||
$atts['aria-required'] = 'true';
|
||||
}
|
||||
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$value = (string) reset( $tag->values );
|
||||
|
||||
if ( $tag->has_option( 'placeholder' )
|
||||
or $tag->has_option( 'watermark' ) ) {
|
||||
$atts['placeholder'] = $value;
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$value = $tag->get_default_option( $value );
|
||||
|
||||
$value = wpcf7_get_hangover( $tag->name, $value );
|
||||
|
||||
$atts['value'] = $value;
|
||||
|
||||
if ( wpcf7_support_html5() ) {
|
||||
$atts['type'] = $tag->basetype;
|
||||
} else {
|
||||
$atts['type'] = 'text';
|
||||
}
|
||||
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_number', 'wpcf7_number_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_number*', 'wpcf7_number_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_range', 'wpcf7_number_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_range*', 'wpcf7_number_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_number_validation_filter( $result, $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
$value = isset( $_POST[$name] )
|
||||
? trim( strtr( (string) $_POST[$name], "\n", " " ) )
|
||||
: '';
|
||||
|
||||
$min = $tag->get_option( 'min', 'signed_int', true );
|
||||
$max = $tag->get_option( 'max', 'signed_int', true );
|
||||
|
||||
if ( $tag->is_required() and '' == $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
} elseif ( '' != $value and ! wpcf7_is_number( $value ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_number' ) );
|
||||
} elseif ( '' != $value and '' != $min and (float) $value < (float) $min ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'number_too_small' ) );
|
||||
} elseif ( '' != $value and '' != $max and (float) $max < (float) $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'number_too_large' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_number_messages', 10, 1 );
|
||||
|
||||
function wpcf7_number_messages( $messages ) {
|
||||
return array_merge( $messages, array(
|
||||
'invalid_number' => array(
|
||||
'description' => __( "Number format that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' => __( "The number format is invalid.", 'contact-form-7' )
|
||||
),
|
||||
|
||||
'number_too_small' => array(
|
||||
'description' => __( "Number is smaller than minimum limit", 'contact-form-7' ),
|
||||
'default' => __( "The number is smaller than the minimum allowed.", 'contact-form-7' )
|
||||
),
|
||||
|
||||
'number_too_large' => array(
|
||||
'description' => __( "Number is larger than maximum limit", 'contact-form-7' ),
|
||||
'default' => __( "The number is larger than the maximum allowed.", 'contact-form-7' )
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_number', 18, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_number() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'number', __( 'number', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_number' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_number( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'number';
|
||||
|
||||
$description = __( "Generate a form-tag for a field for numeric value input. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/number-fields/', 'contact-form-7' ), __( 'Number Fields', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<select name="tagtype">
|
||||
<option value="number" selected="selected"><?php echo esc_html( __( 'Spinbox', 'contact-form-7' ) ); ?></option>
|
||||
<option value="range"><?php echo esc_html( __( 'Slider', 'contact-form-7' ) ); ?></option>
|
||||
</select>
|
||||
<br />
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></legend>
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Min', 'contact-form-7' ) ); ?>
|
||||
<input type="number" name="min" class="numeric option" />
|
||||
</label>
|
||||
–
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Max', 'contact-form-7' ) ); ?>
|
||||
<input type="number" name="max" class="numeric option" />
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [quiz]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_quiz', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_quiz() {
|
||||
wpcf7_add_form_tag( 'quiz',
|
||||
'wpcf7_quiz_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'do-not-store' => true,
|
||||
'not-for-mail' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_quiz_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['size'] = $tag->get_size_option( '40' );
|
||||
$atts['maxlength'] = $tag->get_maxlength_option();
|
||||
$atts['minlength'] = $tag->get_minlength_option();
|
||||
|
||||
if ( $atts['maxlength'] and $atts['minlength']
|
||||
and $atts['maxlength'] < $atts['minlength'] ) {
|
||||
unset( $atts['maxlength'], $atts['minlength'] );
|
||||
}
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
$atts['autocomplete'] = 'off';
|
||||
$atts['aria-required'] = 'true';
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$pipes = $tag->pipes;
|
||||
|
||||
if ( $pipes instanceof WPCF7_Pipes
|
||||
and ! $pipes->zero() ) {
|
||||
$pipe = $pipes->random_pipe();
|
||||
$question = $pipe->before;
|
||||
$answer = $pipe->after;
|
||||
} else {
|
||||
// default quiz
|
||||
$question = '1+1=?';
|
||||
$answer = '2';
|
||||
}
|
||||
|
||||
$answer = wpcf7_canonicalize( $answer );
|
||||
|
||||
$atts['type'] = 'text';
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><label><span class="wpcf7-quiz-label">%2$s</span> <input %3$s /></label><input type="hidden" name="_wpcf7_quiz_answer_%4$s" value="%5$s" />%6$s</span>',
|
||||
sanitize_html_class( $tag->name ),
|
||||
esc_html( $question ), $atts, $tag->name,
|
||||
wp_hash( $answer, 'wpcf7_quiz' ), $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_quiz', 'wpcf7_quiz_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_quiz_validation_filter( $result, $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
$answer = isset( $_POST[$name] ) ? wpcf7_canonicalize( $_POST[$name] ) : '';
|
||||
$answer = wp_unslash( $answer );
|
||||
|
||||
$answer_hash = wp_hash( $answer, 'wpcf7_quiz' );
|
||||
|
||||
$expected_hash = isset( $_POST['_wpcf7_quiz_answer_' . $name] )
|
||||
? (string) $_POST['_wpcf7_quiz_answer_' . $name]
|
||||
: '';
|
||||
|
||||
if ( $answer_hash != $expected_hash ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'quiz_answer_not_correct' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Ajax echo filter */
|
||||
|
||||
add_filter( 'wpcf7_ajax_onload', 'wpcf7_quiz_ajax_refill', 10, 1 );
|
||||
add_filter( 'wpcf7_ajax_json_echo', 'wpcf7_quiz_ajax_refill', 10, 1 );
|
||||
|
||||
function wpcf7_quiz_ajax_refill( $items ) {
|
||||
if ( ! is_array( $items ) ) {
|
||||
return $items;
|
||||
}
|
||||
|
||||
$fes = wpcf7_scan_form_tags( array( 'type' => 'quiz' ) );
|
||||
|
||||
if ( empty( $fes ) ) {
|
||||
return $items;
|
||||
}
|
||||
|
||||
$refill = array();
|
||||
|
||||
foreach ( $fes as $fe ) {
|
||||
$name = $fe['name'];
|
||||
$pipes = $fe['pipes'];
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $pipes instanceof WPCF7_Pipes
|
||||
and ! $pipes->zero() ) {
|
||||
$pipe = $pipes->random_pipe();
|
||||
$question = $pipe->before;
|
||||
$answer = $pipe->after;
|
||||
} else {
|
||||
// default quiz
|
||||
$question = '1+1=?';
|
||||
$answer = '2';
|
||||
}
|
||||
|
||||
$answer = wpcf7_canonicalize( $answer );
|
||||
|
||||
$refill[$name] = array( $question, wp_hash( $answer, 'wpcf7_quiz' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $refill ) ) {
|
||||
$items['quiz'] = $refill;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_quiz_messages', 10, 1 );
|
||||
|
||||
function wpcf7_quiz_messages( $messages ) {
|
||||
$messages = array_merge( $messages, array(
|
||||
'quiz_answer_not_correct' => array(
|
||||
'description' =>
|
||||
__( "Sender doesn't enter the correct answer to the quiz", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "The answer to the quiz is incorrect.", 'contact-form-7' ),
|
||||
),
|
||||
) );
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_quiz', 40, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_quiz() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'quiz', __( 'quiz', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_quiz' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_quiz( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'quiz';
|
||||
|
||||
$description = __( "Generate a form-tag for a question-answer pair. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/quiz/', 'contact-form-7' ), __( 'Quiz', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Questions and answers', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Questions and answers', 'contact-form-7' ) ); ?></legend>
|
||||
<textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea><br />
|
||||
<label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One pipe-separated question-answer pair (e.g. The capital of Brazil?|Rio) per line.", 'contact-form-7' ) ); ?></span></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,655 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [captchac] and [captchar]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_captcha', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_captcha() {
|
||||
// CAPTCHA-Challenge (image)
|
||||
wpcf7_add_form_tag( 'captchac',
|
||||
'wpcf7_captchac_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'zero-controls-container' => true,
|
||||
'not-for-mail' => true,
|
||||
)
|
||||
);
|
||||
|
||||
// CAPTCHA-Response (input)
|
||||
wpcf7_add_form_tag( 'captchar',
|
||||
'wpcf7_captchar_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'do-not-store' => true,
|
||||
'not-for-mail' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_captchac_form_tag_handler( $tag ) {
|
||||
if ( ! class_exists( 'ReallySimpleCaptcha' ) ) {
|
||||
$error = sprintf(
|
||||
/* translators: %s: link labeled 'Really Simple CAPTCHA' */
|
||||
esc_html( __( "To use CAPTCHA, you need %s plugin installed.", 'contact-form-7' ) ),
|
||||
wpcf7_link( 'https://wordpress.org/plugins/really-simple-captcha/', 'Really Simple CAPTCHA' ) );
|
||||
|
||||
return sprintf( '<em>%s</em>', $error );
|
||||
}
|
||||
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
$class .= ' wpcf7-captcha-' . $tag->name;
|
||||
|
||||
$atts = array();
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
|
||||
$op = array( // Default
|
||||
'img_size' => array( 72, 24 ),
|
||||
'base' => array( 6, 18 ),
|
||||
'font_size' => 14,
|
||||
'font_char_width' => 15,
|
||||
);
|
||||
|
||||
$op = array_merge( $op, wpcf7_captchac_options( $tag->options ) );
|
||||
|
||||
if ( ! $filename = wpcf7_generate_captcha( $op ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( ! empty( $op['img_size'] ) ) {
|
||||
if ( isset( $op['img_size'][0] ) ) {
|
||||
$atts['width'] = $op['img_size'][0];
|
||||
}
|
||||
|
||||
if ( isset( $op['img_size'][1] ) ) {
|
||||
$atts['height'] = $op['img_size'][1];
|
||||
}
|
||||
}
|
||||
|
||||
$atts['alt'] = 'captcha';
|
||||
$atts['src'] = wpcf7_captcha_url( $filename );
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$prefix = substr( $filename, 0, strrpos( $filename, '.' ) );
|
||||
|
||||
$html = sprintf(
|
||||
'<input type="hidden" name="_wpcf7_captcha_challenge_%1$s" value="%2$s" /><img %3$s />',
|
||||
$tag->name, esc_attr( $prefix ), $atts );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function wpcf7_captchar_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['size'] = $tag->get_size_option( '40' );
|
||||
$atts['maxlength'] = $tag->get_maxlength_option();
|
||||
$atts['minlength'] = $tag->get_minlength_option();
|
||||
|
||||
if ( $atts['maxlength'] and $atts['minlength']
|
||||
and $atts['maxlength'] < $atts['minlength'] ) {
|
||||
unset( $atts['maxlength'], $atts['minlength'] );
|
||||
}
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
$atts['autocomplete'] = 'off';
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$value = (string) reset( $tag->values );
|
||||
|
||||
if ( wpcf7_is_posted() ) {
|
||||
$value = '';
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'placeholder' )
|
||||
or $tag->has_option( 'watermark' ) ) {
|
||||
$atts['placeholder'] = $value;
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$atts['value'] = $value;
|
||||
$atts['type'] = 'text';
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_captchar',
|
||||
'wpcf7_captcha_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_captcha_validation_filter( $result, $tag ) {
|
||||
$type = $tag->type;
|
||||
$name = $tag->name;
|
||||
|
||||
$captchac = '_wpcf7_captcha_challenge_' . $name;
|
||||
|
||||
$prefix = isset( $_POST[$captchac] ) ? (string) $_POST[$captchac] : '';
|
||||
$response = isset( $_POST[$name] ) ? (string) $_POST[$name] : '';
|
||||
$response = wpcf7_canonicalize( $response );
|
||||
|
||||
if ( 0 == strlen( $prefix )
|
||||
or ! wpcf7_check_captcha( $prefix, $response ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'captcha_not_match' ) );
|
||||
}
|
||||
|
||||
if ( 0 != strlen( $prefix ) ) {
|
||||
wpcf7_remove_captcha( $prefix );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Ajax echo filter */
|
||||
|
||||
add_filter( 'wpcf7_ajax_onload', 'wpcf7_captcha_ajax_refill', 10, 1 );
|
||||
add_filter( 'wpcf7_ajax_json_echo', 'wpcf7_captcha_ajax_refill', 10, 1 );
|
||||
|
||||
function wpcf7_captcha_ajax_refill( $items ) {
|
||||
if ( ! is_array( $items ) ) {
|
||||
return $items;
|
||||
}
|
||||
|
||||
$tags = wpcf7_scan_form_tags( array( 'type' => 'captchac' ) );
|
||||
|
||||
if ( empty( $tags ) ) {
|
||||
return $items;
|
||||
}
|
||||
|
||||
$refill = array();
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$name = $tag->name;
|
||||
$options = $tag->options;
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$op = wpcf7_captchac_options( $options );
|
||||
|
||||
if ( $filename = wpcf7_generate_captcha( $op ) ) {
|
||||
$captcha_url = wpcf7_captcha_url( $filename );
|
||||
$refill[$name] = $captcha_url;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $refill ) ) {
|
||||
$items['captcha'] = $refill;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_captcha_messages', 10, 1 );
|
||||
|
||||
function wpcf7_captcha_messages( $messages ) {
|
||||
$messages = array_merge( $messages, array(
|
||||
'captcha_not_match' => array(
|
||||
'description' =>
|
||||
__( "The code that sender entered does not match the CAPTCHA", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( 'Your entered code is incorrect.', 'contact-form-7' ),
|
||||
),
|
||||
) );
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_captcha', 46, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_captcha() {
|
||||
if ( ! wpcf7_use_really_simple_captcha() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'captcha',
|
||||
__( 'CAPTCHA (Really Simple CAPTCHA)', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_captcha' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_captcha( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
if ( ! class_exists( 'ReallySimpleCaptcha' ) ) {
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php
|
||||
echo sprintf(
|
||||
/* translators: %s: link labeled 'Really Simple CAPTCHA' */
|
||||
esc_html( __( "To use CAPTCHA, you first need to install and activate %s plugin.", 'contact-form-7' ) ),
|
||||
wpcf7_link( 'https://wordpress.org/plugins/really-simple-captcha/', 'Really Simple CAPTCHA' )
|
||||
);
|
||||
?></legend>
|
||||
</fieldset>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$description = __( "Generate form-tags for a CAPTCHA image and corresponding response input field. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/captcha/', 'contact-form-7' ), __( 'CAPTCHA', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table class="form-table scope captchac">
|
||||
<caption><?php echo esc_html( __( "Image settings", 'contact-form-7' ) ); ?></caption>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchac-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchac-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchac-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchac-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table class="form-table scope captchar">
|
||||
<caption><?php echo esc_html( __( "Input field settings", 'contact-form-7' ) ); ?></caption>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchar-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchar-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchar-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchar-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="captcha" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/* Warning message */
|
||||
|
||||
add_action( 'wpcf7_admin_warnings',
|
||||
'wpcf7_captcha_display_warning_message', 10, 3 );
|
||||
|
||||
function wpcf7_captcha_display_warning_message( $page, $action, $object ) {
|
||||
if ( $object instanceof WPCF7_ContactForm ) {
|
||||
$contact_form = $object;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$has_tags = (bool) $contact_form->scan_form_tags(
|
||||
array( 'type' => array( 'captchac' ) ) );
|
||||
|
||||
if ( ! $has_tags ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ReallySimpleCaptcha' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uploads_dir = wpcf7_captcha_tmp_dir();
|
||||
wpcf7_init_captcha();
|
||||
|
||||
if ( ! is_dir( $uploads_dir )
|
||||
or ! wp_is_writable( $uploads_dir ) ) {
|
||||
$message = sprintf( __( 'This contact form contains CAPTCHA fields, but the temporary folder for the files (%s) does not exist or is not writable. You can create the folder or change its permission manually.', 'contact-form-7' ), $uploads_dir );
|
||||
|
||||
echo '<div class="notice notice-warning"><p>' . esc_html( $message ) . '</p></div>';
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'imagecreatetruecolor' )
|
||||
or ! function_exists( 'imagettftext' ) ) {
|
||||
$message = __( "This contact form contains CAPTCHA fields, but the necessary libraries (GD and FreeType) are not available on your server.", 'contact-form-7' );
|
||||
|
||||
echo '<div class="notice notice-warning"><p>' . esc_html( $message ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* CAPTCHA functions */
|
||||
|
||||
function wpcf7_init_captcha() {
|
||||
static $captcha = null;
|
||||
|
||||
if ( $captcha ) {
|
||||
return $captcha;
|
||||
}
|
||||
|
||||
if ( class_exists( 'ReallySimpleCaptcha' ) ) {
|
||||
$captcha = new ReallySimpleCaptcha();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dir = trailingslashit( wpcf7_captcha_tmp_dir() );
|
||||
|
||||
$captcha->tmp_dir = $dir;
|
||||
|
||||
if ( is_callable( array( $captcha, 'make_tmp_dir' ) ) ) {
|
||||
$result = $captcha->make_tmp_dir();
|
||||
|
||||
if ( ! $result ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $captcha;
|
||||
}
|
||||
|
||||
if ( wp_mkdir_p( $dir ) ) {
|
||||
$htaccess_file = path_join( $dir, '.htaccess' );
|
||||
|
||||
if ( file_exists( $htaccess_file ) ) {
|
||||
return $captcha;
|
||||
}
|
||||
|
||||
if ( $handle = fopen( $htaccess_file, 'w' ) ) {
|
||||
fwrite( $handle, 'Order deny,allow' . "\n" );
|
||||
fwrite( $handle, 'Deny from all' . "\n" );
|
||||
fwrite( $handle, '<Files ~ "^[0-9A-Za-z]+\\.(jpeg|gif|png)$">' . "\n" );
|
||||
fwrite( $handle, ' Allow from all' . "\n" );
|
||||
fwrite( $handle, '</Files>' . "\n" );
|
||||
fclose( $handle );
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $captcha;
|
||||
}
|
||||
|
||||
function wpcf7_captcha_tmp_dir() {
|
||||
if ( defined( 'WPCF7_CAPTCHA_TMP_DIR' ) ) {
|
||||
return WPCF7_CAPTCHA_TMP_DIR;
|
||||
} else {
|
||||
return path_join( wpcf7_upload_dir( 'dir' ), 'wpcf7_captcha' );
|
||||
}
|
||||
}
|
||||
|
||||
function wpcf7_captcha_tmp_url() {
|
||||
if ( defined( 'WPCF7_CAPTCHA_TMP_URL' ) ) {
|
||||
return WPCF7_CAPTCHA_TMP_URL;
|
||||
} else {
|
||||
return path_join( wpcf7_upload_dir( 'url' ), 'wpcf7_captcha' );
|
||||
}
|
||||
}
|
||||
|
||||
function wpcf7_captcha_url( $filename ) {
|
||||
$url = path_join( wpcf7_captcha_tmp_url(), $filename );
|
||||
|
||||
if ( is_ssl()
|
||||
and 'http:' == substr( $url, 0, 5 ) ) {
|
||||
$url = 'https:' . substr( $url, 5 );
|
||||
}
|
||||
|
||||
return apply_filters( 'wpcf7_captcha_url', esc_url_raw( $url ) );
|
||||
}
|
||||
|
||||
function wpcf7_generate_captcha( $options = null ) {
|
||||
if ( ! $captcha = wpcf7_init_captcha() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! is_dir( $captcha->tmp_dir )
|
||||
or ! wp_is_writable( $captcha->tmp_dir ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$img_type = imagetypes();
|
||||
|
||||
if ( $img_type & IMG_PNG ) {
|
||||
$captcha->img_type = 'png';
|
||||
} elseif ( $img_type & IMG_GIF ) {
|
||||
$captcha->img_type = 'gif';
|
||||
} elseif ( $img_type & IMG_JPG ) {
|
||||
$captcha->img_type = 'jpeg';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( is_array( $options ) ) {
|
||||
if ( isset( $options['img_size'] ) ) {
|
||||
$captcha->img_size = $options['img_size'];
|
||||
}
|
||||
|
||||
if ( isset( $options['base'] ) ) {
|
||||
$captcha->base = $options['base'];
|
||||
}
|
||||
|
||||
if ( isset( $options['font_size'] ) ) {
|
||||
$captcha->font_size = $options['font_size'];
|
||||
}
|
||||
|
||||
if ( isset( $options['font_char_width'] ) ) {
|
||||
$captcha->font_char_width = $options['font_char_width'];
|
||||
}
|
||||
|
||||
if ( isset( $options['fg'] ) ) {
|
||||
$captcha->fg = $options['fg'];
|
||||
}
|
||||
|
||||
if ( isset( $options['bg'] ) ) {
|
||||
$captcha->bg = $options['bg'];
|
||||
}
|
||||
}
|
||||
|
||||
$prefix = wp_rand();
|
||||
$captcha_word = $captcha->generate_random_word();
|
||||
return $captcha->generate_image( $prefix, $captcha_word );
|
||||
}
|
||||
|
||||
function wpcf7_check_captcha( $prefix, $response ) {
|
||||
if ( ! $captcha = wpcf7_init_captcha() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $captcha->check( $prefix, $response );
|
||||
}
|
||||
|
||||
function wpcf7_remove_captcha( $prefix ) {
|
||||
if ( ! $captcha = wpcf7_init_captcha() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Contact Form 7 generates $prefix with wp_rand()
|
||||
if ( preg_match( '/[^0-9]/', $prefix ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$captcha->remove( $prefix );
|
||||
}
|
||||
|
||||
add_action( 'template_redirect', 'wpcf7_cleanup_captcha_files', 20, 0 );
|
||||
|
||||
function wpcf7_cleanup_captcha_files() {
|
||||
if ( ! $captcha = wpcf7_init_captcha() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( is_callable( array( $captcha, 'cleanup' ) ) ) {
|
||||
return $captcha->cleanup();
|
||||
}
|
||||
|
||||
$dir = trailingslashit( wpcf7_captcha_tmp_dir() );
|
||||
|
||||
if ( ! is_dir( $dir )
|
||||
or ! is_readable( $dir )
|
||||
or ! wp_is_writable( $dir ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $handle = opendir( $dir ) ) {
|
||||
while ( false !== ( $file = readdir( $handle ) ) ) {
|
||||
if ( ! preg_match( '/^[0-9]+\.(php|txt|png|gif|jpeg)$/', $file ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stat = stat( path_join( $dir, $file ) );
|
||||
|
||||
if ( $stat['mtime'] + 3600 < time() ) { // 3600 secs == 1 hour
|
||||
@unlink( path_join( $dir, $file ) );
|
||||
}
|
||||
}
|
||||
|
||||
closedir( $handle );
|
||||
}
|
||||
}
|
||||
|
||||
function wpcf7_captchac_options( $options ) {
|
||||
if ( ! is_array( $options ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$op = array();
|
||||
$image_size_array = preg_grep( '%^size:[smlSML]$%', $options );
|
||||
|
||||
if ( $image_size = array_shift( $image_size_array ) ) {
|
||||
preg_match( '%^size:([smlSML])$%', $image_size, $is_matches );
|
||||
|
||||
switch ( strtolower( $is_matches[1] ) ) {
|
||||
case 's':
|
||||
$op['img_size'] = array( 60, 20 );
|
||||
$op['base'] = array( 6, 15 );
|
||||
$op['font_size'] = 11;
|
||||
$op['font_char_width'] = 13;
|
||||
break;
|
||||
case 'l':
|
||||
$op['img_size'] = array( 84, 28 );
|
||||
$op['base'] = array( 6, 20 );
|
||||
$op['font_size'] = 17;
|
||||
$op['font_char_width'] = 19;
|
||||
break;
|
||||
case 'm':
|
||||
default:
|
||||
$op['img_size'] = array( 72, 24 );
|
||||
$op['base'] = array( 6, 18 );
|
||||
$op['font_size'] = 14;
|
||||
$op['font_char_width'] = 15;
|
||||
}
|
||||
}
|
||||
|
||||
$fg_color_array = preg_grep(
|
||||
'%^fg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $options );
|
||||
|
||||
if ( $fg_color = array_shift( $fg_color_array ) ) {
|
||||
preg_match( '%^fg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%',
|
||||
$fg_color, $fc_matches );
|
||||
|
||||
if ( 3 == strlen( $fc_matches[1] ) ) {
|
||||
$r = substr( $fc_matches[1], 0, 1 );
|
||||
$g = substr( $fc_matches[1], 1, 1 );
|
||||
$b = substr( $fc_matches[1], 2, 1 );
|
||||
|
||||
$op['fg'] = array(
|
||||
hexdec( $r . $r ),
|
||||
hexdec( $g . $g ),
|
||||
hexdec( $b . $b ),
|
||||
);
|
||||
} elseif ( 6 == strlen( $fc_matches[1] ) ) {
|
||||
$r = substr( $fc_matches[1], 0, 2 );
|
||||
$g = substr( $fc_matches[1], 2, 2 );
|
||||
$b = substr( $fc_matches[1], 4, 2 );
|
||||
|
||||
$op['fg'] = array(
|
||||
hexdec( $r ),
|
||||
hexdec( $g ),
|
||||
hexdec( $b ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$bg_color_array = preg_grep(
|
||||
'%^bg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $options );
|
||||
|
||||
if ( $bg_color = array_shift( $bg_color_array ) ) {
|
||||
preg_match( '%^bg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%',
|
||||
$bg_color, $bc_matches );
|
||||
|
||||
if ( 3 == strlen( $bc_matches[1] ) ) {
|
||||
$r = substr( $bc_matches[1], 0, 1 );
|
||||
$g = substr( $bc_matches[1], 1, 1 );
|
||||
$b = substr( $bc_matches[1], 2, 1 );
|
||||
|
||||
$op['bg'] = array(
|
||||
hexdec( $r . $r ),
|
||||
hexdec( $g . $g ),
|
||||
hexdec( $b . $b ),
|
||||
);
|
||||
} elseif ( 6 == strlen( $bc_matches[1] ) ) {
|
||||
$r = substr( $bc_matches[1], 0, 2 );
|
||||
$g = substr( $bc_matches[1], 2, 2 );
|
||||
$b = substr( $bc_matches[1], 4, 2 );
|
||||
|
||||
$op['bg'] = array(
|
||||
hexdec( $r ),
|
||||
hexdec( $g ),
|
||||
hexdec( $b ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $op;
|
||||
}
|
@ -0,0 +1,446 @@
|
||||
<?php
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_recaptcha_register_service', 10, 0 );
|
||||
|
||||
function wpcf7_recaptcha_register_service() {
|
||||
$integration = WPCF7_Integration::get_instance();
|
||||
|
||||
$integration->add_category( 'captcha',
|
||||
__( 'CAPTCHA', 'contact-form-7' )
|
||||
);
|
||||
|
||||
$integration->add_service( 'recaptcha',
|
||||
WPCF7_RECAPTCHA::get_instance()
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts', 10, 0 );
|
||||
|
||||
function wpcf7_recaptcha_enqueue_scripts() {
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'render' => $service->get_sitekey(),
|
||||
),
|
||||
'https://www.google.com/recaptcha/api.js'
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'google-recaptcha', $url, array(), '3.0', true );
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_form_hidden_fields',
|
||||
'wpcf7_recaptcha_add_hidden_fields', 100, 1 );
|
||||
|
||||
function wpcf7_recaptcha_add_hidden_fields( $fields ) {
|
||||
return array_merge( $fields, array(
|
||||
'g-recaptcha-response' => '',
|
||||
) );
|
||||
}
|
||||
|
||||
add_action( 'wp_footer', 'wpcf7_recaptcha_onload_script', 40, 0 );
|
||||
|
||||
function wpcf7_recaptcha_onload_script() {
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_script_is( 'google-recaptcha', 'done' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
( function( grecaptcha, sitekey ) {
|
||||
|
||||
var wpcf7recaptcha = {
|
||||
execute: function() {
|
||||
grecaptcha.execute(
|
||||
sitekey,
|
||||
{ action: 'homepage' }
|
||||
).then( function( token ) {
|
||||
var forms = document.getElementsByTagName( 'form' );
|
||||
|
||||
for ( var i = 0; i < forms.length; i++ ) {
|
||||
var fields = forms[ i ].getElementsByTagName( 'input' );
|
||||
|
||||
for ( var j = 0; j < fields.length; j++ ) {
|
||||
var field = fields[ j ];
|
||||
|
||||
if ( 'g-recaptcha-response' === field.getAttribute( 'name' ) ) {
|
||||
field.setAttribute( 'value', token );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
grecaptcha.ready( wpcf7recaptcha.execute );
|
||||
|
||||
document.addEventListener( 'wpcf7submit', wpcf7recaptcha.execute, false );
|
||||
|
||||
} )( grecaptcha, '<?php echo esc_js( $service->get_sitekey() ); ?>' );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_spam', 'wpcf7_recaptcha_verify_response', 9, 1 );
|
||||
|
||||
function wpcf7_recaptcha_verify_response( $spam ) {
|
||||
if ( $spam ) {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
$token = isset( $_POST['g-recaptcha-response'] )
|
||||
? trim( $_POST['g-recaptcha-response'] ) : '';
|
||||
|
||||
return ! $service->verify( $token );
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_recaptcha_add_form_tag_recaptcha', 10, 0 );
|
||||
|
||||
function wpcf7_recaptcha_add_form_tag_recaptcha() {
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpcf7_add_form_tag( 'recaptcha',
|
||||
'__return_empty_string', // no output
|
||||
array( 'display-block' => true )
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_upgrade', 'wpcf7_upgrade_recaptcha_v2_v3', 10, 2 );
|
||||
|
||||
function wpcf7_upgrade_recaptcha_v2_v3( $new_ver, $old_ver ) {
|
||||
if ( version_compare( '5.1-dev', $old_ver, '<=' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Maybe v2 keys are used now. Warning necessary.
|
||||
WPCF7::update_option( 'recaptcha_v2_v3_warning', true );
|
||||
WPCF7::update_option( 'recaptcha', null );
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_admin_menu', 'wpcf7_admin_init_recaptcha_v2_v3', 10, 0 );
|
||||
|
||||
function wpcf7_admin_init_recaptcha_v2_v3() {
|
||||
if ( ! WPCF7::get_option( 'recaptcha_v2_v3_warning' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_admin_menu_change_notice',
|
||||
'wpcf7_admin_menu_change_notice_recaptcha_v2_v3', 10, 1 );
|
||||
|
||||
add_action( 'wpcf7_admin_warnings',
|
||||
'wpcf7_admin_warnings_recaptcha_v2_v3', 5, 3 );
|
||||
}
|
||||
|
||||
function wpcf7_admin_menu_change_notice_recaptcha_v2_v3( $counts ) {
|
||||
$counts['wpcf7-integration'] += 1;
|
||||
return $counts;
|
||||
}
|
||||
|
||||
function wpcf7_admin_warnings_recaptcha_v2_v3( $page, $action, $object ) {
|
||||
if ( 'wpcf7-integration' !== $page ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
esc_html( __( "API keys for reCAPTCHA v3 are different from those for v2; keys for v2 don’t work with the v3 API. You need to register your sites again to get new keys for v3. For details, see %s.", 'contact-form-7' ) ),
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/recaptcha/', 'contact-form-7' ),
|
||||
__( 'reCAPTCHA (v3)', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
echo sprintf(
|
||||
'<div class="notice notice-warning"><p>%s</p></div>',
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WPCF7_Service' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
class WPCF7_RECAPTCHA extends WPCF7_Service {
|
||||
|
||||
private static $instance;
|
||||
private $sitekeys;
|
||||
|
||||
public static function get_instance() {
|
||||
if ( empty( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$this->sitekeys = WPCF7::get_option( 'recaptcha' );
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return __( 'reCAPTCHA', 'contact-form-7' );
|
||||
}
|
||||
|
||||
public function is_active() {
|
||||
$sitekey = $this->get_sitekey();
|
||||
$secret = $this->get_secret( $sitekey );
|
||||
return $sitekey && $secret;
|
||||
}
|
||||
|
||||
public function get_categories() {
|
||||
return array( 'captcha' );
|
||||
}
|
||||
|
||||
public function icon() {
|
||||
}
|
||||
|
||||
public function link() {
|
||||
echo wpcf7_link(
|
||||
'https://www.google.com/recaptcha/intro/index.html',
|
||||
'google.com/recaptcha'
|
||||
);
|
||||
}
|
||||
|
||||
public function get_sitekey() {
|
||||
if ( empty( $this->sitekeys )
|
||||
or ! is_array( $this->sitekeys ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitekeys = array_keys( $this->sitekeys );
|
||||
|
||||
return $sitekeys[0];
|
||||
}
|
||||
|
||||
public function get_secret( $sitekey ) {
|
||||
$sitekeys = (array) $this->sitekeys;
|
||||
|
||||
if ( isset( $sitekeys[$sitekey] ) ) {
|
||||
return $sitekeys[$sitekey];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function log( $url, $request, $response ) {
|
||||
wpcf7_log_remote_request( $url, $request, $response );
|
||||
}
|
||||
|
||||
public function verify( $token ) {
|
||||
$is_human = false;
|
||||
|
||||
if ( empty( $token ) or ! $this->is_active() ) {
|
||||
return $is_human;
|
||||
}
|
||||
|
||||
$endpoint = 'https://www.google.com/recaptcha/api/siteverify';
|
||||
|
||||
$sitekey = $this->get_sitekey();
|
||||
$secret = $this->get_secret( $sitekey );
|
||||
|
||||
$request = array(
|
||||
'body' => array(
|
||||
'secret' => $secret,
|
||||
'response' => $token,
|
||||
),
|
||||
);
|
||||
|
||||
$response = wp_remote_post( esc_url_raw( $endpoint ), $request );
|
||||
|
||||
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
|
||||
if ( WP_DEBUG ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
|
||||
return $is_human;
|
||||
}
|
||||
|
||||
$response_body = wp_remote_retrieve_body( $response );
|
||||
$response_body = json_decode( $response_body, true );
|
||||
|
||||
$score = isset( $response_body['score'] ) ? $response_body['score'] : 0;
|
||||
$threshold = 0.5;
|
||||
$is_human = $threshold < $score;
|
||||
|
||||
$is_human = apply_filters( 'wpcf7_recaptcha_verify_response',
|
||||
$is_human, $response_body );
|
||||
|
||||
return $is_human;
|
||||
}
|
||||
|
||||
protected function menu_page_url( $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
$url = menu_page_url( 'wpcf7-integration', false );
|
||||
$url = add_query_arg( array( 'service' => 'recaptcha' ), $url );
|
||||
|
||||
if ( ! empty( $args) ) {
|
||||
$url = add_query_arg( $args, $url );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
protected function save_data() {
|
||||
WPCF7::update_option( 'recaptcha', $this->sitekeys );
|
||||
}
|
||||
|
||||
protected function reset_data() {
|
||||
$this->sitekeys = null;
|
||||
$this->save_data();
|
||||
}
|
||||
|
||||
public function load( $action = '' ) {
|
||||
if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
|
||||
check_admin_referer( 'wpcf7-recaptcha-setup' );
|
||||
|
||||
if ( ! empty( $_POST['reset'] ) ) {
|
||||
$this->reset_data();
|
||||
$redirect_to = $this->menu_page_url( 'action=setup' );
|
||||
} else {
|
||||
$sitekey = isset( $_POST['sitekey'] ) ? trim( $_POST['sitekey'] ) : '';
|
||||
$secret = isset( $_POST['secret'] ) ? trim( $_POST['secret'] ) : '';
|
||||
|
||||
if ( $sitekey and $secret ) {
|
||||
$this->sitekeys = array( $sitekey => $secret );
|
||||
$this->save_data();
|
||||
|
||||
$redirect_to = $this->menu_page_url( array(
|
||||
'message' => 'success',
|
||||
) );
|
||||
} else {
|
||||
$redirect_to = $this->menu_page_url( array(
|
||||
'action' => 'setup',
|
||||
'message' => 'invalid',
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( WPCF7::get_option( 'recaptcha_v2_v3_warning' ) ) {
|
||||
WPCF7::update_option( 'recaptcha_v2_v3_warning', false );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_to );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function admin_notice( $message = '' ) {
|
||||
if ( 'invalid' == $message ) {
|
||||
echo sprintf(
|
||||
'<div class="error notice notice-error is-dismissible"><p><strong>%1$s</strong>: %2$s</p></div>',
|
||||
esc_html( __( "ERROR", 'contact-form-7' ) ),
|
||||
esc_html( __( "Invalid key values.", 'contact-form-7' ) ) );
|
||||
}
|
||||
|
||||
if ( 'success' == $message ) {
|
||||
echo sprintf( '<div class="updated notice notice-success is-dismissible"><p>%s</p></div>',
|
||||
esc_html( __( 'Settings saved.', 'contact-form-7' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function display( $action = '' ) {
|
||||
echo '<p>' . sprintf(
|
||||
esc_html( __( 'reCAPTCHA protects you against spam and other types of automated abuse. With Contact Form 7’s reCAPTCHA integration module, you can block abusive form submissions by spam bots. For details, see %s.', 'contact-form-7' ) ),
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/recaptcha/', 'contact-form-7' ),
|
||||
__( 'reCAPTCHA (v3)', 'contact-form-7' )
|
||||
)
|
||||
) . '</p>';
|
||||
|
||||
if ( $this->is_active() or 'setup' == $action ) {
|
||||
$this->display_setup();
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<p><a href="%1$s" class="button">%2$s</a></p>',
|
||||
esc_url( $this->menu_page_url( 'action=setup' ) ),
|
||||
esc_html( __( 'Setup Integration', 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function display_setup() {
|
||||
$sitekey = $this->is_active() ? $this->get_sitekey() : '';
|
||||
$secret = $this->is_active() ? $this->get_secret( $sitekey ) : '';
|
||||
|
||||
?>
|
||||
<form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
|
||||
<?php wp_nonce_field( 'wpcf7-recaptcha-setup' ); ?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="sitekey"><?php echo esc_html( __( 'Site Key', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><?php
|
||||
if ( $this->is_active() ) {
|
||||
echo esc_html( $sitekey );
|
||||
echo sprintf(
|
||||
'<input type="hidden" value="%1$s" id="sitekey" name="sitekey" />',
|
||||
esc_attr( $sitekey )
|
||||
);
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<input type="text" aria-required="true" value="%1$s" id="sitekey" name="sitekey" class="regular-text code" />',
|
||||
esc_attr( $sitekey )
|
||||
);
|
||||
}
|
||||
?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="secret"><?php echo esc_html( __( 'Secret Key', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><?php
|
||||
if ( $this->is_active() ) {
|
||||
echo esc_html( wpcf7_mask_password( $secret ) );
|
||||
echo sprintf(
|
||||
'<input type="hidden" value="%1$s" id="secret" name="secret" />',
|
||||
esc_attr( $secret )
|
||||
);
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<input type="text" aria-required="true" value="%1$s" id="secret" name="secret" class="regular-text code" />',
|
||||
esc_attr( $secret )
|
||||
);
|
||||
}
|
||||
?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
if ( $this->is_active() ) {
|
||||
submit_button(
|
||||
_x( 'Remove Keys', 'API keys', 'contact-form-7' ),
|
||||
'small', 'reset'
|
||||
);
|
||||
} else {
|
||||
submit_button( __( 'Save Changes', 'contact-form-7' ) );
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [response]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_response', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_response() {
|
||||
wpcf7_add_form_tag( 'response', 'wpcf7_response_form_tag_handler',
|
||||
array( 'display-block' => true ) );
|
||||
}
|
||||
|
||||
function wpcf7_response_form_tag_handler( $tag ) {
|
||||
if ( $contact_form = wpcf7_get_current_contact_form() ) {
|
||||
return $contact_form->form_response_output();
|
||||
}
|
||||
}
|
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [select] and [select*]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_select', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_select() {
|
||||
wpcf7_add_form_tag( array( 'select', 'select*' ),
|
||||
'wpcf7_select_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'selectable-values' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_select_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
if ( $tag->is_required() ) {
|
||||
$atts['aria-required'] = 'true';
|
||||
}
|
||||
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$multiple = $tag->has_option( 'multiple' );
|
||||
$include_blank = $tag->has_option( 'include_blank' );
|
||||
$first_as_label = $tag->has_option( 'first_as_label' );
|
||||
|
||||
if ( $tag->has_option( 'size' ) ) {
|
||||
$size = $tag->get_option( 'size', 'int', true );
|
||||
|
||||
if ( $size ) {
|
||||
$atts['size'] = $size;
|
||||
} elseif ( $multiple ) {
|
||||
$atts['size'] = 4;
|
||||
} else {
|
||||
$atts['size'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $data = (array) $tag->get_data_option() ) {
|
||||
$tag->values = array_merge( $tag->values, array_values( $data ) );
|
||||
$tag->labels = array_merge( $tag->labels, array_values( $data ) );
|
||||
}
|
||||
|
||||
$values = $tag->values;
|
||||
$labels = $tag->labels;
|
||||
|
||||
$default_choice = $tag->get_default_option( null, array(
|
||||
'multiple' => $multiple,
|
||||
'shifted' => $include_blank,
|
||||
) );
|
||||
|
||||
if ( $include_blank
|
||||
or empty( $values ) ) {
|
||||
array_unshift( $labels, '---' );
|
||||
array_unshift( $values, '' );
|
||||
} elseif ( $first_as_label ) {
|
||||
$values[0] = '';
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$hangover = wpcf7_get_hangover( $tag->name );
|
||||
|
||||
foreach ( $values as $key => $value ) {
|
||||
if ( $hangover ) {
|
||||
$selected = in_array( $value, (array) $hangover, true );
|
||||
} else {
|
||||
$selected = in_array( $value, (array) $default_choice, true );
|
||||
}
|
||||
|
||||
$item_atts = array(
|
||||
'value' => $value,
|
||||
'selected' => $selected ? 'selected' : '',
|
||||
);
|
||||
|
||||
$item_atts = wpcf7_format_atts( $item_atts );
|
||||
|
||||
$label = isset( $labels[$key] ) ? $labels[$key] : $value;
|
||||
|
||||
$html .= sprintf( '<option %1$s>%2$s</option>',
|
||||
$item_atts, esc_html( $label ) );
|
||||
}
|
||||
|
||||
if ( $multiple ) {
|
||||
$atts['multiple'] = 'multiple';
|
||||
}
|
||||
|
||||
$atts['name'] = $tag->name . ( $multiple ? '[]' : '' );
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $html, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_select', 'wpcf7_select_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_select*', 'wpcf7_select_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_select_validation_filter( $result, $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
if ( isset( $_POST[$name] )
|
||||
and is_array( $_POST[$name] ) ) {
|
||||
foreach ( $_POST[$name] as $key => $value ) {
|
||||
if ( '' === $value ) {
|
||||
unset( $_POST[$name][$key] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$empty = ! isset( $_POST[$name] ) || empty( $_POST[$name] ) && '0' !== $_POST[$name];
|
||||
|
||||
if ( $tag->is_required() and $empty ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_menu', 25, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_menu() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'menu', __( 'drop-down menu', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_menu' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_menu( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
$description = __( "Generate a form-tag for a drop-down menu. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/checkboxes-radio-buttons-and-menus/', 'contact-form-7' ), __( 'Checkboxes, Radio Buttons and Menus', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
|
||||
<textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea>
|
||||
<label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One option per line.", 'contact-form-7' ) ); ?></span></label><br />
|
||||
<label><input type="checkbox" name="multiple" class="option" /> <?php echo esc_html( __( 'Allow multiple selections', 'contact-form-7' ) ); ?></label><br />
|
||||
<label><input type="checkbox" name="include_blank" class="option" /> <?php echo esc_html( __( 'Insert a blank item as the first option', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="select" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [submit]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_submit', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_submit() {
|
||||
wpcf7_add_form_tag( 'submit', 'wpcf7_submit_form_tag_handler' );
|
||||
}
|
||||
|
||||
function wpcf7_submit_form_tag_handler( $tag ) {
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
$value = isset( $tag->values[0] ) ? $tag->values[0] : '';
|
||||
|
||||
if ( empty( $value ) ) {
|
||||
$value = __( 'Send', 'contact-form-7' );
|
||||
}
|
||||
|
||||
$atts['type'] = 'submit';
|
||||
$atts['value'] = $value;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf( '<input %1$s />', $atts );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_submit', 55, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_submit() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'submit', __( 'submit', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_submit', array( 'nameless' => 1 ) );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_submit( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
$description = __( "Generate a form-tag for a submit button. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/submit-button/', 'contact-form-7' ), __( 'Submit Button', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Label', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="submit" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,320 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for the following types of tags:
|
||||
** [text] and [text*] # Single-line text
|
||||
** [email] and [email*] # Email address
|
||||
** [url] and [url*] # URL
|
||||
** [tel] and [tel*] # Telephone number
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_text', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_text() {
|
||||
wpcf7_add_form_tag(
|
||||
array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
|
||||
'wpcf7_text_form_tag_handler', array( 'name-attr' => true ) );
|
||||
}
|
||||
|
||||
function wpcf7_text_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' );
|
||||
|
||||
if ( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) ) {
|
||||
$class .= ' wpcf7-validates-as-' . $tag->basetype;
|
||||
}
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['size'] = $tag->get_size_option( '40' );
|
||||
$atts['maxlength'] = $tag->get_maxlength_option();
|
||||
$atts['minlength'] = $tag->get_minlength_option();
|
||||
|
||||
if ( $atts['maxlength'] and $atts['minlength']
|
||||
and $atts['maxlength'] < $atts['minlength'] ) {
|
||||
unset( $atts['maxlength'], $atts['minlength'] );
|
||||
}
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
$atts['autocomplete'] = $tag->get_option( 'autocomplete',
|
||||
'[-0-9a-zA-Z]+', true );
|
||||
|
||||
if ( $tag->has_option( 'readonly' ) ) {
|
||||
$atts['readonly'] = 'readonly';
|
||||
}
|
||||
|
||||
if ( $tag->is_required() ) {
|
||||
$atts['aria-required'] = 'true';
|
||||
}
|
||||
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$value = (string) reset( $tag->values );
|
||||
|
||||
if ( $tag->has_option( 'placeholder' )
|
||||
or $tag->has_option( 'watermark' ) ) {
|
||||
$atts['placeholder'] = $value;
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$value = $tag->get_default_option( $value );
|
||||
|
||||
$value = wpcf7_get_hangover( $tag->name, $value );
|
||||
|
||||
$atts['value'] = $value;
|
||||
|
||||
if ( wpcf7_support_html5() ) {
|
||||
$atts['type'] = $tag->basetype;
|
||||
} else {
|
||||
$atts['type'] = 'text';
|
||||
}
|
||||
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_text*', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_url', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_url*', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_tel', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_tel*', 'wpcf7_text_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_text_validation_filter( $result, $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
$value = isset( $_POST[$name] )
|
||||
? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) )
|
||||
: '';
|
||||
|
||||
if ( 'text' == $tag->basetype ) {
|
||||
if ( $tag->is_required() and '' == $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'email' == $tag->basetype ) {
|
||||
if ( $tag->is_required() and '' == $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
} elseif ( '' != $value and ! wpcf7_is_email( $value ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_email' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'url' == $tag->basetype ) {
|
||||
if ( $tag->is_required() and '' == $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
} elseif ( '' != $value and ! wpcf7_is_url( $value ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_url' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'tel' == $tag->basetype ) {
|
||||
if ( $tag->is_required() and '' == $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
} elseif ( '' != $value and ! wpcf7_is_tel( $value ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_tel' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( '' !== $value ) {
|
||||
$maxlength = $tag->get_maxlength_option();
|
||||
$minlength = $tag->get_minlength_option();
|
||||
|
||||
if ( $maxlength and $minlength and $maxlength < $minlength ) {
|
||||
$maxlength = $minlength = null;
|
||||
}
|
||||
|
||||
$code_units = wpcf7_count_code_units( stripslashes( $value ) );
|
||||
|
||||
if ( false !== $code_units ) {
|
||||
if ( $maxlength and $maxlength < $code_units ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) );
|
||||
} elseif ( $minlength and $code_units < $minlength ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_text_messages', 10, 1 );
|
||||
|
||||
function wpcf7_text_messages( $messages ) {
|
||||
$messages = array_merge( $messages, array(
|
||||
'invalid_email' => array(
|
||||
'description' =>
|
||||
__( "Email address that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "The e-mail address entered is invalid.", 'contact-form-7' ),
|
||||
),
|
||||
|
||||
'invalid_url' => array(
|
||||
'description' =>
|
||||
__( "URL that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "The URL is invalid.", 'contact-form-7' ),
|
||||
),
|
||||
|
||||
'invalid_tel' => array(
|
||||
'description' =>
|
||||
__( "Telephone number that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "The telephone number is invalid.", 'contact-form-7' ),
|
||||
),
|
||||
) );
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_text', 15, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_text() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'text', __( 'text', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_text' );
|
||||
$tag_generator->add( 'email', __( 'email', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_text' );
|
||||
$tag_generator->add( 'url', __( 'URL', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_text' );
|
||||
$tag_generator->add( 'tel', __( 'tel', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_text' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_text( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = $args['id'];
|
||||
|
||||
if ( ! in_array( $type, array( 'email', 'url', 'tel' ) ) ) {
|
||||
$type = 'text';
|
||||
}
|
||||
|
||||
if ( 'text' == $type ) {
|
||||
$description = __( "Generate a form-tag for a single-line plain text input field. For more details, see %s.", 'contact-form-7' );
|
||||
} elseif ( 'email' == $type ) {
|
||||
$description = __( "Generate a form-tag for a single-line email address input field. For more details, see %s.", 'contact-form-7' );
|
||||
} elseif ( 'url' == $type ) {
|
||||
$description = __( "Generate a form-tag for a single-line URL input field. For more details, see %s.", 'contact-form-7' );
|
||||
} elseif ( 'tel' == $type ) {
|
||||
$description = __( "Generate a form-tag for a single-line telephone number input field. For more details, see %s.", 'contact-form-7' );
|
||||
}
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text Fields', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<?php if ( in_array( $type, array( 'text', 'email', 'url' ) ) ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></legend>
|
||||
|
||||
<?php if ( 'text' == $type ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="akismet:author" class="option" />
|
||||
<?php echo esc_html( __( "This field requires author's name", 'contact-form-7' ) ); ?>
|
||||
</label>
|
||||
<?php elseif ( 'email' == $type ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="akismet:author_email" class="option" />
|
||||
<?php echo esc_html( __( "This field requires author's email address", 'contact-form-7' ) ); ?>
|
||||
</label>
|
||||
<?php elseif ( 'url' == $type ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="akismet:author_url" class="option" />
|
||||
<?php echo esc_html( __( "This field requires author's URL", 'contact-form-7' ) ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [textarea] and [textarea*]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_textarea', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_textarea() {
|
||||
wpcf7_add_form_tag( array( 'textarea', 'textarea*' ),
|
||||
'wpcf7_textarea_form_tag_handler', array( 'name-attr' => true ) );
|
||||
}
|
||||
|
||||
function wpcf7_textarea_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
|
||||
if ( $validation_error ) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['cols'] = $tag->get_cols_option( '40' );
|
||||
$atts['rows'] = $tag->get_rows_option( '10' );
|
||||
$atts['maxlength'] = $tag->get_maxlength_option();
|
||||
$atts['minlength'] = $tag->get_minlength_option();
|
||||
|
||||
if ( $atts['maxlength'] and $atts['minlength']
|
||||
and $atts['maxlength'] < $atts['minlength'] ) {
|
||||
unset( $atts['maxlength'], $atts['minlength'] );
|
||||
}
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
$atts['autocomplete'] = $tag->get_option( 'autocomplete',
|
||||
'[-0-9a-zA-Z]+', true );
|
||||
|
||||
if ( $tag->has_option( 'readonly' ) ) {
|
||||
$atts['readonly'] = 'readonly';
|
||||
}
|
||||
|
||||
if ( $tag->is_required() ) {
|
||||
$atts['aria-required'] = 'true';
|
||||
}
|
||||
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
|
||||
$value = empty( $tag->content )
|
||||
? (string) reset( $tag->values )
|
||||
: $tag->content;
|
||||
|
||||
if ( $tag->has_option( 'placeholder' )
|
||||
or $tag->has_option( 'watermark' ) ) {
|
||||
$atts['placeholder'] = $value;
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$value = $tag->get_default_option( $value );
|
||||
|
||||
$value = wpcf7_get_hangover( $tag->name, $value );
|
||||
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$atts = wpcf7_format_atts( $atts );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>',
|
||||
sanitize_html_class( $tag->name ), $atts,
|
||||
esc_textarea( $value ), $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_textarea',
|
||||
'wpcf7_textarea_validation_filter', 10, 2 );
|
||||
add_filter( 'wpcf7_validate_textarea*',
|
||||
'wpcf7_textarea_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_textarea_validation_filter( $result, $tag ) {
|
||||
$type = $tag->type;
|
||||
$name = $tag->name;
|
||||
|
||||
$value = isset( $_POST[$name] ) ? (string) $_POST[$name] : '';
|
||||
|
||||
if ( $tag->is_required() and '' == $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
|
||||
}
|
||||
|
||||
if ( '' !== $value ) {
|
||||
$maxlength = $tag->get_maxlength_option();
|
||||
$minlength = $tag->get_minlength_option();
|
||||
|
||||
if ( $maxlength and $minlength
|
||||
and $maxlength < $minlength ) {
|
||||
$maxlength = $minlength = null;
|
||||
}
|
||||
|
||||
$code_units = wpcf7_count_code_units( stripslashes( $value ) );
|
||||
|
||||
if ( false !== $code_units ) {
|
||||
if ( $maxlength and $maxlength < $code_units ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) );
|
||||
} elseif ( $minlength and $code_units < $minlength ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_textarea', 20, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_textarea() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'textarea', __( 'text area', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_textarea' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_textarea( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'textarea';
|
||||
|
||||
$description = __( "Generate a form-tag for a multi-line text input field. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text Fields', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
Reference in New Issue
Block a user