| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcodes class. |
| 4 |
* |
| 5 |
* @package WebberZone\Top_Ten\Frontend |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WebberZone\Top_Ten\Frontend; |
| 9 |
|
| 10 |
if ( ! defined( 'WPINC' ) ) { |
| 11 |
die; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Shortcodes Class. |
| 16 |
* |
| 17 |
* @since 3.3.0 |
| 18 |
*/ |
| 19 |
class Shortcodes { |
| 20 |
|
| 21 |
/** |
| 22 |
* Constructor class. |
| 23 |
* |
| 24 |
* @since 3.3.0 |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
add_shortcode( 'tptn_list', array( __CLASS__, 'tptn_list' ) ); |
| 28 |
add_shortcode( 'tptn_views', array( __CLASS__, 'tptn_views' ) ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Creates a shortcode [tptn_list limit="5" heading="1" daily="0"]. |
| 33 |
* |
| 34 |
* @since 3.3.0 |
| 35 |
* |
| 36 |
* @param array $atts Shortcode attributes. |
| 37 |
* @param string $content Content. |
| 38 |
* @return string Formatted list of posts generated by tptn_pop_posts |
| 39 |
*/ |
| 40 |
public static function tptn_list( $atts, $content = null ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed |
| 41 |
$wp_query_args = \WebberZone\Top_Ten\Util\Helpers::get_wp_query_arguments(); |
| 42 |
|
| 43 |
$default_atts = array( |
| 44 |
'heading' => 1, |
| 45 |
'daily' => 0, |
| 46 |
'is_shortcode' => 1, |
| 47 |
'offset' => 0, |
| 48 |
'include_cat_ids' => '', |
| 49 |
'blog_id' => get_current_blog_id(), |
| 50 |
); |
| 51 |
|
| 52 |
/** |
| 53 |
* Filter the default shortcode attributes. |
| 54 |
* |
| 55 |
* @since 4.0.0 |
| 56 |
* @since 4.5.0 Added the `$atts` parameter. |
| 57 |
* |
| 58 |
* @param array $default_atts Default shortcode attributes. |
| 59 |
* @param array $atts Shortcode attributes. |
| 60 |
*/ |
| 61 |
$default_atts = apply_filters( 'tptn_shortcode_defaults', $default_atts, $atts ); |
| 62 |
|
| 63 |
$atts = shortcode_atts( |
| 64 |
array_merge( |
| 65 |
\tptn_get_settings_with_defaults(), |
| 66 |
$wp_query_args, |
| 67 |
$default_atts |
| 68 |
), |
| 69 |
$atts, |
| 70 |
'top-10' |
| 71 |
); |
| 72 |
|
| 73 |
return \WebberZone\Top_Ten\Frontend\Display::pop_posts( $atts ); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Creates a shortcode [tptn_views daily="0"]. |
| 78 |
* |
| 79 |
* @since 3.3.0 |
| 80 |
* |
| 81 |
* @param array $atts Shortcode attributes. |
| 82 |
* @param string $content Content. |
| 83 |
* @param string $tag Shortcode tag. |
| 84 |
* @return string Views of the post. |
| 85 |
*/ |
| 86 |
public static function tptn_views( $atts, $content = null, $tag = '' ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed |
| 87 |
$a = shortcode_atts( |
| 88 |
array( |
| 89 |
'daily' => '0', |
| 90 |
'count' => 'total', |
| 91 |
'format_number' => true, |
| 92 |
'post_id' => get_the_ID(), |
| 93 |
), |
| 94 |
$atts |
| 95 |
); |
| 96 |
|
| 97 |
// If daily is explicitly set to 1, then pass daily, else pass count. |
| 98 |
$count = $a['daily'] ? 'daily' : $a['count']; |
| 99 |
|
| 100 |
return (string) \WebberZone\Top_Ten\Counter::get_post_count_only( $a['post_id'], $count, 0, array( 'format_number' => $a['format_number'] ) ); |
| 101 |
} |
| 102 |
} |
| 103 |
|