Как правильно выводить сообщение пользователю, что плаги был успешно активировал или не возможно активировать плагин по конкретной ошибке
мой код
<?php
/**
* Plugin Name: tested
* Description: tested
* Version: 1.0.0
* Author: tested tested
* Requires at least: 5.2
* Requires PHP: 7.0
* @package tested
*/
// Define constants.
define('LOVAT_API_PLUGIN_VERSION', '1.0.0');
define('LOVAT_API_PLUGIN_DIR', untrailingslashit(plugin_dir_path(__FILE__)));
define('LOVAT_API_URL', plugin_dir_url(__FILE__));
// Include the main class.
require plugin_dir_path(__FILE__) . 'includes/class-lovat.php';
//// Load core packages and the autoloader.
include_once(LOVAT_API_PLUGIN_DIR . '/autoload.php');
//activate plugin, create
function activate_lovat_api()
{
require_once plugin_dir_path(__FILE__) . 'includes/class-lovat-activator.php';
new Lovat_Activator();
}
//deactivate plugin
function deactivate_lovat_api()
{
require_once plugin_dir_path(__FILE__) . 'includes/class-lovat-deactivator.php';
Lovat_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_lovat_api' );
register_deactivation_hook( __FILE__, 'deactivate_lovat_api' );
// Main instance of plugin.
function Lovat()
{
return Lovat::instance();
}
// Global for backwards compatibility.
$GLOBALS['lovat_api'] = Lovat();
<?php
class Lovat_Activator
{
private function __construct()
{
do_action( 'admin_notices', array( $this, 'activate' ) ) ;
}
public static function activate()
{
if (is_plugin_active('woocommerce/woocommerce.php')) {
global $wpdb;
$table = $wpdb->prefix . "lovat_api_keys";
$charset_collate = $wpdb->get_charset_collate();
if ($wpdb->get_var("show tables like '" . $table . "'") != $table) {
$sql = "CREATE TABLE $table (
id int(9) NOT NULL AUTO_INCREMENT,
token VARCHAR(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
user_id INT(4) NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
} else {
$html = '<div class="error">';
$html .= '<p>';
$html .= __('Для работы плагина, пожалуйста, установите или активируйте плагин WooCommerce');
$html .= '</p>';
$html .= '</div>';
echo $html;
}
}
}