Basic settings page with configurables

This commit is contained in:
j 2025-06-18 13:47:55 +10:00
parent 1cd9fa3c29
commit ff5a382856
6 changed files with 351 additions and 2 deletions

74
src/funcs/settings.php Normal file
View file

@ -0,0 +1,74 @@
<?php
defined('ABSPATH') or exit;
// === Add FWP Settings Menu + Recaptcha Page ===
add_action('admin_menu', 'fwp_add_settings_pages');
function fwp_add_settings_pages() {
// Create top-level "FWP Settings" if not already present
if (!isset($GLOBALS['admin_page_hooks']['fwp-settings'])) {
add_menu_page(
'FWP Settings',
'FWP Settings',
'manage_options',
'fwp-settings',
'__return_null',
'dashicons-admin-generic',
80
);
}
// Add FWP Recaptcha submenu
add_submenu_page(
'fwp-settings',
'FWP reCAPTCHA',
'FWP reCAPTCHA',
'manage_options',
'fwp-recaptcha',
'fwp_render_recaptcha_settings_page'
);
remove_submenu_page('fwp-settings', 'fwp-settings');
}
// === Register Settings ===
add_action('admin_init', 'fwp_register_recaptcha_settings');
function fwp_register_recaptcha_settings() {
register_setting('fwp_recaptcha_settings_group', 'fwp_recaptcha_enabled_forms');
register_setting('fwp_recaptcha_settings_group', 'fwp_recaptcha_site_key');
register_setting('fwp_recaptcha_settings_group', 'fwp_recaptcha_secret_key');
}
// === Render Settings Page ===
function fwp_render_recaptcha_settings_page() {
$enabled = get_option('fwp_recaptcha_enabled_forms', ['login', 'register', 'comment']);
$site_key = get_option('fwp_recaptcha_site_key', '');
$secret_key = get_option('fwp_recaptcha_secret_key', '');
?>
<div class="wrap">
<h1>FWP reCAPTCHA Settings</h1>
<form method="post" action="options.php">
<?php settings_fields('fwp_recaptcha_settings_group'); ?>
<table class="form-table" role="presentation">
<tr>
<th scope="row">Enable reCAPTCHA on:</th>
<td>
<label><input type="checkbox" name="fwp_recaptcha_enabled_forms[]" value="login" <?php checked(in_array('login', $enabled)); ?>> Login Form</label><br>
<label><input type="checkbox" name="fwp_recaptcha_enabled_forms[]" value="register" <?php checked(in_array('register', $enabled)); ?>> Registration Form</label><br>
<label><input type="checkbox" name="fwp_recaptcha_enabled_forms[]" value="comment" <?php checked(in_array('comment', $enabled)); ?>> Comment Form</label>
</td>
</tr>
<tr>
<th scope="row"><label for="fwp_recaptcha_site_key">Site Key</label></th>
<td><input type="text" name="fwp_recaptcha_site_key" id="fwp_recaptcha_site_key" value="<?php echo esc_attr($site_key); ?>" class="regular-text" /></td>
</tr>
<tr>
<th scope="row"><label for="fwp_recaptcha_secret_key">Secret Key</label></th>
<td><input type="text" name="fwp_recaptcha_secret_key" id="fwp_recaptcha_secret_key" value="<?php echo esc_attr($secret_key); ?>" class="regular-text" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}