Skip to content

Commit

Permalink
Display an admin notice if dependencies are missing. See #76
Browse files Browse the repository at this point in the history
  • Loading branch information
bradyvercher committed Sep 5, 2018
1 parent deca1e9 commit bd4f87e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Requires PHP 7.0 or later.

## Zip

1. Download the [latest release](https://github.com/cedaro/satispress/releases/latest) from GitHub.
1. Download the [latest release](https://github.com/cedaro/satispress/releases/latest) from GitHub (use the asset named `satispress-{version}.zip`).
2. Go to the _Plugins → Add New_ screen in your WordPress admin panel and click the __Upload Plugin__ button at the top.
3. Upload the zipped archive.
4. Click the __Activate Plugin__ link after installation completes.
Expand All @@ -17,6 +17,6 @@ SatisPress is available on [Packagist](https://packagist.org/packages/cedaro/sat

```bash
composer require cedaro/satispress
```
```

[Back to Index](index.md)
7 changes: 7 additions & 0 deletions satispress.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
require __DIR__ . '/vendor/autoload.php';
}

// Display a notice and bail if dependencies are missing.
if ( ! function_exists( __NAMESPACE__ . '\autoloader_classmap' ) ) {
require_once __DIR__ . '/src/functions.php';
add_action( 'admin_notices', __NAMESPACE__ . '\display_missing_dependencies_notice' );
return;
}

// Autoload mapped classes.
spl_autoload_register( __NAMESPACE__ . '\autoloader_classmap' );

Expand Down
27 changes: 27 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,30 @@ function get_edited_user_id(): int {
function is_plugin_file( $plugin_file ) {
return '.php' === substr( $plugin_file, -4 );
}

/**
* Display a notice about missing dependencies.
*
* @since 0.3.1
*/
function display_missing_dependencies_notice() {
$message = sprintf(
/* translators: %s: documentation URL */
__( 'SatisPress is missing required dependencies. <a href="%s" target="_blank" rel="noopener noreferer">Learn more.</a>', 'satispress' ),
'https://github.com/cedaro/satispress/blob/master/docs/installation.md'
);

printf(
'<div class="satispress-compatibility-notice notice notice-error"><p>%s</p></div>',
wp_kses(
$message,
[
'a' => [
'href' => true,
'rel' => true,
'target' => true,
],
]
)
);
}

0 comments on commit bd4f87e

Please sign in to comment.