Skip to content

Commit 95ce19a

Browse files
committed
sort plugin modal tabs
Signed-off-by: Andy Fragen <[email protected]> Fixes #279
1 parent b6fc7bb commit 95ce19a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

inc/packages/admin/namespace.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function bootstrap() {
3535
add_action( 'load-plugin-install.php', __NAMESPACE__ . '\\load_plugin_install' );
3636
add_action( 'install_plugins_pre_plugin-information', __NAMESPACE__ . '\\maybe_hijack_plugin_info', 0 );
3737
add_filter( 'plugins_api_result', __NAMESPACE__ . '\\alter_slugs', 10, 3 );
38+
add_filter( 'plugins_api_result', __NAMESPACE__ . '\\sort_sections_in_api', 15, 1 );
3839
add_filter( 'plugin_install_action_links', __NAMESPACE__ . '\\maybe_hijack_plugin_install_button', 10, 2 );
3940
add_filter( 'plugin_install_description', __NAMESPACE__ . '\\maybe_add_data_to_description', 10, 2 );
4041
add_action( 'wp_ajax_check_plugin_dependencies', __NAMESPACE__ . '\\set_slug_to_hashed' );
@@ -427,6 +428,32 @@ function alter_slugs( $res, $action, $args ) {
427428
return $res;
428429
}
429430

431+
/**
432+
* Sort plugin modal tabs.
433+
*
434+
* Based on standard tab listing order.
435+
*
436+
* @param object|WP_Error $res Response object or WP_Error.
437+
* @return object|WP_Error
438+
*/
439+
function sort_sections_in_api( $res ) {
440+
$ordered_sections = [
441+
'description',
442+
'installation',
443+
'faq',
444+
'screenshots',
445+
'changelog',
446+
'upgrade_notice',
447+
'other_notes',
448+
];
449+
if ( property_exists( $res, 'sections' ) ) {
450+
$properly_ordered = array_merge( array_fill_keys( $ordered_sections, '' ), $res->sections );
451+
$res->sections = array_filter( $properly_ordered );
452+
}
453+
454+
return $res;
455+
}
456+
430457
/**
431458
* Override the install button, for bridged plugins.
432459
*

0 commit comments

Comments
 (0)