Completed
Push — master ( c4606f...2cda3d )
by
unknown
15:54 queued 06:31
created

Post_Ancestor_ID_Condition::is_fulfilled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 10
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 15
rs 9.4285
1
<?php
2
3
namespace Carbon_Fields\Container\Condition;
4
5
/**
6
 * Check if post has a specific ancestor
7
 *
8
 * Operator "CUSTOM" is passed an array of ancestor post ids
9
 */
10
class Post_Ancestor_ID_Condition extends Condition {
11
12
	/**
13
	 * Check if the condition is fulfilled
14
	 *
15
	 * @param  array $environment
16
	 * @return bool
17
	 */
18
	public function is_fulfilled( $environment ) {
19
		$post_id = $environment['post_id'];
20
		$post = $environment['post'];
21
		$ancestors = array();
22
23
		if ( $post ) {
24
			$ancestors = array_map( 'intval', get_ancestors( $post_id, $post->post_type ) );
25
		}
26
27
		return $this->compare(
28
			$ancestors,
29
			$this->get_comparison_operator(),
30
			$this->get_value()
31
		);
32
	}
33
}