This repository has been archived by the owner on Oct 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
themosis-juicer.php
144 lines (123 loc) · 3.92 KB
/
themosis-juicer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* Plugin Name: Themosis Juicer
* Plugin URI: https://keltiecochrane.com
* Description: A Themosis WordPress plugin that provides a wrapper for the Juicer.io API.
* Version: 1.0.0
* Author: Daniel Gadd @ Keltie Cochrane Ltd.
* Author URI: https://keltiecochrane.com
* Text Domain: themosis-juicer.
* Domain Path: /languages
*/
/**
* Use statements. Add any useful class import
* below.
*/
use Composer\Autoload\ClassLoader;
/*
* Default constants.
*/
defined('DS') ? DS : define('DS', DIRECTORY_SEPARATOR);
/*
* Always define the following constant to help you handle
* your plugin text domain. Make sure to define the same value as
* the one defined in the plugin header comments text domain.
*
* Please update (search and replace) all constants calls found in this file.
*
* TODO: #1
* TODO: #2 - Update plugin textdomain first argument below.
*/
defined('COM_KELTIECOCHRANE_JUICER_TD') ? COM_KELTIECOCHRANE_JUICER_TD : define('COM_KELTIECOCHRANE_JUICER_TD', 'themosis-juicer');
/*
* Plugin variables.
* Configure your plugin.
*
* TODO: #3 - Define your own values.
* TODO: #4 - Update the config files names located into the `resources/config` folder.
* TODO: #5 - Update class namespaces.
*/
$vars = [
'slug' => 'themosis-juicer',
'name' => 'Themosis Juicer',
'namespace' => 'com.keltiecochrane.juicer',
'config' => 'com_keltiecochrane_juicer',
];
/*
* Verify that the main framework is loaded.
*/
add_action('admin_notices', function () use ($vars) {
if (!class_exists('\Themosis\Foundation\Application')) {
printf('<div class="notice notice-error"><p>%s</p></div>', __('This plugin requires the Themosis framework in order to work.', COM_KELTIECOCHRANE_JUICER_TD));
}
/*
* Define your plugin theme support key. Once defined, make sure to add the key
* into your theme `supports.config.php` in order to remove this admin notice.
*/
if (!current_theme_supports($vars['slug']) && current_user_can('switch_themes')) {
printf('<div class="notice notice-warning"><p>%s<strong>%s</strong></p></div>', __('Your application do not handle the following plugin: ', COM_KELTIECOCHRANE_JUICER_TD), $vars['name']);
}
});
/*
* Setup the plugin paths.
*/
$paths['plugin.'.$vars['namespace']] = __DIR__.DS;
$paths['plugin.'.$vars['namespace'].'.resources'] = __DIR__.DS.'resources'.DS;
$paths['plugin.'.$vars['namespace'].'.admin'] = __DIR__.DS.'resources'.DS.'admin'.DS;
themosis_set_paths($paths);
/*
* Setup plugin config files.
*/
container('config.finder')->addPaths([
themosis_path('plugin.'.$vars['namespace'].'.resources').'config'.DS,
]);
/*
* Autoloading.
*/
$loader = new ClassLoader();
$classes = container('config.factory')->get($vars['config'].'_loading');
foreach ($classes as $prefix => $path) {
$loader->addPsr4($prefix, $path);
}
$loader->register();
/*
* Register plugin public assets folder [dist directory].
*/
container('asset.finder')->addPaths([
plugins_url('dist', __FILE__) => themosis_path('plugin.'.$vars['namespace']).'dist',
]);
/*
* Register plugin views.
*/
container('view.finder')->addLocation(themosis_path('plugin.'.$vars['namespace'].'.resources').'views');
/*
* Service providers.
*/
$providers = container('config.factory')->get($vars['config'].'_providers');
foreach ($providers as $provider) {
container()->register($provider);
}
/*
* Admin files autoloading.
* I18n.
*/
container('action')->add('plugins_loaded', function () use ($vars) {
/**
* I18n
* Todo: #2 - Replace constant below.
*/
load_plugin_textdomain(COM_KELTIECOCHRANE_JUICER_TD, false, trailingslashit(dirname(plugin_basename(__FILE__))).'languages');
/*
* Plugin admin files.
* Autoload files in alphabetical order.
*/
$loader = container('loader')->add([
themosis_path('plugin.'.$vars['namespace'].'.admin'),
]);
$loader->load();
});
/*
* Add extra features below.
*/
// Alias the facade
class_alias(Com\KeltieCochrane\Juicer\Facades\Juicer::class, 'Juicer');