true); $features = apply_filters( 'cf7-add-password-field-features',$features ); wpcf7_add_form_tag( array('password','password*'), 'wpcf7_k_password_form_tag_handler',$features ); } function wpcf7_k_password_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' ); $class .= ' wpcf7-validates-as-password'; 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'] && $atts['minlength'] && $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 ); $atts['password_strength'] = (int)$tag->get_option( 'password_strength', 'signed_int', true); $atts['password_check'] = $tag->get_option( 'password_check', '', true); $atts['specific_password_check'] = $tag->get_option( 'specific_password_check', '', true); $atts['hideIcon'] = $tag->has_option( 'hideIcon' ); if ( $tag->is_required() ) { $atts['aria-required'] = 'true'; } if ( $validation_error ) { $atts['aria-invalid'] = 'true'; $atts['aria-describedby'] = wpcf7_get_validation_error_reference( $tag->name ); } else { $atts['aria-invalid'] = 'false'; } $value = (string) reset( $tag->values ); // Support placeholder. Reference: modules/date.php in the contact form 7 plugin. 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'] = 'password'; } $atts['name'] = $tag->name; $atts = wpcf7_format_atts( $atts ); $tag_id = $tag->get_id_option(); if( empty($tag_id) ) $tag_id = $tag->name; // for the version 5.8 of Contact form 7: Contact form 7 ignores the id attribute if the same ID is already used for another element. if( $tag_id === $tag->name && !$tag->has_option( 'hideIcon' ) ){ $html = sprintf( '%3$s', sanitize_html_class( $tag->name ), $atts, $validation_error ); }else{ $html = sprintf( '%3$s', sanitize_html_class( $tag->name ), $atts, $validation_error ); } return $html; } function wpcf7_k_password_validation_filter( $result, $tag ) { $name = $tag->name; $value = isset( $_POST[$name] ) ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) ) : ''; $specific_password_check = $tag->get_option( 'specific_password_check', '', true); if(!empty($specific_password_check)){ $value_pass_array = explode("_", str_replace(" ", "", $specific_password_check)); $flag = false; foreach($value_pass_array as $each_value_pass){ if($value === $each_value_pass ){ $flag = true; break; } } if( $flag === false){ $result->invalidate($tag, __("Passwords do not match defined!", 'cf7-add-password-field' )); } } $password_check = $tag->get_option( 'password_check', '', true); if(!empty($password_check)){ if(isset( $_POST[$password_check] )){ $value_pass = isset( $_POST[$password_check] ) ? trim( wp_unslash( strtr( (string) $_POST[$password_check], "\n", " " ) ) ) : ''; if($value !== $value_pass ){ $result->invalidate($tag, __("Passwords do not match!", 'cf7-add-password-field' )); } } } $password_strength = (int)$tag->get_option( 'password_strength','signed_int', true); if ($password_strength < 0){ $password_strength = 0; } $pattern = preg_quote ($tag->get_option( 'pattern' )); if ( $tag->is_required() and '' === $value ) { $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); }elseif ( '' !== $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( $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' ) ); } } if ($password_strength > 0) { if($password_strength === 1){ if(!preg_match("/^[0-9]+$/", $value)){ $result->invalidate($tag, __("Please use the numbers only", 'cf7-add-password-field' )); } }elseif($password_strength === 2){ if(!preg_match("/([0-9].*[a-z,A-Z])|([a-z,A-Z].*[0-9])/", $value) ){ $result->invalidate($tag, __("Please include one or more letters and numbers.", 'cf7-add-password-field' )); } }elseif($password_strength === 3){ if(!preg_match("/[0-9]/", $value) or !preg_match("/([a-z].*[A-Z])|([A-Z].*[a-z])/", $value)){ $result->invalidate($tag, __("Please include one or more upper and lower case letters and numbers.", 'cf7-add-password-field' )); } }elseif($password_strength === 4){ if(!preg_match("/[0-9]/", $value) or !preg_match("/([a-z].*[A-Z])|([A-Z].*[a-z])/", $value) or !preg_match("/([!,%,&,@,#,$,^,*,?,_,~])/", $value)){ $result->invalidate($tag, __("Please include one or more upper and lower case letters, numbers, and marks.", 'cf7-add-password-field' )); } } } } return apply_filters('wpcf7_k_password_validation_filter', $result, $tag); } // Add Tag. if ( is_admin() ) { add_action( 'wpcf7_admin_init' , 'wpcf7_k_password_add_tag_generator' , 55 ); } function wpcf7_k_password_add_tag_generator( $contact_form , $args = '' ){ if(!class_exists('WPCF7_TagGenerator')) { return false; } $tag_generator = WPCF7_TagGenerator::get_instance(); $tag_generator->add( 'password', __( 'Password', 'cf7-add-password-field' ), 'wpcf7_k_password_pane_confirm', array( 'nameless' => 1 ) ); } function wpcf7_k_password_pane_confirm( $contact_form, $args = '' ) { $args = wp_parse_args( $args, array() ); $description = __( "Generate a form-tag for a password button.", 'cf7-add-password-field' ); ?>