1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LSX functions to make theme Gutenberg compatible |
4
|
|
|
* |
5
|
|
|
* @package lsx |
6
|
|
|
* @subpackage Gutenberg |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Enqueue Admin styles on admin area |
15
|
|
|
*/ |
16
|
|
|
function load_gutenberg_admin_style() { |
17
|
|
|
wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/assets/css/admin/gutenberg-admin.css', false, '1.0.0' ); |
18
|
|
|
} |
19
|
|
|
add_action( 'admin_enqueue_scripts', 'load_gutenberg_admin_style' ); |
20
|
|
|
|
21
|
|
|
// Gutenberg Compatibility. |
22
|
|
|
require get_template_directory() . '/lib/theme-support.php'; |
23
|
|
|
|
24
|
|
|
/** |
|
|
|
|
25
|
|
|
* Add custom class for Gutenberg Compatible template |
26
|
|
|
*/ |
27
|
|
|
function add_gutenberg_compatible_body_class( $classes ) { |
28
|
|
|
// if ( ! is_home() && ! is_front_page() ). |
29
|
|
|
if ( is_page() || is_page_template() || is_single() ) |
30
|
|
|
$classes[] = 'gutenberg-compatible-template'; |
31
|
|
|
|
32
|
|
|
// Add a class if the page is using the Content and Media block. |
33
|
|
|
$post = get_post(); |
34
|
|
|
if ( function_exists( 'has_blocks' ) && isset( $post->post_content ) && has_blocks( $post->post_content ) && ( ! is_search() ) && ( ! is_archive() ) ) { |
35
|
|
|
$blocks = parse_blocks( $post->post_content ); |
36
|
|
|
|
37
|
|
|
if ( 'core/media-text' === $blocks[0]['blockName'] ) { |
38
|
|
|
$classes[] = 'has-block-media-text'; |
39
|
|
|
} |
40
|
|
|
if ( 'core/cover' === $blocks[0]['blockName'] ) { |
41
|
|
|
$classes[] = 'has-block-cover'; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
return $classes; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
add_filter( 'body_class', __NAMESPACE__ . '\add_gutenberg_compatible_body_class' ); |
48
|
|
|
|
49
|
|
|
// Add custom class for templates that are using the Gutenberg editor. |
50
|
|
|
add_action('body_class', function( $classes ) { |
51
|
|
|
if ( function_exists( 'has_blocks' ) && has_blocks( get_the_ID() ) && ( ( is_singular( 'post' ) || is_page() ) ) ) |
52
|
|
|
$classes[] = 'using-gutenberg'; |
53
|
|
|
return $classes; |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Removes the default LSX banner if there is a page that is using blocks. (Only works if LSX banners is not turned on) |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
function remove_lsx_page_banner_when_using_blocks() { |
62
|
|
|
if ( function_exists( 'has_blocks' ) && ( ! class_exists( 'LSX_Banners' ) ) ) { |
63
|
|
|
add_filter( 'lsx_page_banner_disable', '__return_true' ); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
add_filter( 'init', 'remove_lsx_page_banner_when_using_blocks' ); |
67
|
|
|
|