init();
} catch ( \Exception $e ) {
if ( is_admin() ) {
add_action(
'admin_notices',
function () use ( $e ) {
echo '
';
echo esc_html(
sprintf(
/* translators: %s: error message */
__( 'Albert Plugin Error: %s', 'albert-ai-butler' ),
$e->getMessage()
)
);
echo '
';
}
);
}
// Log the error for debugging.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Intentional debug logging when WP_DEBUG_LOG is enabled.
error_log( 'Albert Plugin Error: ' . $e->getMessage() );
}
}
}
// Initialize the plugin.
add_action( 'plugins_loaded', 'albert_init' );
/**
* Plugin activation hook.
*
* @return void
* @since 1.0.0
*/
function albert_activate(): void {
Plugin::activate();
}
register_activation_hook( __FILE__, 'albert_activate' );
/**
* Plugin deactivation hook.
*
* @return void
* @since 1.0.0
*/
function albert_deactivate(): void {
Plugin::deactivate();
}
register_deactivation_hook( __FILE__, 'albert_deactivate' );
// Drop all Albert tables (ability log + OAuth) on uninstall. Fires only when the
// plugin is deleted — not on update or deactivate.
register_uninstall_hook( __FILE__, [ 'Albert\Database\Installer', 'uninstall' ] );
/**
* Add settings link to plugin action links.
*
* @param array $links Existing plugin action links.
*
* @return array Modified plugin action links.
* @since 1.0.0
*/
function albert_plugin_action_links( array $links ): array {
$settings_link = sprintf(
'%s',
esc_url( admin_url( 'admin.php?page=albert-settings' ) ),
esc_html__( 'Settings', 'albert-ai-butler' )
);
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links_' . ALBERT_PLUGIN_BASENAME, 'albert_plugin_action_links' );