kollapsminoriteten/wp-content/plugins/jetpack/extensions/blocks/sharing-buttons/sharing-buttons.php

69 lines
1.5 KiB
PHP
Raw Normal View History

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;
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.).
if ( ! jetpack_is_frontend() ) {
return '';
}
2020-03-03 18:49:45 +01:00
return $content;
}
2024-02-16 11:03:01 +01:00
/**
* Add the services list to the block
*/
function add_sharing_buttons_block_data() {
$services = array(
'print',
'facebook',
'linkedin',
'mail',
'mastodon',
'pinterest',
'pocket',
'reddit',
'telegram',
'tumblr',
'whatsapp',
'x',
'nextdoor',
);
wp_add_inline_script(
'jetpack-block-sharing-button',
'var jetpack_sharing_buttons_services = ' . wp_json_encode( $services, JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
'before'
);
}
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\add_sharing_buttons_block_data' );