Parsi Date - Version 2.3.3

Version Description

  • Fix WooCommerce Sale Price Dates (From/To)
Download this release

Release Info

Developer parselearn
Plugin Icon Parsi Date
Version 2.3.3
Comparing to
See all releases

Code changes from version 2.3.2 to 2.3.3

.gitignore ADDED
@@ -0,0 +1 @@
 
1
+ .idea/
includes/fixes-dates.php CHANGED
@@ -9,14 +9,20 @@
9
 
10
  global $wpp_settings;
11
 
12
- if ( get_locale() == 'fa_IR' && $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
  /**
@@ -27,19 +33,20 @@ if ( get_locale() == 'fa_IR' && $wpp_settings['persian_date'] != 'disable' ) {
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
  /**
@@ -50,18 +57,19 @@ function wpp_fix_post_date( $time, $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
  /**
@@ -72,18 +80,19 @@ function wpp_fix_post_time( $time, $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
  /**
@@ -94,18 +103,19 @@ function wpp_fix_comment_time( $time, $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
  /**
@@ -117,26 +127,45 @@ function wpp_fix_comment_date( $time, $format = '' ) {
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
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  global $wpp_settings;
11
 
12
+ if (get_locale() == 'fa_IR' && $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
+ } else {
21
+ /*remove_filter('the_time', 'wpp_fix_post_time', 1001);
22
+ remove_filter('the_date', 'wpp_fix_post_date', 1001);
23
+ remove_filter('get_comment_time', 'wpp_fix_comment_time', 1001);
24
+ remove_filter('get_comment_date', 'wpp_fix_comment_date', 1001);
25
+ remove_filter('date_i18n', 'wpp_fix_i18n', 1001);*/
26
  }
27
 
28
  /**
33
  *
34
  * @return string Formatted date
35
  */
