'all',
'icon' => 'all',
'label' => 'Everything',
],
[
'id' => 'publish',
'icon' => 'show',
'label' => 'Live',
],
[
'id' => 'draft',
'icon' => 'hide',
'label' => 'Hidden',
],
[
'id' => 'trash',
'icon' => 'delete',
'label' => 'Scrapped',
]
];
$permission = ($content === 'news') ? 'update' : $content;
$permission = JVB_CONTENT[$content]['plural']??$content.'s';
$canPublish = current_user_can("publish_{$permission}");
$out = '
';
if (!empty($statusFilters)) {
$out .= '
';
foreach ($statusFilters as $filter) {
$disabled = ($filter['id'] === 'publish' && !$canPublish) ? ' disabled' : '';
$status = esc_attr($filter['id']);
$title = esc_html($filter['label']);
$out .= sprintf(
'
',
$status,
$status,
$disabled,
$status,
jvbIcon($filter['icon']),
$title
);
}
if (!$canPublish) {
$out .= '
Your account needs to be verified before you can publish '.$content.'.
';
}
$out .= '
';
}
$bulkActions = jvbGetBulkActions($content);
if (!empty($bulkActions)) {
$out .= '
',
jvbIcon('x', ['title'=>'Cancel'])
);
}
$out .= '
';
return $out;
}
/**
* Outputs available actions
* mainly used by news.php
* @param string $content
*
* @return array|array[]
*/
function jvbGetBulkActions(string $content):array
{
$permission = ($content === 'news') ? 'update' : $content;
$permission = JVB_CONTENT[$content]['plural']??$content.'s';
$bulkActions = [
'publish' => [
'icon' => 'show',
'label' => 'Show',
'disabled' => true,
],
'edit' => [
'icon' => 'edit',
'label' => 'Edit',
'disabled' => true,
],
'draft' => [
'icon' => 'hide',
'label' => 'Hide',
'disabled' => true,
],
'trash' => [
'icon' => 'delete',
'label' => 'Scrap',
'disabled' => true,
]
];
if (current_user_can("publish_{$permission}")) {
$bulkActions['publish']['disabled'] = false;
}
if (current_user_can("edit_{$permission}")) {
$bulkActions['edit']['disabled'] = false;
$bulkActions['draft']['disabled'] = false;
}
if (current_user_can("delete_{$permission}")) {
$bulkActions['trash']['disabled'] = false;
}
return $bulkActions;
}
/**
* Outputs the date filters for a content type
* @param string $content
*
* @return string
*/
function jvbRenderDateFilter(string $content):string
{
$cache = Cache::for('date_filter')->connect('post', true);
$check = $cache->get($content);
if ($check) {
return $check;
}
$postType = (str_starts_with($content, BASE)) ? $content : BASE. $content;
// Get available months
global $wpdb;
$months = $wpdb->get_results("
SELECT DISTINCT
YEAR(post_date) as year,
MONTH(post_date) as month
FROM $wpdb->posts
WHERE post_type = '{$postType}'
ORDER BY post_date DESC
");
// Quick filters
$out = '
';
// Custom date range
$out .= '';
$cache->set($content, $out);
return $out;
}
/**
* Renders sections based on what was set in the Content Registry
* @param object $handler
* @param int $ID
* @param string $contentType
* @param string $postType
* @param bool $prefix
*
* @return void
*/
function jvbRenderSections(
int $ID,
string $contentType = 'post',
string $postType = '',
bool $prefix = false
):void {
switch ($contentType) {
case 'post':
$settings = JVB_CONTENT;
break;
case 'term':
$settings = JVB_TAXONOMY;
break;
case 'user':
$settings = JVB_USER;
break;
default:
return;
}
$sections = $settings[$postType]['sections']??[];
if (empty($sections)) {
return;
}
echo '';
$nav = '
';
echo $nav;
$fields = jvbGetFields($postType);
$meta = new JVBase\meta\MetaManager($ID, $contentType);
?>