| 1 |
<?php |
| 2 |
/** |
| 3 |
* Block Editor - Sharing feature. |
| 4 |
* |
| 5 |
* @package automattic/jetpack |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\Extensions\Sharing; |
| 9 |
|
| 10 |
use Jetpack_Gutenberg; |
| 11 |
|
| 12 |
/** |
| 13 |
* Register Sharing plugin. |
| 14 |
* |
| 15 |
* @return void |
| 16 |
*/ |
| 17 |
function register_plugins() { |
| 18 |
// Register Sharing. |
| 19 |
Jetpack_Gutenberg::set_extension_available( 'sharing' ); |
| 20 |
} |
| 21 |
|
| 22 |
add_action( 'jetpack_register_gutenberg_extensions', __NAMESPACE__ . '\register_plugins' ); |
| 23 |
|
| 24 |
/** |
| 25 |
* The Sharing panel is only displayed for post types that support sharing. |
| 26 |
* The sharing module declares support for sharing for all the public post types. |
| 27 |
* Let's do the same thing when the module isn't active yet. |
| 28 |
*/ |
| 29 |
add_action( |
| 30 |
'rest_api_init', |
| 31 |
function () { |
| 32 |
if ( ! \Jetpack::is_module_active( 'sharedaddy' ) ) { |
| 33 |
$post_types = get_post_types( array( 'public' => true ) ); |
| 34 |
|
| 35 |
foreach ( $post_types as $post_type ) { |
| 36 |
register_rest_field( |
| 37 |
$post_type, |
| 38 |
'jetpack_sharing_enabled', |
| 39 |
array( |
| 40 |
'get_callback' => function ( array $post ) { |
| 41 |
return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true ); |
| 42 |
}, |
| 43 |
'schema' => array( |
| 44 |
'description' => __( 'Are sharing buttons enabled?', 'jetpack' ), |
| 45 |
'type' => 'boolean', |
| 46 |
), |
| 47 |
) |
| 48 |
); |
| 49 |
add_post_type_support( $post_type, 'jetpack-sharing-buttons' ); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
); |
| 54 |
|