Make WordPress Themes

source: extendable/2.0.19/functions.php

Last change on this file was 264481, checked in by themedropbox, 8 months ago

New version of Extendable - 2.0.18

File size: 5.6 KB
Line 
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
12if ( ! defined( 'EXTENDABLE_THEME_VERSION' ) ) {
13        $theme_version = wp_get_theme()->get( 'Version' );
14        define( 'EXTENDABLE_THEME_VERSION', is_string( $theme_version ) ? $theme_version : '1.0.0' );
15}
16
17if ( ! function_exists( 'extendable_support' ) ) :
18
19        /**
20         * Sets up theme defaults and registers support for various WordPress features.
21         *
22         * @since Extendable 1.0
23         *
24         * @return void
25         */
26        function extendable_support() {
27
28                // Add support for block styles.
29                add_theme_support( 'wp-block-styles' );
30
31                global $wp_version;
32                // Add style for WordPress older versions.
33                if ( version_compare( $wp_version, '6.0.2', '<=' ) ) {
34                        $editor_style = array(
35                                'style.css',
36                                '/assets/css/deprecate-style.css',
37                        );
38                } else {
39                        $editor_style = 'style.css';
40                }
41                // Enqueue editor styles.
42                add_editor_style( $editor_style );
43        }
44
45endif;
46
47add_action( 'after_setup_theme', 'extendable_support' );
48
49if ( ! function_exists( 'extendable_styles' ) ) :
50
51        /**
52         * Enqueue styles.
53         *
54         * @since Extendable 1.0
55         *
56         * @return void
57         */
58        function extendable_styles() {
59
60                // Register theme stylesheet.
61                wp_register_style(
62                        'extendable-style',
63                        get_template_directory_uri() . '/style.css',
64                        array(),
65                        EXTENDABLE_THEME_VERSION
66                );
67
68                // Enqueue theme stylesheet.
69                wp_enqueue_style( 'extendable-style' );
70
71                global $wp_version;
72                if ( version_compare( $wp_version, '6.0.2', '<=' ) ) {
73                        // Register deprecate stylesheet.
74                        wp_register_style(
75                                'extendable-deprecate-style',
76                                get_template_directory_uri() . '/assets/css/deprecate-style.css',
77                                array(),
78                                EXTENDABLE_THEME_VERSION
79                        );
80                        // Enqueue deprecate stylesheet.
81                        wp_enqueue_style( 'extendable-deprecate-style' );
82                }
83        }
84
85endif;
86
87add_action( 'wp_enqueue_scripts', 'extendable_styles' );
88
89/**
90 * Enqueue block-specific styles.
91 *
92 * @since Extendable 2.0.11
93 *
94 * @return void
95 */
96function extendable_enqueue_block_styles() {
97        // Check for specific blocks and enqueue their styles
98        if ( has_block( 'contact-form-7/contact-form-selector' ) ) {
99                wp_enqueue_style(
100                        'extendable-contact-form-7-style',
101                        get_template_directory_uri() . '/assets/css/contact-form-7.css',
102                        array(),
103                        EXTENDABLE_THEME_VERSION
104                );
105        }
106
107        if ( has_block( 'wpforms/form-selector' ) ) {
108                wp_enqueue_style(
109                        'extendable-wpforms-style',
110                        get_template_directory_uri() . '/assets/css/wpforms.css',
111                        array(),
112                        EXTENDABLE_THEME_VERSION
113                );
114        }
115}
116
117add_action( 'enqueue_block_assets', 'extendable_enqueue_block_styles' );
118
119/**
120 * Registers pattern categories.
121 *
122 * @since Extendable 1.0
123 *
124 * @return void
125 */
126function extendable_register_pattern_categories() {
127        $block_pattern_categories = array(
128                'header' => array( 'label' => __( 'Headers', 'extendable' ) ),
129                'footer' => array( 'label' => __( 'Footers', 'extendable' ) ),
130        );
131
132        /**
133         * Filters the theme block pattern categories.
134         *
135         * @since Extendable 1.0
136         *
137         * @param array[] $block_pattern_categories {
138         *     An associative array of block pattern categories, keyed by category name.
139         *
140         *     @type array[] $properties {
141         *         An array of block category properties.
142         *
143         *         @type string $label A human-readable label for the pattern category.
144         *     }
145         * }
146         */
147        $block_pattern_categories = apply_filters( 'extendable_block_pattern_categories', $block_pattern_categories );
148
149        foreach ( $block_pattern_categories as $name => $properties ) {
150                if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
151                        register_block_pattern_category( $name, $properties );
152                }
153        }
154}
155add_action( 'init', 'extendable_register_pattern_categories', 9 );
156
157
158/**
159 * Enqueue dynamic CSS for primary-foreground duotone filter.
160 *
161 * Ensure default logo works well on light and dark backgrounds
162 *
163 * @since Extendable 2.0.11
164 *
165 * @return void
166 */
167function extendable_enqueue_dynamic_duotone_css() {
168    $theme_json      = WP_Theme_JSON_Resolver::get_merged_data();
169    $duotone_presets = $theme_json->get_settings()['color']['duotone']['theme'] ?? [];
170
171    $preset_index = array_search( 'primary-foreground', array_column( $duotone_presets, 'slug' ) );
172    $primary_color   = '#000000';
173    $foreground_color = '#ffffff';
174    if ( false !== $preset_index ) {
175        $primary_color   = $duotone_presets[ $preset_index ]['colors'][0];
176        $foreground_color = $duotone_presets[ $preset_index ]['colors'][1];
177    }
178    list( $r, $g, $b ) = array_map( fn( $c ) => hexdec( $c ) / 255, sscanf( $primary_color, "#%02x%02x%02x" ) );
179    $css = "
180        .wp-block-site-logo img[src*='extendify-demo-'] {
181            filter: url('data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\"><filter id=\"solid-color\"><feColorMatrix color-interpolation-filters=\"sRGB\" type=\"matrix\" values=\"0 0 0 0 {$r} 0 0 0 0 {$g} 0 0 0 0 {$b} 0 0 0 1 0\"/></filter></svg>#solid-color') !important;
182        }
183    ";
184    wp_add_inline_style( 'wp-block-library', $css );
185}
186add_action( 'wp_enqueue_scripts', 'extendable_enqueue_dynamic_duotone_css' );
187
188/**
189 * Enqueue custom admin CSS file when WooCommerce is not active.
190 *
191 * @since Extendable 2.0.18
192 *
193 * @return void
194 */
195function extendable_admin_custom_css() {
196    // Only enqueue the stylesheet if WooCommerce is not active.
197    if ( ! class_exists( 'WooCommerce' ) ) {
198        wp_enqueue_style(
199            'extendable-admin-custom-css',
200            get_stylesheet_directory_uri() . '/assets/css/admin-custom.css',
201            array(),
202            EXTENDABLE_THEME_VERSION
203        );
204    }
205}
206add_action( 'admin_enqueue_scripts', 'extendable_admin_custom_css' );
Note: See TracBrowser for help on using the repository browser.