~ubuntu-branches/debian/jessie/wordpress/jessie

« back to all changes in this revision

Viewing changes to wp-includes/category-template.php

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-04-17 20:56:19 UTC
  • mfrom: (1.2.35)
  • Revision ID: package-import@ubuntu.com-20140417205619-nurbet6eho4yvwfv
Tags: 3.9+dfsg-1
* New upstream release
* 3.9 seems to handle different locations for plugins so the
  plugin directory handling patches have been cut back.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
                _make_cat_compat( $categories[$key] );
83
83
        }
84
84
 
85
 
        // Filter name is plural because we return alot of categories (possibly more than #13237) not just one
 
85
        /**
 
86
         * Filter the array of categories to return for a post.
 
87
         *
 
88
         * @since 3.1.0
 
89
         *
 
90
         * @param array $categories An array of categories to return for the post.
 
91
         */
86
92
        return apply_filters( 'get_the_categories', $categories );
87
93
}
88
94
 
136
142
function get_the_category_by_ID( $cat_ID ) {
137
143
        $cat_ID = (int) $cat_ID;
138
144
        $category = get_term( $cat_ID, 'category' );
 
145
 
139
146
        if ( is_wp_error( $category ) )
140
147
                return $category;
141
 
        return $category->name;
 
148
 
 
149
        return ( $category ) ? $category->name : '';
142
150
}
143
151
 
144
152
/**
153
161
 */
154
162
function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
155
163
        global $wp_rewrite;
156
 
        if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) )
 
164
        if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) {
 
165
                /** This filter is documented in wp-includes/category-template.php */
157
166
                return apply_filters( 'the_category', '', $separator, $parents );
 
167
        }
158
168
 
159
169
        $categories = get_the_category( $post_id );
160
 
        if ( empty( $categories ) )
 
170
        if ( empty( $categories ) ) {
 
171
                /** This filter is documented in wp-includes/category-template.php */
161
172
                return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
 
173
        }
162
174
 
163
175
        $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
164
176
 
209
221
                        ++$i;
210
222
                }
211
223
        }
 
224
 
 
225
        /**
 
226
         * Filter the category or list of categories.
 
227
         *
 
228
         * @since 1.2.0
 
229
         *
 
230
         * @param array  $thelist   List of categories for the current post.
 
231
         * @param string $separator Separator used between the categories.
 
232
         * @param string $parents   How to display the category parents. Accepts 'multiple',
 
233
         *                          'single', or empty.
 
234
         */
212
235
        return apply_filters( 'the_category', $thelist, $separator, $parents );
213
236
}
214
237
 
342
365
                $output = '';
343
366
 
344
367
        if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
 
368
 
 
369
                /**
 
370
                 * Filter a taxonomy drop-down display element.
 
371
                 *
 
372
                 * A variety of taxonomy drop-down display elements can be modified
 
373
                 * just prior to display via this filter. Filterable arguments include
 
374
                 * 'show_option_none', 'show_option_all', and various forms of the
 
375
                 * term name.
 
376
                 *
 
377
                 * @since 1.2.0
 
378
                 *
 
379
                 * @see wp_dropdown_categories()
 
380
                 *
 
381
                 * @param string $element Taxonomy element to list.
 
382
                 */
345
383
                $show_option_none = apply_filters( 'list_cats', $show_option_none );
346
384
                $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
347
385
        }
