-
Notifications
You must be signed in to change notification settings - Fork 138
Improve discoverability and user guidance for Optimization Detective extensions #2261
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
accd806
d8d4aeb
1d2e403
425cf0f
b73b1de
773eb78
83bc123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,6 +197,135 @@ function od_render_generator_meta_tag(): void { | |
| echo '<meta name="generator" content="' . esc_attr( $content ) . '">' . "\n"; | ||
| } | ||
|
|
||
| /** | ||
| * Adds an Extensions link to the plugin action links for Optimization Detective. | ||
| * | ||
| * This link directs users to the plugin directory to discover extensions that | ||
| * provide optimization functionality using the Optimization Detective plugin. | ||
| * | ||
| * @since n.e.x.t | ||
| * @access private | ||
| * | ||
| * @param string[]|mixed $links List of plugin action links HTML. | ||
| * @return string[]|mixed Modified list of plugin action links HTML. | ||
| */ | ||
| function od_render_extensions_action_link( $links ) { | ||
| if ( ! is_array( $links ) ) { | ||
| return $links; | ||
| } | ||
|
|
||
| $extensions_link = sprintf( | ||
| '<a href="%1$s">%2$s</a>', | ||
| esc_url( admin_url( 'plugin-install.php?s=optimization-detective&tab=search&type=tag' ) ), | ||
| esc_html__( 'Extensions', 'optimization-detective' ) | ||
| ); | ||
|
|
||
| return array_merge( | ||
| array( 'extensions' => $extensions_link ), | ||
| $links | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Checks for installed extensions of Optimization Detective. | ||
| * | ||
| * @since n.e.x.t | ||
| * @access private | ||
| * | ||
| * @return string[] List of installed extension plugin slugs. | ||
| */ | ||
| function od_check_installed_extensions(): array { | ||
| $installed_plugins = get_plugins(); | ||
| $installed_extensions = array(); | ||
|
|
||
| foreach ( $installed_plugins as $plugin_slug => $plugin_data ) { | ||
| if ( isset( $plugin_data['RequiresPlugins'] ) && 'optimization-detective' === $plugin_data['RequiresPlugins'] ) { | ||
| $installed_extensions[] = $plugin_slug; | ||
| } | ||
| } | ||
|
|
||
| // Check for plugins without Requires Plugins header but known to be extensions. | ||
| $extensions = array( | ||
| 'embed-optimizer/load.php', | ||
| ); | ||
| $installed_extensions = array_merge( $installed_extensions, array_intersect( $extensions, array_keys( $installed_plugins ) ) ); | ||
|
|
||
| return $installed_extensions; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Working on using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this, I think there's still a need for a hardcoded list, since Embed Optimizer doesn’t list Optimization Detective as a requirement.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 83bc123. |
||
|
|
||
| /** | ||
| * Renders an admin notice prompting the user to install extensions for Optimization Detective. | ||
| * | ||
| * @since n.e.x.t | ||
| * @access private | ||
| */ | ||
| function od_maybe_render_installed_extensions_admin_notice(): void { | ||
| $message = sprintf( | ||
| '<p><strong>%s</strong></p>', | ||
| esc_html__( 'Optimization Detective does not provide any functionality on its own.', 'optimization-detective' ) | ||
| ); | ||
|
|
||
| $message .= '<p>' . esc_html__( 'This plugin is a framework that requires extension plugins to provide optimization features. To benefit from Optimization Detective, please install one or more of the following extensions:', 'optimization-detective' ) . '</p>'; | ||
|
|
||
| $extensions = array( | ||
| 'image-prioritizer' => array( | ||
| 'name' => __( 'Image Prioritizer', 'optimization-detective' ), | ||
| 'description' => __( 'Prioritizes the loading of images and videos based on how visible they are to actual visitors; adds fetchpriority and applies lazy-loading.', 'optimization-detective' ), | ||
| 'url' => admin_url( 'plugin-install.php?tab=plugin-information&plugin=image-prioritizer&TB_iframe=true&width=772' ), | ||
| ), | ||
| 'embed-optimizer' => array( | ||
| 'name' => __( 'Embed Optimizer', 'optimization-detective' ), | ||
| 'description' => __( 'Optimizes the performance of embeds through lazy-loading, preconnecting, and reserving space to reduce layout shifts.', 'optimization-detective' ), | ||
| 'url' => admin_url( 'plugin-install.php?tab=plugin-information&plugin=embed-optimizer&TB_iframe=true&width=772' ), | ||
| ), | ||
| ); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this info be fetched from the WordPress Plugin Directory using the newly introduced tag, or is it better to keep it hardcoded and only recommend Performance Lab plugins?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc: @westonruter |
||
|
|
||
| $message .= '<table class="widefat" style="margin-bottom: 11px;"><tbody>'; | ||
| foreach ( $extensions as $extension ) { | ||
| $message .= sprintf( | ||
| '<tr> | ||
| <td><strong><a href="%s" class="thickbox open-plugin-details-modal">%s</a></strong></td> | ||
| <td>%s</td> | ||
| </tr>', | ||
| esc_url( $extension['url'] ), | ||
| esc_html( $extension['name'] ), | ||
| esc_html( $extension['description'] ) | ||
| ); | ||
| } | ||
| $message .= '</tbody></table>'; | ||
|
|
||
| $notice = wp_get_admin_notice( | ||
| $message, | ||
| array( | ||
| 'type' => 'warning', | ||
| 'paragraph_wrap' => false, | ||
| ) | ||
| ); | ||
|
|
||
| add_thickbox(); | ||
| echo wp_kses( $notice, wp_kses_allowed_html( 'post' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Checks for installed extensions and displays an admin notice once if none are found. | ||
| * | ||
| * @since n.e.x.t | ||
| * @access private | ||
| */ | ||
| function od_maybe_check_installed_extensions(): void { | ||
| if ( 1 === (int) get_option( 'od_installed_extensions_admin_notice', '0' ) ) { | ||
| return; | ||
| } | ||
| update_option( 'od_installed_extensions_admin_notice', '1' ); | ||
|
|
||
| $installed_extensions = od_check_installed_extensions(); | ||
| if ( count( $installed_extensions ) > 0 ) { | ||
| return; | ||
| } | ||
|
|
||
| add_action( 'admin_notices', 'od_maybe_render_installed_extensions_admin_notice' ); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the path to a script or stylesheet. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a separate PR?