Skip to content

Instantly share code, notes, and snippets.

@colorful-tones
Last active March 17, 2020 04:40
Show Gist options
  • Save colorful-tones/f15044a6830af5d176f066617e1dbbf4 to your computer and use it in GitHub Desktop.
Save colorful-tones/f15044a6830af5d176f066617e1dbbf4 to your computer and use it in GitHub Desktop.
Child theme for Go - includes custom Customizer options
<?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',
)
);
}
<?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;
}
<?php
/**
* Custom template tags for this child theme.
*
* This file is for custom template tags only and it should not contain
* functions that will be used for filtering or adding an action.
*
* @package YourChildTheme
*/
namespace YourChildTheme;
use function Go\load_inline_svg as load_inline_svg;
/**
* Displays the site phone number (set in Customizer).
*
* @param array $args {
* Optional. An array of arguments.
*
* @type string $class The div class. Default is .site-phone
* }
*
* @return void
*/
function phone( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'class' => 'site-phone',
)
);
$phone = get_theme_mod( 'telephone' );
$html = array(
'br' => array(
'class' => array(),
),
'span' => array(
'class' => array(),
),
'a' => array(
'href' => array(),
'class' => array(),
),
);
?>
<div class="<?php echo esc_attr( $args['class'] ); ?>">
<?php if ( $phone || is_customize_preview() ) : ?>
<span class="phone">
<?php echo wp_kses( $phone, $html ); ?>
</span>
<?php endif; ?>
</div>
<?php
}
/**
* Displays the site phone number (set in Customizer).
*
* @param array $args {
* Optional. An array of arguments.
*
* @type string $class The div class. Default is .site-phone
* }
*
* @return void
*/
function site_message( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'class' => 'site-message',
)
);
$site_message = get_theme_mod( 'site_message' );
$html = array(
'div' => array(
'class' => array(),
),
'span' => array(
'class' => array(),
),
'a' => array(
'href' => array(),
'class' => array(),
),
);
?>
<div class="<?php echo esc_attr( $args['class'] ); ?>">
<?php if ( $site_message || is_customize_preview() ) : ?>
<span class="message">
<?php echo wp_kses( $site_message, $html ); ?>
</span>
<?php endif; ?>
</div>
<?php
}
/**
* Displays the company address (set in Customizer).
*
* @param array $args {
* Optional. An array of arguments.
*
* @type string $class The div class. Default is .site-phone
* }
*
* @return void
*/
function company_address( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'class' => 'company-address',
)
);
$company_address = get_theme_mod( 'company_address' );
$html = array(
'br' => array(),
);
?>
<div class="<?php echo esc_attr( $args['class'] ); ?>">
<?php if ( $company_address || is_customize_preview() ) : ?>
<address><?php echo wp_kses( $company_address, $html ); ?></address>
<?php endif; ?>
</div>
<?php
}
/**
* Displays the personal privacy statement (set in Customizer).
*
* @return void
*/
function display_privacy_statement() {
$privacy_statement = get_theme_mod( 'privacy_statement' );
if ( $privacy_statement || is_customize_preview() ) {
echo '<span class="privacy-statement text-sm">' . esc_html( $privacy_statement ) . '</span>';
}
}
/**
* Get either Logged in or Logged out link based
* on current user's state.
*
* @return void
*/
function get_loginout_link() {
$link_text = '';
if ( is_user_logged_in() ) {
$link_text = 'My Account';
}
elseif ( ! is_user_logged_in() ) {
$link_text = 'Sign in';
}
echo '<a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '" class="my-account">';
load_inline_svg( 'account.svg' );
echo esc_html__( $link_text, 'yourchildtheme' );
echo '</a>';
}
/* 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