PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.0
Jetpack – WP Security, Backup, Speed, & Growth v16.0
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 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / extensions / plugins / sharing / sharing.php
sharing.php
71 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Block Editor - Sharing feature.
4 *
5 * @package automattic/jetpack
6 */
7
8 namespace Automattic\Jetpack\Extensions\Sharing;
9
10 use Automattic\Jetpack\Modules;
11 use Jetpack_Gutenberg;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 0 );
15 }
16
17 /**
18 * Register Sharing plugin.
19 *
20 * @return void
21 */
22 function register_plugins() {
23 /*
24 * The extension is available even when the module is not active,
25 * so we can display a nudge to activate the module instead of the block.
26 * However, since non-admins cannot activate modules, we do not display the empty block for them.
27 */
28 if ( ! ( new Modules() )->is_active( 'sharedaddy' ) && ! current_user_can( 'jetpack_activate_modules' ) ) {
29 return;
30 }
31
32 Jetpack_Gutenberg::set_extension_available( 'sharing' );
33 }
34
35 add_action( 'jetpack_register_gutenberg_extensions', __NAMESPACE__ . '\register_plugins' );
36
37 /**
38 * The Sharing panel is only displayed for post types that support sharing.
39 * The sharing module declares support for sharing for all the public post types.
40 * Let's do the same thing when the module isn't active yet.
41 */
42 add_action(
43 'rest_api_init',
44 function () {
45 if ( ! ( new Modules() )->is_active( 'sharedaddy' ) ) {
46 $post_types = get_post_types( array( 'public' => true ) );
47
48 foreach ( $post_types as $post_type ) {
49 register_rest_field(
50 $post_type,
51 'jetpack_sharing_enabled',
52 array(
53 'get_callback' => function ( array $post ) {
54 if ( ! isset( $post['id'] ) ) {
55 return false;
56 }
57
58 return ! get_post_meta( $post['id'], 'sharing_disabled', true );
59 },
60 'schema' => array(
61 'description' => __( 'Are sharing buttons enabled?', 'jetpack' ),
62 'type' => 'boolean',
63 ),
64 )
65 );
66 add_post_type_support( $post_type, 'jetpack-sharing-buttons' );
67 }
68 }
69 }
70 );
71