PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 11.2
Jetpack – WP Security, Backup, Speed, & Growth v11.2
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 / modules / masterbar / inline-help / class-inline-help.php

class-inline-help.php in Jetpack – WP Security, Backup, Speed, & Growth 11.2, at modules/masterbar/inline-help/class-inline-help.php

117 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
9 */
10
11 namespace Automattic\Jetpack\Dashboard_Customizations;
12
13 /**
14 * Class Inline_Help.
15 */
16 class Inline_Help {
17
18 /**
19 * Inline_Help constructor.
20 */
21 public function __construct() {
22 add_action( 'current_screen', array( $this, 'register_actions' ) );
23 }
24
25 /**
26 * Registers actions.
27 *
28 * @param object $current_screen Current screen object.
29 * @return void
30 */
31 public function register_actions( $current_screen ) {
32 // phpcs:disable WordPress.Security.NonceVerification.Recommended
33 // Do not inject the FAB icon on embedded screens since the parent window may already contain a FAB icon.
34 $is_framed = ! empty( $_GET['frame-nonce'] );
35
36 // Do not inject the FAB icon on Yoast screens to avoid overlap with the Yoast help icon.
37 $is_yoast = ! empty( $current_screen->base ) && false !== strpos( $current_screen->base, '_page_wpseo_' );
38
39 if ( $is_framed || $is_yoast ) {
40 return;
41 }
42 // phpcs:enable WordPress.Security.NonceVerification.Recommended
43
44 add_action( 'admin_footer', array( $this, 'add_fab_icon' ) );
45
46 add_action( 'admin_enqueue_scripts', array( $this, 'add_fab_styles' ) );
47 }
48
49 /**
50 * Outputs "FAB" icon markup and SVG.
51 *
52 * @return void|string the HTML markup for the FAB or early exit.
53 */
54 public function add_fab_icon() {
55
56 if ( wp_doing_ajax() ) {
57 return;
58 }
59
60 $svg_allowed = array(
61 'svg' => array(
62 'id' => true,
63 'class' => true,
64 'aria-hidden' => true,
65 'aria-labelledby' => true,
66 'role' => true,
67 'xmlns' => true,
68 'width' => true,
69 'height' => true,
70 'viewbox' => true, // <= Must be lower case!
71 ),
72 'g' => array( 'fill' => true ),
73 'title' => array( 'title' => true ),
74 'path' => array(
75 'd' => true,
76 'fill' => true,
77 ),
78 );
79
80 $gridicon_help = file_get_contents( __DIR__ . '/gridicon-help.svg', true );
81
82 // Add tracking data to link to be picked up by Calypso for GA and Tracks usage.
83 $tracking_href = add_query_arg(
84 array(
85 'utm_source' => 'wp_admin',
86 'utm_medium' => 'other',
87 'utm_content' => 'jetpack_masterbar_inline_help_click',
88 'flags' => 'a8c-analytics.on',
89 ),
90 'https://wordpress.com/help'
91 );
92
93 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
94 // We trust that output in the template has been escaped.
95 echo load_template(
96 __DIR__ . '/inline-help-template.php',
97 true,
98 array(
99 'href' => $tracking_href,
100 'icon' => $gridicon_help,
101 'svg_allowed' => $svg_allowed,
102 )
103 );
104 // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
105
106 }
107
108 /**
109 * Enqueues FAB CSS styles.
110 *
111 * @return void
112 */
113 public function add_fab_styles() {
114 wp_enqueue_style( 'a8c-faux-inline-help', plugins_url( 'inline-help.css', __FILE__ ), array(), JETPACK__VERSION );
115 }
116 }
117