=' ) || 0 === strpos( $version, MINIMUM_WP_VERSION . '-' ); } /** * Queues an error notice for display in the admin. * * @param string $message Notice message. May contain `code` and `a` tags. */ function queue_admin_error_notice( string $message ): void { add_action( 'admin_notices', static function () use ( $message ): void { printf( '
%s
' . esc_html( wp_get_wp_version() ) . ''
)
);
return;
}
if ( ! class_exists( \WordPress\AiClient\AiClient::class ) ) {
queue_admin_error_notice(
__( 'The AI Provider for amazee.ai plugin requires the WordPress AI client available in WordPress 7.0 and newer.', 'ai-provider-for-amazee-ai' )
);
return;
}
// The provider classes may already be autoloadable, e.g. on sites that
// install this plugin via Composer and load a site-wide autoloader.
// Otherwise fall back to the autoloader bundled with packaged releases.
if ( ! class_exists( AmazeeIoAiProvider::class ) ) {
$bundled_autoload = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $bundled_autoload ) ) {
require_once $bundled_autoload;
}
}
if ( ! class_exists( AmazeeIoAiProvider::class ) ) {
queue_admin_error_notice(
sprintf(
/* translators: %1$s: composer install command, %2$s: plugin directory path */
__( 'Your installation of the amazee.ai AI provider plugin is incomplete. Please run %1$s in the %2$s directory.', 'ai-provider-for-amazee-ai' ),
'composer install --no-dev',
'' . esc_html( plugin_dir_path( __FILE__ ) ) . ''
)
);
return;
}
add_action( 'init', __NAMESPACE__ . '\\register_provider' );
}
/**
* Registers the amazee.ai provider with the AI client registry.
*/
function register_provider(): void {
$registry = \WordPress\AiClient\AiClient::defaultRegistry();
if ( ! $registry->hasProvider( AmazeeIoAiProvider::class ) ) {
$registry->registerProvider( AmazeeIoAiProvider::class );
}
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\\bootstrap', 20 );
/**
* Add settings link to plugin actions.
*/
add_filter(
'plugin_action_links_' . plugin_basename( __FILE__ ),
function ( array $links ): array {
$settings_page_url = 'options-connectors.php';
$settings_link = sprintf(
'%2$s',
admin_url( $settings_page_url ),
esc_html__( 'Settings', 'ai-provider-for-amazee-ai' )
);
array_unshift( $links, $settings_link );
return $links;
}
);
// Credentials are managed by the WordPress core Connectors screen
// (Settings > Connectors), based on this provider's apiKey authentication
// metadata.