• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Grunion_Contact_Form_Field::__construct() –

You appear to be a bot. Output may be restricted

Description

Usage

Grunion_Contact_Form_Field::__construct( $attributes, $content, $form );

Parameters

$attributes
( array ) required – An associative array of shortcode attributes. @see shortcode_atts()
$content
( null|string ) optional – Null for selfclosing shortcodes. The inner content otherwise.
$form
( Grunion_Contact_Form ) optional – The parent form

Returns

void

Source

File name: jetpack/modules/contact-form/grunion-contact-form.php


Lines:

1 to 72 of 72
  function __construct( $attributes, $content = null, $form = null ) {
    $attributes = shortcode_atts(
      array(
        'label'                  => null,
        'type'                   => 'text',
        'required'               => false,
        'options'                => array(),
        'id'                     => null,
        'default'                => null,
        'values'                 => null,
        'placeholder'            => null,
        'class'                  => null,
        'width'                  => null,
        'consenttype'            => null,
        'implicitconsentmessage' => null,
        'explicitconsentmessage' => null,
      ), $attributes, 'contact-field'
    );

    // special default for subject field
    if ( 'subject' == $attributes['type'] && is_null( $attributes['default'] ) && ! is_null( $form ) ) {
      $attributes['default'] = $form->get_attribute( 'subject' );
    }

    // allow required=1 or required=true
    if ( '1' == $attributes['required'] || 'true' == strtolower( $attributes['required'] ) ) {
      $attributes['required'] = true;
    } else {
      $attributes['required'] = false;
    }

    // parse out comma-separated options list (for selects, radios, and checkbox-multiples)
    if ( ! empty( $attributes['options'] ) && is_string( $attributes['options'] ) ) {
      $attributes['options'] = array_map( 'trim', explode( ',', $attributes['options'] ) );

      if ( ! empty( $attributes['values'] ) && is_string( $attributes['values'] ) ) {
        $attributes['values'] = array_map( 'trim', explode( ',', $attributes['values'] ) );
      }
    }

    if ( $form ) {
      // make a unique field ID based on the label, with an incrementing number if needed to avoid clashes
      $form_id = $form->get_attribute( 'id' );
      $id      = isset( $attributes['id'] ) ? $attributes['id'] : false;

      $unescaped_label = $this->unesc_attr( $attributes['label'] );
      $unescaped_label = str_replace( '%', '-', $unescaped_label ); // jQuery doesn't like % in IDs?
      $unescaped_label = preg_replace( '/[^a-zA-Z0-9.-_:]/', '', $unescaped_label );

      if ( empty( $id ) ) {
        $id        = sanitize_title_with_dashes( 'g' . $form_id . '-' . $unescaped_label );
        $i         = 0;
        $max_tries = 99;
        while ( isset( $form->fields[ $id ] ) ) {
          $i++;
          $id = sanitize_title_with_dashes( 'g' . $form_id . '-' . $unescaped_label . '-' . $i );

          if ( $i > $max_tries ) {
            break;
          }
        }
      }

      $attributes['id'] = $id;
    }

    parent::__construct( $attributes, $content );

    // Store parent form
    $this->form = $form;
  }
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 27 November 2019 | Last updated: 10 December 2020

Primary Sidebar

Information

Function name: Grunion_Contact_Form_Field::__construct
Class ref: Grunion_Contact_Form_Field
Plugin ref: Jetpack
Version: 9.2
Sourcefile: modules/contact-form/grunion-contact-form.php
File ref: modules/contact-form/grunion-contact-form.php
Deprecated?: No
API Letters: C,F,G

Footer

Jetpack a2z
Jetpack a2z
Jetpack a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites