init.php
3.77 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
<?php
/**
* Blocks Initializer - For supporting backward compatibility with WordPress / Gutenberg / Stackable v1.
*
* @since 1.15.5
* @package Stackable
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/********************************************************************************************
* Version 1 frontend styles backward compatibility.
********************************************************************************************/
if ( ! function_exists( 'stackable_block_editor_assets_deprecated' ) ) {
/**
* Enqueue block assets for both frontend + backend.
*
* @since 2.0
*/
function stackable_block_editor_assets_deprecated() {
$enqueue_styles_in_frontend = apply_filters( 'stackable_enqueue_styles', ! is_admin() );
if ( stackable_should_load_v1_styles() && $enqueue_styles_in_frontend ) {
wp_enqueue_style(
'ugb-style-css-deprecated',
plugins_url( 'dist/deprecated/frontend_blocks_deprecated.css', STACKABLE_FILE ),
array( 'ugb-style-css' ),
STACKABLE_VERSION
);
}
}
add_action( 'enqueue_block_assets', 'stackable_block_editor_assets_deprecated' );
}
if ( ! function_exists( 'stackable_auto_on_deprecated_styles' ) ) {
/**
* When upgrading from v1 to v2, turn on the loading of deprecated styles.
*
* @since 2.0
*/
function stackable_auto_on_deprecated_styles( $old_version, $new_version ) {
if ( $old_version === '1' && get_option( 'stackable_load_v1_styles' ) === false ) {
update_option( 'stackable_load_v1_styles', '1' );
}
}
add_action( 'stackable_version_upgraded', 'stackable_auto_on_deprecated_styles', 10, 2 );
}
if ( ! function_exists( 'stackable_register_load_v1_styles_option' ) ) {
/**
* Ajax handler for saving the setting for loading V1 styles for backward compatibility.
*
* @since 2.0
*/
function stackable_register_load_v1_styles_option() {
register_setting(
'stackable_load_v1_styles',
'stackable_load_v1_styles',
array(
'type' => 'string',
'description' => __( 'Load version 1 styles for backward compatibility', STACKABLE_I18N ),
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'default' => '',
)
);
}
add_action( 'init', 'stackable_register_load_v1_styles_option' );
}
if ( ! function_exists( 'stackable_should_load_v1_styles' ) ) {
/**
* Should we load v1 styles
*
* @return Boolean
*
* @since 2.0
*/
function stackable_should_load_v1_styles() {
return get_option( 'stackable_load_v1_styles' ) === '1';
}
}
/********************************************************************************************
* END Version 1 frontend styles backward compatibility.
********************************************************************************************/
/********************************************************************************************
* Version 1 & TwentyTwenty frontend styles backward compatibility.
********************************************************************************************/
if ( ! function_exists( 'stackable_twentytwenty_body_class' ) ) {
/**
* Adds a twentytwenty class name to the body if the twentytwenty is used.
*/
function stackable_twentytwenty_body_class( $classes ) {
$classes[] = 'ugb--twentytwentytwenty-compat';
return $classes;
}
function stackable_twentytwenty_compat() {
if ( function_exists( 'twentytwenty_theme_support' ) && stackable_should_load_v1_styles() ) {
add_filter( 'body_class','stackable_twentytwenty_body_class' );
}
}
add_action( 'wp', 'stackable_twentytwenty_compat' );
}
/********************************************************************************************
* END Version 1 & TwentyTwenty frontend styles backward compatibility.
********************************************************************************************/