| Server IP : 104.26.5.103 / Your IP : 216.73.216.4 Web Server : nginx/1.27.1 System : Linux in-5 5.15.0-143-generic #153-Ubuntu SMP Fri Jun 13 19:10:45 UTC 2025 x86_64 User : arabianexpress ( 1872) PHP Version : 8.0.30 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /storage/v9321/leapdubai/public_html/wp-content/plugins/kirki/app/Supports/ |
Upload File : |
<?php
namespace Kirki\App\Supports;
defined('ABSPATH') || exit;
use Kirki\App\Constants\CollectionTypes;
use Kirki\App\Constants\PostTypes;
use Kirki\App\Models\Post as PostModel;
use Kirki\App\Models\User as UserModel;
use function Kirki\App\is_not_empty_array;
use function Kirki\Framework\user;
class CollectionItem
{
/**
* Get items from conditions
*
* @param array $conditions
* @param string $search
* @return array
*/
public static function get_items_from_condition($conditions, $search = '')
{
$data = [];
$type = CollectionTypes::POST;
$post_type = PostTypes::WP_POST;
$role = '*';
if (is_not_empty_array($conditions)) {
if (isset($conditions[0]['type'])) {
$type = $conditions[0]['type'];
if ($type === CollectionTypes::POST) {
$post_type = $conditions[0]['post_type'];
// if the conditions has from key then it is term. then it will be term type.
if (isset($conditions[0]['from']) && $conditions[0]['from'] === CollectionTypes::TERM) {
$type = CollectionTypes::TERM;
}
}
if ($type === CollectionTypes::USER) {
$role = $conditions[0]['to'];
}
} else {
//legacy support
$post_type = $conditions[0]['category'];
}
}
if (user()->has_edit_access()) {
$limit = 20;
switch ($type) {
case CollectionTypes::POST:
$posts = PostModel::query()
->where('post_type', $post_type)
->where_in('post_status', ['publish', 'draft', 'future'])
->search($search)
->order_by('ID', 'DESC')
->limit($limit)
->get(['ID', 'post_title']);
foreach ($posts as $post) {
$data[] = [
'ID' => $post->ID,
'title' => $post->post_title,
];
}
break;
case CollectionTypes::TERM:
$taxonomy = [];
foreach ($conditions as $key => $condition) {
if ($condition['from'] === CollectionTypes::TERM) {
$taxonomy[] = $condition['where'];
}
}
$arg = [
'taxonomy' => $taxonomy,
'number' => $limit,
'orderby' => 'ID',
'order' => 'DESC',
];
if ($search) {
$arg['search'] = $search;
}
$terms = get_terms($arg);
if (!is_wp_error($terms) && is_array($terms)) {
foreach ($terms as $term) {
// Handle both object and array cases safely
$term_id = is_object($term) ? $term->term_id : ($term['term_id'] ?? null);
$term_name = is_object($term) ? $term->name : ($term['name'] ?? null);
$data[] = [
'ID' => $term_id,
'title' => $term_name,
];
}
}
break;
case CollectionTypes::USER:
$role === '*' ? '' : $role;
$users = UserModel::query()
->role($role)
->search($search)
->order_by('ID', 'DESC')
->limit($limit)
->get(['ID', 'display_name']);
foreach ($users as $user) {
$data[] = [
'ID' => $user->ID,
'title' => $user->display_name,
];
}
break;
}
}
return ['data' => $data, 'type' => $type];
}
}