-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathItemsField.php
More file actions
52 lines (40 loc) · 1.32 KB
/
ItemsField.php
File metadata and controls
52 lines (40 loc) · 1.32 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
<?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));
}
$query['connected_query'] = [
'post_status' => ['publish', 'draft'], // Draft only for logged in users?
];
return $query;
}
}