349
387
        if ( ! empty( $categories ) ) {
350
388
 
351
389
                if ( $show_option_all ) {
 
390
 
 
391
                        /** This filter is documented in wp-includes/category-template.php */
352
392
                        $show_option_all = apply_filters( 'list_cats', $show_option_all );
353
393
                        $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
354
394
                        $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
355
395
                }
356
396
 
357
397
                if ( $show_option_none ) {
 
398
 
 
399
                        /** This filter is documented in wp-includes/category-template.php */
358
400
                        $show_option_none = apply_filters( 'list_cats', $show_option_none );
359
401
                        $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
360
402
                        $output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
371
413
        if ( ! $r['hide_if_empty'] || ! empty($categories) )
372
414
                $output .= "</select>\n";
373
415
 
374
 
        $output = apply_filters( 'wp_dropdown_cats', $output );
 
416
        /**
 
417
         * Filter the taxonomy drop-down output.
 
418
         *
 
419
         * @since 2.1.0
 
420
         *
 
421
         * @param string $output HTML output.
 
422
         * @param array  $r      Arguments used to build the drop-down.
 
423
         */
 
424
        $output = apply_filters( 'wp_dropdown_cats', $output, $r );
375
425
 
376
426
        if ( $echo )
377
427
                echo $output;
483
533
        if ( $title_li && 'list' == $style )
484
534
                $output .= '</ul></li>';
485
535
 
 
536
        /**
 
537
         * Filter the HTML output of a taxonomy list.
 
538
         *
 
539
         * @since 2.1.0
 
540
         *
 
541
         * @param string $output HTML output.
 
542
         * @param array  $args   An array of taxonomy-listing arguments.
 
543
         */
486
544
        $output = apply_filters( 'wp_list_categories', $output, $args );
487
545
 
488
546
        if ( $echo )
507
565
 * The 'number' argument is how many tags to return. By default, the limit will
508
566
 * be to return the top 45 tags in the tag cloud list.
509
567
 *
510
 
 * The 'topic_count_text_callback' argument is a function, which, given the count
511
 
 * of the posts  with that tag, returns a text for the tooltip of the tag link.
 
568
 * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the
 
569
 * text for the tooltip of the tag link.
 
570
 *
 
571
 * The 'topic_count_text_callback' argument is a function, which given the count
 
572
 * of the posts with that tag returns a text for the tooltip of the tag link.
 
573
 *
 
574
 * The 'post_type' argument is used only when 'link' is set to 'edit'. It determines the post_type
 
575
 * passed to edit.php for the popular tags edit links.
512
576
 *
513
577
 * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
514
578
 * function. Only one should be used, because only one will be used and the
523
587
        $defaults = array(
524
588
                'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
525
589
                'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
526
 
                'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
 
590
                'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true
527
591
        );
528
592
        $args = wp_parse_args( $args, $defaults );
529
593
 
534
598
 
535
599
        foreach ( $tags as $key => $tag ) {
536
600
                if ( 'edit' == $args['link'] )
537
 
                        $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
 
601
                        $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] );
538
602
                else
539
603
                        $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
540
604
                if ( is_wp_error( $link ) )
546
610
 
547
611
        $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
548
612
 
 
613
        /**
 
614
         * Filter the tag cloud output.
 
615
         *
 
616
         * @since 2.3.0
 
617
         *
 
618
         * @param string $return HTML output of the tag cloud.
 
619
         * @param array  $args   An array of tag cloud arguments.
 
620
         */
549
621
        $return = apply_filters( 'wp_tag_cloud', $return, $args );
550
622
 
551
623
        if ( 'array' == $args['format'] || empty($args['echo']) )
555
627
}
556
628
 
557
629
/**
558
 
 * Default text for tooltip for tag links
559
 
 *
560
 
 * @param integer $count number of posts with that tag
561
 
 * @return string text for the tooltip of a tag link.
562
 
 */
563
 
function default_topic_count_text( $count ) {
564
 
        return sprintf( _n('%s topic', '%s topics', $count), number_format_i18n( $count ) );
565
 
}
566
 
 
567
 
/**
568
630
 * Default topic count scaling for tag links
569
631
 *
570
632
 * @param integer $count number of posts with that tag
595
657
 * The 'number' argument is how many tags to return. By default, the limit will
596
658
 * be to return the entire tag cloud list.
597
659
 *
 
660
 * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the
 
661
 * text for the tooltip of the tag link.
 
662
 *
598
663
 * The 'topic_count_text_callback' argument is a function, which given the count
599
 
 * of the posts  with that tag returns a text for the tooltip of the tag link.
 
664
 * of the posts with that tag returns a text for the tooltip of the tag link.
600
665
 *
601
666
 * @todo Complete functionality.
602
667
 * @since 2.3.0
603
668
 *
604
669
 * @param array $tags List of tags.
605
670
 * @param string|array $args Optional, override default arguments.
606
 
 * @return string
 
671
 * @return string|array Tag cloud as a string or an array, depending on 'format' argument.
607
672
 */
