Ticket #43986: 43986v2-8.diff
File 43986v2-8.diff, 10.4 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..c24dc20fc0 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 Plugin data from w.org API. 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 string $version Version required. 708 * @param string $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 * Test if current version of PHP is compatible with plugin requirements. 720 * 721 * @param string $version Version required. 722 * @param string $operator `version_compare()` operator. 723 * 724 * @return bool 725 */ 726 public function is_php_compatible( $version, $operator ) { 727 return isset( $version ) && $version && version_compare( PHP_VERSION, $version, $operator ); 728 } 729 730 /** 731 * Loads the hooks for enforcement of PHP version requirements. 732 */ 733 public function enforce_php_requirement(){ 734 add_filter( 'plugin_install_action_links', array( $this, 'disable_install_button' ), 10, 2 ); 735 add_filter( 'wp_ajax_search-install-plugins', array( $this, 'disable_install_button' ), 10, 2 ); 736 add_filter( 'post_plugins_api_plugin_information', array( $this, 'disable_install_button_iframe' ), 10, 2 ); 737 add_action( 'plugin_install_compatibilty_information', array( $this, 'add_compatibility_text' ), 10, 1 ); 738 } 739 740 /** 741 * Filter plugin action links in Install Plugin page. 742 * 743 * @param array $action_links 744 * @param array $plugin Plugin data from w.org API. 745 * 746 * @return array $action_links 747 */ 748 public function disable_install_button( $action_links, $plugin ) { 749 $disable_button = '<button type="button" class="button button-disabled" disabled="disabled" aria-label="' . esc_attr__( 'Cannot install this plugin' ) . '">'; 750 $disable_button .= __( 'Cannot install' ); 751 $disable_button .= '</button>'; 752 753 if ( $this->is_php_compatible( $plugin['requires_php'], '<=' ) ) { 754 $action_links[0] = $disable_button; 755 } 756 757 return $action_links; 758 } 759 760 /** 761 * Filter button display in Plugins API Plugin Information. 762 * 763 * @param mixed $status 764 * @param mixed $plugin Plugin data from w.org API. 765 * 766 * @return void 767 */ 768 public function disable_install_button_iframe( $status, $plugin ) { 769 $disable_button = '<a class="button button-primary right disabled" aria-label="' . esc_attr__( 'Cannot install this plugin' ) . '">'; 770 $disable_button .= __( 'Cannot install' ); 771 $disable_button .= '</a>'; 772 773 if ( $this->is_php_compatible( $plugin->requires_php, '<=' ) ) { 774 echo $disable_button; 775 $status['status'] = 'cannot_install'; 776 } 777 778 return $status; 779 } 780 781 /** 782 * Add PHP version compatibility text to plugin card bottom. 783 * 784 * @uses `plugin_install_compatibilty_information` action hook. 785 * 786 * @param mixed $plugin Current plugin data. 787 * 788 * @return string 789 */ 790 public function add_compatibility_text( $plugin ) { 791 if ( $this->is_php_compatible( $plugin['requires_php'], '<=' ) ) { 792 /* translators: PHP version */ 793 printf( '<br><span class="compatibility-incompatible" aria-label="' . esc_attr__( 'Plugin is incompatible with your version of PHP' ) . '">' . __( 'PHP %s' ) . '</span>', $plugin['requires_php'] ); 794 } else { 795 /* translators: PHP version */ 796 printf( '<br><span class="compatibility-compatible" aria-label="' . esc_attr__( 'Plugin is compatible with your version of PHP' ) . '">' . __( 'PHP %s' ) . '</span>', $plugin['requires_php'] ); 797 } 798 } 799 689 800 } -
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..202aba31e9 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 ) ) { 751 755 </div> 752 756 <div id="section-holder" class="wrap"> 753 757 <?php 754 $wp_version = get_bloginfo( 'version' ); 755 756 if ( ! empty( $api->tested ) && version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '>' ) ) { 758 if ( $wp_list_table->is_wordpress_compatible( $api->tested, '>' ) ) { 757 759 echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.' ) . '</p></div>'; 758 } elseif ( ! empty( $api->requires ) && version_compare( substr( $wp_version, 0, strlen( $api->requires ) ),$api->requires, '<' ) ) {760 } elseif ( $wp_list_table->is_wordpress_compatible( $api->requires, '<' ) ) { 759 761 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 762 } 763 if ( $wp_list_table->is_php_compatible( $api->requires_php, '<=' ) ) { 764 echo '<div class="notice notice-error notice-alt"><p>' . sprintf( 765 /* translators: Upgrading PHP page URL */ 766 __( '<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>' ), 767 esc_url( __( 'https://wordpress.org/support/upgrade-php/' ) ) 768 ) . '</p></div>'; 769 } 761 770 762 771 foreach ( (array) $api->sections as $section_name => $content ) { 763 772 $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); … … if ( ! empty( $api->contributors ) ) { 777 786 echo "<div id='$tab-footer'>\n"; 778 787 if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { 779 788 $status = install_plugin_install_status( $api ); 789 790 /** 791 * Filter Plugins API plugin information button. 792 * 793 * @since 4.9.x 794 * 795 * @param array $status Data from install_plugin_install_status(). 796 * @param array $api Plugin data from w.org API. 797 * 798 * @return mixed $status 799 */ 800 $status = apply_filters( 'post_plugins_api_plugin_information', $status, $api ); 780 801 switch ( $status['status'] ) { 781 802 case 'install': 782 803 if ( $status['url'] ) {