Skip to content

Commit f4a8c4d

Browse files
committed
WP.org Abilities: Fully load the plugin directory for MCP requests.
Previously, only the class autoloader was loaded when handling MCP requests. This meant post types and custom statuses were not registered, so queries for plugins in the review queue returned empty results. Load the plugin bootstrap and run its initialization to ensure the full runtime environment is available. Also use the plugin directory's own slug lookup for consistency with the rest of the codebase. git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14769 74240141-8908-4e6f-9713-ba540dce6ec7
1 parent 2429594 commit f4a8c4d

3 files changed

Lines changed: 15 additions & 61 deletions

File tree

wordpress.org/public_html/wp-content/plugins/wporg-abilities/plugins/plugin-directory/class-ability-base.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace WordPressdotorg\Abilities\Plugins\Plugin_Directory;
1414

15+
use WordPressdotorg\Plugin_Directory\Plugin_Directory;
16+
1517
defined( 'ABSPATH' ) || exit;
1618

1719
/**
@@ -46,19 +48,11 @@ protected static function maybe_load_plugin_directory(): void {
4648
return;
4749
}
4850

49-
$autoloader = WP_PLUGIN_DIR . '/plugin-directory/class-autoloader.php';
50-
51-
if ( ! file_exists( $autoloader ) ) {
52-
return;
53-
}
51+
switch_to_blog( self::PLUGINS_BLOG_ID );
5452

55-
require_once $autoloader;
56-
\WordPressdotorg\Plugin_Directory\Autoloader\register_class_path(
57-
'WordPressdotorg\\Plugin_Directory',
58-
WP_PLUGIN_DIR . '/plugin-directory'
59-
);
53+
require_once WP_PLUGIN_DIR . '/plugin-directory/plugin-directory.php';
6054

61-
switch_to_blog( self::PLUGINS_BLOG_ID );
55+
Plugin_Directory::instance()->init();
6256

6357
$loaded = true;
6458
}

wordpress.org/public_html/wp-content/plugins/wporg-abilities/plugins/plugin-directory/tools/class-get-plugin-status.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use WordPressdotorg\Abilities\Plugins\Plugin_Directory\Ability_Base;
1313
use WordPressdotorg\Plugin_Directory\Clients\HelpScout as HelpScout_Client;
14+
use WordPressdotorg\Plugin_Directory\Plugin_Directory;
1415
use WordPressdotorg\Plugin_Directory\Template;
1516
use WordPressdotorg\Plugin_Directory\Tools\Helpscout;
1617

@@ -142,12 +143,15 @@ public static function check_permission(): bool|\WP_Error {
142143
public static function execute( array $input ): array {
143144
self::maybe_load_plugin_directory();
144145

145-
$slug = sanitize_title( $input['plugin_slug'] );
146-
$post = self::get_plugin_post( $slug );
146+
$post = Plugin_Directory::get_plugin_post( $input['plugin_slug'] );
147+
148+
if ( $post && (int) $post->post_author !== get_current_user_id() ) {
149+
$post = false;
150+
}
147151

148152
if ( ! $post ) {
149153
return array(
150-
'error' => sprintf( 'No plugin with slug "%s" was found for your account.', $slug ),
154+
'error' => sprintf( 'No plugin with slug "%s" was found for your account.', sanitize_title( $input['plugin_slug'] ) ),
151155
);
152156
}
153157

@@ -159,26 +163,6 @@ public static function execute( array $input ): array {
159163
);
160164
}
161165

162-
/**
163-
* Look up a plugin post owned by the current user.
164-
*
165-
* @param string $slug The plugin slug.
166-
* @return \WP_Post|null
167-
*/
168-
private static function get_plugin_post( string $slug ): ?\WP_Post {
169-
$posts = get_posts(
170-
array(
171-
'post_type' => 'plugin',
172-
'name' => $slug,
173-
'post_status' => 'any',
174-
'author' => get_current_user_id(),
175-
'numberposts' => 1,
176-
)
177-
);
178-
179-
return $posts[0] ?? null;
180-
}
181-
182166
/**
183167
* Build status data for the plugin.
184168
*

wordpress.org/public_html/wp-content/plugins/wporg-abilities/plugins/plugin-directory/tools/class-submit-plugin.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace WordPressdotorg\Abilities\Plugins\Plugin_Directory\Tools;
1111

1212
use WordPressdotorg\Abilities\Plugins\Plugin_Directory\Ability_Base;
13+
use WordPressdotorg\Plugin_Directory\Plugin_Directory;
1314
use WordPressdotorg\Plugin_Directory\Shortcodes\Upload_Handler;
1415

1516
defined( 'ABSPATH' ) || exit;
@@ -206,13 +207,12 @@ public static function execute( array $input ): array {
206207
// Step 3: Resolve $plugin_post_id.
207208
$plugin_post_id = 0;
208209
if ( $is_update ) {
209-
$slug = sanitize_title( $input['plugin_slug'] );
210-
$post = self::find_plugin_post( $slug );
210+
$post = Plugin_Directory::get_plugin_post( $input['plugin_slug'] );
211211

212212
if ( ! $post ) {
213213
return self::error_response(
214214
'plugin_not_found',
215-
sprintf( 'No plugin with slug "%s" was found for your account.', $slug ),
215+
sprintf( 'No plugin with slug "%s" was found for your account.', sanitize_title( $input['plugin_slug'] ) ),
216216
'Use wporg://plugins/plugin-directory/get-plugin-status to check your plugin slugs.'
217217
);
218218
}
@@ -475,30 +475,6 @@ private static function prepare_zip_from_base64( string $base64 ): array|string
475475
return $temp_path;
476476
}
477477

478-
/**
479-
* Find a plugin post owned by the current user or accessible to a plugin reviewer.
480-
*
481-
* @param string $slug The plugin slug.
482-
* @return \WP_Post|null
483-
*/
484-
private static function find_plugin_post( string $slug ): ?\WP_Post {
485-
$query_args = array(
486-
'post_type' => 'plugin',
487-
'name' => $slug,
488-
'post_status' => 'any',
489-
'numberposts' => 1,
490-
);
491-
492-
// Scope to the current user unless they can review plugins.
493-
if ( ! current_user_can( 'plugin_approve' ) ) { // phpcs:ignore WordPress.WP.Capabilities.Unknown -- plugin_approve is registered by the plugin-directory plugin.
494-
$query_args['author'] = get_current_user_id();
495-
}
496-
497-
$posts = get_posts( $query_args );
498-
499-
return $posts[0] ?? null;
500-
}
501-
502478
/**
503479
* Build a structured error response.
504480
*

0 commit comments

Comments
 (0)