php Gravity Wiz // Gravity Forms //添加日期合并标记的格式选项
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Gravity Wiz // Gravity Forms //添加日期合并标记的格式选项相关的知识,希望对你有一定的参考价值。
<?php
/**
* Gravity Wiz // Gravity Forms // Add Formatting Options for Date Merge Tags
* http://gravitywiz.com/
*
* {Date:1:dmy} => 31/1/2017
* {Date:2:l} => Tuesday
*
* See PHP's date() function documentation for full details on formatting:
* http://php.net/manual/en/function.date.php
*/
add_filter( 'gform_pre_replace_merge_tags', function( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}|{entry:date_created:(.+)?}/mi', $text, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
$input_id = $match[1];
$field = GFFormsModel::get_field( $form, $input_id );
$is_entry_date = strpos( $match[0], '{entry:date_created' ) !== false;
if( $is_entry_date ) {
$modifier = rgar( array_map( 'trim', explode( ',', rgar( $match, 5 ) ) ), 0 );
$value = rgar( $entry, 'date_created' );
} else if( ! $field || $field->get_input_type() != 'date' ) {
continue;
} else {
$i = $match[0][0] == '{' ? 4 : 5;
$modifier = rgar( array_map( 'trim', explode( ',', rgar( $match, $i ) ) ), 0 );
if( ! $modifier ) {
continue;
}
$value = GFFormsModel::get_lead_field_value( $entry, $field );
$value = $field->get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $value, $url_encode, $esc_html, $format, $nl2br );
}
$replace = date( $modifier, strtotime( $value ) );
$text = str_replace( $match[0], $replace, $text );
}
return $text;
}, 10, 7 );
以上是关于php Gravity Wiz // Gravity Forms //添加日期合并标记的格式选项的主要内容,如果未能解决你的问题,请参考以下文章
php Gravity Wiz // Gravity Forms //添加日期合并标记的格式选项
php Gravity Wiz // Gravity Forms Coupons //允许零金额优惠券
php Gravity Wiz // Gravity Forms //用户注册//通过电子邮件更新
php Gravity Wiz // Gravity Forms //将GF数据填充到WP Job Manager自定义字段中
css Gravity Wiz // Gravity Forms // CSS // Hide AJAX Spinner
css Gravity Wiz // Gravity Forms // CSS // Hide AJAX Spinner