-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathItemsField.php
More file actions
56 lines (43 loc) · 1.38 KB
/
ItemsField.php
File metadata and controls
56 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Adds connected fields to item in API.
*/
namespace OWC\PDC\Base\RestAPI\SharedFields;
use OWC\PDC\Base\RestAPI\ItemFields\ConnectedField;
use OWC\PDC\Base\Support\Traits\CheckPluginActive;
use OWC\PDC\Base\Support\Traits\QueryHelpers;
use WP_Post;
/**
* Adds connected fields to item in API.
*/
class ItemsField extends ConnectedField
{
use CheckPluginActive;
use QueryHelpers;
/**
* Creates an array of connected posts.
*/
public function create(WP_Post $post): array
{
$connectionType = 'pdc-item_to_' . $post->post_type;
return $this->getConnectedItems($post->ID, $connectionType, $this->extraQueryArgs($connectionType));
}
protected function extraQueryArgs(string $type): array
{
$query = [];
$query = array_merge_recursive($query, $this->excludeInactiveItemsQuery());
if ($this->isPluginPDCInternalProductsActive()) {
$query = array_merge_recursive($query, $this->excludeInternalItemsQuery());
}
if ($this->shouldFilterSource()) {
$query = array_merge_recursive($query, $this->filterShowOnTaxonomyQuery($this->source));
}
$postStatus = \is_user_logged_in()
? ['publish', 'draft']
: ['publish'];
$query['connected_query'] = [
'post_status' => $postStatus,
];
return $query;
}
}