Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Publicize_Assets | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| configure | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| should_enqueue_block_editor_scripts | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| enqueue_block_editor_scripts | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Publicize_Assets. |
| 4 | * |
| 5 | * @package automattic/jetpack-publicize |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Publicize; |
| 9 | |
| 10 | use Automattic\Jetpack\Assets; |
| 11 | |
| 12 | /** |
| 13 | * Publicize_Assets class. |
| 14 | */ |
| 15 | class Publicize_Assets { |
| 16 | |
| 17 | /** |
| 18 | * Initialize the class. |
| 19 | */ |
| 20 | public static function configure() { |
| 21 | Publicize_Script_Data::configure(); |
| 22 | |
| 23 | add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ), 15 ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Whether to enqueue the block editor scripts. |
| 28 | * |
| 29 | * @return boolean True if the criteria are met. |
| 30 | */ |
| 31 | public static function should_enqueue_block_editor_scripts() { |
| 32 | |
| 33 | $post_type = get_post_type(); |
| 34 | |
| 35 | if ( empty( $post_type ) || ! post_type_supports( $post_type, 'publicize' ) ) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | /** This filter is documented in projects/packages/publicize/src/class-publicize-base.php */ |
| 40 | $capability = apply_filters( 'jetpack_publicize_capability', 'publish_posts' ); |
| 41 | |
| 42 | return current_user_can( $capability ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Enqueue block editor scripts and styles. |
| 47 | */ |
| 48 | public static function enqueue_block_editor_scripts() { |
| 49 | if ( ! self::should_enqueue_block_editor_scripts() ) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // We don't want to render the Social UI in Jetpack sidebar |
| 54 | // if Jetpack is old, which has it bundled. |
| 55 | if ( defined( 'JETPACK__VERSION' ) && ( version_compare( (string) JETPACK__VERSION, '14.5-a.1', '<' ) ) ) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | $script_to_load = class_exists( 'Jetpack' ) ? 'block-editor-jetpack' : 'block-editor-social'; |
| 60 | |
| 61 | // Dequeue the old Social assets. |
| 62 | wp_dequeue_script( 'jetpack-social-editor' ); |
| 63 | wp_dequeue_style( 'jetpack-social-editor' ); |
| 64 | |
| 65 | Assets::register_script( |
| 66 | 'jetpack-social-editor', |
| 67 | sprintf( '../build/%s.js', $script_to_load ), |
| 68 | __FILE__, |
| 69 | array( |
| 70 | 'in_footer' => true, |
| 71 | 'textdomain' => 'jetpack-publicize-pkg', |
| 72 | 'enqueue' => true, |
| 73 | ) |
| 74 | ); |
| 75 | } |
| 76 | } |