Ticket #43986: 43986v2-7.diff
File 43986v2-7.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..75054872af 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/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..3facc5c378 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 your version of WordPress' ) . '">' . __( '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 your version of WordPress' ) . '">' . __( '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 your version of WordPress' ) . '">' . __( '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 * 710 * @return bool 711 */ 712 public function is_wordpress_compatible( $version, $operator ) { 713 $wp_version = get_bloginfo( 'version' ); 714 715 return ! empty( $version ) && version_compare( substr( $wp_version, 0, strlen( $version ) ), $version, $operator ); 716 } 717 718 /** 719 * Loads the filter hook to disable the plugin install button if PHP version not sufficient. 720 */ 721 public function enforce_php_requirement(){ 722 add_filter( 'plugin_install_action_links', array( $this, 'disable_install_button' ), 10, 2 ); 723 add_filter( 'wp_ajax_search-install-plugins', array( $this, 'disable_install_button' ), 10, 2 ); 724 add_filter( 'post_plugins_api_plugin_information', array( $this, 'disable_install_button_iframe' ), 10, 2 ); 725 add_action( 'plugin_install_compatibilty_information', array( $this, 'add_compatibility_text' ), 10, 1 ); 726 } 727 728 /** 729 * Filter plugin action links in Install Plugin page. 730 * 731 * @param array $action_links 732 * @param array $plugin 733 * 734 * @return array $action_links 735 */ 736 public function disable_install_button( $action_links, $plugin ) { 737 $disable_button = '<button type="button" class="button button-disabled" disabled="disabled" aria-label="' . esc_attr__( 'Cannot install this plugin' ) . '">'; 738 $disable_button .= __( 'Cannot install' ); 739 $disable_button .= '</button>'; 740 741 if ( isset( $plugin['requires_php'] ) && $plugin['requires_php'] && 742 version_compare( PHP_VERSION, $plugin['requires_php'], '<=' ) 743 ) { 744 $action_links[0] = $disable_button; 745 } 746 747 return $action_links; 748 } 749 750 /** 751 * Filter button display in Plugins API Plugin Information. 752 * 753 * @param mixed $status 754 * @param mixed $plugin 755 * 756 * @return void 757 */ 758 public function disable_install_button_iframe( $status, $plugin ) { 759 $disable_button = '<a class="button button-primary right disabled" aria-label="' . esc_attr__( 'Cannot install this plugin' ) . '">'; 760 $disable_button .= __( 'Cannot install' ); 761 $disable_button .= '</a>'; 762 763 if ( isset( $plugin->requires_php ) && $plugin->requires_php && 764 version_compare( PHP_VERSION, $plugin->requires_php, '<=' ) 765 ) { 766 echo $disable_button; 767 $status['status'] = 'cannot_install'; 768 } 769 770 return $status; 771 } 772 773 /** 774 * Add PHP version compatibility text to plugin card bottom. 775 * 776 * @uses `plugin_install_compatibilty_information` action hook. 777 * 778 * @param mixed $plugin Current plugin data. 779 * 780 * @return string 781 */ 782 public function add_compatibility_text( $plugin ) { 783 if ( $plugin['requires_php'] && 784 version_compare( PHP_VERSION, $plugin['requires_php'], '<=' ) 785 ) { 786 /* translators: PHP version */ 787 printf( '<br><span class="compatibility-incompatible" aria-label="' . esc_attr__( 'Plugin is incompatible with your version of PHP' ) . '">' . __( 'PHP %s' ) . '</span>', $plugin['requires_php'] ); 788 } else { 789 /* translators: PHP version */ 790 printf( '<br><span class="compatibility-compatible" aria-label="' . esc_attr__( 'Plugin is compatible with your version of PHP' ) . '">' . __( 'PHP %s' ) . '</span>', $plugin['requires_php'] ); 791 } 792 } 793 689 794 } -
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'] ) {