| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || exit( 'No direct script access allowed' ); |
| 3 |
|
| 4 |
/** |
| 5 |
* Plugin Name: WP-Parsidate |
| 6 |
* Version: 5.1.3 |
| 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.2 |
| 14 |
* Requires PHP: 7.4 |
| 15 |
* WC tested up to: 9.3.3 |
| 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.3 |
| 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( 'after_setup_theme', 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 |
|
| 82 |
/** |
| 83 |
* Sets up constants for plugin |
| 84 |
* |
| 85 |
* @return void |
| 86 |
* @since 2.0 |
| 87 |
*/ |
| 88 |
private function define_const() { |
| 89 |
if ( ! defined( 'WP_PARSI_ROOT' ) ) { |
| 90 |
define( 'WP_PARSI_ROOT', __FILE__ ); |
| 91 |
} |
| 92 |
|
| 93 |
if ( ! defined( 'WP_PARSI_DIR' ) ) { |
| 94 |
define( 'WP_PARSI_DIR', plugin_dir_path( WP_PARSI_ROOT ) ); |
| 95 |
} |
| 96 |
|
| 97 |
if ( ! defined( 'WP_PARSI_URL' ) ) { |
| 98 |
define( 'WP_PARSI_URL', plugin_dir_url( WP_PARSI_ROOT ) ); |
| 99 |
} |
| 100 |
|
| 101 |
if ( ! defined( 'WP_PARSI_VER' ) ) { |
| 102 |
define( 'WP_PARSI_VER', '5.1.3' ); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Includes files for plugin |
| 108 |
* |
| 109 |
* @return void |
| 110 |
* @since 2.0 |
| 111 |
*/ |
| 112 |
public function include_files() { |
| 113 |
require_once( WP_PARSI_DIR . 'includes/settings.php' ); |
| 114 |
|
| 115 |
global $wpp_settings; |
| 116 |
|
| 117 |
$wpp_settings = wp_parsi_get_settings(); |
| 118 |
$files = array( |
| 119 |
'parsidate', |
| 120 |
'general', |
| 121 |
'tools', |
| 122 |
'fixes-archive', |
| 123 |
'fixes-permalinks', |
| 124 |
'fixes-dates', |
| 125 |
'fixes-misc', |
| 126 |
'admin/styles-fix', |
| 127 |
'admin/gutenberg-jalali-calendar', |
| 128 |
'admin/lists-fix', |
| 129 |
'admin/widgets', |
| 130 |
'fixes-calendar', |
| 131 |
'fixes-archives', |
| 132 |
'widget/widget_archive', |
| 133 |
'widget/widget_calendar' |
| 134 |
); |
| 135 |
|
| 136 |
if ( class_exists( 'WooCommerce' ) ) { |
| 137 |
$files[] = 'plugins/woocommerce'; |
| 138 |
} |
| 139 |
|
| 140 |
if ( class_exists( 'Easy_Digital_Downloads' ) ) { |
| 141 |
$files[] = 'plugins/edd'; |
| 142 |
} |
| 143 |
|
| 144 |
if ( class_exists( 'ACF' ) ) { |
| 145 |
$files[] = 'plugins/acf'; |
| 146 |
} |
| 147 |
|
| 148 |
if ( class_exists( '\Elementor\Core\Editor\Editor' ) ) { |
| 149 |
$files[] = 'plugins/elementor'; |
| 150 |
} |
| 151 |
|
| 152 |
$files[] = 'plugins/disable'; |
| 153 |
|
| 154 |
foreach ( $files as $file ) { |
| 155 |
require_once( WP_PARSI_DIR . 'includes/' . $file . '.php' ); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
public function load_plugin_textdomain() { |
| 160 |
if ( get_locale() === 'fa_IR' ) { |
| 161 |
load_textdomain( 'wp-parsidate', WP_PARSI_DIR . 'languages/fa_IR.mo' ); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Localize name of months after date picker enqueued |
| 167 |
* |
| 168 |
* @since 4.0.1 |
| 169 |
*/ |
| 170 |
public function wpp_localize_months_name() { |
| 171 |
global $wpp_months_name; |
| 172 |
|
| 173 |
$months_name = $wpp_months_name; |
| 174 |
|
| 175 |
// Remove first item (null string) from name of months array |
| 176 |
array_shift( $months_name ); |
| 177 |
|
| 178 |
wp_localize_script( 'wpp_jalali_datepicker', 'WPP_I18N', |
| 179 |
array( |
| 180 |
'months' => $months_name |
| 181 |
) |
| 182 |
); |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Returns an instance of WP_Parsidate class, makes instance if not exists |
| 187 |
* |
| 188 |
* @return WP_Parsidate Instance of WP_Parsidate |
| 189 |
* @since 2.0 |
| 190 |
*/ |
| 191 |
public static function get_instance() { |
| 192 |
if ( self::$instance === null ) { |
| 193 |
self::$instance = new WP_Parsidate(); |
| 194 |
} |
| 195 |
|
| 196 |
return self::$instance; |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Add Setting Link To Install Plugin |
| 201 |
* |
| 202 |
* @param array $links |
| 203 |
* |
| 204 |
* @return array |
| 205 |
*/ |
| 206 |
public static function parsi_settings_link( $links ) { |
| 207 |
$settings_link = array( '<a href="' . menu_page_url( 'wp-parsi-settings', false ) . '">' . __( 'settings', 'wp-parsidate' ) . '</a>' ); |
| 208 |
|
| 209 |
return array_merge( $links, $settings_link ); |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Register Plugin Widgets |
| 214 |
* |
| 215 |
* @return boolean |
| 216 |
* @since 2.0 |
| 217 |
*/ |
| 218 |
public function register_widget() { |
| 219 |
register_widget( 'parsidate_archive' ); |
| 220 |
register_widget( 'parsidate_calendar' ); |
| 221 |
|
| 222 |
return true; |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Load Vazir font in admin area |
| 227 |
* |
| 228 |
* @since 4.0.0 |
| 229 |
*/ |
| 230 |
public function wpp_load_vazir_font_in_admin_area() { |
| 231 |
if ( get_locale() !== 'fa_IR' ) { |
| 232 |
return; |
| 233 |
} |
| 234 |
|
| 235 |
if ( wpp_is_active( 'enable_fonts' ) ) { |
| 236 |
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || wpp_is_active( 'dev_mode' ) ? '' : '.min'; |
| 237 |
|
| 238 |
wp_enqueue_style( 'wpp-vazir-font', WP_PARSI_URL . "assets/css/vazir-font$suffix.css", null, WP_PARSI_VER, 'all' ); |
| 239 |
add_action( 'admin_head', array( $this, 'wpp_preload_vazir_fonts' ) ); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Preload vazir font to achieve to high performance |
| 245 |
* |
| 246 |
* @since 4.0.0 |
| 247 |
*/ |
| 248 |
public function wpp_preload_vazir_fonts() { |
| 249 |
echo '<link rel="preload" href="' . WP_PARSI_URL . 'assets/fonts/Vazirmatn-Regular.woff2" as="font" type="font/woff2" crossorigin>' . PHP_EOL . |
| 250 |
'<link rel="preload" href="' . WP_PARSI_URL . 'assets/fonts/Vazirmatn-Bold.woff2" as="font" type="font/woff2" crossorigin>' . PHP_EOL; |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Check the given plugin is installed and activated |
| 255 |
* |
| 256 |
* Since 5.0.1 |
| 257 |
*/ |
| 258 |
public static function is_plugin_activated( $plugin_file ) { |
| 259 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 260 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 261 |
} |
| 262 |
|
| 263 |
return is_plugin_active( $plugin_file ); |
| 264 |
} |
| 265 |
|
| 266 |
/** |
| 267 |
* Checks WPML or PolyLang plugins is active |
| 268 |
* |
| 269 |
* Since 4.0.1 |
| 270 |
*/ |
| 271 |
public static function wpp_multilingual_is_active() { |
| 272 |
$polylang_activated = self::is_plugin_activated( 'polylang/polylang.php' ); |
| 273 |
$sitepress_activated = self::is_plugin_activated( 'sitepress-multilingual-cms/sitepress.php' ); |
| 274 |
|
| 275 |
return $polylang_activated || $sitepress_activated; |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
return WP_Parsidate::get_instance(); |
| 280 |
|