← All changes
|
extensions/blocks/contact-info/class-jetpack-contact-info-block.php
+43
-2
13.2.4
→
16.3
View file →
| @@ -4,8 +4,10 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | +use Automattic\Jetpack\Blocks; | |
| 9 | + | |
| 8 | 10 | /** |
| 9 | 11 | * Helper class that lets us add schema attributes dynamically because they are not something that is store with the content. |
| 10 | 12 | * Due to the limitations of wp_kses. |
| 11 | 13 | * |
| @@ -13,8 +15,47 @@ | ||
| 13 | 15 | */ |
| 14 | 16 | class Jetpack_Contact_Info_Block { |
| 15 | 17 | |
| 16 | 18 | /** |
| 19 | + * Registers the block for use in Gutenberg | |
| 20 | + * This is done via an action so that we can disable | |
| 21 | + * registration if we need to. | |
| 22 | + */ | |
| 23 | + public static function register_block() { | |
| 24 | + | |
| 25 | + Blocks::jetpack_register_block( | |
| 26 | + __DIR__, | |
| 27 | + array( | |
| 28 | + 'render_callback' => __NAMESPACE__ . '\render', | |
| 29 | + ) | |
| 30 | + ); | |
| 31 | + | |
| 32 | + Blocks::jetpack_register_block( | |
| 33 | + 'jetpack/address', | |
| 34 | + array( | |
| 35 | + 'parent' => array( 'jetpack/contact-info' ), | |
| 36 | + 'render_callback' => __NAMESPACE__ . '\render_adress', | |
| 37 | + ) | |
| 38 | + ); | |
| 39 | + | |
| 40 | + Blocks::jetpack_register_block( | |
| 41 | + 'jetpack/email', | |
| 42 | + array( | |
| 43 | + 'parent' => array( 'jetpack/contact-info' ), | |
| 44 | + 'render_callback' => __NAMESPACE__ . '\render_email', | |
| 45 | + ) | |
| 46 | + ); | |
| 47 | + | |
| 48 | + Blocks::jetpack_register_block( | |
| 49 | + 'jetpack/phone', | |
| 50 | + array( | |
| 51 | + 'parent' => array( 'jetpack/contact-info' ), | |
| 52 | + 'render_callback' => __NAMESPACE__ . '\render_phone', | |
| 53 | + ) | |
| 54 | + ); | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 17 | 58 | * Adds contact info schema attributes. |
| 18 | 59 | * |
| 19 | 60 | * @param array $attr Array containing the contact info block attributes. |
| 20 | 61 | * @param string $content String containing the contact info block content. |
| @@ -21,9 +62,9 @@ | ||
| 21 | 62 | * |
| 22 | 63 | * @return string |
| 23 | 64 | */ |
| 24 | 65 | public static function render( $attr, $content ) { |
| 25 | - Jetpack_Gutenberg::load_styles_as_required( __DIR__ ); | |
| 66 | + Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); | |
| 26 | 67 | return str_replace( |
| 27 | 68 | 'class="wp-block-jetpack-contact-info', // Closing " intentionally ommited to that the user can also add the className as expected. |
| 28 | 69 | 'itemprop="location" itemscope itemtype="http://schema.org/Organization" class="wp-block-jetpack-contact-info', |
| 29 | 70 | $content |
| @@ -69,9 +110,9 @@ | ||
| 69 | 110 | * |
| 70 | 111 | * @param array $attr Array containing the block attributes. |
| 71 | 112 | * @param array $omit Array containing the block attributes that we ignore. |
| 72 | 113 | * |
| 73 | - * @return string | |
| 114 | + * @return bool | |
| 74 | 115 | */ |
| 75 | 116 | public static function has_attributes( $attr, $omit = array() ) { |
| 76 | 117 | foreach ( $attr as $attribute => $value ) { |
| 77 | 118 | if ( ! in_array( $attribute, $omit, true ) && ! empty( $value ) ) { |