Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.67% |
42 / 43 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Dependencies_Notice | |
97.67% |
42 / 43 |
|
50.00% |
1 / 2 |
4 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| print_dependencies_notice | |
97.56% |
40 / 41 |
|
0.00% |
0 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Print an admin notice if the required GMP PHP extension is not present. |
| 4 | * |
| 5 | * @package brianhenryie/bh-wp-bitcoin-gateway |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WP_Bitcoin_Gateway\Admin; |
| 9 | |
| 10 | use BrianHenryIE\WP_Bitcoin_Gateway\API_Interface; |
| 11 | use BrianHenryIE\WP_Bitcoin_Gateway\Settings_Interface; |
| 12 | |
| 13 | /** |
| 14 | * Hooks into wp-admin's admin_notice action and prints a warning if the plugin's dependencies are not present. |
| 15 | * |
| 16 | * @see wp-admin/admin-header.php |
| 17 | */ |
| 18 | class Dependencies_Notice { |
| 19 | |
| 20 | /** |
| 21 | * Used to get the plugin basename for generating the deactivate link. |
| 22 | * |
| 23 | * @var Settings_Interface |
| 24 | */ |
| 25 | protected Settings_Interface $settings; |
| 26 | |
| 27 | /** |
| 28 | * Used to find is the dependency present or not. |
| 29 | * |
| 30 | * @var API_Interface |
| 31 | */ |
| 32 | protected API_Interface $api; |
| 33 | |
| 34 | /** |
| 35 | * Constructor |
| 36 | * |
| 37 | * @param API_Interface $api The main plugin functions. |
| 38 | * @param Settings_Interface $settings The plugin settings. |
| 39 | */ |
| 40 | public function __construct( API_Interface $api, Settings_Interface $settings ) { |
| 41 | $this->api = $api; |
| 42 | $this->settings = $settings; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Print the admin notice, if the dependency is missing and it is an admin logged in. |
| 47 | * The notice links to the PHP.net GMP page, and contains a deactivate link for the plugin. |
| 48 | * |
| 49 | * @hooked admin_notices |
| 50 | */ |
| 51 | public function print_dependencies_notice(): void { |
| 52 | |
| 53 | if ( $this->api->is_server_has_dependencies() ) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | if ( ! current_user_can( 'administrator' ) ) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | echo '<div class="notice notice-warning is-dismissible">'; |
| 62 | echo '<p>'; |
| 63 | echo '<b>Bitcoin Gateway</b>.'; |
| 64 | echo ' '; |
| 65 | |
| 66 | $gmp_link = '<a target="_blank" href="https://www.php.net/manual/en/book.gmp.php">GMP (GNU Multiple Precision Arithmetic Library)</a>'; |
| 67 | |
| 68 | printf( |
| 69 | /* translators: %s is replaced with a link to the PHP.net page for the missing GMP extension. */ |
| 70 | esc_html( __( 'Required PHP extension %s is not installed on this server. This is required for the calculations to derive Bitcoin payment addresses.', 'bh-wp-bitcoin-gateway' ) ), |
| 71 | wp_kses( |
| 72 | $gmp_link, |
| 73 | array( |
| 74 | 'a' => array( |
| 75 | 'target' => array(), |
| 76 | 'href' => array(), |
| 77 | ), |
| 78 | ) |
| 79 | ) |
| 80 | ); |
| 81 | echo ' '; |
| 82 | |
| 83 | echo wp_kses( __( 'Please <b>contact your hosting provider for support</b>.', 'bh-wp-bitcoin-gateway' ), array( 'b' => array() ) ); |
| 84 | echo ' '; |
| 85 | |
| 86 | $deactivate_link = wp_nonce_url( |
| 87 | add_query_arg( |
| 88 | array( |
| 89 | 'action' => 'deactivate', |
| 90 | 'plugin' => $this->settings->get_plugin_basename(), |
| 91 | ), |
| 92 | admin_url( |
| 93 | 'plugins.php' |
| 94 | ) |
| 95 | ), |
| 96 | "deactivate-plugin_{$this->settings->get_plugin_basename()}" |
| 97 | ); |
| 98 | |
| 99 | echo ' <a href="' . esc_url( $deactivate_link ) . '">'; |
| 100 | echo esc_html( __( 'Deactivate Bitcoin Gateway plugin', 'bh-wp-bitcoin-gateway' ) ); |
| 101 | echo '</a>.'; |
| 102 | |
| 103 | echo '</p>'; |
| 104 | echo '</div>'; |
| 105 | } |
| 106 | } |