Completed
Push — develop ( d494ed...7721c5 )
by Paul
02:24
created

PostMeta::get()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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