Support » Plugin: Contact Form 7 » Format Ignored on ‘_date’ Special Mail Tag

  • Resolved WPMonkeyATL

    (@wpmonkeyatl)


    If I specify a particular format for the ‘_date’ Special Mail Tag in my form’s mail message, the specified format is ignored altogether (e.g. using the ‘_format_’ notation as documented here: http://contactform7.com/date-field/). it is ignored on both regular and HTML mail messages. For example:

    [_format__date “Y”] -> date always appears using system default format e.g. “December 8, 2016” (i.e. “Y” is ignored)

    However, if I do the same on a regular Date field defined in my form such as “my_date”, then the format works correctly:

    [_format_my_date “Y”] -> date appears as “2016” (i.e. “Y” is honored)

    (NOTE: this occurs on both CF7 v4.6 and previous version as well)

    Is there a way to make ‘_format_’ apply on the ‘_date’ Special Mail Tag?

    • This topic was modified 2 years, 11 months ago by WPMonkeyATL.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    It uses the Date Format setting in Settings > General.

    Hello –

    Yes, it uses the Date Format in Settings->General as the default format, but the issue is that it ignores any exlicit format specified using the date-field ‘_format_’ notation (as indicated in the documentation here: http://contactform7.com/date-field/).

    For consistency, shouldn’t the Special Mail Tag ‘_date’ apply a specified ‘_format_’ just like any regular Date-Field Tag?

    A small addition to /includes/mail.php would allow this, for example something like the following could be added immediately after Line 313 in mail.php:

    /* LINE 313 in mail.php: */
    $special = apply_filters( 'wpcf7_special_mail_tags', '', $tagname, $html );
    
    /* ADDITION AFTER LINE 313:  An extra condition to apply '_format_' to the '_date' Special Mail Tag: */
    if ( ! empty( $special ) && '_date' == $tagname && ! empty( $format ) ) {
    	$special = mysql2date( $format, $special );
    }
    

    One beneficial use case that this would enable: dynamically adding ‘The Current Year’ in a copyright message in the footer of an html email, without having to define any additional CF7 shortcodes etc (in functions.php):

    Copyright © [_format__date ‘Y’]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Format Ignored on ‘_date’ Special Mail Tag’ is closed to new replies.