Ticket #26909: 0001-add-plugin-headers-Core-PHP-and-functions-to-check-a.patch
File 0001-add-plugin-headers-Core-PHP-and-functions-to-check-a.patch, 14.5 KB (added by , 11 years ago) |
---|
-
wp-admin/css/colors.css
From 54c3b8dfbd9f410bbedfa9592073d5579815e5f8 Mon Sep 17 00:00:00 2001 From: Christian Foellmann <foellmann@foe-services.de> Date: Mon, 23 Dec 2013 01:07:53 +0100 Subject: [PATCH] add plugin headers 'Core', 'PHP' and functions to check against environment variables --- wp-admin/css/colors.css | 5 +- wp-admin/includes/class-wp-plugins-list-table.php | 74 ++++++++++++--- wp-admin/includes/plugin.php | 106 +++++++++++++++++++++- 3 files changed, 169 insertions(+), 16 deletions(-) diff --git a/wp-admin/css/colors.css b/wp-admin/css/colors.css index f26c716..522964f 100644
a b tr.active + tr.plugin-update-tr .plugin-update { 824 824 .plugins .active.update td, 825 825 .plugins .active.update th, 826 826 tr.active.update + tr.plugin-update-tr .plugin-update, 827 .plugins .inactive.incompatible td, 828 .plugins .inactive.incompatible th, 827 829 #activity-widget #the-comment-list .unapproved { 828 830 background-color: #fefaf7; 829 831 } … … tr.active.update + tr.plugin-update-tr .plugin-update, 849 851 } 850 852 851 853 .plugins .active.update th.check-column, 852 .plugins .active.update + .plugin-update-tr .plugin-update { 854 .plugins .active.update + .plugin-update-tr .plugin-update, 855 .plugins .inactive.incompatible th.check-column { 853 856 border-left: 4px solid #d54e21; 854 857 } 855 858 -
wp-admin/includes/class-wp-plugins-list-table.php
diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 9e64849..1230fb3 100644
a b class WP_Plugins_List_Table extends WP_List_Table { 18 18 ) ); 19 19 20 20 $status = 'all'; 21 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )21 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'incompatible' ) ) ) { 22 22 $status = $_REQUEST['plugin_status']; 23 } 23 24 24 25 if ( isset($_REQUEST['s']) ) 25 26 $_SERVER['REQUEST_URI'] = add_query_arg('s', wp_unslash($_REQUEST['s']) ); … … class WP_Plugins_List_Table extends WP_List_Table { 48 49 'recently_activated' => array(), 49 50 'upgrade' => array(), 50 51 'mustuse' => array(), 51 'dropins' => array() 52 'dropins' => array(), 53 'incompatible' => array(), 52 54 ); 53 55 54 56 $screen = $this->screen; … … class WP_Plugins_List_Table extends WP_List_Table { 58 60 $plugins['mustuse'] = get_mu_plugins(); 59 61 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) 60 62 $plugins['dropins'] = get_dropins(); 61 63 if ( apply_filters( 'show_advanced_plugins', true, 'incompatible' ) ) { 64 $plugins['incompatible'] = get_incompatible_plugins(); 65 } 66 62 67 if ( current_user_can( 'update_plugins' ) ) { 63 68 $current = get_site_transient( 'update_plugins' ); 64 69 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { … … class WP_Plugins_List_Table extends WP_List_Table { 68 73 } 69 74 } 70 75 } 76 } elseif ( is_multisite() && !is_network_admin() && current_user_can( 'manage_network_plugins' ) ) { 77 if ( apply_filters( 'show_advanced_plugins', true, 'incompatible' ) ) { 78 $plugins['incompatible'] = get_incompatible_plugins(); 79 } 71 80 } 72 81 73 82 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS ); … … class WP_Plugins_List_Table extends WP_List_Table { 87 96 unset( $plugins['all'][ $plugin_file ] ); 88 97 } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) { 89 98 unset( $plugins['all'][ $plugin_file ] ); 90 } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) ) 91 || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) { 99 } elseif ( !is_plugin_compatible( $plugin_file ) ) { 100 unset( $plugins['all'][ $plugin_file ] ); 101 } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) ) || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) { 92 102 $plugins['active'][ $plugin_file ] = $plugin_data; 93 103 } else { 94 if ( ! $screen->in_admin( 'network' ) && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?104 if ( ! $screen->in_admin( 'network' ) && isset( $recently_activated[ $plugin_file ] ) ) {// Was the plugin recently activated? 95 105 $plugins['recently_activated'][ $plugin_file ] = $plugin_data; 106 } 96 107 $plugins['inactive'][ $plugin_file ] = $plugin_data; 97 108 } 98 109 } … … class WP_Plugins_List_Table extends WP_List_Table { 177 188 global $status; 178 189 179 190 return array( 180 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',191 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) || !( 'incompatible' == $status && is_multisite() && is_network_admin() ) ? '<input type="checkbox" />' : '', 181 192 'name' => __( 'Plugin' ), 182 193 'description' => __( 'Description' ), 183 194 ); … … class WP_Plugins_List_Table extends WP_List_Table { 208 219 case 'inactive': 209 220 $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); 210 221 break; 222 case 'incompatible': 223 $text = _n( 'Incompatible <span class="count">(%s)</span>', 'Incompatible <span class="count">(%s)</span>', $count ); 224 break; 211 225 case 'mustuse': 212 226 $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count ); 213 227 break; … … class WP_Plugins_List_Table extends WP_List_Table { 235 249 global $status; 236 250 237 251 $actions = array(); 252 253 if ( 'incompatible' == $status ) { 254 if ( is_multisite() ) { 255 if ( is_network_admin() && current_user_can( 'manage_network_plugins' ) ) { 256 $actions['delete-selected'] = __( 'Delete' ); 257 $actions['update-selected'] = __( 'Update' ); 258 return $actions; 259 } else { 260 return $actions; 261 } 262 } else { 263 if ( current_user_can( 'update_plugins' ) ) { 264 $actions['update-selected'] = __( 'Update' ); 265 } 266 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { 267 $actions['delete-selected'] = __( 'Delete' ); 268 } 269 return $actions; 270 } 271 } 238 272 239 273 if ( 'active' != $status ) 240 274 $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' ); 241 275 242 276 if ( 'inactive' != $status && 'recent' != $status ) 243 277 $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' ); 244 278 245 279 if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) { 246 280 if ( current_user_can( 'update_plugins' ) ) 247 281 $actions['update-selected'] = __( 'Update' ); … … class WP_Plugins_List_Table extends WP_List_Table { 262 296 } 263 297 264 298 function extra_tablenav( $which ) { 265 global $status ;299 global $status, $wp_version; 266 300 267 if ( ! in_array( $status, array('recently_activated', 'mustuse', 'dropins') ) )301 if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins', 'incompatible' ) ) ) 268 302 return; 269 303 270 304 echo '<div class="alignleft actions">'; 271 305 272 306 if ( ! $this->screen->in_admin( 'network' ) && 'recently_activated' == $status ) 273 307 submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false ); 274 308 elseif ( 'top' == $which && 'mustuse' == $status ) 275 309 echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>'; 276 310 elseif ( 'top' == $which && 'dropins' == $status ) 277 311 echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the <code>%s</code> directory that replace WordPress functionality when present.' ), str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) . '</p>'; 278 312 elseif ( 'bottom' == $which && 'incompatible' == $status ) { 313 if ( is_multisite() && is_network_admin() && current_user_can( 'manage_network' ) || !is_multisite() && current_user_can( 'install_plugins' ) ) { 314 echo '<p> Your PHP version is: ' . PHP_VERSION . ' | Your WP version is: ' . $wp_version . '</p>'; //@todo 315 } 316 } 279 317 echo '</div>'; 280 318 } 281 319 … … class WP_Plugins_List_Table extends WP_List_Table { 330 368 } 331 369 if ( $plugin_data['Description'] ) 332 370 $description .= '<p>' . $plugin_data['Description'] . '</p>'; 371 } elseif ( 'incompatible' == $context ) { 372 $is_active = false; 373 if ( is_network_admin() && current_user_can( 'manage_network_plugins' ) ) { 374 $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__( 'Delete this plugin' ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 375 } elseif ( !is_multisite() && current_user_can( 'delete_plugins' ) ) { 376 $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__( 'Delete this plugin' ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 377 } 333 378 } else { 334 379 if ( $screen->in_admin( 'network' ) ) 335 380 $is_active = is_plugin_active_for_network( $plugin_file ); … … class WP_Plugins_List_Table extends WP_List_Table { 367 412 368 413 $class = $is_active ? 'active' : 'inactive'; 369 414 $checkbox_id = "checkbox_" . md5($plugin_data['Name']); 370 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {415 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) || 'incompatible' == $context ) { 371 416 $checkbox = ''; 417 $class .= ' incompatible'; 372 418 } else { 373 419 $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>" 374 420 . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />"; … … class WP_Plugins_List_Table extends WP_List_Table { 430 476 } 431 477 432 478 echo "</tr>"; 433 479 434 480 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); 435 481 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); 436 482 } -
wp-admin/includes/plugin.php
diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index e85ac5b..f423676 100644
a b 47 47 * 'TextDomain' - Plugin's text domain for localization. 48 48 * 'DomainPath' - Plugin's relative directory path to .mo files. 49 49 * 'Network' - Boolean. Whether the plugin can only be activated network wide. 50 * 'Core' - The minimum WordPress version required. 51 * 'PHP' - The minimal PHP version required. 50 52 * 51 53 * Some users have issues with opening large files and manipulating the contents 52 54 * for want is usually the first 1kiB or 2kiB. This function stops pulling in … … function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { 83 85 'Network' => 'Network', 84 86 // Site Wide Only is deprecated in favor of Network. 85 87 '_sitewide' => 'Site Wide Only', 88 'Core' => 'Core', 89 'PHP' => 'PHP', 86 90 ); 87 91 88 92 $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); … … function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { 94 98 } 95 99 $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ); 96 100 unset( $plugin_data['_sitewide'] ); 97 101 98 102 if ( $markup || $translate ) { 99 103 $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); 100 104 } else { … … function get_mu_plugins() { 346 350 } 347 351 348 352 /** 353 * @todo 354 * 355 * @todo 356 * 357 * @since 3.9.0 358 * @return array @todo Key is the mu-plugin file path and the value is an array of the mu-plugin data. 359 */ 360 function get_incompatible_plugins() { 361 $incompatible_plugins = array(); 362 $wp_plugins = get_plugins(); 363 364 foreach ( $wp_plugins as $plugin => $plugin_data ) { 365 if ( is_plugin_incompatible( $plugin ) ) { 366 $incompatible_plugins[ $plugin ] = $plugin_data; 367 } 368 } 369 370 uasort( $incompatible_plugins, '_sort_uname_callback' ); 371 return $incompatible_plugins; 372 } 373 374 /** 349 375 * Callback to sort array by a 'Name' key. 350 376 * 351 377 * @since 3.1.0 … … function is_plugin_inactive( $plugin ) { 454 480 } 455 481 456 482 /** 483 * Check whether the plugin is compatible to current environment. 484 * 485 * Prevent activation if required WP core version or PHP version is not met or 486 * plugin is incompatible to network wide activation. 487 * 488 * @since 3.9.0 489 * 490 * @global int $wp_version The current version of this particular WP instance 491 * 492 * @param string $plugin Base plugin path from plugins directory. 493 * @return bool True if compatible. False if incompatible. 494 */ 495 function is_plugin_compatible( $plugin ) { 496 497 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; 498 499 if ( is_plugin_compatible_to_php( $plugin_file ) && is_plugin_compatible_to_core( $plugin_file ) ) { 500 return true; 501 } else { 502 return false; 503 } 504 505 } 506 507 /** 508 * @todo 509 * 510 * Reverse of iis_plugin_compatible(). Used as a callback. 511 * 512 * @since 3.9.0 513 * 514 * @param string $plugin Base plugin path from plugins directory. 515 * @return bool True if incompatible. False if compatible. 516 */ 517 function is_plugin_incompatible( $plugin ) { 518 return !is_plugin_compatible( $plugin ); 519 } 520 521 /** 522 * Check whether the plugin is compatible to the current PHP version. 523 * 524 * @since 3.9.0 525 * 526 * @param string $plugin Base plugin path from plugins directory. 527 * @return bool True if compatible. False if incompatible. 528 */ 529 function is_plugin_compatible_to_php( $plugin ) { 530 $plugin_data = get_plugin_data( $plugin ); 531 532 if ( isset( $plugin_data['PHP'] ) ) { 533 return version_compare( PHP_VERSION, $plugin_data['PHP'], '>=' ); 534 } else { 535 return true; 536 } 537 } 538 539 /** 540 * Check whether the plugin is compatible to the current WP version. 541 * 542 * @since 3.9.0 543 * 544 * @global int $wp_version The current version of this particular WP instance 545 * 546 * @param string $plugin Base plugin path from plugins directory. 547 * @return bool True if compatible. False if incompatible. 548 */ 549 function is_plugin_compatible_to_core( $plugin ) { 550 $plugin_data = get_plugin_data( $plugin ); 551 552 if ( isset( $plugin_data['Core'] ) ) { 553 global $wp_version; 554 return version_compare( $wp_version, $plugin_data['Core'], '>=' ); 555 } else { 556 return true; 557 } 558 } 559 560 /** 457 561 * Check whether the plugin is active for the entire network. 458 562 * 459 563 * @since 3.0.0