Completed
Push — develop ( 079584...9aa6f3 )
by Paul
02:09
created

PostMeta::get()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 5
nop 2
1
<?php
2
3
namespace GeminiLabs\Castor\Helpers;
4
5
class PostMeta
6
{
7
	public function get( $value, array $args = [] )
8
	{
9
		if( empty( $value ))return;
10
11
		$args = $this->normalize( $args );
12
13
		if( substr( $value, 0, 1 ) == '_' && !empty( $args['prefix'] )) {
14
			$args['prefix'] = sprintf( '_%s', rtrim( $args['prefix'], '_' ));
15
		}
16
17
		$metaValue = get_post_meta( $args['ID'], $args['prefix'] . $value, $args['single'] );
18
19
		return empty( $metaValue )
20
			? $args['fallback']
21
			: $metaValue;
22
	}
23
24
	protected function normalize( array $args )
25
	{
26
		$defaults = [
27
			'ID'       => get_the_ID(),
28
			'fallback' => '',
29
			'single'   => true,
30
			'prefix'   => 'pollux_',
31
		];
32
		return shortcode_atts( $defaults, $args );
33
	}
34
}
35