2020-01-26 12:53:20 +01:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Star Rating Block.
|
|
|
|
|
*
|
|
|
|
|
* @since 8.0.0
|
|
|
|
|
*
|
|
|
|
|
* @package Jetpack
|
|
|
|
|
*/
|
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
namespace Automattic\Jetpack\Extensions\Rating_Star;
|
|
|
|
|
|
|
|
|
|
use Jetpack_Gutenberg;
|
|
|
|
|
|
|
|
|
|
const FEATURE_NAME = 'rating-star';
|
|
|
|
|
const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
|
|
|
|
|
|
2020-01-26 12:53:20 +01:00
|
|
|
// Load generic function definitions.
|
|
|
|
|
require_once __DIR__ . '/rating-meta.php';
|
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
/**
|
|
|
|
|
* Registers the block for use in Gutenberg
|
|
|
|
|
* This is done via an action so that we can disable
|
|
|
|
|
* registration if we need to.
|
|
|
|
|
*/
|
|
|
|
|
function register_block() {
|
|
|
|
|
jetpack_register_block(
|
|
|
|
|
BLOCK_NAME,
|
|
|
|
|
array(
|
|
|
|
|
'render_callback' => __NAMESPACE__ . '\render_block',
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'rating' => array(
|
|
|
|
|
'type' => 'number',
|
|
|
|
|
'default' => 1,
|
|
|
|
|
),
|
|
|
|
|
'maxRating' => array(
|
|
|
|
|
'type' => 'number',
|
|
|
|
|
'default' => 5,
|
|
|
|
|
),
|
|
|
|
|
'color' => array(
|
|
|
|
|
'type' => 'string',
|
|
|
|
|
),
|
|
|
|
|
'ratingStyle' => array(
|
|
|
|
|
'type' => 'string',
|
|
|
|
|
'default' => 'star',
|
|
|
|
|
),
|
|
|
|
|
'className' => array(
|
|
|
|
|
'type' => 'string',
|
|
|
|
|
),
|
|
|
|
|
'align' => array(
|
|
|
|
|
'type' => 'string',
|
|
|
|
|
'default' => 'left',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
add_action( 'init', __NAMESPACE__ . '\register_block' );
|
|
|
|
|
|
2020-01-26 12:53:20 +01:00
|
|
|
/**
|
|
|
|
|
* Dynamic rendering of the block.
|
|
|
|
|
*
|
|
|
|
|
* @param array $attributes Array containing the block attributes.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2020-05-06 17:20:49 +02:00
|
|
|
function render_block( $attributes ) {
|
2020-01-26 12:53:20 +01:00
|
|
|
// Tell Jetpack to load the assets registered via jetpack_register_block.
|
2020-05-06 17:20:49 +02:00
|
|
|
Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME );
|
2020-01-26 12:53:20 +01:00
|
|
|
|
|
|
|
|
return jetpack_rating_meta_render_block( $attributes );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The following filter is added only to support the old 0.6.2 version of the AMP plugin.
|
|
|
|
|
* This entire section can be removed once we're on version a newer version.
|
|
|
|
|
* Confirmed that version 1.4.1 (or presumably newer) does not need this filter.
|
|
|
|
|
*/
|
2020-05-06 17:20:49 +02:00
|
|
|
function amp_add_inline_css() {
|
2020-01-26 12:53:20 +01:00
|
|
|
echo '.wp-block-jetpack-rating-star span { display: none; }';
|
|
|
|
|
}
|
2020-05-06 17:20:49 +02:00
|
|
|
add_action( 'amp_post_template_css', __NAMESPACE__ . '\amp_add_inline_css', 11 );
|
2020-01-26 12:53:20 +01:00
|
|
|
|