This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,44 @@
<?php
/**
* Goodreads Block.
*
* @since 13.2
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Extensions\Goodreads;
use Automattic\Jetpack\Blocks;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
/**
* 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(
__DIR__,
array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
);
}
add_action( 'init', __NAMESPACE__ . '\register_block' );
/**
* Goodreads block registration/dependency declaration.
*
* The render implementation lives in render.php and is only loaded when the
* block is actually rendered, keeping it out of the eager front-end path.
*
* @param array $attr Array containing the Goodreads block attributes.
*
* @return string
*/
function load_assets( $attr ) {
require_once __DIR__ . '/render.php';
return render_implementation( $attr );
}
@@ -0,0 +1,53 @@
<?php
/**
* Goodreads block render implementation.
*
* Loaded lazily from goodreads.php only when the block is rendered, to keep
* the render body out of the eager front-end PHP/opcache footprint.
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Extensions\Goodreads;
use Automattic\Jetpack\Blocks;
use Jetpack_Gutenberg;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
/**
* Dynamic rendering of the block.
*
* @param array $attr Array containing the Goodreads block attributes.
*
* @return string
*/
function render_implementation( $attr ) {
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
if ( isset( $attr['id'] ) ) {
if ( isset( $attr['link'] ) ) {
wp_enqueue_script(
'jetpack-goodreads-' . esc_attr( $attr['id'] ),
esc_url_raw( $attr['link'] ),
array(),
JETPACK__VERSION,
true
);
}
$id = esc_attr( $attr['id'] );
} else {
$id = '';
}
$classes = esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) );
return sprintf(
'<div id="%1$s" class="%2$s"></div>',
$id,
$classes
);
}