Skip to content

Commit

Permalink
Drop deprecated CHILD_THEME_NAME constant and use CHILD_THEME_HANDLE
Browse files Browse the repository at this point in the history
CHILD_THEME_NAME is no longer required as of Genesis 2.9.0. It was
previously used to set the footer credit text and as the handle for
the enqueued stylesheet. In Genesis 2.9.0 the name is now pulled from
the Theme Name header for the site footer, and a sanitized version
of the same value is used as the stylesheet handle.

See studiopress/genesis#2166.

The CHILD_THEME_HANDLE constant is used instead for enqueueing scripts
and styles. Where a human-readable name is needed (admin notices), it is
pulled directly from the stylesheet Theme Name line.

The goal is to reduce the number of places where people need to set
their theme name and version number.

The sanitized Name is used for the CHILD_THEME_HANDLE instead of the
Text Domain because we have often seen modified Genesis Sample themes
where the name is changed but the text domain is not. We could switch to
the Text Domain once this is implemented:
#142.

It's also likely that we'll switch away from constants and use helper
functions should those become available in Genesis. This would offer
better cache-busting during development, where assets can change often
but version strings do not.
studiopress/genesis#2199 (comment).
  • Loading branch information
nickcernis committed Mar 14, 2019
1 parent 989d959 commit 7142e6f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// Starts the engine.
require_once get_template_directory() . '/lib/init.php';

// Defines the child theme (do not remove).
define( 'CHILD_THEME_NAME', 'Genesis Sample' );
// Defines constants to help enqueue scripts and styles.
define( 'CHILD_THEME_HANDLE', sanitize_title_with_dashes( wp_get_theme()->get( 'Name' ) ) );
define( 'CHILD_THEME_VERSION', wp_get_theme()->get( 'Version' ) );

// Sets up the Theme.
Expand Down
4 changes: 1 addition & 3 deletions lib/gutenberg/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
*/
function genesis_sample_enqueue_gutenberg_frontend_styles() {

$child_theme_slug = defined( 'CHILD_THEME_NAME' ) && CHILD_THEME_NAME ? sanitize_title_with_dashes( CHILD_THEME_NAME ) : 'genesis-sample';

wp_enqueue_style(
'genesis-sample-gutenberg',
get_stylesheet_directory_uri() . '/lib/gutenberg/front-end.css',
array( $child_theme_slug ),
array( CHILD_THEME_HANDLE ),
CHILD_THEME_VERSION
);

Expand Down
3 changes: 1 addition & 2 deletions lib/gutenberg/inline-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ function genesis_sample_custom_gutenberg_css() {
$css .= genesis_sample_inline_font_sizes();
$css .= genesis_sample_inline_color_palette();

$handle = defined( 'CHILD_THEME_NAME' ) && CHILD_THEME_NAME ? sanitize_title_with_dashes( CHILD_THEME_NAME ) : 'child-theme';
wp_add_inline_style( $handle . '-gutenberg', $css );
wp_add_inline_style( CHILD_THEME_HANDLE . '-gutenberg', $css );

}

Expand Down
4 changes: 1 addition & 3 deletions lib/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
function genesis_sample_css() {

$handle = defined( 'CHILD_THEME_NAME' ) && CHILD_THEME_NAME ? sanitize_title_with_dashes( CHILD_THEME_NAME ) : 'child-theme';

$color_link = get_theme_mod( 'genesis_sample_link_color', genesis_sample_customizer_get_default_link_color() );
$color_accent = get_theme_mod( 'genesis_sample_accent_color', genesis_sample_customizer_get_default_accent_color() );
$logo = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' );
Expand Down Expand Up @@ -149,7 +147,7 @@ function genesis_sample_css() {
) : '';

if ( $css ) {
wp_add_inline_style( $handle, $css );
wp_add_inline_style( CHILD_THEME_HANDLE, $css );
}

}
4 changes: 2 additions & 2 deletions lib/woocommerce/woocommerce-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function genesis_sample_woocommerce_theme_notice() {
}

/* translators: %s: child theme name */
$notice_html = sprintf( __( 'Please install and activate <a href="https://wordpress.org/plugins/genesis-connect-woocommerce/" target="_blank">Genesis Connect for WooCommerce</a> to <strong>enable WooCommerce support for %s</strong>.', 'genesis-sample' ), esc_html( CHILD_THEME_NAME ) );
$notice_html = sprintf( __( 'Please install and activate <a href="https://wordpress.org/plugins/genesis-connect-woocommerce/" target="_blank">Genesis Connect for WooCommerce</a> to <strong>enable WooCommerce support for %s</strong>.', 'genesis-sample' ), wp_get_theme()->get( 'Name' ) );

if ( current_user_can( 'install_plugins' ) ) {
$plugin_slug = 'genesis-connect-woocommerce';
Expand All @@ -73,7 +73,7 @@ function genesis_sample_woocommerce_theme_notice() {
);

/* translators: 1: plugin install prompt presented as link, 2: child theme name */
$notice_html = sprintf( __( 'Please %1$s to <strong>enable WooCommerce support for %2$s</strong>.', 'genesis-sample' ), $install_link, esc_html( CHILD_THEME_NAME ) );
$notice_html = sprintf( __( 'Please %1$s to <strong>enable WooCommerce support for %2$s</strong>.', 'genesis-sample' ), $install_link, wp_get_theme()->get( 'Name' ) );
}

echo '<div class="notice notice-info is-dismissible genesis-sample-woocommerce-notice"><p>' . wp_kses_post( $notice_html ) . '</p></div>';
Expand Down

0 comments on commit 7142e6f

Please sign in to comment.