Completed
Pull Request — develop (#1588)
by Zack
18:19
created

Entry::render()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
namespace GV\Gutenberg\Blocks\Block;
4
5
// Exit if accessed directly
6
if ( ! defined( 'ABSPATH' ) ) {
7
	exit;
8
}
9
10
class Entry extends Block {
11
	const BLOCK_NAME = 'entry';
12
13
	/**
14
	 * Generate `[gventry]` shortcode
15
	 *
16
	 * @param array $attributes
17
	 *                         array['view_id']     string  The numeric View ID the entry should be displayed from.
18
	 *                         array['id']          string  A numeric ID or slug referencing the entry. Or the last, first entry from the View. The View's sorting and filtering settings will be applied to the entries
19
	 *
20
	 * @return string $output
21
	 */
22
	static function render( $attributes = array() ) {
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...
23
		$accepted_attributes = array(
24
			'id',
25
			'view_id',
26
		);
27
28
		$shortcode_attributes = array();
29
30
		foreach ( $attributes as $attribute => $value ) {
31
			$value = esc_attr( sanitize_text_field( $value ) );
32
33
			if ( in_array( $attribute, $accepted_attributes ) && ! empty( $value ) ) {
34
				$shortcode_attributes[] = "{$attribute}={$value}";
35
			}
36
		}
37
38
		$shortcode = sprintf( '[gventry %s]', implode( ' ', $shortcode_attributes ) );
39
40
		$output = do_shortcode( $shortcode );
41
42
		return $output;
43
	}
44
}
45