divi-booster.php
7.38 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
228
229
230
231
232
233
234
235
236
237
238
<?php
/*
Plugin Name: Divi Booster
Plugin URI:
Description: Bug fixes and enhancements for Elegant Themes' Divi Theme.
Author: Dan Mossop
Version: 2.4.0
Author URI: https://divibooster.com
*/
// === Configuration === //
$slug = 'wtfdivi';
define('BOOSTER_SLUG', 'divi-booster');
define('BOOSTER_SLUG_OLD', $slug);
define('BOOSTER_VERSION', '2.4.0');
define('BOOSTER_VERSION_OPTION', 'divibooster_version');
define('BOOSTER_SETTINGS_PAGE_SLUG', BOOSTER_SLUG_OLD.'_settings');
define('BOOSTER_NAME', __('Divi Booster', BOOSTER_SLUG));
// Updates
define('BOOSTER_PACKAGE_NAME', 'divi-booster');
define('BOOSTER_PACKAGE_URL', 'https://dansupdates.com/?action=get_metadata&slug='.BOOSTER_PACKAGE_NAME);
// Error Handling
define('BOOSTER_OPTION_LAST_ERROR', 'wtfdivi_last_error');
define('BOOSTER_OPTION_LAST_ERROR_DESC', 'wtfdivi_last_error_details');
// Directories
define('BOOSTER_DIR_FIXES', dirname(__FILE__).'/core/fixes/');
// === Setup ===
include(dirname(__FILE__).'/core/index.php'); // Load the plugin framework
booster_enable_updates(__FILE__); // Enable auto-updates for this plugin
// === Divi-Specific functions ===
// Returns true if this is the Divi Theme
function divibooster_is_divi() {
// Check template name
$template = get_template();
if (strpos($template, 'Divi')!==false) { return true; }
// Check theme name
$theme = wp_get_theme($template);
if (strpos(@$theme->Name, 'Divi')!==false) { return true; }
// Doesn't seem to be Divi Theme
return false;
}
// Returns true if theme is Divi 2.4 or higher
function is_divi24() {
$template = get_template();
$theme = wp_get_theme($template);
return (divibooster_is_divi() and version_compare($theme->Version, '2.3.9', '>='));
}
// Returns true if this is the Divi Theme
function divibooster_is_extra() {
// Check template name
$template = get_template();
if (strpos($template, 'Extra')!==false) { return true; }
// Check theme name
$theme = wp_get_theme($template);
if (strpos(@$theme->Name, 'Extra')!==false) { return true; }
// Doesn't seem to be Extra Theme
return false;
}
// === Build the plugin ===
$theme = wp_get_theme(get_template());
//print_r(divibooster_is_divi()?'yes':'no');
$sections = array(
'general'=>'Site-wide Settings',
'general-icons'=>'Icons',
'general-layout'=>'Layout',
'general-links'=>'Links',
'general-speed'=>'Site Speed',
/*'general-social'=>'Social Media',*/
'header'=>'Header',
'header-top'=>'Top Header',
'header-main'=>'Main Header',
'header-mobile'=>'Mobile Header',
'posts'=>'Posts',
'pages'=>'Pages',
'sidebar'=>'Sidebar',
'footer'=>'Footer',
'pagebuilder'=>'Divi Builder',
'pagebuilder-divi'=>'Standard Builder',
'pagebuilder-visual'=>'Visual Builder',
'modules'=>'Modules',
'modules-accordion'=>'Accordion',
'modules-blurb'=>'Blurb',
'modules-countdown'=>'Countdown',
'modules-gallery'=>'Gallery',
'modules-headerfullwidth'=>'Header (Full Width)',
'modules-map'=>'Map',
'modules-portfolio'=>'Portfolio',
'modules-portfoliofiltered'=>'Portfolio (Filterable)',
'modules-portfoliofullwidth'=>'Portfolio (Full Width)',
'modules-postnav'=>'Post Navigation',
'modules-postslider'=>'Post Slider',
'modules-pricing'=>'Pricing Table',
/*'modules-shop'=>'Shop',*/
'modules-subscribe'=>'Signup',
'modules-slider'=>'Slider',
'modules-text'=>'Text',
'plugins'=>'Plugins',
'plugins-woocommerce'=>'WooCommerce',
'plugins-other'=>'Other',
'customcss'=>'CSS Manager',
'developer'=>'Developer Tools',
'developer-export'=>'Import / Export',
'developer-css'=>'Generated CSS',
'developer-js'=>'Generated JS',
'developer-footer-html'=>'Generated Footer HTML',
'developer-htaccess'=>'Generated .htaccess Rules',
'deprecated'=>'Deprecated (now available in Divi)',
'deprecated-divi24'=>'Divi 2.4',
'deprecated-divi23'=>'Pre Divi 2.4'
);
// JavaScript dependencies
function divibooster_add_dependencies($dependencies) {
// Add divi custom.js as a dependency to ensure it loads first
if (wp_script_is('divi-custom-script', 'enqueued')) {
$dependencies[] = 'divi-custom-script';
} elseif (wp_script_is('divi-custom-script-child', 'enqueued')) { // Munder Difflin pre 2.0
$dependencies[] = 'divi-custom-script-child';
}
return $dependencies;
}
add_filter("$slug-js-dependencies", 'divibooster_add_dependencies');
// === Load the customizer class ===
include(dirname(__FILE__).'/core/customizer/customizer_1_0.class.php'); // Load the customizer library
$divibooster_customizer = new booster_customizer_1_0($slug);
// === Main plugin ===
$wtfdivi = new wtfplugin_1_0(
array(
'theme'=>$theme,
'plugin'=>array(
'name'=>BOOSTER_NAME,
'shortname'=>BOOSTER_NAME, // menu name
'slug'=>$slug,
'package_slug'=>BOOSTER_PACKAGE_NAME,
'plugin_file'=>__FILE__,
'url'=>'https://divibooster.com/themes/divi/',
'basename'=>plugin_basename(__FILE__),
'admin_menu'=>(is_divi24() or !divibooster_is_divi())?'et_divi_options':'themes.php'
),
'sections'=>$sections
)
);
// === Load the settings ===
function divibooster_load_settings($wtfdivi) {
$settings_files = glob(BOOSTER_DIR_FIXES.'*/settings.php');
if ($settings_files) {
foreach($settings_files as $file) { include($file); }
}
}
add_action("$slug-before-settings-page", 'divibooster_load_settings');
// === Add settings page hook ===
function divibooster_settings_page_init() {
global $pagenow, $plugin_page;
if ($pagenow == 'admin.php' and $plugin_page == BOOSTER_SETTINGS_PAGE_SLUG) {
do_action('divibooster_settings_page_init');
}
}
add_action('admin_init', 'divibooster_settings_page_init');
// === Add update hook ===
function booster_update_check() {
global $wtfdivi;
$old = get_option(BOOSTER_VERSION_OPTION);
$new = BOOSTER_VERSION;
if ($old!=$new) {
do_action('booster_update', $wtfdivi, $old, $new);
update_option(BOOSTER_VERSION_OPTION, $new);
} // updated, so run hooked fns
}
add_action('plugins_loaded', 'booster_update_check');
// === DB074: Update for version 1.9.4 - Add 0.7 opacity to old colors ===
function db074_add_alpha($plugin, $old, $new) {
if (version_compare($old, '1.9.4', '<')) {
// set alpha value to 0.7 - default for divi
$fulloption = get_option('wtfdivi');
$col = $fulloption['fixes']['074-set-header-menu-hover-color']['col'];
// convert from hex to rgba
if (preg_match("/^#?([0-9a-f]{3,6})$/", $col, $matches)) {
$hex = $matches[1];
list($r,$g,$b) = str_split($hex,(strlen($hex)==6)?2:1);
$r=hexdec($r); $g=hexdec($g); $b=hexdec($b);
// Update the option with the rgba form of the color
$fulloption['fixes']['074-set-header-menu-hover-color']['col'] = "rgba($r,$g,$b,0.7)";
update_option('wtfdivi', $fulloption);
}
}
}
add_action('booster_update', 'db074_add_alpha', 10, 3);
// Load media library
function db_enqueue_media_loader() { wp_enqueue_media(); }
add_action('admin_enqueue_scripts', 'db_enqueue_media_loader', 11); // Priority > 10 to avoid visualizer plugin conflict
// =========================================================== //
// == FOOTER == //
// =========================================================== //
// === Footer ===
function divibooster_footer() { ?>
<p>Spot a problem with this plugin? Want to make another change to the Divi Theme? <a href="https://divibooster.com/contact-form/">Let me know</a>.</p>
<p><i>This plugin is an independent product which is not associated with, endorsed by, or supported by Elegant Themes.</i></p>
<?php
}
add_action($wtfdivi->slug.'-plugin-footer', 'divibooster_footer');