PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Rules / Condition / WordPress / Post.php

Post.php in Depicter — Popup & Slider Builder trunk, at app/src/Rules/Condition/WordPress/Post.php

81 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Rules\Condition\WordPress;
4
5 use Depicter\Rules\Condition\Base as ConditionBase;
6
7 class Post extends ConditionBase {
8
9 /**
10 * @inheritdoc
11 */
12 public $slug = 'WordPress_Post';
13
14 /**
15 * @inheritdoc
16 */
17 public $control = 'remoteMultiSelect';
18
19 /**
20 * @inheritdoc
21 */
22 protected $queryable = true;
23
24 /**
25 * @inheritdoc
26 */
27 protected $belongsTo = 'WordPress';
28
29 /**
30 * Tier of this condition
31 *
32 * @var string
33 */
34 protected $tier = 'free-user';
35
36
37 /**
38 * @inheritdoc
39 */
40 public function getLabel(){
41 return __('A WP Post', 'depicter' );
42 }
43
44 /**
45 * @inheritdoc
46 */
47 public function getQueryResults(){
48 $posts = get_posts([
49 'post_type' => $this->postType,
50 'numberposts' => $this->maxOptionsNumber,
51 'fields' => [ 'ids', 'post_title']
52 ]);
53
54 return array_map( function( $post ){
55 return [
56 'label' => $post->post_title,
57 'value' => $post->ID
58 ];
59 }, $posts );
60 }
61
62 /**
63 * @inheritdoc
64 */
65 public function check( $value = null ){
66 global $post;
67
68 $value = $value ?? $this->value;
69
70 // if it was not a singular WP page
71 if ( is_null( $post ) || ! is_singular() ) {
72 $isMet = false;
73 } else {
74 $isMet = ! empty( $value ) ? in_array( $post->ID, $value ) : is_singular( $this->postType );
75 }
76
77 return $this->selectionMode === 'include' ? $isMet : !$isMet;
78 }
79
80 }
81