1
|
|
|
<?php |
2
|
|
|
/** Blocks package. |
3
|
|
|
* |
4
|
|
|
* @since 9.0.0 |
5
|
|
|
* |
6
|
|
|
* This package lifts elements from Jetpack's Jetpack_Gutenberg class. |
7
|
|
|
* It is now an standalone package reusable outside Jetpack. |
8
|
|
|
* |
9
|
|
|
* @package automattic/jetpack-blocks |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Automattic\Jetpack; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Register and manage blocks within a plugin. Used to manage block registration, enqueues, and more. |
16
|
|
|
* |
17
|
|
|
* @since 9.0.0 |
18
|
|
|
*/ |
19
|
|
|
class Blocks { |
20
|
|
|
/** |
21
|
|
|
* Get CSS classes for a block. |
22
|
|
|
* |
23
|
|
|
* @since 9.0.0 |
24
|
|
|
* |
25
|
|
|
* @param string $slug Block slug. |
26
|
|
|
* @param array $attr Block attributes. |
27
|
|
|
* @param array $extra Potential extra classes you may want to provide. |
28
|
|
|
* |
29
|
|
|
* @return string $classes List of CSS classes for a block. |
30
|
|
|
*/ |
31
|
|
|
public static function classes( $slug, $attr, $extra = array() ) { |
32
|
|
|
if ( empty( $slug ) ) { |
33
|
|
|
return ''; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Basic block name class. |
37
|
|
|
$classes = array( |
38
|
|
|
'wp-block-jetpack-' . $slug, |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
// Add alignment if provided. |
42
|
|
View Code Duplication |
if ( |
43
|
|
|
! empty( $attr['align'] ) |
44
|
|
|
&& in_array( $attr['align'], array( 'left', 'center', 'right', 'wide', 'full' ), true ) |
45
|
|
|
) { |
46
|
|
|
$classes[] = 'align' . $attr['align']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// Add custom classes if provided in the block editor. |
50
|
|
|
if ( ! empty( $attr['className'] ) ) { |
51
|
|
|
$classes[] = $attr['className']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Add any extra classes. |
55
|
|
View Code Duplication |
if ( is_array( $extra ) && ! empty( $extra ) ) { |
56
|
|
|
$classes = array_merge( $classes, array_filter( $extra ) ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return implode( ' ', $classes ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Does the page return AMP content. |
64
|
|
|
* |
65
|
|
|
* @return bool $is_amp_request Are we on an AMP view. |
66
|
|
|
*/ |
67
|
|
|
public static function is_amp_request() { |
68
|
|
|
$is_amp_request = ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ); |
69
|
|
|
|
70
|
|
|
/** This filter is documented in 3rd-party/class.jetpack-amp-support.php */ |
71
|
|
|
return apply_filters( 'jetpack_is_amp_request', $is_amp_request ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|