true ) ); add_filter( 'wpcf7_validate_jsonpage_company', array( __CLASS__, 'cf7_validate' ), 10, 2 ); add_filter( 'wpcf7_validate_jsonpage_company*', array( __CLASS__, 'cf7_validate' ), 10, 2 ); } /** * Output of the Contact Form 7 tag. * * @param WPCF7_FormTag $tag The tag. * @return string */ public static function cf7_handler( $tag ) { if ( empty( $tag->name ) ) { return ''; } self::enqueue(); $error = wpcf7_get_validation_error( $tag->name ); $class = wpcf7_form_controls_class( $tag->type ); if ( $error ) { $class .= ' wpcf7-not-valid'; } $atts = array( 'type' => 'text', 'name' => $tag->name, 'class' => $tag->get_class_option( $class ), 'id' => $tag->get_id_option(), 'autocomplete' => 'off', 'aria-required' => $tag->is_required() ? 'true' : 'false', 'aria-invalid' => $error ? 'true' : 'false', 'data-jsonpage-company' => '1', 'data-jsonpage-countries' => self::countries_attribute( (string) $tag->get_option( 'countries', '[A-Za-z,]+', true ) ), ); $value = (string) reset( $tag->values ); if ( '' !== $value ) { $atts['value'] = $value; } if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) { $atts['placeholder'] = $value; unset( $atts['value'] ); } return sprintf( '%3$s', esc_attr( $tag->name ), wpcf7_format_atts( $atts ), $error ); } /** * Required check of the Contact Form 7 tag. * * @param WPCF7_Validation $result Validation result. * @param WPCF7_FormTag $tag The tag. * @return WPCF7_Validation */ public static function cf7_validate( $result, $tag ) { // Value read from the submission object of Contact Form 7 (already unslashed and checked by Contact Form 7), not from $_POST. $submission = class_exists( 'WPCF7_Submission' ) ? WPCF7_Submission::get_instance() : null; $posted = $submission ? $submission->get_posted_data( $tag->name ) : ''; $value = is_string( $posted ) ? trim( sanitize_text_field( $posted ) ) : ''; if ( $tag->is_required() && '' === $value ) { $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); } return $result; } /** * Adds the tag to the tag generator of Contact Form 7. */ public static function cf7_generator_register() { if ( ! class_exists( 'WPCF7_TagGenerator' ) ) { return; } $generator = WPCF7_TagGenerator::get_instance(); if ( class_exists( 'WPCF7_TagGeneratorGenerator' ) && class_exists( 'WPCF7_HTMLFormatter' ) ) { // Contact Form 7 6.0 and later: version 2 panel (version 1 is deprecated and logs a notice). $generator->add( 'jsonpage_company', __( 'company (Jsonpage)', 'jsonpage' ), array( __CLASS__, 'cf7_generator_pane_v2' ), array( 'version' => '2' ) ); return; } $generator->add( 'jsonpage_company', __( 'company (Jsonpage)', 'jsonpage' ), array( __CLASS__, 'cf7_generator_pane' ) ); } /** * Panel of the tag generator, Contact Form 7 6.0 and later. * * @param WPCF7_ContactForm $contact_form Form being edited. * @param array $options Panel options (content id). */ public static function cf7_generator_pane_v2( $contact_form, $options ) { $tgg = new WPCF7_TagGeneratorGenerator( $options['content'] ); $formatter = new WPCF7_HTMLFormatter(); $formatter->append_start_tag( 'header', array( 'class' => 'description-box' ) ); $formatter->append_start_tag( 'h3' ); $formatter->append_preformatted( esc_html__( 'Company field (Jsonpage)', 'jsonpage' ) ); $formatter->end_tag( 'h3' ); $formatter->append_start_tag( 'p' ); $formatter->append_preformatted( esc_html__( 'Generates a Company field with autocomplete. Give the other fields of the form the CSS class jsonpage-fill-address, jsonpage-fill-postal_code, jsonpage-fill-city, jsonpage-fill-country, jsonpage-fill-registry_id or jsonpage-fill-vat to have them filled in.', 'jsonpage' ) ); $formatter->end_tag( 'header' ); $formatter->append_start_tag( 'div', array( 'class' => 'control-box' ) ); $formatter->call_user_func( static function () use ( $tgg ) { $tgg->print( 'field_type', array( 'with_required' => true, 'select_options' => array( 'jsonpage_company' => __( 'Company field (Jsonpage)', 'jsonpage' ) ), ) ); $tgg->print( 'field_name' ); $tgg->print( 'class_attr' ); } ); $formatter->end_tag( 'div' ); $formatter->append_start_tag( 'footer', array( 'class' => 'insert-box' ) ); $formatter->call_user_func( static function () use ( $tgg ) { $tgg->print( 'insert_box_content' ); $tgg->print( 'mail_tag_tip' ); } ); $formatter->print(); } /** * Panel of the tag generator. * * @param WPCF7_ContactForm $contact_form Form being edited. * @param array|string $args Arguments. */ public static function cf7_generator_pane( $contact_form, $args = '' ) { $args = wp_parse_args( $args, array() ); $description = __( 'Generate a Company field with autocomplete. Give the other fields of the form the CSS class jsonpage-fill-address, jsonpage-fill-postal_code, jsonpage-fill-city, jsonpage-fill-country, jsonpage-fill-registry_id or jsonpage-fill-vat to have them filled in.', 'jsonpage' ); ?>