Parsi Date - Version 2.3.2

Version Description

  • Change date based on WordPress language (Persian/Farsi)
  • Compatible with WP Multilingual plugin (WPML)
Download this release

Release Info

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

Code changes from version 2.3.1 to 2.3.2

includes/fixes-dates.php CHANGED
@@ -9,7 +9,7 @@
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 );
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 );
includes/fixes-misc.php CHANGED
@@ -8,43 +8,45 @@
8
  * @subpackage Fixes/NumbersAndArabic
9
  */
10
 
11
- global $wpp_settings;
12
-
13
- if ( isset( $wpp_settings['conv_page_title'] ) && $wpp_settings['conv_page_title'] != 'disable' ) {
14
- add_filter( 'wp_title', 'fixnumber', 1000 );
15
- add_filter( 'pre_get_document_title', 'fixnumber', 1000 ); // WP 4.4+
16
- }
17
-
18
- if ( isset( $wpp_settings['conv_title'] ) && $wpp_settings['conv_title'] != 'disable' ) {
19
- add_filter( 'the_title', 'fixnumber', 1000 );
20
- }
21
-
22
- if ( isset( $wpp_settings['conv_contents'] ) && $wpp_settings['conv_contents'] != 'disable' ) {
23
- add_filter( 'the_content', 'fixnumber', 1000 );
24
- }
25
-
26
- if ( isset( $wpp_settings['conv_excerpt'] ) && $wpp_settings['conv_excerpt'] != 'disable' ) {
27
- add_filter( 'the_excerpt', 'fixnumber', 1000 );
28
- }
29
-
30
- if ( isset( $wpp_settings['conv_comments'] ) && $wpp_settings['conv_comments'] != 'disable' ) {
31
- add_filter( 'comment_text', 'fixnumber', 1000 );
32
- }
33
-
34
- if ( isset( $wpp_settings['conv_comment_count'] ) && $wpp_settings['conv_comment_count'] != 'disable' ) {
35
- add_filter( 'comments_number', 'fixnumber', 1000 );
36
- }
37
-
38
- if ( isset( $wpp_settings['conv_cats'] ) && $wpp_settings['conv_cats'] != 'disable' ) {
39
- add_filter( 'wp_list_categories', 'fixnumber', 1000 );
40
- }
41
-
42
- if ( isset( $wpp_settings['conv_arabic'] ) && $wpp_settings['conv_arabic'] != 'disable' ) {
43
- add_filter( 'the_content', 'fixarabic' ,1000);
44
- add_filter( 'the_title', 'fixarabic' ,1000);
45
- add_filter( 'comment_text', 'fixarabic',1000 );
46
- add_filter( 'wp_list_categories', 'fixarabic',1000 );
47
- add_filter( 'the_excerpt', 'fixarabic' ,1000);
48
- add_filter( 'wp_title', 'fixarabic', 1000 );
49
- add_filter( 'pre_get_document_title', 'fixarabic', 1000 ); // WP 4.4+
50
- }
 
 
8
  * @subpackage Fixes/NumbersAndArabic
9
  */
10
 
