Skip to content

Commit 707fa78

Browse files
committed
Connectors: Change admin URL to options-connectors.php.
Changes the Connectors screen URL from a query parameter page to a direct file, following the Settings menu naming convention used by other settings pages (`options-general.php`, `options-writing.php`, etc.). * Adds `src/wp-admin/options-connectors.php` as a direct admin screen file. * Adds a static submenu entry in `menu.php` at position 12 (after General). * Removes `_wp_connectors_add_settings_menu_item()` and its `admin_menu` hook from `connectors.php`. * Updates the `script_module_data` filter from `connectors-wp-admin` to `options-connectors-wp-admin`. Synced from WordPress/gutenberg#76142. Developed in WordPress#11157. Follow-up to [61749], [61824]. See #64730. Props jorgefilipecosta, gziolo. Fixes #64790. git-svn-id: https://develop.svn.wordpress.org/trunk@61825 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 21f3a54 commit 707fa78

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

src/wp-admin/menu.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ function _add_plugin_file_editor_to_tools() {
404404

405405
$menu[80] = array( __( 'Settings' ), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
406406
$submenu['options-general.php'][10] = array( _x( 'General', 'settings screen' ), 'manage_options', 'options-general.php' );
407+
$submenu['options-general.php'][12] = array( __( 'Connectors' ), 'manage_options', 'options-connectors.php' );
407408
$submenu['options-general.php'][15] = array( __( 'Writing' ), 'manage_options', 'options-writing.php' );
408409
$submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' );
409410
$submenu['options-general.php'][25] = array( __( 'Discussion' ), 'manage_options', 'options-discussion.php' );
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Connectors administration screen.
4+
*
5+
* @package WordPress
6+
* @subpackage Administration
7+
* @since 7.0.0
8+
*/
9+
10+
/** WordPress Administration Bootstrap */
11+
require_once __DIR__ . '/admin.php';
12+
13+
if ( ! current_user_can( 'manage_options' ) ) {
14+
wp_die(
15+
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
16+
'<p>' . __( 'Sorry, you are not allowed to manage connectors on this site.' ) . '</p>',
17+
403
18+
);
19+
}
20+
21+
if ( ! class_exists( '\WordPress\AiClient\AiClient' ) || ! function_exists( 'wp_options_connectors_wp_admin_render_page' ) ) {
22+
wp_die(
23+
'<h1>' . __( 'Connectors is not available.' ) . '</h1>' .
24+
'<p>' . __( 'The Connectors page requires build files. Please run <code>npm install</code> to build the necessary files.' ) . '</p>',
25+
503
26+
);
27+
}
28+
29+
// Set the page title.
30+
$title = __( 'Connectors' );
31+
32+
// Set parent file for menu highlighting.
33+
$parent_file = 'options-general.php';
34+
35+
require_once ABSPATH . 'wp-admin/admin-header.php';
36+
37+
// Render the Connectors page.
38+
wp_options_connectors_wp_admin_render_page();
39+
40+
require_once ABSPATH . 'wp-admin/admin-footer.php';

src/wp-includes/connectors.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,6 @@
1010
use WordPress\AiClient\AiClient;
1111
use WordPress\AiClient\Providers\Http\DTO\ApiKeyRequestAuthentication;
1212

13-
/**
14-
* Registers the Connectors menu item under Settings.
15-
*
16-
* @since 7.0.0
17-
* @access private
18-
*/
19-
function _wp_connectors_add_settings_menu_item(): void {
20-
if ( ! class_exists( '\WordPress\AiClient\AiClient' ) || ! function_exists( 'wp_connectors_wp_admin_render_page' ) ) {
21-
return;
22-
}
23-
24-
add_submenu_page(
25-
'options-general.php',
26-
__( 'Connectors' ),
27-
__( 'Connectors' ),
28-
'manage_options',
29-
'connectors-wp-admin',
30-
'wp_connectors_wp_admin_render_page',
31-
1
32-
);
33-
}
34-
add_action( 'admin_menu', '_wp_connectors_add_settings_menu_item' );
3513

3614
/**
3715
* Masks an API key, showing only the last 4 characters.
@@ -415,4 +393,4 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {
415393
$data['connectors'] = $connectors;
416394
return $data;
417395
}
418-
add_filter( 'script_module_data_connectors-wp-admin', '_wp_connectors_get_connector_script_module_data' );
396+
add_filter( 'script_module_data_options-connectors-wp-admin', '_wp_connectors_get_connector_script_module_data' );

0 commit comments

Comments
 (0)