Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
fix(lib/Bootstrap): require ACF plugin (#173)
Browse files Browse the repository at this point in the history
* fix(lib/Bootstrap): require acf plugin in addition to flynt core

also includes minor text improvements

closes #139

* refactor(lib/Bootstrap): align error texts for inactive plugins

and use warnings in case template file is not found

* refactor(lib/Bootstrap): extract admin notice into separate method

* refactor(lib/Bootstrap): rename checkPlugin to checkRequiredPlugins

BREAKING CHANGE: not used anywhere else, but still a public method name that changed

* style(lib/Bootstrap): fix linting error opening brace on same line

* fix(lib/Bootstrap): add missing parameter to function closure
  • Loading branch information
Doğa Gürdal committed May 11, 2017
1 parent e2cb5e6 commit 975c529
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
8 changes: 4 additions & 4 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// defined here.
Bootstrap::setTemplateDirectory();

// Check if the plugin is installed and activated.
// If it isn't, this function redirects the template rendering to use
// plugin-inactive.php instead
if (Bootstrap::checkPlugin()) {
// Check if the required plugins are installed and activated.
// If they aren't, this function redirects the template rendering to use
// plugin-inactive.php instead and shows a warning in the admin backend.
if (Bootstrap::checkRequiredPlugins()) {
require_once get_template_directory() . '/lib/Init.php';
}
38 changes: 26 additions & 12 deletions lib/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,43 @@ public static function setTemplateDirectory()
});
}

public static function checkPlugin()
public static function checkRequiredPlugins()
{
$pluginActive = class_exists('\\Flynt\\Render');
$flyntCoreActive = class_exists('\\Flynt\\Render');
$acfActive = class_exists('acf');

if (!$pluginActive) {
add_action('admin_notices', function () {
echo '<div class="error"><p>Flynt Core Plugin not activated. Make sure you activate the plugin in <a href="'
. esc_url(admin_url('plugins.php#flynt')) . '">'
. esc_url(admin_url('plugins.php')) . '</a></p></div>';
});
if (!$flyntCoreActive) {
self::notifyRequiredPluginIsMissing('Flynt Core');
}

if (!$acfActive) {
self::notifyRequiredPluginIsMissing('ACF');
}

if (!$acfActive || !$flyntCoreActive) {
add_filter('template_include', function () {
$newTemplate = locate_template(['plugin-inactive.php']);
$newTemplate = locate_template('plugin-inactive.php');
if ('' != $newTemplate) {
return $newTemplate;
} else {
return 'Flynt Core Plugin not activated! Please <a href="'
trigger_error(
'One or more required plugins are not activated! Please <a href="'
. esc_url(admin_url('plugins.php'))
. '">activate the plugin</a> and reload the page.';
. '">activate or install the required plugin(s)</a> and reload the page.',
E_USER_WARNING
);
}
});
}

return $pluginActive;
return $acfActive && $flyntCoreActive;
}

protected static function notifyRequiredPluginIsMissing($pluginName)
{
add_action('admin_notices', function () use ($pluginName) {
echo "<div class=\"error\"><p>${pluginName} Plugin not activated. Make sure you activate the plugin on the <a href=\""
. esc_url(admin_url('plugins.php')) . "\">plugin page</a>.</p></div>";
});
}
}
6 changes: 3 additions & 3 deletions templates/plugin-inactive.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html>
<head>
<meta charset="utf-8">
<title>Plugin Inactive!</title>
<title>Flynt - Plugin(s) Inactive!</title>
<?php wp_head(); ?>
</head>
<body>
One or more required Plugins are not activated! Please
<a href="<?= admin_url('plugins.php') ?>">activate or install the required plugin(s)</a>
One or more required plugins are not activated! Please
<a href="<?php echo admin_url('plugins.php') ?>">activate or install the required plugin(s)</a>
and reload the page.
<?php wp_footer(); ?>
</body>
Expand Down

0 comments on commit 975c529

Please sign in to comment.