PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 5.1.2
پارسی دیت – Parsi Date v5.1.2
6.2.1 6.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 / general.php
wp-parsidate / includes Last commit date
admin 1 year ago plugins 1 year ago views 1 year ago widget 1 year ago fixes-archive.php 1 year ago fixes-archives.php 1 year ago fixes-calendar.php 1 year ago fixes-dates.php 1 year ago fixes-misc.php 1 year ago fixes-permalinks.php 1 year ago general.php 1 year ago install.php 1 year ago parsidate.php 1 year ago settings.php 1 year ago tools.php 1 year ago
general.php
253 lines
1 <?php
2
3 defined( 'ABSPATH' ) or exit( 'No direct script access allowed' );
4
5 /**
6 * WP-Parsidate general functions
7 *
8 * @author Mobin Ghasempoor
9 * @author Morteza Geransayeh
10 * @author Ehsaan
11 * @package WP-Parsidate
12 * @subpackage Core/General
13 */
14
15 /**
16 * Change Locale WordPress Admin and Front-end user
17 *
18 * @param String $locale
19 *
20 * @return String
21 */
22 function wp_parsi_set_locale( $locale ) {
23 global $locale;
24
25 if ( wpp_is_active( 'admin_lang' ) ) {
26 $admin_locale = "fa_IR";
27 } else {
28 $admin_locale = $locale;
29 }
30
31 if ( wpp_is_active( 'user_lang' ) ) {
32 $user_locale = "fa_IR";
33 } else {
34 $user_locale = $locale;
35 }
36
37 $locale_s = is_admin() ? $admin_locale : $user_locale;
38
39 if ( ! empty( $locale_s ) ) {
40 $locale = $locale_s;
41 }
42
43 setlocale( LC_ALL, $locale );
44
45 return $locale;
46 }
47
48 add_filter( 'locale', 'wp_parsi_set_locale', 0 );
49
50 /**
51 * Change login header url in wp-login.php
52 *
53 * @return string
54 */
55 function wpp_login_headerurl() {
56 return 'https://wp-parsi.com';
57 }
58
59 add_filter( 'login_headerurl', 'wpp_login_headerurl', 10, 2 );
60
61 /**
62 * Notice for the activation.
63 * Added dismiss feature.
64 *
65 * @return void
66 * @author Ehsaan
67 */
68 function wpp_activation_notice() {
69 $dismissed = get_option( 'wpp_dismissed', false );
70
71 if ( ! $dismissed && ( ! isset( $_GET['page'] ) || 'wp-parsi-settings' !== $_GET['page'] ) ) {
72 if ( ! wpp_is_active( 'persian_date' ) ) {
73 $dismiss_url = wp_nonce_url( add_query_arg( 'wpp-action', 'dismiss-notice' ), 'wpp_dismiss_notice' );
74
75 echo sprintf(
76 __( '<div class="updated wpp-message"><p>ParsiDate activated, you may need to configure it to work properly. <a href="%s">Go to configuration page</a> &ndash; <a href="%s">Dismiss</a></p></div>', 'wp-parsidate' ),
77 esc_url( admin_url( 'admin.php?page=wp-parsi-settings' ) ),
78 esc_url( $dismiss_url ),
79 );
80 }
81 }
82 }
83
84 add_action( 'admin_notices', 'wpp_activation_notice' );
85
86 /**
87 * Dismiss the notice action
88 *
89 * @return void
90 * @author Ehsaan
91 */
92 function wpp_dismiss_notice_action() {
93 if ( isset( $_GET['wpp-action'] ) && $_GET['wpp-action'] == 'dismiss-notice' ) {
94 check_admin_referer( 'wpp_dismiss_notice' );
95 update_option( 'wpp_dismissed', true );
96 }
97 }
98
99 add_action( 'admin_init', 'wpp_dismiss_notice_action' );
100
101 /**
102 * disable wp widget block that introduced in WordPress 5.8
103 *
104 * @since 4.0.0
105 */
106 function wpp_disable_gutenberg_blocks_widget() {
107 if ( wpp_is_active( 'disable_widget_block' ) ) {
108 add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
109 add_filter( 'use_widgets_block_editor', '__return_false' );
110 }
111 }
112
113 add_action( 'init', 'wpp_disable_gutenberg_blocks_widget' );
114
115 /**
116 * Detects current page is feed or not
117 *
118 * @return bool True when page is feed, false when page isn't feed
119 * @since 1.0
120 */
121 function wpp_is_feed() {
122 global $wp_query;
123
124 if ( ! isset( $wp_query ) ) {
125 return false;
126 }
127
128 //if ( is_feed() ) { // Experimental change
129 if ( $wp_query->is_feed() ) {
130 return true;
131 }
132
133 $path = $_SERVER['REQUEST_URI'];
134 $exts = array( 'xml', 'gz', 'xsl' );
135 $ext = pathinfo( $path, PATHINFO_EXTENSION );
136
137 return in_array( $ext, $exts );
138 }
139
140 /**
141 * Converts English digits to Persian digits
142 *
143 * @param string $number Numbers
144 *
145 * @return string Formatted numbers
146 */
147 function per_number( $number ) {
148 return str_replace(
149 range( 0, 9 ),
150 array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ),
151 $number
152 );
153 }
154
155 /**
156 * Converts Persian digits to English digits
157 *
158 * @param string $number Numbers
159 *
160 * @return string Formatted numbers
161 */
162 function eng_number( $number ) {
163 return str_replace(
164 array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ),
165 range( 0, 9 ),
166 $number
167 );
168 }
169
170 /**
171 * Converts English numbers to Persian numbers in post contents
172 *
173 * @param string $content Post content
174 *
175 * @return string Formatted content
176 */
177 function persian_number( $content ) {
178 return isset( $content[1] ) ? per_number( $content[1] ) : $content[0];
179 }
180
181 /**
182 * Fix numbers and convert them to Persian digits style
183 *
184 * @param string $content
185 *
186 * @return array|string|string[]|null
187 */
188 function fix_number( $content ) {
189 return preg_replace_callback( '/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(?<![>=<][\s*])(\b\d+\b)|<\s*[^>]+>/i', 'persian_number', $content );
190 //return preg_replace_callback( '/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\d]*)|<\s*[^>]+>/i', 'persian_number', $content );
191 }
192
193 /**
194 * Fix arabic foreign characters
195 *
196 * @param string $content
197 *
198 * @return array|string|string[]
199 */
200 function fix_arabic( $content ) {
201 return str_replace(
202 array( 'ي', 'ك', 'ة', '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩' ),
203 array( 'ی', 'ک', 'ه', '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ),
204 $content,
205 );
206 }
207
208 /**
209 * parsidate_check_format()
210 * checks format for iso definitions
211 *
212 * @param string $format
213 *
214 * @return boolean
215 */
216 function parsidate_check_format( $format ) {
217 return in_array( $format, array(
218 'Z', // Timezone offset in seconds // -43200 through 50400
219 'T', // Timezone abbreviation // Examples: EST, MDT
220 'O', // Difference to Greenwich time (GMT) in hours // Example: +0200
221 'P', // Difference to Greenwich time (GMT) with colon between hours and minutes // Example: +02:00
222 'U', // Seconds since the Unix Epoch (January 1, 1970 00:00:00 GMT)
223 'u', // Microseconds // Example: 654321
224 'e', // Timezone identifier // Examples: UTC, GMT, Atlantic/Azores
225 'r', // RFC 2822 formatted date // Example: Thu, 21 Dec 2000 16:01:07 +0200
226 'c', // ISO 8601 date // 2004-02-12T15:19:21+00:00 // 'Y-m-d\TH:i:s\Z'
227 'G', // 24-hour format of an hour without leading zeros // 0 through 23
228 'I', // Whether the date is in daylight saving time // 1 if Daylight Saving Time, 0 otherwise.
229
230 // Commented this lines, because user/system want to convert these formats.
231 /*'Y-m-d_H-i-s',
232 'Y-m-d_G-i-s',
233 'Y-m-d H:i:s',
234 'Y-m-d G:i:s',
235 'd-M-Y H:i',*/
236
237 DATE_W3C, // eq `c`
238 DATE_ATOM, // eq `c`
239 DATE_RFC2822, // eq `r`
240 'Y-m-d\TH:i:s+00:00', // eq `DATE_W3C` @SEE: http://jochenhebbrecht.be/site/node/761
241 'Y-m-d\TH:i:sP',
242 ) );
243 }
244
245 /**
246 * wpp_is_sitemap()
247 * checks is WordPress sitemap
248 *
249 * @return boolean
250 */
251 function wpp_is_sitemap() {
252 return ( isset( $_SERVER['REQUEST_URI'] ) and strpos( $_SERVER['REQUEST_URI'], 'wp-sitemap' ) !== false );
253 }