File "acf-wp-functions.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-wp-functions.php
File
size: 4.83 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
function acf_get_object_type($object_type, $object_subtype = '')
{
$props = array('type' => $object_type, 'subtype' => $object_subtype, 'name' => '', 'label' => '', 'icon' => '');
if ($object_subtype) {
$props['name'] = "{$object_type}/{$object_subtype}";
} else {
$props['name'] = $object_type;
}
switch ($object_type) {
case 'post':
if ($object_subtype) {
$post_type = get_post_type_object($object_subtype);
if ($post_type) {
$props['label'] = $post_type->labels->name;
$props['icon'] = acf_with_default($post_type->menu_icon, 'dashicons-admin-post');
} else {
return false;
}
} else {
$props['label'] = __('Posts', 'acf');
$props['icon'] = 'dashicons-admin-post';
}
break;
case 'term':
if ($object_subtype) {
$taxonomy = get_taxonomy($object_subtype);
if ($taxonomy) {
$props['label'] = $taxonomy->labels->name;
} else {
return false;
}
} else {
$props['label'] = __('Taxonomies', 'acf');
}
$props['icon'] = 'dashicons-tag';
break;
case 'attachment':
$props['label'] = __('Attachments', 'acf');
$props['icon'] = 'dashicons-admin-media';
break;
case 'comment':
$props['label'] = __('Comments', 'acf');
$props['icon'] = 'dashicons-admin-comments';
break;
case 'widget':
$props['label'] = __('Widgets', 'acf');
$props['icon'] = 'dashicons-screenoptions';
break;
case 'menu':
$props['label'] = __('Menus', 'acf');
$props['icon'] = 'dashicons-admin-appearance';
break;
case 'menu_item':
$props['label'] = __('Menu items', 'acf');
$props['icon'] = 'dashicons-admin-appearance';
break;
case 'user':
$props['label'] = __('Users', 'acf');
$props['icon'] = 'dashicons-admin-users';
break;
case 'option':
$props['label'] = __('Options', 'acf');
$props['icon'] = 'dashicons-admin-generic';
break;
case 'block':
$props['label'] = __('Blocks', 'acf');
$props['icon'] = acf_version_compare('wp', '>=', '5.5') ? 'dashicons-block-default' : 'dashicons-layout';
break;
default:
return false;
}
$object = (object) $props;
return apply_filters('acf/get_object_type', $object, $object_type, $object_subtype);
}
function acf_decode_post_id($post_id = 0)
{
$type = '';
$id = 0;
if (is_numeric($post_id)) {
$type = 'post';
$id = $post_id;
} elseif (is_string($post_id)) {
$i = strrpos($post_id, '_');
if ($i > 0) {
$type = substr($post_id, 0, $i);
$id = substr($post_id, $i + 1);
} else {
$type = $post_id;
$id = '';
}
} else {
return compact('type', 'id');
}
$format = $type . '_' . (is_numeric($id) ? '%d' : '%s');
switch ($format) {
case 'post_%d':
$type = 'post';
$id = absint($id);
break;
case 'term_%d':
$type = 'term';
$id = absint($id);
break;
case 'attachment_%d':
$type = 'post';
$id = absint($id);
break;
case 'comment_%d':
$type = 'comment';
$id = absint($id);
break;
case 'widget_%s':
case 'widget_%d':
$type = 'option';
$id = $post_id;
break;
case 'menu_%d':
$type = 'term';
$id = absint($id);
break;
case 'menu_item_%d':
$type = 'post';
$id = absint($id);
break;
case 'user_%d':
$type = 'user';
$id = absint($id);
break;
case 'block_%s':
$type = 'block';
$id = $post_id;
break;
case 'option_%s':
$type = 'option';
$id = $post_id;
break;
case 'blog_%d':
case 'site_%d':
$type = taxonomy_exists($type) ? 'term' : 'blog';
$id = absint($id);
break;
default:
if (taxonomy_exists($type) && is_numeric($id)) {
$type = 'term';
$id = absint($id);
break;
}
$type = 'option';
$id = $post_id;
break;
}
return apply_filters('acf/decode_post_id', compact('type', 'id'), $post_id);
}