From 7142e6f561ad49f156da031404441184c618b02f Mon Sep 17 00:00:00 2001 From: Nick Cernis Date: Thu, 14 Mar 2019 12:05:51 +0100 Subject: [PATCH] Drop deprecated CHILD_THEME_NAME constant and use CHILD_THEME_HANDLE 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 https://github.com/studiopress/genesis/pull/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: https://github.com/studiopress/genesis-sample/issues/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. https://github.com/studiopress/genesis/pull/2199#issuecomment-470190883. --- functions.php | 4 ++-- lib/gutenberg/init.php | 4 +--- lib/gutenberg/inline-styles.php | 3 +-- lib/output.php | 4 +--- lib/woocommerce/woocommerce-notice.php | 4 ++-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/functions.php b/functions.php index af5993ac..91eb0cd7 100755 --- a/functions.php +++ b/functions.php @@ -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. diff --git a/lib/gutenberg/init.php b/lib/gutenberg/init.php index 35805068..fb0b6308 100644 --- a/lib/gutenberg/init.php +++ b/lib/gutenberg/init.php @@ -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 ); diff --git a/lib/gutenberg/inline-styles.php b/lib/gutenberg/inline-styles.php index 40c23a12..cafb5e70 100644 --- a/lib/gutenberg/inline-styles.php +++ b/lib/gutenberg/inline-styles.php @@ -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 ); } diff --git a/lib/output.php b/lib/output.php index 3a21874a..ab78bb25 100644 --- a/lib/output.php +++ b/lib/output.php @@ -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' ); @@ -149,7 +147,7 @@ function genesis_sample_css() { ) : ''; if ( $css ) { - wp_add_inline_style( $handle, $css ); + wp_add_inline_style( CHILD_THEME_HANDLE, $css ); } } diff --git a/lib/woocommerce/woocommerce-notice.php b/lib/woocommerce/woocommerce-notice.php index 4d663481..4107bc0c 100644 --- a/lib/woocommerce/woocommerce-notice.php +++ b/lib/woocommerce/woocommerce-notice.php @@ -52,7 +52,7 @@ function genesis_sample_woocommerce_theme_notice() { } /* translators: %s: child theme name */ - $notice_html = sprintf( __( 'Please install and activate Genesis Connect for WooCommerce to enable WooCommerce support for %s.', 'genesis-sample' ), esc_html( CHILD_THEME_NAME ) ); + $notice_html = sprintf( __( 'Please install and activate Genesis Connect for WooCommerce to enable WooCommerce support for %s.', 'genesis-sample' ), wp_get_theme()->get( 'Name' ) ); if ( current_user_can( 'install_plugins' ) ) { $plugin_slug = 'genesis-connect-woocommerce'; @@ -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 enable WooCommerce support for %2$s.', 'genesis-sample' ), $install_link, esc_html( CHILD_THEME_NAME ) ); + $notice_html = sprintf( __( 'Please %1$s to enable WooCommerce support for %2$s.', 'genesis-sample' ), $install_link, wp_get_theme()->get( 'Name' ) ); } echo '

' . wp_kses_post( $notice_html ) . '

';