11
+ if (get_locale() == 'fa_IR') {
12
+ global $wpp_settings;
13
+
14
+ if (isset($wpp_settings['conv_page_title']) && $wpp_settings['conv_page_title'] != 'disable') {
15
+ add_filter('wp_title', 'fixnumber', 1000);
16
+ add_filter('pre_get_document_title', 'fixnumber', 1000); // WP 4.4+
17
+ }
18
+
19
+ if (isset($wpp_settings['conv_title']) && $wpp_settings['conv_title'] != 'disable') {
20
+ add_filter('the_title', 'fixnumber', 1000);
21
+ }
22
+
23
+ if (isset($wpp_settings['conv_contents']) && $wpp_settings['conv_contents'] != 'disable') {
24
+ add_filter('the_content', 'fixnumber', 1000);
25
+ }
26
+
27
+ if (isset($wpp_settings['conv_excerpt']) && $wpp_settings['conv_excerpt'] != 'disable') {
28
+ add_filter('the_excerpt', 'fixnumber', 1000);
29
+ }
30
+
31
+ if (isset($wpp_settings['conv_comments']) && $wpp_settings['conv_comments'] != 'disable') {
32
+ add_filter('comment_text', 'fixnumber', 1000);
33
+ }
34
+
35
+ if (isset($wpp_settings['conv_comment_count']) && $wpp_settings['conv_comment_count'] != 'disable') {
36
+ add_filter('comments_number', 'fixnumber', 1000);
37
+ }
38
+
39
+ if (isset($wpp_settings['conv_cats']) && $wpp_settings['conv_cats'] != 'disable') {
40
+ add_filter('wp_list_categories', 'fixnumber', 1000);
41
+ }
42
+
43
+ if (isset($wpp_settings['conv_arabic']) && $wpp_settings['conv_arabic'] != 'disable') {
44
+ add_filter('the_content', 'fixarabic', 1000);
45
+ add_filter('the_title', 'fixarabic', 1000);
46
+ add_filter('comment_text', 'fixarabic', 1000);
47
+ add_filter('wp_list_categories', 'fixarabic', 1000);
48
+ add_filter('the_excerpt', 'fixarabic', 1000);
49
+ add_filter('wp_title', 'fixarabic', 1000);
50
+ add_filter('pre_get_document_title', 'fixarabic', 1000); // WP 4.4+
51
+ }
52
+ }
includes/fixes-permalinks.php CHANGED
@@ -8,128 +8,130 @@
8
  */
9
  global $wpp_settings;
10
 
11
- if ( $wpp_settings['conv_permalinks'] == 'enable' ) {
12
- add_filter( 'posts_where', 'wpp_posts_where' );
13
- add_action( 'pre_get_posts', 'wpp_pre_get_posts' );
14
- add_filter( 'post_link', 'wpp_permalink', 10, 3 );
15
  }
16
 
17
  /**
18
  * Converts post date pointer to Jalali pointer
19
  *
20
  * @param string $where
 
21
  *
22
  * @return string
23
  */
