| 1 |
<?php |
| 2 |
/** |
| 3 |
* Frontend functions. |
| 4 |
* |
| 5 |
* @package WebberZone\Top_Ten |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'WPINC' ) ) { |
| 9 |
die; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Function to manually display count. |
| 14 |
* |
| 15 |
* @since 1.0 |
| 16 |
* @param int|boolean $echo_output Flag to echo the output. |
| 17 |
* @return string Formatted string if $echo_output is set to 0|false |
| 18 |
*/ |
| 19 |
function echo_tptn_post_count( $echo_output = 1 ) { |
| 20 |
return \WebberZone\Top_Ten\Counter::echo_post_count( $echo_output ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Function to manually display count. |
| 25 |
* |
| 26 |
* @since 1.9.2 |
| 27 |
* @param int|string|\WP_Post $post Post ID or WP_Post object. |
| 28 |
* @param int|string $blog_id Blog ID. |
| 29 |
* @return string Formatted post count |
| 30 |
*/ |
| 31 |
function get_tptn_post_count( $post = 0, $blog_id = 0 ) { |
| 32 |
return \WebberZone\Top_Ten\Counter::get_post_count( $post, $blog_id ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Returns the post count. |
| 37 |
* |
| 38 |
* @since 1.9.8.5 |
| 39 |
* |
| 40 |
* @param int|\WP_Post $post Post ID or WP_Post object. |
| 41 |
* @param string $count Which count to return? total, daily or overall. |
| 42 |
* @param int $blog_id Blog ID. |
| 43 |
* @return int Post count |
| 44 |
*/ |
| 45 |
function get_tptn_post_count_only( $post = 0, $count = 'total', $blog_id = 0 ) { |
| 46 |
return \WebberZone\Top_Ten\Counter::get_post_count_only( $post, $count, $blog_id ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns the total post count. |
| 51 |
* |
| 52 |
* @since 4.0.0 |
| 53 |
* @param int|\WP_Post $post Post ID or WP_Post object. |
| 54 |
* @param int $blog_id Blog ID. |
| 55 |
* @return int Post count |
| 56 |
*/ |
| 57 |
function get_tptn_total_count( $post = 0, $blog_id = 0 ) { |
| 58 |
return get_tptn_post_count_only( $post, 'total', $blog_id ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Returns the daily post count. |
| 63 |
* |
| 64 |
* @since 4.0.0 |
| 65 |
* @param int|\WP_Post $post Post ID or WP_Post object. |
| 66 |
* @param int $blog_id Blog ID. |
| 67 |
* @return int Post count |
| 68 |
*/ |
| 69 |
function get_tptn_daily_count( $post = 0, $blog_id = 0 ) { |
| 70 |
return get_tptn_post_count_only( $post, 'daily', $blog_id ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Returns the overall post count. |
| 75 |
* |
| 76 |
* @since 4.0.0 |
| 77 |
* @param int $blog_id Blog ID. |
| 78 |
* @return int Post count |
| 79 |
*/ |
| 80 |
function get_tptn_overall_count( $blog_id = 0 ) { |
| 81 |
return get_tptn_post_count_only( 0, 'overall', $blog_id ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Retrieves an array of the related posts. |
| 86 |
* |
| 87 |
* The defaults are as follows: |
| 88 |
* |
| 89 |
* @since 3.0.0 |
| 90 |
* |
| 91 |
* @see Top_Ten_Query::prepare_query_args() |
| 92 |
* |
| 93 |
* @param array $args Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments. |
| 94 |
* @return WP_Post[]|int[] Array of post objects or post IDs. |
| 95 |
*/ |
| 96 |
function get_tptn_posts( $args = array() ) { |
| 97 |
return \WebberZone\Top_Ten\Frontend\Display::get_posts( $args ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Function to return formatted list of popular posts. |
| 102 |
* |
| 103 |
* @since 1.5 |
| 104 |
* |
| 105 |
* @param mixed $args Arguments array. |
| 106 |
* @return string HTML output of the popular posts. |
| 107 |
*/ |
| 108 |
function tptn_pop_posts( $args ) { |
| 109 |
return \WebberZone\Top_Ten\Frontend\Display::pop_posts( $args ); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Function to echo popular posts. |
| 114 |
* |
| 115 |
* @since 1.0 |
| 116 |
* |
| 117 |
* @param mixed $args Arguments list. |
| 118 |
*/ |
| 119 |
function tptn_show_pop_posts( $args = array() ) { |
| 120 |
$defaults = array( |
| 121 |
'is_manual' => true, |
| 122 |
); |
| 123 |
$args = wp_parse_args( $args, $defaults ); |
| 124 |
echo tptn_pop_posts( $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
/** |
| 129 |
* Function to show daily popular posts. |
| 130 |
* |
| 131 |
* @since 1.2 |
| 132 |
* |
| 133 |
* @param mixed $args Arguments list. |
| 134 |
*/ |
| 135 |
function tptn_show_daily_pop_posts( $args = array() ) { |
| 136 |
$defaults = array( |
| 137 |
'daily' => true, |
| 138 |
); |
| 139 |
$args = wp_parse_args( $args, $defaults ); |
| 140 |
|
| 141 |
tptn_show_pop_posts( $args ); |
| 142 |
} |
| 143 |
|