Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Extensions\RelatedPosts\render_block_implementation | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Related Posts block render implementation. |
| 4 | * |
| 5 | * Loaded lazily from related-posts.php only when the block is rendered, to keep |
| 6 | * the render body out of the eager front-end PHP/opcache footprint. |
| 7 | * |
| 8 | * @package automattic/jetpack |
| 9 | */ |
| 10 | |
| 11 | namespace Automattic\Jetpack\Extensions\RelatedPosts; |
| 12 | |
| 13 | use Automattic\Jetpack\Modules; |
| 14 | use Automattic\Jetpack\Status\Host; |
| 15 | use WP_Block; |
| 16 | |
| 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | exit( 0 ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Related Posts block render callback. |
| 23 | * |
| 24 | * @param array $attributes Array containing the Button block attributes. |
| 25 | * @param string $content The block content. |
| 26 | * @param WP_Block $block The block object. |
| 27 | * |
| 28 | * @return string |
| 29 | */ |
| 30 | function render_block_implementation( $attributes, $content, $block ) { |
| 31 | // If the Related Posts module is not active, don't render the block. |
| 32 | if ( |
| 33 | ! ( new Host() )->is_wpcom_simple() |
| 34 | && ! ( new Modules() )->is_active( 'related-posts' ) |
| 35 | ) { |
| 36 | return ''; |
| 37 | } |
| 38 | |
| 39 | // If the Related Posts option is turned off, don't render the block. |
| 40 | $options = \Jetpack_Options::get_option( 'relatedposts', array() ); |
| 41 | if ( empty( $options['enabled'] ) || ! $options['enabled'] ) { |
| 42 | return ''; |
| 43 | } |
| 44 | |
| 45 | if ( ! class_exists( 'Jetpack_RelatedPosts' ) ) { |
| 46 | require_once JETPACK__PLUGIN_DIR . 'modules/related-posts/jetpack-related-posts.php'; |
| 47 | } |
| 48 | |
| 49 | return \Jetpack_RelatedPosts::init()->render_block( $attributes, $content, $block ); |
| 50 | } |