Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme/extras hooks cleanup #430

Merged
merged 8 commits into from
Oct 26, 2018
2 changes: 0 additions & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ function _s_widgets_init() {
// Define sidebars.
$sidebars = array(
'sidebar-1' => esc_html__( 'Sidebar 1', '_s' ),
// 'sidebar-2' => esc_html__( 'Sidebar 2', '_s' ),
// 'sidebar-3' => esc_html__( 'Sidebar 3', '_s' ),
);

// Loop through each sidebar and register.
Expand Down
25 changes: 25 additions & 0 deletions inc/acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,28 @@ function _s_acf_load_color_picker_field_choices( $field ) {
return $field;
}
add_filter( 'acf/load_field/name=color_picker', '_s_acf_load_color_picker_field_choices' );

/**
* Get the theme colors for this project. Set these first in the Sass partial then migrate them over here.
*
* @return array The array of our color names and hex values.
* @author Corey Collins
*/
function _s_get_theme_colors() {
return array(
esc_html__( 'Alto', '_s' ) => '#ddd',
esc_html__( 'Black', '_s' ) => '#000',
esc_html__( 'Blue', '_s' ) => '#21759b',
esc_html__( 'Cod Gray', '_s' ) => '#111',
esc_html__( 'Dove Gray', '_s' ) => '#666',
esc_html__( 'Gallery', '_s' ) => '#eee',
esc_html__( 'Gray', '_s' ) => '#808080',
esc_html__( 'Gray Alt', '_s' ) => '#929292',
esc_html__( 'Light Yellow', '_s' ) => '#fff9c0',
esc_html__( 'Mineshaft', '_s' ) => '#333',
esc_html__( 'Silver', '_s' ) => '#ccc',
esc_html__( 'Silver Chalice', '_s' ) => '#aaa',
esc_html__( 'White', '_s' ) => '#fff',
esc_html__( 'Whitesmoke', '_s' ) => '#f1f1f1',
);
}
128 changes: 3 additions & 125 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,63 +66,6 @@ function _s_get_attachment_id_from_url( $attachment_url = '' ) {
return $attachment_id;
}

/**
* Returns an <img> that can be used anywhere a placeholder image is needed
* in a theme. The image is a simple colored block with the image dimensions
* displayed in the middle.
*
* @author Ben Lobaugh
* @throws Exception Details of missing parameters.
* @param array $args {.
* @type int $width
* @type int $height
* @type string $background_color
* @type string $text_color
* }
* @return string
*/
function _s_get_placeholder_image( $args = array() ) {
$default_args = array(
'width' => '',
'height' => '',
'background_color' => 'dddddd',
'text_color' => '000000',
);

$args = wp_parse_args( $args, $default_args );

// Extract the vars we want to work with.
$width = $args['width'];
$height = $args['height'];
$background_color = $args['background_color'];
$text_color = $args['text_color'];

// Perform some quick data validation.
if ( ! is_numeric( $width ) ) {
throw new Exception( esc_html__( 'Width must be an integer', '_s' ) );
}

if ( ! is_numeric( $height ) ) {
throw new Exception( esc_html__( 'Height must be an integer', '_s' ) );
}

if ( ! ctype_xdigit( $background_color ) ) {
throw new Exception( esc_html__( 'Please provide a valid hex color value for background_color', '_s' ) );
}

if ( ! ctype_xdigit( $text_color ) ) {
throw new Exception( esc_html__( 'Please provide a valid hex color value for text_color', '_s' ) );
}

// Set up the url to the image.
$url = "http://placeholder.wdslab.com/i/{$width}x$height/$background_color/$text_color";

// Text that will be utilized by screen readers.
$alt = apply_filters( '_s_placeholder_image_alt', esc_html__( 'WebDevStudios Placeholder Image', '_s' ) );

return "<img src='$url' width='$width' height='$height' alt='$alt' />";
}

/**
* Returns an photo from Unsplash.com wrapped in an <img> that can be used
* in a theme. There are limited category and search capabilities to attempt
Expand All @@ -139,9 +82,10 @@ function _s_get_placeholder_image( $args = array() ) {
* @return string
*/
function _s_get_placeholder_unsplash( $args = array() ) {

$default_args = array(
'width' => '',
'height' => '',
'width' => 200,
'height' => 200,
'category' => '',
'keywords' => '',
);
Expand Down Expand Up @@ -194,47 +138,6 @@ function _s_get_placeholder_unsplash( $args = array() ) {
return "<img src='$url' width='{$args['width']}' height='{$args['height']}' alt='$alt' />";
}

/**
* Display the customizer header scripts.
*
* @author Greg Rickaby
* @return string
*/
function _s_display_customizer_header_scripts() {

// Check for header scripts.
$scripts = get_theme_mod( '_s_header_scripts' );

// None? Bail...
if ( ! $scripts ) {
return false;
}

// Otherwise, echo the scripts!
echo force_balance_tags( $scripts ); // WPCS XSS OK.
}

/**
* Display the customizer footer scripts.
*
* @author Greg Rickaby
* @return string
*/
function _s_display_customizer_footer_scripts() {

// Check for footer scripts.
$scripts = get_theme_mod( '_s_footer_scripts' );

// None? Bail...
if ( ! $scripts ) {
return false;
}

// Otherwise, echo the scripts!
echo force_balance_tags( $scripts ); // WPCS XSS OK.
}


/**
* Shortcode to display copyright year.
*
Expand Down Expand Up @@ -263,28 +166,3 @@ function _s_copyright_year( $atts ) {
return esc_html( $args['starting_year'] . $args['separator'] . $current_year );
}
add_shortcode( '_s_copyright_year', '_s_copyright_year', 15 );

/**
* Get the theme colors for this project. Set these first in the Sass partial then migrate them over here.
*
* @return array The array of our color names and hex values.
* @author Corey Collins
*/
function _s_get_theme_colors() {
return array(
esc_html__( 'Alto', '_s' ) => '#ddd',
esc_html__( 'Black', '_s' ) => '#000',
esc_html__( 'Blue', '_s' ) => '#21759b',
esc_html__( 'Cod Gray', '_s' ) => '#111',
esc_html__( 'Dove Gray', '_s' ) => '#666',
esc_html__( 'Gallery', '_s' ) => '#eee',
esc_html__( 'Gray', '_s' ) => '#808080',
esc_html__( 'Gray Alt', '_s' ) => '#929292',
esc_html__( 'Light Yellow', '_s' ) => '#fff9c0',
esc_html__( 'Mineshaft', '_s' ) => '#333',
esc_html__( 'Silver', '_s' ) => '#ccc',
esc_html__( 'Silver Chalice', '_s' ) => '#aaa',
esc_html__( 'White', '_s' ) => '#fff',
esc_html__( 'Whitesmoke', '_s' ) => '#f1f1f1',
);
}
46 changes: 42 additions & 4 deletions inc/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,52 @@ function _s_custom_mime_types( $mimes ) {
*/
add_filter( 'cancel_comment_reply_link', '__return_false' );

// Additional scripts from Customizer.
add_action( 'wp_head', '_s_display_customizer_header_scripts', 999 );
add_action( 'wp_footer', '_s_display_customizer_footer_scripts', 999 );

// Create shortcode for SVG.
// Usage [svg icon="facebook-square" title="facebook" desc="like us on facebook" fill="#000000" height="20px" width="20px"].
add_shortcode( 'svg', '_s_display_svg' );

/**
* Display the customizer header scripts.
*
* @author Greg Rickaby
* @return string
*/
function _s_display_customizer_header_scripts() {

// Check for header scripts.
$scripts = get_theme_mod( '_s_header_scripts' );

// None? Bail...
if ( ! $scripts ) {
return false;
}

// Otherwise, echo the scripts!
echo force_balance_tags( $scripts ); // WPCS XSS OK.
}
add_action( 'wp_head', '_s_display_customizer_header_scripts', 999 );

/**
* Display the customizer footer scripts.
*
* @author Greg Rickaby
* @return string
*/
function _s_display_customizer_footer_scripts() {

// Check for footer scripts.
$scripts = get_theme_mod( '_s_footer_scripts' );

// None? Bail...
if ( ! $scripts ) {
return false;
}

// Otherwise, echo the scripts!
echo force_balance_tags( $scripts ); // WPCS XSS OK.
}
add_action( 'wp_footer', '_s_display_customizer_footer_scripts', 999 );

/**
* Adds OG tags to the head for better social sharing.
*
Expand Down
4 changes: 2 additions & 2 deletions inc/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function _s_scripts() {
/**
* If WP is in script debug, or we pass ?script_debug in a URL - set debug to true.
*/
$debug = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) || ( isset( $_GET['script_debug'] ) ) ? true : false; // phpcs:ignore
$debug = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) || ( isset( $_GET['script_debug'] ) ) ? true : false; // WPCS: CSRF OK.

/**
* If we are debugging the site, use a unique version every page load so as to ensure no cache issues.
Expand Down Expand Up @@ -105,7 +105,7 @@ function _s_customizer_scripts() {
/**
* If WP is in script debug, or we pass ?script_debug in a URL - set debug to true.
*/
$debug = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) || ( isset( $_GET['script_debug'] ) ) ? true : false; // phpcs:ignore
$debug = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) || ( isset( $_GET['script_debug'] ) ) ? true : false; // WPCS: CSRF OK.

/**
* If we are debugging the site, use a unique version every page load so as to ensure no cache issues.
Expand Down