Sin descripción

class-inline-help.php 3.0KB

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