Ticket #43986: 43986v2-6.diff
File 43986v2-6.diff, 9.5 KB (added by , 6 years ago) |
---|
-
src/wp-admin/css/list-tables-rtl.css
diff --git src/wp-admin/css/list-tables-rtl.css src/wp-admin/css/list-tables-rtl.css index a262405bd7..85d8a75aec 100644
div.action-links, 1523 1523 .plugin-card .compatibility-incompatible:before { 1524 1524 content: "\f158"; 1525 1525 } 1526 .plugin-card .column-compatibility .compatibility-incompatible:before { 1527 color: #f00; 1528 } 1526 1529 1527 1530 .plugin-card .compatibility-compatible:before { 1528 1531 content: "\f147"; 1529 1532 } 1530 1533 1534 .plugin-card .column-compatibility .compatibility-compatible:before { 1535 color: #008000; 1536 } 1537 1531 1538 .plugin-icon { 1532 1539 position: absolute; 1533 1540 top: 20px; -
src/wp-admin/css/list-tables.css
diff --git src/wp-admin/css/list-tables.css src/wp-admin/css/list-tables.css index 1f463e6e54..950e3948e5 100644
div.action-links, 1524 1524 content: "\f158"; 1525 1525 } 1526 1526 1527 .plugin-card .column-compatibility .compatibility-incompatible:before { 1528 color: #f00; 1529 } 1530 1527 1531 .plugin-card .compatibility-compatible:before { 1528 1532 content: "\f147"; 1529 1533 } 1530 1534 1535 .plugin-card .column-compatibility .compatibility-compatible:before { 1536 color: #008000; 1537 } 1538 1531 1539 .plugin-icon { 1532 1540 position: absolute; 1533 1541 top: 20px; -
src/wp-admin/includes/class-wp-plugin-install-list-table.php
diff --git src/wp-admin/includes/class-wp-plugin-install-list-table.php src/wp-admin/includes/class-wp-plugin-install-list-table.php index a19729b1d4..fedb5f7118 100644
class WP_Plugin_Install_List_Table extends WP_List_Table { 456 456 457 457 $group = null; 458 458 459 $this->enforce_php_requirement(); 460 459 461 foreach ( (array) $this->items as $plugin ) { 460 462 if ( is_object( $plugin ) ) { 461 463 $plugin = (array) $plugin; … … class WP_Plugin_Install_List_Table extends WP_List_Table { 665 667 </div> 666 668 <div class="column-compatibility"> 667 669 <?php 670 echo '<strong>' . __( 'Requirements' ) . '</strong><br>'; 668 671 $wp_version = get_bloginfo( 'version' ); 669 672 670 if ( ! empty( $plugin['tested'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '>' ) ) { 671 echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>'; 672 } elseif ( ! empty( $plugin['requires'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '<' ) ) { 673 echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>'; 673 if ( $this->is_wordpress_compatible($plugin['tested'], '>' ) ) { 674 echo '<span class="compatibility-untested" aria-label="' . esc_attr__( 'Plugin untested with current WordPress version' ) . '">' . __( 'WordPress untested' ) . '</span>'; 675 } elseif ( $this->is_wordpress_compatible($plugin['requires'], '<') ) { 676 /* translators: WordPress required version */ 677 printf( '<span class="compatibility-incompatible" aria-label="' . esc_attr__( 'Plugin incompatible with current WordPress version' ) . '">' . __( 'WordPress %s' ) . '</span>', $plugin['requires'] ); 674 678 } else { 675 echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>'; 679 /* translators: WordPress required version */ 680 printf( '<span class="compatibility-compatible" aria-label="' . esc_attr__( 'Plugin compatible with current WordPress version' ) . '">' . __( 'WordPress %s' ) . '</span>', $plugin['requires'] ); 676 681 } 682 683 /** 684 * Add additional compatibility information to bottom of plugin card. 685 * 686 * @since 4.9.x 687 * 688 * @param array $plugin Readme.txt data from current plugin. 689 */ 690 do_action( 'plugin_install_compatibilty_information', $plugin ); 677 691 ?> 678 692 </div> 679 693 </div> … … class WP_Plugin_Install_List_Table extends WP_List_Table { 686 700 echo '</div></div>'; 687 701 } 688 702 } 703 704 /** 705 * Test if current version of WordPress is compatible with plugin requirements. 706 * 707 * @param mixed $version Version required. 708 * @param mixed $operator `version_compare()` operator. 709 * @return bool 710 */ 711 public function is_wordpress_compatible( $version, $operator ) { 712 $wp_version = get_bloginfo( 'version' ); 713 return ! empty( $version ) && version_compare( substr( $wp_version, 0, strlen( $version ) ), $version, $operator ); 714 } 715 716 /** 717 * Loads the filter hook to disable the plugin install button if PHP version not sufficient. 718 */ 719 public function enforce_php_requirement(){ 720 add_filter( 'plugin_install_action_links', array( $this, 'disable_install_button' ), 10, 2 ); 721 add_filter( 'wp_ajax_search-install-plugins', array( $this, 'disable_install_button' ), 10, 2 ); 722 add_filter( 'post_plugins_api_plugin_information', array( $this, 'disable_install_button_iframe' ), 10, 2 ); 723 add_action( 'plugin_install_compatibilty_information', array( $this, 'add_compatibility_text' ), 10, 1 ); 724 } 725 726 /** 727 * Filter plugin action links in Install Plugin page. 728 * 729 * @param array $action_links 730 * @param array $plugin 731 * 732 * @return array $action_links 733 */ 734 public function disable_install_button( $action_links, $plugin ) { 735 $disable_button = '<button type="button" class="button button-disabled" disabled="disabled" aria-label="' . esc_attr__( 'Cannot install this plugin' ) . '">'; 736 $disable_button .= __( 'Cannot install' ); 737 $disable_button .= '</button>'; 738 739 if ( isset( $plugin['requires_php'] ) && $plugin['requires_php'] && 740 version_compare( PHP_VERSION, $plugin['requires_php'], '<=' ) 741 ) { 742 $action_links[0] = $disable_button; 743 } 744 745 return $action_links; 746 } 747 748 /** 749 * Add PHP version compatibility text to plugin card bottom. 750 * 751 * @uses `plugin_install_compatibilty_information` action hook. 752 * 753 * @param mixed $plugin Current plugin data. 754 * 755 * @return string 756 */ 757 public function add_compatibility_text( $plugin ) { 758 if ( $plugin['requires_php'] && 759 version_compare( PHP_VERSION, $plugin['requires_php'], '<=' ) 760 ) { 761 /* translators: PHP version */ 762 printf( '<br><span class="compatibility-incompatible" aria-label="' . esc_attr__( 'PHP version incompatible with this plugin' ) . '">' . __( 'PHP %s' ) . '</span>', $plugin['requires_php'] ); 763 } else { 764 /* translators: PHP version */ 765 printf( '<br><span class="compatibility-compatible" aria-label="' . esc_attr__( 'PHP version compatible with this plugin' ) . '">' . __( 'PHP %s' ) . '</span>', $plugin['requires_php'] ); 766 } 767 } 768 769 /** 770 * Filter button display in Plugins API Plugin Information. 771 * 772 * @param mixed $status 773 * @param mixed $plugin 774 * @return void 775 */ 776 public function disable_install_button_iframe( $status, $plugin ) { 777 $disable_button = '<a class="button button-primary right disabled" aria-label="' . esc_attr__( 'Cannot install this plugin' ) . '">'; 778 $disable_button .= __( 'Cannot install' ); 779 $disable_button .= '</a>'; 780 781 if ( isset( $plugin->requires_php ) && $plugin->requires_php && 782 version_compare( PHP_VERSION, $plugin->requires_php, '<=' ) 783 ) { 784 echo $disable_button; 785 $status['status'] = 'cannot_install'; 786 } 787 788 return $status; 789 } 790 689 791 } -
src/wp-admin/includes/plugin-install.php
diff --git src/wp-admin/includes/plugin-install.php src/wp-admin/includes/plugin-install.php index f765fb286e..46b64b5094 100644
function install_plugin_install_status( $api, $loop = false ) { 483 483 } 484 484 485 485 $file = $update_file; 486 486 487 return compact( 'status', 'url', 'version', 'file' ); 487 488 } 488 489 … … function install_plugin_information() { 553 554 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), 554 555 ); 555 556 557 $wp_list_table = _get_list_table('WP_Plugin_Install_List_Table'); 558 $wp_list_table->enforce_php_requirement(); 559 556 560 // Sanitize HTML 557 561 foreach ( (array) $api->sections as $section_name => $content ) { 558 562 $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); … … if ( ! empty( $api->contributors ) ) { 758 762 } elseif ( ! empty( $api->requires ) && version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '<' ) ) { 759 763 echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.' ) . '</p></div>'; 760 764 } 765 if ( isset( $api->requires_php ) && $api->requires_php && 766 version_compare( PHP_VERSION, $api->requires_php, '<=' ) 767 ) { 768 echo '<div class="notice notice-error notice-alt"><p>' . sprintf( 769 /* translators: Upgrading PHP page URL */ 770 __( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>. You cannot install it. <a href="%s">Click here to learn more about upgrading PHP.</a>' ), 771 esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) ) 772 ) . '</p></div>'; 773 } 761 774 762 775 foreach ( (array) $api->sections as $section_name => $content ) { 763 776 $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); … … if ( ! empty( $api->contributors ) ) { 777 790 echo "<div id='$tab-footer'>\n"; 778 791 if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { 779 792 $status = install_plugin_install_status( $api ); 793 794 /** 795 * Filter Plugins API plugin information button. 796 * 797 * @since 4.9.x 798 */ 799 $status = apply_filters( 'post_plugins_api_plugin_information', $status, $api ); 780 800 switch ( $status['status'] ) { 781 801 case 'install': 782 802 if ( $status['url'] ) {