← All changes
|
jetpack_vendor/automattic/jetpack-masterbar/src/inline-help/class-inline-help.php
+126
-0
16.2-beta
→
16.3
View file →
| @@ -1,0 +1,126 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Inline Help. | |
| 4 | + * | |
| 5 | + * Handles providing a LiveChat icon within WPAdmin until such time | |
| 6 | + * as the full live chat experience can be run in a non-Calypso environment. | |
| 7 | + * | |
| 8 | + * @package automattic/jetpack-masterbar | |
| 9 | + */ | |
| 10 | + | |
| 11 | +namespace Automattic\Jetpack\Masterbar; | |
| 12 | + | |
| 13 | +use Automattic\Jetpack\Assets; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Class Inline_Help. | |
| 17 | + * | |
| 18 | + * @phan-constructor-used-for-side-effects | |
| 19 | + */ | |
| 20 | +class Inline_Help { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * Inline_Help constructor. | |
| 24 | + */ | |
| 25 | + public function __construct() { | |
| 26 | + add_action( 'current_screen', array( $this, 'register_actions' ) ); | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Registers actions. | |
| 31 | + * | |
| 32 | + * @param object $current_screen Current screen object. | |
| 33 | + * @return void | |
| 34 | + */ | |
| 35 | + public function register_actions( $current_screen ) { | |
| 36 | + // phpcs:disable WordPress.Security.NonceVerification.Recommended | |
| 37 | + // Do not inject the FAB icon on embedded screens since the parent window may already contain a FAB icon. | |
| 38 | + $is_framed = ! empty( $_GET['frame-nonce'] ); | |
| 39 | + | |
| 40 | + // Do not inject the FAB icon on Yoast screens to avoid overlap with the Yoast help icon. | |
| 41 | + $is_yoast = ! empty( $current_screen->base ) && str_contains( $current_screen->base, '_page_wpseo_' ); | |
| 42 | + | |
| 43 | + if ( $is_framed || $is_yoast ) { | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + // phpcs:enable WordPress.Security.NonceVerification.Recommended | |
| 47 | + | |
| 48 | + add_action( 'admin_footer', array( $this, 'add_fab_icon' ) ); | |
| 49 | + | |
| 50 | + add_action( 'admin_enqueue_scripts', array( $this, 'add_fab_styles' ) ); | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Outputs "FAB" icon markup and SVG. | |
| 55 | + * | |
| 56 | + * @return void|string the HTML markup for the FAB or early exit. | |
| 57 | + */ | |
| 58 | + public function add_fab_icon() { | |
| 59 | + | |
| 60 | + if ( wp_doing_ajax() ) { | |
| 61 | + return; | |
| 62 | + } | |
| 63 | + | |
| 64 | + $svg_allowed = array( | |
| 65 | + 'svg' => array( | |
| 66 | + 'id' => true, | |
| 67 | + 'class' => true, | |
| 68 | + 'aria-hidden' => true, | |
| 69 | + 'aria-labelledby' => true, | |
| 70 | + 'role' => true, | |
| 71 | + 'xmlns' => true, | |
| 72 | + 'width' => true, | |
| 73 | + 'height' => true, | |
| 74 | + 'viewbox' => true, // <= Must be lower case! | |
| 75 | + ), | |
| 76 | + 'g' => array( 'fill' => true ), | |
| 77 | + 'title' => array( 'title' => true ), | |
| 78 | + 'path' => array( | |
| 79 | + 'd' => true, | |
| 80 | + 'fill' => true, | |
| 81 | + ), | |
| 82 | + ); | |
| 83 | + | |
| 84 | + $gridicon_help = file_get_contents( __DIR__ . '/gridicon-help.svg', true ); | |
| 85 | + | |
| 86 | + // Add tracking data to link to be picked up by Calypso for GA and Tracks usage. | |
| 87 | + $tracking_href = add_query_arg( | |
| 88 | + array( | |
| 89 | + 'utm_source' => 'wp_admin', | |
| 90 | + 'utm_medium' => 'other', | |
| 91 | + 'utm_content' => 'jetpack_masterbar_inline_help_click', | |
| 92 | + 'flags' => 'a8c-analytics.on', | |
| 93 | + ), | |
| 94 | + 'https://wordpress.com/help' | |
| 95 | + ); | |
| 96 | + | |
| 97 | + load_template( | |
| 98 | + __DIR__ . '/inline-help-template.php', | |
| 99 | + true, | |
| 100 | + array( | |
| 101 | + 'href' => $tracking_href, | |
| 102 | + 'icon' => $gridicon_help, | |
| 103 | + 'svg_allowed' => $svg_allowed, | |
| 104 | + ) | |
| 105 | + ); | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Enqueues FAB CSS styles. | |
| 110 | + * | |
| 111 | + * @return void | |
| 112 | + */ | |
| 113 | + public function add_fab_styles() { | |
| 114 | + $assets_base_path = '../../dist/inline-help/'; | |
| 115 | + | |
| 116 | + Assets::register_script( | |
| 117 | + 'a8c-faux-inline-help', | |
| 118 | + $assets_base_path . 'inline-help.js', | |
| 119 | + __FILE__, | |
| 120 | + array( | |
| 121 | + 'enqueue' => true, | |
| 122 | + 'css_path' => $assets_base_path . 'inline-help.css', | |
| 123 | + ) | |
| 124 | + ); | |
| 125 | + } | |
| 126 | +} | |