framework.php
6.59 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
<?php
function et_builder_load_global_functions_script() {
wp_enqueue_script( 'et-builder-modules-global-functions-script', ET_BUILDER_URI . '/scripts/frontend-builder-global-functions.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
}
add_action( 'wp_enqueue_scripts', 'et_builder_load_global_functions_script', 7 );
function et_builder_load_modules_styles() {
wp_register_script( 'google-maps-api', esc_url( add_query_arg( array( 'v' => 3, 'sensor' => 'false' ), is_ssl() ? 'https://maps-api-ssl.google.com/maps/api/js' : 'http://maps.google.com/maps/api/js' ) ), array(), ET_BUILDER_VERSION, true );
wp_enqueue_script( 'divi-fitvids', ET_BUILDER_URI . '/scripts/jquery.fitvids.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
wp_enqueue_script( 'waypoints', ET_BUILDER_URI . '/scripts/waypoints.min.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
wp_enqueue_script( 'magnific-popup', ET_BUILDER_URI . '/scripts/jquery.magnific-popup.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
wp_register_script( 'hashchange', ET_BUILDER_URI . '/scripts/jquery.hashchange.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
wp_register_script( 'salvattore', ET_BUILDER_URI . '/scripts/salvattore.min.js', array(), ET_BUILDER_VERSION, true );
wp_register_script( 'easypiechart', ET_BUILDER_URI . '/scripts/jquery.easypiechart.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
// Load main styles CSS file only if the Builder plugin is active
if ( et_is_builder_plugin_active() ) {
wp_enqueue_style( 'et-builder-modules-style', ET_BUILDER_URI . '/styles/frontend-builder-plugin-style.css', array(), ET_BUILDER_VERSION );
}
wp_enqueue_script( 'et-builder-modules-script', ET_BUILDER_URI . '/scripts/frontend-builder-scripts.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
wp_localize_script( 'et-builder-modules-script', 'et_custom', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'images_uri' => get_template_directory_uri() . '/images',
'builder_images_uri' => get_template_directory_uri() . '/includes/builder/images',
'et_load_nonce' => wp_create_nonce( 'et_load_nonce' ),
'subscription_failed' => __( 'Please, check the fields below to make sure you entered the correct information.', 'Divi' ),
'fill' => esc_html__( 'Fill', 'Divi' ),
'field' => esc_html__( 'field', 'Divi' ),
'invalid' => esc_html__( 'Invalid email', 'Divi' ),
'captcha' => esc_html__( 'Captcha', 'Divi' ),
'prev' => esc_html__( 'Prev', 'Divi' ),
'previous' => esc_html__( 'Previous', 'Divi' ),
'next' => esc_html__( 'Next', 'Divi' ),
'is_builder_plugin_used' => et_is_builder_plugin_active(),
) );
/**
* Only load this during builder preview screen session
*/
if ( is_et_pb_preview() ) {
// Set fixed protocol for preview URL to prevent cross origin issue
$preview_scheme = is_ssl() ? 'https' : 'http';
// Get home url, then parse it
$preview_origin_component = parse_url( home_url( '', $preview_scheme ) );
// Rebuild origin URL, strip sub-directory address if there's any (postMessage e.origin doesn't pass sub-directory address)
$preview_origin = "";
// Perform check, prevent unnecessary error
if ( isset( $preview_origin_component['scheme'] ) && isset( $preview_origin_component['host'] ) ) {
$preview_origin = "{$preview_origin_component['scheme']}://{$preview_origin_component['host']}";
// Append port number if different port number is being used
if ( isset( $preview_origin_component['port'] ) ) {
$preview_origin = "{$preview_origin}:{$preview_origin_component['port']}";
}
}
wp_enqueue_style( 'et-builder-preview-style', ET_BUILDER_URI . '/styles/preview.css', array(), ET_BUILDER_VERSION );
wp_enqueue_script( 'et-builder-preview-script', ET_BUILDER_URI . '/scripts/frontend-builder-preview.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
wp_localize_script( 'et-builder-preview-script', 'et_preview_params', array(
'preview_origin' => esc_url( $preview_origin ),
'alert_origin_not_matched' => sprintf(
esc_html__( 'Unauthorized access. Preview cannot be accessed outside %1$s.', 'Divi' ),
esc_url( home_url( '', $preview_scheme ) )
),
) );
}
}
add_action( 'wp_enqueue_scripts', 'et_builder_load_modules_styles', 11 );
/**
* Added specific body classes for builder related situation
* This enables theme to adjust its case independently
* @return array
*/
function et_builder_body_classes( $classes ) {
if ( is_et_pb_preview() ) {
$classes[] = 'et-pb-preview';
}
return $classes;
}
add_filter( 'body_class', 'et_builder_body_classes' );
if ( ! function_exists( 'et_builder_add_main_elements' ) ) :
function et_builder_add_main_elements() {
require ET_BUILDER_DIR . 'main-structure-elements.php';
require ET_BUILDER_DIR . 'main-modules.php';
}
endif;
if ( ! function_exists( 'et_builder_load_framework' ) ) :
function et_builder_load_framework() {
global $pagenow;
$is_admin = is_admin();
$action_hook = $is_admin ? 'wp_loaded' : 'wp';
$required_admin_pages = array( 'edit.php', 'post.php', 'post-new.php', 'admin.php', 'customize.php', 'edit-tags.php', 'admin-ajax.php' ); // list of admin pages where we need to load builder files
$specific_filter_pages = array( 'edit.php', 'admin.php', 'edit-tags.php' ); // list of admin pages where we need more specific filtering
$is_edit_library_page = 'edit.php' === $pagenow && isset( $_GET['post_type'] ) && 'et_pb_layout' === $_GET['post_type'];
$is_role_editor_page = 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'et_divi_role_editor' === $_GET['page'];
$is_import_page = 'admin.php' === $pagenow && isset( $_GET['import'] ) && 'wordpress' === $_GET['import']; // Page Builder files should be loaded on import page as well to register the et_pb_layout post type properly
$is_edit_layout_category_page = 'edit-tags.php' === $pagenow && isset( $_GET['taxonomy'] ) && 'layout_category' === $_GET['taxonomy'];
require ET_BUILDER_DIR . 'functions.php';
// load builder files on front-end and on specific admin pages only.
if ( ! $is_admin || ( $is_admin && in_array( $pagenow, $required_admin_pages ) && ( ! in_array( $pagenow, $specific_filter_pages ) || $is_edit_library_page || $is_role_editor_page || $is_edit_layout_category_page || $is_import_page ) ) ) {
require ET_BUILDER_DIR . 'layouts.php';
require ET_BUILDER_DIR . 'class-et-builder-element.php';
require ET_BUILDER_DIR . 'class-et-global-settings.php';
add_action( $action_hook, 'et_builder_init_global_settings' );
add_action( $action_hook, 'et_builder_add_main_elements' );
}
}
endif;
et_builder_load_framework();