From a8e7007211f3094911abd3a3195a99315affdd28 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sun, 22 Sep 2019 20:45:42 +0200 Subject: [PATCH 01/38] (Almost) remade body background to be GeneratePress-compatible --- .../CrdmBasic/Customizer/class-background.php | 127 ++++++++++++++++++ .../CrdmBasic/Customizer/class-content.php | 2 +- src/php/CrdmBasic/Customizer/class-init.php | 15 +++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 417f89f..183cd69 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -37,6 +37,14 @@ class Background { */ protected $section_id = ''; + private static $default = [ + 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', + 'body_repeat' => 'no-repeat', + 'body_size' => '376px auto', + 'body_attachment' => 'scroll', + 'body_position' => 'right top', + ]; + /** * Background class constructor * @@ -52,6 +60,123 @@ public function __construct( string $config_id, string $panel_id ) { $this->init_section(); $this->init_controls(); + + add_action('customize_register', [$this, 'customize'], 1000); + add_action('wp_enqueue_scripts', [$this, 'add_inline_css']); + } + + public function customize($wp_customize) + { + if ( ! Init::generatepress_module_enabled('generate_package_backgrounds') ) { + $wp_customize->add_panel( 'generate_backgrounds_panel', [ + 'capability' => 'edit_theme_options', + 'theme_supports' => '', + 'title' => __( 'Background Images', 'crdm-basic' ), + 'priority' => 55 + ] ); + + $wp_customize->add_section( + 'generate_backgrounds_body', + [ + 'title' => __( 'Body', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 5, + 'panel' => 'generate_backgrounds_panel', + ] + ); + + $wp_customize->add_setting( + 'generate_background_settings[body_image]', [ + 'default' => self::$default['body_image'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_url_raw', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Image_Control( + $wp_customize, + 'generate_backgrounds-body-image', + [ + 'section' => 'generate_backgrounds_body', + 'settings' => 'generate_background_settings[body_image]', + 'label' => __( 'Body', 'crdm-basic' ), + ] + ) + ); + + $wp_customize->add_setting( + 'generate_background_settings[body_repeat]', + [ + 'default' => self::$default['body_repeat'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + ] + ); + + $wp_customize->add_setting( + 'generate_background_settings[body_size]', + [ + 'default' => self::$default['body_size'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + ] + ); + + $wp_customize->add_setting( + 'generate_background_settings[body_attachment]', + [ + 'default' => self::$default['body_attachment'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + ] + ); + + $wp_customize->add_setting( + 'generate_background_settings[body_position]', [ + 'default' => self::$default['body_position'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_html', + ] + ); + + /* + $wp_customize->add_control( + new Background_Image_Customize_Control( + $wp_customize, + 'body_backgrounds_control', + [ + 'section' => 'generate_backgrounds_body', + 'settings' => [ + 'repeat' => 'generate_background_settings[body_repeat]', + 'size' => 'generate_background_settings[body_size]', + 'attachment' => 'generate_background_settings[body_attachment]', + 'position' => 'generate_background_settings[body_position]', + ], + ] + ) + ); + */ + } + } + + private function inline_css() + { + $generate_background_settings = wp_parse_args(get_option( 'generate_background_settings', [] ), self::$default); + $background_image = esc_url( $generate_background_settings[ 'body_image' ] ); + return <<inline_css()); } /** @@ -75,6 +200,7 @@ protected function init_section() { * Adds all the controls to the section */ protected function init_controls() { + /* Kirki::add_field( $this->config_id, [ @@ -98,6 +224,7 @@ protected function init_controls() { 'transport' => 'auto', ] ); + */ Kirki::add_field( $this->config_id, diff --git a/src/php/CrdmBasic/Customizer/class-content.php b/src/php/CrdmBasic/Customizer/class-content.php index 3aa51d3..c88619e 100644 --- a/src/php/CrdmBasic/Customizer/class-content.php +++ b/src/php/CrdmBasic/Customizer/class-content.php @@ -343,7 +343,7 @@ public function resolve_and_print_list_css_variables() { private static function get_bg_color() { $bg_color = get_theme_mod( 'contentBg' ); if ( empty( $bg_color ) || ! isset( $bg_color['background-color'] ) || substr( $bg_color['background-color'], 0, 1 ) !== '#' ) { - return get_theme_mod( 'webBg' ); + return get_theme_mod( 'generate_settings[background_color]' ); } return $bg_color; } diff --git a/src/php/CrdmBasic/Customizer/class-init.php b/src/php/CrdmBasic/Customizer/class-init.php index f54e865..9462fa3 100644 --- a/src/php/CrdmBasic/Customizer/class-init.php +++ b/src/php/CrdmBasic/Customizer/class-init.php @@ -76,4 +76,19 @@ protected function init_sections_and_controls() { ( new Footer( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); } + public static function generatepress_module_enabled($module) + { + if ( ! function_exists( 'generatepress_is_module_active' ) ) { + return false; + } + switch($module) + { + case 'generate_package_backgrounds': + $definition = 'GENERATE_BACKGROUNDS'; + break; + default: + return false; + } + return generatepress_is_module_active($module, $definition); + } } From 511444de75a179256924ec13164fc102926dd603 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sun, 22 Sep 2019 20:48:25 +0200 Subject: [PATCH 02/38] Copied over default values --- src/php/CrdmBasic/Customizer/class-background.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 183cd69..71a7af2 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -39,10 +39,10 @@ class Background { private static $default = [ 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', - 'body_repeat' => 'no-repeat', - 'body_size' => '376px auto', + 'body_repeat' => 'repeat', + 'body_size' => '300px auto', 'body_attachment' => 'scroll', - 'body_position' => 'right top', + 'body_position' => 'left top', ]; /** From 82aa9daaf53fe4465bd6afa9de88f670a49f2274 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Mon, 23 Sep 2019 11:10:52 +0200 Subject: [PATCH 03/38] Remade body background-repeat to be GeneratePress-compatible --- .../CrdmBasic/Customizer/class-background.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 71a7af2..b679f85 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -115,6 +115,20 @@ public function customize($wp_customize) ] ); + $wp_customize->add_control( + 'generate_background_settings[body_repeat]', + [ + 'type' => 'select', + 'section' => 'generate_backgrounds_body', + 'choices' => [ + 'repeat' => esc_html__( 'Repeat', 'crdm-basic' ), + 'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ), + 'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ), + 'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ) + ] + ], + ); + $wp_customize->add_setting( 'generate_background_settings[body_size]', [ @@ -165,10 +179,12 @@ public function customize($wp_customize) private function inline_css() { $generate_background_settings = wp_parse_args(get_option( 'generate_background_settings', [] ), self::$default); - $background_image = esc_url( $generate_background_settings[ 'body_image' ] ); + $body_image = esc_url( $generate_background_settings[ 'body_image' ] ); + $body_repeat = esc_attr( $generate_background_settings[ 'body_repeat' ] ); return << Date: Mon, 23 Sep 2019 13:27:11 +0200 Subject: [PATCH 04/38] Remade body background-size to be GeneratePress-compatible --- .../CrdmBasic/Customizer/class-background.php | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index b679f85..e3cbec6 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -39,8 +39,8 @@ class Background { private static $default = [ 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', - 'body_repeat' => 'repeat', - 'body_size' => '300px auto', + 'body_repeat' => '', + 'body_size' => '', 'body_attachment' => 'scroll', 'body_position' => 'left top', ]; @@ -121,7 +121,7 @@ public function customize($wp_customize) 'type' => 'select', 'section' => 'generate_backgrounds_body', 'choices' => [ - 'repeat' => esc_html__( 'Repeat', 'crdm-basic' ), + '' => esc_html__( 'Repeat', 'crdm-basic' ), 'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ), 'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ), 'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ) @@ -138,6 +138,20 @@ public function customize($wp_customize) ] ); + $wp_customize->add_control( + 'generate_background_settings[body_size]', + [ + 'type' => 'select', + 'section' => 'generate_backgrounds_body', + 'choices' => [ + '' => esc_html__( 'Size (Auto)', 'gp-premium' ), + '100' => esc_html__( '100% Width', 'gp-premium' ), + 'cover' => esc_html__( 'Cover', 'gp-premium' ), + 'contain' => esc_html__( 'Contain', 'gp-premium' ) + ] + ], + ); + $wp_customize->add_setting( 'generate_background_settings[body_attachment]', [ @@ -176,17 +190,25 @@ public function customize($wp_customize) } } + private function print_css_property($generate_background_settings, $cssName, $settingsName, $isUrl = false) + { + $value = $generate_background_settings[ $settingsName ]; + if(empty($value)) + { + return ''; + } + $value = $isUrl ? 'url(\'' . esc_url($value) . '\')' : esc_attr($value); + return $cssName . ': ' . $value . ';'; + } + private function inline_css() { - $generate_background_settings = wp_parse_args(get_option( 'generate_background_settings', [] ), self::$default); - $body_image = esc_url( $generate_background_settings[ 'body_image' ] ); - $body_repeat = esc_attr( $generate_background_settings[ 'body_repeat' ] ); - return <<print_css_property($settings, 'background-image', 'body_image', true) . + $this->print_css_property($settings, 'background-repeat', 'body_repeat') . + $this->print_css_property($settings, 'background-size', 'body_size') . + '}'; } public function add_inline_css() { From 582b37312e74b2f1a5d8ac445ab5fd8232b315b4 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Mon, 23 Sep 2019 14:53:03 +0200 Subject: [PATCH 05/38] Fixed lint issues --- .phan/stubs/GeneratePress/functions.php | 4 + .../class-wp-customize-image-control.php | 6 + .../WordPress/class-wp-customize-manager.php | 15 ++ .phan/stubs/WordPress/functions.php | 20 ++- .../CrdmBasic/Customizer/class-background.php | 166 +++++++++++------- src/php/CrdmBasic/Customizer/class-init.php | 27 +-- 6 files changed, 160 insertions(+), 78 deletions(-) create mode 100644 .phan/stubs/GeneratePress/functions.php create mode 100644 .phan/stubs/WordPress/class-wp-customize-image-control.php create mode 100644 .phan/stubs/WordPress/class-wp-customize-manager.php diff --git a/.phan/stubs/GeneratePress/functions.php b/.phan/stubs/GeneratePress/functions.php new file mode 100644 index 0000000..4b0e89b --- /dev/null +++ b/.phan/stubs/GeneratePress/functions.php @@ -0,0 +1,4 @@ + CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', - 'body_repeat' => '', - 'body_size' => '', + const DEFAULT = [ + 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', + 'body_repeat' => '', + 'body_size' => '', 'body_attachment' => 'scroll', - 'body_position' => 'left top', + 'body_position' => 'left top', ]; /** @@ -61,35 +61,45 @@ public function __construct( string $config_id, string $panel_id ) { $this->init_section(); $this->init_controls(); - add_action('customize_register', [$this, 'customize'], 1000); - add_action('wp_enqueue_scripts', [$this, 'add_inline_css']); + add_action( 'customize_register', [ $this, 'customize' ], 1000 ); + add_action( 'wp_enqueue_scripts', [ $this, 'add_inline_css' ] ); } - public function customize($wp_customize) - { - if ( ! Init::generatepress_module_enabled('generate_package_backgrounds') ) { - $wp_customize->add_panel( 'generate_backgrounds_panel', [ - 'capability' => 'edit_theme_options', - 'theme_supports' => '', - 'title' => __( 'Background Images', 'crdm-basic' ), - 'priority' => 55 - ] ); + /** + * Initializes customizer options. + * + * Adds the panel, section, all the settings and controls to the WordPress customizer. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + public function customize( $wp_customize ) { + if ( ! Init::generatepress_module_enabled( 'generate_package_backgrounds' ) ) { + $wp_customize->add_panel( + 'generate_backgrounds_panel', + [ + 'capability' => 'edit_theme_options', + 'theme_supports' => '', + 'title' => __( 'Background Images', 'crdm-basic' ), + 'priority' => 55, + ] + ); $wp_customize->add_section( 'generate_backgrounds_body', [ - 'title' => __( 'Body', 'crdm-basic' ), + 'title' => __( 'Body', 'crdm-basic' ), 'capability' => 'edit_theme_options', - 'priority' => 5, - 'panel' => 'generate_backgrounds_panel', + 'priority' => 5, + 'panel' => 'generate_backgrounds_panel', ] ); $wp_customize->add_setting( - 'generate_background_settings[body_image]', [ - 'default' => self::$default['body_image'], - 'type' => 'option', - 'capability' => 'edit_theme_options', + 'generate_background_settings[body_image]', + [ + 'default' => self::DEFAULT['body_image'], + 'type' => 'option', + 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', ] ); @@ -99,9 +109,9 @@ public function customize($wp_customize) $wp_customize, 'generate_backgrounds-body-image', [ - 'section' => 'generate_backgrounds_body', - 'settings' => 'generate_background_settings[body_image]', - 'label' => __( 'Body', 'crdm-basic' ), + 'section' => 'generate_backgrounds_body', + 'settings' => 'generate_background_settings[body_image]', + 'label' => __( 'Body', 'crdm-basic' ), ] ) ); @@ -109,8 +119,8 @@ public function customize($wp_customize) $wp_customize->add_setting( 'generate_background_settings[body_repeat]', [ - 'default' => self::$default['body_repeat'], - 'type' => 'option', + 'default' => self::DEFAULT['body_repeat'], + 'type' => 'option', 'sanitize_callback' => 'sanitize_key', ] ); @@ -118,22 +128,22 @@ public function customize($wp_customize) $wp_customize->add_control( 'generate_background_settings[body_repeat]', [ - 'type' => 'select', + 'type' => 'select', 'section' => 'generate_backgrounds_body', 'choices' => [ - '' => esc_html__( 'Repeat', 'crdm-basic' ), - 'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ), - 'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ), - 'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ) - ] - ], + '' => esc_html__( 'Repeat', 'crdm-basic' ), + 'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ), + 'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ), + 'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ), + ], + ] ); $wp_customize->add_setting( 'generate_background_settings[body_size]', [ - 'default' => self::$default['body_size'], - 'type' => 'option', + 'default' => self::DEFAULT['body_size'], + 'type' => 'option', 'sanitize_callback' => 'sanitize_key', ] ); @@ -141,31 +151,32 @@ public function customize($wp_customize) $wp_customize->add_control( 'generate_background_settings[body_size]', [ - 'type' => 'select', + 'type' => 'select', 'section' => 'generate_backgrounds_body', 'choices' => [ - '' => esc_html__( 'Size (Auto)', 'gp-premium' ), - '100' => esc_html__( '100% Width', 'gp-premium' ), - 'cover' => esc_html__( 'Cover', 'gp-premium' ), - 'contain' => esc_html__( 'Contain', 'gp-premium' ) - ] - ], + '' => esc_html__( 'Size (Auto)', 'crdm-basic' ), + '100' => esc_html__( '100% Width', 'crdm-basic' ), + 'cover' => esc_html__( 'Cover', 'crdm-basic' ), + 'contain' => esc_html__( 'Contain', 'crdm-basic' ), + ], + ] ); $wp_customize->add_setting( 'generate_background_settings[body_attachment]', [ - 'default' => self::$default['body_attachment'], - 'type' => 'option', + 'default' => self::DEFAULT['body_attachment'], + 'type' => 'option', 'sanitize_callback' => 'sanitize_key', ] ); $wp_customize->add_setting( - 'generate_background_settings[body_position]', [ - 'default' => self::$default['body_position'], - 'type' => 'option', - 'capability' => 'edit_theme_options', + 'generate_background_settings[body_position]', + [ + 'default' => self::DEFAULT['body_position'], + 'type' => 'option', + 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_html', ] ); @@ -190,31 +201,52 @@ public function customize($wp_customize) } } - private function print_css_property($generate_background_settings, $cssName, $settingsName, $isUrl = false) - { - $value = $generate_background_settings[ $settingsName ]; - if(empty($value)) - { + /** + * Prints a CSS property. + * + * Escapes, formats and returns a CSS property line. + * + * @param array $settings Parsed background settings for GeneratePress. + * @param string $css_name The name of the CSS property. + * @param string $settings_name The name of the settings field in $generate_background_settings. + * @param bool $is_url Whether the property is an URL. Default false. + * + * @return string The CSS property line; + */ + private function print_css_property( $settings, $css_name, $settings_name, $is_url = false ) { + $value = $settings[ $settings_name ]; + if ( empty( $value ) ) { return ''; } - $value = $isUrl ? 'url(\'' . esc_url($value) . '\')' : esc_attr($value); - return $cssName . ': ' . $value . ';'; + $value = $is_url ? 'url(\'' . esc_url( $value ) . '\')' : esc_attr( $value ); + return $css_name . ': ' . $value . ';'; } - private function inline_css() - { - $settings = wp_parse_args(get_option( 'generate_background_settings', [] ), self::$default); + /** + * Prints the CSS for the background settings. + * + * Return all the CSS properties for the background settings. + * + * @return string CSS string. + */ + private function inline_css() { + $settings = wp_parse_args( get_option( 'generate_background_settings', [] ), self::DEFAULT ); return "body {\n" . - $this->print_css_property($settings, 'background-image', 'body_image', true) . - $this->print_css_property($settings, 'background-repeat', 'body_repeat') . - $this->print_css_property($settings, 'background-size', 'body_size') . - '}'; + $this->print_css_property( $settings, 'background-image', 'body_image', true ) . + $this->print_css_property( $settings, 'background-repeat', 'body_repeat' ) . + $this->print_css_property( $settings, 'background-size', 'body_size' ) . + '}'; } + /** + * Adds the CSS to WordPress hooks. + * + * Cretes a new stylesheet and adds all the CSS to it. + */ public function add_inline_css() { - wp_register_style('crdm_customizer', false); - wp_enqueue_style('crdm_customizer'); - wp_add_inline_style('crdm_customizer', $this->inline_css()); + wp_register_style( 'crdm_customizer', false, [], CRDMBASIC_APP_VERSION ); + wp_enqueue_style( 'crdm_customizer' ); + wp_add_inline_style( 'crdm_customizer', $this->inline_css() ); } /** diff --git a/src/php/CrdmBasic/Customizer/class-init.php b/src/php/CrdmBasic/Customizer/class-init.php index 9462fa3..b26f531 100644 --- a/src/php/CrdmBasic/Customizer/class-init.php +++ b/src/php/CrdmBasic/Customizer/class-init.php @@ -76,19 +76,26 @@ protected function init_sections_and_controls() { ( new Footer( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); } - public static function generatepress_module_enabled($module) - { + /** + * Checks for GeneratePress module + * + * Checks whether GeneratePress premium is installed and a module is enabled. + * + * @param string $module The name of the module. + * + * $return bool Whether the module is enabled. + */ + public static function generatepress_module_enabled( $module ) { if ( ! function_exists( 'generatepress_is_module_active' ) ) { return false; } - switch($module) - { - case 'generate_package_backgrounds': - $definition = 'GENERATE_BACKGROUNDS'; - break; - default: - return false; + switch ( $module ) { + case 'generate_package_backgrounds': + $definition = 'GENERATE_BACKGROUNDS'; + break; + default: + return false; } - return generatepress_is_module_active($module, $definition); + return generatepress_is_module_active( $module, $definition ); } } From 0d5b2960746b86493fb037abc4eae3f3cc2ef321 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Mon, 23 Sep 2019 15:08:51 +0200 Subject: [PATCH 06/38] Remade body background-attachment to be GeneratePress-compatible --- .../CrdmBasic/Customizer/class-background.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 292473c..fa18946 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -41,7 +41,7 @@ class Background { 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', 'body_repeat' => '', 'body_size' => '', - 'body_attachment' => 'scroll', + 'body_attachment' => '', 'body_position' => 'left top', ]; @@ -171,6 +171,20 @@ public function customize( $wp_customize ) { ] ); + $wp_customize->add_control( + 'generate_background_settings[body_attachment]', + [ + 'type' => 'select', + 'section' => 'generate_backgrounds_body', + 'choices' => [ + '' => esc_html__( 'Attachment', 'crdm-basic' ), + 'fixed' => esc_html__( 'Fixed', 'crdm-basic' ), + 'local' => esc_html__( 'Local', 'crdm-basic' ), + 'inherit' => esc_html__( 'Inherit', 'crdm-basic' ), + ], + ] + ); + $wp_customize->add_setting( 'generate_background_settings[body_position]', [ @@ -235,6 +249,7 @@ private function inline_css() { $this->print_css_property( $settings, 'background-image', 'body_image', true ) . $this->print_css_property( $settings, 'background-repeat', 'body_repeat' ) . $this->print_css_property( $settings, 'background-size', 'body_size' ) . + $this->print_css_property( $settings, 'background-attachment', 'body_attachment' ) . '}'; } From 2ed534cd80f33ff6a6238630d36ec962a2fd3ef5 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Mon, 23 Sep 2019 15:21:42 +0200 Subject: [PATCH 07/38] Remade body background to be GeneratePress-compatible --- .../CrdmBasic/Customizer/class-background.php | 53 ++++--------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index fa18946..e1aed49 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -42,7 +42,7 @@ class Background { 'body_repeat' => '', 'body_size' => '', 'body_attachment' => '', - 'body_position' => 'left top', + 'body_position' => '', ]; /** @@ -195,23 +195,17 @@ public function customize( $wp_customize ) { ] ); - /* $wp_customize->add_control( - new Background_Image_Customize_Control( - $wp_customize, - 'body_backgrounds_control', - [ - 'section' => 'generate_backgrounds_body', - 'settings' => [ - 'repeat' => 'generate_background_settings[body_repeat]', - 'size' => 'generate_background_settings[body_size]', - 'attachment' => 'generate_background_settings[body_attachment]', - 'position' => 'generate_background_settings[body_position]', - ], - ] - ) + 'generate_background_settings[body_position]', + [ + 'type' => 'text', + 'section' => 'generate_backgrounds_body', + 'description' => __( 'left top, x% y%, xpos ypos (px)', 'crdm-basic' ), + 'input_attrs' => [ + 'placeholder' => __( 'Position', 'crdm-basic' ), + ], + ] ); - */ } } @@ -250,6 +244,7 @@ private function inline_css() { $this->print_css_property( $settings, 'background-repeat', 'body_repeat' ) . $this->print_css_property( $settings, 'background-size', 'body_size' ) . $this->print_css_property( $settings, 'background-attachment', 'body_attachment' ) . + $this->print_css_property( $settings, 'background-position', 'body_position' ) . '}'; } @@ -285,32 +280,6 @@ protected function init_section() { * Adds all the controls to the section */ protected function init_controls() { - /* - Kirki::add_field( - $this->config_id, - [ - 'type' => 'background', - 'settings' => 'webBg', - 'label' => esc_attr__( 'Webpage background', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'background-color' => '#f7f3e2', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', - 'background-repeat' => 'repeat', - 'background-position' => 'left top', - 'background-size' => '300px auto', - 'background-attachment' => 'scroll', - ], - 'output' => [ - [ - 'element' => 'body', - ], - ], - 'transport' => 'auto', - ] - ); - */ - Kirki::add_field( $this->config_id, [ From db661d333c7f68def6cf66637b2729672849ed5f Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Wed, 25 Sep 2019 15:44:25 +0200 Subject: [PATCH 08/38] Added Background_Image_Customize_Control --- .phan/stubs/WordPress/class-wp-control.php | 18 ++++ .../WordPress/class-wp-customize-manager.php | 3 + ...ass-background-image-customize-control.php | 92 +++++++++++++++++++ .../CrdmBasic/Customizer/class-background.php | 66 +++---------- 4 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 .phan/stubs/WordPress/class-wp-control.php create mode 100644 src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php diff --git a/.phan/stubs/WordPress/class-wp-control.php b/.phan/stubs/WordPress/class-wp-control.php new file mode 100644 index 0000000..e4d1552 --- /dev/null +++ b/.phan/stubs/WordPress/class-wp-control.php @@ -0,0 +1,18 @@ +json['position_description'] = esc_html__( 'left top, x%, y%, xpos ypos (px)', 'crdm-basic' ); + $this->json['position_placeholder'] = esc_html__( 'Position', 'crdm-basic' ); + + foreach ( $this->settings as $key => $id ) { + $this->json['settings'][ $key ] = [ + 'link' => $this->get_link( $key ), + 'value' => $this->value( $key ), + 'id' => $id->id ?? '', + ]; + } + + $this->json['repeat_choices'] = [ + '' => esc_html__( 'Repeat', 'crdm-basic' ), + 'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ), + 'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ), + 'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ), + ]; + $this->json['size_choices'] = [ + '' => esc_html__( 'Size (Auto)', 'crdm-basic' ), + '100' => esc_html__( '100% Width', 'crdm-basic' ), + 'cover' => esc_html__( 'Cover', 'crdm-basic' ), + 'contain' => esc_html__( 'Contain', 'crdm-basic' ), + ]; + $this->json['attachment_choices'] = [ + '' => esc_html__( 'Attachment', 'crdm-basic' ), + 'fixed' => esc_html__( 'Fixed', 'crdm-basic' ), + 'local' => esc_html__( 'Local', 'crdm-basic' ), + 'inherit' => esc_html__( 'Inherit', 'crdm-basic' ), + ]; + } + + /** + * Prints the Underscore.js template for the control. + * + * @inheritDoc + */ + public function content_template() { + ?> +<# _.each( [ [ data.settings.repeat, data.repeat_choices ], [ data.settings.size, data.size_choices ], [ data.settings.attachment, data.attachment_choices] ], function( tuple ) { + if ( tuple[0] ) { #> + + <# } +} ); #> + +<# if ( data.settings.position ) { #> + +<# } #> + register_control_type( 'CrdmBasic\Customizer\Controls\Background_Image_Customize_Control' ); + $wp_customize->add_panel( 'generate_backgrounds_panel', [ @@ -125,20 +127,6 @@ public function customize( $wp_customize ) { ] ); - $wp_customize->add_control( - 'generate_background_settings[body_repeat]', - [ - 'type' => 'select', - 'section' => 'generate_backgrounds_body', - 'choices' => [ - '' => esc_html__( 'Repeat', 'crdm-basic' ), - 'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ), - 'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ), - 'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ), - ], - ] - ); - $wp_customize->add_setting( 'generate_background_settings[body_size]', [ @@ -148,20 +136,6 @@ public function customize( $wp_customize ) { ] ); - $wp_customize->add_control( - 'generate_background_settings[body_size]', - [ - 'type' => 'select', - 'section' => 'generate_backgrounds_body', - 'choices' => [ - '' => esc_html__( 'Size (Auto)', 'crdm-basic' ), - '100' => esc_html__( '100% Width', 'crdm-basic' ), - 'cover' => esc_html__( 'Cover', 'crdm-basic' ), - 'contain' => esc_html__( 'Contain', 'crdm-basic' ), - ], - ] - ); - $wp_customize->add_setting( 'generate_background_settings[body_attachment]', [ @@ -171,20 +145,6 @@ public function customize( $wp_customize ) { ] ); - $wp_customize->add_control( - 'generate_background_settings[body_attachment]', - [ - 'type' => 'select', - 'section' => 'generate_backgrounds_body', - 'choices' => [ - '' => esc_html__( 'Attachment', 'crdm-basic' ), - 'fixed' => esc_html__( 'Fixed', 'crdm-basic' ), - 'local' => esc_html__( 'Local', 'crdm-basic' ), - 'inherit' => esc_html__( 'Inherit', 'crdm-basic' ), - ], - ] - ); - $wp_customize->add_setting( 'generate_background_settings[body_position]', [ @@ -196,15 +156,19 @@ public function customize( $wp_customize ) { ); $wp_customize->add_control( - 'generate_background_settings[body_position]', - [ - 'type' => 'text', - 'section' => 'generate_backgrounds_body', - 'description' => __( 'left top, x% y%, xpos ypos (px)', 'crdm-basic' ), - 'input_attrs' => [ - 'placeholder' => __( 'Position', 'crdm-basic' ), - ], - ] + new Controls\Background_Image_Customize_Control( + $wp_customize, + 'body_backgrounds_control', + [ + 'section' => 'generate_backgrounds_body', + 'settings' => [ + 'repeat' => 'generate_background_settings[body_repeat]', + 'size' => 'generate_background_settings[body_size]', + 'attachment' => 'generate_background_settings[body_attachment]', + 'position' => 'generate_background_settings[body_position]', + ], + ] + ) ); } } From ca6da3e7ddb0b683242a566ed5f9f59d3026aaa8 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Wed, 25 Sep 2019 22:29:33 +0200 Subject: [PATCH 09/38] Split body background config --- .../CrdmBasic/Customizer/class-background.php | 179 ++++++++++-------- 1 file changed, 95 insertions(+), 84 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index dfe18d7..357278e 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -76,101 +76,112 @@ public function customize( $wp_customize ) { if ( ! Init::generatepress_module_enabled( 'generate_package_backgrounds' ) ) { $wp_customize->register_control_type( 'CrdmBasic\Customizer\Controls\Background_Image_Customize_Control' ); - $wp_customize->add_panel( - 'generate_backgrounds_panel', - [ - 'capability' => 'edit_theme_options', - 'theme_supports' => '', - 'title' => __( 'Background Images', 'crdm-basic' ), - 'priority' => 55, - ] - ); + $this->customize_body( $wp_customize ); + } + } - $wp_customize->add_section( - 'generate_backgrounds_body', - [ - 'title' => __( 'Body', 'crdm-basic' ), - 'capability' => 'edit_theme_options', - 'priority' => 5, - 'panel' => 'generate_backgrounds_panel', - ] - ); + /** + * Initializes customizer body options. + * + * Adds customizer options for controling the body background. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + public function customize_body( $wp_customize ) { + $wp_customize->add_panel( + 'generate_backgrounds_panel', + [ + 'capability' => 'edit_theme_options', + 'theme_supports' => '', + 'title' => __( 'Background Images', 'crdm-basic' ), + 'priority' => 55, + ] + ); - $wp_customize->add_setting( - 'generate_background_settings[body_image]', - [ - 'default' => self::DEFAULT['body_image'], - 'type' => 'option', - 'capability' => 'edit_theme_options', - 'sanitize_callback' => 'esc_url_raw', - ] - ); + $wp_customize->add_section( + 'generate_backgrounds_body', + [ + 'title' => __( 'Body', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 5, + 'panel' => 'generate_backgrounds_panel', + ] + ); - $wp_customize->add_control( - new \WP_Customize_Image_Control( - $wp_customize, - 'generate_backgrounds-body-image', - [ - 'section' => 'generate_backgrounds_body', - 'settings' => 'generate_background_settings[body_image]', - 'label' => __( 'Body', 'crdm-basic' ), - ] - ) - ); + $wp_customize->add_setting( + 'generate_background_settings[body_image]', + [ + 'default' => self::DEFAULT['body_image'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_url_raw', + ] + ); - $wp_customize->add_setting( - 'generate_background_settings[body_repeat]', + $wp_customize->add_control( + new \WP_Customize_Image_Control( + $wp_customize, + 'generate_backgrounds-body-image', [ - 'default' => self::DEFAULT['body_repeat'], - 'type' => 'option', - 'sanitize_callback' => 'sanitize_key', + 'section' => 'generate_backgrounds_body', + 'settings' => 'generate_background_settings[body_image]', + 'label' => __( 'Body', 'crdm-basic' ), ] - ); + ) + ); - $wp_customize->add_setting( - 'generate_background_settings[body_size]', - [ - 'default' => self::DEFAULT['body_size'], - 'type' => 'option', - 'sanitize_callback' => 'sanitize_key', - ] - ); + $wp_customize->add_setting( + 'generate_background_settings[body_repeat]', + [ + 'default' => self::DEFAULT['body_repeat'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + ] + ); - $wp_customize->add_setting( - 'generate_background_settings[body_attachment]', - [ - 'default' => self::DEFAULT['body_attachment'], - 'type' => 'option', - 'sanitize_callback' => 'sanitize_key', - ] - ); + $wp_customize->add_setting( + 'generate_background_settings[body_size]', + [ + 'default' => self::DEFAULT['body_size'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + ] + ); - $wp_customize->add_setting( - 'generate_background_settings[body_position]', + $wp_customize->add_setting( + 'generate_background_settings[body_attachment]', + [ + 'default' => self::DEFAULT['body_attachment'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + ] + ); + + $wp_customize->add_setting( + 'generate_background_settings[body_position]', + [ + 'default' => self::DEFAULT['body_position'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_html', + ] + ); + + $wp_customize->add_control( + new Controls\Background_Image_Customize_Control( + $wp_customize, + 'body_backgrounds_control', [ - 'default' => self::DEFAULT['body_position'], - 'type' => 'option', - 'capability' => 'edit_theme_options', - 'sanitize_callback' => 'esc_html', + 'section' => 'generate_backgrounds_body', + 'settings' => [ + 'repeat' => 'generate_background_settings[body_repeat]', + 'size' => 'generate_background_settings[body_size]', + 'attachment' => 'generate_background_settings[body_attachment]', + 'position' => 'generate_background_settings[body_position]', + ], ] - ); - - $wp_customize->add_control( - new Controls\Background_Image_Customize_Control( - $wp_customize, - 'body_backgrounds_control', - [ - 'section' => 'generate_backgrounds_body', - 'settings' => [ - 'repeat' => 'generate_background_settings[body_repeat]', - 'size' => 'generate_background_settings[body_size]', - 'attachment' => 'generate_background_settings[body_attachment]', - 'position' => 'generate_background_settings[body_position]', - ], - ] - ) - ); - } + ) + ); } /** From 8922900b91d916b7e566d6012382baca65330249 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 27 Sep 2019 12:16:07 +0200 Subject: [PATCH 10/38] Remade header background to be GeneratePress-compatible --- .phan/stubs/WordPress/functions.php | 3 + .../CrdmBasic/Customizer/class-background.php | 136 ++++++++++-------- src/scss/frontend/header.scss | 3 + 3 files changed, 86 insertions(+), 56 deletions(-) diff --git a/.phan/stubs/WordPress/functions.php b/.phan/stubs/WordPress/functions.php index 9f6a0a4..38ad50a 100644 --- a/.phan/stubs/WordPress/functions.php +++ b/.phan/stubs/WordPress/functions.php @@ -118,6 +118,9 @@ function wp_enqueue_script( $a, $b, $c, $d, $e ) { function wp_enqueue_style( $a, $b = '', $c = [], $d = false ) { } +/** + * @return array + */ function wp_parse_args( $a, $b ) { return []; } diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 357278e..a9e83ed 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -38,11 +38,16 @@ class Background { protected $section_id = ''; const DEFAULT = [ - 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', - 'body_repeat' => '', - 'body_size' => '', - 'body_attachment' => '', - 'body_position' => '', + 'generate_background_settings' => [ + 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', + 'body_repeat' => '', + 'body_size' => '', + 'body_attachment' => '', + 'body_position' => '', + ], + 'crdm_basic_header' => [ + 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', + ], ]; /** @@ -76,8 +81,19 @@ public function customize( $wp_customize ) { if ( ! Init::generatepress_module_enabled( 'generate_package_backgrounds' ) ) { $wp_customize->register_control_type( 'CrdmBasic\Customizer\Controls\Background_Image_Customize_Control' ); + $wp_customize->add_panel( + 'generate_backgrounds_panel', + [ + 'capability' => 'edit_theme_options', + 'theme_supports' => '', + 'title' => __( 'Background Images', 'crdm-basic' ), + 'priority' => 55, + ] + ); + $this->customize_body( $wp_customize ); } + $this->customize_header( $wp_customize ); } /** @@ -87,17 +103,7 @@ public function customize( $wp_customize ) { * * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. */ - public function customize_body( $wp_customize ) { - $wp_customize->add_panel( - 'generate_backgrounds_panel', - [ - 'capability' => 'edit_theme_options', - 'theme_supports' => '', - 'title' => __( 'Background Images', 'crdm-basic' ), - 'priority' => 55, - ] - ); - + private function customize_body( $wp_customize ) { $wp_customize->add_section( 'generate_backgrounds_body', [ @@ -111,7 +117,7 @@ public function customize_body( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[body_image]', [ - 'default' => self::DEFAULT['body_image'], + 'default' => self::DEFAULT['generate_background_settings']['body_image'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', @@ -133,7 +139,7 @@ public function customize_body( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[body_repeat]', [ - 'default' => self::DEFAULT['body_repeat'], + 'default' => self::DEFAULT['generate_background_settings']['body_repeat'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', ] @@ -142,7 +148,7 @@ public function customize_body( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[body_size]', [ - 'default' => self::DEFAULT['body_size'], + 'default' => self::DEFAULT['generate_background_settings']['body_size'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', ] @@ -151,7 +157,7 @@ public function customize_body( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[body_attachment]', [ - 'default' => self::DEFAULT['body_attachment'], + 'default' => self::DEFAULT['generate_background_settings']['body_attachment'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', ] @@ -160,7 +166,7 @@ public function customize_body( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[body_position]', [ - 'default' => self::DEFAULT['body_position'], + 'default' => self::DEFAULT['generate_background_settings']['body_position'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_html', @@ -184,20 +190,60 @@ public function customize_body( $wp_customize ) { ); } + /** + * Initializes customizer header options. + * + * Adds customizer options for controling the header background and foreground images. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function customize_header( $wp_customize ) { + // TODO: Gate. + $wp_customize->add_section( + 'generate_backgrounds_Header', + [ + 'title' => __( 'Header', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 5, + 'panel' => 'generate_backgrounds_panel', + ] + ); + + $wp_customize->add_setting( + 'crdm_basic_header[background]', + [ + 'default' => self::DEFAULT['crdm_basic_header']['background'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_url_raw', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Image_Control( + $wp_customize, + 'crdm_basic_header[background]', + [ + 'section' => 'generate_backgrounds_header', + 'settings' => 'crdm_basic_header[background]', + 'label' => __( 'Header background image', 'crdm-basic' ), + ] + ) + ); + } + /** * Prints a CSS property. * * Escapes, formats and returns a CSS property line. * - * @param array $settings Parsed background settings for GeneratePress. * @param string $css_name The name of the CSS property. - * @param string $settings_name The name of the settings field in $generate_background_settings. + * @param string $value The value of the property. * @param bool $is_url Whether the property is an URL. Default false. * * @return string The CSS property line; */ - private function print_css_property( $settings, $css_name, $settings_name, $is_url = false ) { - $value = $settings[ $settings_name ]; + private function print_css_property( $css_name, $value, $is_url = false ) { if ( empty( $value ) ) { return ''; } @@ -213,13 +259,16 @@ private function print_css_property( $settings, $css_name, $settings_name, $is_u * @return string CSS string. */ private function inline_css() { - $settings = wp_parse_args( get_option( 'generate_background_settings', [] ), self::DEFAULT ); + $generate_settings = wp_parse_args( get_option( 'generate_background_settings', [] ), self::DEFAULT['generate_background_settings'] ); + $crdm_settings = wp_parse_args( get_option( 'crdm_basic_header', [] ), self::DEFAULT['crdm_basic_header'] ); return "body {\n" . - $this->print_css_property( $settings, 'background-image', 'body_image', true ) . - $this->print_css_property( $settings, 'background-repeat', 'body_repeat' ) . - $this->print_css_property( $settings, 'background-size', 'body_size' ) . - $this->print_css_property( $settings, 'background-attachment', 'body_attachment' ) . - $this->print_css_property( $settings, 'background-position', 'body_position' ) . + $this->print_css_property( 'background-image', $generate_settings['body_image'], true ) . + $this->print_css_property( 'background-repeat', $generate_settings['body_repeat'] ) . + $this->print_css_property( 'background-size', $generate_settings['body_size'] ) . + $this->print_css_property( 'background-attachment', $generate_settings['body_attachment'] ) . + $this->print_css_property( 'background-position', $generate_settings['body_position'] ) . + "}\n.crdm_header__bg_1 {" . + $this->print_css_property( 'background-image', $crdm_settings['background'], true ) . '}'; } @@ -255,31 +304,6 @@ protected function init_section() { * Adds all the controls to the section */ protected function init_controls() { - Kirki::add_field( - $this->config_id, - [ - 'type' => 'background', - 'settings' => 'headerBg1', - 'label' => esc_attr__( 'Header background image', 'crdm-basic' ), - 'description' => esc_attr__( 'Behind the menu', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right top', - 'background-size' => '376px auto', - 'background-attachment' => 'scroll', - ], - 'output' => [ - [ - 'element' => '.crdm_header__bg_1', - ], - ], - 'transport' => 'auto', - ] - ); - Kirki::add_field( $this->config_id, [ diff --git a/src/scss/frontend/header.scss b/src/scss/frontend/header.scss index 324c3fe..e1f25c4 100644 --- a/src/scss/frontend/header.scss +++ b/src/scss/frontend/header.scss @@ -16,6 +16,9 @@ width: 100%; height: 216px; z-index: -1; + background-repeat: no-repeat; + background-size: auto 215px; + background-position: right top; @media (max-width: 768px) { display: none; From a9a0f75c87bb2ec0dec2579c0875859d8f607d50 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 27 Sep 2019 12:25:55 +0200 Subject: [PATCH 11/38] Fixed default value for body background image --- src/php/CrdmBasic/Customizer/class-background.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index a9e83ed..f9d9de7 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -39,7 +39,7 @@ class Background { const DEFAULT = [ 'generate_background_settings' => [ - 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', + 'body_image' => '', 'body_repeat' => '', 'body_size' => '', 'body_attachment' => '', From 895518626f73e22fda3d7392d4d60641dc2ed4b7 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 27 Sep 2019 17:30:19 +0200 Subject: [PATCH 12/38] Remade header foreground to be GeneratePress-compatible --- .../CrdmBasic/Customizer/class-background.php | 50 +++++++++---------- src/scss/frontend/header.scss | 3 ++ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index f9d9de7..1a3b2bc 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -47,6 +47,7 @@ class Background { ], 'crdm_basic_header' => [ 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', + 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', ], ]; @@ -230,6 +231,28 @@ private function customize_header( $wp_customize ) { ] ) ); + + $wp_customize->add_setting( + 'crdm_basic_header[foreground]', + [ + 'default' => self::DEFAULT['crdm_basic_header']['foreground'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_url_raw', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Image_Control( + $wp_customize, + 'crdm_basic_header[foreground]', + [ + 'section' => 'generate_backgrounds_header', + 'settings' => 'crdm_basic_header[foreground]', + 'label' => __( 'Header foreground image', 'crdm-basic' ), + ] + ) + ); } /** @@ -269,6 +292,8 @@ private function inline_css() { $this->print_css_property( 'background-position', $generate_settings['body_position'] ) . "}\n.crdm_header__bg_1 {" . $this->print_css_property( 'background-image', $crdm_settings['background'], true ) . + "}\n.crdm_header__bg_2-container-content {" . + $this->print_css_property( 'background-image', $crdm_settings['foreground'], true ) . '}'; } @@ -304,31 +329,6 @@ protected function init_section() { * Adds all the controls to the section */ protected function init_controls() { - Kirki::add_field( - $this->config_id, - [ - 'type' => 'background', - 'settings' => 'headerBg2', - 'label' => esc_attr__( 'Header foreground image', 'crdm-basic' ), - 'description' => esc_attr__( 'In front of the menu', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right bottom', - 'background-size' => '100% auto', - 'background-attachment' => 'scroll', - ], - 'output' => [ - [ - 'element' => '.crdm_header__bg_2-container-content', - ], - ], - 'transport' => 'auto', - ] - ); - Kirki::add_field( $this->config_id, [ diff --git a/src/scss/frontend/header.scss b/src/scss/frontend/header.scss index e1f25c4..3e07ebb 100644 --- a/src/scss/frontend/header.scss +++ b/src/scss/frontend/header.scss @@ -35,6 +35,9 @@ width: 340px; height: 205px; z-index: 1; + background-repeat: no-repeat; + background-size: 100% auto; + background-position: right top; @media (max-width: 768px) { display: none; From a488e09757e66646519a6d39167844121159b6da Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 27 Sep 2019 17:34:40 +0200 Subject: [PATCH 13/38] Not adding sections if added by GP --- .../CrdmBasic/Customizer/class-background.php | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 1a3b2bc..8f871b6 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -82,15 +82,7 @@ public function customize( $wp_customize ) { if ( ! Init::generatepress_module_enabled( 'generate_package_backgrounds' ) ) { $wp_customize->register_control_type( 'CrdmBasic\Customizer\Controls\Background_Image_Customize_Control' ); - $wp_customize->add_panel( - 'generate_backgrounds_panel', - [ - 'capability' => 'edit_theme_options', - 'theme_supports' => '', - 'title' => __( 'Background Images', 'crdm-basic' ), - 'priority' => 55, - ] - ); + $this->add_panel_sections(); $this->customize_body( $wp_customize ); } @@ -98,13 +90,23 @@ public function customize( $wp_customize ) { } /** - * Initializes customizer body options. + * Adds the panel and sections * - * Adds customizer options for controling the body background. + * Adds the panel and sections that would otherwise be added by GeneratePress. * * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. */ - private function customize_body( $wp_customize ) { + private function add_panel_sections( $wp_customize ) { + $wp_customize->add_panel( + 'generate_backgrounds_panel', + [ + 'capability' => 'edit_theme_options', + 'theme_supports' => '', + 'title' => __( 'Background Images', 'crdm-basic' ), + 'priority' => 55, + ] + ); + $wp_customize->add_section( 'generate_backgrounds_body', [ @@ -115,6 +117,25 @@ private function customize_body( $wp_customize ) { ] ); + $wp_customize->add_section( + 'generate_backgrounds_header', + [ + 'title' => __( 'Header', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 5, + 'panel' => 'generate_backgrounds_panel', + ] + ); + } + + /** + * Initializes customizer body options. + * + * Adds customizer options for controling the body background. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function customize_body( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[body_image]', [ @@ -199,17 +220,6 @@ private function customize_body( $wp_customize ) { * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. */ private function customize_header( $wp_customize ) { - // TODO: Gate. - $wp_customize->add_section( - 'generate_backgrounds_Header', - [ - 'title' => __( 'Header', 'crdm-basic' ), - 'capability' => 'edit_theme_options', - 'priority' => 5, - 'panel' => 'generate_backgrounds_panel', - ] - ); - $wp_customize->add_setting( 'crdm_basic_header[background]', [ @@ -227,7 +237,7 @@ private function customize_header( $wp_customize ) { [ 'section' => 'generate_backgrounds_header', 'settings' => 'crdm_basic_header[background]', - 'label' => __( 'Header background image', 'crdm-basic' ), + 'label' => __( 'Featured background image', 'crdm-basic' ), ] ) ); @@ -249,7 +259,7 @@ private function customize_header( $wp_customize ) { [ 'section' => 'generate_backgrounds_header', 'settings' => 'crdm_basic_header[foreground]', - 'label' => __( 'Header foreground image', 'crdm-basic' ), + 'label' => __( 'Featured foreground image', 'crdm-basic' ), ] ) ); From ae95517561a2224aa1598bf1106bcdeb0e589d76 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 27 Sep 2019 17:45:59 +0200 Subject: [PATCH 14/38] Remade header grass image to be GeneratePress-compatible --- .../CrdmBasic/Customizer/class-background.php | 27 ++++++++++++++++++- src/scss/frontend/header.scss | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 8f871b6..4792b9b 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -48,6 +48,7 @@ class Background { 'crdm_basic_header' => [ 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', + 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', ], ]; @@ -82,7 +83,7 @@ public function customize( $wp_customize ) { if ( ! Init::generatepress_module_enabled( 'generate_package_backgrounds' ) ) { $wp_customize->register_control_type( 'CrdmBasic\Customizer\Controls\Background_Image_Customize_Control' ); - $this->add_panel_sections(); + $this->add_panel_sections( $wp_customize ); $this->customize_body( $wp_customize ); } @@ -263,6 +264,28 @@ private function customize_header( $wp_customize ) { ] ) ); + + $wp_customize->add_setting( + 'crdm_basic_header[under]', + [ + 'default' => self::DEFAULT['crdm_basic_header']['under'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_url_raw', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Image_Control( + $wp_customize, + 'crdm_basic_header[under]', + [ + 'section' => 'generate_backgrounds_header', + 'settings' => 'crdm_basic_header[under]', + 'label' => __( 'Under menu image', 'crdm-basic' ), + ] + ) + ); } /** @@ -304,6 +327,8 @@ private function inline_css() { $this->print_css_property( 'background-image', $crdm_settings['background'], true ) . "}\n.crdm_header__bg_2-container-content {" . $this->print_css_property( 'background-image', $crdm_settings['foreground'], true ) . + "}\n.crdm_header__bg_3 {" . + $this->print_css_property( 'background-image', $crdm_settings['under'], true ) . '}'; } diff --git a/src/scss/frontend/header.scss b/src/scss/frontend/header.scss index 3e07ebb..0552743 100644 --- a/src/scss/frontend/header.scss +++ b/src/scss/frontend/header.scss @@ -53,6 +53,9 @@ right: 0; width: 100%; height: 28px; + background-repeat: repeat-x; + background-size: auto 100%; + background-position: left bottom; } .page-header-image.crdm_page-header { From e038a59aec11f0d9d8d639418a7c2b0b6d2b956d Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 27 Sep 2019 17:46:24 +0200 Subject: [PATCH 15/38] Removed Kirki from background class --- .../CrdmBasic/Customizer/class-background.php | 82 +------------------ src/php/CrdmBasic/Customizer/class-init.php | 2 +- 2 files changed, 2 insertions(+), 82 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 4792b9b..74e1bb3 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -9,34 +9,12 @@ namespace CrdmBasic\Customizer; -use Kirki; - /** * Background configuration * * This class sets up all the customizer options for configuring the background of the webpage. */ class Background { - - /** - * The ID of the configuration set ("crdm-basic"). - * - * @var string $config_id - */ - protected $config_id = ''; - /** - * The ID of the panel in which this option is displayed. - * - * @var string $panel_id - */ - protected $panel_id = ''; - /** - * The ID of the section in which this option is displayed. - * - * @var string $section_id - */ - protected $section_id = ''; - const DEFAULT = [ 'generate_background_settings' => [ 'body_image' => '', @@ -56,18 +34,8 @@ class Background { * Background class constructor * * Adds the section and its controls to the customizer. - * - * @param string $config_id The ID of the configuration set ("crdm-basic"). - * @param string $panel_id The ID of the panel in which this option is displayed. */ - public function __construct( string $config_id, string $panel_id ) { - $this->config_id = $config_id; - $this->panel_id = $panel_id; - $this->section_id = $panel_id . '_background'; - - $this->init_section(); - $this->init_controls(); - + public function __construct() { add_action( 'customize_register', [ $this, 'customize' ], 1000 ); add_action( 'wp_enqueue_scripts', [ $this, 'add_inline_css' ] ); } @@ -342,52 +310,4 @@ public function add_inline_css() { wp_enqueue_style( 'crdm_customizer' ); wp_add_inline_style( 'crdm_customizer', $this->inline_css() ); } - - /** - * Initializes the section - * - * Adds the section to the customizer. - */ - protected function init_section() { - Kirki::add_section( - $this->section_id, - [ - 'title' => esc_attr__( 'Background', 'crdm-basic' ), - 'panel' => $this->panel_id, - ] - ); - } - - /** - * Initializes the controls - * - * Adds all the controls to the section - */ - protected function init_controls() { - Kirki::add_field( - $this->config_id, - [ - 'type' => 'background', - 'settings' => 'headerBg3', - 'label' => esc_attr__( 'Header bottom image', 'crdm-basic' ), - 'description' => esc_attr__( 'Under the menu', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', - 'background-repeat' => 'repeat-x', - 'background-position' => 'left bottom', - 'background-size' => 'auto 100%', - 'background-attachment' => 'scroll', - ], - 'output' => [ - [ - 'element' => '.crdm_header__bg_3', - ], - ], - 'transport' => 'auto', - ] - ); - } - } diff --git a/src/php/CrdmBasic/Customizer/class-init.php b/src/php/CrdmBasic/Customizer/class-init.php index b26f531..f250220 100644 --- a/src/php/CrdmBasic/Customizer/class-init.php +++ b/src/php/CrdmBasic/Customizer/class-init.php @@ -67,7 +67,7 @@ protected function init_panel() { */ protected function init_sections_and_controls() { ( new Color_Variant( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); - ( new Background( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); + ( new Background() ); ( new Border_Radius( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Menu( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Sidebar( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); From 3b2563c3d5c691a86ce8f6dd8b73b3c01efc68c0 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sat, 28 Sep 2019 22:06:13 +0200 Subject: [PATCH 16/38] Enabled multiple outputs for webpack --- webpack.config.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index d0d3b19..ca02527 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -36,11 +36,11 @@ LiveReloadPlugin.prototype.done = function done(stats) { module.exports = { mode: 'production', entry: { - index: './src/js/frontend/index.js' + 'frontend/index': './src/js/frontend/index.js' }, output: { filename: '[name].js', - path: path.resolve(__dirname, 'dist/frontend') + path: path.resolve(__dirname, 'dist') }, devtool: 'source-map', watchOptions: { @@ -105,26 +105,27 @@ module.exports = { }, plugins: [ new CleanWebpackPlugin({ - verbose: true + verbose: true, + cleanStaleWebpackAssets: false }), new CopyWebpackPlugin([{ from: './src/png/frontend', - to: './' + to: './frontend' },{ from: './src/png/admin', - to: './../admin' + to: './admin' },{ from: './src/php/functions.php', - to: './../' + to: './' },{ from: './src/php/CrdmBasic', - to: './../src/php/CrdmBasic' + to: './src/php/CrdmBasic' },{ from: './src/assets', - to: './../' + to: './' },{ from: './vendor', - to: './../vendor', + to: './vendor', ignore: ['**/\.*', '**/\.*/**/*'], transform(content, path) { if (path.match(/\.(?:php|md)$/)) { From 563b90fc53ff90e6923a511b8158cd1effcf537e Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sun, 29 Sep 2019 14:04:18 +0200 Subject: [PATCH 17/38] Added preset control --- .phan/stubs/WordPress/functions.php | 3 + src/js/admin/preset_customize_control.js | 21 ++ .../class-preset-customize-control.php | 96 +++++++ src/php/CrdmBasic/Customizer/class-init.php | 1 + src/php/CrdmBasic/Customizer/class-preset.php | 270 ++++++++++++++++++ webpack.config.js | 3 +- 6 files changed, 393 insertions(+), 1 deletion(-) create mode 100644 src/js/admin/preset_customize_control.js create mode 100644 src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php create mode 100644 src/php/CrdmBasic/Customizer/class-preset.php diff --git a/.phan/stubs/WordPress/functions.php b/.phan/stubs/WordPress/functions.php index 38ad50a..d87f9b5 100644 --- a/.phan/stubs/WordPress/functions.php +++ b/.phan/stubs/WordPress/functions.php @@ -118,6 +118,9 @@ function wp_enqueue_script( $a, $b, $c, $d, $e ) { function wp_enqueue_style( $a, $b = '', $c = [], $d = false ) { } +function wp_localize_script( $a, $b, $c ) { +} + /** * @return array */ diff --git a/src/js/admin/preset_customize_control.js b/src/js/admin/preset_customize_control.js new file mode 100644 index 0000000..4fb2f19 --- /dev/null +++ b/src/js/admin/preset_customize_control.js @@ -0,0 +1,21 @@ +'use strict'; + +jQuery( 'document' ).ready( function( $ ) { + wp.customize.control( + 'crdm_basic_preset', + function( control ) { + console.log( crdmbasicPresetCustomizeControlLocalize ); + control.container.find( '.button' ).on( 'click', function() { + console.log( 'CLICK' ); + console.log( wp.customize( 'generate_background_settings[body_image]' ).get() ); + console.log( wp.customize( 'generate_background_settings[body_repeat]' ).get() ); + console.log( wp.customize( 'generate_background_settings[body_size]' ).get() ); + console.log( wp.customize( 'generate_background_settings[body_attachment]' ).get() ); + console.log( wp.customize( 'generate_background_settings[body_position]' ).get() ); + console.log( wp.customize( 'crdm_basic_header[background]' ).get() ); + console.log( wp.customize( 'crdm_basic_header[foreground]' ).get() ); + console.log( wp.customize( 'crdm_basic_header[under]' ).get() ); + }); + } + ); +}); diff --git a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php new file mode 100644 index 0000000..568bc88 --- /dev/null +++ b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php @@ -0,0 +1,96 @@ + $this->settings['light'], + 'dark' => $this->settings['dark'], + ] + ); + } + + /** + * Handles AJAX requests + * + * Handles AJAX requests for choosing a preset. + * + public function handle_ajax() { + wp_send_json_success( [ 'status' => 'ok' ] ); + } + */ + + /** + * Exports control parameters for JS. + * + * @inheritDoc + * + public function to_json() { + parent::to_json(); + + //vardump($this->settings); + //$this->json['settings'] = $this->value( $this->settings ); + } + */ + + /** + * Prints the Underscore.js template for the control. + * + * @inheritDoc + */ + public function content_template() { + ?> + + + + register_control_type( 'CrdmBasic\Customizer\Controls\Preset_Customize_Control' ); + + $wp_customize->add_section( + 'crdm_basic_preset', + [ + 'title' => __( 'Preset', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 21, + ] + ); + + /* + $wp_customize->add_setting( + 'crdm_basic_preset', + [ + 'default' => self::DEFAULT, + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => [ $this, 'sanitize' ], + ] + ); + */ + + $wp_customize->add_control( + new Controls\Preset_Customize_Control( + $wp_customize, + 'crdm_basic_preset', + [ + 'section' => 'crdm_basic_preset', + 'settings' => [], + ] + ) + ); + } + + /* + public function sanitize( $value ) { + return 'dark' === $value ? 'dark' : 'light'; + } + */ + + /* + protected function init_section() { + Kirki::add_section( + $this->section_id, + [ + 'title' => esc_attr__( 'Preset', 'crdm-basic' ), + 'panel' => $this->panel_id, + ] + ); + } + + protected function init_controls() { + Kirki::add_field( + $this->config_id, + [ + 'type' => 'radio-image', + 'settings' => 'radio_image_setting', + 'label' => esc_attr__( 'Choose a preset', 'crdm-basic' ), + 'description' => esc_attr__( 'CAUTION! Current theme settings will be overriden upon saving.', 'crdm-basic' ), + 'section' => $this->section_id, + 'default' => 'light', + 'choices' => [ + 'light' => CRDMBASIC_TEMPLATE_URL . 'admin/light.png', + 'dark' => CRDMBASIC_TEMPLATE_URL . 'admin/dark.png', + ], + 'preset' => [ + 'light' => [ + 'settings' => [ + 'webBg' => [ + 'background-color' => 'rgba(255, 255, 255, 0)', + 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', + ], + 'headerBg1' => [ + 'background-color' => 'rgba(255, 255, 255, 0)', + 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', + 'background-repeat' => 'no-repeat', + 'background-position' => 'right top', + 'background-size' => '376px auto', + 'background-attachment' => 'scroll', + ], + 'headerBg2' => [ + 'background-color' => 'rgba(255, 255, 255, 0)', + 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', + 'background-repeat' => 'no-repeat', + 'background-position' => 'right bottom', + 'background-size' => '100% auto', + 'background-attachment' => 'scroll', + ], + 'headerBg3' => [ + 'background-color' => 'rgba(255, 255, 255, 0)', + 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', + 'background-repeat' => 'repeat-x', + 'background-position' => 'left bottom', + 'background-size' => 'auto 100%', + 'background-attachment' => 'scroll', + ], + 'borderRadius' => '0px', + 'menuBg' => [ + 'background-color' => '#037b8c', + 'background-image' => '', + ], + 'menuFont' => [ + 'font-family' => 'Patrick Hand', + 'color' => '#efefe5', + ], + 'menuSeparatorColor' => '#3b969f', + 'submenuBg' => [ + 'background-color' => '#65c3d4', + 'background-image' => '', + ], + 'submenuFont' => [ + 'font-family' => 'Patrick Hand', + 'color' => '#ffffff', + ], + 'submenuSeparatorColor' => '#ffffff', + 'contentFont' => [ + 'font-family' => 'PT Sans', + 'color' => '#3f3f3f', + ], + 'contentH1Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#037b8c', + ], + 'contentH2Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#037b8c', + ], + 'contentH3Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#00011f', + ], + 'contentH4Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#037b8c', + ], + 'contentH5Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#00011f', + ], + 'contentH6Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#00011f', + ], + 'contentLinksColor' => '#037b8c', + 'sidebarLinksColor' => '#037b8c', + 'footerLinksColor' => '#037b8c', + ], + ], + 'dark' => [ + 'settings' => [ + 'webBg' => [ + 'background-color' => '#0f2b4a', + 'background-image' => '', + ], + 'headerBg1' => [ + 'background-color' => 'rgba(255, 255, 255, 0)', + 'background-image' => '', + ], + 'headerBg2' => [ + 'background-color' => 'rgba(255, 255, 255, 0)', + 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_header_foreground.png', + 'background-repeat' => 'no-repeat', + 'background-position' => 'right bottom', + 'background-size' => '87% auto', + 'background-attachment' => 'scroll', + ], + 'headerBg3' => [ + 'background-color' => 'rgba(255, 255, 255, 0)', + 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_pavement.png', + 'background-repeat' => 'repeat-x', + 'background-position' => 'left bottom', + 'background-size' => '24px 10px', + 'background-attachment' => 'scroll', + ], + 'borderRadius' => '0.5em', + 'menuBg' => [ + 'background-color' => '#122030', + 'background-image' => '', + ], + 'menuFont' => [ + 'font-family' => 'Patrick Hand', + 'color' => '#f2efde', + ], + 'menuSeparatorColor' => '#465058', + 'submenuBg' => [ + 'background-color' => '#122030', + 'background-image' => '', + ], + 'submenuFont' => [ + 'font-family' => 'Patrick Hand', + 'color' => '#5aa4cc', + ], + 'submenuSeparatorColor' => '#0f2b4a', + 'contentFont' => [ + 'font-family' => 'PT Sans', + 'color' => '#ebebeb', + ], + 'contentH1Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#7adff1', + ], + 'contentH2Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#7adff1', + ], + 'contentH3Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#ebebeb', + ], + 'contentH4Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#7adff1', + ], + 'contentH5Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#ebebeb', + ], + 'contentH6Font' => [ + 'font-family' => 'PT Sans', + 'color' => '#ebebeb', + ], + 'contentLinksColor' => '#7adff1', + 'sidebarLinksColor' => '#5aa5c8', + 'footerLinksColor' => '#5aa5c8', + ], + ], + ], + ] + ); + } + */ + +} diff --git a/webpack.config.js b/webpack.config.js index ca02527..1d37fab 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -36,7 +36,8 @@ LiveReloadPlugin.prototype.done = function done(stats) { module.exports = { mode: 'production', entry: { - 'frontend/index': './src/js/frontend/index.js' + 'frontend/index': './src/js/frontend/index.js', + 'admin/preset_customize_control': './src/js/admin/preset_customize_control.js' }, output: { filename: '[name].js', From 11047a2d54d25255d9fd16f0b241462709dce671 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sun, 29 Sep 2019 15:45:42 +0200 Subject: [PATCH 18/38] Removed old code --- .../class-preset-customize-control.php | 24 ------------------- src/php/CrdmBasic/Customizer/class-preset.php | 18 -------------- 2 files changed, 42 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php index 568bc88..0c79c60 100644 --- a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php +++ b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php @@ -23,20 +23,6 @@ class Preset_Customize_Control extends \WP_Customize_Control { */ public $type = 'crdm-basic-preset'; - /** - * Preset_Customize_Control constructor. - * - * Adds the action to handle the AJAX from the control. - * - * @inheritDoc - * - public function __construct( $manager, $id, $args = [] ) { - parent::__construct( $manager, $id, $args ); - - //add_action( 'wp_ajax_crdmbasic_choose_preset', [ $this, 'handle_ajax' ] ); - } - */ - /** * Enqueues the JS. * @@ -54,16 +40,6 @@ public function enqueue() { ); } - /** - * Handles AJAX requests - * - * Handles AJAX requests for choosing a preset. - * - public function handle_ajax() { - wp_send_json_success( [ 'status' => 'ok' ] ); - } - */ - /** * Exports control parameters for JS. * diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index c26474b..82a139f 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -45,18 +45,6 @@ public function customize( $wp_customize ) { ] ); - /* - $wp_customize->add_setting( - 'crdm_basic_preset', - [ - 'default' => self::DEFAULT, - 'type' => 'option', - 'capability' => 'edit_theme_options', - 'sanitize_callback' => [ $this, 'sanitize' ], - ] - ); - */ - $wp_customize->add_control( new Controls\Preset_Customize_Control( $wp_customize, @@ -69,12 +57,6 @@ public function customize( $wp_customize ) { ); } - /* - public function sanitize( $value ) { - return 'dark' === $value ? 'dark' : 'light'; - } - */ - /* protected function init_section() { Kirki::add_section( From b749459edd671a4315ef32acdf4712904e357ce9 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sun, 29 Sep 2019 18:04:59 +0200 Subject: [PATCH 19/38] Functional preset changing --- src/js/admin/preset_customize_control.js | 40 ++++++++++++++----- .../class-preset-customize-control.php | 36 ++++++++++++++--- src/php/CrdmBasic/Customizer/class-preset.php | 36 ++++++++++++++++- 3 files changed, 95 insertions(+), 17 deletions(-) diff --git a/src/js/admin/preset_customize_control.js b/src/js/admin/preset_customize_control.js index 4fb2f19..b24a685 100644 --- a/src/js/admin/preset_customize_control.js +++ b/src/js/admin/preset_customize_control.js @@ -1,20 +1,40 @@ 'use strict'; jQuery( 'document' ).ready( function( $ ) { + function flatten( input ) { + const ret = {}; + $.each( input, function( key, value ) { + if ( 'object' === typeof ( value ) ) { + $.each( value, function( subKey, subValue ) { + ret[key + '[' + subKey + ']'] = subValue; + }); + } else { + ret[key] = value; + } + }); + return ret; + } + wp.customize.control( 'crdm_basic_preset', function( control ) { - console.log( crdmbasicPresetCustomizeControlLocalize ); + const presets = []; + $.each( crdmbasicPresetCustomizeControlLocalize, function( key, value ) { + presets[key] = flatten( value ); + }); control.container.find( '.button' ).on( 'click', function() { - console.log( 'CLICK' ); - console.log( wp.customize( 'generate_background_settings[body_image]' ).get() ); - console.log( wp.customize( 'generate_background_settings[body_repeat]' ).get() ); - console.log( wp.customize( 'generate_background_settings[body_size]' ).get() ); - console.log( wp.customize( 'generate_background_settings[body_attachment]' ).get() ); - console.log( wp.customize( 'generate_background_settings[body_position]' ).get() ); - console.log( wp.customize( 'crdm_basic_header[background]' ).get() ); - console.log( wp.customize( 'crdm_basic_header[foreground]' ).get() ); - console.log( wp.customize( 'crdm_basic_header[under]' ).get() ); + const chosen = control.container.find( 'input[name=crdm_basic_preset]:checked' ).val(); + if ( ! chosen ) { + console.log( 'FAIL' ); + return; + } + $.each( presets[chosen], function( key, value ) { + const setting = wp.customize( key ); + if ( ! setting ) { + return; + } + setting.set( value ); + }); }); } ); diff --git a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php index 0c79c60..e39ceb5 100644 --- a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php +++ b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php @@ -23,20 +23,46 @@ class Preset_Customize_Control extends \WP_Customize_Control { */ public $type = 'crdm-basic-preset'; + /** + * The available presets + * + * @var array + */ + private $presets; + + /** + * Preset_Customize_Control constructor. + * + * Initializes the available presets. + * + * @param \WP_Customize_Manager $manager Customizer bootstrap instance. + * @param string $id Control ID. + * @param array $args Control arguments. + * @param array $presets The available presets. + * + * @inheritDoc + * + * @SuppressWarnings(PHPMD.ShortVariable) + */ + public function __construct( $manager, $id, $args, $presets = [] ) { + parent::__construct( $manager, $id, $args ); + + $this->presets = $presets; + } + /** * Enqueues the JS. * * Enqueues the JavaScript file handling the Control. + * + * @inheritDoc */ public function enqueue() { wp_enqueue_script( 'crdm_basic_preset_customize_control', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.js', [ 'jquery', 'customize-preview' ], CRDMBASIC_APP_VERSION, true ); wp_localize_script( 'crdm_basic_preset_customize_control', 'crdmbasicPresetCustomizeControlLocalize', - [ - 'light' => $this->settings['light'], - 'dark' => $this->settings['dark'], - ] + $this->presets ); } @@ -64,7 +90,7 @@ public function content_template() { Light
[ + 'generate_background_settings' => [ + // TODO: Background colour. + 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', + 'body_repeat' => '', + 'body_size' => '', + 'body_attachment' => '', + 'body_position' => '', + ], + 'crdm_basic_header' => [ + 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', + 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', + 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', + ], + ], + 'dark' => [ + 'generate_background_settings' => [ + // TODO: Background colour. + 'body_image' => '', + 'body_repeat' => '', + 'body_size' => '', + 'body_attachment' => '', + 'body_position' => '', + ], + 'crdm_basic_header' => [ + 'background' => '', + 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_header_foreground.png', + 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_pavement.png', + ], + ], + ]; /** * Preset class constructor @@ -52,7 +83,8 @@ public function customize( $wp_customize ) { [ 'section' => 'crdm_basic_preset', 'settings' => [], - ] + ], + self::PRESETS ) ); } From 9124e530935202e36f041a9fcced9c26ade72f7a Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sun, 29 Sep 2019 18:14:58 +0200 Subject: [PATCH 20/38] Added body color selection to presets --- .../Customizer/class-color-variant.php | 52 ----- src/php/CrdmBasic/Customizer/class-preset.php | 201 +----------------- 2 files changed, 6 insertions(+), 247 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index 8b31ac9..09ec8ce 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -91,34 +91,6 @@ protected function init_controls() { 'preset' => [ 'light' => [ 'settings' => [ - 'webBg' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', - ], - 'headerBg1' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right top', - 'background-size' => '376px auto', - 'background-attachment' => 'scroll', - ], - 'headerBg2' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right bottom', - 'background-size' => '100% auto', - 'background-attachment' => 'scroll', - ], - 'headerBg3' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', - 'background-repeat' => 'repeat-x', - 'background-position' => 'left bottom', - 'background-size' => 'auto 100%', - 'background-attachment' => 'scroll', - ], 'borderRadius' => '0px', 'menuBg' => [ 'background-color' => '#037b8c', @@ -173,30 +145,6 @@ protected function init_controls() { ], 'dark' => [ 'settings' => [ - 'webBg' => [ - 'background-color' => '#0f2b4a', - 'background-image' => '', - ], - 'headerBg1' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => '', - ], - 'headerBg2' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_header_foreground.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right bottom', - 'background-size' => '87% auto', - 'background-attachment' => 'scroll', - ], - 'headerBg3' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_pavement.png', - 'background-repeat' => 'repeat-x', - 'background-position' => 'left bottom', - 'background-size' => '24px 10px', - 'background-attachment' => 'scroll', - ], 'borderRadius' => '0.5em', 'menuBg' => [ 'background-color' => '#122030', diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index ccc6894..1b81561 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -17,8 +17,10 @@ class Preset { const PRESETS = [ 'light' => [ + 'generate_settings' => [ + 'background_color' => '#ffffff', + ], 'generate_background_settings' => [ - // TODO: Background colour. 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', 'body_repeat' => '', 'body_size' => '', @@ -32,8 +34,10 @@ class Preset { ], ], 'dark' => [ + 'generate_settings' => [ + 'background_color' => '#0f2b4a', + ], 'generate_background_settings' => [ - // TODO: Background colour. 'body_image' => '', 'body_repeat' => '', 'body_size' => '', @@ -88,197 +92,4 @@ public function customize( $wp_customize ) { ) ); } - - /* - protected function init_section() { - Kirki::add_section( - $this->section_id, - [ - 'title' => esc_attr__( 'Preset', 'crdm-basic' ), - 'panel' => $this->panel_id, - ] - ); - } - - protected function init_controls() { - Kirki::add_field( - $this->config_id, - [ - 'type' => 'radio-image', - 'settings' => 'radio_image_setting', - 'label' => esc_attr__( 'Choose a preset', 'crdm-basic' ), - 'description' => esc_attr__( 'CAUTION! Current theme settings will be overriden upon saving.', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => 'light', - 'choices' => [ - 'light' => CRDMBASIC_TEMPLATE_URL . 'admin/light.png', - 'dark' => CRDMBASIC_TEMPLATE_URL . 'admin/dark.png', - ], - 'preset' => [ - 'light' => [ - 'settings' => [ - 'webBg' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', - ], - 'headerBg1' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right top', - 'background-size' => '376px auto', - 'background-attachment' => 'scroll', - ], - 'headerBg2' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right bottom', - 'background-size' => '100% auto', - 'background-attachment' => 'scroll', - ], - 'headerBg3' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', - 'background-repeat' => 'repeat-x', - 'background-position' => 'left bottom', - 'background-size' => 'auto 100%', - 'background-attachment' => 'scroll', - ], - 'borderRadius' => '0px', - 'menuBg' => [ - 'background-color' => '#037b8c', - 'background-image' => '', - ], - 'menuFont' => [ - 'font-family' => 'Patrick Hand', - 'color' => '#efefe5', - ], - 'menuSeparatorColor' => '#3b969f', - 'submenuBg' => [ - 'background-color' => '#65c3d4', - 'background-image' => '', - ], - 'submenuFont' => [ - 'font-family' => 'Patrick Hand', - 'color' => '#ffffff', - ], - 'submenuSeparatorColor' => '#ffffff', - 'contentFont' => [ - 'font-family' => 'PT Sans', - 'color' => '#3f3f3f', - ], - 'contentH1Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#037b8c', - ], - 'contentH2Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#037b8c', - ], - 'contentH3Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#00011f', - ], - 'contentH4Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#037b8c', - ], - 'contentH5Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#00011f', - ], - 'contentH6Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#00011f', - ], - 'contentLinksColor' => '#037b8c', - 'sidebarLinksColor' => '#037b8c', - 'footerLinksColor' => '#037b8c', - ], - ], - 'dark' => [ - 'settings' => [ - 'webBg' => [ - 'background-color' => '#0f2b4a', - 'background-image' => '', - ], - 'headerBg1' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => '', - ], - 'headerBg2' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_header_foreground.png', - 'background-repeat' => 'no-repeat', - 'background-position' => 'right bottom', - 'background-size' => '87% auto', - 'background-attachment' => 'scroll', - ], - 'headerBg3' => [ - 'background-color' => 'rgba(255, 255, 255, 0)', - 'background-image' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_pavement.png', - 'background-repeat' => 'repeat-x', - 'background-position' => 'left bottom', - 'background-size' => '24px 10px', - 'background-attachment' => 'scroll', - ], - 'borderRadius' => '0.5em', - 'menuBg' => [ - 'background-color' => '#122030', - 'background-image' => '', - ], - 'menuFont' => [ - 'font-family' => 'Patrick Hand', - 'color' => '#f2efde', - ], - 'menuSeparatorColor' => '#465058', - 'submenuBg' => [ - 'background-color' => '#122030', - 'background-image' => '', - ], - 'submenuFont' => [ - 'font-family' => 'Patrick Hand', - 'color' => '#5aa4cc', - ], - 'submenuSeparatorColor' => '#0f2b4a', - 'contentFont' => [ - 'font-family' => 'PT Sans', - 'color' => '#ebebeb', - ], - 'contentH1Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#7adff1', - ], - 'contentH2Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#7adff1', - ], - 'contentH3Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#ebebeb', - ], - 'contentH4Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#7adff1', - ], - 'contentH5Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#ebebeb', - ], - 'contentH6Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#ebebeb', - ], - 'contentLinksColor' => '#7adff1', - 'sidebarLinksColor' => '#5aa5c8', - 'footerLinksColor' => '#5aa5c8', - ], - ], - ], - ] - ); - } - */ - } From 7de82955a5e77dd44fff84478a7d2005c20d2810 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Sun, 29 Sep 2019 19:14:45 +0200 Subject: [PATCH 21/38] Styled the preset chooser --- src/js/admin/preset_customize_control.js | 4 +++ .../class-preset-customize-control.php | 27 ++++++++++++------- src/scss/admin/preset_customize_control.scss | 9 +++++++ 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/scss/admin/preset_customize_control.scss diff --git a/src/js/admin/preset_customize_control.js b/src/js/admin/preset_customize_control.js index b24a685..31aa59f 100644 --- a/src/js/admin/preset_customize_control.js +++ b/src/js/admin/preset_customize_control.js @@ -1,3 +1,4 @@ +import '../../scss/admin/preset_customize_control.scss'; 'use strict'; jQuery( 'document' ).ready( function( $ ) { @@ -22,6 +23,9 @@ jQuery( 'document' ).ready( function( $ ) { $.each( crdmbasicPresetCustomizeControlLocalize, function( key, value ) { presets[key] = flatten( value ); }); + control.container.find( 'input[name=crdm_basic_preset]' ).change( function() { + control.container.find( '.button' ).prop( 'disabled', false ); + }); control.container.find( '.button' ).on( 'click', function() { const chosen = control.container.find( 'input[name=crdm_basic_preset]:checked' ).val(); if ( ! chosen ) { diff --git a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php index e39ceb5..c73f7a8 100644 --- a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php +++ b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php @@ -58,9 +58,10 @@ public function __construct( $manager, $id, $args, $presets = [] ) { * @inheritDoc */ public function enqueue() { - wp_enqueue_script( 'crdm_basic_preset_customize_control', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.js', [ 'jquery', 'customize-preview' ], CRDMBASIC_APP_VERSION, true ); + wp_enqueue_style( 'crdm_basic_preset_customize_control_style', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.css', [], CRDMBASIC_APP_VERSION ); + wp_enqueue_script( 'crdm_basic_preset_customize_control_script', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.js', [ 'jquery', 'customize-preview' ], CRDMBASIC_APP_VERSION, true ); wp_localize_script( - 'crdm_basic_preset_customize_control', + 'crdm_basic_preset_customize_control_script', 'crdmbasicPresetCustomizeControlLocalize', $this->presets ); @@ -70,14 +71,17 @@ public function enqueue() { * Exports control parameters for JS. * * @inheritDoc - * + */ public function to_json() { parent::to_json(); - //vardump($this->settings); - //$this->json['settings'] = $this->value( $this->settings ); + $this->json['light_image'] = CRDMBASIC_TEMPLATE_URL . 'admin/light.png'; + $this->json['dark_image'] = CRDMBASIC_TEMPLATE_URL . 'admin/dark.png'; + $this->json['light'] = esc_html__( 'Light', 'crdm-basic' ); + $this->json['dark'] = esc_html__( 'Dark', 'crdm-basic' ); + $this->json['warning'] = esc_html__( 'Applying the preset overrides a lot of the theme options. You can always go back by closing the customizer.', 'crdm-basic' ); + $this->json['button'] = esc_html__( 'Apply', 'crdm-basic' ); } - */ /** * Prints the Underscore.js template for the control. @@ -87,12 +91,17 @@ public function to_json() { public function content_template() { ?> - +
+ {{{ data.warning }}} +
+ Date: Mon, 30 Sep 2019 00:08:43 +0200 Subject: [PATCH 22/38] Added the Customizer_Category class to reuse code better --- .../class-preset-customize-control.php | 10 +-- .../CrdmBasic/Customizer/class-background.php | 83 +++++------------ .../Customizer/class-customizer-category.php | 90 +++++++++++++++++++ 3 files changed, 119 insertions(+), 64 deletions(-) create mode 100644 src/php/CrdmBasic/Customizer/class-customizer-category.php diff --git a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php index c73f7a8..dc906e2 100644 --- a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php +++ b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php @@ -76,11 +76,11 @@ public function to_json() { parent::to_json(); $this->json['light_image'] = CRDMBASIC_TEMPLATE_URL . 'admin/light.png'; - $this->json['dark_image'] = CRDMBASIC_TEMPLATE_URL . 'admin/dark.png'; - $this->json['light'] = esc_html__( 'Light', 'crdm-basic' ); - $this->json['dark'] = esc_html__( 'Dark', 'crdm-basic' ); - $this->json['warning'] = esc_html__( 'Applying the preset overrides a lot of the theme options. You can always go back by closing the customizer.', 'crdm-basic' ); - $this->json['button'] = esc_html__( 'Apply', 'crdm-basic' ); + $this->json['dark_image'] = CRDMBASIC_TEMPLATE_URL . 'admin/dark.png'; + $this->json['light'] = esc_html__( 'Light', 'crdm-basic' ); + $this->json['dark'] = esc_html__( 'Dark', 'crdm-basic' ); + $this->json['warning'] = esc_html__( 'Applying the preset overrides a lot of the theme options. You can always go back by closing the customizer.', 'crdm-basic' ); + $this->json['button'] = esc_html__( 'Apply', 'crdm-basic' ); } /** diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 74e1bb3..cc1d79d 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -1,6 +1,6 @@ [ 'body_image' => '', @@ -30,16 +30,6 @@ class Background { ], ]; - /** - * Background class constructor - * - * Adds the section and its controls to the customizer. - */ - public function __construct() { - add_action( 'customize_register', [ $this, 'customize' ], 1000 ); - add_action( 'wp_enqueue_scripts', [ $this, 'add_inline_css' ] ); - } - /** * Initializes customizer options. * @@ -257,57 +247,32 @@ private function customize_header( $wp_customize ) { } /** - * Prints a CSS property. - * - * Escapes, formats and returns a CSS property line. - * - * @param string $css_name The name of the CSS property. - * @param string $value The value of the property. - * @param bool $is_url Whether the property is an URL. Default false. - * - * @return string The CSS property line; - */ - private function print_css_property( $css_name, $value, $is_url = false ) { - if ( empty( $value ) ) { - return ''; - } - $value = $is_url ? 'url(\'' . esc_url( $value ) . '\')' : esc_attr( $value ); - return $css_name . ': ' . $value . ';'; - } - - /** - * Prints the CSS for the background settings. + * Returns the CSS for the background settings. * - * Return all the CSS properties for the background settings. + * Returns all the CSS properties for the background settings. * - * @return string CSS string. + * @return array A list of properties in selectors. */ - private function inline_css() { + protected function inline_css() { $generate_settings = wp_parse_args( get_option( 'generate_background_settings', [] ), self::DEFAULT['generate_background_settings'] ); $crdm_settings = wp_parse_args( get_option( 'crdm_basic_header', [] ), self::DEFAULT['crdm_basic_header'] ); - return "body {\n" . - $this->print_css_property( 'background-image', $generate_settings['body_image'], true ) . - $this->print_css_property( 'background-repeat', $generate_settings['body_repeat'] ) . - $this->print_css_property( 'background-size', $generate_settings['body_size'] ) . - $this->print_css_property( 'background-attachment', $generate_settings['body_attachment'] ) . - $this->print_css_property( 'background-position', $generate_settings['body_position'] ) . - "}\n.crdm_header__bg_1 {" . - $this->print_css_property( 'background-image', $crdm_settings['background'], true ) . - "}\n.crdm_header__bg_2-container-content {" . - $this->print_css_property( 'background-image', $crdm_settings['foreground'], true ) . - "}\n.crdm_header__bg_3 {" . - $this->print_css_property( 'background-image', $crdm_settings['under'], true ) . - '}'; - } - - /** - * Adds the CSS to WordPress hooks. - * - * Cretes a new stylesheet and adds all the CSS to it. - */ - public function add_inline_css() { - wp_register_style( 'crdm_customizer', false, [], CRDMBASIC_APP_VERSION ); - wp_enqueue_style( 'crdm_customizer' ); - wp_add_inline_style( 'crdm_customizer', $this->inline_css() ); + return [ + 'body' => [ + [ 'background-image', $generate_settings['body_image'], 'url' ], + [ 'background-repeat', $generate_settings['body_repeat'] ], + [ 'background-size', $generate_settings['body_size'] ], + [ 'background-attachment', $generate_settings['body_attachment'] ], + [ 'background-position', $generate_settings['body_position'] ], + ], + '.crdm_header__bg_1' => [ + [ 'background-image', $crdm_settings['background'], 'url' ], + ], + '.crdm_header__bg_2-container-content' => [ + [ 'background-image', $crdm_settings['foreground'], 'url' ], + ], + '.crdm_header__bg_3' => [ + [ 'background-image', $crdm_settings['under'], 'url' ], + ], + ]; } } diff --git a/src/php/CrdmBasic/Customizer/class-customizer-category.php b/src/php/CrdmBasic/Customizer/class-customizer-category.php new file mode 100644 index 0000000..f22ce15 --- /dev/null +++ b/src/php/CrdmBasic/Customizer/class-customizer-category.php @@ -0,0 +1,90 @@ +inline_css() as $selector => $properties ) { + $css .= $selector . " {\n"; + foreach ( $properties as $property ) { + if ( empty( $property[1] ) ) { + continue; + } + if ( isset( $property[2] ) ) { + switch ( $property[2] ) { + case 'url': + $value = 'url(\'' . esc_url( $property[1] ) . '\')'; + break; + default: + $value = esc_attr( $property[1] ); + } + } else { + $value = esc_attr( $property[1] ); + } + $css .= $property[0] . ': ' . $value . ";\n"; + } + $css .= "}\n"; + } + wp_add_inline_style( 'crdm_customizer', $css ); + } +} + +add_action( 'wp_enqueue_scripts', [ '\\CrdmBasic\\Customizer\\Customizer_Category', 'register_inline_css' ], 10 ); From 53915744f1d7e99be4f13f6742f65a85f957ab68 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Mon, 30 Sep 2019 00:30:07 +0200 Subject: [PATCH 23/38] Remade border radius to be GeneratePress-compatible --- .../Customizer/class-border-radius.php | 117 ++++++++---------- src/php/CrdmBasic/Customizer/class-init.php | 2 +- src/scss/frontend/header.scss | 1 - src/scss/frontend/navigation.scss | 14 --- src/scss/frontend/sidebar.scss | 1 - 5 files changed, 56 insertions(+), 79 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-border-radius.php b/src/php/CrdmBasic/Customizer/class-border-radius.php index b8880e6..a9edad3 100644 --- a/src/php/CrdmBasic/Customizer/class-border-radius.php +++ b/src/php/CrdmBasic/Customizer/class-border-radius.php @@ -9,87 +9,80 @@ namespace CrdmBasic\Customizer; -use Kirki; - /** * Border radius configuration * * This class sets up all the customizer options for configuring the radius of corners of the webpage elements. */ -class Border_Radius { +class Border_Radius extends Customizer_Category { + const DEFAULT = [ + 'crdm_basic_border_radius' => '', + ]; /** - * The ID of the configuration set ("crdm-basic"). + * Initializes customizer options. * - * @var string $config_id - */ - protected $config_id = ''; - /** - * The ID of the panel in which this option is displayed. + * Adds the panel, section, all the settings and controls to the WordPress customizer. * - * @var string $panel_id + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. */ - protected $panel_id = ''; - /** - * The ID of the section in which this option is displayed. - * - * @var string $section_id - */ - protected $section_id = ''; - - /** - * Border_Radius class constructor - * - * Adds the section and its controls to the customizer. - * - * @param string $config_id The ID of the configuration set ("crdm-basic"). - * @param string $panel_id The ID of the panel in which this option is displayed. - */ - public function __construct( string $config_id, string $panel_id ) { - $this->config_id = $config_id; - $this->panel_id = $panel_id; - $this->section_id = $panel_id . '_borderRadius'; + public function customize( $wp_customize ) { + $wp_customize->add_section( + 'crdm_basic_border_radius', + [ + 'capability' => 'edit_theme_options', + 'title' => __( 'Border radius', 'crdm-basic' ), + 'priority' => 25, + ] + ); - $this->init_section(); - $this->init_controls(); - } + $wp_customize->add_setting( + 'crdm_basic_border_radius', + [ + 'default' => self::DEFAULT['crdm_basic_border_radius'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + ] + ); - /** - * Initializes the section - * - * Adds the section to the customizer. - */ - protected function init_section() { - Kirki::add_section( - $this->section_id, + $wp_customize->add_control( + 'crdm_basic_border_radius', [ - 'title' => esc_attr__( 'Border radius', 'crdm-basic' ), - 'panel' => $this->panel_id, + 'type' => 'text', + 'section' => 'crdm_basic_border_radius', + 'label' => __( 'Border radius', 'crdm-basic' ), + 'description' => __( 'Including units, e. g. "10px"', 'crdm-basic' ), ] ); } /** - * Initializes the controls + * Returns the CSS for the background settings. + * + * Returns all the CSS properties for the background settings. * - * Adds all the controls to the section + * @return array A list of properties in selectors. */ - protected function init_controls() { - Kirki::add_field( - $this->config_id, - [ - 'type' => 'dimension', - 'settings' => 'borderRadius', - 'label' => esc_attr__( 'Border radius', 'crdm-basic' ), - 'description' => esc_attr__( 'Including units, e. g. "10px"', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => '0px', - 'css_vars' => [ - [ '--main-border-radius' ], - ], - 'transport' => 'auto', - ] - ); + protected function inline_css() { + $setting = get_option( 'crdm_basic_border_radius', self::DEFAULT['crdm_basic_border_radius'] ); + return [ + '.widget-area .widget' => [ + [ 'border-radius', $setting ], + ], + '.crdm_page-header_captions' => [ + [ 'border-radius', $setting ], + ], + '.main-navigation' => [ + [ 'border-radius', $setting ], + ], + '.main-navigation .main-nav ul.sub-menu li:first-child a' => [ + [ 'border-top-left-radius', $setting ], + [ 'border-top-right-radius', $setting ], + ], + '.main-navigation .main-nav ul.sub-menu li:last-child a' => [ + [ 'border-bottom-left-radius', $setting ], + [ 'border-bottom-right-radius', $setting ], + ], + ]; } - } diff --git a/src/php/CrdmBasic/Customizer/class-init.php b/src/php/CrdmBasic/Customizer/class-init.php index 0fa3371..9698c7f 100644 --- a/src/php/CrdmBasic/Customizer/class-init.php +++ b/src/php/CrdmBasic/Customizer/class-init.php @@ -69,7 +69,7 @@ protected function init_sections_and_controls() { ( new Preset() ); ( new Color_Variant( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Background() ); - ( new Border_Radius( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); + ( new Border_Radius() ); ( new Menu( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Sidebar( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Page_Header( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); diff --git a/src/scss/frontend/header.scss b/src/scss/frontend/header.scss index 0552743..d13ad17 100644 --- a/src/scss/frontend/header.scss +++ b/src/scss/frontend/header.scss @@ -70,7 +70,6 @@ min-width: 33%; padding: 0.5em 1.2em; background-color: rgba(196, 219, 122, 0.79); - border-radius: var(--main-border-radius); h1 { margin: 0 0 0.25em 0; diff --git a/src/scss/frontend/navigation.scss b/src/scss/frontend/navigation.scss index 973c917..ad27f9e 100644 --- a/src/scss/frontend/navigation.scss +++ b/src/scss/frontend/navigation.scss @@ -1,5 +1,4 @@ .main-navigation { - border-radius: var(--main-border-radius); .main-nav { @@ -51,19 +50,6 @@ ul li:first-child a { border-top-color: transparent; } - - &.sub-menu li { - - &:last-child a { - border-bottom-left-radius: var(--main-border-radius); - border-bottom-right-radius: var(--main-border-radius); - } - - &:first-child a { - border-top-left-radius: var(--main-border-radius); - border-top-right-radius: var(--main-border-radius); - } - } } } } diff --git a/src/scss/frontend/sidebar.scss b/src/scss/frontend/sidebar.scss index 83f8cac..63c791d 100644 --- a/src/scss/frontend/sidebar.scss +++ b/src/scss/frontend/sidebar.scss @@ -3,7 +3,6 @@ .widget { padding: 1em; box-shadow: 0 -5px 0 0 rgba(240, 240, 240, 0.75), 0 5px 0 0 rgba(240, 240, 240, 0.75); - border-radius: var(--main-border-radius); a, a:visited, From d356bf233508d4175dd0c4b0384bfc8355bd8e7f Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Mon, 30 Sep 2019 09:17:57 +0200 Subject: [PATCH 24/38] Setting border radius in new presets --- src/php/CrdmBasic/Customizer/class-color-variant.php | 2 -- src/php/CrdmBasic/Customizer/class-preset.php | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index 09ec8ce..20dc6ef 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -91,7 +91,6 @@ protected function init_controls() { 'preset' => [ 'light' => [ 'settings' => [ - 'borderRadius' => '0px', 'menuBg' => [ 'background-color' => '#037b8c', 'background-image' => '', @@ -145,7 +144,6 @@ protected function init_controls() { ], 'dark' => [ 'settings' => [ - 'borderRadius' => '0.5em', 'menuBg' => [ 'background-color' => '#122030', 'background-image' => '', diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index 1b81561..039b2d2 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -32,6 +32,7 @@ class Preset { 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', ], + 'crdm_basic_border_radius' => '', ], 'dark' => [ 'generate_settings' => [ @@ -49,6 +50,7 @@ class Preset { 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_header_foreground.png', 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_pavement.png', ], + 'crdm_basic_border_radius' => '0.5em', ], ]; From 2d871a66c8b2cc20ffe733d1a2c51e0039c6a27d Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Mon, 30 Sep 2019 12:31:52 +0200 Subject: [PATCH 25/38] Added dummy color configuration --- ...ass-background-image-customize-control.php | 2 +- .../class-color-customize-control.php | 45 +++++++ .../Customizer/class-border-radius.php | 2 +- src/php/CrdmBasic/Customizer/class-colors.php | 113 ++++++++++++++++++ .../Customizer/class-customizer-category.php | 2 +- src/php/CrdmBasic/Customizer/class-init.php | 1 + 6 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php create mode 100644 src/php/CrdmBasic/Customizer/class-colors.php diff --git a/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php index 2887945..49936ca 100644 --- a/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php +++ b/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php @@ -21,7 +21,7 @@ class Background_Image_Customize_Control extends \WP_Customize_Control { * * @var string */ - public $type = 'gp-background-images'; + public $type = 'crdm-basic-background-image'; /** * Exports control parameters for JS. diff --git a/src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php new file mode 100644 index 0000000..f15dcfd --- /dev/null +++ b/src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php @@ -0,0 +1,45 @@ + +GO + [ + '.widget-area .widget' => [ [ 'border-radius', $setting ], ], '.crdm_page-header_captions' => [ diff --git a/src/php/CrdmBasic/Customizer/class-colors.php b/src/php/CrdmBasic/Customizer/class-colors.php new file mode 100644 index 0000000..d6efc23 --- /dev/null +++ b/src/php/CrdmBasic/Customizer/class-colors.php @@ -0,0 +1,113 @@ + [ + 'navigation_background_color' => '#222222', + ], + ]; + + /** + * Initializes customizer options. + * + * Adds the panel, section, all the settings and controls to the WordPress customizer. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + public function customize( $wp_customize ) { + if ( ! Init::generatepress_module_enabled( 'generate_package_colors' ) ) { + $wp_customize->register_control_type( 'CrdmBasic\Customizer\Controls\Color_Customize_Control' ); + $this->add_panel_sections( $wp_customize ); + + $this->customize_primary_navigation( $wp_customize ); + } + } + + /** + * Adds the panel and sections + * + * Adds the panel and sections that would otherwise be added by GeneratePress. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function add_panel_sections( $wp_customize ) { + $wp_customize->add_panel( + 'generate_colors_panel', + [ + 'priority' => 30, + 'theme_supports' => '', + 'title' => __( 'Colors', 'crdm-basic' ), + 'description' => '', + ] + ); + + $wp_customize->add_section( + 'navigation_color_section', + [ + 'title' => __( 'Primary Navigation', 'crdm-basic' ), + 'priority' => 60, + 'panel' => 'generate_colors_panel', + ] + ); + } + + /** + * Initializes customizer options for primary navigation. + * + * Adds customizer options for controling the menu background color. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function customize_primary_navigation( $wp_customize ) { + $wp_customize->add_setting( + 'generate_settings[navigation_background_color]', + [ + 'default' => self::DEFAULT['generate_settings']['navigation_background_color'], + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => [ $this, 'sanitize_rgba' ], + ] + ); + + $wp_customize->add_control( + new Controls\Color_Customize_Control( + $wp_customize, + 'navigation_background_color_control', + [ + 'section' => 'navigation_color_section', + 'settings' => 'generate_settings[navigation_background_color]', + ] + ) + ); + } + + public function sanitize_rgba( $value ) { + // TODO. + return $value; + } + + /** + * Returns the CSS for the background settings. + * + * Returns all the CSS properties for the background settings. + * + * @return array A list of properties in selectors. + */ + protected function inline_css() { + return []; + } +} diff --git a/src/php/CrdmBasic/Customizer/class-customizer-category.php b/src/php/CrdmBasic/Customizer/class-customizer-category.php index f22ce15..8b13506 100644 --- a/src/php/CrdmBasic/Customizer/class-customizer-category.php +++ b/src/php/CrdmBasic/Customizer/class-customizer-category.php @@ -21,7 +21,7 @@ abstract class Customizer_Category { * Adds the customize function to the WordPress action. */ public function __construct() { - add_action( 'customize_register', [ $this, 'customize' ], 1000 ); + add_action( 'customize_register', [ $this, 'customize' ], 9 ); add_action( 'wp_enqueue_scripts', [ $this, 'add_inline_css' ], 11 ); } diff --git a/src/php/CrdmBasic/Customizer/class-init.php b/src/php/CrdmBasic/Customizer/class-init.php index 9698c7f..549040d 100644 --- a/src/php/CrdmBasic/Customizer/class-init.php +++ b/src/php/CrdmBasic/Customizer/class-init.php @@ -68,6 +68,7 @@ protected function init_panel() { protected function init_sections_and_controls() { ( new Preset() ); ( new Color_Variant( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); + ( new Colors() ); ( new Background() ); ( new Border_Radius() ); ( new Menu( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); From 7f36a2988cc2ef03a8012da1b5b353fdbf3bbf39 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Tue, 1 Oct 2019 01:15:55 +0200 Subject: [PATCH 26/38] Added primary navigation background color control --- .../class-color-customize-control.php | 45 ------------------- src/php/CrdmBasic/Customizer/class-colors.php | 4 +- 2 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php diff --git a/src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php deleted file mode 100644 index f15dcfd..0000000 --- a/src/php/CrdmBasic/Customizer/Controls/class-color-customize-control.php +++ /dev/null @@ -1,45 +0,0 @@ - -GO - register_control_type( 'CrdmBasic\Customizer\Controls\Color_Customize_Control' ); $this->add_panel_sections( $wp_customize ); $this->customize_primary_navigation( $wp_customize ); @@ -84,10 +83,11 @@ private function customize_primary_navigation( $wp_customize ) { ); $wp_customize->add_control( - new Controls\Color_Customize_Control( + new \WP_Customize_Color_Control( $wp_customize, 'navigation_background_color_control', [ + 'label' => __( 'Background', 'crdm-basic' ), 'section' => 'navigation_color_section', 'settings' => 'generate_settings[navigation_background_color]', ] From 4344cc79c64ca69f1194c4dc7d50b29236cc376b Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Tue, 1 Oct 2019 14:12:29 +0200 Subject: [PATCH 27/38] Controling menu background & color through GP-compatible functions --- .../CrdmBasic/Customizer/class-background.php | 76 ++++++++++++++++++- .../Customizer/class-color-variant.php | 8 -- src/php/CrdmBasic/Customizer/class-menu.php | 24 ------ src/php/CrdmBasic/Customizer/class-preset.php | 6 ++ 4 files changed, 81 insertions(+), 33 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index cc1d79d..e819f39 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -22,6 +22,8 @@ class Background extends Customizer_Category { 'body_size' => '', 'body_attachment' => '', 'body_position' => '', + 'nav_image' => '', + 'nav_repeat' => '', ], 'crdm_basic_header' => [ 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', @@ -44,6 +46,7 @@ public function customize( $wp_customize ) { $this->add_panel_sections( $wp_customize ); $this->customize_body( $wp_customize ); + $this->customize_navigation( $wp_customize ); } $this->customize_header( $wp_customize ); } @@ -81,7 +84,17 @@ private function add_panel_sections( $wp_customize ) { [ 'title' => __( 'Header', 'crdm-basic' ), 'capability' => 'edit_theme_options', - 'priority' => 5, + 'priority' => 10, + 'panel' => 'generate_backgrounds_panel', + ] + ); + + $wp_customize->add_section( + 'generate_backgrounds_navigation', + [ + 'title' => __( 'Primary Navigation', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 15, 'panel' => 'generate_backgrounds_panel', ] ); @@ -171,6 +184,63 @@ private function customize_body( $wp_customize ) { ); } + /** + * Initializes customizer navigation options. + * + * Adds customizer options for controling the background of the primary navigation. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function customize_navigation( $wp_customize ) { + $wp_customize->add_setting( + 'generate_background_settings[nav_image]', + [ + 'default' => self::DEFAULT['generate_background_settings']['nav_image'], + 'type' => 'option', + 'capability' => 'edit_theme_options', + 'sanitize_callback' => 'esc_url_raw', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Image_Control( + $wp_customize, + 'generate_backgrounds_settings[nav_image]', + [ + 'section' => 'generate_backgrounds_navigation', + 'settings' => 'generate_background_settings[nav_image]', + 'priority' => 750, + 'label' => __( 'Navigation', 'crdm-basic' ), + ] + ) + ); + + $wp_customize->add_setting( + 'generate_background_settings[nav_repeat]', + [ + 'default' => self::DEFAULT['generate_background_settings']['nav_repeat'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + ] + ); + + $wp_customize->add_control( + 'generate_background_settings[nav_repeat]', + [ + 'type' => 'select', + 'section' => 'generate_backgrounds_navigation', + 'settings' => 'generate_background_settings[nav_repeat]', + 'choices' => [ + '' => __( 'Repeat', 'crdm-basic' ), + 'repeat-x' => __( 'Repeat x', 'crdm-basic' ), + 'repeat-y' => __( 'Repeat y', 'crdm-basic' ), + 'no-repeat' => __( 'No Repeat', 'crdm-basic' ), + ], + 'priority' => 800 + ] + ); + } + /** * Initializes customizer header options. * @@ -273,6 +343,10 @@ protected function inline_css() { '.crdm_header__bg_3' => [ [ 'background-image', $crdm_settings['under'], 'url' ], ], + '.main-navigation, .menu-toggle' => [ + [ 'background-image', $generate_settings['nav_image'], 'url' ], + [ 'background-repeat', $generate_settings['nav_repeat'] ], + ], ]; } } diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index 20dc6ef..bbc2eb8 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -91,10 +91,6 @@ protected function init_controls() { 'preset' => [ 'light' => [ 'settings' => [ - 'menuBg' => [ - 'background-color' => '#037b8c', - 'background-image' => '', - ], 'menuFont' => [ 'font-family' => 'Patrick Hand', 'color' => '#efefe5', @@ -144,10 +140,6 @@ protected function init_controls() { ], 'dark' => [ 'settings' => [ - 'menuBg' => [ - 'background-color' => '#122030', - 'background-image' => '', - ], 'menuFont' => [ 'font-family' => 'Patrick Hand', 'color' => '#f2efde', diff --git a/src/php/CrdmBasic/Customizer/class-menu.php b/src/php/CrdmBasic/Customizer/class-menu.php index 85880ae..dd14398 100644 --- a/src/php/CrdmBasic/Customizer/class-menu.php +++ b/src/php/CrdmBasic/Customizer/class-menu.php @@ -75,30 +75,6 @@ protected function init_section() { * Adds all the controls to the section */ protected function init_controls() { - Kirki::add_field( - $this->config_id, - [ - 'type' => 'background', - 'settings' => 'menuBg', - 'label' => esc_attr__( 'Menu background', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'background-color' => '#037b8c', - 'background-image' => '', - 'background-repeat' => 'repeat', - 'background-position' => 'center center', - 'background-size' => 'cover', - 'background-attachment' => 'scroll', - ], - 'output' => [ - [ - 'element' => '.main-navigation, .main-navigation .main-nav ul li[class*="current-menu-"] > a, .main-navigation .main-nav ul li[class*="current-menu-"] > a:hover, .main-navigation .main-nav ul li[class*="current-menu-"].sfHover > a', - ], - ], - 'transport' => 'auto', - ] - ); - Kirki::add_field( $this->config_id, [ diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index 039b2d2..35cd87e 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -19,6 +19,7 @@ class Preset { 'light' => [ 'generate_settings' => [ 'background_color' => '#ffffff', + 'navigation_background_color' => '#037b8c', ], 'generate_background_settings' => [ 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', @@ -26,6 +27,8 @@ class Preset { 'body_size' => '', 'body_attachment' => '', 'body_position' => '', + 'nav_image' => '', + 'nav_repeat' => '', ], 'crdm_basic_header' => [ 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', @@ -37,6 +40,7 @@ class Preset { 'dark' => [ 'generate_settings' => [ 'background_color' => '#0f2b4a', + 'navigation_background_color' => '#122030', ], 'generate_background_settings' => [ 'body_image' => '', @@ -44,6 +48,8 @@ class Preset { 'body_size' => '', 'body_attachment' => '', 'body_position' => '', + 'nav_image' => '', + 'nav_repeat' => '', ], 'crdm_basic_header' => [ 'background' => '', From 23cebe9273100da0b497460420634be6e925ba7a Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 4 Oct 2019 10:01:18 +0200 Subject: [PATCH 28/38] Added color sanitization --- src/php/CrdmBasic/Customizer/class-colors.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-colors.php b/src/php/CrdmBasic/Customizer/class-colors.php index bb53e76..b01ba5b 100644 --- a/src/php/CrdmBasic/Customizer/class-colors.php +++ b/src/php/CrdmBasic/Customizer/class-colors.php @@ -78,7 +78,7 @@ private function customize_primary_navigation( $wp_customize ) { 'default' => self::DEFAULT['generate_settings']['navigation_background_color'], 'type' => 'option', 'transport' => 'postMessage', - 'sanitize_callback' => [ $this, 'sanitize_rgba' ], + 'sanitize_callback' => [ $this, 'sanitize_hex' ], ] ); @@ -95,9 +95,11 @@ private function customize_primary_navigation( $wp_customize ) { ); } - public function sanitize_rgba( $value ) { - // TODO. - return $value; + public function sanitize_hex( $value ) { + if ( mb_ereg_match( '^#([a-fA-F0-9]{3}){1,2}$', $value ) ) { + return $value; + } + return ''; } /** From 38c5a7824d14d603bea5906bc0bbe78469c62d73 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Wed, 23 Oct 2019 13:22:52 +0200 Subject: [PATCH 29/38] Fixed a missing switch case --- src/php/CrdmBasic/Customizer/class-init.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-init.php b/src/php/CrdmBasic/Customizer/class-init.php index 549040d..c204a40 100644 --- a/src/php/CrdmBasic/Customizer/class-init.php +++ b/src/php/CrdmBasic/Customizer/class-init.php @@ -67,10 +67,10 @@ protected function init_panel() { */ protected function init_sections_and_controls() { ( new Preset() ); - ( new Color_Variant( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); + ( new Border_Radius() ); ( new Colors() ); ( new Background() ); - ( new Border_Radius() ); + ( new Color_Variant( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Menu( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Sidebar( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Page_Header( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); @@ -79,7 +79,7 @@ protected function init_sections_and_controls() { } /** - * Checks for GeneratePress module + * Checks for a GeneratePress module * * Checks whether GeneratePress premium is installed and a module is enabled. * @@ -95,6 +95,9 @@ public static function generatepress_module_enabled( $module ) { case 'generate_package_backgrounds': $definition = 'GENERATE_BACKGROUNDS'; break; + case 'generate_package_colors': + $definition = 'GENERATE_COLORS'; + break; default: return false; } From f3bd9955427322786820114e4417cae097d1c0c4 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Wed, 23 Oct 2019 15:55:38 +0200 Subject: [PATCH 30/38] Lint fixes --- src/php/CrdmBasic/Customizer/class-background.php | 6 +++--- src/php/CrdmBasic/Customizer/class-colors.php | 15 ++++++++++++--- src/php/CrdmBasic/Customizer/class-preset.php | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index e819f39..64a7cc7 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -22,8 +22,8 @@ class Background extends Customizer_Category { 'body_size' => '', 'body_attachment' => '', 'body_position' => '', - 'nav_image' => '', - 'nav_repeat' => '', + 'nav_image' => '', + 'nav_repeat' => '', ], 'crdm_basic_header' => [ 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', @@ -236,7 +236,7 @@ private function customize_navigation( $wp_customize ) { 'repeat-y' => __( 'Repeat y', 'crdm-basic' ), 'no-repeat' => __( 'No Repeat', 'crdm-basic' ), ], - 'priority' => 800 + 'priority' => 800, ] ); } diff --git a/src/php/CrdmBasic/Customizer/class-colors.php b/src/php/CrdmBasic/Customizer/class-colors.php index b01ba5b..0e1d9ab 100644 --- a/src/php/CrdmBasic/Customizer/class-colors.php +++ b/src/php/CrdmBasic/Customizer/class-colors.php @@ -95,11 +95,20 @@ private function customize_primary_navigation( $wp_customize ) { ); } + /** + * Sanitizes a color. + * + * Checks whether a color is a valid hex code. + * + * @param string $value The value to be checked. + * + * @return string Hex code or empty string. + */ public function sanitize_hex( $value ) { - if ( mb_ereg_match( '^#([a-fA-F0-9]{3}){1,2}$', $value ) ) { - return $value; + if ( mb_ereg_match( '^#([a-fA-F0-9]{3}){1,2}$', $value ) ) { + return $value; } - return ''; + return ''; } /** diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index 35cd87e..a08fa4e 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -18,7 +18,7 @@ class Preset { const PRESETS = [ 'light' => [ 'generate_settings' => [ - 'background_color' => '#ffffff', + 'background_color' => '#ffffff', 'navigation_background_color' => '#037b8c', ], 'generate_background_settings' => [ @@ -39,7 +39,7 @@ class Preset { ], 'dark' => [ 'generate_settings' => [ - 'background_color' => '#0f2b4a', + 'background_color' => '#0f2b4a', 'navigation_background_color' => '#122030', ], 'generate_background_settings' => [ From 17b97ff8baa0805d0422ffd190acb4e1ced10fcd Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Wed, 23 Oct 2019 16:13:43 +0200 Subject: [PATCH 31/38] Converted content font --- .../Customizer/class-color-variant.php | 8 - .../CrdmBasic/Customizer/class-content.php | 24 -- src/php/CrdmBasic/Customizer/class-init.php | 1 + src/php/CrdmBasic/Customizer/class-preset.php | 18 ++ .../CrdmBasic/Customizer/class-typography.php | 298 ++++++++++++++++++ src/php/disable-gp-functions.php | 17 + src/php/functions.php | 2 + webpack.config.js | 3 + 8 files changed, 339 insertions(+), 32 deletions(-) create mode 100644 src/php/CrdmBasic/Customizer/class-typography.php create mode 100644 src/php/disable-gp-functions.php diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index bbc2eb8..b0d0d79 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -105,10 +105,6 @@ protected function init_controls() { 'color' => '#ffffff', ], 'submenuSeparatorColor' => '#ffffff', - 'contentFont' => [ - 'font-family' => 'PT Sans', - 'color' => '#3f3f3f', - ], 'contentH1Font' => [ 'font-family' => 'PT Sans', 'color' => '#037b8c', @@ -154,10 +150,6 @@ protected function init_controls() { 'color' => '#5aa4cc', ], 'submenuSeparatorColor' => '#0f2b4a', - 'contentFont' => [ - 'font-family' => 'PT Sans', - 'color' => '#ebebeb', - ], 'contentH1Font' => [ 'font-family' => 'PT Sans', 'color' => '#7adff1', diff --git a/src/php/CrdmBasic/Customizer/class-content.php b/src/php/CrdmBasic/Customizer/class-content.php index c88619e..457d850 100644 --- a/src/php/CrdmBasic/Customizer/class-content.php +++ b/src/php/CrdmBasic/Customizer/class-content.php @@ -112,30 +112,6 @@ protected function init_controls() { ] ); - Kirki::add_field( - $this->config_id, - [ - 'type' => 'typography', - 'settings' => 'contentFont', - 'label' => esc_attr__( 'Body', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'font-family' => 'PT Sans', - 'variant' => 'regular', - 'font-size' => '17px', - 'line-height' => '1.4', - 'letter-spacing' => 'inherit', - 'color' => '#3f3f3f', - ], - 'output' => [ - [ - 'element' => 'body .site-main', - ], - ], - 'transport' => 'auto', - ] - ); - Kirki::add_field( $this->config_id, [ diff --git a/src/php/CrdmBasic/Customizer/class-init.php b/src/php/CrdmBasic/Customizer/class-init.php index c204a40..aac2d1c 100644 --- a/src/php/CrdmBasic/Customizer/class-init.php +++ b/src/php/CrdmBasic/Customizer/class-init.php @@ -69,6 +69,7 @@ protected function init_sections_and_controls() { ( new Preset() ); ( new Border_Radius() ); ( new Colors() ); + ( new Typography() ); ( new Background() ); ( new Color_Variant( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); ( new Menu( self::CONFIG_ID, self::CONFIG_ID . '_theme' ) ); diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index a08fa4e..6808cba 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -20,6 +20,13 @@ class Preset { 'generate_settings' => [ 'background_color' => '#ffffff', 'navigation_background_color' => '#037b8c', + 'font_body' => 'PT Sans', + 'body_font_weight' => 'normal', + 'body_font_transform' => 'none', + 'body_font_size' => '17', + 'body_line_height' => '1.4', + 'paragraph_margin' => '1.5', + 'text_color' => '#3f3f3f', ], 'generate_background_settings' => [ 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', @@ -35,12 +42,21 @@ class Preset { 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', ], + 'font_body_variants' => 'regular', + 'font_body_category' => '', 'crdm_basic_border_radius' => '', ], 'dark' => [ 'generate_settings' => [ 'background_color' => '#0f2b4a', 'navigation_background_color' => '#122030', + 'font_body' => 'PT Sans', + 'body_font_weight' => 'normal', + 'body_font_transform' => 'none', + 'body_font_size' => '17', + 'body_line_height' => '1.4', + 'paragraph_margin' => '1.5', + 'text_color' => '#ebebeb', ], 'generate_background_settings' => [ 'body_image' => '', @@ -56,6 +72,8 @@ class Preset { 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_header_foreground.png', 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_pavement.png', ], + 'font_body_variants' => 'regular', + 'font_body_category' => '', 'crdm_basic_border_radius' => '0.5em', ], ]; diff --git a/src/php/CrdmBasic/Customizer/class-typography.php b/src/php/CrdmBasic/Customizer/class-typography.php new file mode 100644 index 0000000..0e05c26 --- /dev/null +++ b/src/php/CrdmBasic/Customizer/class-typography.php @@ -0,0 +1,298 @@ + [ + 'font_body' => 'System Stack', + 'body_font_weight' => 'normal', + 'body_font_transform' => 'none', + 'body_font_size' => '17', + 'body_line_height' => '1.5', + 'paragraph_margin' => '1.5', + ], + 'font_body_variants' => '', + 'font_body_category' => '', + ]; + + /** + * Initializes customizer options. + * + * Adds the panel, section, all the settings and controls to the WordPress customizer. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + public function customize( $wp_customize ) { + if ( ! Init::generatepress_module_enabled( 'generate_package_colors' ) ) { + $wp_customize->register_control_type( 'Generate_Typography_Customize_Control' ); + $wp_customize->register_control_type( 'Generate_Range_Slider_Control' ); + $this->add_panel_sections( $wp_customize ); + + $this->customize_body( $wp_customize ); + } + } + + /** + * Adds the panel and sections + * + * Adds the panel and sections that would otherwise be added by GeneratePress. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function add_panel_sections( $wp_customize ) { + $wp_customize->add_panel( + 'generate_typography_panel', + [ + 'capability' => 'edit_theme_options', + 'theme_supports' => '', + 'title' => __( 'Typography', 'crdm-basic' ), + 'priority' => 30, + ] + ); + + $wp_customize->add_section( + 'font_section', + [ + 'title' => __( 'Body', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 30, + 'panel' => 'generate_typography_panel', + ] + ); + } + + /** + * Initializes customizer options for body. + * + * Adds customizer options for controling the body typography. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function customize_body( $wp_customize ) { + // Family. + $wp_customize->add_setting( + 'generate_settings[font_body]', + [ + 'default' => self::DEFAULT['generate_settings']['font_body'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Variants. + $wp_customize->add_setting( + 'font_body_variants', + [ + 'default' => self::DEFAULT['font_body_variants'], + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], + ] + ); + + // Category. + $wp_customize->add_setting( + 'font_body_category', + [ + 'default' => self::DEFAULT['font_body_category'], + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Font weight. + $wp_customize->add_setting( + 'generate_settings[body_font_weight]', + [ + 'default' => self::DEFAULT['generate_settings']['body_font_weight'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + // Transform. + $wp_customize->add_setting( + 'generate_settings[body_font_transform]', + [ + 'default' => self::DEFAULT['generate_settings']['body_font_transform'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Typography_Customize_Control( + $wp_customize, + 'body_typography', + [ + 'section' => 'font_section', + 'priority' => 1, + 'settings' => [ + 'family' => 'generate_settings[font_body]', + 'variant' => 'font_body_variants', + 'category' => 'font_body_category', + 'weight' => 'generate_settings[body_font_weight]', + 'transform' => 'generate_settings[body_font_transform]', + ], + ] + ) + ); + + // Size. + $wp_customize->add_setting( + 'generate_settings[body_font_size]', + [ + 'default' => self::DEFAULT['generate_settings']['body_font_size'], + 'type' => 'option', + 'sanitize_callback' => 'absint', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[body_font_size]', + [ + 'description' => __( 'Font size', 'crdm-basic' ), + 'section' => 'font_section', + 'priority' => 40, + 'settings' => [ + 'desktop' => 'generate_settings[body_font_size]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 6, + 'max' => 25, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + ], + ] + ) + ); + + // Line height. + $wp_customize->add_setting( + 'generate_settings[body_line_height]', + [ + 'default' => self::DEFAULT['generate_settings']['body_line_height'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[body_line_height]', + [ + 'description' => __( 'Line height', 'crdm-basic' ), + 'section' => 'font_section', + 'priority' => 45, + 'settings' => [ + 'desktop' => 'generate_settings[body_line_height]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 1, + 'max' => 5, + 'step' => .1, + 'edit' => true, + 'unit' => '', + ], + ], + ] + ) + ); + + // Paragraph margin. + $wp_customize->add_setting( + 'generate_settings[paragraph_margin]', + [ + 'default' => self::DEFAULT['generate_settings']['paragraph_margin'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[paragraph_margin]', + [ + 'description' => __( 'Paragraph margin', 'crdm-basic' ), + 'section' => 'font_section', + 'priority' => 47, + 'settings' => [ + 'desktop' => 'generate_settings[paragraph_margin]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 0, + 'max' => 5, + 'step' => .1, + 'edit' => true, + 'unit' => 'em', + ], + ], + ] + ) + ); + } + + /** + * Sanitizes a decimal number. + * + * Converts a string representation of a number into a non-negative float. + * + * @param string $value The value to be sanitized. + * + * @return float The float value. + */ + public static function sanitize_decimal_number( $value ) { + return abs( floatval( $value ) ); + } + + /** + * Sanitizes font variants. + * + * Converts a list of font variants into a variant string. + * + * @param string|array $value The value to be sanitized. + * + * @return float The variant string. + */ + public static function sanitize_variants( $value ) { + if ( is_array( $value ) ) { + $value = implode( ',', $value ); + } + return sanitize_text_field( $value ); + } + + /** + * Returns the CSS for the background settings. + * + * Returns all the CSS properties for the background settings. + * + * @return array A list of properties in selectors. + */ + protected function inline_css() { + return []; + } +} diff --git a/src/php/disable-gp-functions.php b/src/php/disable-gp-functions.php new file mode 100644 index 0000000..bbcd2ee --- /dev/null +++ b/src/php/disable-gp-functions.php @@ -0,0 +1,17 @@ + Date: Wed, 23 Oct 2019 22:46:03 +0200 Subject: [PATCH 32/38] Removed SCSS overrides to GP --- src/scss/frontend/content.scss | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/scss/frontend/content.scss b/src/scss/frontend/content.scss index 369085f..00882ac 100644 --- a/src/scss/frontend/content.scss +++ b/src/scss/frontend/content.scss @@ -1,5 +1,4 @@ body { - font-family: "PT Sans", sans-serif; grid-column-gap: 50px; grid-template-rows: 100px 1fr; } @@ -20,12 +19,6 @@ body { background-color: #fff; } - .entry-content, - .entry-summary, - .page-content { - line-height: 1.4; - } - h1 { font-size: 2.3em; font-weight: 700; From 720447b9738ce6eb5b738ed3484edc2457ec90f3 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Thu, 24 Oct 2019 21:48:20 +0200 Subject: [PATCH 33/38] Converted menu font --- src/js/admin/typography_live_preview.js | 8 + .../Customizer/class-color-variant.php | 8 - src/php/CrdmBasic/Customizer/class-colors.php | 25 +++ src/php/CrdmBasic/Customizer/class-menu.php | 30 --- src/php/CrdmBasic/Customizer/class-preset.php | 16 ++ .../CrdmBasic/Customizer/class-typography.php | 211 +++++++++++++++++- src/scss/frontend/navigation.scss | 21 +- webpack.config.js | 3 +- 8 files changed, 261 insertions(+), 61 deletions(-) create mode 100644 src/js/admin/typography_live_preview.js diff --git a/src/js/admin/typography_live_preview.js b/src/js/admin/typography_live_preview.js new file mode 100644 index 0000000..ad2ba94 --- /dev/null +++ b/src/js/admin/typography_live_preview.js @@ -0,0 +1,8 @@ +'use strict'; + +jQuery( 'document' ).ready( function( $ ) { + generatepress_typography_live_update( 'navigation_font_size', '.main-navigation a, .menu-toggle', 'font-size', 'px', crdm_typography_live_preview.desktop ); + generatepress_typography_live_update( 'mobile_navigation_font_size', '.main-navigation:not(.slideout-navigation) a, .menu-toggle', 'font-size', 'px', crdm_typography_live_preview.mobile ); + generatepress_typography_live_update( 'navigation_font_weight', '.main-navigation a, .menu-toggle', 'font-weight' ); + generatepress_typography_live_update( 'navigation_font_transform', '.main-navigation a, .menu-toggle', 'text-transform' ); +}); diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index b0d0d79..5487a81 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -91,10 +91,6 @@ protected function init_controls() { 'preset' => [ 'light' => [ 'settings' => [ - 'menuFont' => [ - 'font-family' => 'Patrick Hand', - 'color' => '#efefe5', - ], 'menuSeparatorColor' => '#3b969f', 'submenuBg' => [ 'background-color' => '#65c3d4', @@ -136,10 +132,6 @@ protected function init_controls() { ], 'dark' => [ 'settings' => [ - 'menuFont' => [ - 'font-family' => 'Patrick Hand', - 'color' => '#f2efde', - ], 'menuSeparatorColor' => '#465058', 'submenuBg' => [ 'background-color' => '#122030', diff --git a/src/php/CrdmBasic/Customizer/class-colors.php b/src/php/CrdmBasic/Customizer/class-colors.php index 0e1d9ab..efea5c4 100644 --- a/src/php/CrdmBasic/Customizer/class-colors.php +++ b/src/php/CrdmBasic/Customizer/class-colors.php @@ -18,6 +18,7 @@ class Colors extends Customizer_Category { const DEFAULT = [ 'generate_settings' => [ 'navigation_background_color' => '#222222', + 'navigation_text_color' => '#ffffff', ], ]; @@ -90,6 +91,30 @@ private function customize_primary_navigation( $wp_customize ) { 'label' => __( 'Background', 'crdm-basic' ), 'section' => 'navigation_color_section', 'settings' => 'generate_settings[navigation_background_color]', + 'priority' => '1', + ] + ) + ); + + $wp_customize->add_setting( + 'generate_settings[navigation_text_color]', + [ + 'default' => self::DEFAULT['generate_settings']['navigation_text_color'], + 'type' => 'option', + 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Color_Control( + $wp_customize, + 'navigation_text_color', + [ + 'label' => __( 'Text', 'crdm-basic' ), + 'section' => 'navigation_color_section', + 'settings' => 'generate_settings[navigation_text_color]', + 'priority' => '2', ] ) ); diff --git a/src/php/CrdmBasic/Customizer/class-menu.php b/src/php/CrdmBasic/Customizer/class-menu.php index dd14398..c5caa4d 100644 --- a/src/php/CrdmBasic/Customizer/class-menu.php +++ b/src/php/CrdmBasic/Customizer/class-menu.php @@ -75,36 +75,6 @@ protected function init_section() { * Adds all the controls to the section */ protected function init_controls() { - Kirki::add_field( - $this->config_id, - [ - 'type' => 'typography', - 'settings' => 'menuFont', - 'label' => esc_attr__( 'Menu items', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'font-family' => 'Patrick Hand', - 'variant' => 'regular', - 'font-size' => '16px', - 'line-height' => '37px', - 'letter-spacing' => 'inherit', - 'color' => '#efefe5', - 'text-transform' => 'none', - ], - 'output' => [ - [ - 'element' => '.main-navigation .main-nav > ul > li > a, .main-navigation .main-nav ul li[class*="current-menu-"] > a, .main-navigation .main-nav ul li[class*="current-menu-"] > a:hover, .main-navigation .main-nav ul li[class*="current-menu-"].sfHover > a', - ], - [ - 'choice' => 'color', - 'element' => '.dropdown-menu-toggle:before', - 'property' => 'color', - ], - ], - 'transport' => 'auto', - ] - ); - Kirki::add_field( $this->config_id, [ diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index 6808cba..5deb0e1 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -20,6 +20,7 @@ class Preset { 'generate_settings' => [ 'background_color' => '#ffffff', 'navigation_background_color' => '#037b8c', + 'navigation_text_color' => '#efefe5', 'font_body' => 'PT Sans', 'body_font_weight' => 'normal', 'body_font_transform' => 'none', @@ -27,6 +28,11 @@ class Preset { 'body_line_height' => '1.4', 'paragraph_margin' => '1.5', 'text_color' => '#3f3f3f', + 'font_navigation' => 'Patrick Hand', + 'navigation_font_weight' => 'normal', + 'navigation_font_transform' => 'none', + 'navigation_font_size' => '16', + 'mobile_navigation_font_size' => '', ], 'generate_background_settings' => [ 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', @@ -44,12 +50,15 @@ class Preset { ], 'font_body_variants' => 'regular', 'font_body_category' => '', + 'font_navigation_variants' => 'regular', + 'font_navigation_category' => '', 'crdm_basic_border_radius' => '', ], 'dark' => [ 'generate_settings' => [ 'background_color' => '#0f2b4a', 'navigation_background_color' => '#122030', + 'navigation_text_color' => '#f2efde', 'font_body' => 'PT Sans', 'body_font_weight' => 'normal', 'body_font_transform' => 'none', @@ -57,6 +66,11 @@ class Preset { 'body_line_height' => '1.4', 'paragraph_margin' => '1.5', 'text_color' => '#ebebeb', + 'font_navigation' => 'Patrick Hand', + 'navigation_font_weight' => 'normal', + 'navigation_font_transform' => 'none', + 'navigation_font_size' => '16', + 'mobile_navigation_font_size' => '', ], 'generate_background_settings' => [ 'body_image' => '', @@ -74,6 +88,8 @@ class Preset { ], 'font_body_variants' => 'regular', 'font_body_category' => '', + 'font_navigation_variants' => 'regular', + 'font_navigation_category' => '', 'crdm_basic_border_radius' => '0.5em', ], ]; diff --git a/src/php/CrdmBasic/Customizer/class-typography.php b/src/php/CrdmBasic/Customizer/class-typography.php index 0e05c26..de17de3 100644 --- a/src/php/CrdmBasic/Customizer/class-typography.php +++ b/src/php/CrdmBasic/Customizer/class-typography.php @@ -16,18 +16,53 @@ */ class Typography extends Customizer_Category { const DEFAULT = [ - 'generate_settings' => [ - 'font_body' => 'System Stack', - 'body_font_weight' => 'normal', - 'body_font_transform' => 'none', - 'body_font_size' => '17', - 'body_line_height' => '1.5', - 'paragraph_margin' => '1.5', + 'generate_settings' => [ + 'font_body' => 'System Stack', + 'body_font_weight' => 'normal', + 'body_font_transform' => 'none', + 'body_font_size' => '17', + 'body_line_height' => '1.5', + 'paragraph_margin' => '1.5', + 'font_navigation' => 'inherit', + 'navigation_font_weight' => 'normal', + 'navigation_font_transform' => 'none', + 'navigation_font_size' => '15', + 'mobile_navigation_font_size' => '15', ], - 'font_body_variants' => '', - 'font_body_category' => '', + 'font_body_variants' => '', + 'font_body_category' => '', + 'font_navigation_variants' => '', + 'font_navigation_category' => '', ]; + /** + * Typography class constructor + * + * Adds the customize function to the WordPress action and registers the JS. + */ + public function __construct() { + parent::__construct(); + add_action( 'customize_preview_init', [ $this, 'enqueue_live_preview' ], 101 ); + } + + /** + * Enqueues the JS. + * + * Enqueues the live-preview JS handlers. + */ + public function enqueue_live_preview() { + wp_enqueue_script( 'crdm_typography_live_preview', CRDMBASIC_TEMPLATE_URL . 'admin/typography_live_preview.js', [ ], CRDMBASIC_APP_VERSION ); + + wp_localize_script( + 'crdm_typography_live_preview', + 'crdm_typography_live_preview', + [ + 'mobile' => apply_filters( 'generate_mobile_media_query', '(max-width:768px)' ), + 'desktop' => apply_filters( 'generate_desktop_media_query', '(min-width:1025px)' ), + ] + ); + } + /** * Initializes customizer options. * @@ -42,6 +77,7 @@ public function customize( $wp_customize ) { $this->add_panel_sections( $wp_customize ); $this->customize_body( $wp_customize ); + $this->customize_primary_navigation( $wp_customize ); } } @@ -72,6 +108,16 @@ private function add_panel_sections( $wp_customize ) { 'panel' => 'generate_typography_panel', ] ); + + $wp_customize->add_section( + 'font_navigation_section', + [ + 'title' => __( 'Primary Navigation', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 50, + 'panel' => 'generate_typography_panel', + ] + ); } /** @@ -256,6 +302,136 @@ private function customize_body( $wp_customize ) { ); } + /** + * Initializes customizer options for primary navigation. + * + * Adds customizer options for controling the primary navigation typography. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function customize_primary_navigation( $wp_customize ) { + // Family. + $wp_customize->add_setting( + 'generate_settings[font_navigation]', + [ + 'default' => self::DEFAULT['generate_settings']['font_navigation'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Variants. + $wp_customize->add_setting( + 'font_navigation_variants', + [ + 'default' => self::DEFAULT['font_navigation_variants'], + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], + ] + ); + + // Category. + $wp_customize->add_setting( + 'font_navigation_category', + [ + 'default' => self::DEFAULT['font_navigation_category'], + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Weight. + $wp_customize->add_setting( + 'generate_settings[navigation_font_weight]', + [ + 'default' => self::DEFAULT['generate_settings']['navigation_font_weight'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + // Transform. + $wp_customize->add_setting( + 'generate_settings[navigation_font_transform]', + [ + 'default' => self::DEFAULT['generate_settings']['navigation_font_transform'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Typography_Customize_Control( + $wp_customize, + 'google_font_site_navigation_control', + [ + 'section' => 'font_navigation_section', + 'priority' => 120, + 'settings' => [ + 'family' => 'generate_settings[font_navigation]', + 'variant' => 'font_navigation_variants', + 'category' => 'font_navigation_category', + 'weight' => 'generate_settings[navigation_font_weight]', + 'transform' => 'generate_settings[navigation_font_transform]', + ], + ] + ) + ); + + // Size. + $wp_customize->add_setting( + 'generate_settings[navigation_font_size]', + [ + 'default' => self::DEFAULT['generate_settings']['navigation_font_size'], + 'type' => 'option', + 'sanitize_callback' => 'absint', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_setting( + 'generate_settings[mobile_navigation_font_size]', + [ + 'default' => self::DEFAULT['generate_settings']['mobile_navigation_font_size'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[navigation_font_size]', + [ + 'description' => __( 'Font size', 'crdm-basic' ), + 'section' => 'font_navigation_section', + 'priority' => 165, + 'settings' => [ + 'desktop' => 'generate_settings[navigation_font_size]', + 'mobile' => 'generate_settings[mobile_navigation_font_size]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 6, + 'max' => 30, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + 'mobile' => [ + 'min' => 6, + 'max' => 30, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + ], + ] + ) + ); + } + /** * Sanitizes a decimal number. * @@ -285,6 +461,23 @@ public static function sanitize_variants( $value ) { return sanitize_text_field( $value ); } + /** + * Sanitizes a non-negative integer. + * + * Converts a string representation of a number into a non-negative integer. Optionally keeps empty string as an empty string + * + * @param string $value The value to be sanitized. + * + * @return string|int The integer value. + */ + public static function sanitize_empty_absint( $value ) { + if ( '' === $value ) { + return ''; + } + return absint( $value ); + } + + /** * Returns the CSS for the background settings. * diff --git a/src/scss/frontend/navigation.scss b/src/scss/frontend/navigation.scss index ad27f9e..dd4df59 100644 --- a/src/scss/frontend/navigation.scss +++ b/src/scss/frontend/navigation.scss @@ -6,18 +6,14 @@ position: relative; z-index: 2; - & > li > a { - font-family: "Patrick Hand", cursive; - - &::after { - content: ""; - position: absolute; - left: 100%; - top: 20%; - bottom: 20%; - width: 1px; - z-index: 1; - } + & > li > a::after { + content: ""; + position: absolute; + left: 100%; + top: 20%; + bottom: 20%; + width: 1px; + z-index: 1; } } @@ -25,7 +21,6 @@ li a { position: relative; - font-size: 16px; line-height: 37px; } diff --git a/webpack.config.js b/webpack.config.js index fe2e979..4e14321 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -37,7 +37,8 @@ module.exports = { mode: 'production', entry: { 'frontend/index': './src/js/frontend/index.js', - 'admin/preset_customize_control': './src/js/admin/preset_customize_control.js' + 'admin/preset_customize_control': './src/js/admin/preset_customize_control.js', + 'admin/typography_live_preview': './src/js/admin/typography_live_preview.js' }, output: { filename: '[name].js', From 616888672bbe5fa2cb92753b09df80fcb6bf48a6 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Thu, 24 Oct 2019 22:06:38 +0200 Subject: [PATCH 34/38] Fixed lint issues --- .../class-generate-range-slider-control.php | 6 ++++++ .../class-generate-typography-customize-control.php | 6 ++++++ .../WordPress/class-wp-customize-color-control.php | 6 ++++++ .phan/stubs/WordPress/functions.php | 8 ++++++++ src/js/admin/typography_live_preview.js | 4 ++-- src/php/CrdmBasic/Customizer/class-typography.php | 10 ++++++---- 6 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 .phan/stubs/GeneratePress/class-generate-range-slider-control.php create mode 100644 .phan/stubs/GeneratePress/class-generate-typography-customize-control.php create mode 100644 .phan/stubs/WordPress/class-wp-customize-color-control.php diff --git a/.phan/stubs/GeneratePress/class-generate-range-slider-control.php b/.phan/stubs/GeneratePress/class-generate-range-slider-control.php new file mode 100644 index 0000000..7d83b6f --- /dev/null +++ b/.phan/stubs/GeneratePress/class-generate-range-slider-control.php @@ -0,0 +1,6 @@ + apply_filters( 'generate_mobile_media_query', '(max-width:768px)' ), + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + 'mobile' => apply_filters( 'generate_mobile_media_query', '(max-width:768px)' ), + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 'desktop' => apply_filters( 'generate_desktop_media_query', '(min-width:1025px)' ), ] ); @@ -452,7 +454,7 @@ public static function sanitize_decimal_number( $value ) { * * @param string|array $value The value to be sanitized. * - * @return float The variant string. + * @return string The variant string. */ public static function sanitize_variants( $value ) { if ( is_array( $value ) ) { From 7c6270d8b8ef0f718d22624d03286738a1278efe Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Thu, 24 Oct 2019 23:33:11 +0200 Subject: [PATCH 35/38] Converted H1 font --- src/js/admin/colors_live_preview.js | 5 + src/js/admin/typography_live_preview.js | 7 + .../Customizer/class-color-variant.php | 8 - src/php/CrdmBasic/Customizer/class-colors.php | 54 ++++- .../CrdmBasic/Customizer/class-content.php | 26 -- .../Customizer/class-customizer-category.php | 8 + src/php/CrdmBasic/Customizer/class-preset.php | 20 ++ .../CrdmBasic/Customizer/class-typography.php | 228 +++++++++++++++++- src/scss/frontend/content.scss | 7 - webpack.config.js | 1 + 10 files changed, 311 insertions(+), 53 deletions(-) create mode 100644 src/js/admin/colors_live_preview.js diff --git a/src/js/admin/colors_live_preview.js b/src/js/admin/colors_live_preview.js new file mode 100644 index 0000000..11a3520 --- /dev/null +++ b/src/js/admin/colors_live_preview.js @@ -0,0 +1,5 @@ +'use strict'; + +jQuery( 'document' ).ready( function( $ ) { + generatepress_colors_live_update( 'h1_color', 'h1', 'color', '', 'text_color' ); +}); diff --git a/src/js/admin/typography_live_preview.js b/src/js/admin/typography_live_preview.js index 32877bf..bdd979a 100644 --- a/src/js/admin/typography_live_preview.js +++ b/src/js/admin/typography_live_preview.js @@ -5,4 +5,11 @@ jQuery( 'document' ).ready( function( $ ) { generatepress_typography_live_update( 'mobile_navigation_font_size', '.main-navigation:not(.slideout-navigation) a, .menu-toggle', 'font-size', 'px', crdmTypographyLivePreview.mobile ); generatepress_typography_live_update( 'navigation_font_weight', '.main-navigation a, .menu-toggle', 'font-weight' ); generatepress_typography_live_update( 'navigation_font_transform', '.main-navigation a, .menu-toggle', 'text-transform' ); + + generatepress_typography_live_update( 'heading_1_font_size', 'h1', 'font-size', 'px', crdmTypographyLivePreview.desktop ); + generatepress_typography_live_update( 'mobile_heading_1_font_size', 'h1', 'font-size', 'px', crdmTypographyLivePreview.mobile ); + generatepress_typography_live_update( 'heading_1_weight', 'h1', 'font-weight' ); + generatepress_typography_live_update( 'heading_1_transform', 'h1', 'text-transform' ); + generatepress_typography_live_update( 'heading_1_line_height', 'h1', 'line-height', 'em' ); + generatepress_typography_live_update( 'heading_1_margin_bottom', 'h1', 'margin-bottom', 'px' ); }); diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index 5487a81..57e6a05 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -101,10 +101,6 @@ protected function init_controls() { 'color' => '#ffffff', ], 'submenuSeparatorColor' => '#ffffff', - 'contentH1Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#037b8c', - ], 'contentH2Font' => [ 'font-family' => 'PT Sans', 'color' => '#037b8c', @@ -142,10 +138,6 @@ protected function init_controls() { 'color' => '#5aa4cc', ], 'submenuSeparatorColor' => '#0f2b4a', - 'contentH1Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#7adff1', - ], 'contentH2Font' => [ 'font-family' => 'PT Sans', 'color' => '#7adff1', diff --git a/src/php/CrdmBasic/Customizer/class-colors.php b/src/php/CrdmBasic/Customizer/class-colors.php index efea5c4..605e003 100644 --- a/src/php/CrdmBasic/Customizer/class-colors.php +++ b/src/php/CrdmBasic/Customizer/class-colors.php @@ -19,9 +19,19 @@ class Colors extends Customizer_Category { 'generate_settings' => [ 'navigation_background_color' => '#222222', 'navigation_text_color' => '#ffffff', + 'h1_color' => '', ], ]; + /** + * Enqueues the JS. + * + * Enqueues the live-preview JS handlers. + */ + public function enqueue_live_preview() { + wp_enqueue_script( 'crdm_colors_live_preview', CRDMBASIC_TEMPLATE_URL . 'admin/colors_live_preview.js', [], CRDMBASIC_APP_VERSION, false ); + } + /** * Initializes customizer options. * @@ -34,6 +44,7 @@ public function customize( $wp_customize ) { $this->add_panel_sections( $wp_customize ); $this->customize_primary_navigation( $wp_customize ); + $this->customize_content( $wp_customize ); } } @@ -63,6 +74,15 @@ private function add_panel_sections( $wp_customize ) { 'panel' => 'generate_colors_panel', ] ); + + $wp_customize->add_section( + 'content_color_section', + [ + 'title' => __( 'Content', 'crdm-basic' ), + 'priority' => 80, + 'panel' => 'generate_colors_panel', + ] + ); } /** @@ -78,8 +98,8 @@ private function customize_primary_navigation( $wp_customize ) { [ 'default' => self::DEFAULT['generate_settings']['navigation_background_color'], 'type' => 'option', - 'transport' => 'postMessage', 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'transport' => 'postMessage', ] ); @@ -120,6 +140,38 @@ private function customize_primary_navigation( $wp_customize ) { ); } + /** + * Initializes customizer options for heading. + * + * Adds customizer options for controling heading text color. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + private function customize_content( $wp_customize ) { + $wp_customize->add_setting( + 'generate_settings[h1_color]', + [ + 'default' => self::DEFAULT['generate_settings']['h1_color'], + 'type' => 'option', + 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Color_Control( + $wp_customize, + 'h1_color', + [ + 'label' => __( 'Heading 1 (H1) Color', 'crdm-basic' ), + 'section' => 'content_color_section', + 'settings' => 'generate_settings[h1_color]', + 'priority' => '11', + ] + ) + ); + } + /** * Sanitizes a color. * diff --git a/src/php/CrdmBasic/Customizer/class-content.php b/src/php/CrdmBasic/Customizer/class-content.php index 457d850..3f7a8c7 100644 --- a/src/php/CrdmBasic/Customizer/class-content.php +++ b/src/php/CrdmBasic/Customizer/class-content.php @@ -130,32 +130,6 @@ protected function init_controls() { ] ); - Kirki::add_field( - $this->config_id, - [ - 'type' => 'typography', - 'settings' => 'contentH1Font', - 'label' => esc_attr__( 'Heading 1 (H1)', 'crdm-basic' ), - 'description' => esc_attr__( 'The color will be used for other elements (lists, tables etc.) as well.', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'font-family' => 'PT Sans', - 'variant' => '700', - 'font-size' => '2.3em', - 'line-height' => '1.15', - 'letter-spacing' => 'inherit', - 'color' => '#037b8c', - 'text-transform' => 'none', - ], - 'output' => [ - [ - 'element' => 'body .site-main h1', - ], - ], - 'transport' => 'auto', - ] - ); - Kirki::add_field( $this->config_id, [ diff --git a/src/php/CrdmBasic/Customizer/class-customizer-category.php b/src/php/CrdmBasic/Customizer/class-customizer-category.php index 8b13506..66818f9 100644 --- a/src/php/CrdmBasic/Customizer/class-customizer-category.php +++ b/src/php/CrdmBasic/Customizer/class-customizer-category.php @@ -23,8 +23,16 @@ abstract class Customizer_Category { public function __construct() { add_action( 'customize_register', [ $this, 'customize' ], 9 ); add_action( 'wp_enqueue_scripts', [ $this, 'add_inline_css' ], 11 ); + add_action( 'customize_preview_init', [ $this, 'enqueue_live_preview' ], 101 ); } + /** + * Enqueues the JS. + * + * Enqueues the live-preview JS handlers. + */ + public function enqueue_live_preview() {} + /** * Initializes customizer options. * diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index 5deb0e1..7f075fb 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -33,6 +33,14 @@ class Preset { 'navigation_font_transform' => 'none', 'navigation_font_size' => '16', 'mobile_navigation_font_size' => '', + 'font_heading_1' => 'PT Sans', + 'heading_1_weight' => 'normal', + 'heading_1_transform' => 'none', + 'heading_1_font_size' => '2.3', + 'mobile_heading_1_font_size' => '', + 'heading_1_line_height' => '1.15', + 'heading_1_margin_bottom' => '20', + 'h1_color' => '#037b8c', ], 'generate_background_settings' => [ 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', @@ -52,6 +60,8 @@ class Preset { 'font_body_category' => '', 'font_navigation_variants' => 'regular', 'font_navigation_category' => '', + 'font_heading_1_variants' => '700', + 'font_heading_1_category' => '', 'crdm_basic_border_radius' => '', ], 'dark' => [ @@ -71,6 +81,14 @@ class Preset { 'navigation_font_transform' => 'none', 'navigation_font_size' => '16', 'mobile_navigation_font_size' => '', + 'font_heading_1' => 'PT Sans', + 'heading_1_weight' => 'normal', + 'heading_1_transform' => 'none', + 'heading_1_font_size' => '2.3', + 'mobile_heading_1_font_size' => '', + 'heading_1_line_height' => '1.15', + 'heading_1_margin_bottom' => '20', + 'h1_color' => '#7adff1', ], 'generate_background_settings' => [ 'body_image' => '', @@ -90,6 +108,8 @@ class Preset { 'font_body_category' => '', 'font_navigation_variants' => 'regular', 'font_navigation_category' => '', + 'font_heading_1_variants' => '700', + 'font_heading_1_category' => '', 'crdm_basic_border_radius' => '0.5em', ], ]; diff --git a/src/php/CrdmBasic/Customizer/class-typography.php b/src/php/CrdmBasic/Customizer/class-typography.php index da53900..8c14744 100644 --- a/src/php/CrdmBasic/Customizer/class-typography.php +++ b/src/php/CrdmBasic/Customizer/class-typography.php @@ -28,23 +28,22 @@ class Typography extends Customizer_Category { 'navigation_font_transform' => 'none', 'navigation_font_size' => '15', 'mobile_navigation_font_size' => '15', + 'font_heading_1' => 'inherit', + 'heading_1_weight' => '300', + 'heading_1_transform' => 'none', + 'heading_1_font_size' => '40', + 'mobile_heading_1_font_size' => '30', + 'heading_1_line_height' => '1.2', + 'heading_1_margin_bottom' => '20', ], 'font_body_variants' => '', 'font_body_category' => '', 'font_navigation_variants' => '', 'font_navigation_category' => '', + 'font_heading_1_variants' => '', + 'font_heading_1_category' => '', ]; - /** - * Typography class constructor - * - * Adds the customize function to the WordPress action and registers the JS. - */ - public function __construct() { - parent::__construct(); - add_action( 'customize_preview_init', [ $this, 'enqueue_live_preview' ], 101 ); - } - /** * Enqueues the JS. * @@ -52,7 +51,6 @@ public function __construct() { */ public function enqueue_live_preview() { wp_enqueue_script( 'crdm_typography_live_preview', CRDMBASIC_TEMPLATE_URL . 'admin/typography_live_preview.js', [], CRDMBASIC_APP_VERSION, false ); - wp_localize_script( 'crdm_typography_live_preview', 'crdmTypographyLivePreview', @@ -80,6 +78,7 @@ public function customize( $wp_customize ) { $this->customize_body( $wp_customize ); $this->customize_primary_navigation( $wp_customize ); + $this->customize_headings( $wp_customize ); } } @@ -120,6 +119,16 @@ private function add_panel_sections( $wp_customize ) { 'panel' => 'generate_typography_panel', ] ); + + $wp_customize->add_section( + 'font_content_section', + [ + 'title' => __( 'Headings', 'crdm-basic' ), + 'capability' => 'edit_theme_options', + 'priority' => 60, + 'panel' => 'generate_typography_panel', + ] + ); } /** @@ -434,6 +443,203 @@ private function customize_primary_navigation( $wp_customize ) { ); } + /** + * Initializes customizer options for headings. + * + * Adds customizer options for controling heading typography. + * + * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + */ + public function customize_headings( $wp_customize ) { + // Family. + $wp_customize->add_setting( + 'generate_settings[font_heading_1]', + [ + 'default' => self::DEFAULT['generate_settings']['font_heading_1'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Variants. + $wp_customize->add_setting( + 'font_heading_1_variants', + [ + 'default' => self::DEFAULT['font_heading_1_variants'], + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], + ] + ); + + // Category. + $wp_customize->add_setting( + 'font_heading_1_category', + [ + 'default' => self::DEFAULT['font_heading_1_category'], + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Weight. + $wp_customize->add_setting( + 'generate_settings[heading_1_weight]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_1_weight'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + // Transform. + $wp_customize->add_setting( + 'generate_settings[heading_1_transform]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_1_transform'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Typography_Customize_Control( + $wp_customize, + 'font_heading_1_control', + [ + 'label' => __( 'Heading 1 (H1)', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'family' => 'generate_settings[font_heading_1]', + 'variant' => 'font_heading_1_variants', + 'category' => 'font_heading_1_category', + 'weight' => 'generate_settings[heading_1_weight]', + 'transform' => 'generate_settings[heading_1_transform]', + ], + ] + ) + ); + + // Size. + $wp_customize->add_setting( + 'generate_settings[heading_1_font_size]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_1_font_size'], + 'type' => 'option', + 'sanitize_callback' => 'absint', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_setting( + 'generate_settings[mobile_heading_1_font_size]', + [ + 'default' => self::DEFAULT['generate_settings']['mobile_heading_1_font_size'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'h1_font_sizes', + [ + 'description' => __( 'Font size', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'desktop' => 'generate_settings[heading_1_font_size]', + 'mobile' => 'generate_settings[mobile_heading_1_font_size]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 15, + 'max' => 100, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + 'mobile' => [ + 'min' => 15, + 'max' => 100, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + ], + ] + ) + ); + + // Line height. + $wp_customize->add_setting( + 'generate_settings[heading_1_line_height]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_1_line_height'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[heading_1_line_height]', + [ + 'description' => __( 'Line height', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'desktop' => 'generate_settings[heading_1_line_height]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 0, + 'max' => 5, + 'step' => .1, + 'edit' => true, + 'unit' => 'em', + ], + ], + ] + ) + ); + + // Paragraph margin. + $wp_customize->add_setting( + 'generate_settings[heading_1_margin_bottom]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_1_margin_bottom'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[heading_1_margin_bottom]', + [ + 'description' => __( 'Bottom margin', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'desktop' => 'generate_settings[heading_1_margin_bottom]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 0, + 'max' => 100, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + ], + ] + ) + ); + } + /** * Sanitizes a decimal number. * diff --git a/src/scss/frontend/content.scss b/src/scss/frontend/content.scss index 00882ac..7d93502 100644 --- a/src/scss/frontend/content.scss +++ b/src/scss/frontend/content.scss @@ -19,13 +19,6 @@ body { background-color: #fff; } - h1 { - font-size: 2.3em; - font-weight: 700; - line-height: 1.15; - color: #037b8c; - } - h2 { font-size: 2.2em; font-weight: 400; diff --git a/webpack.config.js b/webpack.config.js index 4e14321..cd3de82 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -38,6 +38,7 @@ module.exports = { entry: { 'frontend/index': './src/js/frontend/index.js', 'admin/preset_customize_control': './src/js/admin/preset_customize_control.js', + 'admin/colors_live_preview': './src/js/admin/colors_live_preview.js', 'admin/typography_live_preview': './src/js/admin/typography_live_preview.js' }, output: { From 281474c835162b66eaf26193960241a55c1b27be Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 25 Oct 2019 00:14:20 +0200 Subject: [PATCH 36/38] Converted H2 font --- src/js/admin/colors_live_preview.js | 1 + src/js/admin/typography_live_preview.js | 7 + .../Customizer/class-color-variant.php | 8 - src/php/CrdmBasic/Customizer/class-colors.php | 24 +++ .../CrdmBasic/Customizer/class-content.php | 25 --- src/php/CrdmBasic/Customizer/class-preset.php | 20 ++ .../CrdmBasic/Customizer/class-typography.php | 201 ++++++++++++++++++ src/scss/frontend/content.scss | 7 - 8 files changed, 253 insertions(+), 40 deletions(-) diff --git a/src/js/admin/colors_live_preview.js b/src/js/admin/colors_live_preview.js index 11a3520..d5a23c2 100644 --- a/src/js/admin/colors_live_preview.js +++ b/src/js/admin/colors_live_preview.js @@ -2,4 +2,5 @@ jQuery( 'document' ).ready( function( $ ) { generatepress_colors_live_update( 'h1_color', 'h1', 'color', '', 'text_color' ); + generatepress_colors_live_update( 'h2_color', 'h2', 'color', '', 'text_color' ); }); diff --git a/src/js/admin/typography_live_preview.js b/src/js/admin/typography_live_preview.js index bdd979a..b8d7f23 100644 --- a/src/js/admin/typography_live_preview.js +++ b/src/js/admin/typography_live_preview.js @@ -12,4 +12,11 @@ jQuery( 'document' ).ready( function( $ ) { generatepress_typography_live_update( 'heading_1_transform', 'h1', 'text-transform' ); generatepress_typography_live_update( 'heading_1_line_height', 'h1', 'line-height', 'em' ); generatepress_typography_live_update( 'heading_1_margin_bottom', 'h1', 'margin-bottom', 'px' ); + + generatepress_typography_live_update( 'heading_2_font_size', 'h2', 'font-size', 'px', crdmTypographyLivePreview.desktop ); + generatepress_typography_live_update( 'mobile_heading_2_font_size', 'h2', 'font-size', 'px', crdmTypographyLivePreview.mobile ); + generatepress_typography_live_update( 'heading_2_weight', 'h2', 'font-weight' ); + generatepress_typography_live_update( 'heading_2_transform', 'h2', 'text-transform' ); + generatepress_typography_live_update( 'heading_2_line_height', 'h2', 'line-height', 'em' ); + generatepress_typography_live_update( 'heading_2_margin_bottom', 'h2', 'margin-bottom', 'px' ); }); diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index 57e6a05..b85a720 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -101,10 +101,6 @@ protected function init_controls() { 'color' => '#ffffff', ], 'submenuSeparatorColor' => '#ffffff', - 'contentH2Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#037b8c', - ], 'contentH3Font' => [ 'font-family' => 'PT Sans', 'color' => '#00011f', @@ -138,10 +134,6 @@ protected function init_controls() { 'color' => '#5aa4cc', ], 'submenuSeparatorColor' => '#0f2b4a', - 'contentH2Font' => [ - 'font-family' => 'PT Sans', - 'color' => '#7adff1', - ], 'contentH3Font' => [ 'font-family' => 'PT Sans', 'color' => '#ebebeb', diff --git a/src/php/CrdmBasic/Customizer/class-colors.php b/src/php/CrdmBasic/Customizer/class-colors.php index 605e003..732cb52 100644 --- a/src/php/CrdmBasic/Customizer/class-colors.php +++ b/src/php/CrdmBasic/Customizer/class-colors.php @@ -20,6 +20,7 @@ class Colors extends Customizer_Category { 'navigation_background_color' => '#222222', 'navigation_text_color' => '#ffffff', 'h1_color' => '', + 'h2_color' => '', ], ]; @@ -170,6 +171,29 @@ private function customize_content( $wp_customize ) { ] ) ); + + $wp_customize->add_setting( + 'generate_settings[h2_color]', + [ + 'default' => self::DEFAULT['generate_settings']['h2_color'], + 'type' => 'option', + 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \WP_Customize_Color_Control( + $wp_customize, + 'h2_color', + [ + 'label' => __( 'Heading 2 (H2) Color', 'crdm-basic' ), + 'section' => 'content_color_section', + 'settings' => 'generate_settings[h2_color]', + 'priority' => '12', + ] + ) + ); } /** diff --git a/src/php/CrdmBasic/Customizer/class-content.php b/src/php/CrdmBasic/Customizer/class-content.php index 3f7a8c7..7b403bc 100644 --- a/src/php/CrdmBasic/Customizer/class-content.php +++ b/src/php/CrdmBasic/Customizer/class-content.php @@ -130,31 +130,6 @@ protected function init_controls() { ] ); - Kirki::add_field( - $this->config_id, - [ - 'type' => 'typography', - 'settings' => 'contentH2Font', - 'label' => esc_attr__( 'Heading 2 (H2)', 'crdm-basic' ), - 'section' => $this->section_id, - 'default' => [ - 'font-family' => 'PT Sans', - 'variant' => 'regular', - 'font-size' => '2.2em', - 'line-height' => '1.2', - 'letter-spacing' => 'inherit', - 'color' => '#037b8c', - 'text-transform' => 'none', - ], - 'output' => [ - [ - 'element' => 'body .site-main h2', - ], - ], - 'transport' => 'auto', - ] - ); - Kirki::add_field( $this->config_id, [ diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index 7f075fb..04da05c 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -41,6 +41,14 @@ class Preset { 'heading_1_line_height' => '1.15', 'heading_1_margin_bottom' => '20', 'h1_color' => '#037b8c', + 'font_heading_2' => 'PT Sans', + 'heading_2_weight' => 'normal', + 'heading_2_transform' => 'none', + 'heading_2_font_size' => '2.2', + 'mobile_heading_2_font_size' => '', + 'heading_2_line_height' => '1.2', + 'heading_2_margin_bottom' => '20', + 'h2_color' => '#037b8c', ], 'generate_background_settings' => [ 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', @@ -62,6 +70,8 @@ class Preset { 'font_navigation_category' => '', 'font_heading_1_variants' => '700', 'font_heading_1_category' => '', + 'font_heading_2_variants' => 'regular', + 'font_heading_2_category' => '', 'crdm_basic_border_radius' => '', ], 'dark' => [ @@ -89,6 +99,14 @@ class Preset { 'heading_1_line_height' => '1.15', 'heading_1_margin_bottom' => '20', 'h1_color' => '#7adff1', + 'font_heading_2' => 'PT Sans', + 'heading_2_weight' => 'normal', + 'heading_2_transform' => 'none', + 'heading_2_font_size' => '2.2', + 'mobile_heading_2_font_size' => '', + 'heading_2_line_height' => '1.2', + 'heading_2_margin_bottom' => '20', + 'h2_color' => '#7adff1', ], 'generate_background_settings' => [ 'body_image' => '', @@ -110,6 +128,8 @@ class Preset { 'font_navigation_category' => '', 'font_heading_1_variants' => '700', 'font_heading_1_category' => '', + 'font_heading_2_variants' => 'regular', + 'font_heading_2_category' => '', 'crdm_basic_border_radius' => '0.5em', ], ]; diff --git a/src/php/CrdmBasic/Customizer/class-typography.php b/src/php/CrdmBasic/Customizer/class-typography.php index 8c14744..21a8389 100644 --- a/src/php/CrdmBasic/Customizer/class-typography.php +++ b/src/php/CrdmBasic/Customizer/class-typography.php @@ -35,6 +35,13 @@ class Typography extends Customizer_Category { 'mobile_heading_1_font_size' => '30', 'heading_1_line_height' => '1.2', 'heading_1_margin_bottom' => '20', + 'font_heading_2' => 'inherit', + 'heading_2_weight' => '300', + 'heading_2_transform' => 'none', + 'heading_2_font_size' => '40', + 'mobile_heading_2_font_size' => '30', + 'heading_2_line_height' => '1.2', + 'heading_2_margin_bottom' => '20', ], 'font_body_variants' => '', 'font_body_category' => '', @@ -42,6 +49,8 @@ class Typography extends Customizer_Category { 'font_navigation_category' => '', 'font_heading_1_variants' => '', 'font_heading_1_category' => '', + 'font_heading_2_variants' => '', + 'font_heading_2_category' => '', ]; /** @@ -449,8 +458,11 @@ private function customize_primary_navigation( $wp_customize ) { * Adds customizer options for controling heading typography. * * @param \WP_Customize_Manager $wp_customize The WordPress customizer manager. + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function customize_headings( $wp_customize ) { + // H1. // Family. $wp_customize->add_setting( 'generate_settings[font_heading_1]', @@ -638,6 +650,195 @@ public function customize_headings( $wp_customize ) { ] ) ); + + // H2. + // Family. + $wp_customize->add_setting( + 'generate_settings[font_heading_2]', + [ + 'default' => self::DEFAULT['generate_settings']['font_heading_2'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Variants. + $wp_customize->add_setting( + 'font_heading_2_variants', + [ + 'default' => self::DEFAULT['font_heading_2_variants'], + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], + ] + ); + + // Category. + $wp_customize->add_setting( + 'font_heading_2_category', + [ + 'default' => self::DEFAULT['font_heading_2_category'], + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + // Weight. + $wp_customize->add_setting( + 'generate_settings[heading_2_weight]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_2_weight'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + // Transform. + $wp_customize->add_setting( + 'generate_settings[heading_2_transform]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_2_transform'], + 'type' => 'option', + 'sanitize_callback' => 'sanitize_key', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Typography_Customize_Control( + $wp_customize, + 'font_heading_2_control', + [ + 'label' => __( 'Heading 2 (H2)', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'family' => 'generate_settings[font_heading_2]', + 'variant' => 'font_heading_2_variants', + 'category' => 'font_heading_2_category', + 'weight' => 'generate_settings[heading_2_weight]', + 'transform' => 'generate_settings[heading_2_transform]', + ], + ] + ) + ); + + // Size. + $wp_customize->add_setting( + 'generate_settings[heading_2_font_size]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_2_font_size'], + 'type' => 'option', + 'sanitize_callback' => 'absint', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_setting( + 'generate_settings[mobile_heading_2_font_size]', + [ + 'default' => self::DEFAULT['generate_settings']['mobile_heading_2_font_size'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'h2_font_sizes', + [ + 'description' => __( 'Font size', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'desktop' => 'generate_settings[heading_2_font_size]', + 'mobile' => 'generate_settings[mobile_heading_2_font_size]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 10, + 'max' => 80, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + 'mobile' => [ + 'min' => 10, + 'max' => 80, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + ], + ] + ) + ); + + // Line height. + $wp_customize->add_setting( + 'generate_settings[heading_2_line_height]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_2_line_height'], + 'type' => 'option', + 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[heading_2_line_height]', + [ + 'description' => __( 'Line height', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'desktop' => 'generate_settings[heading_2_line_height]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 0, + 'max' => 5, + 'step' => .1, + 'edit' => true, + 'unit' => 'em', + ], + ], + ] + ) + ); + + // Paragraph margin. + $wp_customize->add_setting( + 'generate_settings[heading_2_margin_bottom]', + [ + 'default' => self::DEFAULT['generate_settings']['heading_2_margin_bottom'], + 'type' => 'option', + 'sanitize_callback' => 'generate_premium_sanitize_decimal_integer', + 'transport' => 'postMessage', + ] + ); + + $wp_customize->add_control( + new \Generate_Range_Slider_Control( + $wp_customize, + 'generate_settings[heading_2_margin_bottom]', + [ + 'description' => __( 'Bottom margin', 'crdm-basic' ), + 'section' => 'font_content_section', + 'settings' => [ + 'desktop' => 'generate_settings[heading_2_margin_bottom]', + ], + 'choices' => [ + 'desktop' => [ + 'min' => 0, + 'max' => 100, + 'step' => 1, + 'edit' => true, + 'unit' => 'px', + ], + ], + ] + ) + ); } /** diff --git a/src/scss/frontend/content.scss b/src/scss/frontend/content.scss index 7d93502..50fb19b 100644 --- a/src/scss/frontend/content.scss +++ b/src/scss/frontend/content.scss @@ -19,13 +19,6 @@ body { background-color: #fff; } - h2 { - font-size: 2.2em; - font-weight: 400; - line-height: 1.2; - color: #037b8c; - } - h3 { font-size: 1.8em; font-weight: 700; From 1149b06e3e2235d5550a7b7079f7f0e658c3650c Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Fri, 25 Oct 2019 01:16:33 +0200 Subject: [PATCH 37/38] Fixed GP Premium error --- src/php/disable-gp-functions.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/php/disable-gp-functions.php b/src/php/disable-gp-functions.php index bbcd2ee..a8e61c8 100644 --- a/src/php/disable-gp-functions.php +++ b/src/php/disable-gp-functions.php @@ -9,9 +9,11 @@ declare(strict_types = 1); -/** - * Turns off GP Typography - * - * The presence of this function disables the Typography section from GeneratePress basic. - */ -function generate_fonts_customize_register() {} +if ( ! function_exists( 'generate_fonts_customize_register' ) ) { + /** + * Turns off GP Typography + * + * The presence of this function disables the Typography section from GeneratePress basic. + */ + function generate_fonts_customize_register() {} +} From e68c7d968d53d2bc6ef5fc13a933460c4e9f4169 Mon Sep 17 00:00:00 2001 From: GenaBitu Date: Tue, 12 Nov 2019 14:00:07 +0100 Subject: [PATCH 38/38] Switched [] to array() --- ...ass-background-image-customize-control.php | 16 +- .../class-preset-customize-control.php | 6 +- .../CrdmBasic/Customizer/class-background.php | 152 +++---- .../Customizer/class-border-radius.php | 54 +-- .../Customizer/class-color-variant.php | 28 +- src/php/CrdmBasic/Customizer/class-colors.php | 64 +-- .../CrdmBasic/Customizer/class-content.php | 8 +- .../Customizer/class-customizer-category.php | 10 +- src/php/CrdmBasic/Customizer/class-menu.php | 4 +- src/php/CrdmBasic/Customizer/class-preset.php | 48 +-- .../CrdmBasic/Customizer/class-typography.php | 392 +++++++++--------- 11 files changed, 391 insertions(+), 391 deletions(-) diff --git a/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php index 49936ca..40d2002 100644 --- a/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php +++ b/src/php/CrdmBasic/Customizer/Controls/class-background-image-customize-control.php @@ -35,31 +35,31 @@ public function to_json() { $this->json['position_placeholder'] = esc_html__( 'Position', 'crdm-basic' ); foreach ( $this->settings as $key => $id ) { - $this->json['settings'][ $key ] = [ + $this->json['settings'][ $key ] = array( 'link' => $this->get_link( $key ), 'value' => $this->value( $key ), 'id' => $id->id ?? '', - ]; + ); } - $this->json['repeat_choices'] = [ + $this->json['repeat_choices'] = array( '' => esc_html__( 'Repeat', 'crdm-basic' ), 'repeat-x' => esc_html__( 'Repeat x', 'crdm-basic' ), 'repeat-y' => esc_html__( 'Repeat y', 'crdm-basic' ), 'no-repeat' => esc_html__( 'No Repeat', 'crdm-basic' ), - ]; - $this->json['size_choices'] = [ + ); + $this->json['size_choices'] = array( '' => esc_html__( 'Size (Auto)', 'crdm-basic' ), '100' => esc_html__( '100% Width', 'crdm-basic' ), 'cover' => esc_html__( 'Cover', 'crdm-basic' ), 'contain' => esc_html__( 'Contain', 'crdm-basic' ), - ]; - $this->json['attachment_choices'] = [ + ); + $this->json['attachment_choices'] = array( '' => esc_html__( 'Attachment', 'crdm-basic' ), 'fixed' => esc_html__( 'Fixed', 'crdm-basic' ), 'local' => esc_html__( 'Local', 'crdm-basic' ), 'inherit' => esc_html__( 'Inherit', 'crdm-basic' ), - ]; + ); } /** diff --git a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php index dc906e2..631a546 100644 --- a/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php +++ b/src/php/CrdmBasic/Customizer/Controls/class-preset-customize-control.php @@ -44,7 +44,7 @@ class Preset_Customize_Control extends \WP_Customize_Control { * * @SuppressWarnings(PHPMD.ShortVariable) */ - public function __construct( $manager, $id, $args, $presets = [] ) { + public function __construct( $manager, $id, $args, $presets = array() ) { parent::__construct( $manager, $id, $args ); $this->presets = $presets; @@ -58,8 +58,8 @@ public function __construct( $manager, $id, $args, $presets = [] ) { * @inheritDoc */ public function enqueue() { - wp_enqueue_style( 'crdm_basic_preset_customize_control_style', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.css', [], CRDMBASIC_APP_VERSION ); - wp_enqueue_script( 'crdm_basic_preset_customize_control_script', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.js', [ 'jquery', 'customize-preview' ], CRDMBASIC_APP_VERSION, true ); + wp_enqueue_style( 'crdm_basic_preset_customize_control_style', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.css', array(), CRDMBASIC_APP_VERSION ); + wp_enqueue_script( 'crdm_basic_preset_customize_control_script', CRDMBASIC_TEMPLATE_URL . 'admin/preset_customize_control.js', array( 'jquery', 'customize-preview' ), CRDMBASIC_APP_VERSION, true ); wp_localize_script( 'crdm_basic_preset_customize_control_script', 'crdmbasicPresetCustomizeControlLocalize', diff --git a/src/php/CrdmBasic/Customizer/class-background.php b/src/php/CrdmBasic/Customizer/class-background.php index 64a7cc7..2b5810f 100644 --- a/src/php/CrdmBasic/Customizer/class-background.php +++ b/src/php/CrdmBasic/Customizer/class-background.php @@ -15,8 +15,8 @@ * This class sets up all the customizer options for configuring the background of the webpage. */ class Background extends Customizer_Category { - const DEFAULT = [ - 'generate_background_settings' => [ + const DEFAULT = array( + 'generate_background_settings' => array( 'body_image' => '', 'body_repeat' => '', 'body_size' => '', @@ -24,13 +24,13 @@ class Background extends Customizer_Category { 'body_position' => '', 'nav_image' => '', 'nav_repeat' => '', - ], - 'crdm_basic_header' => [ + ), + 'crdm_basic_header' => array( 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', - ], - ]; + ), + ); /** * Initializes customizer options. @@ -61,42 +61,42 @@ public function customize( $wp_customize ) { private function add_panel_sections( $wp_customize ) { $wp_customize->add_panel( 'generate_backgrounds_panel', - [ + array( 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => __( 'Background Images', 'crdm-basic' ), 'priority' => 55, - ] + ) ); $wp_customize->add_section( 'generate_backgrounds_body', - [ + array( 'title' => __( 'Body', 'crdm-basic' ), 'capability' => 'edit_theme_options', 'priority' => 5, 'panel' => 'generate_backgrounds_panel', - ] + ) ); $wp_customize->add_section( 'generate_backgrounds_header', - [ + array( 'title' => __( 'Header', 'crdm-basic' ), 'capability' => 'edit_theme_options', 'priority' => 10, 'panel' => 'generate_backgrounds_panel', - ] + ) ); $wp_customize->add_section( 'generate_backgrounds_navigation', - [ + array( 'title' => __( 'Primary Navigation', 'crdm-basic' ), 'capability' => 'edit_theme_options', 'priority' => 15, 'panel' => 'generate_backgrounds_panel', - ] + ) ); } @@ -110,76 +110,76 @@ private function add_panel_sections( $wp_customize ) { private function customize_body( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[body_image]', - [ + array( 'default' => self::DEFAULT['generate_background_settings']['body_image'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'generate_backgrounds-body-image', - [ + array( 'section' => 'generate_backgrounds_body', 'settings' => 'generate_background_settings[body_image]', 'label' => __( 'Body', 'crdm-basic' ), - ] + ) ) ); $wp_customize->add_setting( 'generate_background_settings[body_repeat]', - [ + array( 'default' => self::DEFAULT['generate_background_settings']['body_repeat'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', - ] + ) ); $wp_customize->add_setting( 'generate_background_settings[body_size]', - [ + array( 'default' => self::DEFAULT['generate_background_settings']['body_size'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', - ] + ) ); $wp_customize->add_setting( 'generate_background_settings[body_attachment]', - [ + array( 'default' => self::DEFAULT['generate_background_settings']['body_attachment'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', - ] + ) ); $wp_customize->add_setting( 'generate_background_settings[body_position]', - [ + array( 'default' => self::DEFAULT['generate_background_settings']['body_position'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_html', - ] + ) ); $wp_customize->add_control( new Controls\Background_Image_Customize_Control( $wp_customize, 'body_backgrounds_control', - [ + array( 'section' => 'generate_backgrounds_body', - 'settings' => [ + 'settings' => array( 'repeat' => 'generate_background_settings[body_repeat]', 'size' => 'generate_background_settings[body_size]', 'attachment' => 'generate_background_settings[body_attachment]', 'position' => 'generate_background_settings[body_position]', - ], - ] + ), + ) ) ); } @@ -194,50 +194,50 @@ private function customize_body( $wp_customize ) { private function customize_navigation( $wp_customize ) { $wp_customize->add_setting( 'generate_background_settings[nav_image]', - [ + array( 'default' => self::DEFAULT['generate_background_settings']['nav_image'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'generate_backgrounds_settings[nav_image]', - [ + array( 'section' => 'generate_backgrounds_navigation', 'settings' => 'generate_background_settings[nav_image]', 'priority' => 750, 'label' => __( 'Navigation', 'crdm-basic' ), - ] + ) ) ); $wp_customize->add_setting( 'generate_background_settings[nav_repeat]', - [ + array( 'default' => self::DEFAULT['generate_background_settings']['nav_repeat'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', - ] + ) ); $wp_customize->add_control( 'generate_background_settings[nav_repeat]', - [ + array( 'type' => 'select', 'section' => 'generate_backgrounds_navigation', 'settings' => 'generate_background_settings[nav_repeat]', - 'choices' => [ + 'choices' => array( '' => __( 'Repeat', 'crdm-basic' ), 'repeat-x' => __( 'Repeat x', 'crdm-basic' ), 'repeat-y' => __( 'Repeat y', 'crdm-basic' ), 'no-repeat' => __( 'No Repeat', 'crdm-basic' ), - ], + ), 'priority' => 800, - ] + ) ); } @@ -251,67 +251,67 @@ private function customize_navigation( $wp_customize ) { private function customize_header( $wp_customize ) { $wp_customize->add_setting( 'crdm_basic_header[background]', - [ + array( 'default' => self::DEFAULT['crdm_basic_header']['background'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'crdm_basic_header[background]', - [ + array( 'section' => 'generate_backgrounds_header', 'settings' => 'crdm_basic_header[background]', 'label' => __( 'Featured background image', 'crdm-basic' ), - ] + ) ) ); $wp_customize->add_setting( 'crdm_basic_header[foreground]', - [ + array( 'default' => self::DEFAULT['crdm_basic_header']['foreground'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'crdm_basic_header[foreground]', - [ + array( 'section' => 'generate_backgrounds_header', 'settings' => 'crdm_basic_header[foreground]', 'label' => __( 'Featured foreground image', 'crdm-basic' ), - ] + ) ) ); $wp_customize->add_setting( 'crdm_basic_header[under]', - [ + array( 'default' => self::DEFAULT['crdm_basic_header']['under'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'crdm_basic_header[under]', - [ + array( 'section' => 'generate_backgrounds_header', 'settings' => 'crdm_basic_header[under]', 'label' => __( 'Under menu image', 'crdm-basic' ), - ] + ) ) ); } @@ -324,29 +324,29 @@ private function customize_header( $wp_customize ) { * @return array A list of properties in selectors. */ protected function inline_css() { - $generate_settings = wp_parse_args( get_option( 'generate_background_settings', [] ), self::DEFAULT['generate_background_settings'] ); - $crdm_settings = wp_parse_args( get_option( 'crdm_basic_header', [] ), self::DEFAULT['crdm_basic_header'] ); - return [ - 'body' => [ - [ 'background-image', $generate_settings['body_image'], 'url' ], - [ 'background-repeat', $generate_settings['body_repeat'] ], - [ 'background-size', $generate_settings['body_size'] ], - [ 'background-attachment', $generate_settings['body_attachment'] ], - [ 'background-position', $generate_settings['body_position'] ], - ], - '.crdm_header__bg_1' => [ - [ 'background-image', $crdm_settings['background'], 'url' ], - ], - '.crdm_header__bg_2-container-content' => [ - [ 'background-image', $crdm_settings['foreground'], 'url' ], - ], - '.crdm_header__bg_3' => [ - [ 'background-image', $crdm_settings['under'], 'url' ], - ], - '.main-navigation, .menu-toggle' => [ - [ 'background-image', $generate_settings['nav_image'], 'url' ], - [ 'background-repeat', $generate_settings['nav_repeat'] ], - ], - ]; + $generate_settings = wp_parse_args( get_option( 'generate_background_settings', array() ), self::DEFAULT['generate_background_settings'] ); + $crdm_settings = wp_parse_args( get_option( 'crdm_basic_header', array() ), self::DEFAULT['crdm_basic_header'] ); + return array( + 'body' => array( + array( 'background-image', $generate_settings['body_image'], 'url' ), + array( 'background-repeat', $generate_settings['body_repeat'] ), + array( 'background-size', $generate_settings['body_size'] ), + array( 'background-attachment', $generate_settings['body_attachment'] ), + array( 'background-position', $generate_settings['body_position'] ), + ), + '.crdm_header__bg_1' => array( + array( 'background-image', $crdm_settings['background'], 'url' ), + ), + '.crdm_header__bg_2-container-content' => array( + array( 'background-image', $crdm_settings['foreground'], 'url' ), + ), + '.crdm_header__bg_3' => array( + array( 'background-image', $crdm_settings['under'], 'url' ), + ), + '.main-navigation, .menu-toggle' => array( + array( 'background-image', $generate_settings['nav_image'], 'url' ), + array( 'background-repeat', $generate_settings['nav_repeat'] ), + ), + ); } } diff --git a/src/php/CrdmBasic/Customizer/class-border-radius.php b/src/php/CrdmBasic/Customizer/class-border-radius.php index 8af7232..e30f4b4 100644 --- a/src/php/CrdmBasic/Customizer/class-border-radius.php +++ b/src/php/CrdmBasic/Customizer/class-border-radius.php @@ -15,9 +15,9 @@ * This class sets up all the customizer options for configuring the radius of corners of the webpage elements. */ class Border_Radius extends Customizer_Category { - const DEFAULT = [ + const DEFAULT = array( 'crdm_basic_border_radius' => '', - ]; + ); /** * Initializes customizer options. @@ -29,30 +29,30 @@ class Border_Radius extends Customizer_Category { public function customize( $wp_customize ) { $wp_customize->add_section( 'crdm_basic_border_radius', - [ + array( 'capability' => 'edit_theme_options', 'title' => __( 'Border radius', 'crdm-basic' ), 'priority' => 25, - ] + ) ); $wp_customize->add_setting( 'crdm_basic_border_radius', - [ + array( 'default' => self::DEFAULT['crdm_basic_border_radius'], 'type' => 'option', 'capability' => 'edit_theme_options', - ] + ) ); $wp_customize->add_control( 'crdm_basic_border_radius', - [ + array( 'type' => 'text', 'section' => 'crdm_basic_border_radius', 'label' => __( 'Border radius', 'crdm-basic' ), 'description' => __( 'Including units, e. g. "10px"', 'crdm-basic' ), - ] + ) ); } @@ -65,24 +65,24 @@ public function customize( $wp_customize ) { */ protected function inline_css() { $setting = get_option( 'crdm_basic_border_radius', self::DEFAULT['crdm_basic_border_radius'] ); - return [ - '.widget-area .widget' => [ - [ 'border-radius', $setting ], - ], - '.crdm_page-header_captions' => [ - [ 'border-radius', $setting ], - ], - '.main-navigation' => [ - [ 'border-radius', $setting ], - ], - '.main-navigation .main-nav ul.sub-menu li:first-child a' => [ - [ 'border-top-left-radius', $setting ], - [ 'border-top-right-radius', $setting ], - ], - '.main-navigation .main-nav ul.sub-menu li:last-child a' => [ - [ 'border-bottom-left-radius', $setting ], - [ 'border-bottom-right-radius', $setting ], - ], - ]; + return array( + '.widget-area .widget' => array( + array( 'border-radius', $setting ), + ), + '.crdm_page-header_captions' => array( + array( 'border-radius', $setting ), + ), + '.main-navigation' => array( + array( 'border-radius', $setting ), + ), + '.main-navigation .main-nav ul.sub-menu li:first-child a' => array( + array( 'border-top-left-radius', $setting ), + array( 'border-top-right-radius', $setting ), + ), + '.main-navigation .main-nav ul.sub-menu li:last-child a' => array( + array( 'border-bottom-left-radius', $setting ), + array( 'border-bottom-right-radius', $setting ), + ), + ); } } diff --git a/src/php/CrdmBasic/Customizer/class-color-variant.php b/src/php/CrdmBasic/Customizer/class-color-variant.php index e927f4d..733d4c3 100644 --- a/src/php/CrdmBasic/Customizer/class-color-variant.php +++ b/src/php/CrdmBasic/Customizer/class-color-variant.php @@ -88,9 +88,9 @@ protected function init_controls() { 'light' => CRDMBASIC_TEMPLATE_URL . 'admin/light.png', 'dark' => CRDMBASIC_TEMPLATE_URL . 'admin/dark.png', ), - 'preset' => [ - 'light' => [ - 'settings' => [ + 'preset' => array( + 'light' => array( + 'settings' => array( 'menuSeparatorColor' => '#3b969f', 'submenuBg' => array( 'background-color' => '#65c3d4', @@ -101,10 +101,10 @@ protected function init_controls() { 'color' => '#ffffff', ), 'submenuSeparatorColor' => '#ffffff', - 'contentH3Font' => [ + 'contentH3Font' => array( 'font-family' => 'PT Sans', 'color' => '#00011f', - ], + ), 'contentH4Font' => array( 'font-family' => 'PT Sans', 'color' => '#037b8c', @@ -120,10 +120,10 @@ protected function init_controls() { 'contentLinksColor' => '#037b8c', 'sidebarLinksColor' => '#037b8c', 'footerLinksColor' => '#037b8c', - ], - ], - 'dark' => [ - 'settings' => [ + ), + ), + 'dark' => array( + 'settings' => array( 'menuSeparatorColor' => '#465058', 'submenuBg' => array( 'background-color' => '#122030', @@ -134,10 +134,10 @@ protected function init_controls() { 'color' => '#5aa4cc', ), 'submenuSeparatorColor' => '#0f2b4a', - 'contentH3Font' => [ + 'contentH3Font' => array( 'font-family' => 'PT Sans', 'color' => '#ebebeb', - ], + ), 'contentH4Font' => array( 'font-family' => 'PT Sans', 'color' => '#7adff1', @@ -153,9 +153,9 @@ protected function init_controls() { 'contentLinksColor' => '#7adff1', 'sidebarLinksColor' => '#5aa5c8', 'footerLinksColor' => '#5aa5c8', - ], - ], - ], + ), + ), + ), ) ); } diff --git a/src/php/CrdmBasic/Customizer/class-colors.php b/src/php/CrdmBasic/Customizer/class-colors.php index 732cb52..5d31c46 100644 --- a/src/php/CrdmBasic/Customizer/class-colors.php +++ b/src/php/CrdmBasic/Customizer/class-colors.php @@ -15,14 +15,14 @@ * This class sets up all the customizer options for configuring the various colors of the webpage. */ class Colors extends Customizer_Category { - const DEFAULT = [ - 'generate_settings' => [ + const DEFAULT = array( + 'generate_settings' => array( 'navigation_background_color' => '#222222', 'navigation_text_color' => '#ffffff', 'h1_color' => '', 'h2_color' => '', - ], - ]; + ), + ); /** * Enqueues the JS. @@ -30,7 +30,7 @@ class Colors extends Customizer_Category { * Enqueues the live-preview JS handlers. */ public function enqueue_live_preview() { - wp_enqueue_script( 'crdm_colors_live_preview', CRDMBASIC_TEMPLATE_URL . 'admin/colors_live_preview.js', [], CRDMBASIC_APP_VERSION, false ); + wp_enqueue_script( 'crdm_colors_live_preview', CRDMBASIC_TEMPLATE_URL . 'admin/colors_live_preview.js', array(), CRDMBASIC_APP_VERSION, false ); } /** @@ -59,30 +59,30 @@ public function customize( $wp_customize ) { private function add_panel_sections( $wp_customize ) { $wp_customize->add_panel( 'generate_colors_panel', - [ + array( 'priority' => 30, 'theme_supports' => '', 'title' => __( 'Colors', 'crdm-basic' ), 'description' => '', - ] + ) ); $wp_customize->add_section( 'navigation_color_section', - [ + array( 'title' => __( 'Primary Navigation', 'crdm-basic' ), 'priority' => 60, 'panel' => 'generate_colors_panel', - ] + ) ); $wp_customize->add_section( 'content_color_section', - [ + array( 'title' => __( 'Content', 'crdm-basic' ), 'priority' => 80, 'panel' => 'generate_colors_panel', - ] + ) ); } @@ -96,47 +96,47 @@ private function add_panel_sections( $wp_customize ) { private function customize_primary_navigation( $wp_customize ) { $wp_customize->add_setting( 'generate_settings[navigation_background_color]', - [ + array( 'default' => self::DEFAULT['generate_settings']['navigation_background_color'], 'type' => 'option', - 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'sanitize_callback' => array( $this, 'sanitize_hex' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Color_Control( $wp_customize, 'navigation_background_color_control', - [ + array( 'label' => __( 'Background', 'crdm-basic' ), 'section' => 'navigation_color_section', 'settings' => 'generate_settings[navigation_background_color]', 'priority' => '1', - ] + ) ) ); $wp_customize->add_setting( 'generate_settings[navigation_text_color]', - [ + array( 'default' => self::DEFAULT['generate_settings']['navigation_text_color'], 'type' => 'option', - 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'sanitize_callback' => array( $this, 'sanitize_hex' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Color_Control( $wp_customize, 'navigation_text_color', - [ + array( 'label' => __( 'Text', 'crdm-basic' ), 'section' => 'navigation_color_section', 'settings' => 'generate_settings[navigation_text_color]', 'priority' => '2', - ] + ) ) ); } @@ -151,47 +151,47 @@ private function customize_primary_navigation( $wp_customize ) { private function customize_content( $wp_customize ) { $wp_customize->add_setting( 'generate_settings[h1_color]', - [ + array( 'default' => self::DEFAULT['generate_settings']['h1_color'], 'type' => 'option', - 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'sanitize_callback' => array( $this, 'sanitize_hex' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Color_Control( $wp_customize, 'h1_color', - [ + array( 'label' => __( 'Heading 1 (H1) Color', 'crdm-basic' ), 'section' => 'content_color_section', 'settings' => 'generate_settings[h1_color]', 'priority' => '11', - ] + ) ) ); $wp_customize->add_setting( 'generate_settings[h2_color]', - [ + array( 'default' => self::DEFAULT['generate_settings']['h2_color'], 'type' => 'option', - 'sanitize_callback' => [ $this, 'sanitize_hex' ], + 'sanitize_callback' => array( $this, 'sanitize_hex' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \WP_Customize_Color_Control( $wp_customize, 'h2_color', - [ + array( 'label' => __( 'Heading 2 (H2) Color', 'crdm-basic' ), 'section' => 'content_color_section', 'settings' => 'generate_settings[h2_color]', 'priority' => '12', - ] + ) ) ); } @@ -220,6 +220,6 @@ public function sanitize_hex( $value ) { * @return array A list of properties in selectors. */ protected function inline_css() { - return []; + return array(); } } diff --git a/src/php/CrdmBasic/Customizer/class-content.php b/src/php/CrdmBasic/Customizer/class-content.php index 7f24d4c..4e64fa5 100644 --- a/src/php/CrdmBasic/Customizer/class-content.php +++ b/src/php/CrdmBasic/Customizer/class-content.php @@ -114,7 +114,7 @@ protected function init_controls() { Kirki::add_field( $this->config_id, - [ + array( 'type' => 'color', 'settings' => 'contentLinksColor', 'label' => esc_attr__( 'Link color', 'crdm-basic' ), @@ -127,12 +127,12 @@ protected function init_controls() { ), ), 'transport' => 'auto', - ] + ) ); Kirki::add_field( $this->config_id, - [ + array( 'type' => 'typography', 'settings' => 'contentH3Font', 'label' => esc_attr__( 'Heading 3 (H3)', 'crdm-basic' ), @@ -152,7 +152,7 @@ protected function init_controls() { ), ), 'transport' => 'auto', - ] + ) ); Kirki::add_field( diff --git a/src/php/CrdmBasic/Customizer/class-customizer-category.php b/src/php/CrdmBasic/Customizer/class-customizer-category.php index 66818f9..6b57579 100644 --- a/src/php/CrdmBasic/Customizer/class-customizer-category.php +++ b/src/php/CrdmBasic/Customizer/class-customizer-category.php @@ -21,9 +21,9 @@ abstract class Customizer_Category { * Adds the customize function to the WordPress action. */ public function __construct() { - add_action( 'customize_register', [ $this, 'customize' ], 9 ); - add_action( 'wp_enqueue_scripts', [ $this, 'add_inline_css' ], 11 ); - add_action( 'customize_preview_init', [ $this, 'enqueue_live_preview' ], 101 ); + add_action( 'customize_register', array( $this, 'customize' ), 9 ); + add_action( 'wp_enqueue_scripts', array( $this, 'add_inline_css' ), 11 ); + add_action( 'customize_preview_init', array( $this, 'enqueue_live_preview' ), 101 ); } /** @@ -57,7 +57,7 @@ abstract protected function inline_css(); * Registers and enqueues an empty stylesheet to be used for the customizer-defined settings. */ public static function register_inline_css() { - wp_register_style( 'crdm_customizer', false, [], CRDMBASIC_APP_VERSION ); + wp_register_style( 'crdm_customizer', false, array(), CRDMBASIC_APP_VERSION ); wp_enqueue_style( 'crdm_customizer' ); } @@ -95,4 +95,4 @@ public function add_inline_css() { } } -add_action( 'wp_enqueue_scripts', [ '\\CrdmBasic\\Customizer\\Customizer_Category', 'register_inline_css' ], 10 ); +add_action( 'wp_enqueue_scripts', array( '\\CrdmBasic\\Customizer\\Customizer_Category', 'register_inline_css' ), 10 ); diff --git a/src/php/CrdmBasic/Customizer/class-menu.php b/src/php/CrdmBasic/Customizer/class-menu.php index 88bcf3d..1c96dc1 100644 --- a/src/php/CrdmBasic/Customizer/class-menu.php +++ b/src/php/CrdmBasic/Customizer/class-menu.php @@ -77,7 +77,7 @@ protected function init_section() { protected function init_controls() { Kirki::add_field( $this->config_id, - [ + array( 'type' => 'color', 'settings' => 'menuSeparatorColor', 'label' => esc_attr__( 'Menu item separator color', 'crdm-basic' ), @@ -90,7 +90,7 @@ protected function init_controls() { ), ), 'transport' => 'auto', - ] + ) ); Kirki::add_field( diff --git a/src/php/CrdmBasic/Customizer/class-preset.php b/src/php/CrdmBasic/Customizer/class-preset.php index 04da05c..e42e200 100644 --- a/src/php/CrdmBasic/Customizer/class-preset.php +++ b/src/php/CrdmBasic/Customizer/class-preset.php @@ -15,9 +15,9 @@ * This class sets up all the customizer options for choosing one of the built-in presets of the template */ class Preset { - const PRESETS = [ - 'light' => [ - 'generate_settings' => [ + const PRESETS = array( + 'light' => array( + 'generate_settings' => array( 'background_color' => '#ffffff', 'navigation_background_color' => '#037b8c', 'navigation_text_color' => '#efefe5', @@ -49,8 +49,8 @@ class Preset { 'heading_2_line_height' => '1.2', 'heading_2_margin_bottom' => '20', 'h2_color' => '#037b8c', - ], - 'generate_background_settings' => [ + ), + 'generate_background_settings' => array( 'body_image' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_background.png', 'body_repeat' => '', 'body_size' => '', @@ -58,12 +58,12 @@ class Preset { 'body_position' => '', 'nav_image' => '', 'nav_repeat' => '', - ], - 'crdm_basic_header' => [ + ), + 'crdm_basic_header' => array( 'background' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_background.png', 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_header_foreground.png', 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/light_grass.png', - ], + ), 'font_body_variants' => 'regular', 'font_body_category' => '', 'font_navigation_variants' => 'regular', @@ -73,9 +73,9 @@ class Preset { 'font_heading_2_variants' => 'regular', 'font_heading_2_category' => '', 'crdm_basic_border_radius' => '', - ], - 'dark' => [ - 'generate_settings' => [ + ), + 'dark' => array( + 'generate_settings' => array( 'background_color' => '#0f2b4a', 'navigation_background_color' => '#122030', 'navigation_text_color' => '#f2efde', @@ -107,8 +107,8 @@ class Preset { 'heading_2_line_height' => '1.2', 'heading_2_margin_bottom' => '20', 'h2_color' => '#7adff1', - ], - 'generate_background_settings' => [ + ), + 'generate_background_settings' => array( 'body_image' => '', 'body_repeat' => '', 'body_size' => '', @@ -116,12 +116,12 @@ class Preset { 'body_position' => '', 'nav_image' => '', 'nav_repeat' => '', - ], - 'crdm_basic_header' => [ + ), + 'crdm_basic_header' => array( 'background' => '', 'foreground' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_header_foreground.png', 'under' => CRDMBASIC_TEMPLATE_URL . 'frontend/dark_pavement.png', - ], + ), 'font_body_variants' => 'regular', 'font_body_category' => '', 'font_navigation_variants' => 'regular', @@ -131,8 +131,8 @@ class Preset { 'font_heading_2_variants' => 'regular', 'font_heading_2_category' => '', 'crdm_basic_border_radius' => '0.5em', - ], - ]; + ), + ); /** * Preset class constructor @@ -140,7 +140,7 @@ class Preset { * Adds settings for the 2 presets for the page. */ public function __construct() { - add_action( 'customize_register', [ $this, 'customize' ], 1000 ); + add_action( 'customize_register', array( $this, 'customize' ), 1000 ); } /** @@ -155,21 +155,21 @@ public function customize( $wp_customize ) { $wp_customize->add_section( 'crdm_basic_preset', - [ + array( 'title' => __( 'Preset', 'crdm-basic' ), 'capability' => 'edit_theme_options', 'priority' => 21, - ] + ) ); $wp_customize->add_control( new Controls\Preset_Customize_Control( $wp_customize, 'crdm_basic_preset', - [ + array( 'section' => 'crdm_basic_preset', - 'settings' => [], - ], + 'settings' => array(), + ), self::PRESETS ) ); diff --git a/src/php/CrdmBasic/Customizer/class-typography.php b/src/php/CrdmBasic/Customizer/class-typography.php index 21a8389..e9ca95b 100644 --- a/src/php/CrdmBasic/Customizer/class-typography.php +++ b/src/php/CrdmBasic/Customizer/class-typography.php @@ -15,8 +15,8 @@ * This class sets up all the customizer options for configuring the various font and text properties of the theme. */ class Typography extends Customizer_Category { - const DEFAULT = [ - 'generate_settings' => [ + const DEFAULT = array( + 'generate_settings' => array( 'font_body' => 'System Stack', 'body_font_weight' => 'normal', 'body_font_transform' => 'none', @@ -42,7 +42,7 @@ class Typography extends Customizer_Category { 'mobile_heading_2_font_size' => '30', 'heading_2_line_height' => '1.2', 'heading_2_margin_bottom' => '20', - ], + ), 'font_body_variants' => '', 'font_body_category' => '', 'font_navigation_variants' => '', @@ -51,7 +51,7 @@ class Typography extends Customizer_Category { 'font_heading_1_category' => '', 'font_heading_2_variants' => '', 'font_heading_2_category' => '', - ]; + ); /** * Enqueues the JS. @@ -59,16 +59,16 @@ class Typography extends Customizer_Category { * Enqueues the live-preview JS handlers. */ public function enqueue_live_preview() { - wp_enqueue_script( 'crdm_typography_live_preview', CRDMBASIC_TEMPLATE_URL . 'admin/typography_live_preview.js', [], CRDMBASIC_APP_VERSION, false ); + wp_enqueue_script( 'crdm_typography_live_preview', CRDMBASIC_TEMPLATE_URL . 'admin/typography_live_preview.js', array(), CRDMBASIC_APP_VERSION, false ); wp_localize_script( 'crdm_typography_live_preview', 'crdmTypographyLivePreview', - [ + array( // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 'mobile' => apply_filters( 'generate_mobile_media_query', '(max-width:768px)' ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 'desktop' => apply_filters( 'generate_desktop_media_query', '(min-width:1025px)' ), - ] + ) ); } @@ -101,42 +101,42 @@ public function customize( $wp_customize ) { private function add_panel_sections( $wp_customize ) { $wp_customize->add_panel( 'generate_typography_panel', - [ + array( 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => __( 'Typography', 'crdm-basic' ), 'priority' => 30, - ] + ) ); $wp_customize->add_section( 'font_section', - [ + array( 'title' => __( 'Body', 'crdm-basic' ), 'capability' => 'edit_theme_options', 'priority' => 30, 'panel' => 'generate_typography_panel', - ] + ) ); $wp_customize->add_section( 'font_navigation_section', - [ + array( 'title' => __( 'Primary Navigation', 'crdm-basic' ), 'capability' => 'edit_theme_options', 'priority' => 50, 'panel' => 'generate_typography_panel', - ] + ) ); $wp_customize->add_section( 'font_content_section', - [ + array( 'title' => __( 'Headings', 'crdm-basic' ), 'capability' => 'edit_theme_options', 'priority' => 60, 'panel' => 'generate_typography_panel', - ] + ) ); } @@ -151,173 +151,173 @@ private function customize_body( $wp_customize ) { // Family. $wp_customize->add_setting( 'generate_settings[font_body]', - [ + array( 'default' => self::DEFAULT['generate_settings']['font_body'], 'type' => 'option', 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Variants. $wp_customize->add_setting( 'font_body_variants', - [ + array( 'default' => self::DEFAULT['font_body_variants'], - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], - ] + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ), + ) ); // Category. $wp_customize->add_setting( 'font_body_category', - [ + array( 'default' => self::DEFAULT['font_body_category'], 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Font weight. $wp_customize->add_setting( 'generate_settings[body_font_weight]', - [ + array( 'default' => self::DEFAULT['generate_settings']['body_font_weight'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); // Transform. $wp_customize->add_setting( 'generate_settings[body_font_transform]', - [ + array( 'default' => self::DEFAULT['generate_settings']['body_font_transform'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Typography_Customize_Control( $wp_customize, 'body_typography', - [ + array( 'section' => 'font_section', 'priority' => 1, - 'settings' => [ + 'settings' => array( 'family' => 'generate_settings[font_body]', 'variant' => 'font_body_variants', 'category' => 'font_body_category', 'weight' => 'generate_settings[body_font_weight]', 'transform' => 'generate_settings[body_font_transform]', - ], - ] + ), + ) ) ); // Size. $wp_customize->add_setting( 'generate_settings[body_font_size]', - [ + array( 'default' => self::DEFAULT['generate_settings']['body_font_size'], 'type' => 'option', 'sanitize_callback' => 'absint', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[body_font_size]', - [ + array( 'description' => __( 'Font size', 'crdm-basic' ), 'section' => 'font_section', 'priority' => 40, - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[body_font_size]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 6, 'max' => 25, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - ], - ] + ), + ), + ) ) ); // Line height. $wp_customize->add_setting( 'generate_settings[body_line_height]', - [ + array( 'default' => self::DEFAULT['generate_settings']['body_line_height'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[body_line_height]', - [ + array( 'description' => __( 'Line height', 'crdm-basic' ), 'section' => 'font_section', 'priority' => 45, - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[body_line_height]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 1, 'max' => 5, 'step' => .1, 'edit' => true, 'unit' => '', - ], - ], - ] + ), + ), + ) ) ); // Paragraph margin. $wp_customize->add_setting( 'generate_settings[paragraph_margin]', - [ + array( 'default' => self::DEFAULT['generate_settings']['paragraph_margin'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[paragraph_margin]', - [ + array( 'description' => __( 'Paragraph margin', 'crdm-basic' ), 'section' => 'font_section', 'priority' => 47, - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[paragraph_margin]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 0, 'max' => 5, 'step' => .1, 'edit' => true, 'unit' => 'em', - ], - ], - ] + ), + ), + ) ) ); } @@ -333,121 +333,121 @@ private function customize_primary_navigation( $wp_customize ) { // Family. $wp_customize->add_setting( 'generate_settings[font_navigation]', - [ + array( 'default' => self::DEFAULT['generate_settings']['font_navigation'], 'type' => 'option', 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Variants. $wp_customize->add_setting( 'font_navigation_variants', - [ + array( 'default' => self::DEFAULT['font_navigation_variants'], - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], - ] + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ), + ) ); // Category. $wp_customize->add_setting( 'font_navigation_category', - [ + array( 'default' => self::DEFAULT['font_navigation_category'], 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Weight. $wp_customize->add_setting( 'generate_settings[navigation_font_weight]', - [ + array( 'default' => self::DEFAULT['generate_settings']['navigation_font_weight'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); // Transform. $wp_customize->add_setting( 'generate_settings[navigation_font_transform]', - [ + array( 'default' => self::DEFAULT['generate_settings']['navigation_font_transform'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Typography_Customize_Control( $wp_customize, 'google_font_site_navigation_control', - [ + array( 'section' => 'font_navigation_section', 'priority' => 120, - 'settings' => [ + 'settings' => array( 'family' => 'generate_settings[font_navigation]', 'variant' => 'font_navigation_variants', 'category' => 'font_navigation_category', 'weight' => 'generate_settings[navigation_font_weight]', 'transform' => 'generate_settings[navigation_font_transform]', - ], - ] + ), + ) ) ); // Size. $wp_customize->add_setting( 'generate_settings[navigation_font_size]', - [ + array( 'default' => self::DEFAULT['generate_settings']['navigation_font_size'], 'type' => 'option', 'sanitize_callback' => 'absint', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_setting( 'generate_settings[mobile_navigation_font_size]', - [ + array( 'default' => self::DEFAULT['generate_settings']['mobile_navigation_font_size'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[navigation_font_size]', - [ + array( 'description' => __( 'Font size', 'crdm-basic' ), 'section' => 'font_navigation_section', 'priority' => 165, - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[navigation_font_size]', 'mobile' => 'generate_settings[mobile_navigation_font_size]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 6, 'max' => 30, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - 'mobile' => [ + ), + 'mobile' => array( 'min' => 6, 'max' => 30, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - ], - ] + ), + ), + ) ) ); } @@ -466,188 +466,188 @@ public function customize_headings( $wp_customize ) { // Family. $wp_customize->add_setting( 'generate_settings[font_heading_1]', - [ + array( 'default' => self::DEFAULT['generate_settings']['font_heading_1'], 'type' => 'option', 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Variants. $wp_customize->add_setting( 'font_heading_1_variants', - [ + array( 'default' => self::DEFAULT['font_heading_1_variants'], - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], - ] + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ), + ) ); // Category. $wp_customize->add_setting( 'font_heading_1_category', - [ + array( 'default' => self::DEFAULT['font_heading_1_category'], 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Weight. $wp_customize->add_setting( 'generate_settings[heading_1_weight]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_1_weight'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); // Transform. $wp_customize->add_setting( 'generate_settings[heading_1_transform]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_1_transform'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Typography_Customize_Control( $wp_customize, 'font_heading_1_control', - [ + array( 'label' => __( 'Heading 1 (H1)', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'family' => 'generate_settings[font_heading_1]', 'variant' => 'font_heading_1_variants', 'category' => 'font_heading_1_category', 'weight' => 'generate_settings[heading_1_weight]', 'transform' => 'generate_settings[heading_1_transform]', - ], - ] + ), + ) ) ); // Size. $wp_customize->add_setting( 'generate_settings[heading_1_font_size]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_1_font_size'], 'type' => 'option', 'sanitize_callback' => 'absint', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_setting( 'generate_settings[mobile_heading_1_font_size]', - [ + array( 'default' => self::DEFAULT['generate_settings']['mobile_heading_1_font_size'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'h1_font_sizes', - [ + array( 'description' => __( 'Font size', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[heading_1_font_size]', 'mobile' => 'generate_settings[mobile_heading_1_font_size]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 15, 'max' => 100, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - 'mobile' => [ + ), + 'mobile' => array( 'min' => 15, 'max' => 100, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - ], - ] + ), + ), + ) ) ); // Line height. $wp_customize->add_setting( 'generate_settings[heading_1_line_height]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_1_line_height'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[heading_1_line_height]', - [ + array( 'description' => __( 'Line height', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[heading_1_line_height]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 0, 'max' => 5, 'step' => .1, 'edit' => true, 'unit' => 'em', - ], - ], - ] + ), + ), + ) ) ); // Paragraph margin. $wp_customize->add_setting( 'generate_settings[heading_1_margin_bottom]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_1_margin_bottom'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[heading_1_margin_bottom]', - [ + array( 'description' => __( 'Bottom margin', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[heading_1_margin_bottom]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 0, 'max' => 100, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - ], - ] + ), + ), + ) ) ); @@ -655,188 +655,188 @@ public function customize_headings( $wp_customize ) { // Family. $wp_customize->add_setting( 'generate_settings[font_heading_2]', - [ + array( 'default' => self::DEFAULT['generate_settings']['font_heading_2'], 'type' => 'option', 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Variants. $wp_customize->add_setting( 'font_heading_2_variants', - [ + array( 'default' => self::DEFAULT['font_heading_2_variants'], - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ], - ] + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_variants' ), + ) ); // Category. $wp_customize->add_setting( 'font_heading_2_category', - [ + array( 'default' => self::DEFAULT['font_heading_2_category'], 'sanitize_callback' => 'sanitize_text_field', - ] + ) ); // Weight. $wp_customize->add_setting( 'generate_settings[heading_2_weight]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_2_weight'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); // Transform. $wp_customize->add_setting( 'generate_settings[heading_2_transform]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_2_transform'], 'type' => 'option', 'sanitize_callback' => 'sanitize_key', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Typography_Customize_Control( $wp_customize, 'font_heading_2_control', - [ + array( 'label' => __( 'Heading 2 (H2)', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'family' => 'generate_settings[font_heading_2]', 'variant' => 'font_heading_2_variants', 'category' => 'font_heading_2_category', 'weight' => 'generate_settings[heading_2_weight]', 'transform' => 'generate_settings[heading_2_transform]', - ], - ] + ), + ) ) ); // Size. $wp_customize->add_setting( 'generate_settings[heading_2_font_size]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_2_font_size'], 'type' => 'option', 'sanitize_callback' => 'absint', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_setting( 'generate_settings[mobile_heading_2_font_size]', - [ + array( 'default' => self::DEFAULT['generate_settings']['mobile_heading_2_font_size'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_empty_absint' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'h2_font_sizes', - [ + array( 'description' => __( 'Font size', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[heading_2_font_size]', 'mobile' => 'generate_settings[mobile_heading_2_font_size]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 10, 'max' => 80, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - 'mobile' => [ + ), + 'mobile' => array( 'min' => 10, 'max' => 80, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - ], - ] + ), + ), + ) ) ); // Line height. $wp_customize->add_setting( 'generate_settings[heading_2_line_height]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_2_line_height'], 'type' => 'option', - 'sanitize_callback' => [ '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ], + 'sanitize_callback' => array( '\\CrdmBasic\\Customizer\\Typography', 'sanitize_decimal_number' ), 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[heading_2_line_height]', - [ + array( 'description' => __( 'Line height', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[heading_2_line_height]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 0, 'max' => 5, 'step' => .1, 'edit' => true, 'unit' => 'em', - ], - ], - ] + ), + ), + ) ) ); // Paragraph margin. $wp_customize->add_setting( 'generate_settings[heading_2_margin_bottom]', - [ + array( 'default' => self::DEFAULT['generate_settings']['heading_2_margin_bottom'], 'type' => 'option', 'sanitize_callback' => 'generate_premium_sanitize_decimal_integer', 'transport' => 'postMessage', - ] + ) ); $wp_customize->add_control( new \Generate_Range_Slider_Control( $wp_customize, 'generate_settings[heading_2_margin_bottom]', - [ + array( 'description' => __( 'Bottom margin', 'crdm-basic' ), 'section' => 'font_content_section', - 'settings' => [ + 'settings' => array( 'desktop' => 'generate_settings[heading_2_margin_bottom]', - ], - 'choices' => [ - 'desktop' => [ + ), + 'choices' => array( + 'desktop' => array( 'min' => 0, 'max' => 100, 'step' => 1, 'edit' => true, 'unit' => 'px', - ], - ], - ] + ), + ), + ) ) ); } @@ -895,6 +895,6 @@ public static function sanitize_empty_absint( $value ) { * @return array A list of properties in selectors. */ protected function inline_css() { - return []; + return array(); } }