Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Extensions\Publicize\register_plugins | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Block Editor - Publicize and Republicize features. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Extensions\Publicize; |
| 9 | |
| 10 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 11 | use Automattic\Jetpack\Modules; |
| 12 | use Automattic\Jetpack\Status; |
| 13 | use Automattic\Jetpack\Status\Host; |
| 14 | use Jetpack_Gutenberg; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit( 0 ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Register both Publicize and Republicize plugins. |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 25 | function register_plugins() { |
| 26 | /** This filter is documented in projects/packages/publicize/src/class-publicize-base.php */ |
| 27 | $capability = apply_filters( 'jetpack_publicize_capability', 'publish_posts' ); |
| 28 | |
| 29 | // Capability check. |
| 30 | if ( |
| 31 | ! current_user_can( $capability ) |
| 32 | ) { |
| 33 | Jetpack_Gutenberg::set_extension_unavailable( 'publicize', 'unauthorized' ); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * The extension is available even when the module is not active, |
| 39 | * so we can display a nudge to activate the module instead of the block. |
| 40 | * However, since non-admins cannot activate modules, we do not display the empty block for them. |
| 41 | */ |
| 42 | if ( ! ( new Modules() )->is_active( 'publicize' ) && ! current_user_can( 'jetpack_activate_modules' ) ) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | // Connection check. |
| 47 | if ( |
| 48 | ( new Host() )->is_wpcom_simple() |
| 49 | || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() ) |
| 50 | ) { |
| 51 | // Register Publicize. |
| 52 | Jetpack_Gutenberg::set_extension_available( 'publicize' ); |
| 53 | |
| 54 | // Set the republicize availability, depending on the site plan. |
| 55 | Jetpack_Gutenberg::set_availability_for_plan( 'republicize' ); |
| 56 | } |
| 57 | } |
| 58 | add_action( 'jetpack_register_gutenberg_extensions', __NAMESPACE__ . '\register_plugins' ); |
| 59 | |
| 60 | // Populate the available extensions with republicize. |
| 61 | add_filter( |
| 62 | 'jetpack_set_available_extensions', |
| 63 | function ( $extensions ) { |
| 64 | return array_merge( |
| 65 | (array) $extensions, |
| 66 | array( |
| 67 | 'republicize', |
| 68 | ) |
| 69 | ); |
| 70 | } |
| 71 | ); |
| 72 | |
| 73 | /** |
| 74 | * Publicize declares its support for the 'post' post type by default. |
| 75 | * Let's do it here as well, when the module hasn't been activated yet. |
| 76 | * It helps us display the Publicize UI in the editor. |
| 77 | */ |
| 78 | add_action( |
| 79 | 'init', |
| 80 | function () { |
| 81 | if ( ! ( new Modules() )->is_active( 'publicize' ) ) { |
| 82 | add_post_type_support( 'post', 'publicize' ); |
| 83 | } |
| 84 | } |
| 85 | ); |