Skip to content

Commit

Permalink
Merge pull request #543 from takayukister/dev/5.5
Browse files Browse the repository at this point in the history
Update contact-form.php
  • Loading branch information
takayukister authored Sep 6, 2021
2 parents 78484b0 + 0be534b commit cb60a36
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions includes/contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,23 @@ public function set_locale( $locale ) {
}
}


/**
* Returns the specified shortcode attribute value.
*
* @param string $name Shortcode attribute name.
* @return string|null Attribute value. Null if the attribute doesn't exist.
*/
public function shortcode_attr( $name ) {
if ( isset( $this->shortcode_atts[$name] ) ) {
return (string) $this->shortcode_atts[$name];
}
}

// Return true if this form is the same one as currently POSTed.

/**
* Returns true if this contact form is identical to the submitted one.
*/
public function is_posted() {
if ( ! WPCF7_Submission::get_instance() ) {
return false;
Expand All @@ -420,8 +430,13 @@ public function is_posted() {
return $this->unit_tag() === $_POST['_wpcf7_unit_tag'];
}

/* Generating Form HTML */

/**
* Generates HTML that represents a form.
*
* @param string|array $args Optional. Form options.
* @return string HTML output.
*/
public function form_html( $args = '' ) {
$args = wp_parse_args( $args, array(
'html_id' => '',
Expand All @@ -433,18 +448,23 @@ public function form_html( $args = '' ) {
$this->shortcode_atts = $args;

if ( 'raw_form' == $args['output'] ) {
return '<pre class="wpcf7-raw-form"><code>'
. esc_html( $this->prop( 'form' ) ) . '</code></pre>';
return sprintf(
'<pre class="wpcf7-raw-form"><code>%s</code></pre>',
esc_html( $this->prop( 'form' ) )
);
}

if ( $this->is_true( 'subscribers_only' )
and ! current_user_can( 'wpcf7_submit', $this->id() ) ) {
$notice = __(
"This contact form is available only for logged in users.",
'contact-form-7' );
'contact-form-7'
);

$notice = sprintf(
'<p class="wpcf7-subscribers-only">%s</p>',
esc_html( $notice ) );
esc_html( $notice )
);

return apply_filters( 'wpcf7_subscribers_only_notice', $notice, $this );
}
Expand Down Expand Up @@ -481,10 +501,12 @@ public function form_html( $args = '' ) {
$url = apply_filters( 'wpcf7_form_action_url', $url );

$id_attr = apply_filters( 'wpcf7_form_id_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_id'] ) );
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_id'] )
);

$name_attr = apply_filters( 'wpcf7_form_name_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_name'] ) );
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_name'] )
);

$class = 'wpcf7-form';

Expand Down Expand Up @@ -557,6 +579,10 @@ public function form_html( $args = '' ) {
return $html;
}


/**
* Returns the class name that matches the given form status.
*/
private function form_status_class_name( $status ) {
switch ( $status ) {
case 'init':
Expand Down Expand Up @@ -590,6 +616,10 @@ private function form_status_class_name( $status ) {
return $class;
}


/**
* Returns a set of hidden fields.
*/
private function form_hidden_fields() {
$hidden_fields = array(
'_wpcf7' => $this->id(),
Expand All @@ -604,19 +634,22 @@ private function form_hidden_fields() {
$hidden_fields['_wpcf7_container_post'] = (int) get_the_ID();
}

if ( $this->nonce_is_active() && is_user_logged_in() ) {
if ( $this->nonce_is_active() and is_user_logged_in() ) {
$hidden_fields['_wpnonce'] = wpcf7_create_nonce();
}

$hidden_fields += (array) apply_filters(
'wpcf7_form_hidden_fields', array() );
'wpcf7_form_hidden_fields', array()
);

$content = '';

foreach ( $hidden_fields as $name => $value ) {
$content .= sprintf(
'<input type="hidden" name="%1$s" value="%2$s" />',
esc_attr( $name ), esc_attr( $value ) ) . "\n";
esc_attr( $name ),
esc_attr( $value )
) . "\n";
}

return '<div style="display: none;">' . "\n" . $content . '</div>' . "\n";
Expand Down

0 comments on commit cb60a36

Please sign in to comment.