-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdivi-5-dev-tool.php
More file actions
132 lines (119 loc) · 4.35 KB
/
divi-5-dev-tool.php
File metadata and controls
132 lines (119 loc) · 4.35 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
<?php
/*
Plugin Name: Divi 5 Dev Tool
Plugin URI: https://github.com/elegantthemes/d5-dev-tool
Description: A Divi 5 extension with various tools for developers.
Version: 0.1.2
Author: Elegant Themes
Author URI: https://elegantthemes.com
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: divi-5-dev-tool
Domain Path: /languages
Divi 5 Dev Tool is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
Divi 5 Dev Tool is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Divi 5 Dev Tool. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
*/
use ET\Builder\Framework\Utility\Conditions;
use ET\Builder\VisualBuilder\Assets\PackageBuildManager;
/**
* Add custom item on admin bar for `Divi 5 Dev Tool`
*
* @since ??
*
* @param WP_Admin_Bar $admin_bar WordPress admin bar object.
*/
function divi_5_dev_tool_admin_bar_link( $admin_bar ) {
// Only display this admin bar item on D5 Visual Builder.
if ( function_exists( 'et_builder_d5_enabled' ) && et_builder_d5_enabled() && et_core_is_fb_enabled() ) {
$d5_dev_tools_id = 'divi-5-dev-tool';
// Main menu.
$admin_bar->add_node(
array(
'id' => $d5_dev_tools_id,
'title' => __( 'Debug Divi 5', 'divi-5-dev-tool' ),
'href' => '#',
)
);
}
}
add_action( 'admin_bar_menu', 'divi_5_dev_tool_admin_bar_link', 700 );
/**
* Enqueue style and scripts of State Monitor modal
*
* @since ??
*/
function divi_5_dev_tool_enqueue_scripts() {
if ( ( function_exists( 'et_builder_d5_enabled' ) && et_builder_d5_enabled() && et_core_is_fb_enabled() ) || ( class_exists( 'ET\Builder\Framework\Utility\Conditions' ) && Conditions::is_tb_admin_screen() ) ) {
$plugin_dir_url = plugin_dir_url( __FILE__ );
PackageBuildManager::register_package_build( [
'name' => 'divi-5-dev-tool-builder-bundle',
'version' => '0.1.2.' . rand(1, 10000000),
'script' => [
'src' => "{$plugin_dir_url}scripts/bundle.js",
'deps' => [
// 'divi-visual-builder',
'divi-data',
'divi-error-boundary',
'divi-modal',
'divi-object-renderer',
],
'args' => true,
'defer' => false,
'async' => false,
'data_app_window' => [],
'data_top_window' => [],
'enqueue_top_window' => false,
'enqueue_app_window' => true,
],
'style' => [
'src' => "{$plugin_dir_url}styles/bundle.css",
'deps' => [],
'args' => [],
'enqueue_top_window' => true,
'enqueue_app_window' => false,
'media' => 'all',
]
] );
}
}
add_action( 'et_fb_framework_loaded', 'divi_5_dev_tool_enqueue_scripts', 20 );
/**
* Enqueue object renderer on top window.
*
* @param array $params Package build parameters.
* @return array Modified parameters.
*/
function divi_5_dev_tool_enqueue_object_renderer_on_top_window( $params ) {
// Enqueue object renderer style on top window. Layout panel needs it.
$params['style']['enqueue_top_window'] = true;
return $params;
}
add_filter( 'divi_visual_builder_package_build_params_divi-object-renderer', 'divi_5_dev_tool_enqueue_object_renderer_on_top_window' );
// Include AJAX handlers for Divi Options management.
require_once plugin_dir_path( __FILE__ ) . 'includes/ajax-handlers.php';
/**
* Enqueue WordPress AJAX nonce for dev tool.
*/
function divi_5_dev_tool_localize_script() {
if ( ( function_exists( 'et_builder_d5_enabled' ) && et_builder_d5_enabled() && et_core_is_fb_enabled() ) || ( class_exists( 'ET\Builder\Framework\Utility\Conditions' ) && Conditions::is_tb_admin_screen() ) ) {
wp_localize_script(
'divi-5-dev-tool-builder-bundle',
'divi5DevToolAjax',
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'divi_5_dev_tool_nonce' ),
'newPostUrl' => admin_url( 'post-new.php' ),
'newPageUrl' => admin_url( 'post-new.php?post_type=page' ),
)
);
}
}
add_action( 'wp_enqueue_scripts', 'divi_5_dev_tool_localize_script', 21 );