PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / php / Admin / Feedback_Error_Capture.php

Feedback_Error_Capture.php in Code Snippets 4.0.0-beta.2, at php/Admin/Feedback_Error_Capture.php

61 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Admin;
4
5 use const Code_Snippets\PLUGIN_FILE;
6 use const Code_Snippets\PLUGIN_VERSION;
7
8 /**
9 * Collects JavaScript errors thrown on a Code Snippets screen, ready to attach to a report.
10 *
11 * The panel itself is a React application in the page footer and cannot see anything that
12 * failed before it mounted, so the listeners are enqueued in the document head instead.
13 * Errors thrown by scripts printed above this one are still missed.
14 *
15 * @package Code_Snippets
16 */
17 class Feedback_Error_Capture {
18
19 /**
20 * Script handle.
21 */
22 private const SCRIPT_HANDLE = 'code-snippets-feedback-capture';
23
24 /**
25 * Panel deciding whether the reporter belongs on this request.
26 *
27 * @var Feedback_Panel
28 */
29 private Feedback_Panel $panel;
30
31 /**
32 * Class constructor.
33 *
34 * @param Feedback_Panel $panel Panel deciding whether the reporter belongs on this request.
35 */
36 public function __construct( Feedback_Panel $panel ) {
37 $this->panel = $panel;
38
39 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ], 0 );
40 }
41
42 /**
43 * Enqueue the error listeners in the document head.
44 *
45 * @return void
46 */
47 public function enqueue_assets(): void {
48 if ( ! $this->panel->should_render() ) {
49 return;
50 }
51
52 wp_enqueue_script(
53 self::SCRIPT_HANDLE,
54 plugins_url( 'dist/feedback-capture.js', PLUGIN_FILE ),
55 [],
56 PLUGIN_VERSION,
57 false
58 );
59 }
60 }
61