24
- function wpp_posts_where( $where ) {
25
- global $wp_query, $wpdb;
26
- if ( empty( $wp_query->query_vars ) ) {
27
- return $where;
28
- }
29
-
30
- $pd = bn_parsidate::getInstance();
31
-
32
- $m = ( isset( $wp_query->query_vars['m'] ) ) ? $wp_query->query_vars['m'] : '';
33
- $hour = ( isset( $wp_query->query_vars['hour'] ) ) ? $wp_query->query_vars['hour'] : '';
34
- $minute = ( isset( $wp_query->query_vars['minute'] ) ) ? $wp_query->query_vars['minute'] : '';
35
- $second = ( isset( $wp_query->query_vars['second'] ) ) ? $wp_query->query_vars['second'] : '';
36
- $year = ( isset( $wp_query->query_vars['year'] ) ) ? $wp_query->query_vars['year'] : '';
37
- $month = ( isset( $wp_query->query_vars['month'] ) ) ? $wp_query->query_vars['month'] : '';
38
- $day = ( isset( $wp_query->query_vars['day'] ) ) ? $wp_query->query_vars['day'] : '';
39
-
40
- if ( ! empty( $m ) ) {
41
- $len = strlen( $m );
42
- $year = substr( $m, 0, 4 );
43
- if ( $len > 5 ) {
44
- $month = substr( $m, 4, 2 );
45
- }
46
- if ( $len > 7 ) {
47
- $day = substr( $m, 6, 2 );
48
- }
49
- if ( $len > 9 ) {
50
- $hour = substr( $m, 8, 2 );
51
- }
52
- if ( $len > 11 ) {
53
- $minute = substr( $m, 10, 2 );
54
- }
55
- if ( $len > 13 ) {
56
- $second = substr( $m, 12, 2 );
57
- }
58
- }
59
-
60
- if ( empty( $year ) || $year > 1700 ) {
61
- return $where;
62
- }
63
-
64
- $stamon = 1;
65
- $staday = 1;
66
- $stahou = '00';
67
- $stamin = '00';
68
- $stasec = '00';
69
- $endmon = 1;
70
- $endday = 1;
71
- $endhou = '00';
72
- $endmin = '00';
73
- $endsec = '00';
74
-
75
- $stayear = $year;
76
- $endyear = $year + 1;
77
-
78
- if ( $month != '' ) {
79
- $stamon = $month;
80
- $endmon = ( $month == 12 ? 1 : $month + 1 );
81
- $endyear = ( $endmon == 1 ? $stayear + 1 : $stayear );
82
- }
83
-
84
- if ( $day != '' ) {
85
- $staday = $day;
86
- $endday = ( $day == $pd->j_days_in_month[ (int) $month - 1 ] ? 1 : $day + 1 );
87
- $endmon = ( $endday == 1 ? $stamon + 1 : $stamon );
88
- }
89
-
90
- if ( $hour != '' ) {
91
- $stahou = $hour;
92
- $endhou = ( $hour == 24 ? '00' : $hour + 1 );
93
- $endday = ( $endhou == '00' ? $staday + 1 : $staday );
94
- }
95
-
96
- if ( $minute != '' ) {
97
- $stamin = $minute;
98
- $endmin = ( $minute == 59 ? '00' : $minute + 1 );
99
- $endhou = ( $endmin == '00' ? $stahou + 1 : $stahou );
100
- }
101
-
102
- if ( $second != '' ) {
103
- $stasec = $second;
104
- $endsec = ( $second == 59 ? '00' : $second + 1 );
105
- $endmin = ( $endsec == '00' ? $stamin + 1 : $stamin );
106
- }
107
-
108
- $stadate = "$stayear-$stamon-$staday";
109
- $enddate = "$endyear-$endmon-$endday";
110
- $stadate = gregdate( 'Y-m-d', $stadate );
111
- $enddate = gregdate( 'Y-m-d', $enddate );
112
- $stadate .= " $stahou:$stamin:$stasec";
113
- $enddate .= " $endhou:$endmin:$endsec";
114
-
115
- $patterns = array(
116
- '/YEAR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
117
- '/DAYOFMONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
118
- '/MONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
119
- '/HOUR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
120
- '/MINUTE\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
121
- '/SECOND\((.*?)post_date\s*\)\s*=\s*[0-9\']*/'
122
- );
123
- foreach ( $patterns as $pattern ) {
124
- $where = preg_replace( $pattern, '1=1', $where );
125
- }
126
-
127
- $prefixp = "{$wpdb->posts}.";
128
- $prefixp = ( strpos( $where, $prefixp ) == false ) ? '' : $prefixp;
129
-
130
- $where .= " AND {$prefixp}post_date >= '$stadate' AND {$prefixp}post_date < '$enddate' ";
131
-
132
- return $where;
 
133
  }
134
 
135
  /**
@@ -139,113 +141,114 @@ function wpp_posts_where( $where ) {
139
  *
140
  * @return mixed
141
  */
