832 lines
32 KiB
PHP
832 lines
32 KiB
PHP
<?php
|
|
/**
|
|
* Hesabix2 functions and definitions
|
|
*
|
|
* @package Hesabix2
|
|
* @version 0.1
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
|
|
/**
|
|
* راهاندازی تم
|
|
*/
|
|
function hesabix2_setup() {
|
|
add_theme_support('title-tag');
|
|
add_theme_support('post-thumbnails');
|
|
add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
|
|
add_theme_support('automatic-feed-links');
|
|
add_theme_support('custom-logo', array(
|
|
'height' => 48,
|
|
'width' => 48,
|
|
'flex-height' => true,
|
|
'flex-width' => true,
|
|
));
|
|
/* آیکون سایت (فاویکون و آیکون در هدر) — از ظاهر → سفارشیسازی → هویت سایت قابل آپلود است */
|
|
add_theme_support('site-icon');
|
|
|
|
register_nav_menus(array(
|
|
'primary' => __('منوی اصلی', 'hesabix2'),
|
|
'footer' => __('منوی فوتر', 'hesabix2'),
|
|
));
|
|
|
|
load_theme_textdomain( 'hesabix2', get_template_directory() . '/languages' );
|
|
}
|
|
add_action('after_setup_theme', 'hesabix2_setup');
|
|
|
|
/**
|
|
* مخفی کردن نوار مدیریت وردپرس در فرانتاند برای کاربران لاگینشده
|
|
*/
|
|
function hesabix2_disable_admin_bar($show) {
|
|
if (!is_admin()) {
|
|
return false;
|
|
}
|
|
|
|
return $show;
|
|
}
|
|
add_filter('show_admin_bar', 'hesabix2_disable_admin_bar');
|
|
|
|
/**
|
|
* ثبت ناحیههای ویجت — وقتی ویجتی در ستون نباشد، چیدمان تکستونه میشود
|
|
*/
|
|
function hesabix2_register_sidebars() {
|
|
register_sidebar(array(
|
|
'name' => __('سایدبار اصلی', 'hesabix2'),
|
|
'id' => 'sidebar-1',
|
|
'description' => __('در صفحات وبلاگ و برگه نمایش داده میشود. اگر خالی باشد، محتوا تکستونه نمایش داده میشود.', 'hesabix2'),
|
|
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
|
'after_widget' => '</div>',
|
|
'before_title' => '<h3 class="widget-title">',
|
|
'after_title' => '</h3>',
|
|
));
|
|
|
|
register_sidebar(array(
|
|
'name' => __('فوتر — دسترسی سریع', 'hesabix2'),
|
|
'id' => 'footer-1',
|
|
'description' => __('ستون اول فوتر (دسترسی سریع). اگر خالی باشد، منوی پیشفرض نمایش داده میشود.', 'hesabix2'),
|
|
'before_widget' => '<div id="%1$s" class="widget footer-widget %2$s">',
|
|
'after_widget' => '</div>',
|
|
'before_title' => '<h4 class="footer-heading">',
|
|
'after_title' => '</h4>',
|
|
));
|
|
|
|
register_sidebar(array(
|
|
'name' => __('فوتر — منابع', 'hesabix2'),
|
|
'id' => 'footer-2',
|
|
'description' => __('ستون دوم فوتر (منابع). اگر خالی باشد، لینکهای پیشفرض نمایش داده میشود.', 'hesabix2'),
|
|
'before_widget' => '<div id="%1$s" class="widget footer-widget %2$s">',
|
|
'after_widget' => '</div>',
|
|
'before_title' => '<h4 class="footer-heading">',
|
|
'after_title' => '</h4>',
|
|
));
|
|
|
|
register_sidebar(array(
|
|
'name' => __('فوتر — تماس', 'hesabix2'),
|
|
'id' => 'footer-3',
|
|
'description' => __('ستون سوم فوتر (تماس). اگر خالی باشد، بلوک تماس پیشفرض نمایش داده میشود.', 'hesabix2'),
|
|
'before_widget' => '<div id="%1$s" class="widget footer-widget %2$s">',
|
|
'after_widget' => '</div>',
|
|
'before_title' => '<h4 class="footer-heading">',
|
|
'after_title' => '</h4>',
|
|
));
|
|
}
|
|
add_action('widgets_init', 'hesabix2_register_sidebars');
|
|
|
|
/**
|
|
* آیا سایدبار اصلی فعال است؟
|
|
*/
|
|
function hesabix2_has_sidebar() {
|
|
return is_active_sidebar('sidebar-1');
|
|
}
|
|
|
|
/**
|
|
* بارگذاری استایلها و اسکریپتها (همه به صورت لوکال، بدون وابستگی خارجی)
|
|
*/
|
|
function hesabix2_scripts() {
|
|
$theme_uri = get_template_directory_uri();
|
|
$theme_dir = get_template_directory();
|
|
$tailwind = $theme_dir . '/assets/css/tailwind.css';
|
|
$style_ver = '0.89';
|
|
$tailwind_ver = file_exists( $tailwind ) ? (string) filemtime( $tailwind ) : $style_ver;
|
|
|
|
// Tailwind CSS (فایل بیلدشده)
|
|
wp_enqueue_style(
|
|
'hesabix2-tailwind',
|
|
$theme_uri . '/assets/css/tailwind.css',
|
|
array(),
|
|
$tailwind_ver
|
|
);
|
|
|
|
// استایل اصلی قالب — شامل متغیرهای رنگ و کلاس دکمه/گرادیان
|
|
wp_enqueue_style(
|
|
'hesabix2-style',
|
|
get_stylesheet_uri(),
|
|
array( 'hesabix2-tailwind' ),
|
|
$style_ver
|
|
);
|
|
|
|
// پورتال مجتمع احراز هویت
|
|
if ( is_page() ) {
|
|
$page_template = get_page_template_slug( get_queried_object_id() );
|
|
if ( 'page-tamas.php' === $page_template ) {
|
|
$contact_js = $theme_dir . '/assets/js/contact-form.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-contact-form',
|
|
$theme_uri . '/assets/js/contact-form.js',
|
|
array(),
|
|
file_exists( $contact_js ) ? (string) filemtime( $contact_js ) : '1.0.0',
|
|
true
|
|
);
|
|
wp_localize_script(
|
|
'hesabix2-contact-form',
|
|
'hesabix2ContactForm',
|
|
array(
|
|
'restUrl' => esc_url_raw( rest_url( HESABIX2_CONTACT_CAPTCHA_NS ) ),
|
|
'nonce' => wp_create_nonce( 'wp_rest' ),
|
|
)
|
|
);
|
|
}
|
|
if ( 'page-portal-auth.php' === $page_template ) {
|
|
$portal_css = $theme_dir . '/assets/css/portal-auth.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-portal-auth',
|
|
$theme_uri . '/assets/css/portal-auth.css',
|
|
array( 'hesabix2-style' ),
|
|
file_exists( $portal_css ) ? (string) filemtime( $portal_css ) : '1.0.0'
|
|
);
|
|
$portal_js = $theme_dir . '/assets/js/portal-auth.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-portal-auth',
|
|
$theme_uri . '/assets/js/portal-auth.js',
|
|
array(),
|
|
file_exists( $portal_js ) ? (string) filemtime( $portal_js ) : '1.0.0',
|
|
true
|
|
);
|
|
wp_localize_script(
|
|
'hesabix2-portal-auth',
|
|
'hesabix2PortalAuth',
|
|
array(
|
|
'restUrl' => esc_url_raw( rest_url( 'hesabix-portal/v1' ) ),
|
|
'nonce' => wp_create_nonce( 'wp_rest' ),
|
|
'homeUrl' => home_url( '/' ),
|
|
'adminUrl' => admin_url(),
|
|
'canAccessAdmin' => function_exists( 'hpauth_user_can_access_wp_admin' ) && hpauth_user_can_access_wp_admin(),
|
|
'hadRedirect' => isset( $_GET['redirect_to'] ) && '' !== trim( wp_unslash( (string) $_GET['redirect_to'] ) ),
|
|
)
|
|
);
|
|
}
|
|
// قالبهای قدیمی (تا زمان حذف کامل)
|
|
$legacy_auth = array( 'page-login.php', 'page-register.php', 'page-lostpassword.php' );
|
|
if ( in_array( $page_template, $legacy_auth, true ) ) {
|
|
$auth_css = $theme_dir . '/assets/css/auth.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-auth',
|
|
$theme_uri . '/assets/css/auth.css',
|
|
array( 'hesabix2-style' ),
|
|
file_exists( $auth_css ) ? (string) filemtime( $auth_css ) : '0.1'
|
|
);
|
|
}
|
|
}
|
|
|
|
$header_js = $theme_dir . '/assets/js/header.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-header',
|
|
$theme_uri . '/assets/js/header.js',
|
|
array(),
|
|
file_exists( $header_js ) ? (string) filemtime( $header_js ) : '0.1',
|
|
true
|
|
);
|
|
|
|
// اسکریپتهای صفحه نخست
|
|
if ( is_front_page() ) {
|
|
$fp_css = $theme_dir . '/assets/css/front-page.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-front-page',
|
|
$theme_uri . '/assets/css/front-page.css',
|
|
array( 'hesabix2-style' ),
|
|
file_exists( $fp_css ) ? (string) filemtime( $fp_css ) : '1.0.0'
|
|
);
|
|
$hero_js = $theme_dir . '/assets/js/hero-clouds.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-hero-clouds',
|
|
$theme_uri . '/assets/js/hero-clouds.js',
|
|
array(),
|
|
file_exists( $hero_js ) ? (string) filemtime( $hero_js ) : '0.2',
|
|
true
|
|
);
|
|
$fp_js = $theme_dir . '/assets/js/front-page.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-front-page',
|
|
$theme_uri . '/assets/js/front-page.js',
|
|
array(),
|
|
file_exists( $fp_js ) ? (string) filemtime( $fp_js ) : '0.1',
|
|
true
|
|
);
|
|
wp_localize_script(
|
|
'hesabix2-front-page',
|
|
'hesabix2FrontPage',
|
|
array(
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'abNonce' => wp_create_nonce( 'hesabix2_fp_ab' ),
|
|
'abAction' => 'hesabix2_fp_ab',
|
|
'abVariant'=> function_exists( 'hesabix2_fp_hero_ab_variant' ) ? hesabix2_fp_hero_ab_variant() : 'a',
|
|
'abEnabled'=> function_exists( 'hesabix2_fp_hero_ab_enabled' ) && hesabix2_fp_hero_ab_enabled(),
|
|
)
|
|
);
|
|
}
|
|
|
|
if ( is_singular( 'post' ) || is_home() || is_category() || is_tag() || is_author() || is_date() || ( is_search() && ! is_post_type_archive() ) ) {
|
|
$blog_js = $theme_dir . '/assets/js/blog.js';
|
|
$blog_ver = file_exists( $blog_js ) ? (string) filemtime( $blog_js ) : '0.1';
|
|
wp_enqueue_script(
|
|
'hesabix2-blog',
|
|
$theme_uri . '/assets/js/blog.js',
|
|
array(),
|
|
$blog_ver,
|
|
true
|
|
);
|
|
wp_localize_script(
|
|
'hesabix2-blog',
|
|
'hesabix2Blog',
|
|
array(
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'trackAction' => 'hesabix2_track_post_view',
|
|
'postId' => is_singular( 'post' ) ? (int) get_queried_object_id() : 0,
|
|
'trackNonce' => wp_create_nonce( 'hesabix2_track_view' ),
|
|
)
|
|
);
|
|
}
|
|
|
|
if (is_404()) {
|
|
$css_404 = $theme_dir . '/assets/css/404.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-404',
|
|
$theme_uri . '/assets/css/404.css',
|
|
array('hesabix2-style'),
|
|
file_exists($css_404) ? (string) filemtime($css_404) : '0.1'
|
|
);
|
|
$js_404 = $theme_dir . '/assets/js/404.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-404',
|
|
$theme_uri . '/assets/js/404.js',
|
|
array(),
|
|
file_exists($js_404) ? (string) filemtime($js_404) : '0.1',
|
|
true
|
|
);
|
|
}
|
|
|
|
if ( is_page_template( 'page-android.php' ) ) {
|
|
$and_css = $theme_dir . '/assets/css/android-page.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-android',
|
|
$theme_uri . '/assets/css/android-page.css',
|
|
array( 'hesabix2-style' ),
|
|
file_exists( $and_css ) ? (string) filemtime( $and_css ) : '1.0.0'
|
|
);
|
|
$and_js = $theme_dir . '/assets/js/android-page.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-android',
|
|
$theme_uri . '/assets/js/android-page.js',
|
|
array(),
|
|
file_exists( $and_js ) ? (string) filemtime( $and_js ) : '1.0.0',
|
|
true
|
|
);
|
|
}
|
|
|
|
if ( is_page_template( 'page-windows.php' ) ) {
|
|
$win_css = $theme_dir . '/assets/css/windows-page.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-windows',
|
|
$theme_uri . '/assets/css/windows-page.css',
|
|
array( 'hesabix2-style' ),
|
|
file_exists( $win_css ) ? (string) filemtime( $win_css ) : '1.0.0'
|
|
);
|
|
$win_js = $theme_dir . '/assets/js/windows-page.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-windows',
|
|
$theme_uri . '/assets/js/windows-page.js',
|
|
array(),
|
|
file_exists( $win_js ) ? (string) filemtime( $win_js ) : '1.0.0',
|
|
true
|
|
);
|
|
}
|
|
|
|
if ( is_page_template( 'page-helo-hesabix.php' ) ) {
|
|
$helo_css = $theme_dir . '/assets/css/helo-page.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-helo',
|
|
$theme_uri . '/assets/css/helo-page.css',
|
|
array( 'hesabix2-style' ),
|
|
file_exists( $helo_css ) ? (string) filemtime( $helo_css ) : '1.0.0'
|
|
);
|
|
$helo_js = $theme_dir . '/assets/js/helo-page.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-helo',
|
|
$theme_uri . '/assets/js/helo-page.js',
|
|
array(),
|
|
file_exists( $helo_js ) ? (string) filemtime( $helo_js ) : '1.0.0',
|
|
true
|
|
);
|
|
}
|
|
|
|
if ( is_page_template( 'page-brand.php' ) ) {
|
|
$brand_css = $theme_dir . '/assets/css/brand-page.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-brand',
|
|
$theme_uri . '/assets/css/brand-page.css',
|
|
array( 'hesabix2-style' ),
|
|
file_exists( $brand_css ) ? (string) filemtime( $brand_css ) : '1.0.0'
|
|
);
|
|
$brand_js = $theme_dir . '/assets/js/brand-page.js';
|
|
wp_enqueue_script(
|
|
'hesabix2-brand',
|
|
$theme_uri . '/assets/js/brand-page.js',
|
|
array(),
|
|
file_exists( $brand_js ) ? (string) filemtime( $brand_js ) : '1.0.0',
|
|
true
|
|
);
|
|
}
|
|
}
|
|
add_action('wp_enqueue_scripts', 'hesabix2_scripts');
|
|
|
|
/**
|
|
* صفحهٔ همدلی — استایلهای سنگین قالب را حذف میکند تا طراحی immersive دستنخورده بماند.
|
|
*/
|
|
function hesabix2_hamdeli_dequeue_assets() {
|
|
if ( ! is_page_template( 'page-hamdeli.php' ) ) {
|
|
return;
|
|
}
|
|
wp_dequeue_style( 'hesabix2-tailwind' );
|
|
wp_dequeue_style( 'hesabix2-style' );
|
|
wp_dequeue_script( 'hesabix2-header' );
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'hesabix2_hamdeli_dequeue_assets', 999 );
|
|
|
|
/**
|
|
* قالبهای صفحه ورود، ثبتنام و بازیابی رمز — برای نمایش در ویرایشگر برگه
|
|
*/
|
|
function hesabix2_page_templates( $templates ) {
|
|
$templates['page-portal-auth.php'] = __( 'پورتال مشتریان (ورود / عضویت / بازیابی)', 'hesabix2' );
|
|
$templates['page-login.php'] = __( 'ورود (قدیمی — هدایت به پورتال)', 'hesabix2' );
|
|
$templates['page-register.php'] = __( 'ثبتنام (قدیمی — هدایت به پورتال)', 'hesabix2' );
|
|
$templates['page-lostpassword.php'] = __( 'بازیابی رمز (قدیمی — هدایت به پورتال)', 'hesabix2' );
|
|
$templates['page-arc-shadoman.php'] = __( 'مقایسه آرک و شادمان', 'hesabix2' );
|
|
$templates['page-development.php'] = __( 'وضعیت توسعه', 'hesabix2' );
|
|
$templates['page-api-reference.php'] = __( 'مرجع API', 'hesabix2' );
|
|
$templates['page-hesabix-module.php'] = __( 'صفحهٔ ماژول / راهحل حسابیکس', 'hesabix2' );
|
|
$templates['page-about.php'] = __( 'داستان حسابیکس', 'hesabix2' );
|
|
$templates['page-hamdeli.php'] = __( 'کنار هم بمانیم', 'hesabix2' );
|
|
$templates['page-android.php'] = __( 'اپلیکیشن اندروید', 'hesabix2' );
|
|
$templates['page-windows.php'] = __( 'اپلیکیشن ویندوز', 'hesabix2' );
|
|
$templates['page-helo-hesabix.php'] = __( 'مهاجرت از هلو به حسابیکس', 'hesabix2' );
|
|
$templates['page-brand.php'] = __( 'دستورالعمل برند', 'hesabix2' );
|
|
return $templates;
|
|
}
|
|
add_filter( 'theme_page_templates', 'hesabix2_page_templates' );
|
|
|
|
/**
|
|
* کلاس بدنه برای صفحات احراز هویت
|
|
*/
|
|
function hesabix2_auth_body_class( $classes ) {
|
|
if ( is_page() ) {
|
|
$slug = get_page_template_slug( get_queried_object_id() );
|
|
if ( 'page-portal-auth.php' === $slug ) {
|
|
$classes[] = 'hesabix2-portal-auth';
|
|
} elseif ( $slug === 'page-login.php' ) {
|
|
$classes[] = 'hesabix2-auth-login';
|
|
} elseif ( $slug === 'page-register.php' ) {
|
|
$classes[] = 'hesabix2-auth-register';
|
|
} elseif ( $slug === 'page-lostpassword.php' ) {
|
|
$classes[] = 'hesabix2-auth-lostpassword';
|
|
} elseif ( $slug === 'page-development.php' ) {
|
|
$classes[] = 'hesabix2-development';
|
|
} elseif ( $slug === 'page-api-reference.php' ) {
|
|
$classes[] = 'hesabix2-api-docs';
|
|
} elseif ( $slug === 'page-hesabix-module.php' ) {
|
|
$classes[] = 'hesabix2-module-page';
|
|
if ( function_exists( 'hesabix2_is_module_page' ) && hesabix2_is_module_page() ) {
|
|
$mk = get_post_meta( get_queried_object_id(), '_hesabix_module_key', true );
|
|
if ( $mk && function_exists( 'hesabix2_module_page_def' ) ) {
|
|
$mdef = hesabix2_module_page_def( (string) $mk );
|
|
if ( ! empty( $mdef['page_design'] ) && 'rich' === $mdef['page_design'] ) {
|
|
$classes[] = 'hesabix2-module-page--rich';
|
|
}
|
|
}
|
|
}
|
|
} elseif ( $slug === 'page-about.php' ) {
|
|
$classes[] = 'hesabix2-about-page';
|
|
} elseif ( $slug === 'page-android.php' ) {
|
|
$classes[] = 'hesabix2-android-page';
|
|
} elseif ( $slug === 'page-windows.php' ) {
|
|
$classes[] = 'hesabix2-windows-page';
|
|
} elseif ( $slug === 'page-helo-hesabix.php' ) {
|
|
$classes[] = 'hesabix2-helo-page';
|
|
} elseif ( $slug === 'page-brand.php' ) {
|
|
$classes[] = 'hesabix2-brand-page';
|
|
}
|
|
}
|
|
return $classes;
|
|
}
|
|
add_filter( 'body_class', 'hesabix2_auth_body_class' );
|
|
|
|
/**
|
|
* برگهای که از قالب احراز هویت استفاده میکند را پیدا میکند (اختیاری؛ وقتی از برگه استفاده شود)
|
|
*/
|
|
function hesabix2_get_auth_page_id( $template_slug ) {
|
|
$pages = get_pages( array(
|
|
'meta_key' => '_wp_page_template',
|
|
'meta_value' => $template_slug,
|
|
'number' => 1,
|
|
) );
|
|
return ! empty( $pages ) ? (int) $pages[0]->ID : 0;
|
|
}
|
|
|
|
/* ========== استایل و رفتار صفحه پیشفرض ورود وردپرس (wp-login.php) ========== */
|
|
|
|
/**
|
|
* بارگذاری استایل و فونت در صفحه ورود/ثبتنام/بازیابی رمز پیشفرض
|
|
*/
|
|
function hesabix2_login_enqueue_scripts() {
|
|
$theme_uri = get_template_directory_uri();
|
|
$theme_dir = get_template_directory();
|
|
$login_css = $theme_dir . '/assets/css/login.css';
|
|
wp_enqueue_style(
|
|
'hesabix2-login',
|
|
$theme_uri . '/assets/css/login.css',
|
|
array( 'login' ),
|
|
file_exists( $login_css ) ? (string) filemtime( $login_css ) : '0.1'
|
|
);
|
|
}
|
|
add_action( 'login_enqueue_scripts', 'hesabix2_login_enqueue_scripts' );
|
|
|
|
/**
|
|
* فونت یکان در head صفحه ورود
|
|
*/
|
|
function hesabix2_login_head_font() {
|
|
$font_base = function_exists('hesabix2_font_base_uri')
|
|
? hesabix2_font_base_uri()
|
|
: get_template_directory_uri() . '/assets/fonts';
|
|
?>
|
|
<style id="hesabix2-login-fonts">
|
|
@font-face {
|
|
font-family: 'Yekan Bakh FaNum';
|
|
font-style: normal;
|
|
font-weight: 400 700;
|
|
font-display: swap;
|
|
src: url('<?php echo esc_url( $font_base ); ?>/woff2/YekanBakhFaNum-Regular.woff2') format('woff2'),
|
|
url('<?php echo esc_url( $font_base ); ?>/woff/YekanBakhFaNum-Regular.woff') format('woff');
|
|
}
|
|
</style>
|
|
<?php
|
|
}
|
|
add_action( 'login_head', 'hesabix2_login_head_font' );
|
|
|
|
/**
|
|
* لینک لوگو در صفحه ورود → صفحه اصلی سایت
|
|
*/
|
|
function hesabix2_login_headerurl( $url ) {
|
|
return home_url( '/' );
|
|
}
|
|
add_filter( 'login_headerurl', 'hesabix2_login_headerurl' );
|
|
|
|
/**
|
|
* متن لوگو در صفحه ورود → نام سایت
|
|
*/
|
|
function hesabix2_login_headertext( $text ) {
|
|
return get_bloginfo( 'name', 'display' );
|
|
}
|
|
add_filter( 'login_headertext', 'hesabix2_login_headertext' );
|
|
|
|
/**
|
|
* پشتیبانی از صفحه نخست ثابت
|
|
*/
|
|
function hesabix2_front_page_support() {
|
|
// در hesabix2_setup ثبت شده
|
|
}
|
|
add_action('after_setup_theme', 'hesabix2_front_page_support');
|
|
|
|
/**
|
|
* تخمین زمان مطالعه (بر اساس حدود ۲۰۰ کلمه در دقیقه)
|
|
*/
|
|
function hesabix2_reading_time($content, $wpm = 200) {
|
|
$content = strip_tags($content);
|
|
$words = preg_split('/\s+/u', $content, -1, PREG_SPLIT_NO_EMPTY);
|
|
$count = count($words);
|
|
if ($count < 1) {
|
|
return '';
|
|
}
|
|
$minutes = max(1, ceil($count / $wpm));
|
|
if ($minutes < 60) {
|
|
return $minutes . ' دقیقه مطالعه';
|
|
}
|
|
$hours = floor($minutes / 60);
|
|
$mins = $minutes % 60;
|
|
if ($mins === 0) {
|
|
return $hours . ' ساعت مطالعه';
|
|
}
|
|
return $hours . ' ساعت و ' . $mins . ' دقیقه مطالعه';
|
|
}
|
|
|
|
/**
|
|
* ساختار نمایش هر نظر
|
|
*/
|
|
function hesabix2_comment_callback($comment, $args, $depth) {
|
|
$avatar_size = isset($args['avatar_size']) ? $args['avatar_size'] : 56;
|
|
?>
|
|
<article id="div-comment-<?php comment_ID(); ?>" class="single-comment">
|
|
<header class="single-comment__head">
|
|
<div class="single-comment__avatar">
|
|
<?php echo get_avatar($comment, $avatar_size, '', '', array('class' => 'single-comment__avatar-img')); ?>
|
|
</div>
|
|
<div class="single-comment__info">
|
|
<cite class="single-comment__author"><?php comment_author_link(); ?></cite>
|
|
<?php if ($comment->comment_approved === '0') : ?>
|
|
<p class="single-comment__moderation"><?php esc_html_e('نظر شما در انتظار تایید است.', 'hesabix2'); ?></p>
|
|
<?php else : ?>
|
|
<time datetime="<?php comment_time('c'); ?>" class="single-comment__date">
|
|
<?php
|
|
printf(
|
|
/* translators: 1: date, 2: time */
|
|
esc_html__('%1$s در %2$s', 'hesabix2'),
|
|
get_comment_date('', $comment),
|
|
get_comment_time()
|
|
);
|
|
?>
|
|
</time>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php edit_comment_link(__('ویرایش', 'hesabix2'), '<span class="single-comment__edit">', '</span>'); ?>
|
|
</header>
|
|
<div class="single-comment__text"><?php comment_text(); ?></div>
|
|
<footer class="single-comment__actions">
|
|
<?php
|
|
comment_reply_link(array_merge($args, array(
|
|
'depth' => $depth,
|
|
'max_depth' => $args['max_depth'],
|
|
'before' => '',
|
|
'after' => '',
|
|
'reply_text' => __('پاسخ', 'hesabix2'),
|
|
)));
|
|
?>
|
|
</footer>
|
|
</article>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* سفارشیسازی فیلدهای فرم نظر
|
|
*/
|
|
function hesabix2_comment_form_defaults($defaults) {
|
|
$defaults['comment_field'] = '<p class="single-comment-form__field"><label for="comment">' . __('نظر', 'hesabix2') . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="5" maxlength="65525" required placeholder="' . esc_attr__('نظر خود را بنویسید...', 'hesabix2') . '" class="single-comment-form__textarea"></textarea></p>';
|
|
return $defaults;
|
|
}
|
|
add_filter('comment_form_defaults', 'hesabix2_comment_form_defaults');
|
|
|
|
/**
|
|
* سفارشیسازی ترتیب فیلدهای فرم نظر (کامنت در انتها)
|
|
*/
|
|
function hesabix2_comment_form_fields($fields) {
|
|
$comment_field = $fields['comment'];
|
|
unset($fields['comment']);
|
|
$fields['comment'] = $comment_field;
|
|
return $fields;
|
|
}
|
|
add_filter('comment_form_fields', 'hesabix2_comment_form_fields');
|
|
|
|
/**
|
|
* یکپارچهسازی WeDocs با قالب Hesabix2
|
|
*/
|
|
function hesabix2_wedocs_theme_integration() {
|
|
if ( ! function_exists( 'wedocs' ) ) {
|
|
return;
|
|
}
|
|
remove_action( 'wedocs_before_main_content', 'wedocs_template_wrapper_start', 10 );
|
|
remove_action( 'wedocs_after_main_content', 'wedocs_template_wrapper_end', 10 );
|
|
add_action( 'wedocs_before_main_content', 'hesabix2_wedocs_wrapper_start', 10 );
|
|
add_action( 'wedocs_after_main_content', 'hesabix2_wedocs_wrapper_end', 10 );
|
|
}
|
|
add_action( 'after_setup_theme', 'hesabix2_wedocs_theme_integration', 20 );
|
|
|
|
function hesabix2_wedocs_wrapper_start() {
|
|
echo '<div class="wedocs-outer max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-10 sm:py-14">';
|
|
}
|
|
|
|
function hesabix2_wedocs_wrapper_end() {
|
|
echo '</div>';
|
|
}
|
|
|
|
function hesabix2_wedocs_body_class( $classes ) {
|
|
if ( is_singular( 'docs' ) || ( get_post_type() === 'docs' ) ) {
|
|
$classes[] = 'is-wedocs';
|
|
}
|
|
return $classes;
|
|
}
|
|
add_filter( 'body_class', 'hesabix2_wedocs_body_class' );
|
|
|
|
/** جلوگیری از لود CSS پیشفرض WeDocs در frontend تا استایل قالب اعمال شود */
|
|
function hesabix2_dequeue_wedocs_styles() {
|
|
wp_dequeue_style( 'wedocs-styles' );
|
|
wp_deregister_style( 'wedocs-styles' );
|
|
wp_dequeue_style( 'wedocs-styles-css' );
|
|
wp_deregister_style( 'wedocs-styles-css' );
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'hesabix2_dequeue_wedocs_styles', 100 );
|
|
|
|
/** در صفحه نقشه راه / اصلی اسناد، بخش لیست اسناد نمایش داده نشود */
|
|
function hesabix2_wedocs_hide_docs_list_on_roadmap( $args ) {
|
|
$docs_home = function_exists( 'wedocs_get_general_settings' ) ? wedocs_get_general_settings( 'docs_home', '' ) : '';
|
|
if ( $docs_home && is_page( (int) $docs_home ) ) {
|
|
$args['hide_docs_list'] = true;
|
|
}
|
|
return $args;
|
|
}
|
|
add_filter( 'wedocs_get_doc_listing_template_args', 'hesabix2_wedocs_hide_docs_list_on_roadmap' );
|
|
|
|
/** توابع کمکی AnsPress */
|
|
$hesabix2_ap_helpers = get_template_directory() . '/inc/anspress-helpers.php';
|
|
if ( is_readable( $hesabix2_ap_helpers ) ) {
|
|
require_once $hesabix2_ap_helpers;
|
|
}
|
|
|
|
/** توابع کمکی bbPress */
|
|
$hesabix2_bbp_helpers = get_template_directory() . '/inc/bbpress-helpers.php';
|
|
if ( is_readable( $hesabix2_bbp_helpers ) ) {
|
|
require_once $hesabix2_bbp_helpers;
|
|
}
|
|
|
|
$hesabix2_bbp_shell = get_template_directory() . '/inc/bbpress-shell.php';
|
|
if ( is_readable( $hesabix2_bbp_shell ) ) {
|
|
require_once $hesabix2_bbp_shell;
|
|
}
|
|
|
|
/** ادغام bbPress (در صورت نصب افزونه) */
|
|
$hesabix2_bbp = get_template_directory() . '/inc/bbpress-hesabix.php';
|
|
if ( is_readable( $hesabix2_bbp ) ) {
|
|
require_once $hesabix2_bbp;
|
|
}
|
|
|
|
$hesabix2_bbp_media = get_template_directory() . '/inc/bbpress-media.php';
|
|
if ( is_readable( $hesabix2_bbp_media ) ) {
|
|
require_once $hesabix2_bbp_media;
|
|
}
|
|
|
|
/**
|
|
* یکپارچهسازی AnsPress (پرسش و پاسخ) با قالب Hesabix2
|
|
*/
|
|
function hesabix2_anspress_body_class( $classes ) {
|
|
if ( function_exists( 'hesabix2_is_anspress_page' ) && hesabix2_is_anspress_page() ) {
|
|
$classes[] = 'is-anspress';
|
|
$classes[] = 'hesabix2-anspress';
|
|
}
|
|
if ( function_exists( 'is_question' ) && is_question() ) {
|
|
$classes[] = 'hesabix2-ap-single-page';
|
|
}
|
|
return $classes;
|
|
}
|
|
add_filter( 'body_class', 'hesabix2_anspress_body_class' );
|
|
|
|
/** صفحات ماژول / راهحل */
|
|
$hesabix2_mp = get_template_directory() . '/inc/module-pages.php';
|
|
if ( is_readable( $hesabix2_mp ) ) {
|
|
require_once $hesabix2_mp;
|
|
}
|
|
|
|
/** ناوبری هدر */
|
|
$hesabix2_hn = get_template_directory() . '/inc/header-nav.php';
|
|
if ( is_readable( $hesabix2_hn ) ) {
|
|
require_once $hesabix2_hn;
|
|
}
|
|
|
|
/** فوتر — لینکها و رندر ستونها */
|
|
$hesabix2_fn = get_template_directory() . '/inc/footer-nav.php';
|
|
if ( is_readable( $hesabix2_fn ) ) {
|
|
require_once $hesabix2_fn;
|
|
}
|
|
|
|
/** مقایسه آرک و شادمان */
|
|
$hesabix2_vc = get_template_directory() . '/inc/versions-compare.php';
|
|
if ( is_readable( $hesabix2_vc ) ) {
|
|
require_once $hesabix2_vc;
|
|
}
|
|
|
|
/** اپلیکیشن اندروید */
|
|
$hesabix2_android = get_template_directory() . '/inc/android-app.php';
|
|
if ( is_readable( $hesabix2_android ) ) {
|
|
require_once $hesabix2_android;
|
|
}
|
|
|
|
/** اپلیکیشن ویندوز */
|
|
$hesabix2_windows = get_template_directory() . '/inc/windows-app.php';
|
|
if ( is_readable( $hesabix2_windows ) ) {
|
|
require_once $hesabix2_windows;
|
|
}
|
|
|
|
/** مهاجرت از هلو */
|
|
$hesabix2_helo = get_template_directory() . '/inc/helo-migration.php';
|
|
if ( is_readable( $hesabix2_helo ) ) {
|
|
require_once $hesabix2_helo;
|
|
}
|
|
|
|
/** دستورالعمل برند */
|
|
$hesabix2_brand = get_template_directory() . '/inc/brand.php';
|
|
if ( is_readable( $hesabix2_brand ) ) {
|
|
require_once $hesabix2_brand;
|
|
}
|
|
|
|
/** تنظیمات قالب در پیشخوان */
|
|
$hesabix2_theme_settings = get_template_directory() . '/inc/theme-settings.php';
|
|
if ( is_readable( $hesabix2_theme_settings ) ) {
|
|
require_once $hesabix2_theme_settings;
|
|
}
|
|
|
|
/** وضعیت توسعه — Forgejo API */
|
|
$hesabix2_fj = get_template_directory() . '/inc/forgejo-feed.php';
|
|
if ( is_readable( $hesabix2_fj ) ) {
|
|
require_once $hesabix2_fj;
|
|
}
|
|
|
|
/** مرجع API — OpenAPI */
|
|
$hesabix2_api = get_template_directory() . '/inc/api-docs.php';
|
|
if ( is_readable( $hesabix2_api ) ) {
|
|
require_once $hesabix2_api;
|
|
}
|
|
|
|
/** کمکی صفحه نخست */
|
|
$hesabix2_fp = get_template_directory() . '/inc/front-page-helpers.php';
|
|
if ( is_readable( $hesabix2_fp ) ) {
|
|
require_once $hesabix2_fp;
|
|
}
|
|
|
|
/** سئو، اسکیما، بازدید */
|
|
$hesabix2_seo = get_template_directory() . '/inc/seo.php';
|
|
if ( is_readable( $hesabix2_seo ) ) {
|
|
require_once $hesabix2_seo;
|
|
}
|
|
|
|
/** شبکه تأمین — breadcrumb و یکپارچگی نمایش */
|
|
$hesabix2_st = get_template_directory() . '/inc/shabake-tamin.php';
|
|
if ( is_readable( $hesabix2_st ) ) {
|
|
require_once $hesabix2_st;
|
|
}
|
|
|
|
/** وبلاگ — کارت، آرشیو، TOC */
|
|
$hesabix2_blog = get_template_directory() . '/inc/blog-helpers.php';
|
|
if ( is_readable( $hesabix2_blog ) ) {
|
|
require_once $hesabix2_blog;
|
|
}
|
|
|
|
/** پورتال مشتریان — احراز هویت مجتمع */
|
|
$hesabix2_portal = get_template_directory() . '/inc/portal-auth-helpers.php';
|
|
if ( is_readable( $hesabix2_portal ) ) {
|
|
require_once $hesabix2_portal;
|
|
}
|
|
|
|
/** پیامهای فرم تماس با ما */
|
|
$hesabix2_contact = get_template_directory() . '/inc/contact-messages.php';
|
|
if ( is_readable( $hesabix2_contact ) ) {
|
|
require_once $hesabix2_contact;
|
|
}
|
|
|
|
/** دانشنامه MediaWiki */
|
|
$hesabix2_wiki = get_template_directory() . '/inc/wiki-bridge.php';
|
|
if ( is_readable( $hesabix2_wiki ) ) {
|
|
require_once $hesabix2_wiki;
|
|
}
|
|
|
|
/** راهنمای جامع آموزش */
|
|
$hesabix2_help = get_template_directory() . '/inc/help-bridge.php';
|
|
if ( is_readable( $hesabix2_help ) ) {
|
|
require_once $hesabix2_help;
|
|
}
|
|
|
|
$hesabix2_header_user = get_template_directory() . '/inc/header-user-menu.php';
|
|
if ( is_readable( $hesabix2_header_user ) ) {
|
|
require_once $hesabix2_header_user;
|
|
}
|
|
|
|
/** دیالوگ ورود + حمایت (سراسر سایت) */
|
|
$hesabix2_entry = get_template_directory() . '/inc/support-entry-dialog.php';
|
|
if ( is_readable( $hesabix2_entry ) ) {
|
|
require_once $hesabix2_entry;
|
|
}
|
|
|
|
/** ادغام ووکامرس (در صورت نصب افزونه) */
|
|
$hesabix2_wc = get_template_directory() . '/inc/woocommerce-hesabix.php';
|
|
if ( is_readable( $hesabix2_wc ) ) {
|
|
require_once $hesabix2_wc;
|
|
}
|
|
$hesabix2_wc_fa = get_template_directory() . '/inc/woocommerce-i18n-fa.php';
|
|
if ( is_readable( $hesabix2_wc_fa ) ) {
|
|
require_once $hesabix2_wc_fa;
|
|
}
|
|
$hesabix2_wc_shop = get_template_directory() . '/inc/woocommerce-shop.php';
|
|
if ( is_readable( $hesabix2_wc_shop ) ) {
|
|
require_once $hesabix2_wc_shop;
|
|
}
|
|
$hesabix2_wc_cart = get_template_directory() . '/inc/woocommerce-cart.php';
|
|
if ( is_readable( $hesabix2_wc_cart ) ) {
|
|
require_once $hesabix2_wc_cart;
|
|
}
|