Old.php
134 lines
| 1 | <?php |
| 2 | |
| 3 | use WPParsidate\App\Tools\HookDeactivator; |
| 4 | use WPParsidate\Helper\{Date, Number, WooCommerce, WordPress}; |
| 5 | use WPParsidate\Settings\Settings; |
| 6 | |
| 7 | if ( ! function_exists( 'wpp_is_active' ) ) { |
| 8 | /** |
| 9 | * Gets an option name and check that option is active or not |
| 10 | * |
| 11 | * @param $option_name |
| 12 | * |
| 13 | * @return bool |
| 14 | * @since 4.0.0 |
| 15 | */ |
| 16 | function wpp_is_active( $option_name ): bool { |
| 17 | return Settings::get( $option_name, false ) === true; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | if ( ! function_exists( 'disable_wpp' ) ) { |
| 22 | /** |
| 23 | * Check hook deactivator enable in current call back trace |
| 24 | * |
| 25 | * @return bool |
| 26 | */ |
| 27 | function disable_wpp(): bool { |
| 28 | return HookDeactivator::checkDisable(); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | if ( ! function_exists( 'wpp_date_is' ) ) { |
| 33 | /** |
| 34 | * Validate date string |
| 35 | * |
| 36 | * @param $dateString |
| 37 | * @param $format |
| 38 | * |
| 39 | * @return array |
| 40 | */ |
| 41 | function wpp_date_is( $dateString, $format = 'Y-m-d\TH:i:sP' ): array { |
| 42 | return Date::isDateString( $dateString, $format ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if ( ! function_exists( 'wpp_is_time_validate' ) ) { |
| 47 | /** |
| 48 | * Validate time string |
| 49 | * |
| 50 | * @param mixed $time |
| 51 | * @param string $default_seconds |
| 52 | * |
| 53 | * @return false|string |
| 54 | */ |
| 55 | function wpp_is_time_validate( $time, string $default_seconds = '00' ) { |
| 56 | return Date::isTimeString( $time, $default_seconds ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if ( ! function_exists( 'wpp_is_postal_code_validate' ) ) { |
| 61 | /** |
| 62 | * Check value is postal code |
| 63 | * |
| 64 | * @param mixed $postalCode |
| 65 | * @param bool $checkSum |
| 66 | * |
| 67 | * @return bool |
| 68 | */ |
| 69 | function wpp_is_postal_code_validate( $postalCode, bool $checkSum = false ): bool { |
| 70 | return WooCommerce::isPostalCode( $postalCode, $checkSum ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if ( ! function_exists( 'wpp_is_sitemap' ) ) { |
| 75 | /** |
| 76 | * Checks is WordPress sitemap |
| 77 | * |
| 78 | * @return boolean |
| 79 | */ |
| 80 | function wpp_is_sitemap(): bool { |
| 81 | return WordPress::isSitemap(); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if ( ! function_exists( 'fix_number' ) ) { |
| 86 | /** |
| 87 | * Fix numbers and convert them to Persian digits style |
| 88 | * |
| 89 | * @param string $content |
| 90 | * |
| 91 | * @return array|string|string[]|null |
| 92 | */ |
| 93 | function fix_number( string $content ) { |
| 94 | return Number::fixNumber( $content ); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if ( ! function_exists( 'wpp_is_feed' ) ) { |
| 99 | /** |
| 100 | * Detects current page is feed or not |
| 101 | * |
| 102 | * @return bool |
| 103 | */ |
| 104 | function wpp_is_feed(): bool { |
| 105 | return WordPress::isFeed(); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if ( ! function_exists( 'per_number' ) ) { |
| 110 | /** |
| 111 | * Converts English digits to Persian digits |
| 112 | * |
| 113 | * @param string $number Numbers |
| 114 | * |
| 115 | * @return string Formatted numbers |
| 116 | */ |
| 117 | function per_number( string $number ): string { |
| 118 | return Number::toPersian( $number ); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if ( ! function_exists( 'eng_number' ) ) { |
| 123 | /** |
| 124 | * Converts Persian digits to English digits |
| 125 | * |
| 126 | * @param string $number Numbers |
| 127 | * |
| 128 | * @return string Formatted numbers |
| 129 | */ |
| 130 | function eng_number( string $number ): string { |
| 131 | return Number::toEnglish( $number ); |
| 132 | } |
| 133 | } |
| 134 |