142
- function wpp_pre_get_posts( $query ) {
143
- global $wpdb;
144
-
145
- $permalink = $query->query;
146
- $year = '';
147
- $monthnum = '';
148
- $day = '';//start
149
-
150
- if ( isset( $permalink['year'] ) ) {
151
- $year = $permalink['year'];
152
- }
153
- if ( isset( $permalink['monthnum'] ) ) {
154
- $monthnum = $permalink['monthnum'];
155
- }
156
- if ( isset( $permalink['day'] ) ) {
157
- $day = $permalink['day'];
158
- }
159
- if ( $year > 1700 ) {
160
- return $query;
161
- }
162
-
163
- $out = false;
164
- $pd = bn_parsidate::getInstance();
165
- if ( isset( $permalink['name'] ) ) {
166
- $var = $wpdb->get_var( "SELECT post_date FROM {$wpdb->prefix}posts WHERE post_name='{$permalink['name']}' ORDER BY id" );
167
- $per = parsidate( 'Y-m-d', $var, 'eng' );
168
- //update_option('options', $per );
169
- $per = explode( '-', $per );
170
- $out = true;
171
-
172
- if ( $year != $per[0] ) {
173
- $out = false;
174
- }
175
- if ( $out && $monthnum != $per[1] ) {
176
- $out = false;
177
- }
178
- if ( $out && $day != $per[2] ) {
179
- $out = false;
180
- }
181
-
182
- } elseif ( isset( $permalink['post_id'] ) ) {
183
- $out = true;
184
- $var = $wpdb->get_var( "SELECT post_date FROM {$wpdb->prefix}posts WHERE ID={$permalink['post_id']}" );
185
- } elseif ( ! empty( $year ) && ! empty( $monthnum ) && ! empty( $day ) ) {
186
- $out = true;
187
- $var = gregdate( 'Y-m-d', "$year-$monthnum-$day" );
188
- } elseif ( ! empty( $year ) && ! empty( $monthnum ) ) {
189
- $stadate = $pd->persian_to_gregorian( $year, $monthnum, 1 );
190
- $enddate = $pd->persian_to_gregorian( $year, $monthnum, $pd->j_days_in_month[ ( $monthnum - 1 ) ] );
191
- $date_query = array(
192
- array(
193
- 'after' => array(
194
- 'year' => $stadate[0],
195
- 'month' => $stadate[1],
196
- 'day' => $stadate[2] - 1,
197
- ),
198
- 'before' => array(
199
- 'year' => $enddate[0],
200
- 'month' => $enddate[1],
201
- 'day' => $enddate[2] + 1,
202
- ),
203
- 'inclusive' => true,
204
- ),
205
- );
206
- $query->set( 'date_query', $date_query );
207
-
208
- // commented for get year & month in calander widget
209
- // $query->set('year', '');
210
- // $query->set('monthnum', '');
211
- $out = false;
212
-
213
- } elseif ( ! empty( $year ) ) {
214
- $stadate = $pd->persian_to_gregorian( $year, 1, 1 );
215
- $enddate = $pd->persian_to_gregorian( ( $year + 1 ), 1, 1 );
216
- $date_query = array(
217
- array(
218
- 'after' => array(
219
- 'year' => $stadate[0],
220
- 'month' => $stadate[1],
221
- 'day' => $stadate[2] - 1,
222
- ),
223
- 'before' => array(
224
- 'year' => $enddate[0],
225
- 'month' => $enddate[1],
226
- 'day' => $enddate[2],
227
- ),
228
- 'inclusive' => true,
229
- ),
230
- );
231
- $query->set( 'date_query', $date_query );
232
- // $query->set('year', '');
233
- $out = false;
234
- }
235
-
236
- if ( $out ) {
237
- preg_match_all( '!\d+!', $var, $matches );
238
- $var = $matches[0];
239
-
240
- $query->set( 'year', $var[0] );
241
- $query->set( 'monthnum', $var[1] );
242
- $query->set( 'day', $var[2] );
243
- }
244
-
245
- $query->is_404 = false;
246
- $query->query_vars['error'] = '';
247
-
248
- return $query;
 
249
 
250
  }
251
 
