| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Extendable functions and definitions |
|---|
| 4 | * |
|---|
| 5 | * @link https://developer.wordpress.org/themes/basics/theme-functions/ |
|---|
| 6 | * |
|---|
| 7 | * @package Extendable |
|---|
| 8 | * @since Extendable 1.0 |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | if ( ! function_exists( 'extendable_support' ) ) : |
|---|
| 12 | |
|---|
| 13 | /** |
|---|
| 14 | * Sets up theme defaults and registers support for various WordPress features. |
|---|
| 15 | * |
|---|
| 16 | * @since Extendable 1.0 |
|---|
| 17 | * |
|---|
| 18 | * @return void |
|---|
| 19 | */ |
|---|
| 20 | function extendable_support() { |
|---|
| 21 | |
|---|
| 22 | // Add support for block styles. |
|---|
| 23 | add_theme_support( 'wp-block-styles' ); |
|---|
| 24 | |
|---|
| 25 | // Enqueue editor styles. |
|---|
| 26 | add_editor_style( 'style.css' ); |
|---|
| 27 | |
|---|
| 28 | // Register WooCommerce theme features. |
|---|
| 29 | add_theme_support( 'wc-product-gallery-zoom' ); |
|---|
| 30 | add_theme_support( 'wc-product-gallery-lightbox' ); |
|---|
| 31 | add_theme_support( 'wc-product-gallery-slider' ); |
|---|
| 32 | add_theme_support( |
|---|
| 33 | 'woocommerce', |
|---|
| 34 | array( |
|---|
| 35 | 'thumbnail_image_width' => 400, |
|---|
| 36 | 'single_image_width' => 600, |
|---|
| 37 | ) |
|---|
| 38 | ); |
|---|
| 39 | |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | endif; |
|---|
| 43 | |
|---|
| 44 | add_action( 'after_setup_theme', 'extendable_support' ); |
|---|
| 45 | |
|---|
| 46 | if ( ! function_exists( 'extendable_styles' ) ) : |
|---|
| 47 | |
|---|
| 48 | /** |
|---|
| 49 | * Enqueue styles. |
|---|
| 50 | * |
|---|
| 51 | * @since Extendable 1.0 |
|---|
| 52 | * |
|---|
| 53 | * @return void |
|---|
| 54 | */ |
|---|
| 55 | function extendable_styles() { |
|---|
| 56 | |
|---|
| 57 | // Register theme stylesheet. |
|---|
| 58 | $theme_version = wp_get_theme()->get( 'Version' ); |
|---|
| 59 | |
|---|
| 60 | $version_string = is_string( $theme_version ) ? $theme_version : false; |
|---|
| 61 | wp_register_style( |
|---|
| 62 | 'extendable-style', |
|---|
| 63 | get_template_directory_uri() . '/style.css', |
|---|
| 64 | array(), |
|---|
| 65 | $version_string |
|---|
| 66 | ); |
|---|
| 67 | |
|---|
| 68 | // Enqueue theme stylesheet. |
|---|
| 69 | wp_enqueue_style( 'extendable-style' ); |
|---|
| 70 | |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | endif; |
|---|
| 74 | |
|---|
| 75 | add_action( 'wp_enqueue_scripts', 'extendable_styles' ); |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | * Registers pattern categories. |
|---|
| 79 | * |
|---|
| 80 | * @since Extendable 1.0 |
|---|
| 81 | * |
|---|
| 82 | * @return void |
|---|
| 83 | */ |
|---|
| 84 | function extendable_register_pattern_categories() { |
|---|
| 85 | $block_pattern_categories = array( |
|---|
| 86 | 'header' => array( 'label' => __( 'Headers', 'extendable' ) ), |
|---|
| 87 | 'footer' => array( 'label' => __( 'Footers', 'extendable' ) ), |
|---|
| 88 | ); |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * Filters the theme block pattern categories. |
|---|
| 92 | * |
|---|
| 93 | * @since Extendable 1.0 |
|---|
| 94 | * |
|---|
| 95 | * @param array[] $block_pattern_categories { |
|---|
| 96 | * An associative array of block pattern categories, keyed by category name. |
|---|
| 97 | * |
|---|
| 98 | * @type array[] $properties { |
|---|
| 99 | * An array of block category properties. |
|---|
| 100 | * |
|---|
| 101 | * @type string $label A human-readable label for the pattern category. |
|---|
| 102 | * } |
|---|
| 103 | * } |
|---|
| 104 | */ |
|---|
| 105 | $block_pattern_categories = apply_filters( 'extendable_block_pattern_categories', $block_pattern_categories ); |
|---|
| 106 | |
|---|
| 107 | foreach ( $block_pattern_categories as $name => $properties ) { |
|---|
| 108 | if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) { |
|---|
| 109 | register_block_pattern_category( $name, $properties ); |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | } |
|---|
| 114 | add_action( 'init', 'extendable_register_pattern_categories', 9 ); |
|---|
| 115 | |
|---|
| 116 | if ( ! function_exists( 'is_woocommerce_activated' ) ) { |
|---|
| 117 | // This theme does not have a traditional sidebar. |
|---|
| 118 | remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 ); |
|---|
| 119 | |
|---|
| 120 | /** |
|---|
| 121 | * Alter the queue for WooCommerce styles and scripts. |
|---|
| 122 | * |
|---|
| 123 | * @since Extendable 1.0.5 |
|---|
| 124 | * |
|---|
| 125 | * @param array $styles Array of registered styles. |
|---|
| 126 | * |
|---|
| 127 | * @return array |
|---|
| 128 | */ |
|---|
| 129 | function extendable_woocommerce_enqueue_styles( $styles ) { |
|---|
| 130 | // Get a theme version for cache busting. |
|---|
| 131 | $theme_version = wp_get_theme()->get( 'Version' ); |
|---|
| 132 | $version_string = is_string( $theme_version ) ? $theme_version : false; |
|---|
| 133 | |
|---|
| 134 | // Add Extendable's WooCommerce styles. |
|---|
| 135 | $styles['extendable-woocommerce'] = array( |
|---|
| 136 | 'src' => get_template_directory_uri() . '/assets/css/woocommerce.css', |
|---|
| 137 | 'deps' => '', |
|---|
| 138 | 'version' => $version_string, |
|---|
| 139 | 'media' => 'all', |
|---|
| 140 | 'has_rtl' => true, |
|---|
| 141 | ); |
|---|
| 142 | |
|---|
| 143 | return apply_filters( 'woocommerce_extendable_styles', $styles ); |
|---|
| 144 | } |
|---|
| 145 | add_filter( 'woocommerce_enqueue_styles', 'extendable_woocommerce_enqueue_styles' ); |
|---|
| 146 | } |
|---|