Skip to content

Commit 93f8c29

Browse files
committed
update requirements check for php extensions
1 parent a0d4f74 commit 93f8c29

File tree

4 files changed

+59
-19
lines changed

4 files changed

+59
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Please test and report issues here.
1717
Some of the included libraries have relatively recent dependency requirements so you will need the following in your WordPress platform:
1818
* PHP 8.1+
1919
* php-gmp module must be installed ([Installation on Ubuntu](https://computingforgeeks.com/how-to-install-php-on-ubuntu-linux-system/))
20+
* php-bcmath module must be installed ([Installation on Ubuntu](https://www.itsolutionstuff.com/post/ubuntu-php-bcmath-extension-install-commands-exampleexample.html))
2021
* WordPress 6.0+
2122
* Writable uploads directory (on activation, the plugin writes a cryptographic keyfile to a storage directory)
2223

classes/class-nostrtium-requirements-check.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Nostrtium_Requirements_Check {
88
// args
99
private $title = '';
1010
private $php = '8.1';
11+
private $extensions = [];
1112
private $wp = '6.0';
1213
private $dir = '';
1314
private $file;
@@ -20,62 +21,95 @@ public function __construct($args) {
2021
}
2122
}
2223
}
24+
2325
public function passes() {
24-
$passes = $this->php_passes() && $this->wp_passes() && $this->dir_passes();
26+
$passes = $this->php_passes() && $this->extensions_passes() && $this->wp_passes() && $this->dir_passes();
2527
if (!$passes) {
2628
add_action('admin_notices', [$this, 'deactivate']);
2729
}
2830

2931
return $passes;
3032
}
33+
3134
public function deactivate() {
3235
if (isset($this->file)) {
3336
deactivate_plugins(plugin_basename($this->file));
3437
}
3538
}
39+
3640
private function php_passes() {
3741
if ($this->__php_at_least($this->php)) {
3842
return true;
3943
} else {
4044
add_action('admin_notices', [$this, 'php_version_notice']);
41-
4245
return false;
4346
}
4447
}
48+
4549
private static function __php_at_least($min_version) {
4650
return version_compare(phpversion(), $min_version, '>=');
4751
}
52+
4853
public function php_version_notice() {
4954
echo '<div class="error">';
5055
echo '<p>The &#8220;' . esc_html($this->title) . '&#8221; plugin cannot run on PHP versions older than ' . $this->php . '. Please contact your host and ask them to upgrade.</p>';
5156
echo '</div>';
5257
}
58+
59+
private function extensions_passes() {
60+
$loaded_extensions = get_loaded_extensions();
61+
$passes = true;
62+
$missing = "";
63+
64+
foreach ($this->extensions as $extension) {
65+
if (!in_array($extension, $loaded_extensions)) {
66+
$passes = false;
67+
$missing .= $extension . ", ";
68+
}
69+
}
70+
71+
if ($passes) {
72+
return true;
73+
} else {
74+
add_action('admin_notices', [$this, 'extensions_notice', $missing]);
75+
return false;
76+
}
77+
}
78+
79+
public function extensions_notice($missing) {
80+
echo '<div class="error">';
81+
echo '<p>The &#8220;' . esc_html($this->title) . '&#8221; plugin cannot run without these missing php extensions: ' . $missing . '.</p>';
82+
echo '</div>';
83+
}
84+
5385
private function wp_passes() {
5486
if ($this->__wp_at_least($this->wp)) {
5587
return true;
5688
} else {
5789
add_action('admin_notices', [$this, 'wp_version_notice']);
58-
5990
return false;
6091
}
6192
}
93+
6294
private static function __wp_at_least($min_version) {
6395
return version_compare(get_bloginfo('version'), $min_version, '>=');
6496
}
97+
6598
public function wp_version_notice() {
6699
echo '<div class="error">';
67100
echo '<p>The &#8220;' . esc_html($this->title) . '&#8221; plugin cannot run on WordPress versions older than ' . $this->wp . '. Please update WordPress.</p>';
68101
echo '</div>';
69102
}
70-
private function dir_passes() {
71-
if (is_writable($this->dir)) {
72-
return true;
73-
} else {
74-
add_action('admin_notices', [$this, 'dir_writeable_notice']);
75103

76-
return false;
77-
}
104+
private function dir_passes() {
105+
if (is_writable($this->dir)) {
106+
return true;
107+
} else {
108+
add_action('admin_notices', [$this, 'dir_writeable_notice']);
109+
return false;
78110
}
111+
}
112+
79113
public function dir_writeable_notice() {
80114
echo '<div class="error">';
81115
echo '<p>The &#8220;' . esc_html($this->title) . '&#8221; plugin cannot run without the wp-content/uploads directory being writeable.</p>';

nostrtium.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Author URI: https://github.com/pjv
99
* Text Domain: nostrtium
1010
* Domain Path: /languages
11-
* Version: 0.7.1
11+
* Version: 0.7.2
1212
* Requires at least 6.0
1313
* Requires PHP 8.1
1414
* License Unlicense
@@ -21,18 +21,18 @@
2121
exit;
2222
}
2323

24-
define('PJV_NOSTRTIUM_VERSION', '0.7.1');
24+
define('PJV_NOSTRTIUM_VERSION', '0.7.2');
2525
define('PJV_NOSTRTIUM_DIR', plugin_dir_path(__FILE__));
2626
define('PJV_NOSTRTIUM_DEFAULT_USER_ROLE', 'edit_posts');
2727
define('PJV_NOSTRTIUM_STORAGE', wp_upload_dir()['basedir'] . '/nostrtium_' . md5(LOGGED_IN_SALT) . '/');
2828

2929
require_once PJV_NOSTRTIUM_DIR . 'classes/class-nostrtium-requirements-check.php';
30-
$pjv_nostrtium_requirements_check = new Nostrtium_Requirements_Check([
31-
'title' => 'Nostrtium',
32-
'php' => '8.1',
33-
'wp' => '6.0',
34-
'dir' => wp_upload_dir()['basedir'],
35-
'file' => __FILE__,
30+
$pjv_nostrtium_requirements_check = new Nostrtium_Requirements_Check(['title' => 'Nostrtium',
31+
'php' => '8.1',
32+
'extensions' => ['gmp', 'bcmath'],
33+
'wp' => '6.0',
34+
'dir' => wp_upload_dir()['basedir'],
35+
'file' => __FILE__,
3636
]);
3737
if ($pjv_nostrtium_requirements_check->passes()) {
3838
require_once PJV_NOSTRTIUM_DIR . 'vendor/autoload.php';

readme.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: social media, nostr
55
Requires at least: 6.0
66
Requires PHP: 8.1
77
Tested up to: 6.2.2
8-
Stable tag: 0.7.0
8+
Stable tag: 0.7.2
99
License: Unlicense
1010
License URI: https://unlicense.org
1111

@@ -30,6 +30,7 @@ Development is taking place on [github](https://github.com/pjv/nostrtium) and th
3030
Some of the included libraries have relatively recent dependency requirements so you will need the following in your WordPress platform:
3131
* PHP 8.1+
3232
* php-gmp module must be installed ([Installation on Ubuntu](https://computingforgeeks.com/how-to-install-php-on-ubuntu-linux-system/))
33+
* php-bcmath module must be installed ([Installation on Ubuntu](https://www.itsolutionstuff.com/post/ubuntu-php-bcmath-extension-install-commands-exampleexample.html))
3334
* WordPress 6.0+
3435
* Writable uploads directory (on activation, the plugin writes a cryptographic keyfile to a storage directory)
3536

@@ -65,6 +66,10 @@ The manual installation method involves downloading the plugin and then uploadin
6566

6667
== Changelog ==
6768

69+
= 0.7.2 =
70+
* Update requirements text and requirements check
71+
* Fix missing variable declaration
72+
6873
= 0.7.1 =
6974
* Auto-post only on first publication - not updates of old posts.
7075
* Auto post only of type 'post' (currently not pages or custom post types).

0 commit comments

Comments
 (0)