PluginProbe
Getwid – Gutenberg Blocks / 3.0.1
Getwid – Gutenberg Blocks v3.0.1
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
getwid / includes / blocks / advanced-heading.php

advanced-heading.php in Getwid – Gutenberg Blocks 3.0.1, at includes/blocks/advanced-heading.php

79 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Getwid\Blocks;
4
5 class AdvancedHeading extends AbstractBlock {
6
7 public function __construct() {
8
9 parent::__construct( 'getwid/advanced-heading' );
10
11 register_block_type(
12 getwid_get_plugin_path( 'assets/blocks/advanced-heading' ),
13 array(
14 'render_callback' => array( $this, 'render_callback' ),
15 )
16 );
17 }
18
19 public function get_label() {
20 return __( 'Advanced Heading', 'getwid' );
21 }
22
23 public function render_callback( $attributes, $content ) {
24
25 if (
26 isset( $attributes['fontWeight'] ) &&
27 ( 'regular' === $attributes['fontWeight'] || 'normal' === $attributes['fontWeight'] )
28 ) {
29 $attributes['fontWeight'] = '400';
30 }
31
32 if ( $this->should_load_google_font( $attributes ) ) {
33 $font_family = $attributes['fontFamily'];
34 $font_family_handle = strtolower( preg_replace( '/\s+/', '_', $font_family ) );
35 $font_weight = '';
36 $font_weight_handle = '';
37 $font_weight_part = '';
38
39 if ( isset( $attributes['fontWeight'] ) && '400' !== $attributes['fontWeight'] ) {
40 $font_weight = $attributes['fontWeight'];
41 $font_weight_handle = '_' . $font_weight;
42 $font_weight_part = ':' . $font_weight;
43 }
44
45 wp_enqueue_style(
46 'google-font-' . esc_attr( $font_family_handle ) . esc_attr( $font_weight_handle ),
47 'https://fonts.googleapis.com/css?family=' . esc_attr( $font_family ) . esc_attr( $font_weight_part ),
48 null,
49 getwid()->settings()->getVersion()
50 );
51 }
52
53 return $content;
54 }
55
56 private function should_load_google_font( $attributes ) {
57
58 $should_load = false;
59
60 if ( isset( $attributes['fontFamily'] ) && ! empty( $attributes['fontFamily'] ) ) {
61 $should_load = true;
62 }
63
64 if (
65 $should_load &&
66 isset( $attributes['fontGroupID'] ) &&
67 'google-fonts' !== $attributes['fontGroupID']
68 ) {
69 $should_load = false;
70 }
71
72 return $should_load;
73 }
74 }
75
76 getwid()->blocksManager()->addBlock(
77 new AdvancedHeading()
78 );
79