true ]; return $tags; }); if (! function_exists('blocksy_post_meta')) { function blocksy_post_meta($post_meta_descriptor = null, $args = []) { if (! $post_meta_descriptor) { $post_meta_descriptor = blocksy_post_meta_defaults([ [ 'id' => 'author', 'enabled' => true, ], [ 'id' => 'comments', 'enabled' => true, ], [ 'id' => 'post_date', 'enabled' => true, ], [ 'id' => 'updated_date', 'enabled' => true, ], [ 'id' => 'categories', 'enabled' => true, ], [ 'id' => 'tags', 'enabled' => true, ], ]); } $args = wp_parse_args( $args, [ 'class' => '', 'meta_type' => 'simple', 'meta_divider' => 'none', 'force_icons' => false, 'attr' => [] ] ); $has_any_enabled_element = false; foreach ($post_meta_descriptor as $index => $single_meta) { global $post; if (get_post_type($post) === 'page') { if ($single_meta['id'] === 'comments') { $post_meta_descriptor[$index]['enabled'] = false; } if ( $single_meta['id'] === 'categories' && $single_meta['enabled'] ) { $post_meta_descriptor[$index]['enabled'] = in_array( 'category', get_object_taxonomies('page') ); } if ( $single_meta['id'] === 'tags' && $single_meta['enabled'] ) { $post_meta_descriptor[$index]['enabled'] = in_array( 'post_tag', get_object_taxonomies('page') ); } } if ( $single_meta['id'] === 'author' && ! isset($single_meta['label']) ) { $post_meta_descriptor[$index]['label'] = __('By', 'blocksy'); } if ( ( $single_meta['id'] === 'post_date' || $single_meta['id'] === 'updated_date' ) && ! isset($single_meta['label']) ) { $post_meta_descriptor[$index]['label'] = __('On', 'blocksy'); } if ( ( $single_meta['id'] === 'categories' || $single_meta['id'] === 'tags' ) && ! isset($single_meta['label']) ) { $post_meta_descriptor[$index]['label'] = __('In', 'blocksy'); } if ($post_meta_descriptor[$index]['enabled']) { $has_any_enabled_element = true; } } if (! $has_any_enabled_element) { return ''; } $default_date_format = get_option('date_format', ''); if (! empty($args['class'])) { $args['class'] = ' ' . $args['class']; } // Author ID global $post; $user_id = $post->post_author; $container_attr = array_merge([ 'class' => 'entry-meta' . $args['class'], 'data-type' => $args['meta_type'] . ':' . $args['meta_divider'] ], $args['attr']); ob_start(); foreach ($post_meta_descriptor as $single_meta) { if (! $single_meta['enabled']) { continue; } if ( $single_meta['id'] === 'author' && get_the_author() ) { ?>
  • > intval($single_meta['avatar_size']) * 2 ] ), [ 'tag_name' => 'a', 'suffix' => 'static', 'ratio_blocks' => false, 'html_atts' => [ 'href' => get_author_posts_url(get_the_author_meta('ID')), ], 'img_atts' => [ 'width' => intval($single_meta['avatar_size']), 'height' => intval($single_meta['avatar_size']), 'style' => 'height:' . intval($single_meta['avatar_size']) . 'px', ], ] ); } if ($args['meta_type'] === 'label') { echo '' . esc_html($single_meta['label']) . ''; } if ($args['meta_type'] === 'icons' || $args['force_icons']) { ?> 'ct-meta-element-author', 'href' => esc_url(get_author_posts_url($authordata->ID, $authordata->user_nicename)), /* translators: %s: Author's display name. */ 'title' => esc_attr(sprintf(__('Posts by %s', 'blocksy'), get_the_author())), 'rel' => 'author', ], blocksy_schema_org_definitions('author_link', [ 'array' => true ]), ( $args['meta_type'] === 'label' ? [ 'data-label' => __( 'By', 'blocksy' ) ] : [] )), get_the_author()); ?>
  • > ' . esc_html($single_meta['label']) . ''; } $date_format = $single_meta['date_format']; if ($single_meta['date_format_source'] === 'default') { $date_format = $default_date_format; } echo blocksy_html_tag( 'time', array_merge([ 'class' => 'ct-meta-element-date', 'datetime' => get_the_date('c') ], ( ($args['meta_type'] === 'label') ? ([ 'data-label' => __( 'On', 'blocksy' ) ]) : [] ), ( is_customize_preview() ? [ 'data-default-format' => $default_date_format, 'data-date' => get_the_date('c') ] : [] )), esc_html(get_the_date($date_format)) ); ?>
  • > ' . esc_html($single_meta['label']) . ''; } $date_format = $single_meta['date_format']; if ($single_meta['date_format_source'] === 'default') { $date_format = $default_date_format; } $proper_updated_date = intval(get_the_modified_date('U')) < intval( get_the_date('U') ) ? get_the_date($date_format) : get_the_modified_date($date_format); $proper_updated_date_initial = intval(get_the_modified_date('U')) < intval( get_the_date('U') ) ? get_the_date('c') : get_the_modified_date('c'); echo blocksy_html_tag( 'time', array_merge([ 'class' => 'ct-meta-element-date', 'datetime' => $proper_updated_date_initial ], ( $args['meta_type'] === 'label' ? [ 'data-label' => __( 'On', 'blocksy' ) ] : [] ), ( is_customize_preview() ? [ 'data-default-format' => $default_date_format, 'data-date' => $proper_updated_date_initial ] : [] )), esc_html($proper_updated_date) ); ?>
  • 0) { ?>
  • '; if ($args['meta_type'] === 'icons' || $args['force_icons']) { echo ''; } if ($args['meta_type'] === 'label') { echo '' . esc_html($single_meta['label']) . ''; } echo wp_kses_post(blocksy_get_categories_list($divider)); echo ''; } if ($single_meta['id'] === 'tags' && blocksy_get_categories_list('', false)) { if ( $args['meta_type'] === 'icons' || ! isset($single_meta['style']) ) { $single_meta['style'] = 'simple'; } $divider = ''; if ($single_meta['style'] === 'simple') { $divider = ', '; } if ($single_meta['style'] === 'underline') { $divider = '/'; } echo '
  • '; if ($args['meta_type'] === 'icons' || $args['force_icons']) { echo ''; } if ($args['meta_type'] === 'label') { echo '' . esc_html($single_meta['label'], 'blocksy') . ''; } echo wp_kses_post(blocksy_get_categories_list($divider, false)); echo '
  • '; } } $to_return = ob_get_contents(); ob_end_clean(); if (empty(trim($to_return))) { return ''; } ob_start(); ?> 'author', 'enabled' => false, 'label' => __('By', 'blocksy'), 'has_author_avatar' => 'no', 'avatar_size' => 25 ], [ 'id' => 'post_date', 'enabled' => false, 'label' => __('On', 'blocksy'), 'date_format_source' => 'default', 'date_format' => 'M j, Y' ], [ 'id' => 'updated_date', 'enabled' => false, 'label' => __('On', 'blocksy'), 'date_format_source' => 'default', 'date_format' => 'M j, Y' ], [ 'id' => 'categories', 'enabled' => false, 'label' => __('In', 'blocksy'), 'style' => 'simple' ], [ 'id' => 'comments', 'enabled' => false, ], [ 'id' => 'tags', 'enabled' => false, 'label' => __('In', 'blocksy'), 'style' => 'simple' ] ]; $result = []; foreach ($defaults as $index => $single_meta) { foreach ($opts as $single_opt) { if ($single_meta['id'] !== $single_opt['id']) { continue; } $future_layer = wp_parse_args($single_opt, $single_meta); if (! $future_layer['enabled']) { continue; } $result[] = $future_layer; } } return $result; }