Skip to content

Commit

Permalink
Add an admin notice if Shiny Code is installed from source and missin…
Browse files Browse the repository at this point in the history
…g dependencies. See #5
  • Loading branch information
bradyvercher committed Dec 20, 2018
1 parent 3bba8bb commit 25363f3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## [Unreleased]

## 1.0.0 - 2018-12-13
* Added an admin notice if Shiny Code is missing dependencies. ([#5](https://github.com/cedaro/shiny-code/issues/5))

## [1.0.0] - 2018-12-13

* Fixed enqueuing of custom Prism.js language assets.
* Fixed the handle for core block editor styles for WordPress 5.0.
Expand Down
40 changes: 40 additions & 0 deletions php/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Helper functions
*
* @package ShinyCode
* @since 1.0.1
* @copyright Copyright (c) 2018 Cedaro, LLC
* @license GPL-2.0-or-later
*/

declare ( strict_types = 1 );

namespace Cedaro\WP\BlockType\Code;

/**
* Display a notice about missing dependencies.
*
* @since 1.0.1
*/
function display_missing_dependencies_notice() {
$message = sprintf(
/* translators: %s: documentation URL */
__( 'Shiny Code is missing required dependencies. <a href="%s" target="_blank" rel="noopener noreferer">Learn more.</a>', 'shiny-code' ),
'https://github.com/cedaro/shiny-code#installation'
);

printf(
'<div class="shiny-code-compatibility-notice notice notice-error"><p>%s</p></div>',
wp_kses(
$message,
[
'a' => [
'href' => true,
'rel' => true,
'target' => true,
],
]
)
);
}
7 changes: 7 additions & 0 deletions shiny-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
require __DIR__ . '/vendor/autoload.php';
}

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

// Create the main plugin instance.
$shiny_code = ( new Plugin() )
->set_basename( plugin_basename( __FILE__ ) )
Expand Down

0 comments on commit 25363f3

Please sign in to comment.