cba0df9439
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>
82 lines
3.2 KiB
PHP
82 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Buddy dashboard widget — the pet appears on the main WordPress
|
|
* Dashboard (`/wp-admin/index.php`) so the user sees it without
|
|
* navigating anywhere. This is the "Buddy exists" baseline of Phase A.
|
|
*
|
|
* The widget shows: the SVG character + the pet's name + current
|
|
* mood label + four stats bars. No interaction yet (Phase B will add
|
|
* Feed / Play / Clean / Sleep). The render also includes a "Visit
|
|
* Buddy" link that jumps to the dedicated admin page.
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
|
|
|
add_action( 'wp_dashboard_setup', 'buddy_register_dashboard_widget' );
|
|
function buddy_register_dashboard_widget() {
|
|
if ( ! current_user_can( 'read' ) ) { return; }
|
|
|
|
wp_add_dashboard_widget(
|
|
'buddy_dashboard_widget',
|
|
'🐾 ' . __( 'Buddy', 'rangerhq-buddy' ),
|
|
'buddy_render_dashboard_widget'
|
|
);
|
|
}
|
|
|
|
function buddy_render_dashboard_widget() {
|
|
$state = buddy_get_state();
|
|
$mood = buddy_overall_mood( $state );
|
|
$tone = buddy_mood_label( $mood );
|
|
?>
|
|
<div class="buddy-widget">
|
|
<div class="buddy-widget__pet">
|
|
<?php buddy_render_sprite( $state['species'], $tone['tone'], 'md' ); ?>
|
|
</div>
|
|
<div class="buddy-widget__info">
|
|
<div class="buddy-widget__name">
|
|
<?php echo esc_html( $state['name'] ); ?>
|
|
<span class="buddy-widget__mood buddy-widget__mood--<?php echo esc_attr( $tone['tone'] ); ?>">
|
|
<?php echo esc_html( $tone['label'] ); ?>
|
|
</span>
|
|
</div>
|
|
<?php buddy_render_stats_bars( $state ); ?>
|
|
<p class="buddy-widget__cta">
|
|
<a href="<?php echo esc_url( admin_url( 'admin.php?page=buddy' ) ); ?>" class="button button-small">
|
|
<?php esc_html_e( 'Visit Buddy →', 'rangerhq-buddy' ); ?>
|
|
</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* Render the four stats as labelled progress bars. Reused by the
|
|
* dedicated admin page so they look identical wherever Buddy appears.
|
|
*/
|
|
function buddy_render_stats_bars( array $state ) {
|
|
$stats = array(
|
|
'hunger' => array( 'label' => __( 'Hunger', 'rangerhq-buddy' ), 'icon' => '🍎' ),
|
|
'happiness' => array( 'label' => __( 'Happiness', 'rangerhq-buddy' ), 'icon' => '😊' ),
|
|
'health' => array( 'label' => __( 'Health', 'rangerhq-buddy' ), 'icon' => '💚' ),
|
|
'energy' => array( 'label' => __( 'Energy', 'rangerhq-buddy' ), 'icon' => '⚡' ),
|
|
);
|
|
echo '<ul class="buddy-stats">';
|
|
foreach ( $stats as $key => $meta ) {
|
|
$val = max( 0, min( 100, (int) ( $state[ $key ] ?? 0 ) ) );
|
|
$low = $val < 30;
|
|
printf(
|
|
'<li class="buddy-stat"><span class="buddy-stat__icon" aria-hidden="true">%s</span>'
|
|
. '<span class="buddy-stat__label">%s</span>'
|
|
. '<span class="buddy-stat__bar"><span class="buddy-stat__fill%s" style="width:%d%%"></span></span>'
|
|
. '<span class="buddy-stat__num">%d</span></li>',
|
|
esc_html( $meta['icon'] ),
|
|
esc_html( $meta['label'] ),
|
|
$low ? ' buddy-stat__fill--low' : '',
|
|
(int) $val,
|
|
(int) $val
|
|
);
|
|
}
|
|
echo '</ul>';
|
|
}
|