has_connected_owner() && ! ( new Status() )->is_offline_mode() ) { Blocks::jetpack_register_block( __DIR__, array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) ); } } add_action( 'init', __NAMESPACE__ . '\register_block' ); /** * Top Posts block registration/dependency declaration. * * @param array $attributes Array containing the Top Posts block attributes. * * @return string */ function load_assets( $attributes ) { // Do not render in contexts outside the front-end (eg. emails, API). if ( ! jetpack_is_frontend() ) { return; } Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); /* * We cannot rely on obtaining posts from the block because * top posts might have changed since then. As such, we must * check for updated stats. */ $period = $attributes['period']; $number = $attributes['postsToShow']; $types = implode( ',', array_keys( array_filter( $attributes['postTypes'] ) ) ); $data = Jetpack_Top_Posts_Helper::get_top_posts( $period, $number, $types ); if ( ! is_array( $data ) ) { return; } $wrapper_attributes = \WP_Block_Supports::get_instance()->apply_block_supports(); $output = sprintf( '