init.php
3.62 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
<?php
/**
* Redirect admin post to FB builder if set.
*
* @since 3.0.0
*
* @param string $location Parameter passed by the 'redirect_post_location' filter.
* @return string $_POST['et-fb-builder-redirect'] if set, $location otherwise.
*/
function et_fb_redirect_post_location( $location ) {
if ( is_admin() && isset( $_POST['et-fb-builder-redirect'] ) ) {
return $_POST['et-fb-builder-redirect'];
}
return $location;
}
add_filter( 'redirect_post_location', 'et_fb_redirect_post_location' );
function et_fb_enabled() {
if ( defined( 'ET_FB_ENABLED' ) ) {
return ET_FB_ENABLED;
}
if ( empty( $_GET['et_fb'] ) ) {
return false;
}
if ( is_customize_preview() ) {
return false;
}
if ( ! is_single() && ! is_page() ) {
return false;
}
if ( ! et_fb_is_user_can_edit() ) {
return false;
}
if ( ! et_pb_is_allowed( 'use_visual_builder' ) ) {
return false;
}
return true;
}
function et_fb_is_user_can_edit() {
if ( is_page() ) {
if ( ! current_user_can( 'edit_pages' ) ) {
return false;
}
if ( ! current_user_can( 'edit_others_pages' ) && ! current_user_can( 'edit_page', get_the_ID() ) ) {
return false;
}
if ( ( ! current_user_can( 'publish_pages' ) || ! current_user_can( 'edit_published_pages' ) ) && 'publish' === get_post_status() ) {
return false;
}
if ( ( ! current_user_can( 'edit_private_pages' ) || ! current_user_can( 'read_private_pages' ) ) && 'private' === get_post_status() ) {
return false;
}
} else {
if ( ! current_user_can( 'edit_posts' ) ) {
return false;
}
if ( ! current_user_can( 'edit_others_posts' ) && ! current_user_can( 'edit_post', get_the_ID() ) ) {
return false;
}
if ( ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_published_posts' ) ) && 'publish' === get_post_status() ) {
return false;
}
if ( ( ! current_user_can( 'edit_private_posts' ) || ! current_user_can( 'read_private_posts' ) ) && 'private' === get_post_status() ) {
return false;
}
}
return true;
}
define( 'ET_FB_ENABLED', et_fb_enabled() );
// Stop here if the front end builder isn't enabled.
if ( ! ET_FB_ENABLED ) {
return;
}
/**
* The VB requires the WP Heartbeat script in order to function. We ensure the heartbeat
* is loaded with the VB by scheduling this callback to run right before scripts
* are output to the footer. {@see 'wp_footer'}
*/
function et_fb_ensure_heartbeat_script() {
// We have to check both 'registered' AND 'enqueued' to cover cases where heartbeat has been
// de-registered because 'enqueued' will return `true` for a de-registered script at this stage.
if ( wp_script_is( 'heartbeat', 'registered' ) && wp_script_is( 'heartbeat', 'enqueued' ) ) {
return;
}
$suffix = SCRIPT_DEBUG ? '' : '.min';
$src = "/wp-includes/js/heartbeat{$suffix}.js";
wp_enqueue_script( 'heartbeat', $src, array( 'jquery' ), false, true );
wp_localize_script( 'heartbeat', 'heartbeatSettings', apply_filters( 'heartbeat_settings', array() ) );
}
add_action( 'wp_footer', 'et_fb_ensure_heartbeat_script', 19 );
define( 'ET_FB_URI', ET_BUILDER_URI . '/frontend-builder' );
define( 'ET_FB_ASSETS_URI', ET_FB_URI . '/assets' );
require_once ET_BUILDER_DIR . 'frontend-builder/view.php';
require_once ET_BUILDER_DIR . 'frontend-builder/assets.php';
require_once ET_BUILDER_DIR . 'frontend-builder/helpers.php';
require_once ET_BUILDER_DIR . 'frontend-builder/rtl.php';
do_action( 'et_fb_framework_loaded' );
if ( 'on' === et_get_option( 'divi_disable_translations', 'off' ) ) {
add_filter( 'locale_stylesheet_uri', 'et_fb_remove_rtl_stylesheet' );
add_filter( 'language_attributes', 'et_fb_remove_html_rtl_dir' );
}
et_fb_fix_plugin_conflicts();