Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix standalone plugins with 'PL' in list table and add plugin row meta link to Performance Lab settings screen #1052

Closed
wants to merge 2 commits into from
Closed
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
57 changes: 57 additions & 0 deletions admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,60 @@ function perflab_print_modules_page_style() {
</style>
<?php
}

/**
* Adds "PL" prefix to the names of all Performance Lab standalone plugins.
*
* @since n.e.x.t
*
* @param array<string, array{ Name: string }> $plugins Plugins.
* @return array<string, array{ Name: string }> Filtered plugins.
*/
function perflab_add_pl_prefix_to_standalone_plugins( array $plugins ): array {
$standalone_plugins = perflab_get_standalone_plugins();

$did_prefix = false;
$name_prefix = __( 'PL', 'performance-lab' ) . ' ';
foreach ( array_keys( $plugins ) as $plugin_basename ) {
if ( in_array( strtok( $plugin_basename, '/' ), $standalone_plugins, true ) ) {
$plugins[ $plugin_basename ]['Name'] = $name_prefix . $plugins[ $plugin_basename ]['Name'];

$did_prefix = true;
}
}

// Re-sort by name if prefixed.
if ( $did_prefix ) {
uasort(
$plugins,
static function ( array $a, array $b ) {
return strnatcasecmp( $a['Name'], $b['Name'] );
}
);
}

return $plugins;
}
add_filter( 'all_plugins', 'perflab_add_pl_prefix_to_standalone_plugins' );

/**
* Filters plugin row meta to add a Performance Lab link to its settings screen.
*
* @since n.e.x.t
*
* @param string[] $plugin_meta An array of the plugin's metadata, including
* the version, author, author URI, and plugin URI.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @return string[] Plugin meta.
*/
function perflab_filter_plugin_row_meta( array $plugin_meta, string $plugin_file ): array {
if ( in_array( strtok( $plugin_file, '/' ), perflab_get_standalone_plugins(), true ) ) {
$plugin_meta[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( add_query_arg( 'page', PERFLAB_MODULES_SCREEN, admin_url( 'options-general.php' ) ) ),
esc_html__( 'Performance Lab', 'performance-lab' )
);
}
return $plugin_meta;
}
add_filter( 'plugin_row_meta', 'perflab_filter_plugin_row_meta', 10, 2 );
Loading