PluginProbe
پارسی دیت – Parsi Date / 5.1.7
پارسی دیت – Parsi Date v5.1.7
6.3 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 All 49 releases
wp-parsidate / includes / tools.php

tools.php in پارسی دیت – Parsi Date 5.1.7, at includes/tools.php

139 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) or exit( 'No direct script access allowed' );
4
5 /**
6 * WP-Parsidate Tools
7 *
8 * @author HamidReza Yazdani
9 * @sicne 5.1.0
10 */
11
12 if ( wpp_is_active( 'date_in_admin_bar' ) ) {
13
14 if ( ! function_exists( 'wpp_add_date_to_admin_bar' ) ) {
15 /**
16 * Add Jalali date to WordPress admin bar
17 *
18 * @param $wp_admin_bar
19 *
20 * @return void
21 */
22 function wpp_add_date_to_admin_bar( $wp_admin_bar ) {
23 $current_date = parsidate( 'l Y/m/d', date( 'Y-m-d' ) );
24
25 $args = array(
26 'id' => 'wpp_current_date',
27 'title' => esc_html__( 'Today:&nbsp;', 'wp-parsidate' ) . $current_date,
28 'meta' => array( 'class' => 'wpp-admin-bar-date' ),
29 );
30
31 $wp_admin_bar->add_node( $args );
32 }
33
34 add_action( 'admin_bar_menu', 'wpp_add_date_to_admin_bar', PHP_INT_MAX );
35 }
36
37 /**
38 * Style Wp-Parsidate admin bar date
39 */
40 if ( ! function_exists( 'wpp_admin_bar_date_style' ) ) {
41 function wpp_admin_bar_date_style( $wp_admin_bar ) {
42 echo '<style>
43 .wpp-admin-bar-date {
44 color: #fff;
45 background-color: var(--e-context-primary-color) !important;
46 border-radius: 5px 5px 0 0 !important;
47 unicode-bidi: embed !important;
48 }
49 </style>';
50 }
51
52 add_action( 'admin_head', 'wpp_admin_bar_date_style' );
53 }
54 }
55
56 if (!function_exists('wpp_is_postal_code_validate')) {
57 function wpp_is_postal_code_validate($postalCode, $checkSum = false): bool
58 {
59 // Convert to english
60 $postalCode = eng_number($postalCode);
61
62 // Remove space and special character
63 $cleanedCode = preg_replace('/[-\s]/', '', $postalCode);
64 if (!preg_match("/^\d{10}$/", $cleanedCode)) {
65 return false;
66 }
67
68 // Postal code not start with zero
69 if ($cleanedCode[0] === '0') {
70 return false;
71 }
72
73 // Checksum Control
74 if ($checkSum) {
75
76 $checkDigit = (int)$cleanedCode[9];
77 $sum = 0;
78 for ($i = 0; $i < 9; $i++) {
79 $sum += (int)$cleanedCode[$i] * (10 - $i);
80 }
81 $remainder = $sum % 11;
82 $calculatedCheckDigit = ($remainder < 2) ? $remainder : 11 - $remainder;
83 return $checkDigit === $calculatedCheckDigit;
84 }
85
86 return true;
87 }
88 }
89
90 if (!function_exists('wpp_is_time_validate')) {
91 function wpp_is_time_validate($time, $default_seconds = '00')
92 {
93 if (!is_string($time)) {
94 return false;
95 }
96
97 if (preg_match('/^(?:2[0-3]|[01][0-9]):[0-5][0-9](?::[0-5][0-9])?$/', $time)) {
98 if (substr_count($time, ':') === 1) {
99 $time .= ':' . $default_seconds;
100 }
101
102 return $time;
103 }
104
105 return false;
106 }
107 }
108
109 /*if ( wpp_is_active( 'disable_copy' ) ) {
110 if ( ! function_exists( 'wpp_disable_copy' ) ) {
111 function wpp_disable_copy() {
112 echo '<script>
113 document.addEventListener("DOMContentLoaded", (event) => {
114 document.body.onselectstart = () => false;
115 document.body.oncopy = (e) => {
116 e.preventDefault();
117 return false;
118 };
119 });
120 </script>';
121 }
122
123 add_action( 'wp_footer', 'wpp_disable_copy' );
124 }
125 }
126
127 if ( wpp_is_active( 'disable_right_click' ) ) {
128 if ( ! function_exists( 'wpp_disable_right_click' ) ) {
129 function wpp_disable_right_click() {
130 echo '<script>
131 document.addEventListener("contextmenu", function(e) {
132 e.preventDefault();
133 });
134 </script>';
135 }
136
137 add_action( 'wp_footer', 'wpp_disable_right_click' );
138 }
139 }*/