1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class GravityView_Field_Date_Created extends GravityView_Field { |
4
|
|
|
|
5
|
|
|
var $name = 'date_created'; |
6
|
|
|
|
7
|
|
|
var $search_operators = array( 'less_than', 'greater_than', 'is', 'isnot' ); |
8
|
|
|
|
9
|
|
|
var $group = 'meta'; |
10
|
|
|
|
11
|
|
|
var $contexts = array( 'single', 'multiple', 'export' ); |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* GravityView_Field_Date_Created constructor. |
15
|
|
|
*/ |
16
|
|
|
public function __construct() { |
17
|
|
|
$this->label = esc_attr__( 'Date Created', 'gravityview' ); |
|
|
|
|
18
|
|
|
$this->description = esc_attr__( 'The date the entry was created.', 'gravityview' ); |
|
|
|
|
19
|
|
|
parent::__construct(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
|
|
|
23
|
|
|
|
24
|
|
|
if( 'edit' === $context ) { |
25
|
|
|
return $field_options; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->add_field_support('date_display', $field_options ); |
29
|
|
|
|
30
|
|
|
return $field_options; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function format( $value, $format = '', $context = 'display' ) { |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n |
37
|
|
|
* date_created is stored in UTC format. Convert search date into UTC (also used on templates/fields/date_created.php) |
38
|
|
|
* @since 1.16 |
39
|
|
|
* @param[out,in] boolean $adjust_tz Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default: true |
40
|
|
|
* @param[in] string $context Where the filter is being called from. `display` in this case. |
41
|
|
|
*/ |
42
|
|
|
$adjust_tz = apply_filters( 'gravityview_date_created_adjust_timezone', true, $context ); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* date_created is stored in UTC format. Fetch in the current blog's timezone if $adjust_tz is true |
46
|
|
|
*/ |
47
|
|
|
$tz_value = $adjust_tz ? get_date_from_gmt( $value ) : $value; |
48
|
|
|
|
49
|
|
|
if( $format ) { |
50
|
|
|
|
51
|
|
|
$output = date_i18n( $format, strtotime( $tz_value ) ); |
52
|
|
|
|
53
|
|
|
} else { |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @filter `gravityview_date_format` Whether to override the Gravity Forms date format with a PHP date format |
57
|
|
|
* @see https://codex.wordpress.org/Formatting_Date_and_Time |
58
|
|
|
* @param null|string Date Format (default: $field->dateFormat) |
59
|
|
|
*/ |
60
|
|
|
$format = apply_filters( 'gravityview_date_format', rgar($field, "dateFormat") ); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$output = GFCommon::date_display( $tz_value, $format ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $output; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
new GravityView_Field_Created_By; |
71
|
|
|
|
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.