'
. ' '
. wp_nonce_field( self::ACTION, '_wpnonce', true, false )
. '' . esc_html( $label ) . ' ';
}
/**
* On the Plugins screen only, while MCP Adapter is missing or inactive.
* It goes away by itself once the step is done.
*/
public static function notice() {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( ! $screen || 'plugins' !== $screen->base || ! current_user_can( 'activate_plugins' ) ) {
return;
}
$state = self::state();
if ( 'active' === $state ) {
return;
}
echo '
' . esc_html__( 'AdMindra MCP is active. One step left:', 'admindra-mcp' ) . ' ';
echo esc_html__( 'ChatGPT and Claude connect through MCP Adapter, the free plugin from the WordPress AI team.', 'admindra-mcp' ) . '
';
if ( self::allowed( $state ) ) {
echo '
';
} else {
echo '
' . esc_html__( 'Ask an administrator who can install plugins to install and activate MCP Adapter.', 'admindra-mcp' ) . '
';
}
echo '
';
}
/**
* Where the "came from the button" mark waits, per person.
*
* @return string
*/
private static function started_key() {
return 'admindra_mcp_setup_' . get_current_user_id();
}
/**
* The button's handler: remember that the step was started here, then
* hand over to WordPress's install screen or activate link.
*/
public static function run() {
check_admin_referer( self::ACTION );
$state = self::state();
if ( 'active' === $state ) {
wp_safe_redirect( add_query_arg( 'adm-setup', 'done', AdMindra_MCP::page_url() ) );
exit;
}
if ( ! self::allowed( $state ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to install or activate plugins on this site.', 'admindra-mcp' ), '', array( 'response' => 403 ) );
}
set_transient( self::started_key(), 1, 30 * MINUTE_IN_SECONDS );
wp_safe_redirect( self::core_url( $state ) );
exit;
}
/**
* WordPress's own screen for the step.
*
* @param string $state 'missing' or 'inactive'.
* @return string
*/
public static function core_url( $state ) {
if ( 'missing' === $state ) {
return add_query_arg(
array(
'action' => 'install-plugin',
'plugin' => self::SLUG,
'_wpnonce' => wp_create_nonce( 'install-plugin_' . self::SLUG ),
),
self_admin_url( 'update.php' )
);
}
$file = self::installed_file();
return add_query_arg(
array(
'action' => 'activate',
'plugin' => rawurlencode( $file ),
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file ),
),
self_admin_url( 'plugins.php' )
);
}
/**
* After WordPress activated MCP Adapter for someone who started from
* this plugin's button, open this plugin's screen instead of the list.
*/
public static function come_back() {
global $pagenow;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- reads WordPress's own "activated" flag; nothing is changed.
if ( 'plugins.php' !== $pagenow || ! isset( $_GET['activate'] ) || ! get_transient( self::started_key() ) || ! self::ready() ) {
return;
}
delete_transient( self::started_key() );
wp_safe_redirect( add_query_arg( 'adm-setup', 'done', AdMindra_MCP::page_url() ) );
exit;
}
}