Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Yoast_Promo | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| init | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| enqueue_block_editor_assets | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Package description here |
| 4 | * |
| 5 | * @package automattic/jetpack-yoast-promo |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack; |
| 9 | |
| 10 | /** |
| 11 | * Class description. |
| 12 | */ |
| 13 | class Yoast_Promo { |
| 14 | |
| 15 | const PACKAGE_VERSION = '0.4.2'; |
| 16 | |
| 17 | /** |
| 18 | * Script handle for the JS file we enqueue in the post editor. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | const SCRIPT_HANDLE = 'yoast-promo-editor'; |
| 23 | |
| 24 | /** |
| 25 | * Path of the JS file we enqueue in the post editor. |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | public static $script_path = '../build/editor.js'; |
| 30 | |
| 31 | /** |
| 32 | * The configuration method that is called from the jetpack-config package. |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public static function init() { |
| 37 | // Do not do anything if promotions are disabled on the site |
| 38 | if ( |
| 39 | /** This filter is documented in _inc/lib/admin-pages/class.jetpack-react-page.php */ |
| 40 | ! apply_filters( 'jetpack_show_promotions', true ) |
| 41 | ) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | // In the post editor, add a pre-publish panel to promote Yoast |
| 46 | add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_assets' ) ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Enqueue block editor assets. |
| 51 | */ |
| 52 | public static function enqueue_block_editor_assets() { |
| 53 | /* |
| 54 | * We do not want (nor need) Yoast promo in the site editor, or the widget editor, or the classic editor. |
| 55 | * We only want it in the post editor. |
| 56 | * Enqueueing the script in those editors would cause a fatal error. |
| 57 | * See #20357 for more info. |
| 58 | */ |
| 59 | if ( ! function_exists( 'get_current_screen' ) ) { // When Gutenberg is loaded in the frontend. |
| 60 | return; |
| 61 | } |
| 62 | $current_screen = get_current_screen(); |
| 63 | if ( |
| 64 | empty( $current_screen ) |
| 65 | || $current_screen->base !== 'post' |
| 66 | || ! $current_screen->is_block_editor() |
| 67 | ) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | Assets::register_script( |
| 72 | self::SCRIPT_HANDLE, |
| 73 | self::$script_path, |
| 74 | __FILE__, |
| 75 | array( |
| 76 | 'enqueue' => true, |
| 77 | 'in_footer' => true, |
| 78 | 'textdomain' => 'jetpack-yoast-promo', |
| 79 | ) |
| 80 | ); |
| 81 | } |
| 82 | } |