-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusinessx-extensions.php
265 lines (220 loc) · 7.39 KB
/
businessx-extensions.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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/*
Plugin Name: Businessx Extensions
Plugin URI: http://www.acosmin.com/themes/businessx/
Description: Adds front page sections and other extensions to Businessx WordPress theme.
Version: 1.0.6
Author: Acosmin
Author URI: http://www.acosmin.com/
Text Domain: businessx-extensions
Domain Path: /languages
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
if ( ! function_exists( 'add_action' ) ) {
die( 'Nothing to do...' );
}
/* Some constants */
if( ! defined( 'BUSINESSX_EXTS_VERSION' ) ) {
define( 'BUSINESSX_EXTS_VERSION', '1.0.6' ); }
if( ! defined( 'BUSINESSX_EXTS_THEME_NAME' ) ) {
define( 'BUSINESSX_EXTS_THEME_NAME', 'Businessx' ); }
if( ! defined( 'BUSINESSX_EXTS_THEME_URL' ) ) {
define( 'BUSINESSX_EXTS_THEME_URL', '//www.acosmin.com/theme/businessx/' ); }
if( ! defined( 'USINESSX_EXTS_THEME_DOCS' ) ) {
define( 'BUSINESSX_EXTS_THEME_DOCS', '//www.acosmin.com/documentation/businessx/' ); }
if( ! defined( 'BUSINESSX_EXTS_URL' ) ) {
define( 'BUSINESSX_EXTS_URL', plugin_dir_url( __FILE__ ) ); }
if( ! defined( 'BUSINESSX_EXTS_PATH' ) ) {
define( 'BUSINESSX_EXTS_PATH', plugin_dir_path( __FILE__ ) ); }
/* Theme names */
if( ! function_exists( 'businessx_extensions_theme' ) ) {
/**
* Get current theme name
*
* @since 1.0.0
* @param boolean $parent Return child name if false
* @return string Current theme name
*/
function businessx_extensions_theme( $parent = false ) {
$theme = wp_get_theme();
if( ! $parent ) {
return $theme->name;
} else {
return $theme->parent_theme;
}
}
}
/* Load text domain */
if( ! function_exists( 'businessx_extensions_textdomain' ) ) {
/**
* Load text domain
*
* @since 1.0.0
* @return void
*/
function businessx_extensions_textdomain() {
load_plugin_textdomain( 'businessx-extensions', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
}
add_action( 'plugins_loaded', 'businessx_extensions_textdomain' );
/* Add front page sections */
if( ! function_exists( 'businessx_extensions_sections' ) ) {
/**
* A list of all the default & supported sections
*
* Use the `businessx_extensions_sections___filter` to add yours
*
* @since 1.0.0
* @return array An array with unique, non duplicate sections names
*/
function businessx_extensions_sections() {
$sections = apply_filters( 'businessx_extensions_sections___filter', array(
'slider',
'features',
'about',
'team',
'clients',
'portfolio',
'actions',
'testimonials',
'pricing',
'faq',
'hero',
'blog',
'contact',
'maps'
) );
return array_map( 'sanitize_key', array_unique( $sections ) );
}
}
if( ! function_exists( 'businessx_extensions_sections_items' ) ) {
/**
* Returns an array with names of sections
* that can add items
*
* @since 1.0.4.3
* @return array
*/
function businessx_extensions_sections_items() {
$sections = apply_filters( 'businessx_extensions_sections_items___filter', array(
'slider',
'features',
'about',
'team',
'clients',
'actions',
'testimonials',
'pricing',
'faq',
) );
return array_map( 'sanitize_key', array_unique( $sections ) );
}
}
if( ! function_exists( 'businessx_extensions_add_sections' ) ) {
/**
* Adds the sections saved in your theme mod
*
* The theme will not handle this part anymore, it's deprecated in
* functions.php:L115-126
*
* @todo Do some checks on `$positions` in case it's not JSON.
* @since 1.0.6
* @return void
*/
function businessx_extensions_add_sections() {
$mod = 'businessx_sections_position';
$sections = businessx_extensions_sections();
$positions = get_theme_mod( $mod );
/*
* Checks if no sections are saved in a theme_mod and if we
* have at least one default sections
*/
if( empty( $positions ) && ! empty( $sections ) ) {
$new = array();
/* Use the prefix for backwards compatibility */
foreach( $sections as $key => $value ) {
$new[] = 'businessx_section__' . sanitize_key( $value );
}
/* Add the default sections if it's the first time. */
set_theme_mod( $mod, json_encode( $new ) );
}
if( is_array( $positions ) ) {
/* Pre version 1.0.6, convert them to JSON. */
set_theme_mod( $mod, json_encode( $positions ) );
}
}
}
add_action( 'after_setup_theme', 'businessx_extensions_add_sections', 15 );
if( ! function_exists( 'businessx_extensions_add_new_sections' ) ) {
/**
* Checks if new sections are added and adds them
* to the end of `businessx_sections_position`
*
* @since 1.0.4.3
* @return array
*/
function businessx_extensions_add_new_sections() {
$prefix = 'businessx_section__';
$sections = $new_sections = array();
$defaults = businessx_extensions_sections();
$saved = get_theme_mod( 'businessx_sections_position' );
/* Return if no theme mods are saved */
if( $saved === false ) return;
/* Check if it's an array, pre v1.0.6 */
if( ! is_array( $saved ) ) {
$saved = json_decode( $saved );
}
/**
* Create an array of all the sections and prefix
* them with `businessx_section__`
*/
foreach ( $defaults as $section ) {
$sections[] = $prefix . $section;
}
/**
* Check if any new sections were added
* @var array
*/
$diff = array_diff( $sections, $saved );
/* If not, do nothing */
if( empty( $diff ) ) return;
/* Add all the new sections at the end of the array */
foreach( $diff as $new_section ) {
array_push( $saved, $new_section );
}
/* JSON encode the new array and set the theme mod with the new values */
$saved = wp_json_encode( array_map( 'sanitize_key', array_unique( $saved ) ) );
/* Update the theme mod with the new sections and positions */
set_theme_mod( 'businessx_sections_position', $saved );
}
}
add_action( 'plugins_loaded', 'businessx_extensions_add_new_sections' );
/**
* Needed functions
* ----------------
* Sanitization functions are included in the theme. (../acosmin/function/sanitization.php)
* Icons function are included in the theme. (../acosmin/function/icons.php)
* Some other used functions (../acosmin/function/helpers.php)
*/
/* No requirements */
require_once ( dirname( __FILE__ ) . '/inc/sidebars/register.php' );
require_once ( dirname( __FILE__ ) . '/inc/functions/helpers.php' );
require_once ( dirname( __FILE__ ) . '/inc/functions/backup-functions.php' );
require_once ( dirname( __FILE__ ) . '/inc/customizer/sections-widgets/init.php' );
/* Required Businessx or a child theme of it to be the current theme */
if ( ( 'Businessx' == businessx_extensions_theme() ) || ( 'Businessx' == businessx_extensions_theme( true ) ) ) {
require_once ( dirname( __FILE__ ) . '/inc/compatibility/polylang.php' );
require_once ( dirname( __FILE__ ) . '/inc/functions/shortcodes.php' );
require_once ( dirname( __FILE__ ) . '/inc/templating.php' );
require_once ( dirname( __FILE__ ) . '/inc/scripts/scripts.php' );
require_once ( dirname( __FILE__ ) . '/inc/icons/icons.php' );
require_once ( dirname( __FILE__ ) . '/inc/customizer/customizer.php' );
require_once ( dirname( __FILE__ ) . '/inc/customizer/setup/front-page.php' );
require_once ( dirname( __FILE__ ) . '/inc/customizer/sections-widgets/styles.php' );
require_once ( dirname( __FILE__ ) . '/inc/partials/partials.php' );
require_once ( dirname( __FILE__ ) . '/inc/partials/hooks.php' );
require_once ( dirname( __FILE__ ) . '/inc/partials/items-hooks.php' );
} else {
add_action( 'admin_enqueue_scripts', 'businessx_extensions_enqueue_backup' );
}