wp_dashboard_site_health()


WordPressのwp_dashboard_site_health()関数は、ダッシュボードに「サイトヘルスステータス」ウィジェットを表示するために使用されます。この関数は管理画面のメインダッシュボードにサイトの健康状態に関する情報を追加します。

構文

wp_dashboard_site_health();

例1: 基本的な使用法

ダッシュボードにサイトヘルスステータスウィジェットを追加します。

add_action('wp_dashboard_setup', 'add_site_health_widget'); function add_site_health_widget() { wp_dashboard_site_health(); }

例2: 特定のユーザー権限に制限

管理者のみにサイトヘルスウィジェットを表示します。

add_action('wp_dashboard_setup', 'add_site_health_for_admin'); function add_site_health_for_admin() { if(current_user_can('manage_options')) { wp_dashboard_site_health(); } }

例3: 優先度を変更して表示位置を調整

ダッシュボードウィジェットの表示順序を変更します。

add_action('wp_dashboard_setup', 'change_site_health_priority', 999); function change_site_health_priority() { wp_dashboard_site_health(); }

例4: 他のダッシュボードウィジェットと一緒に使用

複数のダッシュボードウィジェットを登録する例です。

add_action('wp_dashboard_setup', 'register_multiple_widgets'); function register_multiple_widgets() { wp_dashboard_site_health(); wp_add_dashboard_widget('custom_widget', 'カスタムウィジェット', 'custom_widget_callback'); }

例5: サイトヘルスウィジェットを削除

デフォルトのサイトヘルスウィジェットを削除します。

add_action('wp_dashboard_setup', 'remove_default_site_health'); function remove_default_site_health() { remove_meta_box('dashboard_site_health', 'dashboard', 'normal'); }

例6: カスタムダッシュボードページに追加

カスタム管理ページにサイトヘルスウィジェットを表示します。

add_action('admin_init', 'add_to_custom_admin_page'); function add_to_custom_admin_page() { add_submenu_page('tools.php', 'サイトヘルス', 'サイトヘルス', 'manage_options', 'site-health', 'display_site_health'); function display_site_health() { wp_dashboard_site_health(); } }

例7: 翻訳対応

サイトヘルスウィジェットのテキストを翻訳可能にします。

add_action('wp_dashboard_setup', 'translatable_site_health'); function translatable_site_health() { load_plugin_textdomain('text-domain', false, dirname(plugin_basename(__FILE__)).'/languages/'); wp_dashboard_site_health(); }

注意点

  • wp_dashboard_site_health()はWordPress 5.2以降で利用可能です。
  • この関数は管理画面でのみ動作します。
  • サイトヘルス機能を無効化するにはwp_dashboard_setupフックを使用します。

関連機能: