forked from awps/smk-sidebar-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmk-sidebar-generator.php
More file actions
227 lines (177 loc) · 6.65 KB
/
smk-sidebar-generator.php
File metadata and controls
227 lines (177 loc) · 6.65 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/*
* Plugin Name: Sidebar Generator and Manager
* Plugin URI: http://zerowp.com/sidebar-generator-manager
* Description: Generate an unlimited number of sidebars and assign them to any page, using the conditional options, without touching a single line of code.
* Author: ZeroWP Team
* Author URI: http://zerowp.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: smk-sidebar-generator
* Domain Path: /languages
*
* Version: 4.0
*
*/
/* No direct access allowed!
---------------------------------*/
if ( ! defined( 'ABSPATH' ) ) exit;
/* Plugin configuration
----------------------------*/
function ssgm_config( $key = false ){
$settings = apply_filters( 'ssgm:config_args', array(
// Plugin data
'version' => '4.0',
'min_php_version' => '5.3',
// The list of required plugins. 'slug' => array 'name and uri'
'required_plugins' => array(),
// The priority in plugins loaded. Only if has required plugins
'priority' => 10,
// Main action. You may need to change it if is an extension for another plugin.
'action_name' => 'init',
// Plugin branding
'plugin_name' => __( 'Sidebar Generator and Manager', 'smk-sidebar-generator' ),
'id' => 'smk-sidebar-generator',
'namespace' => 'SmkSidebar',
'uppercase_prefix' => 'SMK_SIDEBAR',
'lowercase_prefix' => 'ssgm',
// Access to plugin directory
'file' => __FILE__,
'lang_path' => plugin_dir_path( __FILE__ ) . 'languages',
'basename' => plugin_basename( __FILE__ ),
'path' => plugin_dir_path( __FILE__ ),
'url' => plugin_dir_url( __FILE__ ),
'uri' => plugin_dir_url( __FILE__ ),//Alias
'slug' => 'smk_sidebar_generator',
'capability' => 'manage_options',
'option_name' => 'smk_sidebar_generator',
'settings_register_name' => 'smk_sidebar_generator_register',
// Menu settings
'menu_name' => __('Sidebars', 'smk-sidebar-generator'),
'menu_priority' => 60,
'menu_icon' => 'dashicons-layout',
// Widget settings
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
// Make sure that PHP version is set to 5.3+
if( version_compare( $settings[ 'min_php_version' ], '5.3', '<' ) ){
$settings[ 'min_php_version' ] = '5.3';
}
// Get the value by key
if( !empty($key) ){
if( array_key_exists($key, $settings) ){
return $settings[ $key ];
}
else{
return false;
}
}
// Get settings
else{
return $settings;
}
}
/* Define the current version of this plugin.
-----------------------------------------------------------------------------*/
define( 'SMK_SIDEBAR_VERSION', ssgm_config( 'version' ) );
/* Plugin constants
------------------------*/
define( 'SMK_SIDEBAR_PLUGIN_FILE', ssgm_config( 'file' ) );
define( 'SMK_SIDEBAR_PLUGIN_BASENAME', ssgm_config( 'basename' ) );
define( 'SMK_SIDEBAR_PATH', ssgm_config( 'path' ) );
define( 'SMK_SIDEBAR_URL', ssgm_config( 'url' ) );
define( 'SMK_SIDEBAR_URI', ssgm_config( 'url' ) ); // Alias
/* Minimum PHP version required
------------------------------------*/
define( 'SMK_SIDEBAR_MIN_PHP_VERSION', ssgm_config( 'min_php_version' ) );
/* Plugin Init
----------------------*/
final class SMK_SIDEBAR_Plugin_Init{
public function __construct(){
$required_plugins = ssgm_config( 'required_plugins' );
$missed_plugins = $this->missedPlugins();
/* The installed PHP version is lower than required.
---------------------------------------------------------*/
if ( version_compare( PHP_VERSION, SMK_SIDEBAR_MIN_PHP_VERSION, '<' ) ) {
require_once SMK_SIDEBAR_PATH . 'warnings/php-warning.php';
new SMK_SIDEBAR_PHP_Warning;
}
/* Required plugins are not installed/activated
----------------------------------------------------*/
elseif( !empty( $required_plugins ) && !empty( $missed_plugins ) ){
require_once SMK_SIDEBAR_PATH . 'warnings/noplugin-warning.php';
new SMK_SIDEBAR_NoPlugin_Warning( $missed_plugins );
}
/* We require some plugins and all of them are activated
-------------------------------------------------------------*/
elseif( !empty( $required_plugins ) && empty( $missed_plugins ) ){
add_action(
'plugins_loaded',
array( $this, 'getSource' ),
ssgm_config( 'priority' )
);
}
/* We don't require any plugins. Include the source directly
----------------------------------------------------------------*/
else{
$this->getSource();
}
}
//------------------------------------//--------------------------------------//
/**
* Get plugin source
*
* @return void
*/
public function getSource(){
require_once SMK_SIDEBAR_PATH . 'plugin.php';
$components = glob( SMK_SIDEBAR_PATH .'components/*', GLOB_ONLYDIR );
foreach ($components as $component_path) {
require_once trailingslashit( $component_path ) .'component.php';
}
}
//------------------------------------//--------------------------------------//
/**
* Missed plugins
*
* Get an array of missed plugins
*
* @return array
*/
public function missedPlugins(){
$required = ssgm_config( 'required_plugins' );
$active = $this->activePlugins();
$diff = array_diff_key( $required, $active );
return $diff;
}
//------------------------------------//--------------------------------------//
/**
* Active plugins
*
* Get an array of active plugins
*
* @return array
*/
public function activePlugins(){
$active = get_option('active_plugins');
$slugs = array();
if( !empty($active) ){
$slugs = array_flip( array_map( array( $this, '_filterPlugins' ), (array) $active ) );
}
return $slugs;
}
//------------------------------------//--------------------------------------//
/**
* Filter plugins callback
*
* @return string
*/
protected function _filterPlugins( $value ){
$plugin = explode( '/', $value );
return $plugin[0];
}
}
new SMK_SIDEBAR_Plugin_Init;