PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 2.2.2
پارسی دیت – Parsi Date v2.2.2
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
126 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 * @return string Formatted date
28 */
29 function wpp_fix_post_date( $time, $format = '' ) {
30 global $post, $wpp_settings;
31
32 // It's seems some plugin like acf does not exits $post.
33 if( empty($post) )
34 return $time;
35
36 if ( empty( $format ) )
37 $format = get_option( 'date_format' );
38
39 if ( $wpp_settings['conv_dates'] == 'disable' )
40 return parsidate( $format, $post->post_date, 'eng' );
41 else
42 return parsidate( $format, $post->post_date );
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 * @return string Formatted date
51 */
52 function wpp_fix_post_time( $time, $format = '' ) {
53 global $post, $wpp_settings;
54 if ( empty( $format ) )
55 $format = get_option( 'time_format' );
56
57 if ( $wpp_settings['conv_dates'] == 'disable' )
58 return parsidate( $format, $post->post_date, 'eng' );
59 else
60 return parsidate( $format, $post->post_date );
61 }
62
63 /**
64 * Fixes comment time and returns in Jalali format
65 *
66 * @param string $time Comment time
67 * @param string $fomat Date format
68 * @return string Formatted date
69 */
70 function wpp_fix_comment_time( $time, $format = '' ) {
71 global $comment, $wpp_settings;
72 if ( empty( $format ) )
73 $format = get_option( 'time_format' );
74
75 if ( $wpp_settings['conv_dates'] == 'disable' )
76 return parsidate( $format, $comment->comment_date, 'eng' );
77 else
78 return parsidate( $format, $comment->comment_date );
79 }
80
81 /**
82 * Fixes comment date and returns in Jalali format
83 *
84 * @param string $time Comment time
85 * @param string $fomat Date format
86 * @return string Formatted date
87 */
88 function wpp_fix_comment_date( $time, $format = '' ) {
89 global $comment, $wpp_settings;
90 if ( empty( $format ) )
91 $format = get_option( 'date_format' );
92
93 if ( $wpp_settings['conv_dates'] == 'disable' )
94 return parsidate( $format, $comment->comment_date, 'eng' );
95 else
96 return parsidate( $format, $comment->comment_date );
97 }
98
99 /**
100 * Fixes i18n date formatting and convert them to Jalali
101 *
102 * @param string $format_string Date format
103 * @param string $timestamp Unix timestamp
104 * @param string $gmt GMT timestamp
105 * @return string Formatted time
106 */
107 function wpp_fix_i18n( $format_string, $timestamp, $gmt ) {
108 global $wpp_settings;
109
110 if(function_exists('debug_backtrace')) {
111 $callers = debug_backtrace();
112
113 // WordPress SEO OpenGraph Dates fix
114 if (isset($callers[6]['class']) && $callers[6]['class'] == 'WPSEO_OpenGraph') return $format_string;
115 if (isset($callers[6]['function']) && $callers[6]['function'] == 'get_the_modified_date') return $format_string;
116
117 // WooCommerce order detail fix
118 if(isset($callers['4']['class']) && $callers['4']['class']=='WC_Meta_Box_Order_Data') return $format_string;
119 }
120
121 if ( $wpp_settings['conv_dates'] == 'disable' )
122 return parsidate( $timestamp, $gmt, 'eng' );
123 else
124 return parsidate( $timestamp, $gmt );
125 }
126