Esempio n. 1
0
 function wm_post_meta($args = array())
 {
     //Helper variables
     $output = '';
     $args = wp_parse_args($args, apply_filters('wmhook_wm_post_meta_defaults', array('class' => 'entry-meta clearfix', 'date_format' => null, 'html' => '<span class="{class}"{attributes}>{content}</span> ', 'html_custom' => array('date' => '<time datetime="{datetime}" class="{class}"{attributes}>{content}</time> '), 'meta' => array(), 'post_id' => null, 'post' => null)));
     $args = apply_filters('wmhook_wm_post_meta_args', $args);
     $args['meta'] = array_filter((array) $args['meta']);
     if ($args['post_id']) {
         $args['post_id'] = absint($args['post_id']);
         $args['post'] = get_post($args['post_id']);
     }
     //Requirements check
     if (empty($args['meta'])) {
         return;
     }
     //Preparing output
     foreach ($args['meta'] as $meta) {
         //Allow custom metas
         $helper = '';
         $replacements = (array) apply_filters('wmhook_wm_post_meta_replacements', array(), $meta, $args);
         $single_output = apply_filters('wmhook_wm_post_meta', '', $meta, $args);
         $output .= $single_output;
         //Predefined metas
         switch ($meta) {
             case 'author':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args)) {
                     $replacements = array('{attributes}' => wm_schema_org('Person'), '{class}' => 'author vcard entry-meta-element', '{content}' => '<a href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '" class="url fn n" rel="author"' . wm_schema_org('author') . '>' . get_the_author() . '</a>');
                 }
                 break;
             case 'category':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args) && wm_is_categorized_blog() && ($helper = get_the_category_list(', ', '', $args['post_id']))) {
                     $replacements = array('{attributes}' => '', '{class}' => 'cat-links entry-meta-element', '{content}' => $helper);
                 }
                 break;
             case 'comments':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args) && !post_password_required() && (comments_open($args['post_id']) || get_comments_number($args['post_id']))) {
                     $helper = get_comments_number($args['post_id']);
                     //Don't know why this can not be in IF condition, but otherwise it won't work...
                     $element_id = $helper ? '#comments' : '#respond';
                     $replacements = array('{attributes}' => '', '{class}' => 'comments-link entry-meta-element', '{content}' => '<a href="' . esc_url(get_permalink($args['post_id'])) . $element_id . '" title="' . esc_attr(sprintf(_x('Comments: %s', 'Number of comments in post meta.', 'wm_domain'), $helper)) . '">' . sprintf(_x('<span class="comments-title">Comments: </span>%s', 'Number of comments in post meta (keep the HTML tags).', 'wm_domain'), '<span class="comments-count">' . $helper . '</span>') . '</a>');
                 }
                 break;
             case 'date':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args)) {
                     $replacements = array('{attributes}' => ' title="' . esc_attr(get_the_date()) . ' | ' . esc_attr(get_the_time('', $args['post'])) . '"' . wm_schema_org('datePublished'), '{class}' => 'entry-date entry-meta-element published', '{content}' => esc_html(get_the_date($args['date_format'])), '{datetime}' => esc_attr(get_the_date('c')));
                 }
                 break;
             case 'edit':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args) && ($helper = get_edit_post_link($args['post_id']))) {
                     $the_title_attribute_args = array('echo' => false);
                     if ($args['post_id']) {
                         $the_title_attribute_args['post'] = $args['post'];
                     }
                     $replacements = array('{attributes}' => '', '{class}' => 'entry-edit entry-meta-element', '{content}' => '<a href="' . esc_url($helper) . '" title="' . esc_attr(sprintf(__('Edit the "%s"', 'wm_domain'), the_title_attribute($the_title_attribute_args))) . '"><span>' . _x('Edit', 'Edit post link.', 'wm_domain') . '</span></a>');
                 }
                 break;
             case 'likes':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args) && function_exists('zilla_likes')) {
                     global $zilla_likes;
                     $helper = $zilla_likes->do_likes();
                     $replacements = array('{attributes}' => '', '{class}' => 'entry-likes entry-meta-element', '{content}' => $helper);
                 }
                 break;
             case 'permalink':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args)) {
                     $the_title_attribute_args = array('echo' => false);
                     if ($args['post_id']) {
                         $the_title_attribute_args['post'] = $args['post'];
                     }
                     $replacements = array('{attributes}' => wm_schema_org('url'), '{class}' => 'entry-permalink entry-meta-element', '{content}' => '<a href="' . esc_url(get_permalink($args['post_id'])) . '" title="' . esc_attr(sprintf(__('Permalink to "%s"', 'wm_domain'), the_title_attribute($the_title_attribute_args))) . '" rel="bookmark"><span>' . get_the_title($args['post_id']) . '</span></a>');
                 }
                 break;
             case 'tags':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args) && ($helper = get_the_tag_list('', ' ', '', $args['post_id']))) {
                     $replacements = array('{attributes}' => wm_schema_org('keywords'), '{class}' => 'tags-links entry-meta-element', '{content}' => $helper);
                 }
                 break;
             case 'views':
                 if (apply_filters('wmhook_wm_post_meta_enable_' . $meta, true, $args) && function_exists('bawpvc_views_sc') && ($helper = bawpvc_views_sc(array()))) {
                     $replacements = array('{attributes}' => ' title="' . __('Views count', 'wm_domain') . '"', '{class}' => 'entry-views entry-meta-element', '{content}' => $helper);
                 }
                 break;
             default:
                 break;
         }
         // /switch
         //Single meta output
         $replacements = (array) apply_filters('wmhook_wm_post_meta_replacements_' . $meta, $replacements, $args);
         if (empty($single_output) && !empty($replacements)) {
             if (isset($args['html_custom'][$meta])) {
                 $output .= strtr($args['html_custom'][$meta], (array) $replacements);
             } else {
                 $output .= strtr($args['html'], (array) $replacements);
             }
         }
     }
     // /foreach
     if ($output) {
         $output = '<div class="' . esc_attr($args['class']) . '">' . $output . '</div>';
     }
     //Output
     return apply_filters('wmhook_wm_post_meta_output', $output, $args);
 }
Esempio n. 2
0
 function wm_post_custom_metas($empty, $meta, $args)
 {
     //Requirements check
     if (!in_array($meta, array('likes', 'views'))) {
         return $empty;
     }
     //Helper variables
     $meta_output = $output = $title = '';
     if ('likes' === $meta) {
         if (function_exists('zilla_likes')) {
             //ZillaLikes is prioritized as Love It does work 100% only on single post page
             global $zilla_likes;
             $meta_output = $zilla_likes->do_likes();
         } elseif (function_exists('lip_love_it_link')) {
             $meta_output = lip_love_it_link(null, __('Like it!', 'mustang'), __('Liked already!', 'mustang'), false);
         }
     } elseif ('views' === $meta) {
         $title = __('Views count', 'mustang');
         $meta_output = bawpvc_views_sc(array());
     }
     //Add new meta
     $replacements = array('{attributes}' => ' title="' . $title . '"', '{class}' => 'entry-' . $meta . ' entry-meta-element', '{content}' => $meta_output);
     $replacements = apply_filters('wmhook_wm_post_custom_metas_replacements_' . $meta, $replacements);
     if (isset($args['html_custom'][$meta])) {
         $output .= strtr($args['html_custom'][$meta], $replacements);
     } else {
         $output .= strtr($args['html'], $replacements);
     }
     //Output
     return apply_filters('wmhook_wm_post_custom_metas_output', $empty . $output, $meta);
 }