From eb6af685f7850d9c9914e2a215338f7d4edf3224 Mon Sep 17 00:00:00 2001 From: benazeer1909 Date: Sat, 23 Nov 2024 00:40:50 +0530 Subject: [PATCH 1/3] Added last updated details of plugins --- src/wp-admin/css/list-tables.css | 4 ++ .../includes/class-wp-plugins-list-table.php | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/wp-admin/css/list-tables.css b/src/wp-admin/css/list-tables.css index da4bb599be97e..b7063ebcfda64 100644 --- a/src/wp-admin/css/list-tables.css +++ b/src/wp-admin/css/list-tables.css @@ -1338,6 +1338,10 @@ ul.cat-checklist input[name="post_category[]"]:indeterminate::before { width: 14.2em; } +.plugins .column-last-updated { + width: 14.2em; +} + .plugins .inactive .plugin-title strong { font-weight: 400; } diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index e96445b7710a7..ff1f769fb90b6 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -478,8 +478,37 @@ public function get_columns() { $columns['auto-updates'] = __( 'Automatic Updates' ); } + $columns['last-updated'] = __( 'Last Updated' ); + return $columns; } + protected function column_last_updated( $plugin_file ) { + + $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_file ); + + $plugin_uri = isset( $plugin_data['PluginURI'] ) ? $plugin_data['PluginURI'] : ''; + + $plugin_slug = basename( parse_url( $plugin_uri, PHP_URL_PATH ) ); + + $http_args = array( + 'timeout' => 10, + 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ), + ); + + // Fetch plugin info from WordPress API + $response = wp_remote_get( "https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=$plugin_slug", $http_args ); + + if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) === 200 ) { + $plugin_info = json_decode( wp_remote_retrieve_body( $response ), true ); + + if ( isset( $plugin_info['last_updated'] ) ) { + return esc_html( date( 'M j, Y', strtotime( $plugin_info['last_updated'] ) ) ); + } + } + + return __( 'Unknown', 'default' ); + } + /** * @return array @@ -1384,6 +1413,25 @@ public function single_row( $item ) { echo ''; + break; + case 'last-updated': + + echo ""; + + $html = array(); + + $last_updated = $this->column_last_updated( $plugin_file ); + + if ( ! empty( $last_updated ) ) { + $html[] = '' . $last_updated . ''; + } + + $html = implode( '', $html ); + + echo apply_filters( 'plugin_last_updated_setting_html', $html, $plugin_file, $plugin_data ); + + echo ''; + break; default: $classes = "$column_name column-$column_name $class"; @@ -1470,6 +1518,7 @@ public function single_row( $item ) { ); echo ''; + } /** From f974ccac5f9f64741d53c15a34ba5ce603b4e39a Mon Sep 17 00:00:00 2001 From: benazeer1909 Date: Sat, 23 Nov 2024 01:00:37 +0530 Subject: [PATCH 2/3] PHPCS fix --- .../includes/class-wp-plugins-list-table.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index ff1f769fb90b6..3426b1fa16dfa 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -478,23 +478,23 @@ public function get_columns() { $columns['auto-updates'] = __( 'Automatic Updates' ); } - $columns['last-updated'] = __( 'Last Updated' ); + $columns['last-updated'] = __( 'Last Updated' ); return $columns; } protected function column_last_updated( $plugin_file ) { - + $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_file ); - + $plugin_uri = isset( $plugin_data['PluginURI'] ) ? $plugin_data['PluginURI'] : ''; - + $plugin_slug = basename( parse_url( $plugin_uri, PHP_URL_PATH ) ); - + $http_args = array( 'timeout' => 10, 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ), ); - + // Fetch plugin info from WordPress API $response = wp_remote_get( "https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=$plugin_slug", $http_args ); @@ -1414,10 +1414,9 @@ public function single_row( $item ) { echo ''; break; - case 'last-updated': - + case 'last-updated': echo ""; - + $html = array(); $last_updated = $this->column_last_updated( $plugin_file ); @@ -1429,7 +1428,7 @@ public function single_row( $item ) { $html = implode( '', $html ); echo apply_filters( 'plugin_last_updated_setting_html', $html, $plugin_file, $plugin_data ); - + echo ''; break; @@ -1518,7 +1517,7 @@ public function single_row( $item ) { ); echo ''; - + } /** From 76b907b8cf87986b7b503e3bdd3485927c7f3791 Mon Sep 17 00:00:00 2001 From: benazeer1909 Date: Sat, 23 Nov 2024 01:05:18 +0530 Subject: [PATCH 3/3] PHPCS fix for gmdate --- src/wp-admin/includes/class-wp-plugins-list-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index 3426b1fa16dfa..98fbb1653781f 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -502,7 +502,7 @@ protected function column_last_updated( $plugin_file ) { $plugin_info = json_decode( wp_remote_retrieve_body( $response ), true ); if ( isset( $plugin_info['last_updated'] ) ) { - return esc_html( date( 'M j, Y', strtotime( $plugin_info['last_updated'] ) ) ); + return esc_html( gmdate( 'M j, Y', strtotime( $plugin_info['last_updated'] ) ) ); } }