| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Twenty Twenty-Four functions and definitions. |
|---|
| 4 | * |
|---|
| 5 | * @link https://developer.wordpress.org/themes/basics/theme-functions/ |
|---|
| 6 | * |
|---|
| 7 | * @package Twenty Twenty-Four |
|---|
| 8 | * @since Twenty Twenty-Four 1.0 |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * Register block styles. |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | if ( ! function_exists( 'twentytwentyfour_block_styles' ) ) : |
|---|
| 16 | /** |
|---|
| 17 | * Register custom block styles |
|---|
| 18 | * |
|---|
| 19 | * @since Twenty Twenty-Four 1.0 |
|---|
| 20 | * @return void |
|---|
| 21 | */ |
|---|
| 22 | function twentytwentyfour_block_styles() { |
|---|
| 23 | |
|---|
| 24 | register_block_style( |
|---|
| 25 | 'core/details', |
|---|
| 26 | array( |
|---|
| 27 | 'name' => 'arrow-icon-details', |
|---|
| 28 | 'label' => __( 'Arrow icon', 'twentytwentyfour' ), |
|---|
| 29 | |
|---|
| 30 | /* |
|---|
| 31 | * Styles for the custom Arrow icon style of the Details block. |
|---|
| 32 | */ |
|---|
| 33 | 'inline_style' => ' |
|---|
| 34 | .is-style-arrow-icon-details { |
|---|
| 35 | padding-top: var(--wp--preset--spacing--10); |
|---|
| 36 | padding-bottom: var(--wp--preset--spacing--10); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | .is-style-arrow-icon-details summary { |
|---|
| 40 | list-style-type: "\2193\00a0\00a0\00a0"; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | .is-style-arrow-icon-details[open]>summary { |
|---|
| 44 | list-style-type: "\2192\00a0\00a0\00a0"; |
|---|
| 45 | }', |
|---|
| 46 | ) |
|---|
| 47 | ); |
|---|
| 48 | register_block_style( |
|---|
| 49 | 'core/post-terms', |
|---|
| 50 | array( |
|---|
| 51 | 'name' => 'pill', |
|---|
| 52 | 'label' => __( 'Pill', 'twentytwentyfour' ), |
|---|
| 53 | |
|---|
| 54 | /* |
|---|
| 55 | * Styles variation for post terms. |
|---|
| 56 | * https://github.com/WordPress/gutenberg/issues/24956 |
|---|
| 57 | */ |
|---|
| 58 | 'inline_style' => ' |
|---|
| 59 | .is-style-pill a, |
|---|
| 60 | .is-style-pill span:not([class], [data-rich-text-placeholder]) { |
|---|
| 61 | display: inline-block; |
|---|
| 62 | background-color: var(--wp--preset--color--base-2); |
|---|
| 63 | padding: 0.375rem 0.875rem; |
|---|
| 64 | border-radius: var(--wp--preset--spacing--20); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | .is-style-pill a:hover { |
|---|
| 68 | background-color: var(--wp--preset--color--contrast-3); |
|---|
| 69 | }', |
|---|
| 70 | ) |
|---|
| 71 | ); |
|---|
| 72 | register_block_style( |
|---|
| 73 | 'core/list', |
|---|
| 74 | array( |
|---|
| 75 | 'name' => 'checkmark-list', |
|---|
| 76 | 'label' => __( 'Checkmark', 'twentytwentyfour' ), |
|---|
| 77 | |
|---|
| 78 | /* |
|---|
| 79 | * Styles for the custom checkmark list block style |
|---|
| 80 | * https://github.com/WordPress/gutenberg/issues/51480 |
|---|
| 81 | */ |
|---|
| 82 | 'inline_style' => ' |
|---|
| 83 | ul.is-style-checkmark-list { |
|---|
| 84 | list-style-type: "\2713"; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | ul.is-style-checkmark-list li { |
|---|
| 88 | padding-inline-start: 1ch; |
|---|
| 89 | }', |
|---|
| 90 | ) |
|---|
| 91 | ); |
|---|
| 92 | register_block_style( |
|---|
| 93 | 'core/navigation-link', |
|---|
| 94 | array( |
|---|
| 95 | 'name' => 'arrow-link', |
|---|
| 96 | 'label' => __( 'With arrow', 'twentytwentyfour' ), |
|---|
| 97 | |
|---|
| 98 | /* |
|---|
| 99 | * Styles for the custom arrow nav link block style. |
|---|
| 100 | */ |
|---|
| 101 | 'inline_style' => ' |
|---|
| 102 | .is-style-arrow-link .wp-block-navigation-item__label:after { |
|---|
| 103 | content: "\2197"; |
|---|
| 104 | padding-inline-start: 0.25rem; |
|---|
| 105 | vertical-align: middle; |
|---|
| 106 | text-decoration: none; |
|---|
| 107 | display: inline-block; |
|---|
| 108 | }', |
|---|
| 109 | ) |
|---|
| 110 | ); |
|---|
| 111 | register_block_style( |
|---|
| 112 | 'core/heading', |
|---|
| 113 | array( |
|---|
| 114 | 'name' => 'asterisk', |
|---|
| 115 | 'label' => __( 'With asterisk', 'twentytwentyfour' ), |
|---|
| 116 | 'inline_style' => " |
|---|
| 117 | .is-style-asterisk:before { |
|---|
| 118 | content: ''; |
|---|
| 119 | width: 1.5rem; |
|---|
| 120 | height: 3rem; |
|---|
| 121 | background: var(--wp--preset--color--contrast-2, currentColor); |
|---|
| 122 | clip-path: path('M11.93.684v8.039l5.633-5.633 1.216 1.23-5.66 5.66h8.04v1.737H13.2l5.701 5.701-1.23 1.23-5.742-5.742V21h-1.737v-8.094l-5.77 5.77-1.23-1.217 5.743-5.742H.842V9.98h8.162l-5.701-5.7 1.23-1.231 5.66 5.66V.684h1.737Z'); |
|---|
| 123 | display: block; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /* Hide the asterisk if the heading has no content, to avoid using empty headings to display the asterisk only, which is an A11Y issue */ |
|---|
| 127 | .is-style-asterisk:empty:before { |
|---|
| 128 | content: none; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | .is-style-asterisk:-moz-only-whitespace:before { |
|---|
| 132 | content: none; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | .is-style-asterisk.has-text-align-center:before { |
|---|
| 136 | margin: 0 auto; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | .is-style-asterisk.has-text-align-right:before { |
|---|
| 140 | margin-left: auto; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | .rtl .is-style-asterisk.has-text-align-left:before { |
|---|
| 144 | margin-right: auto; |
|---|
| 145 | }", |
|---|
| 146 | ) |
|---|
| 147 | ); |
|---|
| 148 | } |
|---|
| 149 | endif; |
|---|
| 150 | |
|---|
| 151 | add_action( 'init', 'twentytwentyfour_block_styles' ); |
|---|
| 152 | |
|---|
| 153 | /** |
|---|
| 154 | * Enqueue block stylesheets. |
|---|
| 155 | */ |
|---|
| 156 | |
|---|
| 157 | if ( ! function_exists( 'twentytwentyfour_block_stylesheets' ) ) : |
|---|
| 158 | /** |
|---|
| 159 | * Enqueue custom block stylesheets |
|---|
| 160 | * |
|---|
| 161 | * @since Twenty Twenty-Four 1.0 |
|---|
| 162 | * @return void |
|---|
| 163 | */ |
|---|
| 164 | function twentytwentyfour_block_stylesheets() { |
|---|
| 165 | /** |
|---|
| 166 | * The wp_enqueue_block_style() function allows us to enqueue a stylesheet |
|---|
| 167 | * for a specific block. These will only get loaded when the block is rendered |
|---|
| 168 | * (both in the editor and on the front end), improving performance |
|---|
| 169 | * and reducing the amount of data requested by visitors. |
|---|
| 170 | * |
|---|
| 171 | * See https://make.wordpress.org/core/2021/12/15/using-multiple-stylesheets-per-block/ for more info. |
|---|
| 172 | */ |
|---|
| 173 | wp_enqueue_block_style( |
|---|
| 174 | 'core/button', |
|---|
| 175 | array( |
|---|
| 176 | 'handle' => 'twentytwentyfour-button-style-outline', |
|---|
| 177 | 'src' => get_parent_theme_file_uri( 'assets/css/button-outline.css' ), |
|---|
| 178 | 'ver' => wp_get_theme( get_template() )->get( 'Version' ), |
|---|
| 179 | 'path' => get_parent_theme_file_path( 'assets/css/button-outline.css' ), |
|---|
| 180 | ) |
|---|
| 181 | ); |
|---|
| 182 | } |
|---|
| 183 | endif; |
|---|
| 184 | |
|---|
| 185 | add_action( 'init', 'twentytwentyfour_block_stylesheets' ); |
|---|
| 186 | |
|---|
| 187 | /** |
|---|
| 188 | * Register pattern categories. |
|---|
| 189 | */ |
|---|
| 190 | |
|---|
| 191 | if ( ! function_exists( 'twentytwentyfour_pattern_categories' ) ) : |
|---|
| 192 | /** |
|---|
| 193 | * Register pattern categories |
|---|
| 194 | * |
|---|
| 195 | * @since Twenty Twenty-Four 1.0 |
|---|
| 196 | * @return void |
|---|
| 197 | */ |
|---|
| 198 | function twentytwentyfour_pattern_categories() { |
|---|
| 199 | |
|---|
| 200 | register_block_pattern_category( |
|---|
| 201 | 'page', |
|---|
| 202 | array( |
|---|
| 203 | 'label' => _x( 'Pages', 'Block pattern category' ), |
|---|
| 204 | 'description' => __( 'A collection of full page layouts.' ), |
|---|
| 205 | ) |
|---|
| 206 | ); |
|---|
| 207 | } |
|---|
| 208 | endif; |
|---|
| 209 | |
|---|
| 210 | add_action( 'init', 'twentytwentyfour_pattern_categories' ); |
|---|