PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 13.2.4
Jetpack – WP Security, Backup, Speed, & Growth v13.2.4
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 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / extensions / blocks / related-posts / related-posts.php
related-posts.php
65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Related Posts Block.
4 *
5 * @package automattic/jetpack
6 */
7
8 namespace Automattic\Jetpack\Extensions\RelatedPosts;
9
10 use Automattic\Jetpack\Blocks;
11 use Automattic\Jetpack\Modules;
12 use Automattic\Jetpack\Status;
13 use Automattic\Jetpack\Status\Host;
14
15 /**
16 * Registers the block for use in Gutenberg
17 * This is done via an action so that we can disable
18 * registration if we need to.
19 */
20 function register_block() {
21 if (
22 ( new Host() )->is_wpcom_simple()
23 || ( \Jetpack::is_connection_ready() && ! ( new Status() )->is_offline_mode() )
24 ) {
25 Blocks::jetpack_register_block(
26 __DIR__,
27 array(
28 'render_callback' => __NAMESPACE__ . '\render_block',
29 )
30 );
31 }
32 }
33 add_action( 'init', __NAMESPACE__ . '\register_block', 9 );
34
35 /**
36 * Related Posts block render callback.
37 *
38 * @param array $attributes Array containing the Button block attributes.
39 * @param string $content The block content.
40 * @param WP_Block $block The block object.
41 *
42 * @return string
43 */
44 function render_block( $attributes, $content, $block ) {
45 // If the Related Posts module is not active, don't render the block.
46 if (
47 ! ( new Host() )->is_wpcom_simple()
48 && ! ( new Modules() )->is_active( 'related-posts' )
49 ) {
50 return '';
51 }
52
53 // If the Related Posts option is turned off, don't render the block.
54 $options = \Jetpack_Options::get_option( 'relatedposts', array() );
55 if ( empty( $options['enabled'] ) || ! $options['enabled'] ) {
56 return '';
57 }
58
59 if ( ! class_exists( 'Jetpack_RelatedPosts' ) ) {
60 require_once JETPACK__PLUGIN_DIR . 'modules/related-posts/jetpack-related-posts.php';
61 }
62
63 return \Jetpack_RelatedPosts::init()->render_block( $attributes, $content, $block );
64 }
65