wp-parsidate.php
| 1 | <?php |
| 2 | defined( 'ABSPATH' ) || exit( 'No direct script access allowed' ); |
| 3 | |
| 4 | /** |
| 5 | * Plugin Name: WP-Parsidate |
| 6 | * Version: 5.1.8.2 |
| 7 | * Plugin URI: https://wp-parsi.com/support/ |
| 8 | * 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. |
| 9 | * Author: WP-Parsi Team |
| 10 | * Author URI: https://wp-parsi.com/ |
| 11 | * Text Domain: wp-parsidate |
| 12 | * Domain Path: /languages |
| 13 | * Requires at least: 5.3 |
| 14 | * Requires PHP: 7.4 |
| 15 | * WC tested up to: 10.4.0 |
| 16 | * License: GPLv3 |
| 17 | * |
| 18 | * WP-Parsidate is free software: you can redistribute it and/or modify |
| 19 | * it under the terms of the GNU General Public License as published by |
| 20 | * the Free Software Foundation, either version 2 of the License, or |
| 21 | * any later version. |
| 22 | * |
| 23 | * WP-Parsidate is distributed in the hope that it will be useful, |
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | * GNU General Public License for more details. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License |
| 29 | * along with WP-Parsidate. |
| 30 | * |
| 31 | * |
| 32 | * WordPress Parsi Package, Adds Persian language & Jalali date support to your blog |
| 33 | * |
| 34 | * Developers: |
| 35 | * Mobin Ghasempoor ( Developer & Founder ) |
| 36 | * Morteza Geransayeh ( Developer & Founder ) |
| 37 | * HamidReza Yazdani ( Developer ) |
| 38 | * Saeed Fard ( Analyst & Developer ) |
| 39 | * Parsa Kafi ( Developer ) |
| 40 | * |
| 41 | * @author Mobin Ghasempoor |
| 42 | * @author Morteza Geransayeh |
| 43 | * @link https://wp-parsi.com/ |
| 44 | * @version 5.1.6 |
| 45 | * @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public License v3.0 |
| 46 | * @package WP-Parsidate |
| 47 | * @subpackage Core |
| 48 | */ |
| 49 | |
| 50 | /** |
| 51 | * WP Parsidate main class |
| 52 | */ |
| 53 | final class WP_Parsidate { |
| 54 | /** |
| 55 | * @var WP_Parsidate Class instance |
| 56 | */ |
| 57 | public static $instance = null; |
| 58 | |
| 59 | private function __construct() { |
| 60 | add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
| 61 | |
| 62 | $this->define_const(); |
| 63 | $this->include_files(); |
| 64 | |
| 65 | require_once( WP_PARSI_DIR . 'includes/settings.php' ); |
| 66 | |
| 67 | if ( self::wpp_multilingual_is_active() && wpp_is_active( 'wpp_multilingual_support' ) ) { |
| 68 | if ( ( defined( 'ICL_LANGUAGE_CODE' ) && 'fa_IR' !== ICL_LANGUAGE_CODE ) || |
| 69 | ( function_exists( 'pll_current_language' ) && pll_current_language() !== 'fa' ) ) { |
| 70 | return; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | WPP_ParsiDate::getInstance(); |
| 75 | |
| 76 | add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'parsi_settings_link' ) ); |
| 77 | add_action( 'widgets_init', array( $this, 'register_widget' ) ); |
| 78 | add_action( 'admin_enqueue_scripts', array( $this, 'wpp_load_vazir_font_in_admin_area' ) ); |
| 79 | add_action( 'wpp_jalali_datepicker_enqueued', array( $this, 'wpp_localize_months_name' ) ); |
| 80 | |
| 81 | do_action('wpp_init'); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Sets up constants for plugin |
| 86 | * |
| 87 | * @return void |
| 88 | * @since 2.0 |
| 89 | */ |
| 90 | private function define_const() { |
| 91 | if ( ! defined( 'WP_PARSI_ROOT' ) ) { |
| 92 | define( 'WP_PARSI_ROOT', __FILE__ ); |
| 93 | } |
| 94 | |
| 95 | if ( ! defined( 'WP_PARSI_DIR' ) ) { |
| 96 | define( 'WP_PARSI_DIR', plugin_dir_path( WP_PARSI_ROOT ) ); |
| 97 | } |
| 98 | |
| 99 | if ( ! defined( 'WP_PARSI_URL' ) ) { |
| 100 | define( 'WP_PARSI_URL', plugin_dir_url( WP_PARSI_ROOT ) ); |
| 101 | } |
| 102 | |
| 103 | if ( ! defined( 'WP_PARSI_VER' ) ) { |
| 104 | define( 'WP_PARSI_VER', '5.1.8' ); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Includes files for plugin |
| 110 | * |
| 111 | * @return void |
| 112 | * @since 2.0 |
| 113 | */ |
| 114 | public function include_files() { |
| 115 | require_once( WP_PARSI_DIR . 'includes/settings.php' ); |
| 116 | |
| 117 | global $wpp_settings; |
| 118 | |
| 119 | $wpp_settings = wp_parsi_get_settings(); |
| 120 | $files = array( |
| 121 | 'parsidate', |
| 122 | 'general', |
| 123 | 'tools', |
| 124 | 'fixes-archive', |
| 125 | 'fixes-permalinks', |
| 126 | 'fixes-dates', |
| 127 | 'fixes-misc', |
| 128 | 'admin/styles-fix', |
| 129 | 'admin/gutenberg-jalali-calendar', |
| 130 | 'admin/lists-fix', |
| 131 | 'admin/widgets', |
| 132 | 'fixes-calendar', |
| 133 | 'fixes-archives', |
| 134 | 'widget/widget_archive', |
| 135 | 'widget/widget_calendar' |
| 136 | ); |
| 137 | |
| 138 | if ( class_exists( 'WooCommerce' ) ) { |
| 139 | $files[] = 'plugins/woocommerce'; |
| 140 | } |
| 141 | |
| 142 | if ( class_exists( 'Easy_Digital_Downloads' ) ) { |
| 143 | $files[] = 'plugins/edd'; |
| 144 | } |
| 145 | |
| 146 | if ( class_exists( 'ACF' ) ) { |
| 147 | $files[] = 'plugins/acf'; |
| 148 | } |
| 149 | |
| 150 | if ( class_exists( '\Elementor\Core\Editor\Editor' ) ) { |
| 151 | $files[] = 'plugins/elementor'; |
| 152 | } |
| 153 | |
| 154 | if ( class_exists( '\RankMath' ) ) { |
| 155 | $files[] = 'plugins/rank-math'; |
| 156 | } |
| 157 | |
| 158 | $files[] = 'plugins/disable'; |
| 159 | |
| 160 | foreach ( $files as $file ) { |
| 161 | require_once( WP_PARSI_DIR . 'includes/' . $file . '.php' ); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | public function load_plugin_textdomain() { |
| 166 | if ( get_locale() === 'fa_IR' ) { |
| 167 | load_textdomain( 'wp-parsidate', WP_PARSI_DIR . 'languages/fa_IR.mo' ); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Localize name of months after date picker enqueued |
| 173 | * |
| 174 | * @since 4.0.1 |
| 175 | */ |
| 176 | public function wpp_localize_months_name() { |
| 177 | global $wpp_months_name; |
| 178 | |
| 179 | $months_name = $wpp_months_name; |
| 180 | |
| 181 | // Remove first item (null string) from name of months array |
| 182 | array_shift( $months_name ); |
| 183 | |
| 184 | wp_localize_script( 'wpp_jalali_datepicker', 'WPP_I18N', |
| 185 | array( |
| 186 | 'months' => $months_name |
| 187 | ) |
| 188 | ); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Returns an instance of WP_Parsidate class, makes instance if not exists |
| 193 | * |
| 194 | * @return WP_Parsidate Instance of WP_Parsidate |
| 195 | * @since 2.0 |
| 196 | */ |
| 197 | public static function get_instance() { |
| 198 | if ( self::$instance === null ) { |
| 199 | self::$instance = new WP_Parsidate(); |
| 200 | } |
| 201 | |
| 202 | return self::$instance; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Add Setting Link To Install Plugin |
| 207 | * |
| 208 | * @param array $links |
| 209 | * |
| 210 | * @return array |
| 211 | */ |
| 212 | public static function parsi_settings_link( $links ) { |
| 213 | $settings_link = array( '<a href="' . menu_page_url( 'wp-parsi-settings', false ) . '">' . __( 'settings', 'wp-parsidate' ) . '</a>' ); |
| 214 | |
| 215 | return array_merge( $links, $settings_link ); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Register Plugin Widgets |
| 220 | * |
| 221 | * @return boolean |
| 222 | * @since 2.0 |
| 223 | */ |
| 224 | public function register_widget() { |
| 225 | register_widget( 'parsidate_archive' ); |
| 226 | register_widget( 'parsidate_calendar' ); |
| 227 | |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Load Vazir font in admin area |
| 233 | * |
| 234 | * @since 4.0.0 |
| 235 | */ |
| 236 | public function wpp_load_vazir_font_in_admin_area() { |
| 237 | if ( get_locale() !== 'fa_IR' ) { |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | if ( wpp_is_active( 'enable_fonts' ) ) { |
| 242 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || wpp_is_active( 'dev_mode' ) ? '' : '.min'; |
| 243 | |
| 244 | wp_enqueue_style( 'wpp-vazir-font', WP_PARSI_URL . "assets/css/vazir-font$suffix.css", null, WP_PARSI_VER, 'all' ); |
| 245 | add_action( 'admin_head', array( $this, 'wpp_preload_vazir_fonts' ) ); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Preload vazir font to achieve to high performance |
| 251 | * |
| 252 | * @since 4.0.0 |
| 253 | */ |
| 254 | public function wpp_preload_vazir_fonts() { |
| 255 | echo '<link rel="preload" href="' . WP_PARSI_URL . 'assets/fonts/Vazirmatn-Regular.woff2" as="font" type="font/woff2" crossorigin>' . PHP_EOL . |
| 256 | '<link rel="preload" href="' . WP_PARSI_URL . 'assets/fonts/Vazirmatn-Bold.woff2" as="font" type="font/woff2" crossorigin>' . PHP_EOL; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Check the given plugin is installed and activated |
| 261 | * |
| 262 | * Since 5.0.1 |
| 263 | */ |
| 264 | public static function is_plugin_activated( $plugin_file ) { |
| 265 | if ( ! function_exists( 'is_plugin_active' ) ) { |
| 266 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 267 | } |
| 268 | |
| 269 | return is_plugin_active( $plugin_file ); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Checks WPML or PolyLang plugins is active |
| 274 | * |
| 275 | * Since 4.0.1 |
| 276 | */ |
| 277 | public static function wpp_multilingual_is_active() { |
| 278 | $polylang_activated = self::is_plugin_activated( 'polylang/polylang.php' ); |
| 279 | $sitepress_activated = self::is_plugin_activated( 'sitepress-multilingual-cms/sitepress.php' ); |
| 280 | |
| 281 | return $polylang_activated || $sitepress_activated; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | return WP_Parsidate::get_instance(); |
| 286 |