| @@ -98,8 +98,25 @@ | ||
| 98 | 98 | if ( self::exclude_on( $post, $args ) ) { |
| 99 | 99 | return ''; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | + /** | |
| 103 | + * Pre-filter the popular posts output. | |
| 104 | + * | |
| 105 | + * Return a non-null value to short-circuit the default rendering, e.g. to | |
| 106 | + * replace it with a lazy load placeholder. Runs for all display methods. | |
| 107 | + * | |
| 108 | + * @since 4.4.0 | |
| 109 | + * | |
| 110 | + * @param string|null $pre Pre-rendered output. Default null. | |
| 111 | + * @param array $args Fully parsed arguments array. | |
| 112 | + * @param \WP_Post|null $post Current post object. | |
| 113 | + */ | |
| 114 | + $pre = apply_filters( 'tptn_pre_pop_posts', null, $args, $post ); | |
| 115 | + if ( null !== $pre ) { | |
| 116 | + return (string) $pre; | |
| 117 | + } | |
| 118 | + | |
| 102 | 119 | // Check if the cache is enabled and if the output exists. If so, return the output. |
| 103 | 120 | if ( $args['cache'] ) { |
| 104 | 121 | $cache_name = \WebberZone\Top_Ten\Util\Cache::get_key( $args ); |
| 105 | 122 | |
| @@ -192,8 +209,12 @@ | ||
| 192 | 209 | |
| 193 | 210 | $output .= ' <span class="tptn_list_count">' . self::get_list_count( $args, $result, $visits ) . '</span>'; |
| 194 | 211 | } |
| 195 | 212 | |
| 213 | + if ( ! empty( $args['show_ratings'] ) ) { | |
| 214 | + $output .= self::get_the_ratings( $args, $result ); | |
| 215 | + } | |
| 216 | + | |
| 196 | 217 | $tptn_list = ''; |
| 197 | 218 | /** |
| 198 | 219 | * Filter to add content to the end of each item in the list. |
| 199 | 220 | * |
| @@ -747,9 +768,9 @@ | ||
| 747 | 768 | public static function get_the_author( $args, $result ) { |
| 748 | 769 | |
| 749 | 770 | $author_info = get_userdata( (int) $result->post_author ); |
| 750 | 771 | $author_link = ( false === $author_info ) ? '' : get_author_posts_url( $author_info->ID ); |
| 751 | - $author_name = ( false === $author_info ) ? '' : ucwords( trim( stripslashes( $author_info->display_name ) ) ); | |
| 772 | + $author_name = ( false === $author_info ) ? '' : ucwords( trim( stripslashes( $author_info->display_name ), " \t\n\r\0\x0B" ) ); | |
| 752 | 773 | |
| 753 | 774 | /** |
| 754 | 775 | * Filter the author name. |
| 755 | 776 | * |
| @@ -879,10 +900,12 @@ | ||
| 879 | 900 | * @return string Formatted post date |
| 880 | 901 | */ |
| 881 | 902 | public static function get_list_count( $args, $result, $visits ) { |
| 882 | 903 | |
| 883 | - $tptn_list_count = '(' . Helpers::number_format_i18n( $visits ) . ')'; | |
| 904 | + $number_format_style = isset( $args['number_format_style'] ) ? $args['number_format_style'] : null; | |
| 884 | 905 | |
| 906 | + $tptn_list_count = '(' . Helpers::number_format_i18n( $visits, 0, $number_format_style ) . ')'; | |
| 907 | + | |
| 885 | 908 | /** |
| 886 | 909 | * Filter the formatted list count text. |
| 887 | 910 | * |
| 888 | 911 | * @since 2.1.0 |
| @@ -896,8 +919,40 @@ | ||
| 896 | 919 | } |
| 897 | 920 | |
| 898 | 921 | |
| 899 | 922 | /** |
| 923 | + * Returns the WP-PostRatings rating of each list item. | |
| 924 | + * | |
| 925 | + * @since 4.4.0 | |
| 926 | + * | |
| 927 | + * @param array $args Array of arguments. `show_ratings` can be `stars` (WP-PostRatings template) or `score` (average rating number). | |
| 928 | + * @param \WP_Post $result Object of the current post result. | |
| 929 | + * @return string Formatted rating markup. Empty string if WP-PostRatings is not active. | |
| 930 | + */ | |
| 931 | + public static function get_the_ratings( $args, $result ) { | |
| 932 | + | |
| 933 | + $ratings = ''; | |
| 934 | + | |
| 935 | + if ( 'score' === $args['show_ratings'] && function_exists( 'expand_ratings_template' ) ) { | |
| 936 | + $ratings = ' <span class="tptn_ratings">' . expand_ratings_template( '%RATINGS_AVERAGE%', $result->ID ) . '</span>'; | |
| 937 | + } elseif ( function_exists( 'the_ratings_results' ) ) { | |
| 938 | + $ratings = ' <span class="tptn_ratings">' . the_ratings_results( $result->ID ) . '</span>'; | |
| 939 | + } | |
| 940 | + | |
| 941 | + /** | |
| 942 | + * Filter the WP-PostRatings rating markup of each list item. | |
| 943 | + * | |
| 944 | + * @since 4.4.0 | |
| 945 | + * | |
| 946 | + * @param string $ratings Formatted rating markup. Empty string if WP-PostRatings is not active. | |
| 947 | + * @param \WP_Post $result Object of the current post result. | |
| 948 | + * @param array $args Array of arguments. | |
| 949 | + */ | |
| 950 | + return apply_filters( 'tptn_ratings', $ratings, $result, $args ); | |
| 951 | + } | |
| 952 | + | |
| 953 | + | |
| 954 | + /** | |
| 900 | 955 | * Function to create an excerpt for the post. |
| 901 | 956 | * |
| 902 | 957 | * @since 3.3.0 |
| 903 | 958 | * @since 4.0.0 Added $more_link_text parameter. $post parameter can now be a WP_Post instance. |
| @@ -904,9 +959,9 @@ | ||
| 904 | 959 | * |
| 905 | 960 | * @param int|\WP_Post $post Post ID or WP_Post instance. |
| 906 | 961 | * @param int|string $excerpt_length Length of the excerpt in words. |
| 907 | 962 | * @param bool $use_excerpt Use excerpt instead of content. |
| 908 | - * @param string $more_link_text Content for when there is more text. Default is null. | |
| 963 | + * @param string|null $more_link_text Read More text. Pass null to use the default "(more…)" link. Default '' (no Read More link). | |
| 909 | 964 | * @return string Post Excerpt |
| 910 | 965 | */ |
| 911 | 966 | public static function get_the_excerpt( $post, $excerpt_length = 0, $use_excerpt = true, $more_link_text = '' ) { |
| 912 | 967 | $content = ''; |
| @@ -942,10 +997,10 @@ | ||
| 942 | 997 | * Filters the Read More text of the CRP excerpt. |
| 943 | 998 | * |
| 944 | 999 | * @since 3.0.0 |
| 945 | 1000 | * |
| 946 | - * @param string $more_link_text Read More text. | |
| 947 | - * @param \WP_Post $post Source Post instance. | |
| 1001 | + * @param string|null $more_link_text Read More text. Null uses the default "(more…)" link. | |
| 1002 | + * @param \WP_Post $post Source Post instance. | |
| 948 | 1003 | */ |
| 949 | 1004 | $more_link_text = apply_filters( 'tptn_excerpt_more_link_text', $more_link_text, $post ); |
| 950 | 1005 | |
| 951 | 1006 | if ( null === $more_link_text ) { |
| @@ -1112,10 +1167,10 @@ | ||
| 1112 | 1167 | } |
| 1113 | 1168 | |
| 1114 | 1169 | // Exclude page_on_front and page_for_posts. |
| 1115 | 1170 | if ( 'page' === get_option( 'show_on_front' ) && \tptn_get_option( 'exclude_front' ) ) { |
| 1116 | - $page_on_front = get_option( 'page_on_front' ); | |
| 1117 | - $page_for_posts = get_option( 'page_for_posts' ); | |
| 1171 | + $page_on_front = (int) get_option( 'page_on_front' ); | |
| 1172 | + $page_for_posts = (int) get_option( 'page_for_posts' ); | |
| 1118 | 1173 | if ( $page_on_front > 0 ) { |
| 1119 | 1174 | $exclude_post_ids[] = $page_on_front; |
| 1120 | 1175 | } |
| 1121 | 1176 | if ( $page_for_posts > 0 ) { |