PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.2.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.2.0
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 4.2.0, at includes/Admin/Customizer/Customizer.php

152 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(
62 'betterdocs_customize_options',
63 [
64 'priority' => 30,
65 'theme_supports' => '',
66 'title' => __( 'BetterDocs', 'betterdocs' ),
67 'description' => __( 'Controls the design settings for the theme.', 'betterdocs' )
68 ]
69 );
70
71 $_settings_sections = apply_filters(
72 'betterdocs_customizer_settings',
73 [
74 DocsPage::class,
75 SingleDoc::class,
76 Sidebar::class,
77 ArchivePage::class,
78 LiveSearch::class,
79 FaqBuilder::class,
80 BreadCrumb::class,
81 ]
82 );
83
84 /**
85 * Register All Settings
86 */
87 foreach ( $_settings_sections as $settings ) {
88 betterdocs()->container->get( $settings )->register( $wp_customize, $defaults );
89 }
90 }
91
92 /**
93 * Enqueueing styles and scripts for controls and conditions.
94 *
95 * old functions :
96 * * betterdocs_customizer_styles
97 * * betterdocs_customizer_condition
98 *
99 * @return void
100 */
101 public function enqueue() {
102 betterdocs()->assets->enqueue( 'betterdocs-cutomizer-styles', 'customizer/css/customizer-controls.css' );
103 betterdocs()->assets->enqueue( 'betterdocs-customize-condition', 'customizer/js/customizer-condition.js' );
104 betterdocs()->assets->localize(
105 'betterdocs-customize-condition',
106 'betterdocsCustomizer',
107 [
108 'isFSETheme' => betterdocs()->helper->current_theme_is_fse_theme(),
109 'betterdocsBlockThemeNotification' => sprintf(
110 /* translators: 1: Link to your documentation, 2: Link to Site Editor */
111 __( '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' ),
112 esc_url( 'https://betterdocs.co/docs/betterdocs-provides-full-site-editor-support/' ), // Learn more link
113 esc_url( admin_url( 'site-editor.php' ) ) // Site Editor link
114 )
115 ]
116 );
117 }
118
119 public function customize_preview_init() {
120 betterdocs()->assets->enqueue( 'betterdocs-customizer', 'customizer/js/customizer.js', [ 'customize-preview' ] );
121 }
122
123 public function controls_print_styles() {
124 ob_start();
125 include_once __DIR__ . '/controls.css.php';
126 echo ob_get_clean(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Because The Styles Are Needed, Nothing To Sanitize Here
127 }
128
129 /**
130 * Generates dynamic css from customizer options.
131 * @return void
132 */
133 public function dynamic_css() {
134 if ( ! betterdocs()->helper->is_templates() ) {
135 return false;
136 }
137 /**
138 * Don't remove this line, it's used in dynamic.css.php file.
139 */
140 $mods = $this->defaults->theme_mods();
141 require __DIR__ . '/dynamic.css.php';
142
143 ob_start();
144 // echo '<-- betterdocs customizer css -->';
145 echo '<style type="text/css">';
146 echo $css->get_output( true ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Because The Styles Are Needed Rendered Here, Nothing To Sanitize. We need to sanitize datas which are dynamic only & Not in our control
147 echo '</style>';
148 // echo '<-- betterdocs customizer css end -->';
149 echo ob_get_clean(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Because The Styles Are Needed, Nothing To Sanitize Here
150 }
151 }
152