| | |
| | | namespace JVBase\meta; |
| | | |
| | | use DateTime; |
| | | use JVBase\registrar\Registrar; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | $content = $config['content']; |
| | | |
| | | $config['data']['content'] = $content; |
| | | $plural = |
| | | JVB_CONTENT[$content]['plural'] |
| | | ?? JVB_TAXONOMY[$content]['plural'] |
| | | ?? JVB_USER[$content]['plural'] |
| | | ?? str_replace('_', ' ', $content) . 's'; |
| | | |
| | | $singular = JVB_CONTENT[$content]['singular'] |
| | | ?? JVB_TAXONOMY[$content]['singular'] |
| | | ?? JVB_USER[$content]['singular'] |
| | | ?? str_replace('_', ' ',$config['content']); |
| | | $registrar = Registrar::getInstance($content); |
| | | $plural = $registrar->getPlural()??str_replace('_', ' ', $content).'s'; |
| | | $singular = $registrar->getSingular()??str_replace('_', ' ', $content); |
| | | } |
| | | if ($config['limit'] > 0) { |
| | | $config['data']['max-files'] = $config['limit']; |
| | |
| | | } |
| | | |
| | | $input .= '</div>'; // closes .file-upload-container |
| | | |
| | | $input .= sprintf( |
| | | '<input type="hidden" name="%s" value="%s">', |
| | | esc_attr($name), |
| | | esc_attr(!empty($attachmentIds) ? implode(',', $attachmentIds) : '') |
| | | ); |
| | | |
| | | unset($config['description']); |
| | | unset($config['label']); |
| | | return static::fieldWrap($name, $input, $config); |
| | |
| | | 'type' => $config['subtype'], |
| | | ], $config); |
| | | |
| | | $icon = match ($config['subtype']) { |
| | | 'taxonomy' => JVB_TAXONOMY[$config['taxonomy']]['icon'] ?? jvbDefaultIcon(), |
| | | 'content' => JVB_CONTENT[$config['content']]['icon'] ?? jvbDefaultIcon(), |
| | | 'user' => JVB_USER[$config['role']]['icon'] ?? 'user', |
| | | default => jvbDefaultIcon(), |
| | | }; |
| | | $registrar = Registrar::getInstance($config[$config['subtype']]); |
| | | $icon = jvbDefaultIcon(); |
| | | if ($registrar){ |
| | | $icon = $registrar->getIcon()??jvbDefaultIcon(); |
| | | } |
| | | |
| | | $containerId = sprintf('%s-%s-selector', $name, $config['subtype']); |
| | | |
| | |
| | | |
| | | protected static function getPlural(array $config):array |
| | | { |
| | | $single = $plural = ''; |
| | | switch ($config['subtype']) { |
| | | case 'taxonomy': |
| | | if (array_key_exists($config['taxonomy'], JVB_TAXONOMY)) { |
| | | $single = JVB_TAXONOMY[$config['taxonomy']]['singular']; |
| | | $plural = JVB_TAXONOMY[$config['taxonomy']]['plural']; |
| | | $registrar = Registrar::getInstance($config['taxonomy']); |
| | | if ($registrar) { |
| | | $single = $registrar->getSingular(); |
| | | $plural = $registrar->getPlural(); |
| | | } else { |
| | | $taxonomy = get_taxonomy($config['taxonomy']); |
| | | if (!$taxonomy) { |
| | | return []; |
| | | if ($taxonomy) { |
| | | $single = $taxonomy->labels->singular_name; |
| | | $plural = $taxonomy->labels->name; |
| | | } |
| | | $single = $taxonomy->labels->singular_name; |
| | | $plural = $taxonomy->labels->name; |
| | | } |
| | | break; |
| | | case 'content': |
| | | if (array_key_exists($config['content'], JVB_CONTENT)) { |
| | | $single = JVB_CONTENT[$config['content']]['singular']; |
| | | $plural = JVB_CONTENT[$config['content']]['plural']; |
| | | $registrar = Registrar::getInstance($config['content']); |
| | | if ($registrar) { |
| | | $single = $registrar->getSingular(); |
| | | $plural = $registrar->getPlural(); |
| | | } else { |
| | | $postType = get_post_type_object($config['content']); |
| | | if (!$postType) { |
| | | return ''; |
| | | if ($postType) { |
| | | $single = $postType->labels->singular_name; |
| | | $plural = $postType->labels->name; |
| | | } |
| | | $single = $postType->labels->singular_name; |
| | | $plural = $postType->labels->name; |
| | | |
| | | } |
| | | break; |
| | | |
| | | case 'user': |
| | | if (array_key_exists($config['user'], JVB_USER)) { |
| | | $single = JVB_USER[$config['user']]['singular']; |
| | | $plural = JVB_USER[$config['user']]['plural']; |
| | | $registrar = Registrar::getInstance($config['user']); |
| | | |
| | | if ($registrar) { |
| | | $single = $registrar->getSingular(); |
| | | $plural = $registrar->getPlural(); |
| | | } else { |
| | | $user = get_role($config['user']); |
| | | if (!$user) { |
| | | return ''; |
| | | if ($user) { |
| | | $single = 'User'; |
| | | $plural = 'Users'; |
| | | } |
| | | $single = 'User'; |
| | | $plural = 'Users'; |
| | | } |
| | | break; |
| | | } |
| | |
| | | { |
| | | switch ($config['subtype']) { |
| | | case 'taxonomy': |
| | | if (array_key_exists($config['taxonomy'], JVB_TAXONOMY)) { |
| | | $single = JVB_TAXONOMY[$config['taxonomy']]['singular']; |
| | | $plural = JVB_TAXONOMY[$config['taxonomy']]['plural']; |
| | | $registrar = Registrar::getInstance($config['taxonomy']); |
| | | if ($registrar) { |
| | | $single = $registrar->getSingular(); |
| | | $plural = $registrar->getPlural(); |
| | | } else { |
| | | $taxonomy = get_taxonomy($config['taxonomy']); |
| | | if (!$taxonomy) { |
| | |
| | | ); |
| | | break; |
| | | case 'content': |
| | | if (array_key_exists($config['content'], JVB_CONTENT)) { |
| | | $single = JVB_CONTENT[$config['content']]['singular']; |
| | | $plural = JVB_CONTENT[$config['content']]['plural']; |
| | | $registrar = Registrar::getInstance($config['content']); |
| | | if ($registrar) { |
| | | $single = $registrar->getSingular(); |
| | | $plural = $registrar->getPlural(); |
| | | } else { |
| | | $postType = get_post_type_object($config['content']); |
| | | if (!$postType) { |
| | |
| | | break; |
| | | |
| | | case 'user': |
| | | if (array_key_exists($config['user'], JVB_USER)) { |
| | | $single = JVB_USER[$config['user']]['singular']; |
| | | $plural = JVB_USER[$config['user']]['plural']; |
| | | $registrar = Registrar::getInstance($config['user']); |
| | | if ($registrar){ |
| | | $single = $registrar->getSingular(); |
| | | $plural = $registrar->getPlural(); |
| | | } else { |
| | | $user = get_role($config['user']); |
| | | if (!$user) { |
| | |
| | | { |
| | | $fields = $config['fields'] ?? []; |
| | | $rows = is_array($value) ? $value : []; |
| | | if(array_key_exists('row_label', $config)) { |
| | | $config['data']['label'] = esc_attr($config['row_label']); |
| | | if(array_key_exists('add_label', $config)) { |
| | | $config['data']['label'] = esc_attr($config['add_label']); |
| | | } |
| | | |
| | | $input = sprintf( |
| | |
| | | array_key_exists('add_label', $config) ? $config['add_label'] : 'Add Item' |
| | | ); |
| | | |
| | | unset($config['label']); |
| | | return static::fieldWrap($name, $input, $config); |
| | | } |
| | | protected static function renderRepeaterRow(array $fields, array $values, int|string $index, string $name, string $rowTitle='New Item'):string |