rareloop / lumberjack-sitehealth

此包的最新版本(v1.0.1)没有可用的许可信息。

v1.0.1 2023-04-05 14:19 UTC

This package is auto-updated.

Last update: 2024-09-05 17:33:31 UTC


README

此包提供了一个简单的方法来注册自定义检查,这些检查是WordPress 5.2中引入的网站健康功能的一部分。

安装后,请在 config/app.php 中注册服务提供者

'providers' => [
    ...

    Rareloop\Lumberjack\SiteHealth\SiteHealthServiceProvider::class,

    ...
],

配置

您可以在 config/sitehealth.php 文件中注册自定义检查

return [
    'checks' => [
        \App\SiteHealth\MyCustomCheck::class,
    ],
];

创建检查

创建一个继承自 Rareloop\Lumberjack\SiteHealth\HealthCheck 类的类,并在配置中注册,如上所述。

示例

<?php

namespace App\SiteHealth;

use Rareloop\Lumberjack\SiteHealth\HealthCheck;

class MyCustomCheck extends HealthCheck
{
    public function identifier(): string
    {
        return 'my-custom-check';
    }

    public function label(): string
    {
        return __('My Custom Check');
    }

    public function execute(): array
    {
        return [
            'label' => 'My custom function test',
            'description' => 'The callback to this test worked',
            'badge' => [
                'label' => 'Performance',
                'color' = 'blue',
            ],
            'status' => 'good', // 'good'|'recommended'|'critical'
            'test' => $this->identifier(),
        ];
    }
}

关于 execute() 方法应返回的内容的详细信息,可以在WordPress 5.2 发布说明中找到。

设置异步或直接

默认情况下,所有检查都将注册为 async。如果您希望它直接运行,请将以下方法添加到您的类中

public function type()
{
    return static::DIRECT;
}