@@ -258,91 +261,92 @@ function wpp_pre_get_posts( $query ) {
258
  *
259
  * @return string New permalink
260
  */
261
- function wpp_permalink( $perma, $post, $leavename = false ) {
262
- if ( empty( $post->ID ) ) {
263
- return false;
264
- }
265
- if ( $post->post_type == 'page' || $post->post_status == 'static' ) {
266
- return get_page_link( $post->ID );
267
- } elseif ( $post->post_type == 'attachment' ) {
268
- return get_attachment_link( $post->ID );
269
- } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) {
270
- return get_post_permalink( $post->ID );
271
- }
272
-
273
- $permalink = get_option( 'permalink_structure' );
274
- preg_match_all( '/%([^\/]*)%/', $permalink, $rewritecode );
275
- $rewritecode = $rewritecode[0];
276
- if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
277
- if ( $leavename ) {
278
- $rewritecode = array_diff( $rewritecode, array( '%postname%', '%pagename%' ) );
279
- }
280
-
281
- $date = explode( ' ', parsidate( 'Y m d H i s', $post->post_date, 'eng' ) );
282
- $out = array();
283
-
284
- foreach ( $rewritecode as $rewrite ) {
285
- switch ( $rewrite ) {
286
- case '%year%':
287
- $out[] = $date[0];
288
- break;
289
- case '%monthnum%':
290
- $out[] = $date[1];
291
- break;
292
- case '%day%':
293
- $out[] = $date[2];
294
- break;
295
- case '%hour%':
296
- $out[] = $date[3];
297
- break;
298
- case '%minute%':
299
- $out[] = $date[4];
300
- break;
301
- case '%second%':
302
- $out[] = $date[5];
303
- break;
304
- case '%post_id%':
305
- $out[] = $post->ID;
306
- break;
307
- case '%postname%':
308
- $out[] = $post->post_name;
309
- break;
310
- case '%category%':
311
- $category = '';
312
- $cats = get_the_category( $post->ID );
313
- if ( $cats ) {
314
- usort( $cats, '_usort_terms_by_ID' );
315
- $category = $cats[0]->slug;
316
- if ( $parent = $cats[0]->parent ) {
317
- $category = get_category_parents( $parent, false, '/', true );
318
- }
319
-
320
- if ( $cats[0]->parent != 0 ) {
321
- $category .= $cats[0]->slug;
322
- }
323
- }
324
- if ( empty( $category ) ) {
325
- $default_category = get_term( get_option( 'default_category' ), 'category' );
326
- $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
327
- }
328
- $out[] = $category;
329
- break;
330
- case '%author%':
331
- $authordata = get_userdata( $post->post_author );
332
- $out[] = $authordata->user_nicename;
333
- break;
334
- case '%pagename%':
335
- $out[] = $post->post_name;
336
- break;
337
- default:
338
- unset( $rewritecode[ array_search( $rewrite, $rewritecode ) ] );
339
- break;
340
- }
341
- }
342
- $permalink = home_url( str_replace( $rewritecode, $out, $permalink ) );
343
-
344
- return user_trailingslashit( $permalink, 'single' );
345
- } else {
346
- return home_url( "?p=$post->ID" );
347
- }
 
348
  }
8
  */
9
  global $wpp_settings;
10
 
11
+ if ($wpp_settings['conv_permalinks'] == 'enable') {
12
+ add_filter('posts_where', 'wpp_posts_where', 10, 2);
13
+ add_action('pre_get_posts', 'wpp_pre_get_posts');
14
+ add_filter('post_link', 'wpp_permalink', 10, 3);
15
  }
16
 
17
  /**
18
  * Converts post date pointer to Jalali pointer
19
  *
20
  * @param string $where
21
+ * @param string $wp_query
22
  *
23
  * @return string
24
  */
