flyntwp /
flynt
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Flynt; |
||
| 4 | |||
| 5 | use Flynt\Api; |
||
| 6 | use Flynt\Defaults; |
||
| 7 | use Flynt\Utils\AdminNoticeManager; |
||
| 8 | use Flynt\Utils\Asset; |
||
| 9 | use Timber\Timber; |
||
| 10 | |||
| 11 | class Init |
||
| 12 | { |
||
| 13 | public static function initTheme() |
||
| 14 | { |
||
| 15 | Api::registerHooks(); |
||
| 16 | Defaults::init(); |
||
| 17 | |||
| 18 | // Set to true to load all assets from a CDN if there is one specified |
||
| 19 | Asset::loadFromCdn(false); |
||
| 20 | |||
| 21 | new Timber(); |
||
| 22 | } |
||
| 23 | |||
| 24 | public static function loadComponents() |
||
| 25 | { |
||
| 26 | $basePath = get_template_directory() . '/Components'; |
||
| 27 | Api::registerComponentsFromPath($basePath); |
||
| 28 | do_action('Flynt/afterRegisterComponents'); |
||
| 29 | } |
||
| 30 | |||
| 31 | public static function checkRequiredPlugins() |
||
| 32 | { |
||
| 33 | $acfActive = class_exists('acf'); |
||
| 34 | |||
| 35 | if (!$acfActive) { |
||
| 36 | self::notifyRequiredPluginIsMissing('<a href="https://www.advancedcustomfields.com/pro/">Advanced Custom Fields PRO</a>'); |
||
| 37 | add_filter('template_include', function () { |
||
| 38 | die( |
||
|
0 ignored issues
–
show
|
|||
| 39 | 'One or more required plugins are not activated! Please <a href="' |
||
| 40 | . esc_url(admin_url('plugins.php')) |
||
| 41 | . '">activate or install the required plugin(s)</a> and reload the page.' |
||
| 42 | ); |
||
| 43 | }); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $acfActive; |
||
| 47 | } |
||
| 48 | |||
| 49 | protected static function notifyRequiredPluginIsMissing($pluginName) |
||
| 50 | { |
||
| 51 | $manager = AdminNoticeManager::getInstance(); |
||
| 52 | |||
| 53 | $pluginUrl = esc_url(admin_url('plugins.php')); |
||
| 54 | $message = ["${pluginName} plugin not activated. Make sure you activate the plugin on the <a href=\"${pluginUrl}\">plugin page</a>."]; |
||
| 55 | $options = [ |
||
| 56 | 'type' => 'error', |
||
| 57 | 'title' => 'Flynt is missing a required plugin', |
||
| 58 | 'dismissible' => false, |
||
| 59 | ]; |
||
| 60 | |||
| 61 | $manager->addNotice($message, $options); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.