| 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_enqueue_scripts', 'bugherd_enqueue_admin_stylesheet' ); |
| 14 |
/** |
| 15 |
* Enqueue stylesheet in the admin. |
| 16 |
* |
| 17 |
* @return void |
| 18 |
* @since 1.0.0 |
| 19 |
*/ |
| 20 |
function bugherd_enqueue_admin_stylesheet() { |
| 21 |
wp_enqueue_style( 'bugherd', plugin_dir_url( __DIR__ ) . 'assets/css/style.css', array(), '1.0.0' ); |
| 22 |
} |
| 23 |
|
| 24 |
add_action( 'admin_menu', 'bugherd_register_options_page' ); |
| 25 |
/** |
| 26 |
* Add menu into options page |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
function bugherd_register_options_page() { |
| 32 |
add_options_page( |
| 33 |
esc_html__( 'BugHerd', 'bugherd' ), |
| 34 |
esc_html__( 'BugHerd', 'bugherd' ), |
| 35 |
'manage_options', |
| 36 |
'bugherd', |
| 37 |
'bugherd_options_page' |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
add_filter( 'plugin_action_links_bugherd/bugherd.php', 'bugherd_options_page_link', 10, 4 ); |
| 42 |
/** |
| 43 |
* Add options page link to the plugin actions list. |
| 44 |
* |
| 45 |
* @param array $actions An array of plugin action links. By default this can include 'activate', 'deactivate', and 'delete'. |
| 46 |
* @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 47 |
* @param array $plugin_data An array of plugin data. |
| 48 |
* @param string $context The plugin context. |
| 49 |
* @return array |
| 50 |
* @since 1.0.1 |
| 51 |
*/ |
| 52 |
function bugherd_options_page_link( $actions, $plugin_file, $plugin_data, $context ) { |
| 53 |
$actions[] = sprintf( |
| 54 |
'<a href="%s">%s</a>', |
| 55 |
esc_url( admin_url( 'options-general.php?page=bugherd' ) ), |
| 56 |
esc_html__( 'Settings', 'bugherd' ) |
| 57 |
); |
| 58 |
return $actions; |
| 59 |
} |
| 60 |
|
| 61 |
add_action( 'admin_menu', 'bugherd_register_settings' ); |
| 62 |
/** |
| 63 |
* Register options and settings fields. |
| 64 |
* |
| 65 |
* @return void |
| 66 |
* @since 1.0.0 |
| 67 |
*/ |
| 68 |
function bugherd_register_settings() { |
| 69 |
|
| 70 |
// Section. |
| 71 |
add_settings_section( 'bugherd_settings', '', '__return_false', 'bugherd_settings' ); |
| 72 |
|
| 73 |
// Project ID. |
| 74 |
register_setting( |
| 75 |
'bugherd_settings', |
| 76 |
'bugherd_project_key', |
| 77 |
array( |
| 78 |
'type' => 'string', |
| 79 |
'description' => esc_html__( 'Bugherd Project Key', 'bugherd' ), |
| 80 |
'sanitize_callback' => 'sanitize_text_field', |
| 81 |
'show_in_rest' => true, |
| 82 |
'default' => '', |
| 83 |
) |
| 84 |
); |
| 85 |
|
| 86 |
// Enable Admin. |
| 87 |
register_setting( |
| 88 |
'bugherd_settings', |
| 89 |
'bugherd_enable_admin', |
| 90 |
array( |
| 91 |
'type' => 'boolean', |
| 92 |
'description' => esc_html__( 'Enable BugHerd in wp-admin?', 'bugherd' ), |
| 93 |
'sanitize_callback' => 'sanitize_text_field', |
| 94 |
'show_in_rest' => true, |
| 95 |
'default' => false, |
| 96 |
) |
| 97 |
); |
| 98 |
|
| 99 |
// Project ID Field. |
| 100 |
add_settings_field( |
| 101 |
'bugherd_project_key_field', |
| 102 |
__( 'Project Key', 'bugherd' ), |
| 103 |
'bugherd_project_key_settings_field', |
| 104 |
'bugherd_settings', |
| 105 |
'bugherd_settings' |
| 106 |
); |
| 107 |
|
| 108 |
// Enable admin Field. |
| 109 |
add_settings_field( |
| 110 |
'bugherd_enable_admin_field', |
| 111 |
__( 'Enable BugHerd in wp-admin?', 'bugherd' ), |
| 112 |
'bugherd_enable_admin_settings_field', |
| 113 |
'bugherd_settings', |
| 114 |
'bugherd_settings' |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Display the settings field for the Project Key. |
| 120 |
* |
| 121 |
* @return void |
| 122 |
* @since 1.0.0 |
| 123 |
*/ |
| 124 |
function bugherd_project_key_settings_field() { |
| 125 |
printf( |
| 126 |
'<label id="%2$s-description">%1$s:</label><input type="text" id="%2$s" name="%4$s" value="%3$s" aria-describedby="%2$s-description" class="regular-text ltr" /><p class="description">%5$s</p>', |
| 127 |
esc_html__( 'Project Key', 'bugherd' ), |
| 128 |
esc_attr( 'bugherd-project-key' ), |
| 129 |
esc_attr( get_option( 'bugherd_project_key' ) ), |
| 130 |
esc_attr( 'bugherd_project_key' ), |
| 131 |
esc_html__( 'Leave blank to disable plugin', 'bugherd' ) |
| 132 |
); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Display the settings for the Enable in Admin checkbox. |
| 137 |
* |
| 138 |
* @return void |
| 139 |
* @since 1.0.0 |
| 140 |
*/ |
| 141 |
function bugherd_enable_admin_settings_field() { |
| 142 |
printf( |
| 143 |
'<input type="checkbox" id="%2$s" name="%4$s" value="1" %3$s aria-describedby="%2$s-description" /><label id="%2$s-description">%1$s</label><p class="description">%5$s</p>', |
| 144 |
esc_html__( 'Also show BugHerd on WP Admin pages?', 'bugherd' ), |
| 145 |
esc_attr( 'bugherd-enable-admin' ), |
| 146 |
checked( get_option( 'bugherd_enable_admin' ), '1', false ), |
| 147 |
esc_attr( 'bugherd_enable_admin' ), |
| 148 |
esc_html__( 'If selected, the BugHerd sidebar will also appear on WordPress admin screens, in addition to your website.', 'bugherd' ) |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Display the options page. |
| 154 |
* |
| 155 |
* @return void |
| 156 |
* @since 1.0.0 |
| 157 |
*/ |
| 158 |
function bugherd_options_page() { |
| 159 |
|
| 160 |
// Logo. |
| 161 |
printf( |
| 162 |
'<img src="%s%s" class="bugherd-logo">', |
| 163 |
esc_url( plugin_dir_url( __DIR__ ) ), |
| 164 |
'assets/images/logo-web.png' |
| 165 |
); |
| 166 |
|
| 167 |
// Tagline. |
| 168 |
printf( |
| 169 |
'<h2 class="bugherd-tagline">%s<br>%s</h2>', |
| 170 |
esc_html__( 'The Visual Feedback', 'bugherd' ), |
| 171 |
esc_html__( 'Tool for Websites', 'bugherd' ) |
| 172 |
); |
| 173 |
|
| 174 |
echo '<form method="post" action="options.php" class="card bugherd-container">'; |
| 175 |
|
| 176 |
// Intro. |
| 177 |
printf( |
| 178 |
'<p>%s <a href="%s" target="_blank" rel="noopener">%s</a></p>', |
| 179 |
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' ), |
| 180 |
esc_url( 'https://support.bugherd.com/hc/en-us/articles/360002121575' ), |
| 181 |
esc_html__( 'Check out this help article.', 'bugherd' ) |
| 182 |
); |
| 183 |
|
| 184 |
// Settings. |
| 185 |
settings_fields( 'bugherd_settings' ); |
| 186 |
do_settings_sections( 'bugherd_settings' ); |
| 187 |
|
| 188 |
// Submit. |
| 189 |
printf( |
| 190 |
'<div class="bugherd-submit">%1$s<p>%2$s <a href="%3$s" target="_blank" rel="noopener">%3$s</a></p></div>', |
| 191 |
get_submit_button(), // phpcs:ignore |
| 192 |
esc_html__( 'Need help? Try', 'bugherd' ), |
| 193 |
esc_url( 'https://support.bugherd.com' ) |
| 194 |
); |
| 195 |
|
| 196 |
echo '</form>'; |
| 197 |
} |
| 198 |
|