| 1 |
<?php |
| 2 |
/** |
| 3 |
* Star Rating Block. |
| 4 |
* |
| 5 |
* @since 8.0.0 |
| 6 |
* |
| 7 |
* @package automattic/jetpack |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Automattic\Jetpack\Extensions\Rating_Star; |
| 11 |
|
| 12 |
use Automattic\Jetpack\Blocks; |
| 13 |
use Jetpack_Gutenberg; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit( 0 ); |
| 17 |
} |
| 18 |
|
| 19 |
// Load generic function definitions. |
| 20 |
require_once __DIR__ . '/rating-meta.php'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Registers the block for use in Gutenberg |
| 24 |
* This is done via an action so that we can disable |
| 25 |
* registration if we need to. |
| 26 |
*/ |
| 27 |
function register_block() { |
| 28 |
Blocks::jetpack_register_block( |
| 29 |
__DIR__, |
| 30 |
array( |
| 31 |
'render_callback' => __NAMESPACE__ . '\render_block', |
| 32 |
) |
| 33 |
); |
| 34 |
} |
| 35 |
add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 36 |
|
| 37 |
/** |
| 38 |
* Dynamic rendering of the block. |
| 39 |
* |
| 40 |
* @param array $attributes Array containing the block attributes. |
| 41 |
* |
| 42 |
* @return string |
| 43 |
*/ |
| 44 |
function render_block( $attributes ) { |
| 45 |
// Tell Jetpack to load the assets registered via jetpack_register_block. |
| 46 |
Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); |
| 47 |
|
| 48 |
return jetpack_rating_meta_render_block( $attributes ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Older versions of AMP (0.6.2) are unable to render the markup, so we hide it |
| 53 |
* Newer versions of AMP (1.4.1+) seem OK, but need the screen-reader text hidden |
| 54 |
*/ |
| 55 |
function amp_add_inline_css() { |
| 56 |
if ( defined( 'AMP__VERSION' ) && version_compare( AMP__VERSION, '1.4.1', '>=' ) ) { |
| 57 |
echo '.wp-block-jetpack-rating-star span.screen-reader-text { border: 0; clip-path: inset(50%); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; word-wrap: normal; }'; |
| 58 |
} else { |
| 59 |
echo '.wp-block-jetpack-rating-star span:not([aria-hidden="true"]) { display: none; }'; |
| 60 |
} |
| 61 |
} |
| 62 |
add_action( 'amp_post_template_css', __NAMESPACE__ . '\amp_add_inline_css', 11 ); |
| 63 |
|