| @@ -46,39 +46,42 @@ | ||
| 46 | 46 | * @return void |
| 47 | 47 | */ |
| 48 | 48 | public function register_setting_fields() { |
| 49 | 49 | // Setting fields. |
| 50 | + // phpcs:disable PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic | |
| 50 | 51 | register_setting( |
| 51 | - 'boldblocks', | |
| 52 | - 'boldblocks_enable_typography', | |
| 52 | + 'cbb', | |
| 53 | + 'cbb_enable_typography', | |
| 53 | 54 | [ |
| 54 | - 'type' => 'boolean', | |
| 55 | - 'show_in_rest' => [ | |
| 55 | + 'type' => 'boolean', | |
| 56 | + 'sanitize_callback' => 'rest_sanitize_boolean', | |
| 57 | + 'show_in_rest' => [ | |
| 56 | 58 | 'name' => 'EnableTypography', |
| 57 | 59 | ], |
| 58 | - 'default' => false, | |
| 60 | + 'default' => false, | |
| 59 | 61 | ] |
| 60 | 62 | ); |
| 61 | 63 | |
| 62 | 64 | register_setting( |
| 63 | - 'boldblocks', | |
| 64 | - 'boldblocks_use_bunny_fonts', | |
| 65 | + 'cbb', | |
| 66 | + 'cbb_use_bunny_fonts', | |
| 65 | 67 | [ |
| 66 | - 'type' => 'boolean', | |
| 67 | - 'show_in_rest' => [ | |
| 68 | + 'type' => 'boolean', | |
| 69 | + 'sanitize_callback' => 'rest_sanitize_boolean', | |
| 70 | + 'show_in_rest' => [ | |
| 68 | 71 | 'name' => 'UseBunnyFonts', |
| 69 | 72 | ], |
| 70 | - 'default' => false, | |
| 73 | + 'default' => false, | |
| 71 | 74 | ] |
| 72 | 75 | ); |
| 73 | 76 | |
| 74 | 77 | register_setting( |
| 75 | - 'boldblocks', | |
| 76 | - 'boldblocks_typography', | |
| 78 | + 'cbb', | |
| 79 | + 'cbb_typography', | |
| 77 | 80 | [ |
| 78 | 81 | 'type' => 'object', |
| 79 | 82 | 'show_in_rest' => array( |
| 80 | - 'name' => 'BoldBlocksTypography', | |
| 83 | + 'name' => 'CBBTypography', | |
| 81 | 84 | 'schema' => array( |
| 82 | 85 | 'type' => 'object', |
| 83 | 86 | 'properties' => array( |
| 84 | 87 | 'fonts' => array( |
| @@ -91,8 +94,9 @@ | ||
| 91 | 94 | ), |
| 92 | 95 | ), |
| 93 | 96 | ] |
| 94 | 97 | ); |
| 98 | + // phpcs:enable PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic | |
| 95 | 99 | |
| 96 | 100 | register_meta( |
| 97 | 101 | 'post', |
| 98 | 102 | 'boldblocks_typography', |
| @@ -99,9 +103,9 @@ | ||
| 99 | 103 | [ |
| 100 | 104 | 'single' => true, |
| 101 | 105 | 'type' => 'object', |
| 102 | 106 | 'show_in_rest' => array( |
| 103 | - 'name' => 'BoldBlocksTypography', | |
| 107 | + 'name' => 'CBBTypography', | |
| 104 | 108 | 'schema' => array( |
| 105 | 109 | 'type' => 'object', |
| 106 | 110 | 'additionalProperties' => array( |
| 107 | 111 | 'type' => 'string', |
| @@ -209,14 +213,15 @@ | ||
| 209 | 213 | * @param boolean $is_editor |
| 210 | 214 | * @return void |
| 211 | 215 | */ |
| 212 | 216 | private function enqueue_custom_fonts( $post_id, $is_editor = false ) { |
| 213 | - $use_bunny_fonts = get_option( 'boldblocks_use_bunny_fonts' ); | |
| 217 | + $use_bunny_fonts = get_option( 'cbb_use_bunny_fonts' ); | |
| 214 | 218 | |
| 215 | 219 | $fonts_url = $this->get_fonts_url( $post_id, $use_bunny_fonts ); |
| 216 | 220 | if ( $fonts_url ) { |
| 217 | 221 | $prefix = $is_editor ? 'https:' : ''; |
| 218 | 222 | $service_url = $use_bunny_fonts ? '//fonts.bunny.net/css?family=' : '//fonts.googleapis.com/css2?'; |
| 223 | + // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 219 | 224 | wp_enqueue_style( 'boldblocks-custom-fonts', $prefix . $service_url . $fonts_url, [], null ); |
| 220 | 225 | |
| 221 | 226 | $typography_style = $this->get_typography_style( $post_id, $is_editor ); |
| 222 | 227 | wp_add_inline_style( 'boldblocks-custom-fonts', $typography_style ); |
| @@ -240,9 +245,9 @@ | ||
| 240 | 245 | * @return array $urls URLs to print for resource hints. |
| 241 | 246 | */ |
| 242 | 247 | public function preconnect_fonts( $urls, $relation_type ) { |
| 243 | 248 | if ( wp_style_is( 'boldblocks-custom-fonts', 'queue' ) && 'preconnect' === $relation_type ) { |
| 244 | - $use_bunny_fonts = get_option( 'boldblocks_use_bunny_fonts' ); | |
| 249 | + $use_bunny_fonts = get_option( 'cbb_use_bunny_fonts' ); | |
| 245 | 250 | |
| 246 | 251 | $urls[] = array( |
| 247 | 252 | 'href' => $use_bunny_fonts ? '//fonts.bunny.net' : '//fonts.gstatic.com', |
| 248 | 253 | 'crossorigin', |
| @@ -261,8 +266,9 @@ | ||
| 261 | 266 | $wp_styles = wp_styles(); |
| 262 | 267 | $style = $wp_styles->query( 'boldblocks-custom-fonts', 'registered' ); |
| 263 | 268 | |
| 264 | 269 | if ( $style ) { |
| 270 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 265 | 271 | echo "<link rel='preload' as='style' href='{$style->src}'/>"; |
| 266 | 272 | } |
| 267 | 273 | } |
| 268 | 274 | |
| @@ -459,9 +465,9 @@ | ||
| 459 | 465 | * @param int $post_id |
| 460 | 466 | * @return mixed |
| 461 | 467 | */ |
| 462 | 468 | private function get_custom_typography( $post_id = 0 ) { |
| 463 | - $enable_typography = get_option( 'boldblocks_enable_typography' ); | |
| 469 | + $enable_typography = \get_option( 'cbb_enable_typography' ); | |
| 464 | 470 | |
| 465 | 471 | if ( ! $enable_typography ) { |
| 466 | 472 | return false; |
| 467 | 473 | } |
| @@ -467,9 +473,9 @@ | ||
| 467 | 473 | } |
| 468 | 474 | |
| 469 | 475 | $typography_raw = $post_id > 0 ? get_post_meta( $post_id, 'boldblocks_typography', true ) : false; |
| 470 | 476 | if ( empty( $typography_raw ) || ! is_array( $typography_raw ) || empty( $typography_raw['fonts'] ) ) { |
| 471 | - $typography_raw = \get_option( 'boldblocks_typography' ); | |
| 477 | + $typography_raw = \get_option( 'cbb_typography' ); | |
| 472 | 478 | } |
| 473 | 479 | |
| 474 | 480 | if ( ! is_array( $typography_raw ) || empty( $typography_raw['fonts'] ) ) { |
| 475 | 481 | return; |
| @@ -490,9 +496,9 @@ | ||
| 490 | 496 | * @param array $classes |
| 491 | 497 | * @return string |
| 492 | 498 | */ |
| 493 | 499 | public function add_typography_to_body_class( $classes ) { |
| 494 | - $enable_typography = get_option( 'boldblocks_enable_typography' ); | |
| 500 | + $enable_typography = get_option( 'cbb_enable_typography' ); | |
| 495 | 501 | |
| 496 | 502 | if ( $enable_typography ) { |
| 497 | 503 | $classes[] = 'has-boldblocks-typography'; |
| 498 | 504 | } |