/var/www/html/wp-content/plugins/elementor/core/debug/inspector.php


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
<?php
namespace Elementor\Core\Debug;

use 
Elementor\Settings;
use 
Elementor\Tools;

if ( ! 
defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly
}

class 
Inspector {

    protected 
$is_enabled false;

    protected 
$log = [];

    
/**
     * @since 2.1.2
     * @access public
     */
    
public function __construct() {
        
$is_debug = ( defined'WP_DEBUG' ) && WP_DEBUG );
        
$option get_option'elementor_enable_inspector'null );

        
$this->is_enabled is_null$option ) ? $is_debug 'enable' === $option;

        if ( 
$this->is_enabled ) {
            
add_action'admin_bar_menu', [ $this'add_menu_in_admin_bar' ], 201 );
        }

        
add_action'elementor/admin/after_create_settings/' Tools::PAGE_ID, [ $this'register_admin_tools_fields' ], 50 );
    }

    
/**
     * @since 2.1.3
     * @access public
     */
    
public function is_enabled() {
        return 
$this->is_enabled;
    }

    
/**
     * @since 2.1.3
     * @access public
     */
    
public function register_admin_tools_fieldsTools $tools ) {
        
$tools->add_fieldsSettings::TAB_GENERAL'tools', [
            
'enable_inspector' => [
                
'label' => esc_html__'Debug Bar''elementor' ),
                
'field_args' => [
                    
'type' => 'select',
                    
'std' => $this->is_enabled 'enable' '',
                    
'options' => [
                        
'' => esc_html__'Disable''elementor' ),
                        
'enable' => esc_html__'Enable''elementor' ),
                    ],
                    
'desc' => esc_html__'Debug Bar adds an admin bar menu that lists all the templates that are used on a page that is being displayed.''elementor' ),
                ],
            ],
        ] );
    }

    
/**
     * @since 2.1.2
     * @access public
     */
    
public function parse_template_path$template ) {
        
// `untrailingslashit` for windows path style.
        
if ( === strpos$templateuntrailingslashitELEMENTOR_PATH ) ) ) {
            return 
'Elementor - ' basename$template );
        }

        if ( 
=== strpos$templateget_stylesheet_directory() ) ) {
            return 
wp_get_theme()->get'Name' ) . ' - ' basename$template );
        }

        
$plugins_dir dirnameELEMENTOR_PATH );
        if ( 
=== strpos$template$plugins_dir ) ) {
            return 
ltrimstr_replace$plugins_dir''$template ), '/\\' );
        }

        return 
str_replaceWP_CONTENT_DIR''$template );
    }

    
/**
     * @since 2.1.2
     * @access public
     */
    
public function add_log$module$title$url '' ) {
        if ( ! 
$this->is_enabled ) {
            return;
        }

        if ( ! isset( 
$this->log$module ] ) ) {
            
$this->log$module ] = [];
        }

        
$this->log$module ][] = [
            
'title' => $title,
            
'url' => $url,
        ];
    }

    
/**
     * @since 2.1.2
     * @access public
     */
    
public function add_menu_in_admin_bar\WP_Admin_Bar $wp_admin_bar ) {
        if ( empty( 
$this->log ) ) {
            return;
        }

        
$wp_admin_bar->add_node( [
            
'id' => 'elementor_inspector',
            
'title' => esc_html__'Elementor Debugger''elementor' ),
        ] );

        foreach ( 
$this->log as $module => $log ) {
            
$module_id sanitize_key$module );

            
$wp_admin_bar->add_menu( [
                
'id' => 'elementor_inspector_' $module_id,
                
'parent' => 'elementor_inspector',
                
'title' => $module,
            ] );

            foreach ( 
$log as $index => $row ) {
                
$url $row['url'];

                unset( 
$row['url'] );

                
$wp_admin_bar->add_menu( [
                    
'id' => 'elementor_inspector_log_' $module_id '_' $index,
                    
'parent' => 'elementor_inspector_' $module_id,
                    
'href' => $url,
                    
'title' => implode' > '$row ),
                    
'meta' => [
                        
'target' => '_blank',
                    ],
                ] );
            }
        }
    }
}