36
+ function wpp_fix_post_date($time, $format = '')
37
+ {
38
+ global $post, $wpp_settings;
39
 
40
+ // It's seems some plugin like acf does not exits $post.
41
+ if (empty($post)) {
42
+ return $time;
43
+ }
44
 
45
+ if (empty($format)) {
46
+ $format = get_option('date_format');
47
+ }
48
 
49
+ return parsidate($format, $post->post_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per');
50
  }
51
 
52
  /**
57
  *
58
  * @return string Formatted date
59
  */
60
+ function wpp_fix_post_time($time, $format = '')
61
+ {
62
+ global $post, $wpp_settings;
63
 
64
+ if (empty($post)) {
65
+ return $time;
66
+ }
67
 
68
+ if (empty($format)) {
69
+ $format = get_option('time_format');
70
+ }
71
 
72
+ return parsidate($format, $post->post_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per');
73
  }
74
 
75
  /**
80
  *
81
  * @return string Formatted date
82
  */
83
+ function wpp_fix_comment_time($time, $format = '')
84
+ {
85
+ global $comment, $wpp_settings;
86
 
87
+ if (empty($comment)) {
88
+ return $time;
89
+ }
90
 
91
+ if (empty($format)) {
92
+ $format = get_option('time_format');
93
+ }
94
 
95
+ return parsidate($format, $comment->comment_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per');
96
  }
97
 
98
  /**
103
  *
104
  * @return string Formatted date
105
  */
106
+ function wpp_fix_comment_date($time, $format = '')
107
+ {
108
+ global $comment, $wpp_settings;
109
 
110
+ if (empty($comment)) {
111
+ return $time;
112
+ }
113
 
114
+ if (empty($format)) {
115
+ $format = get_option('date_format');
116
+ }
117
 
118
+ return parsidate($format, $comment->comment_date, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per');
119
  }
120
 
121
  /**
127
  *
128
  * @return string Formatted time
129
  */
130
+ function wpp_fix_i18n($format_string, $timestamp, $gmt)
131
+ {
132
+ global $wpp_settings;
133
+
134
+ if (function_exists('debug_backtrace')) {
135
+ $callers = debug_backtrace();
136
+
137
+ // WordPress SEO OpenGraph Dates fix
138
+ if (
139
+ (isset($callers[6]['class']) && $callers[6]['class'] == 'WPSEO_OpenGraph') ||
140
+ (isset($callers[6]['function']) && $callers[6]['function'] == 'get_the_modified_date')
141
+ )
142
+ return $format_string;
143
+
144
+ // WooCommerce (Order & Product MetaBox)
145
+ if (
146
+ (isset($callers['4']['class']) && $callers['4']['class'] == 'WC_Meta_Box_Order_Data') ||
147
+ (isset($callers['5']['class']) && $callers['5']['class'] == 'WC_Meta_Box_Product_Data')
148
+ )
149
+ return $format_string;
150
+
151
+ }
152
+
153
+ return parsidate($timestamp, $gmt, $wpp_settings['conv_dates'] == 'disable' ? 'eng' : 'per');
154
  }
155
+
156
+ function array_key_exists_r($needle, $haystack, $value = null)
157
+ {
158
+ $result = array_key_exists($needle, $haystack);
159
+ if ($result) {
160
+ if ($value != null && $haystack[$needle])
161
+ return 1;
162
+ return $result;
163
+ }
164
+ foreach ($haystack as $v) {
165
+ if (is_array($v) || is_object($v))
166
+ $result = array_key_exists_r($needle, $v);
167
+ if ($result)
168
+ return $result;
169
+ }
170
+ return $result;
171
+ }
includes/fixes-misc.php CHANGED
@@ -49,4 +49,20 @@ if (get_locale() == 'fa_IR') {
49
  add_filter('wp_title', 'fixarabic', 1000);
50
  add_filter('pre_get_document_title', 'fixarabic', 1000); // WP 4.4+
51
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
49
  add_filter('wp_title', 'fixarabic', 1000);
50
  add_filter('pre_get_document_title', 'fixarabic', 1000); // WP 4.4+
51
  }
52
+ } else {
53
+ /*remove_filter('wp_title', 'fixnumber', 1001);
54
+ remove_filter('pre_get_document_title', 'fixnumber', 1001); // WP 4.4+
55
+ remove_filter('the_title', 'fixnumber', 1001);
56
+ remove_filter('the_content', 'fixnumber', 1001);
57
+ remove_filter('the_excerpt', 'fixnumber', 1001);
58
+ remove_filter('comment_text', 'fixnumber', 1001);
59
+ remove_filter('comments_number', 'fixnumber', 1001);
60
+ remove_filter('wp_list_categories', 'fixnumber', 1001);
61
+ remove_filter('the_content', 'fixarabic', 1001);
62
+ remove_filter('the_title', 'fixarabic', 1001);
63
+ remove_filter('comment_text', 'fixarabic', 1001);
64
+ remove_filter('wp_list_categories', 'fixarabic', 1001);
65
+ remove_filter('the_excerpt', 'fixarabic', 1001);
66
+ remove_filter('wp_title', 'fixarabic', 1001);
67
+ remove_filter('pre_get_document_title', 'fixarabic', 1001); // WP 4.4+*/
68
  }
includes/general.php CHANGED
@@ -9,10 +9,10 @@
9
  */
10
  global $wpp_settings;
11
 
12
- add_filter( 'login_headerurl', 'wpp_login_headerurl', 10, 2 );
13
- add_filter( 'locale', 'wp_parsi_set_locale' );
14
- add_action( 'admin_notices', 'wpp_activation_notice' );
15
- add_action( 'admin_init', 'wpp_dismiss_notice_action' );
16
 
17
  /**
18
  * Change Locale WordPress Admin and Front-end user
@@ -22,28 +22,32 @@ add_action( 'admin_init', 'wpp_dismiss_notice_action' );
22
  *
23
  * @return String
24
  */
25
- function wp_parsi_set_locale( $locale ) {
26
- $settings = get_option( 'wpp_settings' );
27
- if ( $settings['admin_lang'] == 'enable' ) {
28
- $admin_locale = "fa_IR";
29
- } elseif ( $settings['admin_lang'] == 'disable' ) {
30
- $admin_locale = "en_US";
31
- }
32
- if ( $settings['user_lang'] == 'enable' ) {
33
- $user_locale = "fa_IR";
34
- } elseif ( $settings['user_lang'] == 'disable' ) {
35
- $user_locale = "en_US";
36
- }
37
-
38
- $locale_s = ( is_admin() ) ? $admin_locale : $user_locale;
39
-
40
- if ( ! empty( $locale_s ) ) {
41
- $locale = $locale_s;
42
- }
43
-
44
- setlocale( LC_ALL, $locale );
45
-
46
- return $locale;
 
 
 
 
47
  }
48
 
49
 
@@ -53,16 +57,17 @@ function wp_parsi_set_locale( $locale ) {
53
  * @since 1.0
54
  * @return bool True when page is feed, false when page isn't feed
55
  */
56
- function wpp_is_feed() {
57
- if ( is_feed() ) {
58
- return true;
59
- }
 
60
 
61
- $path = $_SERVER['REQUEST_URI'];
62
- $exts = array( 'xml', 'gz', 'xsl' );
63
- $ext = pathinfo( $path, PATHINFO_EXTENSION );
64
 
65
- return in_array( $ext, $exts );
66
  }
67
 
68
  /**
@@ -72,12 +77,13 @@ function wpp_is_feed() {
72
  *
73
  * @return string Formatted numbers
74
  */
75
- function per_number( $number ) {
76
- return str_replace(
77
- range( 0, 9 ),
78
- array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ),
79
- $number
80
- );
 
81
  }
82
 
83
  /**
@@ -87,12 +93,13 @@ function per_number( $number ) {
87
  *
88
  * @return string Formatted numbers
89
  */
90
- function eng_number( $number ) {
91
- return str_replace(
92
- array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ),
93
- range( 0, 9 ),
94
- $number
95
- );
 
96
  }
97
 
98
  /**
@@ -102,10 +109,11 @@ function eng_number( $number ) {
102
  *
103
  * @return string Formatted content
104
  */
105
- function persian_number( $content ) {
106
- return (
107
- isset( $content[1] ) ? per_number( $content[1] ) : $content[0]
108
- );
 
109
  }
110
 
111
  /**
@@ -115,8 +123,9 @@ function persian_number( $content ) {
115
  *
116
  * @return mixed
117
  */
118
- function fixnumber( $content ) {
119
- return preg_replace_callback( '/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\.\d]*)|<\s*[^>]+>/i', 'persian_number', $content );
 
120
  }
121
 
122
  /**
@@ -126,8 +135,9 @@ function fixnumber( $content ) {
126
  *
127
  * @return mixed
128
  */
129
- function fixarabic( $content ) {
130
- return str_replace( array( 'ي', 'ك', '٤', '٥', '٦', 'ة' ), array( 'ی', 'ک', '۴', '۵', '۶', 'ه' ), $content );
 
131
  }
132
 
133
  /**
@@ -135,8 +145,9 @@ function fixarabic( $content ) {
135
  *
136
  * @return string
137
  */
138
- function wpp_login_headerurl() {
139
- return 'http://wp-parsi.com';
 
140
  }
141
 
142
  /**
@@ -146,17 +157,18 @@ function wpp_login_headerurl() {
146
  * @author Ehsaan
147
  * @return void
148
  */
149
- function wpp_activation_notice() {
150
- $dismissed = get_option( 'wpp_dismissed', false );
151
-
152
- if ( ! $dismissed ) {
153
- global $wpp_settings;
154
-
155
- if ( $wpp_settings['persian_date'] != 'enable' ) {
156
- $output = sprintf( __( '<div class="updated wpp-message"><p>ParsiDate activated, you may need to configure it to work properly. <a href="%s">Go to configuartion page</a> &ndash; <a href="%s">Dismiss</a></p></div>', 'wp-parsidate' ), admin_url( 'admin.php?page=wp-parsi-settings' ), add_query_arg( 'wpp-action', 'dismiss-notice' ) );
157
- echo $output;
158
- }
159
- }
 
160
  }
161
 
162
  /**
@@ -165,8 +177,9 @@ function wpp_activation_notice() {
165
  * @author Ehsaan
166
  * @return void
167
  */
168
- function wpp_dismiss_notice_action() {
169
- if ( isset( $_GET['wpp-action'] ) && $_GET['wpp-action'] == 'dismiss-notice' ) {
170
- update_option( 'wpp_dismissed', true );
171
- }
 
172
  }
9
  */
10
  global $wpp_settings;
11
 
12
+ add_filter('login_headerurl', 'wpp_login_headerurl', 10, 2);
13
+ add_filter('locale', 'wp_parsi_set_locale', 0);
14
+ add_action('admin_notices', 'wpp_activation_notice');
15
+ add_action('admin_init', 'wpp_dismiss_notice_action');
16
 
17
  /**
18
  * Change Locale WordPress Admin and Front-end user
22
  *
23
  * @return String
24
  */
25
+ function wp_parsi_set_locale($locale)
26
+ {
27
+ global $locale;
28
+ $settings = get_option('wpp_settings');
29
+ $user_locale = $admin_locale = $locale;
30
+
31
+ if ($settings['admin_lang'] == 'enable') {
32
+ $admin_locale = "fa_IR";
33
+ } elseif ($locale == 'fa_IR' && $settings['admin_lang'] == 'disable') {
34
+ $admin_locale = "en_US";
35
+ }
36
+ if ($settings['user_lang'] == 'enable') {
37
+ $user_locale = "fa_IR";
38
+ } elseif ($locale == 'fa_IR' && $settings['user_lang'] == 'disable') {
39
+ $user_locale = "en_US";
40
+ }
41
+
42
+ $locale_s = is_admin() ? $admin_locale : $user_locale;
43
+
44
+ if (!empty($locale_s)) {
45
+ $locale = $locale_s;
46
+ }
47
+
48
+ setlocale(LC_ALL, $locale);
49
+
50
+ return $locale;
51
  }
52
 
53
 
57
  * @since 1.0
58
  * @return bool True when page is feed, false when page isn't feed
59
  */
60
+ function wpp_is_feed()
61
+ {
62
+ if (is_feed()) {
63
+ return true;
64
+ }
65
 
66
+ $path = $_SERVER['REQUEST_URI'];
67
+ $exts = array('xml', 'gz', 'xsl');
68
+ $ext = pathinfo($path, PATHINFO_EXTENSION);
69
 
70
+ return in_array($ext, $exts);
71
  }
72
 
73
  /**
77
  *
78
  * @return string Formatted numbers
79
  */
80
+ function per_number($number)
81
+ {
82
+ return str_replace(
83
+ range(0, 9),
84
+ array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'),
85
+ $number
86
+ );
87
  }
88
 
89
  /**
93
  *
94
  * @return string Formatted numbers
95
  */
96
+ function eng_number($number)
97
+ {
98
+ return str_replace(
99
+ array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'),
100
+ range(0, 9),
101
+ $number
102
+ );
103
  }
104
 
105
  /**
109
  *
110
  * @return string Formatted content
111
  */
112
+ function persian_number($content)
113
+ {
114
+ return (
115
+ isset($content[1]) ? per_number($content[1]) : $content[0]
116
+ );
117
  }
118
 
119
  /**
123
  *
124
  * @return mixed
125
  */
126
+ function fixnumber($content)
127
+ {
128
+ return preg_replace_callback('/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\.\d]*)|<\s*[^>]+>/i', 'persian_number', $content);
129
  }
130
 
131
  /**
135
  *
136
  * @return mixed
137
  */
138
+ function fixarabic($content)
139
+ {
140
+ return str_replace(array('ي', 'ك', '٤', '٥', '٦', 'ة'), array('ی', 'ک', '۴', '۵', '۶', 'ه'), $content);
141
  }
142
 
143
  /**
145
  *
146
  * @return string
147
  */
148
+ function wpp_login_headerurl()
149
+ {
150
+ return 'http://wp-parsi.com';
151
  }
152
 
153
  /**
157
  * @author Ehsaan
158
  * @return void
159
  */
160
+ function wpp_activation_notice()
161
+ {
162
+ $dismissed = get_option('wpp_dismissed', false);
163
+
164
+ if (!$dismissed) {
165
+ global $wpp_settings;
166
+
167
+ if ($wpp_settings['persian_date'] != 'enable') {
168
+ $output = sprintf(__('<div class="updated wpp-message"><p>ParsiDate activated, you may need to configure it to work properly. <a href="%s">Go to configuartion page</a> &ndash; <a href="%s">Dismiss</a></p></div>', 'wp-parsidate'), admin_url('admin.php?page=wp-parsi-settings'), add_query_arg('wpp-action', 'dismiss-notice'));
169
+ echo $output;
170
+ }
171
+ }
172
  }
173
 
174
  /**
177
  * @author Ehsaan
178
  * @return void
179
  */
180
+ function wpp_dismiss_notice_action()
181
+ {
182
+ if (isset($_GET['wpp-action']) && $_GET['wpp-action'] == 'dismiss-notice') {
183
+ update_option('wpp_dismissed', true);
184
+ }
185
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://forum.wp-parsi.com/
4
  Tags: shamsi, wp-parsi, wpparsi, persian, parsi, farsi, jalali, date, calendar, i18n, l10n, Iran, Iranian, parsidate, rtl
5
  Requires at least: 3.6
6
  Tested up to: 4.8
7
- Stable tag: 2.3.2
8
 
9
  Persian date support for WordPress
10
 
@@ -41,6 +41,9 @@ List of some features:
41
  4. 'Jalali Date Calender' in action
42
 
43
  == Changelog ==
 
 
 
44
  = 2.3.2 =
45
  * Change date based on WordPress language (Persian/Farsi)
46
  * Compatible with WP Multilingual plugin (WPML)
4
  Tags: shamsi, wp-parsi, wpparsi, persian, parsi, farsi, jalali, date, calendar, i18n, l10n, Iran, Iranian, parsidate, rtl
5
  Requires at least: 3.6
6
  Tested up to: 4.8
7
+ Stable tag: 2.3.3
8
 
9
  Persian date support for WordPress
10
 
41
  4. 'Jalali Date Calender' in action
42
 
43
  == Changelog ==
44
+ = 2.3.3 =
45
+ * Fix WooCommerce Sale Price Dates (From/To)
46
+
47
  = 2.3.2 =
48
  * Change date based on WordPress language (Persian/Farsi)
49
  * Compatible with WP Multilingual plugin (WPML)
wp-parsidate.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Plugin Name: WP-Parsidate
4
- * Version: 2.3.2
5
  * Plugin URI: http://forum.wp-parsi.com/
6
  * Description: Persian package for WordPress, Adds full RTL and Shamsi (Jalali) support for: posts, comments, pages, archives, search, categories, permalinks and all admin sections and TinyMce editor, lists, quick editor. This package has Jalali archive widget.
7
  * Author: WP-Parsi Team
1
  <?php
2
  /**
3
  * Plugin Name: WP-Parsidate
4
+ * Version: 2.3.3
5
  * Plugin URI: http://forum.wp-parsi.com/
6
  * Description: Persian package for WordPress, Adds full RTL and Shamsi (Jalali) support for: posts, comments, pages, archives, search, categories, permalinks and all admin sections and TinyMce editor, lists, quick editor. This package has Jalali archive widget.
7
  * Author: WP-Parsi Team