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

Updated code to display plugin settings link in the features screen and fix responsive layout for mobile #1208

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d11dfee
Updated code to display plugin settings link in the features screen
ashwinparthasarathi May 7, 2024
c7cd3d1
Merge branch 'trunk' into add/plugin-settings-link-in-features-screen
ashwinparthasarathi May 7, 2024
3fd724e
Merge branch 'WordPress:trunk' into add/plugin-settings-link-in-featu…
ashwinparthasarathi May 8, 2024
e88f109
Updated code to fetch plugin path from plugin list
ashwinparthasarathi May 8, 2024
e7dbfa6
Merge branch 'add/plugin-settings-link-in-features-screen' of github.…
ashwinparthasarathi May 8, 2024
95642a3
Fix function stub docs
mukeshpanchal27 May 7, 2024
2da8c22
Bump PHPStan level to 5
westonruter May 6, 2024
c197b9f
Ignore phpstan errors when testing for incorrect usage
westonruter May 6, 2024
1501ebc
Fix types for arguments passed in tests
westonruter May 6, 2024
bc55f7a
Add rememberPossiblyImpureFunctionValues:false to fix it_should_use_t…
westonruter May 6, 2024
d024264
Add comments explaining why PHPStan is ignored
westonruter May 7, 2024
8067df4
Updated code to fetch plugin path from plugin list
ashwinparthasarathi May 8, 2024
b4b73ca
fix: avoid needless array allocation in rgb to hex conversion
ju1ius Apr 1, 2024
3a3d733
Ensure RGB variable is int
westonruter May 8, 2024
2473091
Add test case for when RGB values are too high
westonruter May 8, 2024
91b1f73
Merge branch 'add/plugin-settings-link-in-features-screen' of github.…
ashwinparthasarathi May 8, 2024
0fe54ec
Moved Settings to the last action link and made review changes.
ashwinparthasarathi May 13, 2024
eecfad1
Moved Settings to the last action link
ashwinparthasarathi May 13, 2024
08b83aa
Merge branch 'trunk' into add/plugin-settings-link-in-features-screen
westonruter May 13, 2024
606c4e3
Added settings link to activation admin notice.
ashwinparthasarathi May 15, 2024
18a71cc
Changed as per review shared.
ashwinparthasarathi May 16, 2024
0cf11f5
Updated the admin notice for conditions
ashwinparthasarathi May 16, 2024
b946a4d
Updated as per review changes.
ashwinparthasarathi May 16, 2024
3e6b9d4
Updated as per review changes.
ashwinparthasarathi May 16, 2024
ea00ad5
Merge branch 'trunk' into add/plugin-settings-link-in-features-screen
ashwinparthasarathi May 16, 2024
af3b5a9
Improve sanitization logic for plugin slug
westonruter May 16, 2024
c7ba02c
Prevent Settings link from overflowing plugin card
westonruter May 16, 2024
893e91b
Factor out common plugin slug sanitization logic
westonruter May 16, 2024
57e0f8e
Fix presentation of plugin cards on mobile
westonruter May 16, 2024
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
55 changes: 53 additions & 2 deletions includes/admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function perflab_install_activate_plugin_callback(): void {
$url = add_query_arg(
array(
'page' => PERFLAB_SCREEN,
'activate' => 'true',
'activate' => $plugin_slug,
),
admin_url( 'options-general.php' )
);
Expand Down Expand Up @@ -330,8 +330,27 @@ static function ( $name ) {
}

if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$message = __( 'Feature activated.', 'performance-lab' );

$plugin_settings_link = perflab_get_plugin_settings_link( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved

if ( $plugin_settings_link ) {
$p = new WP_HTML_Tag_Processor( $plugin_settings_link );
if ( ! empty( $p->next_tag( array( 'tag_name' => 'A' ) ) ) && ! empty( $p->get_attribute( 'href' ) ) && ! is_bool( $p->get_attribute( 'href' ) ) ) {
/* translators: %s is the settings URL */
$message .= ' ' . sprintf( __( 'Review <a href="%s">settings</a>.', 'performance-lab' ), esc_url( $p->get_attribute( 'href' ) ) );
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
}
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
}

wp_admin_notice(
esc_html__( 'Feature activated.', 'performance-lab' ),
wp_kses(
$message,
array(
'a' => array(
'href' => array(),
),
)
),
array(
'type' => 'success',
'dismissible' => true,
Expand Down Expand Up @@ -375,3 +394,35 @@ function addPluginProgressIndicator( message ) {
array( 'type' => 'module' )
);
}

/**
* Callback function that returns plugin settings link.
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
*
* @since n.e.x.t
*
* @param string $plugin_slug Plugin slug passed to generate the settings link.
* @return string|null Either the plugin settings link or null if not available.
*/
function perflab_get_plugin_settings_link( string $plugin_slug ): ?string {
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
$plugin_file = null;

foreach ( array_keys( get_plugins() ) as $file ) {
if ( strtok( $file, '/' ) === $plugin_slug ) {
$plugin_file = $file;
break;
}
}

if ( null === $plugin_file ) {
return null;
}

/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */
$plugin_links = apply_filters( "plugin_action_links_{$plugin_file}", array() );

if ( is_array( $plugin_links ) && array_key_exists( 'settings', $plugin_links ) ) {
return $plugin_links['settings'];
}
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved

return null;
}
15 changes: 12 additions & 3 deletions includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,20 @@ function perflab_render_plugin_card( array $plugin_data ): void {
/** This filter is documented in wp-admin/includes/class-wp-plugin-install-list-table.php */
$description = apply_filters( 'plugin_install_description', $description, $plugin_data );

$availability = perflab_get_plugin_availability( $plugin_data );

$availability = perflab_get_plugin_availability( $plugin_data );
$compatible_php = $availability['compatible_php'];
$compatible_wp = $availability['compatible_wp'];

$action_links = array();

$show_settings_link = false;

ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
if ( $availability['activated'] ) {
$action_links[] = sprintf(
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
esc_html( _x( 'Active', 'plugin', 'default' ) )
);
$show_settings_link = true;
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
} elseif (
$availability['compatible_php'] &&
$availability['compatible_wp'] &&
Expand Down Expand Up @@ -398,6 +400,13 @@ function perflab_render_plugin_card( array $plugin_data ): void {
esc_html__( 'Visit plugin site', 'default' )
);
}

if ( $show_settings_link ) {
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
$plugin_link = perflab_get_plugin_settings_link( $plugin_data['slug'] );
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
if ( ! empty( $plugin_link ) ) {
ashwinparthasarathi marked this conversation as resolved.
Show resolved Hide resolved
$action_links[] = $plugin_link;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the $show_settings_link variable needed? Couldn't this code be put right up above where $show_settings_link = true; is currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter yes the variable is needed as the suggestion to move the Settings links to the last in the list made the "Learn more" link consistent over all the plugin cards.

I set a variable in the if condition checking if the plugin is active, and at the end of the else condition, added the Settings link into the action links array.

?>
<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin_data['slug'] ); ?>">
<?php
Expand Down
Loading