PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 2.3.1
پارسی دیت – Parsi Date v2.3.1
6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / includes / fixes-dates.php
wp-parsidate / includes Last commit date
admin 9 years ago plugins 9 years ago widget 9 years ago fixes-archive.php 9 years ago fixes-archives.php 9 years ago fixes-calendar.php 9 years ago fixes-dates.php 9 years ago fixes-misc.php 9 years ago fixes-permalinks.php 9 years ago general.php 9 years ago install.php 9 years ago parsidate.php 9 years ago settings.php 9 years ago
fixes-dates.php
143 lines
1 <?php
2 /**
3 * Fixes dates and convert them to Jalali date.
4 *
5 * @author Mobin Ghasempoor
6 * @package WP-Parsidate
7 * @subpackage Fixes/Dates
8 */
9
10 global $wpp_settings;
11
12 if ( $wpp_settings['persian_date'] != 'disable' ) {
13 add_filter( 'the_time', 'wpp_fix_post_time', 10, 2 );
14 add_filter( 'the_date', 'wpp_fix_post_date', 10, 2 );
15 add_filter( 'get_comment_time', 'wpp_fix_comment_time', 10, 2 );
16 add_filter( 'get_comment_date', 'wpp_fix_comment_date', 10, 2 );
17 //add_filter( 'get_post_modified_time', 'wpp_fix_post_date', 10, 2 );
18
19 add_action( 'date_i18n', 'wpp_fix_i18n', 10, 3 );
20 }
21
22 /**
23 * Fixes post date and returns in Jalali format
24 *
25 * @param string $time Post time
26 * @param string $format Date format
27 *
28 * @return string Formatted date
29 */
30 function wpp_fix_post_date( $time, $format = '' ) {
31 global $post, $wpp_settings;
32
33 // It's seems some plugin like acf does not exits $post.
34 if ( empty( $post ) ) {
35 return $time;
36 }
37
38 if ( empty( $format ) ) {
39 $format = get_option( 'date_format' );
40 }
41
42 return parsidate( $format, $post->post_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per' );
43 }
44
45 /**
46 * Fixes post time and returns in Jalali format
47 *
48 * @param string $time Post time
49 * @param string $format Date format
50 *
51 * @return string Formatted date
52 */
53 function wpp_fix_post_time( $time, $format = '' ) {
54 global $post, $wpp_settings;
55
56 if ( empty( $post ) ) {
57 return $time;
58 }
59
60 if ( empty( $format ) ) {
61 $format = get_option( 'time_format' );
62 }
63
64 return parsidate( $format, $post->post_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per' );
65 }
66
67 /**
68 * Fixes comment time and returns in Jalali format
69 *
70 * @param string $time Comment time
71 * @param string $fomat Date format
72 *
73 * @return string Formatted date
74 */
75 function wpp_fix_comment_time( $time, $format = '' ) {
76 global $comment, $wpp_settings;
77
78 if ( empty( $comment ) ) {
79 return $time;
80 }
81
82 if ( empty( $format ) ) {
83 $format = get_option( 'time_format' );
84 }
85
86 return parsidate( $format, $comment->comment_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per' );
87 }
88
89 /**
90 * Fixes comment date and returns in Jalali format
91 *
92 * @param string $time Comment time
93 * @param string $format Date format
94 *
95 * @return string Formatted date
96 */
97 function wpp_fix_comment_date( $time, $format = '' ) {
98 global $comment, $wpp_settings;
99
100 if ( empty( $comment ) ) {
101 return $time;
102 }
103
104 if ( empty( $format ) ) {
105 $format = get_option( 'date_format' );
106 }
107
108 return parsidate( $format, $comment->comment_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per' );
109 }
110
111 /**
112 * Fixes i18n date formatting and convert them to Jalali
113 *
114 * @param string $format_string Date format
115 * @param string $timestamp Unix timestamp
116 * @param string $gmt GMT timestamp
117 *
118 * @return string Formatted time
119 */
120 function wpp_fix_i18n( $format_string, $timestamp, $gmt ) {
121 global $wpp_settings;
122
123 if ( function_exists( 'debug_backtrace' ) ) {
124 $callers = debug_backtrace();
125
126 // WordPress SEO OpenGraph Dates fix
127 if ( isset( $callers[6]['class'] ) && $callers[6]['class'] == 'WPSEO_OpenGraph' ) {
128 return $format_string;
129 }
130
131 if ( isset( $callers[6]['function'] ) && $callers[6]['function'] == 'get_the_modified_date' ) {
132 return $format_string;
133 }
134
135 // WooCommerce order detail fix
136 if ( isset( $callers['4']['class'] ) && $callers['4']['class'] == 'WC_Meta_Box_Order_Data' ) {
137 return $format_string;
138 }
139 }
140
141 return parsidate( $timestamp, $gmt, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per' );
142 }
143