2020-03-03 18:49:45 +01:00
|
|
|
<?php
|
|
|
|
|
/**
|
2023-12-07 09:44:11 +01:00
|
|
|
* Sharing Buttons Block.
|
2020-03-03 18:49:45 +01:00
|
|
|
*
|
2023-12-07 09:44:11 +01:00
|
|
|
* @since 11.x
|
2020-03-03 18:49:45 +01:00
|
|
|
*
|
2021-04-27 08:32:47 +02:00
|
|
|
* @package automattic/jetpack
|
2020-03-03 18:49:45 +01:00
|
|
|
*/
|
|
|
|
|
|
2023-12-07 09:44:11 +01:00
|
|
|
namespace Automattic\Jetpack\Extensions\Sharing_Buttons;
|
2020-05-06 17:20:49 +02:00
|
|
|
|
2020-11-18 09:10:44 +01:00
|
|
|
use Automattic\Jetpack\Blocks;
|
2025-07-27 19:58:08 +02:00
|
|
|
use Automattic\Jetpack\Status\Request;
|
|
|
|
|
|
2025-12-12 13:13:07 +01:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
|
exit( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
/**
|
|
|
|
|
* Registers the block for use in Gutenberg
|
|
|
|
|
* This is done via an action so that we can disable
|
|
|
|
|
* registration if we need to.
|
|
|
|
|
*/
|
|
|
|
|
function register_block() {
|
2020-11-18 09:10:44 +01:00
|
|
|
Blocks::jetpack_register_block(
|
2023-09-26 10:24:36 +02:00
|
|
|
__DIR__,
|
2024-02-16 11:03:01 +01:00
|
|
|
array( 'render_callback' => __NAMESPACE__ . '\render_block' )
|
2020-05-06 17:20:49 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
add_action( 'init', __NAMESPACE__ . '\register_block' );
|
2020-03-03 18:49:45 +01:00
|
|
|
|
|
|
|
|
/**
|
2023-12-07 09:44:11 +01:00
|
|
|
* Sharing Buttons block registration/dependency declaration.
|
2020-03-03 18:49:45 +01:00
|
|
|
*
|
2023-12-07 09:44:11 +01:00
|
|
|
* @param array $attr Array containing the Sharing Buttons block attributes.
|
|
|
|
|
* @param string $content String containing the Sharing Buttons block content.
|
2020-03-03 18:49:45 +01:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2024-02-16 11:03:01 +01:00
|
|
|
function render_block( $attr, $content ) {
|
|
|
|
|
// Render nothing in other contexts than frontend (i.e. feed, emails, API, etc.).
|
2025-07-27 19:58:08 +02:00
|
|
|
if ( ! Request::is_frontend() ) {
|
2024-02-16 11:03:01 +01:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 11:32:24 +02:00
|
|
|
return $content;
|
2024-02-16 11:03:01 +01:00
|
|
|
}
|