608
673
function wp_generate_tag_cloud( $tags, $args = '' ) {
609
674
        $defaults = array(
610
675
                'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
611
676
                'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
612
 
                'topic_count_text_callback' => 'default_topic_count_text',
 
677
                'topic_count_text' => null, 'topic_count_text_callback' => null,
613
678
                'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
614
679
        );
615
680
 
616
 
        if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
617
 
                $body = 'return sprintf (
618
 
                        _n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
619
 
                        number_format_i18n( $count ));';
620
 
                $args['topic_count_text_callback'] = create_function('$count', $body);
621
 
        }
622
 
 
623
681
        $args = wp_parse_args( $args, $defaults );
624
 
        extract( $args );
625
 
 
626
 
        if ( empty( $tags ) )
627
 
                return;
628
 
 
 
682
        extract( $args, EXTR_SKIP );
 
683
 
 
684
        $return = ( 'array' === $format ) ? array() : '';
 
685
 
 
686
        if ( empty( $tags ) ) {
 
687
                return $return;
 
688
        }
 
689
 
 
690
        // Juggle topic count tooltips:
 
691
        if ( isset( $args['topic_count_text'] ) ) {
 
692
                // First look for nooped plural support via topic_count_text.
 
693
                $translate_nooped_plural = $args['topic_count_text'];
 
694
        } elseif ( ! empty( $args['topic_count_text_callback'] ) ) {
 
695
                // Look for the alternative callback style. Ignore the previous default.
 
696
                if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) {
 
697
                        $translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
 
698
                } else {
 
699
                        $translate_nooped_plural = false;
 
700
                }
 
701
        } elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
 
702
                // If no callback exists, look for the old-style single_text and multiple_text arguments.
 
703
                $translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] );
 
704
        } else {
 
705
                // This is the default for when no callback, plural, or argument is passed in.
 
706
                $translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
 
707
        }
 
708
 
 
709
        /**
 
710
         * Filter how the items in a tag cloud are sorted.
 
711
         *
 
712
         * @since 2.8.0
 
713
         *
 
714
         * @param array $tags Ordered array of terms.
 
715
         * @param array $args An array of tag cloud arguments.
 
716
         */
629
717
        $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
630
 
        if ( $tags_sorted != $tags  ) { // the tags have been sorted by a plugin
 
718
        if ( empty( $tags_sorted ) ) {
 
719
                return $return;
 
720
        }
 
721
 
 
722
        if ( $tags_sorted !== $tags ) {
631
723
                $tags = $tags_sorted;
632
 
                unset($tags_sorted);
 
724
                unset( $tags_sorted );
633
725
        } else {
634
 
                if ( 'RAND' == $order ) {
635
 
                        shuffle($tags);
 
726
                if ( 'RAND' === $order ) {
 
727
                        shuffle( $tags );
636
728
                } else {
637
729
                        // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
638
 
                        if ( 'name' == $orderby )
 
730
                        if ( 'name' === $orderby ) {
639
731
                                uasort( $tags, '_wp_object_name_sort_cb' );
640
 
                        else
 
732
                        } else {
641
733
                                uasort( $tags, '_wp_object_count_sort_cb' );
 
734
                        }
642
735
 
643
 
                        if ( 'DESC' == $order )
 
736
                        if ( 'DESC' === $order ) {
644
737
                                $tags = array_reverse( $tags, true );
 
738
                        }
645
739
                }
646
740
        }
647
741
 
672
766
                $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
673
767
                $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
674
768
                $tag_name = $tags[ $key ]->name;
675
 
                $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count, $tag, $args ) ) . "' style='font-size: " .
 
769
 
 
770
                if ( $translate_nooped_plural ) {
 
771
                        $title_attribute = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) );
 
