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

Add a special banner for obsolete plugins #417

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,27 @@ public static function is_plugin_outdated( $post = null ) {
return version_compare( $version_to_check_against, $tested_up_to, '>' );
}

/**
* Checks if the plugin is many years out of date.
*
* @static
*
* @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
* @return bool True if the plugin is obsolete, false otherwise.
*/
public static function is_plugin_obsolete( $post = null ) {
$post = get_post( $post );
$tested_up_to = (string) $post->tested;
$version_to_check_against = (string) ( self::get_current_major_wp_version() - 3.5 ); // 35 major releases behind is at least 10 years.

$last_updated = new \DateTime( $post->last_updated ?: $post->post_modified_gmt );
$date_threshold = new \DateTime( '10 years ago' );

// A plugin is obsolete if it hasn't been updated in a long time AND hasn't been tested against a modern version.
return version_compare( $version_to_check_against, $tested_up_to, '>' )
&& $last_updated < $date_threshold;
}

/**
* Returns a string representing the number of active installations for an item.
*
Expand Down Expand Up @@ -721,6 +742,26 @@ public static function download_link( $post = null, $version = 'latest' ) {
}
}

/**
* Determine whether or not we should show a primary Download button for a given plugin.
* Generally yes, but there are exceptions for closed and very old buttons.
*
* @param int|\WP_Post|null $post Optional. Post ID or object. Defaults to global $post.
* @return bool True if the button should be shown; false otherwise.
*/
public static function is_download_available( $post = null ) {
$post = get_post( $post );

if ( 'publish' === get_post_status() || current_user_can( 'plugin_admin_view', $post ) ) {
// We usually want to have a download button for published plugins; but not if it's ancient.
if ( ! self::is_plugin_obsolete( $post ) ) {
return true;
}
}

return false;
}

/**
* Is a live preview available for the plugin, and allowed for the current user to view?
*
Expand Down Expand Up @@ -1117,7 +1158,7 @@ public static function get_close_data( $post = null ) {
$result['public'] = true;
}

return $result;
return $result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ function get_plugin_status_notice( $post = null ) {

switch ( $post_status ) {
case 'publish':
if ( Template::is_plugin_outdated( $post ) ) {
if ( Template::is_plugin_obsolete( $post ) ) {
$message = sprintf(
$warning_notice,
__( '<strong>This plugin is obsolete.</strong> It has not been maintained in many years, and should not be used on a new site. It is available here for archival and historical reasons.', 'wporg-plugins' )
);
} elseif ( Template::is_plugin_outdated( $post ) ) {
$message = sprintf(
$warning_notice,
__( 'This plugin <strong>hasn&#146;t been tested with the latest 3 major releases of WordPress</strong>. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.', 'wporg-plugins' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<?php
$buttons = '<!-- wp:wporg/favorite-button /-->';

if ( 'publish' === get_post_status() || current_user_can( 'plugin_admin_view', $post ) ) {
if ( Template::is_download_available() ) {
$buttons .= sprintf(
'<!-- wp:button {"className":"is-small plugin-download download-button"} -->
<div class="wp-block-button is-small plugin-download download-button"><a class="wp-block-button__link wp-element-button" href="%1$s">%2$s</a></div>
Expand Down