Files
rangerhq-buddy/inc/settings.php
T
ranger cba0df9439 chore: wp.org submission prep — v0.1.3
Rebrand to RangerHQ Buddy and prepare for the WordPress.org Plugin
Directory. Same workflow as rangerhq-radio v0.7.0 → v0.7.5.

Changes:
- Plugin Name: Buddy → RangerHQ Buddy (matches family naming)
- Plugin URI: icanhelp.ie/buddy → davidtkeane.com/rangerhq-buddy
- Author URI: rangersmyth.xyz → davidtkeane.com
- Text Domain: buddy → rangerhq-buddy (62 occurrences across 8 PHP files)
- Add LICENSE file (full GPL v2 text from gnu.org)
- Add wp.org-format readme.txt with all 8 required headers
- Remove inc/updater.php (self-hosted Gitea updater forbidden for
  wp.org-hosted plugins per the rangerhq-radio v0.7.3 walkback)
- Replace mt_rand with wp_rand in inc/state.php for better RNG
- Add 5 translator comments for printf-style i18n placeholders
- Wrap 2 dashboard-widget.php printf placeholders in (int) casts
- Add tests/ to .gitignore (PCP reports are local-only)

PCP audit: 85 issues → ~1 (the .gitignore file itself, stripped from
the submission zip).
Plugin Check Namer Tool: "Generally Allowable" verdict on both name
and slug.
Plugin URI https://davidtkeane.com/rangerhq-buddy/ returns HTTP 200.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-07 01:56:26 +01:00

78 lines
2.9 KiB
PHP

<?php
/**
* Buddy settings page — placeholder shell for Phase A. Settings will
* grow in later phases:
* Phase B: cooldown timers
* Phase C: decay tick interval
* Phase D: species picker (currently only one available)
* Phase E: site-health integration toggle
*
* For v0.1.0 this page exists to (a) host the Updates panel from the
* Logbook-style update checker, and (b) let the user rename their
* Buddy.
*/
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
* Handle the rename form POST. Capability-gated to anyone who can
* read (every WP user) since each user owns their own Buddy.
*/
add_action( 'admin_init', 'buddy_handle_rename_post' );
function buddy_handle_rename_post() {
if ( empty( $_POST['buddy_rename_submit'] ) ) { return; }
if ( ! current_user_can( 'read' ) ) { return; }
if ( ! isset( $_POST['buddy_rename_nonce'] )
|| ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['buddy_rename_nonce'] ) ), 'buddy_rename' ) ) {
return;
}
$new_name = isset( $_POST['buddy_name'] ) ? sanitize_text_field( wp_unslash( $_POST['buddy_name'] ) ) : '';
if ( $new_name === '' || mb_strlen( $new_name ) > 32 ) { return; }
buddy_update_state( array( 'name' => $new_name ) );
add_action( 'admin_notices', function () {
printf(
'<div class="notice notice-success is-dismissible"><p>%s</p></div>',
esc_html__( 'Buddy renamed.', 'rangerhq-buddy' )
);
} );
}
function buddy_render_settings_page() {
if ( ! current_user_can( 'read' ) ) {
wp_die( esc_html__( 'You do not have permission to view this page.', 'rangerhq-buddy' ) );
}
$state = buddy_get_state();
?>
<div class="wrap">
<h1><?php esc_html_e( 'Buddy Settings', 'rangerhq-buddy' ); ?></h1>
<form method="post" style="max-width: 720px; background:#fff; padding:18px 22px; border:1px solid #ccd0d4; border-radius:4px; margin-top: 16px;">
<?php wp_nonce_field( 'buddy_rename', 'buddy_rename_nonce' ); ?>
<h2 style="margin-top:0;"><?php esc_html_e( 'Name', 'rangerhq-buddy' ); ?></h2>
<p>
<label for="buddy_name"><?php esc_html_e( 'What is your Buddy called?', 'rangerhq-buddy' ); ?></label><br>
<input type="text"
name="buddy_name"
id="buddy_name"
value="<?php echo esc_attr( $state['name'] ); ?>"
maxlength="32"
class="regular-text">
</p>
<p>
<button type="submit" name="buddy_rename_submit" class="button button-primary">
<?php esc_html_e( 'Save name', 'rangerhq-buddy' ); ?>
</button>
</p>
</form>
<?php
// Updates panel — defined in inc/updater.php.
if ( function_exists( 'buddy_render_updates_panel' ) ) {
buddy_render_updates_panel();
}
?>
</div>
<?php
}