25
+ function wpp_posts_where($where, $wp_query)
26
+ {
27
+ global $wpdb;
28
+ if (!$wp_query->is_main_query() || empty($wp_query->query_vars)) {
29
+ return $where;
30
+ }
31
+
32
+ $pd = bn_parsidate::getInstance();
33
+
34
+ $m = (isset($wp_query->query_vars['m'])) ? $wp_query->query_vars['m'] : '';
35
+ $hour = (isset($wp_query->query_vars['hour'])) ? $wp_query->query_vars['hour'] : '';
36
+ $minute = (isset($wp_query->query_vars['minute'])) ? $wp_query->query_vars['minute'] : '';
37
+ $second = (isset($wp_query->query_vars['second'])) ? $wp_query->query_vars['second'] : '';
38
+ $year = (isset($wp_query->query_vars['year'])) ? $wp_query->query_vars['year'] : '';
39
+ $month = (isset($wp_query->query_vars['month'])) ? $wp_query->query_vars['month'] : '';
40
+ $day = (isset($wp_query->query_vars['day'])) ? $wp_query->query_vars['day'] : '';
41
+
42
+ if (!empty($m)) {
43
+ $len = strlen($m);
44
+ $year = substr($m, 0, 4);
45
+ if ($len > 5) {
46
+ $month = substr($m, 4, 2);
47
+ }
48
+ if ($len > 7) {
49
+ $day = substr($m, 6, 2);
50
+ }
51
+ if ($len > 9) {
52
+ $hour = substr($m, 8, 2);
53
+ }
54
+ if ($len > 11) {
55
+ $minute = substr($m, 10, 2);
56
+ }
57
+ if ($len > 13) {
58
+ $second = substr($m, 12, 2);
59
+ }
60
+ }
61
+
62
+ if (empty($year) || $year > 1700) {
63
+ return $where;
64
+ }
65
+
66
+ $stamon = 1;
67
+ $staday = 1;
68
+ $stahou = '00';
69
+ $stamin = '00';
70
+ $stasec = '00';
71
+ $endmon = 1;
72
+ $endday = 1;
73
+ $endhou = '00';
74
+ $endmin = '00';
75
+ $endsec = '00';
76
+
77
+ $stayear = $year;
78
+ $endyear = $year + 1;
79
+
80
+ if ($month != '') {
81
+ $stamon = $month;
82
+ $endmon = ($month == 12 ? 1 : $month + 1);
83
+ $endyear = ($endmon == 1 ? $stayear + 1 : $stayear);
84
+ }
85
+
86
+ if ($day != '') {
87
+ $staday = $day;
88
+ $endday = ($day == $pd->j_days_in_month[(int)$month - 1] ? 1 : $day + 1);
89
+ $endmon = ($endday == 1 ? $stamon + 1 : $stamon);
90
+ }
91
+
92
+ if ($hour != '') {
93
+ $stahou = $hour;
94
+ $endhou = ($hour == 24 ? '00' : $hour + 1);
95
+ $endday = ($endhou == '00' ? $staday + 1 : $staday);
96
+ }
97
+
98
+ if ($minute != '') {
99
+ $stamin = $minute;
100
+ $endmin = ($minute == 59 ? '00' : $minute + 1);
101
+ $endhou = ($endmin == '00' ? $stahou + 1 : $stahou);
102
+ }
103
+
104
+ if ($second != '') {
105
+ $stasec = $second;
106
+ $endsec = ($second == 59 ? '00' : $second + 1);
107
+ $endmin = ($endsec == '00' ? $stamin + 1 : $stamin);
108
+ }
109
+
110
+ $stadate = "$stayear-$stamon-$staday";
111
+ $enddate = "$endyear-$endmon-$endday";
112
+ $stadate = gregdate('Y-m-d', $stadate);
113
+ $enddate = gregdate('Y-m-d', $enddate);
114
+ $stadate .= " $stahou:$stamin:$stasec";
115
+ $enddate .= " $endhou:$endmin:$endsec";
116
+
117
+ $patterns = array(
118
+ '/YEAR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
119
+ '/DAYOFMONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
120
+ '/MONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
121
+ '/HOUR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
122
+ '/MINUTE\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
123
+ '/SECOND\((.*?)post_date\s*\)\s*=\s*[0-9\']*/'
124
+ );
125
+ foreach ($patterns as $pattern) {
126
+ $where = preg_replace($pattern, '1=1', $where);
127
+ }
128
+
129
+ $prefixp = "{$wpdb->posts}.";
130
+ $prefixp = (strpos($where, $prefixp) == false) ? '' : $prefixp;
131
+
132
+ $where .= " AND {$prefixp}post_date >= '$stadate' AND {$prefixp}post_date < '$enddate' ";
133
+
134
+ return $where;
135
  }
136
 
137
  /**
141
  *
142
  * @return mixed
143
  */
