PluginProbe
Snippet Shortcodes / 5.1
Snippet Shortcodes v5.1
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
shortcode-variables / includes / shortcode.marketing.php

shortcode.marketing.php in Snippet Shortcodes 5.1, at includes/shortcode.marketing.php

183 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Render text file for promo
5 */
6 function sh_cd_shortcode_render_text() {
7
8 $output = '**Premium Shortcodes**' . PHP_EOL;
9
10 $shortcodes = sh_cd_shortcode_presets_premium_list();
11
12 foreach ( $shortcodes as $key => $data ) {
13 $output .= sprintf('- %s - %s' . PHP_EOL , $key, $data['description'] );
14 }
15
16 $output .= '**Free Shortcodes**' . PHP_EOL;
17
18 $shortcodes = sh_cd_shortcode_presets_free_list();
19
20 foreach ( $shortcodes as $key => $data ) {
21 $output .= sprintf('- %s - %s' . PHP_EOL , $key, $data['description'] );
22 }
23
24 return $output;
25
26 }
27 add_shortcode( 'sv-promo', 'sh_cd_shortcode_render_text' );
28
29 /**
30 * Shortcode to render free shortcodes (more for promo purposes)
31 *
32 * @return string
33 */
34 function sh_cd_shortcode_render_table_free() {
35
36 return sh_cd_display_premade_shortcodes( 'free' );
37
38 }
39 add_shortcode( 'sv-promo-free', 'sh_cd_shortcode_render_table_free');
40
41 /**
42 * Shortcode to render premium shortcodes (more for promo purposes)
43 *
44 * @return string
45 */
46 function sh_cd_shortcode_render_table_premium() {
47
48 return sh_cd_display_premade_shortcodes( 'premium' );
49
50 }
51 add_shortcode( 'sv-promo-premium', 'sh_cd_shortcode_render_table_premium');
52
53 /**
54 * Shortcode to render premium shortcodes (more for promo purposes)
55 *
56 * @return string
57 */
58 function sh_cd_shortcode_version() {
59
60 return SH_CD_PLUGIN_VERSION;
61
62 }
63 add_shortcode( 'sv-version', 'sh_cd_shortcode_version');
64
65 /**
66 * Shortcode to render premium features
67 *
68 * @return string
69 */
70 function sh_cd_shortcode_render_table_premium_features() {
71
72 return sh_cd_display_premium( true );
73
74 }
75 add_shortcode( 'sv-promo-premium-features', 'sh_cd_shortcode_render_table_premium_features');
76
77 /**
78 * Return Premode shortcodes as a list
79 *
80 * @return string
81 */
82 function sh_cd_display_premade_premium_shortcodes_as_ul() {
83
84 $shortcodes = sh_cd_shortcode_presets_premium_list();
85 $html = '<ul class="sh-cd-promo-list">';
86
87 foreach ( $shortcodes as $key => $data ) {
88 $html .= sprintf( '<li><span>%s</span> - %s</li>', $shortcode = '[' . SH_CD_SHORTCODE. ' slug="' . $key . '"]', wp_kses_post( $data['description'] ) );
89 }
90
91 $html .= '</ul>';
92
93 return $html;
94 }
95 add_shortcode( 'sv-promo-premium-shortcodes-as-list', 'sh_cd_display_premade_premium_shortcodes_as_ul');
96
97 /**
98 * Shortcode to render all shortcodes (more for promo purposes)
99 *
100 * @return string
101 */
102 function sh_cd_shortcode_render_table_all() {
103
104 return sh_cd_display_premade_shortcodes();
105
106 }
107 add_shortcode( 'sv-promo-all', 'sh_cd_shortcode_render_table_all');
108
109 /**
110 * Fetch license price
111 *
112 * @return float|null
113 */
114 function sh_cd_license_price() {
115
116 $price = yeken_license_price( 'sv-premium' );
117
118 return ( false === empty( $price ) ) ? $price : '(Error fetching price)';
119 }
120
121 if ( false === function_exists( 'yeken_license_api_fetch_licenses' ) ) {
122
123 /**
124 * Call out to YeKen API for license prices
125 */
126 function yeken_license_api_fetch_licenses() {
127
128 if ( $cache = get_transient( 'yeken_api_prices' ) ) {
129 return $cache;
130 }
131
132 $response = wp_remote_get( 'https://shop.yeken.uk/wp-json/yeken/v1/license-prices/' );
133
134 // All ok?
135 if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
136
137 $body = wp_remote_retrieve_body( $response );
138
139 if ( false === empty( $body ) ) {
140
141 $body = json_decode( $body, true );
142 set_transient( 'yeken_api_prices', $body, 216000 ); // Cache for 6 hours
143
144 return $body;
145 }
146 }
147
148 return NULL;
149 }
150
151 /**
152 * Fetch a certain product price
153 * @param $sku
154 * @param string $type
155 */
156 function yeken_license_price( $sku, $type = 'yearly' ) {
157
158 $licenses = yeken_license_api_fetch_licenses();
159
160 return ( false === empty( $licenses[ $sku ][ $type ] ) ) ? $licenses[ $sku ][ $type ] : NULL;
161 }
162
163 /**
164 * Render out license prices
165 *
166 * @param $args
167 * @return mixed|string
168 */
169 function yeken_license_shortcode( $args ) {
170
171 $args = wp_parse_args( $args, [ 'sku' => 'sv-premium', 'type' => 'yearly', 'prefix' => '&pound;' ] );
172
173 $price = yeken_license_price( $args[ 'sku' ], $args[ 'type' ] );
174
175 if ( false === empty( $price ) ) {
176 return sprintf( '%s%d', esc_html( $args[ 'prefix' ] ), $price );
177 }
178
179 return '';
180 }
181 add_shortcode( 'yeken-license-price', 'yeken_license_shortcode' );
182
183 }