772
                } else {
 
773
                        $title_attribute = call_user_func( $topic_count_text_callback, $real_count, $tag, $args );
 
774
                }
 
775
 
 
776
                $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $title_attribute ) . "' style='font-size: " .
676
777
                        str_replace( ',', '.', ( $smallest + ( ( $count - $min_count ) * $font_step ) ) )
677
778
                        . "$unit;'>$tag_name</a>";
678
779
        }
691
792
                break;
692
793
        endswitch;
693
794
 
694
 
        if ( $filter )
 
795
        if ( $filter ) {
 
796
                /**
 
797
                 * Filter the generated output of a tag cloud.
 
798
                 *
 
799
                 * The filter is only evaluated if a true value is passed
 
800
                 * to the $filter argument in wp_generate_tag_cloud().
 
801
                 *
 
802
                 * @since 2.3.0
 
803
                 *
 
804
                 * @see wp_generate_tag_cloud()
 
805
                 *
 
806
                 * @param array|string $return String containing the generated HTML tag cloud output
 
807
                 *                             or an array of tag links if the 'format' argument
 
808
                 *                             equals 'array'.
 
809
                 * @param array        $tags   An array of terms used in the tag cloud.
 
810
                 * @param array        $args   An array of wp_generate_tag_cloud() arguments.
 
811
                 */
695
812
                return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
 
813
        }
 
814
 
696
815
        else
697
816
                return $return;
698
817
}
841
960
                extract($args);
842
961
 
843
962
                $cat_name = esc_attr( $category->name );
 
963
 
 
964
                /** This filter is documented in wp-includes/category-template.php */
844
965
                $cat_name = apply_filters( 'list_cats', $cat_name, $category );
 
966
 
845
967
                $link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
846
 
                if ( $use_desc_for_title == 0 || empty($category->description) )
 
968
                if ( $use_desc_for_title == 0 || empty($category->description) ) {
847
969
                        $link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
848
 
                else
 
970
                } else {
 
971
                        /**
 
972
                         * Filter the category description for display.
 
973
                         *
 
974
                         * @since 1.2.0
 
975
                         *
 
976
                         * @param string $description Category description.
 
977
                         * @param object $category    Category object.
 
978
                         */
849
979
                        $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
 
980
                }
 
981
 
850
982
                $link .= '>';
851
983
                $link .= $cat_name . '</a>';
852
984
 
881
1013
                }
882
1014
 
883
1015
                if ( !empty($show_count) )
884
 
                        $link .= ' (' . intval($category->count) . ')';
 
1016
                        $link .= ' (' . number_format_i18n( $category->count ) . ')';
885
1017
 
886
1018
                if ( 'list' == $args['style'] ) {
887
1019
                        $output .= "\t<li";
958
1090
        function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
959
1091
                $pad = str_repeat('&nbsp;', $depth * 3);
960
1092
 
961
 
                $cat_name = apply_filters('list_cats', $category->name, $category);
 
1093
                /** This filter is documented in wp-includes/category-template.php */
 
1094
                $cat_name = apply_filters( 'list_cats', $category->name, $category );
 
1095
 
962
1096
                $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
963
1097
                if ( $category->term_id == $args['selected'] )
964
1098
                        $output .= ' selected="selected"';
965
1099
                $output .= '>';
966
1100
                $output .= $pad.$cat_name;
967
1101
                if ( $args['show_count'] )
968
 
                        $output .= '&nbsp;&nbsp;('. $category->count .')';
 
1102
                        $output .= '&nbsp;&nbsp;('. number_format_i18n( $category->count ) .')';
969
1103
                $output .= "</option>\n";
970
1104
        }
971
1105
}
999
1133
 * Retrieve the tags for a post.
1000
1134
 *
1001
1135
 * @since 2.3.0
1002
 
 * @uses apply_filters() Calls 'get_the_tags' filter on the list of post tags.
1003
1136
 *
1004
1137
 * @param int $id Post ID.
1005
1138
 * @return array|bool Array of tag objects on success, false on failure.
1006
1139
 */