144
+ function wpp_pre_get_posts($query)
145
+ {
146
+ global $wpdb;
147
+
148
+ $permalink = $query->query;
149
+ $year = '';
150
+ $monthnum = '';
151
+ $day = '';//start
152
+
153
+ if (isset($permalink['year'])) {
154
+ $year = $permalink['year'];
155
+ }
156
+ if (isset($permalink['monthnum'])) {
157
+ $monthnum = $permalink['monthnum'];
158
+ }
159
+ if (isset($permalink['day'])) {
160
+ $day = $permalink['day'];
161
+ }
162
+ if ($year > 1700) {
163
+ return $query;
164
+ }
165
+
166
+ $out = false;
167
+ $pd = bn_parsidate::getInstance();
168
+ if (isset($permalink['name'])) {
169
+ $var = $wpdb->get_var("SELECT post_date FROM {$wpdb->prefix}posts WHERE post_name='{$permalink['name']}' ORDER BY id");
170
+ $per = parsidate('Y-m-d', $var, 'eng');
171
+ //update_option('options', $per );
172
+ $per = explode('-', $per);
173
+ $out = true;
174
+
175
+ if ($year != $per[0]) {
176
+ $out = false;
177
+ }
178
+ if ($out && $monthnum != $per[1]) {
179
+ $out = false;
180
+ }
181
+ if ($out && $day != $per[2]) {
182
+ $out = false;
183
+ }
184
+
185
+ } elseif (isset($permalink['post_id'])) {
186
+ $out = true;
187
+ $var = $wpdb->get_var("SELECT post_date FROM {$wpdb->prefix}posts WHERE ID={$permalink['post_id']}");
188
+ } elseif (!empty($year) && !empty($monthnum) && !empty($day)) {
189
+ $out = true;
190
+ $var = gregdate('Y-m-d', "$year-$monthnum-$day");
191
+ } elseif (!empty($year) && !empty($monthnum)) {
192
+ $stadate = $pd->persian_to_gregorian($year, $monthnum, 1);
193
+ $enddate = $pd->persian_to_gregorian($year, $monthnum, $pd->j_days_in_month[($monthnum - 1)]);
194
+ $date_query = array(
195
+ array(
196
+ 'after' => array(
197
+ 'year' => $stadate[0],
198
+ 'month' => $stadate[1],
199
+ 'day' => $stadate[2] - 1,
200
+ ),
201
+ 'before' => array(
202
+ 'year' => $enddate[0],
203
+ 'month' => $enddate[1],
204
+ 'day' => $enddate[2] + 1,
205
+ ),
206
+ 'inclusive' => true,
207
+ ),
208
+ );
209
+ $query->set('date_query', $date_query);
210
+
211
+ // commented for get year & month in calander widget
212
+ // $query->set('year', '');
213
+ // $query->set('monthnum', '');
214
+ $out = false;
215
+
216
+ } elseif (!empty($year)) {
217
+ $stadate = $pd->persian_to_gregorian($year, 1, 1);
218
+ $enddate = $pd->persian_to_gregorian(($year + 1), 1, 1);
219
+ $date_query = array(
220
+ array(
221
+ 'after' => array(
222
+ 'year' => $stadate[0],
223
+ 'month' => $stadate[1],
224
+ 'day' => $stadate[2] - 1,
225
+ ),
226
+ 'before' => array(
227
+ 'year' => $enddate[0],
228
+ 'month' => $enddate[1],
229
+ 'day' => $enddate[2],
230
+ ),
231
+ 'inclusive' => true,
232
+ ),
233
+ );
234
+ $query->set('date_query', $date_query);
235
+ // $query->set('year', '');
236
+ $out = false;
237
+ }
238
+
239
+ if ($out) {
240
+ preg_match_all('!\d+!', $var, $matches);
241
+ $var = $matches[0];
242
+
243
+ $query->set('year', $var[0]);
244
+ $query->set('monthnum', $var[1]);
245
+ $query->set('day', $var[2]);
246
+ }
247
+
248
+ $query->is_404 = false;
249
+ $query->query_vars['error'] = '';
250
+
251
+ return $query;
252
 
253
  }
254
 
261
  *
262
  * @return string New permalink
