| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Plugin Report |
| 4 | 4 | * Plugin URI: https://roytanck.com/?p=277 |
| 5 | 5 | * Description: Provides detailed information about currently installed plugins |
| 6 | - * Version: 2.0.0 | |
| 6 | + * Version: 1.7 | |
| 7 | 7 | * Requires at least: 4.6 |
| 8 | 8 | * Requires PHP: 5.6 |
| 9 | 9 | * Author: Roy Tanck |
| 10 | 10 | * Author URI: https://roytanck.com |
| @@ -19,11 +19,8 @@ | ||
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | if ( is_admin() && ! class_exists( 'RT_Plugin_Report' ) ) { |
| 22 | 22 | |
| 23 | - /** | |
| 24 | - * Plugin Report main class. | |
| 25 | - */ | |
| 26 | 23 | class RT_Plugin_Report { |
| 27 | 24 | |
| 28 | 25 | // CSS class constants. |
| 29 | 26 | const CSS_CLASS_LOW = 'pr-risk-low'; |
| @@ -30,10 +27,10 @@ | ||
| 30 | 27 | const CSS_CLASS_MED = 'pr-risk-medium'; |
| 31 | 28 | const CSS_CLASS_HIGH = 'pr-risk-high'; |
| 32 | 29 | |
| 33 | 30 | // Other class constants. |
| 34 | - const PLUGIN_VERSION = '1.9.1'; | |
| 35 | - const COLS_PER_ROW = 9; | |
| 31 | + const PLUGIN_VERSION = '1.7'; | |
| 32 | + const COLS_PER_ROW = 7; | |
| 36 | 33 | const CACHE_LIFETIME = DAY_IN_SECONDS; |
| 37 | 34 | const CACHE_LIFETIME_NOREPO = WEEK_IN_SECONDS; |
| 38 | 35 | |
| 39 | 36 | /** |
| @@ -130,14 +127,12 @@ | ||
| 130 | 127 | // The report's main table. |
| 131 | 128 | echo '<table id="plugin-report-table" class="wp-list-table widefat fixed striped">'; |
| 132 | 129 | echo '<thead>'; |
| 133 | 130 | echo '<tr>'; |
| 134 | - echo '<th data-sort-default>' . esc_html__( 'Name', 'plugin-report' ) . '</th>'; | |
| 131 | + echo '<th>' . esc_html__( 'Name', 'plugin-report' ) . '</th>'; | |
| 135 | 132 | echo '<th>' . esc_html__( 'Author', 'plugin-report' ) . '</th>'; |
| 136 | - echo '<th>' . esc_html__( 'Repository', 'plugin-report' ) . '</th>'; | |
| 137 | 133 | echo '<th>' . esc_html__( 'Activated', 'plugin-report' ) . '</th>'; |
| 138 | 134 | echo '<th data-sort-method="none" class="no-sort">' . esc_html__( 'Installed version', 'plugin-report' ) . '</th>'; |
| 139 | - echo '<th>' . esc_html__( 'Auto-update', 'plugin-report' ) . '</th>'; | |
| 140 | 135 | echo '<th>' . esc_html__( 'Last update', 'plugin-report' ) . '</th>'; |
| 141 | 136 | echo '<th data-sort-method="dotsep">' . esc_html__( 'Tested up to WP version', 'plugin-report' ) . '</th>'; |
| 142 | 137 | echo '<th data-sort-method="number">' . esc_html__( 'Rating', 'plugin-report' ) . '</th>'; |
| 143 | 138 | echo '</tr>'; |
| @@ -169,10 +164,8 @@ | ||
| 169 | 164 | |
| 170 | 165 | |
| 171 | 166 | /** |
| 172 | 167 | * Enqueue admin javascript |
| 173 | - * | |
| 174 | - * @param string $hook Screen hook. | |
| 175 | 168 | */ |
| 176 | 169 | public function enqueue_assets( $hook ) { |
| 177 | 170 | // Check if we're on the right screen. |
| 178 | 171 | if ( 'plugins_page_plugin_report' !== $hook ) { |
| @@ -179,11 +172,11 @@ | ||
| 179 | 172 | return; |
| 180 | 173 | } |
| 181 | 174 | // Register the plugin's admin js, and require jquery. |
| 182 | 175 | wp_enqueue_script( 'plugin-report-js', plugins_url( '/js/plugin-report.js', __FILE__ ), array( 'jquery', 'plugin-report-tablesort-js' ), self::PLUGIN_VERSION ); |
| 183 | - wp_enqueue_script( 'plugin-report-tablesort-js', plugins_url( '/js/tablesort.min.js', __FILE__ ), array( 'jquery' ), '5.2.1' ); | |
| 184 | - wp_enqueue_script( 'plugin-report-tablesort-number-js', plugins_url( '/js/tablesort.number.min.js', __FILE__ ), array( 'plugin-report-tablesort-js' ), '5.2.1' ); | |
| 185 | - wp_enqueue_script( 'plugin-report-tablesort-dotsep-js', plugins_url( '/js/tablesort.dotsep.min.js', __FILE__ ), array( 'plugin-report-tablesort-js' ), '5.2.1' ); | |
| 176 | + wp_enqueue_script( 'plugin-report-tablesort-js', plugins_url( '/js/tablesort.min.js', __FILE__ ), array( 'jquery' ), '5.1.0' ); | |
| 177 | + wp_enqueue_script( 'plugin-report-tablesort-number-js', plugins_url( '/js/tablesort.number.min.js', __FILE__ ), array( 'plugin-report-tablesort-js' ), '5.1.0' ); | |
| 178 | + wp_enqueue_script( 'plugin-report-tablesort-dotsep-js', plugins_url( '/js/tablesort.dotsep.min.js', __FILE__ ), array( 'plugin-report-tablesort-js' ), '5.1.0' ); | |
| 186 | 179 | // Add some variables to the page, to be used by the javascript. |
| 187 | 180 | $slugs = $this->get_plugin_slugs(); |
| 188 | 181 | $slugs_str = implode( ',', $slugs ); |
| 189 | 182 | $vars = array( |
| @@ -212,11 +205,9 @@ | ||
| 212 | 205 | } |
| 213 | 206 | |
| 214 | 207 | |
| 215 | 208 | /** |
| 216 | - * Convert a plugin's file path into its slug. | |
| 217 | - * | |
| 218 | - * @param string $file Plugin file path. | |
| 209 | + * Convert a plugin's file path into its slug | |
| 219 | 210 | */ |
| 220 | 211 | private function get_plugin_slug( $file ) { |
| 221 | 212 | if ( strpos( $file, '/' ) !== false ) { |
| 222 | 213 | $parts = explode( '/', $file ); |
| @@ -271,19 +262,16 @@ | ||
| 271 | 262 | |
| 272 | 263 | |
| 273 | 264 | /** |
| 274 | 265 | * Gather all the info we can get about a plugin. |
| 275 | - * Uses transient caching to avoid doing repo API calls on every page visit. | |
| 276 | - * | |
| 277 | - * @param string $slug Plugin slug. | |
| 266 | + * Uses transient caching to avoid doing repo API calls on every page visit | |
| 278 | 267 | */ |
| 279 | 268 | private function assemble_plugin_report( $slug ) { |
| 280 | 269 | if ( ! empty( $slug ) ) { |
| 281 | - $report = array(); | |
| 282 | - $cache_key = $this->create_cache_key( $slug ); | |
| 283 | - $cache = get_site_transient( $cache_key ); | |
| 284 | - $plugins = get_plugins(); | |
| 285 | - $auto_updates = (array) get_site_option( 'auto_update_plugins', array() ); | |
| 270 | + $report = array(); | |
| 271 | + $cache_key = $this->create_cache_key( $slug ); | |
| 272 | + $cache = get_site_transient( $cache_key ); | |
| 273 | + $plugins = get_plugins(); | |
| 286 | 274 | |
| 287 | 275 | if ( empty( $cache ) ) { |
| 288 | 276 | |
| 289 | 277 | // Add the plugin's slug to the report. |
| @@ -288,39 +276,13 @@ | ||
| 288 | 276 | |
| 289 | 277 | // Add the plugin's slug to the report. |
| 290 | 278 | $report['slug'] = $slug; |
| 291 | 279 | |
| 292 | - // Get the locally available info, and add it to the report. | |
| 280 | + // Get the locally available info, and add it to the report. | |
| 293 | 281 | foreach ( $plugins as $key => $plugin ) { |
| 294 | - if ( $this->get_plugin_slug( $key ) === $slug ) { | |
| 295 | - | |
| 296 | - // Translate plugin data. | |
| 297 | - $textdomain = $plugin['TextDomain']; | |
| 298 | - if ( $textdomain ) { | |
| 299 | - if ( ! is_textdomain_loaded( $textdomain ) ) { | |
| 300 | - if ( $plugin['DomainPath'] ) { | |
| 301 | - load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin['DomainPath'] ); | |
| 302 | - } else { | |
| 303 | - load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); | |
| 304 | - } | |
| 305 | - } | |
| 306 | - } elseif ( 'hello.php' === basename( $plugin_file ) ) { | |
| 307 | - $textdomain = 'default'; | |
| 308 | - } | |
| 309 | - if ( $textdomain ) { | |
| 310 | - foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) { | |
| 311 | - // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain | |
| 312 | - $plugin[ $field ] = translate( $plugin[ $field ], $textdomain ); | |
| 313 | - } | |
| 314 | - } | |
| 315 | - | |
| 316 | - $report['local_info'] = $plugin; | |
| 317 | - $report['file_path'] = $key; | |
| 318 | - $report['auto-update'] = in_array( $key, $auto_updates ); | |
| 319 | - | |
| 320 | - // Change any whitespace to default space. | |
| 321 | - $report['local_info']['Name'] = preg_replace( '/\s+/u', ' ', $report['local_info']['Name'] ); | |
| 322 | - | |
| 282 | + if ( $this->get_plugin_slug( $key ) == $slug ) { | |
| 283 | + $report['local_info'] = $plugin; | |
| 284 | + $report['file_path'] = $key; | |
| 323 | 285 | break; |
| 324 | 286 | } |
| 325 | 287 | } |
| 326 | 288 | |
| @@ -338,16 +300,10 @@ | ||
| 338 | 300 | 'compatibility' => true, |
| 339 | 301 | 'author' => true, |
| 340 | 302 | ), |
| 341 | 303 | ); |
| 304 | + $returned_object = plugins_api( 'plugin_information', $args ); | |
| 342 | 305 | |
| 343 | - // Check wordpress.org only if "Update URI" plugin header is not set or set to wordpress.org. | |
| 344 | - $parsed_repo_url = wp_parse_url( $report['local_info']['UpdateURI'] ); | |
| 345 | - $repo_host = isset( $parsed_repo_url['host'] ) ? $parsed_repo_url['host'] : null; | |
| 346 | - if ( empty( $repo_host ) || strtolower( $repo_host ) === 'w.org' || strtolower( $repo_host ) === 'wordpress.org' ) { | |
| 347 | - $returned_object = plugins_api( 'plugin_information', $args ); | |
| 348 | - } | |
| 349 | - | |
| 350 | 306 | // Add the repo info to the report. |
| 351 | 307 | if ( ! is_wp_error( $returned_object ) ) { |
| 352 | 308 | $report['repo_info'] = maybe_unserialize( $returned_object ); |
| 353 | 309 | // Cache the report. |
| @@ -353,9 +309,9 @@ | ||
| 353 | 309 | // Cache the report. |
| 354 | 310 | set_site_transient( $cache_key, $report, self::CACHE_LIFETIME ); |
| 355 | 311 | } else { |
| 356 | 312 | // Store the error code and message in the report. |
| 357 | - $report['repo_error_code'] = $returned_object->get_error_code(); | |
| 313 | + $report['repo_error_code'] = $returned_object->get_error_code(); | |
| 358 | 314 | $report['repo_error_message'] = $returned_object->get_error_message(); |
| 359 | 315 | // Cache for an extra long time when the plugin is not in the repo. |
| 360 | 316 | set_site_transient( $cache_key, $report, self::CACHE_LIFETIME_NOREPO ); |
| 361 | 317 | } |
| @@ -372,24 +328,19 @@ | ||
| 372 | 328 | } |
| 373 | 329 | |
| 374 | 330 | |
| 375 | 331 | /** |
| 376 | - * From a report, generate an HTML table row with relevant data for the plugin. | |
| 377 | - * | |
| 378 | - * @param array $report Report of plugin. | |
| 332 | + * From a report, generate an HTML table row with relevant data for the plugin | |
| 379 | 333 | */ |
| 380 | 334 | private function render_table_row( $report ) { |
| 381 | - // Get the current WP version number. | |
| 382 | - global $wp_version; | |
| 383 | 335 | // Get the latest WP release version number. |
| 384 | 336 | $wp_latest = $this->check_core_updates(); |
| 385 | 337 | // Check if the report is valid. |
| 386 | - if ( null === $report ) { | |
| 338 | + if ( $report == null ) { | |
| 387 | 339 | $html = $this->render_error_row( esc_html__( 'No plugin data available.', 'plugin-report' ) ); |
| 388 | 340 | } else { |
| 389 | 341 | // Start the new table row. |
| 390 | 342 | $html = '<tr class="plugin-report-row-' . $report['slug'] . '">'; |
| 391 | - | |
| 392 | 343 | // Name. |
| 393 | 344 | if ( isset( $report['local_info']['PluginURI'] ) && ! empty( $report['local_info']['PluginURI'] ) ) { |
| 394 | 345 | $html .= '<td><a href="' . $report['local_info']['PluginURI'] . '"><strong>' . $report['local_info']['Name'] . '</strong></a></td>'; |
| 395 | 346 | } else { |
| @@ -394,9 +345,8 @@ | ||
| 394 | 345 | $html .= '<td><a href="' . $report['local_info']['PluginURI'] . '"><strong>' . $report['local_info']['Name'] . '</strong></a></td>'; |
| 395 | 346 | } else { |
| 396 | 347 | $html .= '<td><strong>' . $report['local_info']['Name'] . '</strong></td>'; |
| 397 | 348 | } |
| 398 | - | |
| 399 | 349 | // Author. |
| 400 | 350 | if ( isset( $report['local_info']['AuthorURI'] ) && ! empty( $report['local_info']['AuthorURI'] ) ) { |
| 401 | 351 | $html .= '<td><a href="' . $report['local_info']['AuthorURI'] . '">' . $report['local_info']['Author'] . '</a></td>'; |
| 402 | 352 | } else { |
| @@ -401,49 +351,19 @@ | ||
| 401 | 351 | $html .= '<td><a href="' . $report['local_info']['AuthorURI'] . '">' . $report['local_info']['Author'] . '</a></td>'; |
| 402 | 352 | } else { |
| 403 | 353 | $html .= '<td>' . $report['local_info']['Author'] . '</td>'; |
| 404 | 354 | } |
| 405 | - | |
| 406 | - // Repository. | |
| 407 | - if ( isset( $report['local_info']['UpdateURI'] ) ) { | |
| 408 | - // Parse the UpdateURI's value to get the host. | |
| 409 | - $parsed_repo_url = wp_parse_url( $report['local_info']['UpdateURI'] ); | |
| 410 | - // If the URI is valid, extract the host, otherwise we'll use the header value. | |
| 411 | - $repo_host = isset( $parsed_repo_url['host'] ) ? $parsed_repo_url['host'] : $report['local_info']['UpdateURI']; | |
| 412 | - // Check if the plugin is supposed to be hosted on wp.org. | |
| 413 | - if ( empty( $repo_host ) || strtolower( $repo_host ) === 'w.org' || strtolower( $repo_host ) === 'wordpress.org' ) { | |
| 414 | - // Plugin should be available on wp.org, check if we got a 'not found' error. | |
| 415 | - if ( isset( $report['repo_error_code'] ) && $report['repo_error_code'] === 'plugins_api_failed' ) { | |
| 416 | - // Plugin is not available in the wp.org repo. | |
| 417 | - $html .= '<td class="' . self::CSS_CLASS_HIGH . '">' . __( 'wordpress.org, plugin not found', 'plugin-report' ) . '</td>'; | |
| 418 | - } else { | |
| 419 | - // Plugin is available on wp.org. | |
| 420 | - $html .= '<td class="' . self::CSS_CLASS_LOW . '">wordpress.org</td>'; | |
| 421 | - } | |
| 422 | - } else { | |
| 423 | - if ( $parsed_repo_url && isset( $parsed_repo_url[ 'host' ] ) ) { | |
| 424 | - // Update URI is a valid URL, display the host. | |
| 425 | - $html .= '<td class="' . self::CSS_CLASS_MED . '">' . $repo_host . '</td>'; | |
| 426 | - } else { | |
| 427 | - // Some other value (like 'false'), so assume updates are disabled. | |
| 428 | - $html .= '<td class="' . self::CSS_CLASS_MED . '">' . __( 'Updates disabled', 'plugin-report' ) . '</td>'; | |
| 429 | - } | |
| 430 | - } | |
| 431 | - } else { | |
| 432 | - $html .= $this->render_error_cell(); | |
| 433 | - } | |
| 434 | - | |
| 435 | 355 | // Activated. |
| 436 | - $active = __( 'Please clear cache to update', 'plugin-report' ); | |
| 356 | + $active = __( 'Please clear cache to update', 'plugin-report' ); | |
| 437 | 357 | $css_class = self::CSS_CLASS_MED; |
| 438 | 358 | if ( is_multisite() ) { |
| 439 | 359 | $activation_status = $this->get_multisite_activation( $report['file_path'] ); |
| 440 | 360 | if ( true === $activation_status['network'] ) { |
| 441 | 361 | $css_class = self::CSS_CLASS_LOW; |
| 442 | - $html .= '<td class="' . $css_class . '">' . __( 'Network activated', 'plugin-report' ) . '</td>'; | |
| 362 | + $html .= '<td class="' . $css_class . '">' . __( 'Network activated', 'plugin-report' ) . '</td>'; | |
| 443 | 363 | } else { |
| 444 | 364 | $css_class = ( $activation_status['active'] > 0 ) ? self::CSS_CLASS_LOW : self::CSS_CLASS_HIGH; |
| 445 | - $html .= '<td class="' . $css_class . '">' . $activation_status['active'] . '/' . $activation_status['sites'] . '</td>'; | |
| 365 | + $html .= '<td class="' . $css_class . '">' . $activation_status['active'] . '/' . $activation_status['sites'] . '</td>'; | |
| 446 | 366 | } |
| 447 | 367 | } else { |
| 448 | 368 | if ( isset( $report['file_path'] ) ) { |
| 449 | 369 | $active = is_plugin_active( $report['file_path'] ) ? __( 'Yes', 'plugin-report' ) : __( 'No', 'plugin-report' ); |
| @@ -450,31 +370,31 @@ | ||
| 450 | 370 | $css_class = is_plugin_active( $report['file_path'] ) ? self::CSS_CLASS_LOW : self::CSS_CLASS_HIGH; |
| 451 | 371 | } |
| 452 | 372 | $html .= '<td class="' . $css_class . '">' . $active . '</td>'; |
| 453 | 373 | } |
| 454 | - | |
| 455 | 374 | // Installed / available version. |
| 456 | 375 | if ( isset( $report['repo_info'] ) ) { |
| 457 | 376 | $css_class = $this->get_version_risk_classname( $report['local_info']['Version'], $report['repo_info']->version ); |
| 458 | - $html .= '<td class="' . $css_class . '">'; | |
| 459 | - $html .= $report['local_info']['Version']; | |
| 460 | - if ( $report['local_info']['Version'] !== $report['repo_info']->version ) { | |
| 377 | + $html .= '<td class="' . $css_class . '">'; | |
| 378 | + $html .= $report['local_info']['Version']; | |
| 379 | + if ( $report['local_info']['Version'] != $report['repo_info']->version ) { | |
| 461 | 380 | // Any platform upgrades needed? |
| 381 | + global $wp_version; | |
| 462 | 382 | $needs_php_upgrade = isset( $report['repo_info']->requires_php ) ? version_compare( phpversion(), $report['repo_info']->requires_php, '<' ) : false; |
| 463 | 383 | $needs_wp_upgrade = isset( $report['repo_info']->requires ) ? version_compare( $wp_version, $report['repo_info']->requires, '<' ) : false; |
| 464 | 384 | // Create the additional message. |
| 465 | 385 | if ( $needs_wp_upgrade && $needs_php_upgrade ) { |
| 466 | 386 | /* translators: %1$s: Plugin version number, %2$s: WP version number, %3$s: PHP version number */ |
| 467 | - $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%1$s available, requires WP %2$s and PHP %3$s)', 'plugin-report' ), $report['repo_info']->version, $report['repo_info']->requires, $report['repo_info']->requires_php ) . '</span>'; | |
| 387 | + $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%1$s available, requires WP %2$s and PHP %3$s)', 'plugin-report'), $report['repo_info']->version, $report['repo_info']->requires, $report['repo_info']->requires_php ) . '</span>'; | |
| 468 | 388 | } elseif ( $needs_wp_upgrade ) { |
| 469 | 389 | /* translators: %1$s: Plugin version number, %2$s: WP version number. */ |
| 470 | - $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%1$s available, requires WP %2$s)', 'plugin-report' ), $report['repo_info']->version, $report['repo_info']->requires ) . '</span>'; | |
| 390 | + $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%1$s available, requires WP %2$s)', 'plugin-report'), $report['repo_info']->version, $report['repo_info']->requires ) . '</span>'; | |
| 471 | 391 | } elseif ( $needs_php_upgrade ) { |
| 472 | 392 | /* translators: %1$s: Plugin version number, %2$s: PHP version number. */ |
| 473 | - $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%1$s available, requires PHP %2$s)', 'plugin-report' ), $report['repo_info']->version, $report['repo_info']->requires_php ) . '</span>'; | |
| 393 | + $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%1$s available, requires PHP %2$s)', 'plugin-report'), $report['repo_info']->version, $report['repo_info']->requires_php ) . '</span>'; | |
| 474 | 394 | } else { |
| 475 | 395 | /* translators: %s: Plugin version number. */ |
| 476 | - $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%s available)', 'plugin-report' ), $report['repo_info']->version ) . '</span>'; | |
| 396 | + $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%s available)', 'plugin-report'), $report['repo_info']->version ) . '</span>'; | |
| 477 | 397 | } |
| 478 | 398 | } |
| 479 | 399 | $html .= '</td>'; |
| 480 | 400 | } else { |
| @@ -479,20 +399,8 @@ | ||
| 479 | 399 | $html .= '</td>'; |
| 480 | 400 | } else { |
| 481 | 401 | $html .= '<td>' . $report['local_info']['Version'] . '</td>'; |
| 482 | 402 | } |
| 483 | - | |
| 484 | - // Auto-update. | |
| 485 | - if ( version_compare( $wp_version, '5.5', '<' ) ) { | |
| 486 | - $html .= '<td>' . __( 'Requires WordPress 5.5 or higher', 'plugin-report' ) . '</td>'; | |
| 487 | - } else { | |
| 488 | - if ( isset( $report['auto-update'] ) && $report['auto-update'] ) { | |
| 489 | - $html .= '<td class="' . self::CSS_CLASS_LOW . '">' . __( 'Enabled', 'plugin-report' ) . '</td>'; | |
| 490 | - } else { | |
| 491 | - $html .= '<td>' . __( 'Not enabled', 'plugin-report' ) . '</td>'; | |
| 492 | - } | |
| 493 | - } | |
| 494 | - | |
| 495 | 403 | // Last updates. |
| 496 | 404 | if ( isset( $report['repo_info'] ) ) { |
| 497 | 405 | $time_update = new DateTime( $report['repo_info']->last_updated ); |
| 498 | 406 | $time_diff = human_time_diff( $time_update->getTimestamp(), current_time( 'timestamp' ) ); |
| @@ -500,17 +408,15 @@ | ||
| 500 | 408 | $html .= '<td class="' . $css_class . '" data-sort="' . $time_update->getTimestamp() . '">' . $time_diff . '</td>'; |
| 501 | 409 | } else { |
| 502 | 410 | $html .= $this->render_error_cell(); |
| 503 | 411 | } |
| 504 | - | |
| 505 | 412 | // Tested up to. |
| 506 | 413 | if ( isset( $report['repo_info'] ) ) { |
| 507 | - $css_class = $this->get_version_risk_classname( $report['repo_info']->tested, $wp_latest, true ); | |
| 508 | - $html .= '<td class="' . $css_class . '">' . $report['repo_info']->tested . '</td>'; | |
| 414 | + $css_class = $this->get_version_risk_classname( $report['repo_info']->tested, $wp_latest ); | |
| 415 | + $html .= '<td class="' . $css_class . '">' . $report['repo_info']->tested . '</td>'; | |
| 509 | 416 | } else { |
| 510 | 417 | $html .= $this->render_error_cell(); |
| 511 | 418 | } |
| 512 | - | |
| 513 | 419 | // Overall user rating. |
| 514 | 420 | if ( isset( $report['repo_info'] ) ) { |
| 515 | 421 | $css_class = ( intval( $report['repo_info']->num_ratings ) > 0 ) ? $this->get_percentage_risk_classname( intval( $report['repo_info']->rating ) ) : ''; |
| 516 | 422 | $value_text = ( ( intval( $report['repo_info']->num_ratings ) > 0 ) ? $report['repo_info']->rating . '%' : esc_html__( 'No data available', 'plugin-report' ) ); |
| @@ -517,9 +423,8 @@ | ||
| 517 | 423 | $html .= '<td class="' . $css_class . '">' . $value_text . '</td>'; |
| 518 | 424 | } else { |
| 519 | 425 | $html .= $this->render_error_cell(); |
| 520 | 426 | } |
| 521 | - | |
| 522 | 427 | // Close the new table row. |
| 523 | 428 | $html .= '</tr>'; |
| 524 | 429 | } |
| 525 | 430 | return $html; |
| @@ -526,11 +431,9 @@ | ||
| 526 | 431 | } |
| 527 | 432 | |
| 528 | 433 | |
| 529 | 434 | /** |
| 530 | - * Format an error message as a table row, so we can return it to javascript. | |
| 531 | - * | |
| 532 | - * @param string $message Message to be shown. | |
| 435 | + * Format an error message as a table row, so we can return it to javascript | |
| 533 | 436 | */ |
| 534 | 437 | private function render_error_row( $message ) { |
| 535 | 438 | return '<tr class="pluginreport-row-error"><td colspan="' . self::COLS_PER_ROW . '">' . $message . '</td></tr>'; |
| 536 | 439 | } |
| @@ -536,11 +439,9 @@ | ||
| 536 | 439 | } |
| 537 | 440 | |
| 538 | 441 | |
| 539 | 442 | /** |
| 540 | - * Format an error message as a table cell, so we can return it to javascript. | |
| 541 | - * | |
| 542 | - * @param string $message Message to be shown. | |
| 443 | + * Format an error message as a table cell, so we can return it to javascript | |
| 543 | 444 | */ |
| 544 | 445 | private function render_error_cell( $message = null ) { |
| 545 | 446 | if ( ! $message ) { |
| 546 | 447 | $message = esc_html__( 'No data available', 'plugin-report' ); |
| @@ -549,33 +450,11 @@ | ||
| 549 | 450 | } |
| 550 | 451 | |
| 551 | 452 | |
| 552 | 453 | /** |
| 553 | - * Return the version string with all elements beyond the second removed ("5.5.1" -> "5.5"). | |
| 554 | - * | |
| 555 | - * @param string $version_string Complete version number. | |
| 454 | + * Figure out what CSS class to use based on current and optimal version numbers | |
| 556 | 455 | */ |
| 557 | - private function get_major_version( $version_string ) { | |
| 558 | - $parts = explode( '.', $version_string ); | |
| 559 | - array_splice( $parts, 2 ); | |
| 560 | - return implode( '.', $parts ); | |
| 561 | - } | |
| 562 | - | |
| 563 | - | |
| 564 | - /** | |
| 565 | - * Figure out what CSS class to use based on current and optimal version numbers. | |
| 566 | - * | |
| 567 | - * @param string $available Available version. | |
| 568 | - * @param string $optimal Optimal version. | |
| 569 | - * @param bool $major_only True to compare only major versions, false otherwise. | |
| 570 | - */ | |
| 571 | - private function get_version_risk_classname( $available, $optimal, $major_only = false ) { | |
| 572 | - // Use only the first two elements of the version number if $major_only is set to true. | |
| 573 | - // This is used for WP version numbers, where point releases are not considered a risk. | |
| 574 | - if ( $major_only ) { | |
| 575 | - $available = $this->get_major_version( $available ); | |
| 576 | - $optimal = $this->get_major_version( $optimal ); | |
| 577 | - } | |
| 456 | + private function get_version_risk_classname( $available, $optimal ) { | |
| 578 | 457 | // If the version is equal or higher, indicate low risk. |
| 579 | 458 | if ( version_compare( $available, $optimal, '>=' ) ) { |
| 580 | 459 | return self::CSS_CLASS_LOW; |
| 581 | 460 | } |
| @@ -584,11 +463,9 @@ | ||
| 584 | 463 | } |
| 585 | 464 | |
| 586 | 465 | |
| 587 | 466 | /** |
| 588 | - * Assess the risk associated with low ratings or poor compatibility feedback, return corresponding CSS class. | |
| 589 | - * | |
| 590 | - * @param int $perc Rating percentage. | |
| 467 | + * Assess the risk associated with low ratings or poor compatibility feedback, return corresponding CSS class | |
| 591 | 468 | */ |
| 592 | 469 | private function get_percentage_risk_classname( $perc ) { |
| 593 | 470 | if ( $perc < 70 ) { |
| 594 | 471 | return self::CSS_CLASS_HIGH; |
| @@ -600,11 +477,9 @@ | ||
| 600 | 477 | } |
| 601 | 478 | |
| 602 | 479 | |
| 603 | 480 | /** |
| 604 | - * Assess the risk associated with low ratings or poor compatibility feedback, return corresponding CSS class. | |
| 605 | - * | |
| 606 | - * @param string $time_diff Time difference. | |
| 481 | + * Assess the risk associated with low ratings or poor compatibility feedback, return corresponding CSS class | |
| 607 | 482 | */ |
| 608 | 483 | private function get_timediff_risk_classname( $time_diff ) { |
| 609 | 484 | $days = $time_diff / ( DAY_IN_SECONDS ); |
| 610 | 485 | if ( $days > 365 ) { |
| @@ -624,13 +499,13 @@ | ||
| 624 | 499 | private function check_core_updates() { |
| 625 | 500 | global $wp_version; |
| 626 | 501 | $update = get_preferred_from_update_core(); |
| 627 | 502 | // Bail out of no valid response, or false. |
| 628 | - if ( ! $update || false === $update ) { | |
| 503 | + if ( ! $update || $update == false ) { | |
| 629 | 504 | return $wp_version; |
| 630 | 505 | } |
| 631 | 506 | // If latest, return current version number. |
| 632 | - if ( 'latest' === $update->response ) { | |
| 507 | + if ( $update->response == 'latest' ) { | |
| 633 | 508 | return $wp_version; |
| 634 | 509 | } |
| 635 | 510 | // Return the preferred update's version number. |
| 636 | 511 | return $update->version; |
| @@ -637,11 +512,9 @@ | ||
| 637 | 512 | } |
| 638 | 513 | |
| 639 | 514 | |
| 640 | 515 | /** |
| 641 | - * Gather statistics about a plugin's activation on a multisite install. | |
| 642 | - * | |
| 643 | - * @param string $path Plugin path. | |
| 516 | + * Gather statistics about a plugin's activation on a multisite install | |
| 644 | 517 | */ |
| 645 | 518 | private function get_multisite_activation( $path ) { |
| 646 | 519 | // Create an array to contain the return values. |
| 647 | 520 | $activation_status = array( |
| @@ -654,9 +527,9 @@ | ||
| 654 | 527 | if ( array_key_exists( $path, $network_plugins ) ) { |
| 655 | 528 | $activation_status['network'] = true; |
| 656 | 529 | } else { |
| 657 | 530 | // Get a list of all sites in the multisite install. |
| 658 | - $args = array( | |
| 531 | + $args = array( | |
| 659 | 532 | 'number' => 9999, |
| 660 | 533 | 'fields' => 'ids', |
| 661 | 534 | ); |
| 662 | 535 | $sites = get_sites( $args ); |
| @@ -680,10 +553,8 @@ | ||
| 680 | 553 | |
| 681 | 554 | |
| 682 | 555 | /** |
| 683 | 556 | * Create a cache key that is unique to the provided plugin slug. |
| 684 | - * | |
| 685 | - * @param string $slug Plugin slug. | |
| 686 | 557 | */ |
| 687 | 558 | private function create_cache_key( $slug ) { |
| 688 | 559 | // Create a hash for the plugin slug. |
| 689 | 560 | $slug_hash = hash( 'sha256', $slug ); |
| @@ -708,11 +579,9 @@ | ||
| 708 | 579 | } |
| 709 | 580 | |
| 710 | 581 | |
| 711 | 582 | /** |
| 712 | - * Remove the cache item for a single plugin. | |
| 713 | - * | |
| 714 | - * @param string $slug Plugin slug. | |
| 583 | + * Remove the cache item for a single plugin | |
| 715 | 584 | */ |
| 716 | 585 | private function clear_cache_item( $slug ) { |
| 717 | 586 | if ( isset( $slug ) ) { |
| 718 | 587 | $cache_key = $this->create_cache_key( $slug ); |