| @@ -2,14 +2,15 @@ | ||
| 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: 1.5 | |
| 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 |
| 11 | 11 | * License: GPLv3 |
| 12 | + * Network: true | |
| 12 | 13 | */ |
| 13 | 14 | |
| 14 | 15 | // If called without WordPress, exit. |
| 15 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -21,13 +22,14 @@ | ||
| 21 | 22 | |
| 22 | 23 | class RT_Plugin_Report { |
| 23 | 24 | |
| 24 | 25 | // CSS class constants. |
| 25 | - const CSS_CLASS_LOW = 'rt-risk-low'; | |
| 26 | - const CSS_CLASS_MED = 'rt-risk-medium'; | |
| 27 | - const CSS_CLASS_HIGH = 'rt-risk-high'; | |
| 26 | + const CSS_CLASS_LOW = 'pr-risk-low'; | |
| 27 | + const CSS_CLASS_MED = 'pr-risk-medium'; | |
| 28 | + const CSS_CLASS_HIGH = 'pr-risk-high'; | |
| 28 | 29 | |
| 29 | - // Othe class constants | |
| 30 | + // Other class constants. | |
| 31 | + const PLUGIN_VERSION = '1.7'; | |
| 30 | 32 | const COLS_PER_ROW = 7; |
| 31 | 33 | const CACHE_LIFETIME = DAY_IN_SECONDS; |
| 32 | 34 | const CACHE_LIFETIME_NOREPO = WEEK_IN_SECONDS; |
| 33 | 35 | |
| @@ -49,13 +51,13 @@ | ||
| 49 | 51 | } else { |
| 50 | 52 | add_action( 'admin_menu', array( $this, 'register_settings_page' ) ); |
| 51 | 53 | } |
| 52 | 54 | // Hook for the admin js. |
| 53 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_js' ) ); | |
| 55 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); | |
| 54 | 56 | // Add the AJAX hook. |
| 55 | 57 | add_action( 'wp_ajax_rt_get_plugin_info', array( $this, 'get_plugin_info' ) ); |
| 56 | 58 | // Hook into the WP Upgrader to selectively delete cache items. |
| 57 | - add_action( 'upgrader_process_complete', array( $this, 'upgrade_delete_cache_items' ), 10 ,2 ); | |
| 59 | + add_action( 'upgrader_process_complete', array( $this, 'upgrade_delete_cache_items' ), 10, 2 ); | |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | |
| 61 | 63 | /** |
| @@ -65,9 +67,9 @@ | ||
| 65 | 67 | add_plugins_page( |
| 66 | 68 | esc_html_x( 'Plugin Report', 'Page and menu title', 'plugin-report' ), |
| 67 | 69 | esc_html_x( 'Plugin Report', 'Page and menu title', 'plugin-report' ), |
| 68 | 70 | 'manage_options', |
| 69 | - 'rt_plugin_report', | |
| 71 | + 'plugin_report', | |
| 70 | 72 | array( $this, 'settings_page' ) |
| 71 | 73 | ); |
| 72 | 74 | } |
| 73 | 75 | |
| @@ -89,12 +91,12 @@ | ||
| 89 | 91 | |
| 90 | 92 | // Refresh the cache, but only if this is a fresh timestamp (not if the page has been refreshed with the timestamp still in the URL). |
| 91 | 93 | if ( isset( $_GET['clear_cache'] ) ) { |
| 92 | 94 | $new_timestamp = intval( $_GET['clear_cache'] ); |
| 93 | - $last_timestamp = intval( get_site_transient( 'rt_plugin_report_cache_cleared' ) ); | |
| 95 | + $last_timestamp = intval( get_site_transient( 'plugin_report_cache_cleared' ) ); | |
| 94 | 96 | if ( ! $last_timestamp || $new_timestamp > $last_timestamp ) { |
| 95 | 97 | $this->clear_cache(); |
| 96 | - set_site_transient( 'rt_plugin_report_cache_cleared', $new_timestamp, self::CACHE_LIFETIME ); | |
| 98 | + set_site_transient( 'plugin_report_cache_cleared', $new_timestamp, self::CACHE_LIFETIME ); | |
| 97 | 99 | } |
| 98 | 100 | } |
| 99 | 101 | |
| 100 | 102 | // Start the page's output. |
| @@ -101,10 +103,10 @@ | ||
| 101 | 103 | echo '<div class="wrap">'; |
| 102 | 104 | echo '<h1>' . esc_html_x( 'Plugin Report', 'Page and menu title', 'plugin-report' ) . '</h1>'; |
| 103 | 105 | echo '<p>'; |
| 104 | 106 | $version_temp = '<span class="' . $this->get_version_risk_classname( $wp_version, $wp_latest ) . '">' . $wp_version . '</span>'; |
| 105 | - /* translators: %s = Current WordPress version number */ | |
| 106 | - echo sprintf( __( 'Currently running WordPress version: %s.', 'plugin-report' ), $version_temp ); | |
| 107 | + /* translators: %1$s: Current WordPress version number, %2$s: Current PHP version number */ | |
| 108 | + echo sprintf( __( 'Currently running WordPress version %1$s and PHP version %2$s.', 'plugin-report' ), $version_temp, phpversion() ); | |
| 107 | 109 | if ( version_compare( $wp_version, $wp_latest, '<' ) ) { |
| 108 | 110 | /* translators: %s = Available new version number */ |
| 109 | 111 | echo sprintf( ' (' . esc_html__( 'An upgrade to %s is available', 'plugin-report' ) . ')', $wp_latest ); |
| 110 | 112 | } |
| @@ -111,29 +113,29 @@ | ||
| 111 | 113 | echo '</p>'; |
| 112 | 114 | echo '<p>'; |
| 113 | 115 | // Clear cache and reload. |
| 114 | 116 | if ( is_multisite() ) { |
| 115 | - $page_url = 'network/plugins.php?page=rt_plugin_report'; | |
| 117 | + $page_url = 'network/plugins.php?page=plugin_report'; | |
| 116 | 118 | } else { |
| 117 | - $page_url = 'plugins.php?page=rt_plugin_report'; | |
| 119 | + $page_url = 'plugins.php?page=plugin_report'; | |
| 118 | 120 | } |
| 119 | 121 | echo '<a href="' . admin_url( $page_url . '&clear_cache=' . current_time( 'timestamp' ) ) . '">' . esc_html__( 'Clear cached plugin data and reload', 'plugin-report' ) . '</a>'; |
| 120 | 122 | echo '</p>'; |
| 121 | 123 | echo '<h3>' . esc_html__( 'Currently installed plugins', 'plugin-report' ) . '</h3>'; |
| 122 | - echo '<p id="rt-plugin-report-progress"></p>'; | |
| 124 | + echo '<p id="plugin-report-progress"></p>'; | |
| 123 | 125 | echo '<p>'; |
| 124 | 126 | |
| 125 | 127 | // The report's main table. |
| 126 | - echo '<table id="rt-plugin-report-table" class="wp-list-table widefat fixed striped">'; | |
| 128 | + echo '<table id="plugin-report-table" class="wp-list-table widefat fixed striped">'; | |
| 127 | 129 | echo '<thead>'; |
| 128 | 130 | echo '<tr>'; |
| 129 | 131 | echo '<th>' . esc_html__( 'Name', 'plugin-report' ) . '</th>'; |
| 130 | 132 | echo '<th>' . esc_html__( 'Author', 'plugin-report' ) . '</th>'; |
| 131 | 133 | echo '<th>' . esc_html__( 'Activated', 'plugin-report' ) . '</th>'; |
| 132 | - echo '<th>' . esc_html__( 'Installed version', 'plugin-report' ) . '</th>'; | |
| 134 | + echo '<th data-sort-method="none" class="no-sort">' . esc_html__( 'Installed version', 'plugin-report' ) . '</th>'; | |
| 133 | 135 | echo '<th>' . esc_html__( 'Last update', 'plugin-report' ) . '</th>'; |
| 134 | - echo '<th>' . esc_html__( 'Tested up to WP version', 'plugin-report' ) . '</th>'; | |
| 135 | - echo '<th>' . esc_html__( 'Rating', 'plugin-report' ) . '</th>'; | |
| 136 | + echo '<th data-sort-method="dotsep">' . esc_html__( 'Tested up to WP version', 'plugin-report' ) . '</th>'; | |
| 137 | + echo '<th data-sort-method="number">' . esc_html__( 'Rating', 'plugin-report' ) . '</th>'; | |
| 136 | 138 | echo '</tr>'; |
| 137 | 139 | echo '</thead>'; |
| 138 | 140 | echo '<tbody>'; |
| 139 | 141 | |
| @@ -145,9 +147,9 @@ | ||
| 145 | 147 | // Use the cached report to create a table row. |
| 146 | 148 | echo $this->render_table_row( $cache ); |
| 147 | 149 | } else { |
| 148 | 150 | // Render a special table row that's used as a signal to the front-end js that new data is needed. |
| 149 | - echo '<tr class="rt-plugin-report-row-temp-' . $slug . '"><td colspan="' . self::COLS_PER_ROW . '">' . esc_html__( 'Loading...', 'plugin-report' ) . '</td></tr>'; | |
| 151 | + echo '<tr class="plugin-report-row-temp-' . $slug . '"><td colspan="' . self::COLS_PER_ROW . '">' . esc_html__( 'Loading...', 'plugin-report' ) . '</td></tr>'; | |
| 150 | 152 | } |
| 151 | 153 | } |
| 152 | 154 | |
| 153 | 155 | echo '</tbody>'; |
| @@ -153,9 +155,9 @@ | ||
| 153 | 155 | echo '</tbody>'; |
| 154 | 156 | echo '</table>'; |
| 155 | 157 | echo '</p>'; |
| 156 | 158 | |
| 157 | - echo '<p id="rt-plugin-report-buttons"></p>'; | |
| 159 | + echo '<p id="plugin-report-buttons"></p>'; | |
| 158 | 160 | |
| 159 | 161 | // Wrap up. |
| 160 | 162 | echo '</div>'; |
| 161 | 163 | } |
| @@ -163,26 +165,31 @@ | ||
| 163 | 165 | |
| 164 | 166 | /** |
| 165 | 167 | * Enqueue admin javascript |
| 166 | 168 | */ |
| 167 | - public function enqueue_js( $hook ) { | |
| 169 | + public function enqueue_assets( $hook ) { | |
| 168 | 170 | // Check if we're on the right screen. |
| 169 | - if ( 'plugins_page_rt_plugin_report' != $hook ) { | |
| 171 | + if ( 'plugins_page_plugin_report' !== $hook ) { | |
| 170 | 172 | return; |
| 171 | 173 | } |
| 172 | - // register the plugin's admin js, and require jquery | |
| 173 | - wp_enqueue_script( 'rt-plugin-report-js', plugins_url( '/js/rt-plugin-report.js', __FILE__ ), array( 'jquery' ) ); | |
| 174 | - // add some variables to the page, to be used by the javascript | |
| 174 | + // Register the plugin's admin js, and require jquery. | |
| 175 | + wp_enqueue_script( 'plugin-report-js', plugins_url( '/js/plugin-report.js', __FILE__ ), array( 'jquery', 'plugin-report-tablesort-js' ), self::PLUGIN_VERSION ); | |
| 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' ); | |
| 179 | + // Add some variables to the page, to be used by the javascript. | |
| 175 | 180 | $slugs = $this->get_plugin_slugs(); |
| 176 | 181 | $slugs_str = implode( ',', $slugs ); |
| 177 | 182 | $vars = array( |
| 178 | - 'plugin_slugs' => $slugs_str, | |
| 179 | - 'ajax_nonce' => wp_create_nonce( 'rt_plugin_report_nonce' ), | |
| 180 | - 'export_btn' => __( 'Export .xls file', 'plugin-report' ), | |
| 183 | + 'plugin_slugs' => $slugs_str, | |
| 184 | + 'ajax_nonce' => wp_create_nonce( 'plugin_report_nonce' ), | |
| 185 | + 'export_btn' => __( 'Export .csv file', 'plugin-report' ), | |
| 186 | + 'plugin_url_header' => __( 'Plugin URL', 'plugin-report' ), | |
| 187 | + 'author_url_header' => __( 'Author URL', 'plugin-report' ), | |
| 181 | 188 | ); |
| 182 | - wp_localize_script( 'rt-plugin-report-js', 'rt_plugin_report_vars', $vars ); | |
| 189 | + wp_localize_script( 'plugin-report-js', 'plugin_report_vars', $vars ); | |
| 183 | 190 | // Enqueue admin CSS file. |
| 184 | - wp_enqueue_style( 'rt-plugin-report-css', plugin_dir_url( __FILE__ ) . 'css/rt-plugin-report.css' ); | |
| 191 | + wp_enqueue_style( 'plugin-report-css', plugin_dir_url( __FILE__ ) . 'css/plugin-report.css', array(), self::PLUGIN_VERSION ); | |
| 185 | 192 | } |
| 186 | 193 | |
| 187 | 194 | |
| 188 | 195 | /** |
| @@ -217,9 +224,9 @@ | ||
| 217 | 224 | */ |
| 218 | 225 | public function get_plugin_info() { |
| 219 | 226 | |
| 220 | 227 | // Check the ajax nonce, display an error if the check fails. |
| 221 | - if ( ! check_ajax_referer( 'rt_plugin_report_nonce', 'nonce', false ) ) { | |
| 228 | + if ( ! check_ajax_referer( 'plugin_report_nonce', 'nonce', false ) ) { | |
| 222 | 229 | wp_die(); |
| 223 | 230 | } |
| 224 | 231 | |
| 225 | 232 | // Check user capabilites, just to be sure. |
| @@ -247,9 +254,9 @@ | ||
| 247 | 254 | 'html' => $table_row, |
| 248 | 255 | 'message' => 'Success!', |
| 249 | 256 | ); |
| 250 | 257 | // Return the response. |
| 251 | - echo json_encode( $response ); | |
| 258 | + echo wp_json_encode( $response ); | |
| 252 | 259 | |
| 253 | 260 | wp_die(); |
| 254 | 261 | } |
| 255 | 262 | |
| @@ -288,8 +295,9 @@ | ||
| 288 | 295 | 'tags' => false, |
| 289 | 296 | 'version' => true, |
| 290 | 297 | 'tested' => true, |
| 291 | 298 | 'requires' => true, |
| 299 | + 'requires_php' => true, | |
| 292 | 300 | 'compatibility' => true, |
| 293 | 301 | 'author' => true, |
| 294 | 302 | ), |
| 295 | 303 | ); |
| @@ -330,17 +338,17 @@ | ||
| 330 | 338 | if ( $report == null ) { |
| 331 | 339 | $html = $this->render_error_row( esc_html__( 'No plugin data available.', 'plugin-report' ) ); |
| 332 | 340 | } else { |
| 333 | 341 | // Start the new table row. |
| 334 | - $html = '<tr class="rt-plugin-report-row-' . $report['slug'] . '">'; | |
| 342 | + $html = '<tr class="plugin-report-row-' . $report['slug'] . '">'; | |
| 335 | 343 | // Name. |
| 336 | - if( isset( $report['local_info']['PluginURI'] ) && !empty( $report['local_info']['PluginURI'] ) ){ | |
| 344 | + if ( isset( $report['local_info']['PluginURI'] ) && ! empty( $report['local_info']['PluginURI'] ) ) { | |
| 337 | 345 | $html .= '<td><a href="' . $report['local_info']['PluginURI'] . '"><strong>' . $report['local_info']['Name'] . '</strong></a></td>'; |
| 338 | 346 | } else { |
| 339 | 347 | $html .= '<td><strong>' . $report['local_info']['Name'] . '</strong></td>'; |
| 340 | 348 | } |
| 341 | 349 | // Author. |
| 342 | - if( isset( $report['local_info']['AuthorURI'] ) && !empty( $report['local_info']['AuthorURI'] ) ){ | |
| 350 | + if ( isset( $report['local_info']['AuthorURI'] ) && ! empty( $report['local_info']['AuthorURI'] ) ) { | |
| 343 | 351 | $html .= '<td><a href="' . $report['local_info']['AuthorURI'] . '">' . $report['local_info']['Author'] . '</a></td>'; |
| 344 | 352 | } else { |
| 345 | 353 | $html .= '<td>' . $report['local_info']['Author'] . '</td>'; |
| 346 | 354 | } |
| @@ -346,11 +354,11 @@ | ||
| 346 | 354 | } |
| 347 | 355 | // Activated. |
| 348 | 356 | $active = __( 'Please clear cache to update', 'plugin-report' ); |
| 349 | 357 | $css_class = self::CSS_CLASS_MED; |
| 350 | - if( is_multisite() ){ | |
| 358 | + if ( is_multisite() ) { | |
| 351 | 359 | $activation_status = $this->get_multisite_activation( $report['file_path'] ); |
| 352 | - if( $activation_status['network'] === true ){ | |
| 360 | + if ( true === $activation_status['network'] ) { | |
| 353 | 361 | $css_class = self::CSS_CLASS_LOW; |
| 354 | 362 | $html .= '<td class="' . $css_class . '">' . __( 'Network activated', 'plugin-report' ) . '</td>'; |
| 355 | 363 | } else { |
| 356 | 364 | $css_class = ( $activation_status['active'] > 0 ) ? self::CSS_CLASS_LOW : self::CSS_CLASS_HIGH; |
| @@ -356,9 +364,9 @@ | ||
| 356 | 364 | $css_class = ( $activation_status['active'] > 0 ) ? self::CSS_CLASS_LOW : self::CSS_CLASS_HIGH; |
| 357 | 365 | $html .= '<td class="' . $css_class . '">' . $activation_status['active'] . '/' . $activation_status['sites'] . '</td>'; |
| 358 | 366 | } |
| 359 | 367 | } else { |
| 360 | - if( isset( $report['file_path'] ) ){ | |
| 368 | + if ( isset( $report['file_path'] ) ) { | |
| 361 | 369 | $active = is_plugin_active( $report['file_path'] ) ? __( 'Yes', 'plugin-report' ) : __( 'No', 'plugin-report' ); |
| 362 | 370 | $css_class = is_plugin_active( $report['file_path'] ) ? self::CSS_CLASS_LOW : self::CSS_CLASS_HIGH; |
| 363 | 371 | } |
| 364 | 372 | $html .= '<td class="' . $css_class . '">' . $active . '</td>'; |
| @@ -363,14 +371,31 @@ | ||
| 363 | 371 | } |
| 364 | 372 | $html .= '<td class="' . $css_class . '">' . $active . '</td>'; |
| 365 | 373 | } |
| 366 | 374 | // Installed / available version. |
| 367 | - if( isset( $report['repo_info'] ) ){ | |
| 375 | + if ( isset( $report['repo_info'] ) ) { | |
| 368 | 376 | $css_class = $this->get_version_risk_classname( $report['local_info']['Version'], $report['repo_info']->version ); |
| 369 | 377 | $html .= '<td class="' . $css_class . '">'; |
| 370 | 378 | $html .= $report['local_info']['Version']; |
| 371 | 379 | if ( $report['local_info']['Version'] != $report['repo_info']->version ) { |
| 372 | - $html .= ' <span class="rt-additional-info">(' . $report['repo_info']->version . ' available)</span>'; | |
| 380 | + // Any platform upgrades needed? | |
| 381 | + global $wp_version; | |
| 382 | + $needs_php_upgrade = isset( $report['repo_info']->requires_php ) ? version_compare( phpversion(), $report['repo_info']->requires_php, '<' ) : false; | |
| 383 | + $needs_wp_upgrade = isset( $report['repo_info']->requires ) ? version_compare( $wp_version, $report['repo_info']->requires, '<' ) : false; | |
| 384 | + // Create the additional message. | |
| 385 | + if ( $needs_wp_upgrade && $needs_php_upgrade ) { | |
| 386 | + /* translators: %1$s: Plugin version number, %2$s: WP version number, %3$s: PHP version number */ | |
| 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>'; | |
| 388 | + } elseif ( $needs_wp_upgrade ) { | |
| 389 | + /* translators: %1$s: Plugin version number, %2$s: WP version number. */ | |
| 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>'; | |
| 391 | + } elseif ( $needs_php_upgrade ) { | |
| 392 | + /* translators: %1$s: Plugin version number, %2$s: PHP version number. */ | |
| 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>'; | |
| 394 | + } else { | |
| 395 | + /* translators: %s: Plugin version number. */ | |
| 396 | + $html .= ' <span class="pr-additional-info">' . sprintf( esc_html__( '(%s available)', 'plugin-report'), $report['repo_info']->version ) . '</span>'; | |
| 397 | + } | |
| 373 | 398 | } |
| 374 | 399 | $html .= '</td>'; |
| 375 | 400 | } else { |
| 376 | 401 | $html .= '<td>' . $report['local_info']['Version'] . '</td>'; |
| @@ -375,18 +400,18 @@ | ||
| 375 | 400 | } else { |
| 376 | 401 | $html .= '<td>' . $report['local_info']['Version'] . '</td>'; |
| 377 | 402 | } |
| 378 | 403 | // Last updates. |
| 379 | - if( isset( $report['repo_info'] ) ){ | |
| 404 | + if ( isset( $report['repo_info'] ) ) { | |
| 380 | 405 | $time_update = new DateTime( $report['repo_info']->last_updated ); |
| 381 | 406 | $time_diff = human_time_diff( $time_update->getTimestamp(), current_time( 'timestamp' ) ); |
| 382 | 407 | $css_class = $this->get_timediff_risk_classname( current_time( 'timestamp' ) - $time_update->getTimestamp() ); |
| 383 | - $html .= '<td class="' . $css_class . '">' . $time_diff . '</td>'; | |
| 408 | + $html .= '<td class="' . $css_class . '" data-sort="' . $time_update->getTimestamp() . '">' . $time_diff . '</td>'; | |
| 384 | 409 | } else { |
| 385 | 410 | $html .= $this->render_error_cell(); |
| 386 | 411 | } |
| 387 | 412 | // Tested up to. |
| 388 | - if( isset( $report['repo_info'] ) ){ | |
| 413 | + if ( isset( $report['repo_info'] ) ) { | |
| 389 | 414 | $css_class = $this->get_version_risk_classname( $report['repo_info']->tested, $wp_latest ); |
| 390 | 415 | $html .= '<td class="' . $css_class . '">' . $report['repo_info']->tested . '</td>'; |
| 391 | 416 | } else { |
| 392 | 417 | $html .= $this->render_error_cell(); |
| @@ -391,9 +416,9 @@ | ||
| 391 | 416 | } else { |
| 392 | 417 | $html .= $this->render_error_cell(); |
| 393 | 418 | } |
| 394 | 419 | // Overall user rating. |
| 395 | - if( isset( $report['repo_info'] ) ){ | |
| 420 | + if ( isset( $report['repo_info'] ) ) { | |
| 396 | 421 | $css_class = ( intval( $report['repo_info']->num_ratings ) > 0 ) ? $this->get_percentage_risk_classname( intval( $report['repo_info']->rating ) ) : ''; |
| 397 | 422 | $value_text = ( ( intval( $report['repo_info']->num_ratings ) > 0 ) ? $report['repo_info']->rating . '%' : esc_html__( 'No data available', 'plugin-report' ) ); |
| 398 | 423 | $html .= '<td class="' . $css_class . '">' . $value_text . '</td>'; |
| 399 | 424 | } else { |
| @@ -409,9 +434,9 @@ | ||
| 409 | 434 | /** |
| 410 | 435 | * Format an error message as a table row, so we can return it to javascript |
| 411 | 436 | */ |
| 412 | 437 | private function render_error_row( $message ) { |
| 413 | - return '<tr class="rt-pluginreport-row-error"><td colspan="' . self::COLS_PER_ROW . '">' . $message . '</td></tr>'; | |
| 438 | + return '<tr class="pluginreport-row-error"><td colspan="' . self::COLS_PER_ROW . '">' . $message . '</td></tr>'; | |
| 414 | 439 | } |
| 415 | 440 | |
| 416 | 441 | |
| 417 | 442 | /** |
| @@ -417,12 +442,12 @@ | ||
| 417 | 442 | /** |
| 418 | 443 | * Format an error message as a table cell, so we can return it to javascript |
| 419 | 444 | */ |
| 420 | 445 | private function render_error_cell( $message = null ) { |
| 421 | - if( !$message ){ | |
| 446 | + if ( ! $message ) { | |
| 422 | 447 | $message = esc_html__( 'No data available', 'plugin-report' ); |
| 423 | 448 | } |
| 424 | - return '<td class="rt-pluginreport-cell-error">' . $message . '</td>'; | |
| 449 | + return '<td class="pluginreport-cell-error">' . $message . '</td>'; | |
| 425 | 450 | } |
| 426 | 451 | |
| 427 | 452 | |
| 428 | 453 | /** |
| @@ -428,16 +453,12 @@ | ||
| 428 | 453 | /** |
| 429 | 454 | * Figure out what CSS class to use based on current and optimal version numbers |
| 430 | 455 | */ |
| 431 | 456 | private function get_version_risk_classname( $available, $optimal ) { |
| 432 | - // If the version match, indicate low risk. | |
| 433 | - if ( version_compare( $available, $optimal, '==' ) ) { | |
| 457 | + // If the version is equal or higher, indicate low risk. | |
| 458 | + if ( version_compare( $available, $optimal, '>=' ) ) { | |
| 434 | 459 | return self::CSS_CLASS_LOW; |
| 435 | 460 | } |
| 436 | - // If major version match, indicate medium risk. | |
| 437 | - if ( version_compare( $this->major_release_version_nr( $available ), $this->major_release_version_nr( $optimal ), '==' ) ) { | |
| 438 | - return self::CSS_CLASS_MED; | |
| 439 | - } | |
| 440 | 461 | // Else, indicate high risk. |
| 441 | 462 | return self::CSS_CLASS_HIGH; |
| 442 | 463 | } |
| 443 | 464 | |
| @@ -491,21 +512,11 @@ | ||
| 491 | 512 | } |
| 492 | 513 | |
| 493 | 514 | |
| 494 | 515 | /** |
| 495 | - * Extract the major release number from a WP version nr | |
| 496 | - */ | |
| 497 | - private function major_release_version_nr( $version ) { | |
| 498 | - $parts = explode( '.', $version ); | |
| 499 | - $parts = array_slice( $parts, 0, 2 ); | |
| 500 | - return implode( '.', $parts ); | |
| 501 | - } | |
| 502 | - | |
| 503 | - | |
| 504 | - /** | |
| 505 | 516 | * Gather statistics about a plugin's activation on a multisite install |
| 506 | 517 | */ |
| 507 | - private function get_multisite_activation( $path ){ | |
| 518 | + private function get_multisite_activation( $path ) { | |
| 508 | 519 | // Create an array to contain the return values. |
| 509 | 520 | $activation_status = array( |
| 510 | 521 | 'network' => false, |
| 511 | 522 | 'active' => 0, |
| @@ -512,9 +523,9 @@ | ||
| 512 | 523 | 'sites' => 1, |
| 513 | 524 | ); |
| 514 | 525 | // Check if the plugin is network activated. |
| 515 | 526 | $network_plugins = get_site_option( 'active_sitewide_plugins', null ); |
| 516 | - if( array_key_exists( $path, $network_plugins ) ){ | |
| 527 | + if ( array_key_exists( $path, $network_plugins ) ) { | |
| 517 | 528 | $activation_status['network'] = true; |
| 518 | 529 | } else { |
| 519 | 530 | // Get a list of all sites in the multisite install. |
| 520 | 531 | $args = array( |
| @@ -524,13 +535,13 @@ | ||
| 524 | 535 | $sites = get_sites( $args ); |
| 525 | 536 | // Add the total number of sites to the return array. |
| 526 | 537 | $activation_status['sites'] = count( $sites ); |
| 527 | 538 | // Loop through the sites to find where the plugin is active. |
| 528 | - foreach( $sites as $site_id ){ | |
| 539 | + foreach ( $sites as $site_id ) { | |
| 529 | 540 | $plugins = get_blog_option( $site_id, 'active_plugins', null ); |
| 530 | - if( $plugins ){ | |
| 531 | - foreach( $plugins as $plugin_path ){ | |
| 532 | - if( $plugin_path === $path ){ | |
| 541 | + if ( $plugins ) { | |
| 542 | + foreach ( $plugins as $plugin_path ) { | |
| 543 | + if ( $plugin_path === $path ) { | |
| 533 | 544 | $activation_status['active']++; |
| 534 | 545 | } |
| 535 | 546 | } |
| 536 | 547 | } |
| @@ -544,9 +555,9 @@ | ||
| 544 | 555 | /** |
| 545 | 556 | * Create a cache key that is unique to the provided plugin slug. |
| 546 | 557 | */ |
| 547 | 558 | private function create_cache_key( $slug ) { |
| 548 | - // Create a hash for the plugiin slug. | |
| 559 | + // Create a hash for the plugin slug. | |
| 549 | 560 | $slug_hash = hash( 'sha256', $slug ); |
| 550 | 561 | // Prefix and limit the string to 40 characters to avoid issues with long keys. |
| 551 | 562 | $cache_key = 'rtpr_' . substr( $slug_hash, 0, 35 ); |
| 552 | 563 | // Return the key. |
| @@ -574,9 +585,9 @@ | ||
| 574 | 585 | private function clear_cache_item( $slug ) { |
| 575 | 586 | if ( isset( $slug ) ) { |
| 576 | 587 | $cache_key = $this->create_cache_key( $slug ); |
| 577 | 588 | delete_site_transient( $cache_key ); |
| 578 | - } | |
| 589 | + } | |
| 579 | 590 | } |
| 580 | 591 | |
| 581 | 592 | |
| 582 | 593 | /** |
| @@ -595,8 +606,8 @@ | ||
| 595 | 606 | |
| 596 | 607 | } |
| 597 | 608 | |
| 598 | 609 | // Instantiate the class. |
| 599 | - $rt_plugin_report_instance = new RT_Plugin_Report(); | |
| 600 | - $rt_plugin_report_instance->init(); | |
| 610 | + $plugin_report_instance = new RT_Plugin_Report(); | |
| 611 | + $plugin_report_instance->init(); | |
| 601 | 612 | |
| 602 | 613 | } |