263
  */
264
+ function wpp_permalink($perma, $post, $leavename = false)
265
+ {
266
+ if (empty($post->ID)) {
267
+ return false;
268
+ }
269
+ if ($post->post_type == 'page' || $post->post_status == 'static') {
270
+ return get_page_link($post->ID);
271
+ } elseif ($post->post_type == 'attachment') {
272
+ return get_attachment_link($post->ID);
273
+ } elseif (in_array($post->post_type, get_post_types(array('_builtin' => false)))) {
274
+ return get_post_permalink($post->ID);
275
+ }
276
+
277
+ $permalink = get_option('permalink_structure');
278
+ preg_match_all('/%([^\/]*)%/', $permalink, $rewritecode);
279
+ $rewritecode = $rewritecode[0];
280
+ if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
281
+ if ($leavename) {
282
+ $rewritecode = array_diff($rewritecode, array('%postname%', '%pagename%'));
283
+ }
284
+
285
+ $date = explode(' ', parsidate('Y m d H i s', $post->post_date, 'eng'));
286
+ $out = array();
287
+
288
+ foreach ($rewritecode as $rewrite) {
289
+ switch ($rewrite) {
290
+ case '%year%':
291
+ $out[] = $date[0];
292
+ break;
293
+ case '%monthnum%':
294
+ $out[] = $date[1];
295
+ break;
296
+ case '%day%':
297
+ $out[] = $date[2];
298
+ break;
299
+ case '%hour%':
300
+ $out[] = $date[3];
301
+ break;
302
+ case '%minute%':
303
+ $out[] = $date[4];
304
+ break;
305
+ case '%second%':
306
+ $out[] = $date[5];
307
+ break;
308
+ case '%post_id%':
309
+ $out[] = $post->ID;
310
+ break;
311
+ case '%postname%':
312
+ $out[] = $post->post_name;
313
+ break;
314
+ case '%category%':
315
+ $category = '';
316
+ $cats = get_the_category($post->ID);
317
+ if ($cats) {
318
+ usort($cats, '_usort_terms_by_ID');
319
+ $category = $cats[0]->slug;
320
+ if ($parent = $cats[0]->parent) {
321
+ $category = get_category_parents($parent, false, '/', true);
322
+ }
323
+
324
+ if ($cats[0]->parent != 0) {
325
+ $category .= $cats[0]->slug;
326
+ }
327
+ }
328
+ if (empty($category)) {
329
+ $default_category = get_term(get_option('default_category'), 'category');
330
+ $category = is_wp_error($default_category) ? '' : $default_category->slug;
331
+ }
332
+ $out[] = $category;
333
+ break;
334
+ case '%author%':
335
+ $authordata = get_userdata($post->post_author);
336
+ $out[] = $authordata->user_nicename;
337
+ break;
338
+ case '%pagename%':
339
+ $out[] = $post->post_name;
340
+ break;
341
+ default:
342
+ unset($rewritecode[array_search($rewrite, $rewritecode)]);
343
+ break;
344
+ }
345
+ }
346
+ $permalink = home_url(str_replace($rewritecode, $out, $permalink));
347
+
348
+ return user_trailingslashit($permalink, 'single');
349
+ } else {
350
+ return home_url("?p=$post->ID");
351
+ }
352
  }
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.1
8
 
9
  Persian date support for WordPress
10
 
@@ -41,6 +41,10 @@ List of some features:
41
  4. 'Jalali Date Calender' in action
42
 
43
  == Changelog ==
 
 
 
 
44
  = 2.3.1 =
45
  * Fix date picker's month dropdown bug in admin edit post. [#issue](https://github.com/wordpress-parsi/wp-parsidate/issues/5)
46
 
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
  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)
47
+
48
  = 2.3.1 =
49
  * Fix date picker's month dropdown bug in admin edit post. [#issue](https://github.com/wordpress-parsi/wp-parsidate/issues/5)
50
 
wp-parsidate.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Plugin Name: WP-Parsidate
4
- * Version: 2.3.1
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.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