Last active
March 17, 2020 04:40
-
-
Save colorful-tones/f15044a6830af5d176f066617e1dbbf4 to your computer and use it in GitHub Desktop.
Child theme for Go - includes custom Customizer options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customizer setup | |
* | |
* @package YourChildTheme | |
*/ | |
namespace YourChildTheme\Customizer; | |
/** | |
* Set up Customizer hooks | |
* | |
* @return void | |
*/ | |
function setup() { | |
$n = function( $function ) { | |
return __NAMESPACE__ . "\\$function"; | |
}; | |
add_action( 'customize_register', $n( 'register_yourchildtheme_site_controls' ) ); | |
} | |
/** | |
* Add telephone control to Go's existing Site Settings section. | |
* | |
* @param \WP_Customize_Manager $wp_customize The customize manager object. | |
* | |
* @return void | |
*/ | |
function register_yourchildtheme_site_controls( \WP_Customize_Manager $wp_customize ) { | |
$wp_customize->add_setting( | |
'telephone', | |
array( | |
'default' => '1.800.555.5555', | |
'transport' => 'postMessage', | |
'sanitize_callback' => 'sanitize_text_field', | |
) | |
); | |
$wp_customize->add_control( | |
'telephone_control', | |
array( | |
'label' => esc_html__( 'Phone number', 'yourchildtheme' ), | |
'priority' => 80, | |
'section' => 'go_site_settings', // Here we referece Go's origin section ID. | |
'settings' => 'telephone', | |
'type' => 'text', | |
) | |
); | |
$wp_customize->add_setting( | |
'site_message', | |
array( | |
'default' => '', | |
'transport' => 'postMessage', | |
) | |
); | |
$wp_customize->add_control( | |
'site_message_control', | |
array( | |
'description' => esc_html__( 'This will appear in the header at the top of the site.', 'yourchildtheme' ), | |
'label' => esc_html__( 'Site message', 'yourchildtheme' ), | |
'priority' => 90, | |
'section' => 'go_site_settings', // Here we referece Go's origin section ID. | |
'settings' => 'site_message', | |
'type' => 'textarea', | |
) | |
); | |
$wp_customize->add_setting( | |
'company_address', | |
array( | |
'default' => '', | |
'transport' => 'postMessage', | |
) | |
); | |
$wp_customize->add_control( | |
'company_address_control', | |
array( | |
'description' => esc_html__( 'This will appear in the footer at the bottom of the site.', 'yourchildtheme' ), | |
'label' => esc_html__( 'Company address', 'yourchildtheme' ), | |
'priority' => 100, | |
'section' => 'go_site_settings', // Here we referece Go's origin section ID. | |
'settings' => 'company_address', | |
'type' => 'textarea', | |
) | |
); | |
$wp_customize->add_setting( | |
'privacy_statement', | |
array( | |
'default' => '', | |
'transport' => 'postMessage', | |
) | |
); | |
$wp_customize->add_control( | |
'personal_privacy_control', | |
array( | |
'description' => esc_html__( 'This will appear in the footer at the bottom of the site.', 'yourchildtheme' ), | |
'label' => esc_html__( 'Privacy Statement', 'yourchildtheme' ), | |
'priority' => 110, | |
'section' => 'go_site_settings', // Here we referece Go's origin section ID. | |
'settings' => 'privacy_statement', | |
'type' => 'textarea', | |
) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Our Child theme overrides. | |
* "Keep it light, keep it simple." - Mahatma Gandhi 🙃 | |
* | |
*/ | |
/** | |
* Customizer additions. | |
*/ | |
require_once get_theme_file_path( 'includes/customizer.php' ); | |
/** | |
* Custom template tags for this child theme. | |
*/ | |
require_once get_theme_file_path( 'includes/template-tags.php' ); | |
/** | |
* Run setup functions. | |
*/ | |
YourChildTheme\Customizer\setup(); | |
/** | |
* Enqueue our child theme assets and dependencies. | |
* | |
* @return void | |
*/ | |
function yourchildtheme_theme_enqueue_styles() { | |
// Enqueue the Go parent shared styles. | |
wp_enqueue_style( | |
'go-style', | |
get_template_directory_uri() . '/dist/css/style-shared.min.css', | |
GO_VERSION | |
); | |
// Enqueue Google Font CSS. | |
wp_enqueue_style( | |
'yourchildtheme-google-font', | |
yourchildtheme_font_url(), | |
array(), | |
null | |
); | |
} | |
add_action( 'wp_enqueue_scripts', 'yourchildtheme_theme_enqueue_styles' ); | |
/** | |
* Set our Go child theme's default footer variant. | |
* | |
* @link https://github.com/godaddy-wordpress/go/blob/master/includes/core.php#L977 | |
* @return void | |
*/ | |
function yourchildtheme_default_footer_variation() { | |
return 'footer-4'; | |
} | |
add_filter( 'go_default_footer_variation', 'yourchildtheme_default_footer_variation' ); | |
/** | |
* Set our Go child theme's default color scheme. | |
* | |
* @link https://github.com/godaddy-wordpress/go/blob/master/includes/core.php#L1112 | |
* @return void | |
*/ | |
function yourchildtheme_default_color_scheme() { | |
return 'two'; | |
} | |
add_filter( 'go_default_color_scheme', 'yourchildtheme_default_color_scheme' ); | |
/** | |
* Add our new design style to Go's design styles. | |
* | |
* @link https://github.com/godaddy-wordpress/go/blob/master/includes/core.php#L557 | |
* @return void | |
*/ | |
function yourchildtheme_design_styles() { | |
$suffix = SCRIPT_DEBUG ? '' : '.min'; | |
$yourchildtheme_design_styles = array( | |
'yourchildtheme' => array( | |
'slug' => 'yourchildtheme', | |
'label' => _x( 'YourChildTheme', 'design style name', 'go' ), | |
'url' => get_theme_file_uri( "dist/css/design-styles/style-yourchildtheme{$suffix}.css" ), | |
'editor_style' => "dist/css/design-styles/style-yourchildtheme-editor{$suffix}.css", | |
'color_schemes' => array( | |
'one' => array( | |
'label' => _x( 'Forest', 'color palette name', 'go' ), // possibly for alternative (in the future) | |
'primary' => '#165144', | |
'secondary' => '#01332e', | |
'tertiary' => '#c9c9c9', | |
'background' => '#ffffff', | |
'header_background' => '#ffffff', | |
), | |
'two' => array( | |
'label' => _x( 'Bathe', 'color palette name', 'go' ), // for primary | |
'primary' => '#000000', | |
'secondary' => '#333536', | |
'tertiary' => '#0281ba', | |
'background' => '#ffffff', | |
'header_background' => '#ffffff', | |
), | |
), | |
), | |
); | |
return $yourchildtheme_design_styles; | |
} | |
add_filter( 'go_design_styles', 'yourchildtheme_design_styles' ); | |
/** | |
* Register Google font. | |
* | |
* @link http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/ | |
* @return string | |
*/ | |
function yourchildtheme_font_url() { | |
$fonts_url = ''; | |
/** | |
* Translators: If there are characters in your language that are not | |
* supported by the following, translate this to 'off'. Do not translate | |
* into your own language. | |
*/ | |
$raleway = esc_html_x( 'on', 'Raleway font: on or off', 'yourchildtheme' ); | |
if ( 'off' !== $raleway ) { | |
$font_families = array(); | |
if ( 'off' !== $raleway ) { | |
$font_families[] = 'Roboto:300,400,700'; | |
} | |
$query_args = array( | |
'family' => rawurlencode( implode( '|', $font_families ) ), | |
'subset' => rawurlencode( 'latin,latin-ext' ), | |
); | |
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' ); | |
} | |
return $fonts_url; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global module */ | |
// Webpack settings exports. | |
module.exports = { | |
entries: { | |
'design-styles/style-yourchildtheme': './.dev/assets/design-styles/yourchildtheme/css/style-yourchildtheme.css', | |
'design-styles/style-yourchildtheme-editor': './.dev/assets/design-styles/yourchildtheme/css/style-yourchildtheme-editor.css' | |
}, | |
paths: { | |
src: { | |
base: './.dev/assets/', | |
yourchildthemeBase: './.dev/assets/design-styles/yourchildtheme/', | |
yourchildthemeCss: './.dev/assets/design-styles/yourchildtheme/css/' | |
}, | |
dist: { | |
base: './dist/', | |
clean: ['./images', './css', './js'] | |
}, | |
}, | |
stats: { | |
all: false, | |
errors: true, | |
maxModules: 0, | |
modules: true, | |
warnings: true, | |
assets: true, | |
errorDetails: true, | |
excludeAssets: /\.(jpe?g|png|gif|svg|woff|woff2|ttf)$/i, | |
moduleTrace: true, | |
performance: true | |
}, | |
copyWebpackConfig: { | |
from: '.dev/assets/**/*.{jpg,jpeg,png,gif,svg}', | |
to: 'images/[path][name].[ext]', | |
transformPath: ( targetPath ) => { | |
return 'images/' + targetPath.replace( /(\.dev\/assets\/|images\/|shared\/)/g, '' ); | |
}, | |
}, | |
BrowserSyncConfig: { | |
host: 'localhost', | |
port: 3000, | |
proxy: 'https://go.test', | |
open: true, | |
files: [ | |
'**/*.php', | |
'dist/js/**/*.js', | |
'dist/css/**/*.css', | |
'dist/images/**/*.{jpg,jpeg,png,gif,svg}' | |
] | |
}, | |
performance: { | |
maxAssetSize: 100000 | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment