Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions includes/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,39 @@
return true;
}

/**
* Checks whether the current WordPress environment supports AI.
*
* Displays an admin notice if not.
*
* @since x.x.x
Comment thread
justlevine marked this conversation as resolved.
*
* @return bool True if AI is supported, false otherwise.
*/
function check_ai_support(): bool {
// @todo Remove the function check once the minimum WordPress version is 7.0 or higher.
if ( ! function_exists( 'wp_supports_ai' ) || wp_supports_ai() ) {
return true;
}

foreach ( array( 'admin_notices', 'network_admin_notices' ) as $hook ) {
add_action(
$hook,
static function () {
wp_admin_notice(
esc_html__( 'Your WordPress environment has AI functionality disabled. The AI Experiments plugin will not work until AI support is enabled.', 'ai' ),
array(
'type' => 'error',
'dismiss' => false,
)
);
}
);
}
Comment thread
justlevine marked this conversation as resolved.

return false;
}

/**
* Adds action links to the plugin list table.
*
Expand Down Expand Up @@ -306,8 +339,8 @@
return;
}

// Check version requirements.
if ( ! check_php_version() || ! check_wp_version() ) {
// Check plugin requirements.
if ( ! check_php_version() || ! check_wp_version() || ! check_ai_support() ) {
return;
}

Expand All @@ -331,8 +364,8 @@
// Add plugin action links.
add_filter( 'plugin_action_links_' . plugin_basename( WPAI_PLUGIN_FILE ), __NAMESPACE__ . '\plugin_action_links' );

// Hook feature initialization to init.
add_action( 'init', __NAMESPACE__ . '\initialize_features', 15 );
// Hook experiment initialization to init.
add_action( 'init', __NAMESPACE__ . '\initialize_experiments' );

Check failure on line 368 in includes/bootstrap.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #2 $callback of function add_action expects callable(): mixed, 'WordPress\\AI…' given.
}

/**
Expand Down
Loading