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

View_Details::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 View_Details extends Block {
11
	const BLOCK_NAME = 'view-details';
12
13
	/**
14
	 * Generate `[gravityview]` shortcode
15
	 *
16
	 * @param array $attributes
17
	 *                         array['id']     string  The ID of the View you want to display
18
	 *                         array['detail'] string  Display specific information about a View. Valid values are total_entries, first_entry, last_entry, page_size
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
			'detail',
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( '[gravityview %s]', implode( ' ', $shortcode_attributes ) );
39
40
		$output = do_shortcode( $shortcode );
41
42
		return $output;
43
	}
44
}
45