PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 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 All 508 releases
← All changes | extensions/blocks/top-posts/top-posts.php +59 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,59 @@
1 +<?php
2 +/**
3 + * Top Posts Block.
4 + *
5 + * @since 13.0
6 + *
7 + * @package automattic/jetpack
8 + */
9 +
10 +namespace Automattic\Jetpack\Extensions\Top_Posts;
11 +
12 +use Automattic\Jetpack\Blocks;
13 +use Automattic\Jetpack\Connection\Manager as Connection_Manager;
14 +use Automattic\Jetpack\Modules;
15 +use Automattic\Jetpack\Status;
16 +use Automattic\Jetpack\Status\Host;
17 +
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit( 0 );
20 +}
21 +
22 +/**
23 + * Registers the block for use in Gutenberg
24 + * This is done via an action so that we can disable
25 + * registration if we need to.
26 + */
27 +function register_block() {
28 + /*
29 + * The block is available even when the module is not active,
30 + * so we can display a nudge to activate the module instead of the block.
31 + * However, since non-admins cannot activate modules, we do not display the empty block for them.
32 + */
33 + if ( ! ( new Modules() )->is_active( 'stats' ) && ! current_user_can( 'jetpack_activate_modules' ) ) {
34 + return;
35 + }
36 +
37 + if ( ( new Host() )->is_wpcom_simple() || ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() ) {
38 + Blocks::jetpack_register_block(
39 + __DIR__,
40 + array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
41 + );
42 + }
43 +}
44 +add_action( 'init', __NAMESPACE__ . '\register_block' );
45 +
46 +/**
47 + * Top Posts block registration/dependency declaration.
48 + *
49 + * The render implementation lives in render.php and is only loaded when the
50 + * block is actually rendered, keeping it out of the eager front-end path.
51 + *
52 + * @param array $attributes Array containing the Top Posts block attributes.
53 + *
54 + * @return string
55 + */
56 +function load_assets( $attributes ) {
57 + require_once __DIR__ . '/render.php';
58 + return load_assets_implementation( $attributes );
59 +}