diff --git a/functions.php b/functions.php index 88d274a..4c9e63a 100644 --- a/functions.php +++ b/functions.php @@ -137,17 +137,32 @@ function flash_block_editor_styles() { * @global int $content_width **/ function flash_content_width() { - $content_width = 780; + $GLOBALS['content_width'] = apply_filters( 'flash_content_width', 780 ); + } - $classes = flash_get_layout(); - if ( $classes == 'full-width' ) { - $content_width = 1200; - } + // Sets the theme's own default early, so wp-admin (image size caps, the block + // editor) and REST API requests -- which never reach template_redirect -- still + // get a value. + add_action( 'after_setup_theme', 'flash_content_width', 0 ); +endif; - $GLOBALS['content_width'] = apply_filters( 'flash_content_width', $content_width ); +if ( ! function_exists( 'flash_content_width_for_layout' ) ) : + /** + * Widen content_width for a full-width page's actual frontend render. + * + * Run on template_redirect, not after_setup_theme: flash_get_layout() relies + * on is_page()/is_single()/$post, which aren't reliable until the main query + * has been parsed. + * + * @global int $content_width + **/ + function flash_content_width_for_layout() { + if ( 'full-width' == flash_get_layout() ) { + $GLOBALS['content_width'] = apply_filters( 'flash_content_width', 1200 ); + } } - add_action( 'after_setup_theme', 'flash_content_width', 0 ); + add_action( 'template_redirect', 'flash_content_width_for_layout' ); endif; /** diff --git a/inc/extras.php b/inc/extras.php index 0541d2a..1b444ad 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -646,25 +646,3 @@ function flash_change_logo_attr( $attr, $attachment, $size ) { endif; add_filter( 'wp_get_attachment_image_attributes', 'flash_change_logo_attr', 10, 3 ); - -/** - * Compare user's current version of plugin. - */ -if ( ! function_exists( 'flash_plugin_version_compare' ) ) { - function flash_plugin_version_compare( $plugin_slug, $version_to_compare ) { - if ( ! function_exists( 'get_plugins' ) ) { - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - } - - $installed_plugins = get_plugins(); - - // Plugin not installed. - if ( ! isset( $installed_plugins[ $plugin_slug ] ) ) { - return false; - } - - $tdi_user_version = $installed_plugins[ $plugin_slug ]['Version']; - - return version_compare( $tdi_user_version, $version_to_compare, '<' ); - } -} diff --git a/inc/template-tags.php b/inc/template-tags.php index 346b6d8..7058fbc 100644 --- a/inc/template-tags.php +++ b/inc/template-tags.php @@ -101,7 +101,7 @@ function flash_categorized_blog() { // Count the number of categories that are attached to the posts. $all_the_cool_cats = count( $all_the_cool_cats ); - set_transient( 'flash_categories', $all_the_cool_cats ); + set_transient( 'flash_categories', $all_the_cool_cats, DAY_IN_SECONDS ); } if ( $all_the_cool_cats > 1 ) { @@ -124,4 +124,6 @@ function flash_category_transient_flusher() { delete_transient( 'flash_categories' ); } add_action( 'edit_category', 'flash_category_transient_flusher' ); -add_action( 'save_post', 'flash_category_transient_flusher' ); +add_action( 'save_post', 'flash_category_transient_flusher' ); +add_action( 'create_category', 'flash_category_transient_flusher' ); +add_action( 'delete_category', 'flash_category_transient_flusher' ); diff --git a/inc/woocommerce.php b/inc/woocommerce.php index 5a0f2ca..159e99a 100644 --- a/inc/woocommerce.php +++ b/inc/woocommerce.php @@ -51,16 +51,3 @@ function flash_woocommerce_header_add_to_cart_fragment( $fragments ) { $fragments['div.flash-cart-views'] = ob_get_clean(); return $fragments; } - -/** - * Check if the current viewed page is of WooCommerce - * - * @return void - */ -function flash_is_woocommerce_pages() { - if ( is_shop() || is_product() || is_product_category() || is_product_tag() ) { - return true; - } - - return false; -} \ No newline at end of file