1007
1140
function get_the_tags( $id = 0 ) {
 
1141
 
 
1142
        /**
 
1143
         * Filter the array of tags for the given post.
 
1144
         *
 
1145
         * @since 2.3.0
 
1146
         *
 
1147
         * @see get_the_terms()
 
1148
         *
 
1149
         * @param array $terms An array of tags for the given post.
 
1150
         */
1008
1151
        return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) );
1009
1152
}
1010
1153
 
1012
1155
 * Retrieve the tags for a post formatted as a string.
1013
1156
 *
1014
1157
 * @since 2.3.0
1015
 
 * @uses apply_filters() Calls 'the_tags' filter on string list of tags.
1016
1158
 *
1017
1159
 * @param string $before Optional. Before tags.
1018
1160
 * @param string $sep Optional. Between tags.
1021
1163
 * @return string|bool|WP_Error A list of tags on success, false or WP_Error on failure.
1022
1164
 */
1023
1165
function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) {
 
1166
 
 
1167
        /**
 
1168
         * Filter the tags list for a given post.
 
1169
         *
 
1170
         * @since 2.3.0
 
1171
         *
 
1172
         * @param string $tag_list List of tags.
 
1173
         * @param string $before   String to use before tags.
 
1174
         * @param string $sep      String to use between the tags.
 
1175
         * @param string $after    String to use after tags.
 
1176
         * @param int    $id       Post ID.
 
1177
         */
1024
1178
        return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id );
1025
1179
}
1026
1180
 
1042
1196
/**
1043
1197
 * Retrieve tag description.
1044
1198
 *
1045
 
 * @since 2.8
 
1199
 * @since 2.8.0
1046
1200
 *
1047
1201
 * @param int $tag Optional. Tag ID. Will use global tag ID by default.
1048
1202
 * @return string Tag description, available.
1054
1208
/**
1055
1209
 * Retrieve term description.
1056
1210
 *
1057
 
 * @since 2.8
 
1211
 * @since 2.8.0
1058
1212
 *
1059
1213
 * @param int $term Optional. Term ID. Will use global term ID by default.
1060
1214
 * @param string $taxonomy Optional taxonomy name. Defaults to 'post_tag'.
1091
1245
                wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
1092
1246
        }
1093
1247
 
 
1248
        /**
 
1249
         * Filter the list of terms attached to the given post.
 
1250
         *
 
1251
         * @since 3.1.0
 
1252
         *
 
1253
         * @param array  $terms    List of attached terms.
 
1254
         * @param int    $post_id  Post ID.
 
1255
         * @param string $taxonomy Name of the taxonomy.
 
1256
         */
1094
1257
        $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
1095
1258
 
1096
1259
        if ( empty( $terms ) )
1127
1290
                $term_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
1128
1291
        }
1129
1292
 
 
1293
        /**
 
1294
         * Filter the term links for a given taxonomy.
 
1295
         *
 
1296
         * The dynamic portion of the filter name, $taxonomy, refers
 
1297
         * to the taxonomy slug.
 
1298
         *
 
1299
         * @since 2.5.0
 
1300
         *
 
1301
         * @param array $term_links An array of term links.
 
1302
         */
1130
1303
        $term_links = apply_filters( "term_links-$taxonomy", $term_links );
1131
1304
 
1132
1305
        return $before . join( $sep, $term_links ) . $after;
1150
1323
        if ( is_wp_error( $term_list ) )
1151
1324
                return false;
1152
1325
 
1153
 
        echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after);
 
1326
        /**
 
1327
         * Filter the list of terms to display.
 
1328
         *
 
1329
         * @since 2.9.0
 
1330
         *
 
1331
         * @param array  $term_list List of terms to display.
 
1332
         * @param string $taxonomy  The taxonomy name.
 
1333
         * @param string $before    String to use before the terms.
 
1334
         * @param string $sep       String to use between the terms.
 
1335
         * @param string $after     String to use after the terms.
 
1336
         */
 
1337
        echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after );
1154
1338
}
1155
1339
 
1156
1340
/**