PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 14.8.1
Jetpack – WP Security, Backup, Speed, & Growth v14.8.1
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / extensions / blocks / recipe / class-jetpack-recipe-block.php
class-jetpack-recipe-block.php
88 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Jetpack Recipe Block
4 *
5 * @package automattic/jetpack
6 */
7
8 namespace Automattic\Jetpack\Extensions\Recipe;
9
10 use Jetpack_Gutenberg;
11
12 /**
13 * Jetpack Recipe Block class.
14 *
15 * Helper class that lets us add schema attributes dynamically because they are not something that is store with the content.
16 * Due to the limitations of wp_kses.
17 *
18 * @since 11.1
19 */
20 class Jetpack_Recipe_Block {
21 /**
22 * Adds recipe schema attributes.
23 *
24 * @param array $attr Array containing the recipe block attributes.
25 * @param string $content String containing the recipe block content.
26 *
27 * @return string
28 */
29 public static function render( $attr, $content ) {
30 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
31
32 $find = array(
33 '/(class="wp-block-jetpack-recipe(\s|"))/',
34 '/(class="wp-block-jetpack-recipe-title(\s|"))/',
35 '/(class="wp-block-jetpack-recipe-description(\s|"))/',
36 );
37 $replace = array(
38 'itemscope itemtype="https://schema.org/Recipe" ${1}',
39 'itemprop="name" ${1}',
40 'itemprop="description" ${1}',
41 );
42
43 return preg_replace( $find, $replace, $content );
44 }
45
46 /**
47 * Adds recipe hero schema attributes.
48 *
49 * @param array $attr Array containing the recipe-hero block attributes.
50 * @param string $content String containing the recipe-hero block content.
51 *
52 * @return string
53 */
54 public static function render_hero( $attr, $content ) {
55 $find = array(
56 '<img',
57 );
58 $replace = array(
59 '<img itemprop="image" ',
60 );
61
62 return str_replace( $find, $replace, $content );
63 }
64
65 /**
66 * Adds recipe step schema attributes.
67 *
68 * @param array $attr Array containing the recipe-step block attributes.
69 * @param string $content String containing the recipe-step block content.
70 *
71 * @return string
72 */
73 public static function render_step( $attr, $content ) {
74 $find = array(
75 'class="wp-block-jetpack-recipe-step-name"',
76 'class="wp-block-jetpack-recipe-step-desc"',
77 'class="wp-image',
78 );
79 $replace = array(
80 'itemprop="name" class="wp-block-jetpack-recipe-step-name"',
81 'itemprop="text" class="wp-block-jetpack-recipe-step-desc"',
82 'itemprop="image" class="wp-image',
83 );
84
85 return str_replace( $find, $replace, $content );
86 }
87 }
88