PluginProbe
BugHerd / 1.0.14
BugHerd v1.0.14
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 / settings.php

settings.php in BugHerd 1.0.14, at includes/settings.php

129 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Settings Page.
4 *
5 * @package BugHerd
6 */
7
8 // If this file is called directly, abort.
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 add_action( 'admin_menu', 'bugherd_register_options_page' );
14 function bugherd_register_options_page() {
15 add_options_page(
16 esc_html__( 'BugHerd', 'bugherd' ),
17 esc_html__( 'BugHerd', 'bugherd' ),
18 'manage_options',
19 'bugherd',
20 'bugherd_options_page'
21 );
22 }
23
24 add_action( 'admin_init', 'bugherd_register_settings' );
25 function bugherd_register_settings() {
26 add_settings_section( 'bugherd_settings', '', '__return_false', 'bugherd_settings' );
27
28 // Project Key
29 register_setting( 'bugherd_settings', 'bugherd_project_key', [
30 'type' => 'string',
31 'description' => esc_html__( 'BugHerd Project Key', 'bugherd' ),
32 'sanitize_callback' => 'sanitize_text_field',
33 'show_in_rest' => true,
34 'default' => '',
35 ]);
36
37 // Enable BugHerd in WP Admin
38 register_setting( 'bugherd_settings', 'bugherd_enable_admin', [
39 'type' => 'boolean',
40 'description' => esc_html__( 'Enable BugHerd in wp-admin?', 'bugherd' ),
41 'sanitize_callback' => 'sanitize_text_field',
42 'show_in_rest' => true,
43 'default' => false,
44 ]);
45
46 // Query Params for Disabling BugHerd
47 register_setting( 'bugherd_settings', 'bugherd_disable_query_params', [
48 'type' => 'string',
49 'description' => esc_html__( 'Comma-separated list of query parameters to disable BugHerd.', 'bugherd' ),
50 'sanitize_callback' => 'sanitize_text_field',
51 'show_in_rest' => true,
52 'default' => false,
53 ]);
54
55 // Add Fields
56 add_settings_field( 'bugherd_project_key_field', __( 'Project Key', 'bugherd' ), 'bugherd_project_key_settings_field', 'bugherd_settings', 'bugherd_settings' );
57
58 add_settings_field( 'bugherd_enable_admin_field', __( 'Enable BugHerd in wp-admin?', 'bugherd' ), 'bugherd_enable_admin_settings_field', 'bugherd_settings', 'bugherd_settings' );
59
60 add_settings_field( 'bugherd_disable_query_params_field', __( 'Query Parameters to Disable BugHerd', 'bugherd' ), 'bugherd_disable_query_params_settings_field', 'bugherd_settings', 'bugherd_settings' );
61 }
62
63 function bugherd_project_key_settings_field() {
64 printf(
65 '<input type="text" id="bugherd-project-key" name="bugherd_project_key" value="%s" class="regular-text ltr" /><p class="description">%s</p>',
66 esc_attr( get_option( 'bugherd_project_key' ) ),
67 esc_html__( 'Leave blank to disable plugin.', 'bugherd' )
68 );
69 }
70
71 function bugherd_enable_admin_settings_field() {
72 printf(
73 '<input type="checkbox" id="bugherd-enable-admin" name="bugherd_enable_admin" value="1" %s /><label for="bugherd-enable-admin">%s</label>',
74 checked( get_option( 'bugherd_enable_admin' ), '1', false ),
75 esc_html__( 'Show BugHerd on WP Admin pages?', 'bugherd' )
76 );
77 }
78
79 function bugherd_disable_query_params_settings_field() {
80 printf(
81 '<input type="text" id="bugherd-disable-query-params" name="bugherd_disable_query_params" value="%s" class="regular-text" />
82 <p class="description">%s</p>',
83 esc_attr( get_option( 'bugherd_disable_query_params', 'disable_bugherd, bricks, elementor, no_bugherd' ) ),
84 esc_html__( 'Enter query parameters (comma-separated) to disable BugHerd. Example: bricks, elementor' )
85 );
86 }
87
88 function bugherd_options_page() {
89 echo '<div class="wrap bugherd-settings-container">';
90
91 // Logo
92 printf(
93 '<img src="%s%s" class="bugherd-logo">',
94 esc_url( plugin_dir_url( __DIR__ ) ),
95 'assets/images/logo-web.png'
96 );
97
98 // Tagline
99 printf(
100 '<h2 class="bugherd-tagline">%s<br>%s</h2>',
101 esc_html__( 'The Visual Feedback', 'bugherd' ),
102 esc_html__( 'Tool for Websites', 'bugherd' )
103 );
104
105 echo '<form method="post" action="options.php" class="card bugherd-container">';
106
107 // Intro
108 printf(
109 '<p>%s <a href="%s" target="_blank" rel="noopener">%s</a></p>',
110 esc_html__( 'To install BugHerd on this site simply add your BugHerd Project Key to the field below. Not sure where to find your Project Key?', 'bugherd' ),
111 esc_url( 'https://support.bugherd.com/hc/en-us/articles/360002121575' ),
112 esc_html__( 'Check out this help article.', 'bugherd' )
113 );
114
115 settings_fields( 'bugherd_settings' );
116 do_settings_sections( 'bugherd_settings' );
117
118 // Submit button
119 printf(
120 '<div class="bugherd-submit">%1$s<p>%2$s <a href="%3$s" target="_blank" rel="noopener">%3$s</a></p></div>',
121 get_submit_button(),
122 esc_html__( 'Need help? Try', 'bugherd' ),
123 esc_url( 'https://support.bugherd.com' )
124 );
125
126 echo '</form>';
127 echo '</div>';
128 }
129