PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | extensions/blocks/related-posts/related-posts.php +23 -22 12.8.3 → 16.3-a.5 View file →
@@ -10,9 +10,14 @@
10 10 use Automattic\Jetpack\Blocks;
11 11 use Automattic\Jetpack\Modules;
12 12 use Automattic\Jetpack\Status;
13 13 use Automattic\Jetpack\Status\Host;
14 +use WP_Block;
14 15
16 +if ( ! defined( 'ABSPATH' ) ) {
17 + exit( 0 );
18 +}
19 +
15 20 /**
16 21 * Registers the block for use in Gutenberg
17 22 * This is done via an action so that we can disable
18 23 * registration if we need to.
@@ -17,8 +22,17 @@
17 22 * This is done via an action so that we can disable
18 23 * registration if we need to.
19 24 */
20 25 function register_block() {
26 + /*
27 + * The block is available even when the module is not active,
28 + * so we can display a nudge to activate the module instead of the block.
29 + * However, since non-admins cannot activate modules, we do not display the empty block for them.
30 + */
31 + if ( ! ( new Modules() )->is_active( 'related-posts' ) && ! current_user_can( 'jetpack_activate_modules' ) ) {
32 + return;
33 + }
34 +
21 35 if (
22 36 ( new Host() )->is_wpcom_simple()
23 37 || ( \Jetpack::is_connection_ready() && ! ( new Status() )->is_offline_mode() )
24 38 ) {
@@ -34,30 +48,17 @@
34 48
35 49 /**
36 50 * Related Posts block render callback.
37 51 *
38 - * @param array $attributes Array containing the Button block attributes.
39 - * @param string $content The Button block content.
52 + * The render implementation lives in render.php and is only loaded when the
53 + * block is actually rendered, keeping it out of the eager front-end path.
40 54 *
55 + * @param array $attributes Array containing the Button block attributes.
56 + * @param string $content The block content.
57 + * @param WP_Block $block The block object.
58 + *
41 59 * @return string
42 60 */
43 -function render_block( $attributes, $content ) {
44 - // If the Related Posts module is not active, don't render the block.
45 - if (
46 - ! ( new Host() )->is_wpcom_simple()
47 - && ! ( new Modules() )->is_active( 'related-posts' )
48 - ) {
49 - return '';
50 - }
51 -
52 - // If the Related Posts option is turned off, don't render the block.
53 - $options = \Jetpack_Options::get_option( 'relatedposts', array() );
54 - if ( empty( $options['enabled'] ) || ! $options['enabled'] ) {
55 - return '';
56 - }
57 -
58 - if ( ! class_exists( 'Jetpack_RelatedPosts' ) ) {
59 - require_once JETPACK__PLUGIN_DIR . 'modules/related-posts/jetpack-related-posts.php';
60 - }
61 -
62 - return \Jetpack_RelatedPosts::init()->render_block( $attributes, $content );
61 +function render_block( $attributes, $content, $block ) {
62 + require_once __DIR__ . '/render.php';
63 + return render_block_implementation( $attributes, $content, $block );
63 64 }