php Gravity Perks // GP通知计划程序//信用卡到期
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Gravity Perks // GP通知计划程序//信用卡到期相关的知识,希望对你有一定的参考价值。
<?php
/**
* Gravity Perks // GP Notification Scheduler // Credit Card Expiration
*
* Send notifications based on a credit card expiration date.
*
* @version 0.1
* @author David Smith <david@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/
*
* Plugin Name: GP Notification Scheduler - Credit Card Expiration
* Plugin URI: http://gravitywiz.com/
* Description: Send notifications based on a credit card expiration date.
* Author: Gravity Wiz
* Version: 0.1
* Author URI: http://gravitywiz.com
*/
class GPNS_CC_Expiration {
public function __construct( $args = array() ) {
// set our default arguments, parse against the provided arguments, and store for use throughout the class
$this->_args = wp_parse_args( $args, array(
'form_id' => false,
'date_field_id' => false
) );
// do version check in the init to make sure if GF is going to be loaded, it is already loaded
add_action( 'init', array( $this, 'init' ) );
}
public function init() {
// make sure we're running the required minimum version of Gravity Forms
if( ! property_exists( 'GFCommon', 'version' ) || ! version_compare( GFCommon::$version, '1.8', '>=' ) ) {
return;
}
add_action( 'gform_pre_submission', array( $this, 'populate_date_field' ) );
}
public function populate_date_field( $form ) {
if( ! $this->is_applicable_form( $form ) ) {
return;
}
$cc_field = GFFormsModel::get_fields_by_type( $form, array( 'creditcard' ) );
if( empty( $cc_field ) ) {
return;
}
$date_field = GFFormsModel::get_field( $form, $this->_args['date_field_id'] );
$value = rgpost( "input_{$cc_field[0]->id}_2" ); // Format: array( 1, 2018 ).
$timestamp = strtotime( sprintf( '%d/%d/1', $value[1], $value[0] ) );
$_POST[ "input_{$this->_args['date_field_id']}" ] = $this->format_by_date_field( $timestamp, $date_field );
}
public function format_by_date_field( $timestamp, $field ) {
list( $format, $divider ) = $field['dateFormat'] ? array_pad( explode( '_', $field['dateFormat' ] ), 2, 'slash' ) : array( 'mdy', 'slash' );
$dividers = array( 'slash' => '/', 'dot' => '.', 'dash' => '-' );
$format = str_replace( 'y', 'Y', $format );
$divider = $dividers[ $divider ];
$format = implode( $divider, str_split( $format ) );
return date( $format, $timestamp );
}
public function is_applicable_form( $form ) {
$form_id = isset( $form['id'] ) ? $form['id'] : $form;
return empty( $this->_args['form_id'] ) || $form_id == $this->_args['form_id'];
}
}
# Configuration
new GPNS_CC_Expiration( array(
'form_id' => 1787,
'date_field_id' => 3
) );
以上是关于php Gravity Perks // GP通知计划程序//信用卡到期的主要内容,如果未能解决你的问题,请参考以下文章
php Gravity Perks // GP条件定价//显示价格标签
php Gravity Perks // GP限制提交//集体应用全局限制
php Gravity Perks // GP电子商务领域//动态设置税额
php Gravity Perks // GP嵌套表单//从值隐藏产品名称
php Gravity Perks // GP唯一ID //从Gravity PDF中排除唯一ID字段
php Gravity Perks // GP填充任何东西//微小的邮件列表