<?php

namespace ModernFields\WordPress\Hooks;

use ModernFields\WordPress\Interfaces\Hooks;

use ModernFields\WordPress\Security\SecurityHelper;

defined('ABSPATH') || exit;

/**
 * Handles customization of the WordPress admin footer text.
 *
 * @since 1.0.0
 */
class Signature implements Hooks
{
  /**
   * @since 1.0.0
   */
  public function registerHooks(): void
  {
    add_filter('admin_footer_text', [$this, 'modifyFooterText']);
  }

  /**
   * Appends a custom signature on all Modern Fields admin pages.
   *
   * @since 1.0.0
   * @param string $text The default footer text.
   * @return string
   */
  public function modifyFooterText(string $text): string
  {
    if (SecurityHelper::isCurrentAdminPage(['admin.php']) && isset($_GET['page']) && str_starts_with($_GET['page'], 'modern-fields-')) {
      return $text . ' <a href="https://modern-fields.com" target="_blank" rel="noopener">Modern Fields</a> is crafted with love ♥️ in the French 🇫🇷 Alps 🏔️.';
    }

    return $text;
  }
}
