| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace WPDeveloper\BetterDocs\Admin\Customizer; |
| 4 | 4 | |
| 5 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | - exit; | |
| 6 | + exit; | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | use WPDeveloper\BetterDocs\Utils\Base; |
| 10 | 10 | use WPDeveloper\BetterDocs\Admin\Customizer\Sections\Sidebar; |
| @@ -15,141 +15,118 @@ | ||
| 15 | 15 | use WPDeveloper\BetterDocs\Admin\Customizer\Sections\LiveSearch; |
| 16 | 16 | use WPDeveloper\BetterDocs\Admin\Customizer\Sections\ArchivePage; |
| 17 | 17 | |
| 18 | 18 | class Customizer extends Base { |
| 19 | - /** | |
| 20 | - * Defaults | |
| 21 | - * | |
| 22 | - * @var Defaults | |
| 23 | - */ | |
| 24 | - public $defaults; | |
| 19 | + /** | |
| 20 | + * Defaults | |
| 21 | + * | |
| 22 | + * @var Defaults | |
| 23 | + */ | |
| 24 | + public $defaults; | |
| 25 | 25 | |
| 26 | - /** | |
| 27 | - * Enqueue | |
| 28 | - * | |
| 29 | - * @var \WPDeveloper\BetterDocs\Utils\Enqueue | |
| 30 | - */ | |
| 31 | - private $assets; | |
| 26 | + /** | |
| 27 | + * Enqueue | |
| 28 | + * | |
| 29 | + * @var \WPDeveloper\BetterDocs\Utils\Enqueue | |
| 30 | + */ | |
| 31 | + private $assets; | |
| 32 | 32 | |
| 33 | - public function __construct( Defaults $defaults ) { | |
| 34 | - $this->defaults = $defaults; | |
| 33 | + public function __construct( Defaults $defaults ) { | |
| 34 | + $this->defaults = $defaults; | |
| 35 | 35 | |
| 36 | - add_action( 'customize_register', [ $this, 'register' ] ); | |
| 36 | + add_action( 'customize_register', [$this, 'register'] ); | |
| 37 | 37 | |
| 38 | - add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue' ] ); | |
| 39 | - add_action( 'customize_preview_init', [ $this, 'customize_preview_init' ] ); | |
| 38 | + add_action( 'customize_controls_enqueue_scripts', [$this, 'enqueue'] ); | |
| 39 | + add_action( 'customize_preview_init', [$this, 'customize_preview_init'] ); | |
| 40 | 40 | |
| 41 | - add_action( 'customize_controls_print_styles', [ $this, 'controls_print_styles' ], 999 ); | |
| 41 | + add_action( 'customize_controls_print_styles', [$this, 'controls_print_styles'], 999 ); | |
| 42 | 42 | |
| 43 | - if ( function_exists( 'wp_is_block_theme' ) && ! wp_is_block_theme() ) { | |
| 44 | - add_action( 'wp_head', [ $this, 'dynamic_css' ] ); | |
| 45 | - } | |
| 46 | - } | |
| 43 | + if( ! wp_is_block_theme() ) { | |
| 44 | + add_action( 'wp_head', [$this, 'dynamic_css'] ); | |
| 45 | + } | |
| 46 | + } | |
| 47 | 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(); | |
| 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 | 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 | - ); | |
| 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 | + ] ); | |
| 70 | 67 | |
| 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 | - ); | |
| 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 | + ] ); | |
| 83 | 77 | |
| 84 | - /** | |
| 85 | - * Register All Settings | |
| 86 | - */ | |
| 87 | - foreach ( $_settings_sections as $settings ) { | |
| 88 | - betterdocs()->container->get( $settings )->register( $wp_customize, $defaults ); | |
| 89 | - } | |
| 90 | - } | |
| 78 | + /** | |
| 79 | + * Register All Settings | |
| 80 | + */ | |
| 81 | + foreach ( $_settings_sections as $settings ) { | |
| 82 | + betterdocs()->container->get( $settings )->register( $wp_customize, $defaults ); | |
| 83 | + } | |
| 84 | + } | |
| 91 | 85 | |
| 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 | - } | |
| 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 | + } | |
| 118 | 99 | |
| 119 | - public function customize_preview_init() { | |
| 120 | - betterdocs()->assets->enqueue( 'betterdocs-customizer', 'customizer/js/customizer.js', [ 'customize-preview' ] ); | |
| 121 | - } | |
| 100 | + public function customize_preview_init() { | |
| 101 | + betterdocs()->assets->enqueue( 'betterdocs-customizer', 'customizer/js/customizer.js', ['customize-preview'] ); | |
| 102 | + } | |
| 122 | 103 | |
| 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 | - } | |
| 104 | + public function controls_print_styles() { | |
| 105 | + ob_start(); | |
| 106 | + include_once __DIR__ . '/controls.css.php'; | |
| 107 | + echo ob_get_clean(); | |
| 108 | + } | |
| 128 | 109 | |
| 129 | - /** | |
| 130 | - * Generates dynamic css from customizer options. | |
| 131 | - * @return void | |
| 132 | - */ | |
| 133 | - public function dynamic_css() { | |
| 134 | - // Also emit on single WooCommerce product pages so the "Product FAQ for | |
| 135 | - // WooCommerce" customizer controls (.betterdocs-woo-product-faq rules) | |
| 136 | - // apply there — is_templates() only covers docs/KB templates. | |
| 137 | - $is_woo_product = function_exists( 'is_product' ) && is_product(); | |
| 138 | - if ( ! betterdocs()->helper->is_templates() && ! $is_woo_product ) { | |
| 139 | - return false; | |
| 140 | - } | |
| 141 | - /** | |
| 142 | - * Don't remove this line, it's used in dynamic.css.php file. | |
| 143 | - */ | |
| 144 | - $mods = $this->defaults->theme_mods(); | |
| 145 | - require __DIR__ . '/dynamic.css.php'; | |
| 110 | + /** | |
| 111 | + * Generates dynamic css from customizer options. | |
| 112 | + * @return void | |
| 113 | + */ | |
| 114 | + public function dynamic_css() { | |
| 115 | + if ( ! betterdocs()->helper->is_templates() ) { | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + /** | |
| 119 | + * Don't remove this line, it's used in dynamic.css.php file. | |
| 120 | + */ | |
| 121 | + $mods = $this->defaults->theme_mods(); | |
| 122 | + require __DIR__ . '/dynamic.css.php'; | |
| 146 | 123 | |
| 147 | - ob_start(); | |
| 148 | - // echo '<-- betterdocs customizer css -->'; | |
| 149 | - echo '<style type="text/css">'; | |
| 150 | - 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 | |
| 151 | - echo '</style>'; | |
| 152 | - // echo '<-- betterdocs customizer css end -->'; | |
| 153 | - echo ob_get_clean(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Because The Styles Are Needed, Nothing To Sanitize Here | |
| 154 | - } | |
| 124 | + ob_start(); | |
| 125 | + // echo '<-- betterdocs customizer css -->'; | |
| 126 | + echo '<style type="text/css">'; | |
| 127 | + echo $css->get_output( true ); | |
| 128 | + echo '</style>'; | |
| 129 | + // echo '<-- betterdocs customizer css end -->'; | |
| 130 | + echo ob_get_clean(); | |
| 131 | + } | |
| 155 | 132 | } |