PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.2.27
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.2.27
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / CampaignShortcode.php

CampaignShortcode.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.2.27, at includes/CampaignShortcode.php

76 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer;
4
5 class CampaignShortcode
6 {
7
8 /**
9 * Init shortcode
10 */
11 function init()
12 {
13 add_shortcode( 'hurrytimer', [ $this, 'content' ] );
14 add_filter( 'pre_do_shortcode_tag', [ $this, 'maybe_display' ], 10, 3 );
15 }
16
17 /**
18 *
19 * @param $return
20 * @param $tag
21 * @param $attr
22 *
23 * @return mixed|string|void
24 */
25 function maybe_display( $return, $tag, $attr )
26 {
27
28 if ( $tag !== 'hurrytimer' ) {
29 return $return;
30 }
31 $id = wp_parse_args( $attr, [ 'id' => -1 ] )[ 'id' ];
32
33 // Nothing to display if the campaign doesn't exist.
34 if ( !get_post( $id ) ) {
35 return __( 'HurryTimer: Invalid campaign ID.', 'hurrytimer' );
36 }
37 $campaign = hurryt_get_campaign( $id );
38
39 if ( !$campaign->is_running() ) {
40
41 // Show something else.
42 return apply_filters( 'hurryt_no_campaign', '', $campaign->get_id() );
43 }
44
45 // Let developer decide whether to show the campaign or not.
46 if ( !apply_filters( 'hurryt_show_campaign', true, $campaign->get_id() ) ) {
47 return '';
48 }
49
50 return $return;
51 }
52
53 /**
54 * Return shortcode content.
55 *
56 * @param $attrs
57 *
58 * @return string
59 */
60 public function content( $attrs )
61 {
62
63 $campaign = hurryt_get_campaign( absint( $attrs[ 'id' ] ) );
64
65 if ( $campaign->is_expired() ) {
66 (new ActionManager( $campaign ))->run();
67 }
68
69 $template = apply_filters( 'hurryt_campaign_template', $campaign->build_template(), $campaign->get_id() );
70
71 return !empty( $template ) ? $campaign->wrap_template( $template ) : '';
72 }
73
74
75 }
76