summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury German <blueknight@gentoo.org>2022-01-23 18:37:36 -0500
committerYury German <blueknight@gentoo.org>2022-01-23 18:37:36 -0500
commitf18b23a3a9378fb0a98856d436aa9ebf94e47429 (patch)
treee418433e22854ebd2d77eaa869d5d0470a973317 /plugins/jetpack/extensions/blocks/slideshow/slideshow.php
parentAdd classic-editor 1.5 (diff)
downloadblogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.gz
blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.bz2
blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.zip
Updating Classic Editor, Google Authenticatior, Jetpack, Public Post Preview, Table of Contents, Wordpress Importer
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/extensions/blocks/slideshow/slideshow.php')
-rw-r--r--plugins/jetpack/extensions/blocks/slideshow/slideshow.php71
1 files changed, 44 insertions, 27 deletions
diff --git a/plugins/jetpack/extensions/blocks/slideshow/slideshow.php b/plugins/jetpack/extensions/blocks/slideshow/slideshow.php
index ba18661c..bef76ed3 100644
--- a/plugins/jetpack/extensions/blocks/slideshow/slideshow.php
+++ b/plugins/jetpack/extensions/blocks/slideshow/slideshow.php
@@ -4,15 +4,29 @@
*
* @since 7.1.0
*
- * @package Jetpack
+ * @package automattic/jetpack
*/
-jetpack_register_block(
- 'jetpack/slideshow',
- array(
- 'render_callback' => 'jetpack_slideshow_block_load_assets',
- )
-);
+namespace Automattic\Jetpack\Extensions\Slideshow;
+
+use Automattic\Jetpack\Blocks;
+use Jetpack_Gutenberg;
+
+const FEATURE_NAME = 'slideshow';
+const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
+
+/**
+ * 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() {
+ Blocks::jetpack_register_block(
+ BLOCK_NAME,
+ array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
+ );
+}
+add_action( 'init', __NAMESPACE__ . '\register_block' );
/**
* Slideshow block registration/dependency declaration.
@@ -22,10 +36,10 @@ jetpack_register_block(
*
* @return string
*/
-function jetpack_slideshow_block_load_assets( $attr, $content ) {
- Jetpack_Gutenberg::load_assets_as_required( 'slideshow' );
- if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
- return jetpack_slideshow_block_render_amp( $attr );
+function load_assets( $attr, $content ) {
+ Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME );
+ if ( Blocks::is_amp_request() ) {
+ return render_amp( $attr );
}
return $content;
}
@@ -37,27 +51,30 @@ function jetpack_slideshow_block_load_assets( $attr, $content ) {
*
* @return string
*/
-function jetpack_slideshow_block_render_amp( $attr ) {
+function render_amp( $attr ) {
+ if ( empty( $attr['ids'] ) ) {
+ return '';
+ }
+
static $wp_block_jetpack_slideshow_id = 0;
$wp_block_jetpack_slideshow_id++;
- $ids = empty( $attr['ids'] ) ? array() : $attr['ids'];
- $autoplay = empty( $attr['autoplay'] ) ? false : $attr['autoplay'];
-
- $extras = array(
+ $ids = $attr['ids'];
+ $autoplay = empty( $attr['autoplay'] ) ? false : true;
+ $extras = array(
'wp-amp-block',
$autoplay ? 'wp-block-jetpack-slideshow__autoplay' : null,
$autoplay ? 'wp-block-jetpack-slideshow__autoplay-playing' : null,
);
- $classes = Jetpack_Gutenberg::block_classes( 'slideshow', $attr, $extras );
+ $classes = Blocks::classes( FEATURE_NAME, $attr, $extras );
return sprintf(
'<div class="%1$s" id="wp-block-jetpack-slideshow__%2$d"><div class="wp-block-jetpack-slideshow_container swiper-container">%3$s%4$s%5$s</div></div>',
esc_attr( $classes ),
absint( $wp_block_jetpack_slideshow_id ),
- jetpack_slideshow_block_amp_carousel( $attr, $wp_block_jetpack_slideshow_id ),
- $autoplay ? jetpack_slideshow_block_autoplay_ui( $wp_block_jetpack_slideshow_id ) : '',
- jetpack_slideshow_block_bullets( $ids, $wp_block_jetpack_slideshow_id )
+ amp_carousel( $attr, $wp_block_jetpack_slideshow_id ),
+ $autoplay ? autoplay_ui( $wp_block_jetpack_slideshow_id ) : '',
+ bullets( $ids, $wp_block_jetpack_slideshow_id )
);
}
@@ -69,7 +86,7 @@ function jetpack_slideshow_block_render_amp( $attr ) {
*
* @return string amp-carousel markup.
*/
-function jetpack_slideshow_block_amp_carousel( $attr, $block_ordinal ) {
+function amp_carousel( $attr, $block_ordinal ) {
$ids = empty( $attr['ids'] ) ? array() : $attr['ids'];
$first_image = wp_get_attachment_metadata( $ids[0] );
$delay = empty( $attr['delay'] ) ? 3 : absint( $attr['delay'] );
@@ -84,7 +101,7 @@ function jetpack_slideshow_block_amp_carousel( $attr, $block_ordinal ) {
esc_attr__( 'Previous Slide', 'jetpack' ),
$autoplay ? 'autoplay delay=' . esc_attr( $delay * 1000 ) : '',
absint( $block_ordinal ),
- implode( '', jetpack_slideshow_block_slides( $ids, $width, $height ) )
+ implode( '', slides( $ids, $width, $height ) )
);
}
@@ -97,9 +114,9 @@ function jetpack_slideshow_block_amp_carousel( $attr, $block_ordinal ) {
*
* @return array Array of slides markup.
*/
-function jetpack_slideshow_block_slides( $ids = array(), $width = 400, $height = 300 ) {
+function slides( $ids = array(), $width = 400, $height = 300 ) {
return array_map(
- function( $id ) use ( $width, $height ) {
+ function ( $id ) use ( $width, $height ) {
$caption = wp_get_attachment_caption( $id );
$figcaption = $caption ? sprintf(
'<figcaption class="wp-block-jetpack-slideshow_caption gallery-caption">%s</figcaption>',
@@ -132,9 +149,9 @@ function jetpack_slideshow_block_slides( $ids = array(), $width = 400, $height =
*
* @return array Array of bullets markup.
*/
-function jetpack_slideshow_block_bullets( $ids = array(), $block_ordinal = 0 ) {
+function bullets( $ids = array(), $block_ordinal = 0 ) {
$buttons = array_map(
- function( $index ) {
+ function ( $index ) {
$aria_label = sprintf(
/* translators: %d: Slide number. */
__( 'Go to slide %d', 'jetpack' ),
@@ -164,7 +181,7 @@ function jetpack_slideshow_block_bullets( $ids = array(), $block_ordinal = 0 ) {
*
* @return string Autoplay UI markup.
*/
-function jetpack_slideshow_block_autoplay_ui( $block_ordinal = 0 ) {
+function autoplay_ui( $block_ordinal = 0 ) {
$block_id = sprintf(
'wp-block-jetpack-slideshow__%d',
absint( $block_ordinal )