define_const();
$this->include_files();
require_once( WP_PARSI_DIR . 'includes/settings.php' );
if ( self::wpp_multilingual_is_active() && wpp_is_active( 'wpp_multilingual_support' ) ) {
if ( ( defined( 'ICL_LANGUAGE_CODE' ) && 'fa_IR' !== ICL_LANGUAGE_CODE ) ||
( function_exists( 'pll_current_language' ) && pll_current_language() !== 'fa' ) ) {
return;
}
}
WPP_ParsiDate::getInstance();
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'parsi_settings_link' ) );
add_action( 'widgets_init', array( $this, 'register_widget' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'wpp_load_vazir_font_in_admin_area' ) );
add_action( 'wpp_jalali_datepicker_enqueued', array( $this, 'wpp_localize_months_name' ) );
}
/**
* Sets up constants for plugin
*
* @return void
* @since 2.0
*/
private function define_const() {
if ( ! defined( 'WP_PARSI_ROOT' ) ) {
define( 'WP_PARSI_ROOT', __FILE__ );
}
if ( ! defined( 'WP_PARSI_DIR' ) ) {
define( 'WP_PARSI_DIR', plugin_dir_path( WP_PARSI_ROOT ) );
}
if ( ! defined( 'WP_PARSI_URL' ) ) {
define( 'WP_PARSI_URL', plugin_dir_url( WP_PARSI_ROOT ) );
}
if ( ! defined( 'WP_PARSI_VER' ) ) {
define( 'WP_PARSI_VER', '5.1.5' );
}
}
/**
* Includes files for plugin
*
* @return void
* @since 2.0
*/
public function include_files() {
require_once( WP_PARSI_DIR . 'includes/settings.php' );
global $wpp_settings;
$wpp_settings = wp_parsi_get_settings();
$files = array(
'parsidate',
'general',
'tools',
'fixes-archive',
'fixes-permalinks',
'fixes-dates',
'fixes-misc',
'admin/styles-fix',
'admin/gutenberg-jalali-calendar',
'admin/lists-fix',
'admin/widgets',
'fixes-calendar',
'fixes-archives',
'widget/widget_archive',
'widget/widget_calendar'
);
if ( class_exists( 'WooCommerce' ) ) {
$files[] = 'plugins/woocommerce';
}
if ( class_exists( 'Easy_Digital_Downloads' ) ) {
$files[] = 'plugins/edd';
}
if ( class_exists( 'ACF' ) ) {
$files[] = 'plugins/acf';
}
if ( class_exists( '\Elementor\Core\Editor\Editor' ) ) {
$files[] = 'plugins/elementor';
}
$files[] = 'plugins/disable';
foreach ( $files as $file ) {
require_once( WP_PARSI_DIR . 'includes/' . $file . '.php' );
}
}
public function load_plugin_textdomain() {
if ( get_locale() === 'fa_IR' ) {
load_textdomain( 'wp-parsidate', WP_PARSI_DIR . 'languages/fa_IR.mo' );
}
}
/**
* Localize name of months after date picker enqueued
*
* @since 4.0.1
*/
public function wpp_localize_months_name() {
global $wpp_months_name;
$months_name = $wpp_months_name;
// Remove first item (null string) from name of months array
array_shift( $months_name );
wp_localize_script( 'wpp_jalali_datepicker', 'WPP_I18N',
array(
'months' => $months_name
)
);
}
/**
* Returns an instance of WP_Parsidate class, makes instance if not exists
*
* @return WP_Parsidate Instance of WP_Parsidate
* @since 2.0
*/
public static function get_instance() {
if ( self::$instance === null ) {
self::$instance = new WP_Parsidate();
}
return self::$instance;
}
/**
* Add Setting Link To Install Plugin
*
* @param array $links
*
* @return array
*/
public static function parsi_settings_link( $links ) {
$settings_link = array( '' . __( 'settings', 'wp-parsidate' ) . '' );
return array_merge( $links, $settings_link );
}
/**
* Register Plugin Widgets
*
* @return boolean
* @since 2.0
*/
public function register_widget() {
register_widget( 'parsidate_archive' );
register_widget( 'parsidate_calendar' );
return true;
}
/**
* Load Vazir font in admin area
*
* @since 4.0.0
*/
public function wpp_load_vazir_font_in_admin_area() {
if ( get_locale() !== 'fa_IR' ) {
return;
}
if ( wpp_is_active( 'enable_fonts' ) ) {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || wpp_is_active( 'dev_mode' ) ? '' : '.min';
wp_enqueue_style( 'wpp-vazir-font', WP_PARSI_URL . "assets/css/vazir-font$suffix.css", null, WP_PARSI_VER, 'all' );
add_action( 'admin_head', array( $this, 'wpp_preload_vazir_fonts' ) );
}
}
/**
* Preload vazir font to achieve to high performance
*
* @since 4.0.0
*/
public function wpp_preload_vazir_fonts() {
echo '' . PHP_EOL .
'' . PHP_EOL;
}
/**
* Check the given plugin is installed and activated
*
* Since 5.0.1
*/
public static function is_plugin_activated( $plugin_file ) {
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return is_plugin_active( $plugin_file );
}
/**
* Checks WPML or PolyLang plugins is active
*
* Since 4.0.1
*/
public static function wpp_multilingual_is_active() {
$polylang_activated = self::is_plugin_activated( 'polylang/polylang.php' );
$sitepress_activated = self::is_plugin_activated( 'sitepress-multilingual-cms/sitepress.php' );
return $polylang_activated || $sitepress_activated;
}
}
return WP_Parsidate::get_instance();