✏️ 正在编辑: comments.php
路径:
/home/h359620/public_html/wp-content/themes/datis/inc/includes/comments.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php if (! defined('ABSPATH')) exit; if (! class_exists('Datis_Comments')) { final class Datis_Comments { private static $instance = null; private $args = [ // style-1, style-2, style-3 'style' => '', 'text_domain' => 'datis', ]; public static function get_instance(): self { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; } private function __construct() { $this->args = apply_filters('datis_comments_args', $this->args); } private function __clone() {} public function __wakeup() { throw new \Exception('Cannot unserialize singleton'); } private function resolve_style_from_demo(): string { $demo = get_option('datis_active_demo', 'architecture'); $map = [ 'architecture' => 'style-1', 'business' => 'style-2', 'industry' => 'style-3', ]; return $map[$demo] ?? 'style-1'; } /** * args نهایی را نرمال میکند (style را اگر خالی بود از روی دمو میگیرد) */ private function normalize_args(array $override_args = []): array { $a = wp_parse_args($override_args, $this->args); if (empty($a['style'])) { $a['style'] = $this->resolve_style_from_demo(); } return $a; } /** * دیتا مشترک برای template-part ها */ private function build_data(array $a): array { $data = [ 'post_id' => get_the_ID(), 'style' => $a['style'], 'args' => $a, ]; return apply_filters('datis_comments_data', $data); } /** * ✅ فقط لیست دیدگاهها (سفارشی) را رندر میکند */ public function render_list(array $override_args = []): string { if (post_password_required()) return ''; $a = $this->normalize_args($override_args); $data = $this->build_data($a); ob_start(); get_template_part('template-parts/comments/list', $a['style'], $data); return ob_get_clean(); } /** * ✅ فقط فرم دیدگاه (سفارشی) را رندر میکند */ public function render_form(array $override_args = []): string { if (post_password_required()) return ''; $a = $this->normalize_args($override_args); $data = $this->build_data($a); ob_start(); get_template_part('template-parts/comments/form', $a['style'], $data); return ob_get_clean(); } /** * ✅ رندر کامل (لیست + فرم) - اختیاری */ public function render(array $override_args = []): string { if (post_password_required()) return ''; $a = $this->normalize_args($override_args); $data = $this->build_data($a); ob_start(); get_template_part('template-parts/comments/list', $a['style'], $data); get_template_part('template-parts/comments/form', $a['style'], $data); return ob_get_clean(); } } // Helper functions if (! function_exists('datis_comments')) { function datis_comments(array $args = []): void { echo Datis_Comments::get_instance()->render($args); } } if (! function_exists('datis_comments_list')) { function datis_comments_list(array $args = []): void { echo Datis_Comments::get_instance()->render_list($args); } } if (! function_exists('datis_comments_form')) { function datis_comments_form(array $args = []): void { echo Datis_Comments::get_instance()->render_form($args); } } }
💾 保存文件
← 返回文件管理器