GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8970a4...b3ee5f )
by Brad
06:24 queued 03:11
created

FooGallery_Blocks::php_block_init()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
1
<?php
2
/**
3
 * FooGallery Blocks Initializer
4
 *
5
 * Enqueue CSS/JS of all the FooGallery blocks.
6
 *
7
 * @since   1.0.0
8
 * @package CGB
9
 */
10
11
if ( ! class_exists( 'FooGallery_Blocks' ) ) {
12
	class FooGallery_Blocks {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
14
		function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
15
			//Frontend block assets.
16
			add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ) );
17
18
			//Backend editor block assets.
19
			add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
20
21
			add_action( 'init', array( $this, 'php_block_init' ) );
22
		}
23
24
		/**
25
		 * Enqueue Gutenberg block assets for backend editor.
26
		 *
27
		 * `wp-blocks`: includes block type registration and related functions.
28
		 * `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
29
		 * `wp-i18n`: To internationalize the block's text.
30
		 *
31
		 * @since 1.0.0
32
		 */
33
		function enqueue_block_editor_assets() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
35
			if ( !apply_filters( 'foogallery_gutenberg_enabled', true ) ) {
36
				return;
37
			}
38
39
			//enqueue foogallery dependencies
40
			wp_enqueue_script( 'masonry' );
41
			foogallery_enqueue_core_gallery_template_script();
42
			foogallery_enqueue_core_gallery_template_style();
43
44
			$deps = array(
45
				'wp-blocks',
46
				'wp-i18n',
47
				'wp-element',
48
				'foogallery-core',
49
				'wp-components',
50
				'wp-editor',
51
				'underscore'
52
			);
53
54
			$js_url = plugins_url( 'gutenberg/dist/blocks.build.js', dirname( __FILE__ ) );
55
56
			// Scripts.
57
			wp_enqueue_script(
58
				'foogallery-block-js', // Handle.
59
				$js_url, // Block.build.js: We register the block here. Built with Webpack.
60
				$deps, // Dependencies, defined above.
61
				// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time.
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% 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...
62
				true // Enqueue the script in the footer.
63
			);
64
65
			// Styles.
66
			wp_enqueue_style(
67
				'foogallery-block-editor-css', // Handle.
68
				plugins_url( 'gutenberg/dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
69
				array( 'wp-edit-blocks', 'foogallery-core' ) // Dependency to include the CSS after it.
70
				// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time.
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
71
			);
72
73
			$local_data = false;
74
75
			if ( function_exists( 'wp_get_jed_locale_data' ) ) {
76
				$local_data = wp_get_jed_locale_data( 'foogallery' );
77
			} else if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) {
78
				$local_data = gutenberg_get_jed_locale_data( 'foogallery' );
79
			}
80
81
			if ( false !== $local_data ) {
82
83
				/*
84
				 * Pass already loaded translations to our JavaScript.
85
				 *
86
				 * This happens _before_ our JavaScript runs, afterwards it's too late.
87
				 */
88
				wp_add_inline_script(
89
					'foogallery-block-js',
90
					'wp.i18n.setLocaleData( ' . json_encode( $local_data ) . ', "foogallery" );',
91
					'before'
92
				);
93
			}
94
		}
95
96
		/**
97
		 * Enqueue Gutenberg block assets for both frontend + backend.
98
		 *
99
		 * `wp-blocks`: includes block type registration and related functions.
100
		 *
101
		 * @since 1.0.0
102
		 */
103
		function enqueue_block_assets() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
104
			if ( !apply_filters( 'foogallery_gutenberg_enabled', true ) ) {
105
				return;
106
			}
107
108
			// Styles.
109
			wp_enqueue_style(
110
				'foogallery-block-css',
111
				plugins_url( 'gutenberg/dist/blocks.style.build.css', dirname( __FILE__ ) ),
112
				array( 'wp-blocks' )
113
			);
114
		}
115
116
		/**
117
		 * Register our block and shortcode.
118
		 */
119
		function php_block_init() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
120
			if ( !apply_filters( 'foogallery_gutenberg_enabled', true ) ) {
121
				return;
122
			}
123
124
			//get out quickly if no Gutenberg
125
			if ( !function_exists( 'register_block_type' ) ) {
126
				return;
127
			}
128
129
			// Register our block, and explicitly define the attributes we accept.
130
			register_block_type(
131
				'fooplugins/foogallery', array(
132
				'attributes' => array(
133
					'id' => array(
134
						'type' => 'number',
135
						'default' => 0
136
					),
137
				),
138
				'render_callback' => array( $this, 'render_block' ),
139
			));
140
		}
141
142
		function render_block( $attributes ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
143
			$foogallery_id = $attributes['id'];
144
			$args = array(
145
				'id' => $foogallery_id
146
			);
147
			//create new instance of template engine
148
			$engine = new FooGallery_Template_Loader();
149
150
			ob_start();
151
152
			$engine->render_template( $args );
153
154
			$output_string = ob_get_contents();
155
			ob_end_clean();
156
			return !empty($output_string) ? $output_string : null;
157
		}
158
	}
159
}
160