class-fl-builder-loader.php
6.2 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
<?php
if ( ! class_exists( 'FLBuilderLoader' ) ) {
/**
* Responsible for setting up builder constants, classes and includes.
*
* @since 1.8
*/
final class FLBuilderLoader {
/**
* Load the builder if it's not already loaded, otherwise
* show an admin notice.
*
* @since 1.8
* @return void
*/
static public function init()
{
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$lite_dirname = 'beaver-builder-lite-version';
$lite_active = is_plugin_active( $lite_dirname . '/fl-builder.php' );
$plugin_dirname = basename( dirname( dirname( __FILE__ ) ) );
if ( class_exists( 'FLBuilder' ) || ( $plugin_dirname != $lite_dirname && $lite_active ) ) {
add_action('admin_notices', __CLASS__ . '::double_install_admin_notice');
add_action('network_admin_notices', __CLASS__ . '::double_install_admin_notice');
return;
}
self::define_constants();
self::load_files();
self::check_permissions();
}
/**
* Define builder constants.
*
* @since 1.8
* @return void
*/
static private function define_constants()
{
define('FL_BUILDER_VERSION', '1.9.1');
define('FL_BUILDER_FILE', trailingslashit(dirname(dirname(__FILE__))) . 'fl-builder.php');
define('FL_BUILDER_DIR', plugin_dir_path(FL_BUILDER_FILE));
define('FL_BUILDER_URL', plugins_url('/', FL_BUILDER_FILE));
define('FL_BUILDER_LITE', false);
define('FL_BUILDER_SUPPORT_URL', 'https://www.wpbeaverbuilder.com/support/'); // Deprecated, do not use.
define('FL_BUILDER_UPGRADE_URL', 'https://www.wpbeaverbuilder.com/'); // Deprecated, do not use.
define('FL_BUILDER_STORE_URL', 'https://www.wpbeaverbuilder.com/');
define('FL_BUILDER_DEMO_URL', 'http://demos.wpbeaverbuilder.com');
define('FL_BUILDER_OLD_DEMO_URL', 'http://demos.fastlinemedia.com');
define('FL_BUILDER_DEMO_CACHE_URL', 'http://demos.wpbeaverbuilder.com/wp-content/uploads/bb-plugin/cache/');
}
/**
* Loads classes and includes.
*
* @since 1.8
* @return void
*/
static private function load_files()
{
/* Classes */
require_once FL_BUILDER_DIR . 'classes/class-fl-builder.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-admin.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-admin-posts.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-admin-settings.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-ajax.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-ajax-layout.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-auto-suggest.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-color.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-export.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-extensions.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-fonts.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-icons.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-import.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-loop.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-model.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-module.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-photo.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-services.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-shortcodes.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-update.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-timezones.php';
require_once FL_BUILDER_DIR . 'classes/class-fl-builder-utils.php';
/* WP CLI Commands */
if ( defined( 'WP_CLI' ) ) {
require __DIR__ . '/class-fl-builder-wpcli-command.php';
}
/* Includes */
require_once FL_BUILDER_DIR . 'includes/compatibility.php';
require_once FL_BUILDER_DIR . 'includes/updater/updater.php';
}
/**
* Checks to see if we can write to files and shows
* an admin notice if we can't.
*
* @since 1.8.2
* @access private
* @return void
*/
static private function check_permissions()
{
if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], array( 'fl-builder-settings', 'fl-builder-multisite-settings' ) ) ) {
$wp_upload_dir = wp_upload_dir();
$bb_upload_dir = FLBuilderModel::get_upload_dir();
if ( ! is_writable( $wp_upload_dir['basedir'] ) || ! is_writable( $bb_upload_dir['path'] ) ) {
add_action('admin_notices', __CLASS__ . '::permissions_admin_notice');
add_action('network_admin_notices', __CLASS__ . '::permissions_admin_notice');
}
}
}
/**
* Shows an admin notice if we can't write to files.
*
* @since 1.8.2
* @return void
*/
static public function permissions_admin_notice()
{
$message = __( 'Beaver Builder may not be functioning correctly as it does not have permission to write files to the WordPress uploads directory on your server. Please update the WordPress uploads directory permissions before continuing or contact your host for assistance.', 'fl-builder' );
self::render_admin_notice( $message, 'error' );
}
/**
* Shows an admin notice if another version of the builder
* has already been loaded before this one.
*
* @since 1.8
* @return void
*/
static public function double_install_admin_notice()
{
$message = __( 'You currently have two versions of Beaver Builder active on this site. Please <a href="%s">deactivate one</a> before continuing.', 'fl-builder' );
self::render_admin_notice( sprintf( $message, admin_url( 'plugins.php' ) ), 'error' );
}
/**
* Renders an admin notice.
*
* @since 1.8.2
* @access private
* @param string $message
* @param string $type
* @return void
*/
static private function render_admin_notice( $message, $type = 'update' )
{
if ( ! is_admin() ) {
return;
}
else if ( ! is_user_logged_in() ) {
return;
}
else if ( ! current_user_can( 'update_core' ) ) {
return;
}
echo '<div class="' . $type . '">';
echo '<p>' . $message . '</p>';
echo '</div>';
}
}
}
FLBuilderLoader::init();