PluginProbe
BugHerd / 1.0.20
BugHerd v1.0.20
1.0.20 1.0.18 1.0.19 1.0.17 trunk 1.0.0 1.0.1 1.0.11 1.0.12 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
bugherd / includes / scripts.php

scripts.php in BugHerd 1.0.20, at includes/scripts.php

89 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Frontend and Admin Scripts.
4 *
5 * @package BugHerd
6 */
7
8 // If this file is called directly, abort.
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 /**
14 * Get the tracking script.
15 *
16 * @param string $project_key BugHerd project Key.
17 * @return string
18 */
19 function bugherd_get_the_script( $project_key ) {
20 return sprintf(
21 '<script type="text/javascript" src="https://www.bugherd.com/sidebarv2.js?utm_source=wordpress&apikey=%s" async="true"></script>',
22 esc_html( $project_key )
23 );
24 }
25
26 /**
27 * Check if BugHerd should be disabled based on query parameters.
28 *
29 * Users can add `?disable_bugherd` (or any defined query params) to prevent BugHerd from loading.
30 *
31 * @return bool
32 */
33 function is_bugherd_disabled_by_query() {
34 $query_params = get_option( 'bugherd_disable_query_params', 'disable_bugherd, bricks, elementor, no_bugherd' );
35 $disabled_params = array_map('trim', explode(',', $query_params)); // Convert to an array
36
37 foreach ( $disabled_params as $param ) {
38 if ( isset( $_GET[ $param ] ) ) {
39 return true;
40 }
41 }
42 return false;
43 }
44
45 /**
46 * Add BugHerd integration code for the frontend.
47 */
48 add_action( 'wp_head', 'bugherd_do_the_frontend_script' );
49 function bugherd_do_the_frontend_script() {
50 $project_key = get_option( 'bugherd_project_key', '' );
51
52 // Prevent BugHerd from loading if any specified query parameter is present
53 if ( is_bugherd_disabled_by_query() ) {
54 return;
55 }
56
57 if ( empty( $project_key ) ) {
58 return;
59 }
60
61 echo bugherd_get_the_script( $project_key );
62 }
63
64 /**
65 * Add BugHerd integration code for wp-admin.
66 */
67 add_action( 'admin_head', 'bugherd_do_the_admin_script' );
68 function bugherd_do_the_admin_script() {
69 $enable_admin = filter_var( get_option( 'bugherd_enable_admin', false ), FILTER_VALIDATE_BOOLEAN );
70
71 // If admin mode is disabled in settings, don't load BugHerd
72 if ( ! $enable_admin ) {
73 return;
74 }
75
76 // Prevent BugHerd from loading if any specified query parameter is present
77 if ( is_bugherd_disabled_by_query() ) {
78 return;
79 }
80
81 $project_key = get_option( 'bugherd_project_key', '' );
82
83 if ( empty( $project_key ) ) {
84 return;
85 }
86
87 echo bugherd_get_the_script( $project_key );
88 }
89