/var/www/hkosl.com/aga/wp-content/plugins/siteorigin-panels/inc/live-editor.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
<?php

/**
 * The live editor class. Only loaded when in live editor mode.
 *
 * Class SiteOrigin_Panels_Live_Editor
 */
class SiteOrigin_Panels_Live_Editor {

    function 
__construct() {
        
add_action'template_redirect', array( $this'xss_headers' ) );
        
add_action'get_post_metadata', array( $this'post_metadata' ), 10);
        
add_action'wp_enqueue_scripts', array( $this'frontend_scripts' ) );

        
// Don't display the admin bar when in live editor mode
        
add_filter'show_admin_bar''__return_false' );
    }

    public static function 
single() {
        static 
$single;
        return empty( 
$single ) ? $single = new self() : $single;
    }

    public function 
xss_headers(){
        global 
$post;
        if(
            ! empty( 
$_POST['live_editor_panels_data'] ) &&
            ! empty( 
$post->ID ) &&
            
current_user_can'edit_post'$post->ID )
        ) {
            
// Disable XSS protection when in the Live Editor
            
header'X-XSS-Protection: 0' );
        }
    }
    
    
    
/**
     * Edit the page builder data when we're viewing the live editor version. This is necessary to ensure updated styles
     * are rendered in the preview.
     *
     * @param $value
     * @param $post_id
     * @param $meta_key
     *
     * @return array
     */
    
function post_metadata$value$post_id$meta_key ) {
        if (
            
$meta_key == 'panels_data' &&
            
current_user_can'edit_post'$post_id ) &&
            ! empty( 
$_POST['live_editor_panels_data'] ) &&
            
$_POST['live_editor_post_ID'] == $post_id
        
) {
            
$value = array( json_decodewp_unslash$_POST['live_editor_panels_data'] ), true ) );
        }
        return 
$value;
    }

    
/**
     * Load the frontend scripts for the live editor
     */
    
function frontend_scripts() {
        
wp_enqueue_script(
            
'live-editor-front',
            
siteorigin_panels_url'js/live-editor/live-editor-front' SITEORIGIN_PANELS_JS_SUFFIX '.js' ),
            array( 
'jquery' ),
            
SITEORIGIN_PANELS_VERSION
        
);

        
wp_enqueue_script(
            
'live-editor-scrollto',
            
siteorigin_panels_url'js/live-editor/jquery.scrollTo' SITEORIGIN_PANELS_JS_SUFFIX '.js' ),
            array( 
'jquery' ),
            
SITEORIGIN_PANELS_VERSION
        
);

        
wp_enqueue_style(
            
'live-editor-front',
            
siteorigin_panels_url'css/live-editor-front' SITEORIGIN_PANELS_CSS_SUFFIX '.css' ),
            array(),
            
SITEORIGIN_PANELS_VERSION
        
);
    }
}