PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.4
WebberZone Top 10 — Popular Posts v4.3.4
4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 All 117 releases
top-10 / includes / frontend / class-shortcodes.php

class-shortcodes.php in WebberZone Top 10 — Popular Posts 4.3.4, at includes/frontend/class-shortcodes.php

103 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 global $tptn_settings;
42
43 $wp_query_args = \WebberZone\Top_Ten\Util\Helpers::get_wp_query_arguments();
44
45 $default_atts = array(
46 'heading' => 1,
47 'daily' => 0,
48 'is_shortcode' => 1,
49 'offset' => 0,
50 'include_cat_ids' => '',
51 'blog_id' => get_current_blog_id(),
52 );
53
54 /**
55 * Filter the default shortcode attributes.
56 *
57 * @since 4.0.0
58 *
59 * @param array $default_atts Default shortcode attributes.
60 */
61 $default_atts = apply_filters( 'tptn_shortcode_defaults', $default_atts );
62
63 $atts = shortcode_atts(
64 array_merge(
65 $tptn_settings,
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