Passed
Push — master ( e51c9a...41921a )
by Chris
04:16
created

includes/gutenberg.php (30 issues)

1
<?php
2
/**
3
 * LSX functions to make theme Gutenberg compatible
4
 *
5
 * @package    lsx
6
 * @subpackage Gutenberg
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
10
	exit;
11
}
12
13
/**
14
 * Enqueue Admin styles on admin area
15
 */
16
function load_gutenberg_admin_style() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
17
	wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/assets/css/admin/gutenberg-admin.css', false, '1.0.0' );
18
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 0 found
Loading history...
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
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$classes" missing
Loading history...
25
 * Add custom class for Gutenberg Compatible template
26
 */
27
function add_gutenberg_compatible_body_class( $classes ) {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
28
	// if ( ! is_home() && ! is_front_page() ).
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
	if ( is_page() || is_page_template() || is_single() )
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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() ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
35
		$blocks = parse_blocks( $post->post_content );
36
37
		if ( 'core/media-text' === $blocks[0]['blockName'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
38
			$classes[] = 'has-block-media-text';
39
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
40
		if ( 'core/cover' === $blocks[0]['blockName'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
41
			$classes[] = 'has-block-cover';
42
		}
43
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
44
	return $classes;
45
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
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 ) {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
51
	if ( function_exists( 'has_blocks' ) && has_blocks( get_the_ID() ) && ( ( is_singular( 'post' ) || is_page() ) ) )
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
52
		$classes[] = 'using-gutenberg';
53
	return $classes;
54
});
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
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() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
62
	if ( function_exists( 'has_blocks' ) && ( ! class_exists( 'LSX_Banners' ) ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
63
		add_filter( 'lsx_page_banner_disable', '__return_true' );
64
	}
65
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 0 found
Loading history...
66
add_filter( 'init', 'remove_lsx_page_banner_when_using_blocks' );
67