PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.7.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.7.3
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Admin / Customizer / Customizer.php

Customizer.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.7.3, at includes/Admin/Customizer/Customizer.php

142 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Admin\Customizer;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use WPDeveloper\BetterDocs\Utils\Base;
10 use WPDeveloper\BetterDocs\Admin\Customizer\Sections\Sidebar;
11 use WPDeveloper\BetterDocs\Admin\Customizer\Sections\DocsPage;
12 use WPDeveloper\BetterDocs\Admin\Customizer\Sections\SingleDoc;
13 use WPDeveloper\BetterDocs\Admin\Customizer\Sections\BreadCrumb;
14 use WPDeveloper\BetterDocs\Admin\Customizer\Sections\FaqBuilder;
15 use WPDeveloper\BetterDocs\Admin\Customizer\Sections\LiveSearch;
16 use WPDeveloper\BetterDocs\Admin\Customizer\Sections\ArchivePage;
17
18 class Customizer extends Base {
19 /**
20 * Defaults
21 *
22 * @var Defaults
23 */
24 public $defaults;
25
26 /**
27 * Enqueue
28 *
29 * @var \WPDeveloper\BetterDocs\Utils\Enqueue
30 */
31 private $assets;
32
33 public function __construct( Defaults $defaults ) {
34 $this->defaults = $defaults;
35
36 add_action( 'customize_register', [$this, 'register'] );
37
38 add_action( 'customize_controls_enqueue_scripts', [$this, 'enqueue'] );
39 add_action( 'customize_preview_init', [$this, 'customize_preview_init'] );
40
41 add_action( 'customize_controls_print_styles', [$this, 'controls_print_styles'], 999 );
42
43 if ( function_exists( 'wp_is_block_theme' ) && ! wp_is_block_theme() ) {
44 add_action( 'wp_head', [$this, 'dynamic_css'] );
45 }
46 }
47
48 /**
49 * Register all customizer options here.
50 * Devided into classes for better readability.
51 *
52 * This methods refers to old customizer.php in admin/customizer
53 * @param mixed $wp_customize
54 * @return void
55 */
56 public function register( $wp_customize ) {
57 $this->assets = betterdocs()->assets;
58 $defaults = $this->defaults->defaults();
59
60 // Create custom panels
61 $wp_customize->add_panel( 'betterdocs_customize_options', [
62 'priority' => 30,
63 'theme_supports' => '',
64 'title' => __( 'BetterDocs', 'betterdocs' ),
65 'description' => __( 'Controls the design settings for the theme.', 'betterdocs' )
66 ] );
67
68 $_settings_sections = apply_filters( 'betterdocs_customizer_settings', [
69 DocsPage::class,
70 SingleDoc::class,
71 Sidebar::class,
72 ArchivePage::class,
73 LiveSearch::class,
74 FaqBuilder::class,
75 BreadCrumb::class,
76 ] );
77
78 /**
79 * Register All Settings
80 */
81 foreach ( $_settings_sections as $settings ) {
82 betterdocs()->container->get( $settings )->register( $wp_customize, $defaults );
83 }
84 }
85
86 /**
87 * Enqueueing styles and scripts for controls and conditions.
88 *
89 * old functions :
90 * * betterdocs_customizer_styles
91 * * betterdocs_customizer_condition
92 *
93 * @return void
94 */
95 public function enqueue() {
96 betterdocs()->assets->enqueue( 'betterdocs-cutomizer-styles', 'customizer/css/customizer-controls.css' );
97 betterdocs()->assets->enqueue( 'betterdocs-customize-condition', 'customizer/js/customizer-condition.js' );
98 betterdocs()->assets->localize( 'betterdocs-customize-condition', 'betterdocsCustomizer', [
99 'isFSETheme' => betterdocs()->helper->current_theme_is_fse_theme(),
100 'betterdocsBlockThemeNotification' => sprintf(
101 /* translators: 1: Link to your documentation, 2: Link to Site Editor */
102 __( 'BetterDocs Customizer options are not compatible with block-based themes and will not function as expected. Please use the <a href="%2$s">Site Editor</a> to customize your site. <a href="%1$s">Learn more</a>', 'betterdocs' ),
103 esc_url( 'https://betterdocs.co/docs/betterdocs-provides-full-site-editor-support/' ), // Learn more link
104 esc_url( admin_url( 'site-editor.php' ) ) // Site Editor link
105 )
106 ] );
107 }
108
109 public function customize_preview_init() {
110 betterdocs()->assets->enqueue( 'betterdocs-customizer', 'customizer/js/customizer.js', ['customize-preview'] );
111 }
112
113 public function controls_print_styles() {
114 ob_start();
115 include_once __DIR__ . '/controls.css.php';
116 echo ob_get_clean();
117 }
118
119 /**
120 * Generates dynamic css from customizer options.
121 * @return void
122 */
123 public function dynamic_css() {
124 if ( ! betterdocs()->helper->is_templates() ) {
125 return false;
126 }
127 /**
128 * Don't remove this line, it's used in dynamic.css.php file.
129 */
130 $mods = $this->defaults->theme_mods();
131 require __DIR__ . '/dynamic.css.php';
132
133 ob_start();
134 // echo '<-- betterdocs customizer css -->';
135 echo '<style type="text/css">';
136 echo $css->get_output( true );
137 echo '</style>';
138 // echo '<-- betterdocs customizer css end -->';
139 echo ob_get_clean();
140 }
141 }
142