| | 700 | |
| | 701 | /** |
| | 702 | * Loads the filter hook to disable the plugin install button if PHP version not sufficient. |
| | 703 | */ |
| | 704 | public function load_requires_php(){ |
| | 705 | add_filter( 'plugin_install_action_links', array( $this, 'disable_install_button' ), 10, 2 ); |
| | 706 | add_filter( 'wp_ajax_search-install-plugins', array( $this, 'disable_install_button' ), 10, 2 ); |
| | 707 | add_action( 'plugin_install_compatibilty_information', array( $this, 'add_compatibility_text' ), 10, 1 ); |
| | 708 | } |
| | 709 | |
| | 710 | /** |
| | 711 | * Filter plugin action links in Install Plugin page. |
| | 712 | * |
| | 713 | * @param array $action_links |
| | 714 | * @param array $plugin |
| | 715 | * |
| | 716 | * @return array $action_links |
| | 717 | */ |
| | 718 | public function disable_install_button( $action_links, $plugin ) { |
| | 719 | $disable_button = '<button type="button" class="button button-disabled" disabled="disabled">'; |
| | 720 | $disable_button .= __( 'Cannot install' ); |
| | 721 | $disable_button .= '</button>'; |
| | 722 | |
| | 723 | if ( $plugin['requires_php'] && |
| | 724 | version_compare( PHP_VERSION, $plugin['requires_php'], '<=' ) |
| | 725 | ) { |
| | 726 | $action_links[0] = $disable_button; |
| | 727 | } |
| | 728 | |
| | 729 | return $action_links; |
| | 730 | } |
| | 731 | |
| | 732 | /** |
| | 733 | * Add PHP version compatibility text to plugin card bottom. |
| | 734 | * |
| | 735 | * @uses `plugin_install_compatibilty_information` action hook. |
| | 736 | * |
| | 737 | * @param mixed $plugin Current plugin data. |
| | 738 | * |
| | 739 | * @return string |
| | 740 | */ |
| | 741 | public function add_compatibility_text( $plugin ) { |
| | 742 | if ( $plugin['requires_php'] && |
| | 743 | version_compare( PHP_VERSION, $plugin['requires_php'], '<=' ) |
| | 744 | ) { |
| | 745 | printf( '<br><span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of PHP, PHP v%s required.' ) . '</span>', $plugin['requires_php'] ); |
| | 746 | } |
| | 747 | } |
| | 748 | |