PluginProbe
Snippet Shortcodes / 5.0a
Snippet Shortcodes v5.0a
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 / marketing.php

marketing.php in Snippet Shortcodes 5.0a, at includes/marketing.php

447 lines 24.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die('Jog on!');
4
5 /**
6 * If we think we have a valid license, but the Premium plugin hasn't been installed then prompt the user to.
7 */
8 function sh_cd_prompt_to_install_premium() {
9
10 if ( true === sh_cd_is_premium_plugin_activated() ) {
11 return;
12 }
13
14 if ( false === (bool) get_option( 'sh-cd-license-valid', false ) ) {
15 return;
16 }
17
18 if ( false === empty( $_GET['dismiss-premium'] ) ) {
19 sh_cd_marketing_prompt_been_dismissed( '_yeken_shortcode_variables_install_premium_has_been_dismissed', 1 );
20 return;
21 }
22
23 if ( false === empty( sh_cd_marketing_prompt_been_dismissed( '_yeken_shortcode_variables_install_premium_has_been_dismissed' ) ) ) {
24 return;
25 }
26
27 $dismiss_url = add_query_arg( [ 'dismiss-premium' => 1 ], sh_cd_get_current_url() );
28
29 printf('<div class="notice notice-warning">
30 <p><strong>%1$s</strong>: %2$s</p>
31 <p>
32 %3$s
33 <a href="%4$s" class="button">%5$s</a>
34 </p>
35 </div>',
36 esc_html( SH_CD_PLUGIN_NAME ),
37 __( 'Shortcode Snippets now consists of two plugins: the one you currently have installed, and an additional plugin called <strong>"Snippet Shortcodes – Premium."</strong> You\'re seeing this message because it appears you may already have a Premium license. If that\'s the case, be sure to download and install the Premium plugin to continue accessing all Premium features.', SH_CD_SLUG ),
38 sh_cd_premium_shortcode_download( true ),
39 $dismiss_url,
40 __( 'Dismiss', SH_CD_SLUG ),
41 );
42 }
43 add_action( 'admin_notices', 'sh_cd_prompt_to_install_premium' );
44
45 /**
46 * If we think the premium plugin is installed, but not the latest version then prompt
47 */
48 function sh_cd_prompt_to_upgrade_premium() {
49
50 if ( false === sh_cd_is_premium_plugin_activated() ) {
51 return;
52 }
53
54 if ( SH_CD_PREMIUM_PLUGIN_LATEST_VERSION === YK_SS_PLUGIN_VERSION ) {
55 return;
56 }
57
58 if ( false === empty( $_GET[ 'dismiss-premium-upgrade' ] ) ) {
59 sh_cd_marketing_prompt_been_dismissed( '_yeken_shortcode_variables_upgrade_premium_has_been_dismissed', $_GET[ 'dismiss-premium-upgrade' ] );
60 return;
61 }
62
63 $version_dismissed = sh_cd_marketing_prompt_been_dismissed( '_yeken_shortcode_variables_upgrade_premium_has_been_dismissed' );
64
65 if ( false !== empty( $version_dimissed ) && $version_dismissed === SH_CD_PREMIUM_PLUGIN_LATEST_VERSION ) {
66 return;
67 }
68
69 $dismiss_url = add_query_arg( [ 'dismiss-premium-upgrade' => SH_CD_PREMIUM_PLUGIN_LATEST_VERSION ], sh_cd_get_current_url() );
70
71 printf('<div class="notice notice-warning">
72 <p><strong>%1$s</strong>: %2$s</p>
73 <p>
74 <a href="%3$s" class="button">%6$s</a>
75 %7$s
76 <a href="%4$s" class="button">%5$s</a>
77 </p>
78 </div>',
79 esc_html( SH_CD_PLUGIN_NAME ),
80 __( 'A newer version of <strong>"Snippet Shortcodes – Premium"</strong> is available. Please update it from the Plugins screen to access the latest features and bug fixes.', SH_CD_SLUG ),
81 esc_url( admin_url('plugins.php') ),
82 $dismiss_url,
83 __( 'Dismiss', SH_CD_SLUG ),
84 __( 'Update to ', SH_CD_SLUG ) . SH_CD_PREMIUM_PLUGIN_LATEST_VERSION,
85 sh_cd_premium_shortcode_download( true ),
86 );
87 }
88 add_action( 'admin_notices', 'sh_cd_prompt_to_upgrade_premium' );
89
90 /**
91 * Save the fact the user has dismissed the prompt to install the premium plugin
92 */
93 function sh_cd_marketing_prompt_been_dismissed( $key, $value = NULL ) {
94
95 if ( NULL !== $value ) {
96 update_option( $key, $value );
97 }
98
99 return get_option( $key ) ;
100 }
101
102 /**
103 * Return a link to the upgrade page
104 *
105 * @return string
106 */
107 function sh_cd_license_upgrade_link() {
108
109 $link = admin_url('admin.php?page=sh-cd-shortcode-variables-upgrade');
110
111 return esc_url( $link );
112 }
113
114 /**
115 * Return a list of all premium features
116 * @return array
117 */
118 function sh_cd_premium_features_list() {
119
120 return [
121 [ 'title' => 'No limits', 'description' => 'Create unlimited custom shortcodes.', 'read-more-url' => '' ],
122 [ 'title' => 'Inline editor', 'description' => 'Ability to edit custom shortcodes without having to use a full editor.', 'read-more-url' => '' ],
123 [ 'title' => 'Duplicator', 'description' => 'Ability to duplicate custom shortcodes.', 'read-more-url' => '' ],
124 [ 'title' => 'Enable/Disable', 'description' => 'Ability to enable or disable custom shortcodes.', 'read-more-url' => '' ],
125 [ 'title' => 'Multi-site', 'description' => 'Use custom shortcodes throughout your entire multi-site, not just limited to the one child site', 'read-more-url' => '' ],
126 [ 'title' => 'CSV import', 'description' => 'Bulk import your custom shortcodes.', 'read-more-url' => 'https://snippet-shortcodes.yeken.uk/csv-import.html' ],
127 [ 'title' => 'WooCommerce fields', 'description' => 'A ready-made shortcode to display WooCommerce fields.', 'read-more-url' => 'https://snippet-shortcodes.yeken.uk/shortcodes/sc-woocommerce.html' ],
128 [ 'title' => 'Fetch values from database', 'description' => 'A ready-made shortcode to fetch a value from any database table', 'read-more-url' => 'https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html' ],
129 [ 'title' => 'More out-of-the-box shortcodes', 'description' => 'Display additional WordPress fields, as well as wrapping around PHP functionality like GET/POST values, number of users, etc', 'read-more-url' => 'https://snippet-shortcodes.yeken.uk/shortcodes-premium.html' ]
130
131 // [ 'title' => '', 'description' => '', 'read-more-url' => '' ],
132 ];
133
134 }
135 /**
136 * Return a list of slugs / titles for free presets
137 * @return array
138 */
139 function sh_cd_shortcode_presets_premium_list() {
140
141 return [
142 'db-value-by-id' => [ 'class' => 'SC_DB_VALUE_BY_ID', 'description' => __( 'Return a column value from a MySQL database for the given ID of search criteria e.g. <a href="https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html" rel="noopener" target="_blank">[sv slug="db-value-by-id" table="users" column="user_login" column-to-search="id" key="3" key-format="%d"]</a>', SH_CD_SLUG ), 'premium' => true, 'args' => [ '_sh_cd_func' => 'by-id' ] ],
143 'date' => [ 'class' => 'SC_DATE', 'description' => __( 'A shortcode that displays today\'s date with the ability to add or subtract days, months and years. To specify an interval to add or subtract onto the date use the parameter "interval" e.g. [sv slug="date" interval="-1 year"], [sv slug="date" interval="+5 days"], [sv slug="date" interval="+3 months"]. Intervals are based upon PHP intervals and are outlined here <a href="https://www.php.net/manual/en/dateinterval.createfromdatestring.php" target="_blank">https://www.php.net/manual/en/dateinterval.createfromdatestring.php</a>. Default is UK format (DD/MM/YYYY). Format can be changed by adding the parameter format="m/d/Y" onto the shortcode. Format syntax is based upon PHP date: <a href="http://php.net/manual/en/function.date.php" target="_blank">http://php.net/manual/en/function.date.php</a>', SH_CD_SLUG ), 'premium' => true ],
144 'site-language' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Language code for the current site', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'language' ], 'premium' => true ],
145 'site-description' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Site tagline (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'description' ], 'premium' => true ],
146 'site-wp-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The WordPress address (URL) (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'wpurl' ], 'premium' => true ],
147 'site-charset' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The "Encoding for pages and feeds" (set in Settings > Reading)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'charset' ], 'premium' => true ],
148 'site-wp-version' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The current WordPress version', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'version' ], 'premium' => true ],
149 'site-html-type' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The content-type (default: "text/html"). Themes and plugins', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'html_type' ], 'premium' => true ],
150 'site-stylesheet-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'URL to the stylesheet for the active theme.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'stylesheet_url' ], 'premium' => true ],
151 'site-stylesheet_directory' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Directory path for the active theme.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'stylesheet_directory' ], 'premium' => true ],
152 'site-current-url' => [ 'class' => 'SC_CURRENT_URL', 'description' => __( 'Get the current URL.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'current_url' ], 'premium' => true],
153 'site-register-url' => [ 'class' => 'SC_REGISTER_URL', 'description' => __( 'Get the URL to the WordPress registration page.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'registration_url' ], 'premium' => true],
154 'site-template-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The URL of the active theme\'s directory.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'template_url' ], 'premium' => true],
155 'site-pingback-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The pingback XML-RPC file URL (xmlrpc.php)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'pingback_url' ], 'premium' => true ],
156 'site-atom-feed' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The Atom feed URL (/feed/atom)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'atom_url' ], 'premium' => true ],
157 'site-rdf-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The RDF/RSS 1.0 feed URL (/feed/rfd)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'rdf_url' ], 'premium' => true ],
158 'site-rss-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The RSS 0.92 feed URL (/feed/rss)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'rss_url' ], 'premium' => true ],
159 'site-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The RSS 2.0 feed URL (/feed)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'rss2_url' ], 'premium' => true ],
160 'site-comments-atom-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The comments Atom feed URL (/comments/feed)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'comments_atom_url' ], 'premium' => true ],
161 'site-comments-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The comments RSS 2.0 feed URL (/comments/feed)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'comments_rss2_url' ], 'premium' => true ],
162 'php-server-info' => [ 'class' => 'SC_SERVER_INFO', 'description' => __( 'Display data from the PHP $_SERVER global e.g. [sv slug="server-info" field="SERVER_SOFTWARE"]. <a href="http://php.net/manual/en/reserved.variables.server.php" rel="noopener" target="_blank">Allowed values for field attribute</a>.', SH_CD_SLUG ), 'premium' => true ],
163 'php-unique-id' => [ 'class' => 'SC_UNIQUE_ID', 'description' => __( 'Generate a unique ID. Based upon <a href="http://php.net/manual/en/function.uniqid.php" rel="noopener" target="_blank">uniqid()</a>. If you wish the unique ID to be prefixed, add a the prefix attribute e.g. [sv slug="php-unique-id" prefix="yeken"]', SH_CD_SLUG ), 'premium' => true ],
164 'php-timestamp' => [ 'class' => 'SC_TIMESTAMP', 'description' => __( 'Display the current unix timestamp. Based upon <a href="http://php.net/manual/en/function.time.php" rel="noopener" target="_blank">time()</a>.', SH_CD_SLUG ), 'premium' => true ],
165 'php-random-number' => [ 'class' => 'SC_RAND_NUMBER', 'description' => __( 'Display a random number. Based upon <a href="http://php.net/manual/en/function.rand.php" rel="noopener" target="_blank">rand()</a>. It also supports the optional arguments of min and max e.g. [sv slug="php-random-number" min="5" max="20" ]', SH_CD_SLUG ), 'premium' => true ],
166 'php-random-string' => [ 'class' => 'SC_RAND_STRING', 'description' => __( 'Display a random string of characters. It also supports the optional argument of "length". This specifies the number of characters you wish to display (default is 10) [sv slug="php-random-string" length="15"]', SH_CD_SLUG ), 'premium' => true ],
167 'php-post-value' => [ 'class' => 'SC_POST_VALUE', 'description' => __( 'Display a value from the $_POST array. The "key" arguments specifies which array value to render. It also supports the optional arguments of "default". If there is no value in the array for the given "key" then the "default" will be displayed. [sv slug="php-post-value" key="username" default="Not Found"]', SH_CD_SLUG ), 'premium' => true ],
168 'php-get-value' => [ 'class' => 'SC_GET_VALUE', 'description' => __( 'Display a value from the $_GET array. The "key" arguments specifies which array value to render. It also supports the optional arguments of "default". If there is no value in the array for the given "key" then the "default" will be displayed. [sv slug="php-get-value" key="username" default="Not Found"]', SH_CD_SLUG ), 'premium' => true ],
169 'php-info' => [ 'class' => 'SC_PHP_INFO', 'description' => __( 'Display PHP Info', SH_CD_SLUG ), 'premium' => true ],
170 'post-id' => [ 'class' => 'SC_POST_ID', 'description' => __( 'Display ID for the current post.', SH_CD_SLUG ), 'premium' => true ],
171 'post-author' => [ 'class' => 'SC_POST_AUTHOR', 'description' => __( 'Display the author\'s display name or ID. The optional argument "field" allows you to specify whether you wish to display the author\'s "display-name" or "id". [sv slug="post-author" field="id" ]', SH_CD_SLUG ), 'premium' => true ],
172 'post-counts' => [ 'class' => 'SC_POST_COUNTS', 'description' => __( 'Display a count of posts for certain statuses. Using the argument status, specify whether to return a count for all posts that have a status of "publish" (default), "future", "draft", "pending" or "private". [sv slug="post-counts" status="draft"]', SH_CD_SLUG ), 'premium' => true ],
173 'user-counts' => [ 'class' => 'SC_USER_COUNTS', 'description' => __( 'Display a count of all WordPress users or the number of WordPress users for a given role e.g. [sv slug="user-counts" role="subscriber"] or [sv slug="user-counts"]', SH_CD_SLUG ), 'premium' => true ],
174 'user-profile-photo' => [ 'class' => 'SC_AVATAR', 'description' => __( 'Display the WordPress profile photo for the logged in user e.g. [sv slug="user-profile-photo" width="150"] or [sv slug="user-profile-photo"]. Please note, width defaults to 96px.', SH_CD_SLUG ), 'premium' => true ],
175 'user-meta' => [ 'class' => 'SC_USER_META', 'description' => __( 'Display a WordPress user meta field (wraps get_user_meta) field e.g. last_name. Read more: <a href="https://snippet-shortcodes.yeken.uk/shortcodes/sc-user-meta" rel="noopener" target="_blank">[sv slug="user-meta" field="last_name"]</a>', SH_CD_SLUG ), 'premium' => true ],
176 'woocommerce' => [ 'class' => 'SC_USER_META', 'description' => __( 'Display a Woocommerce user profile field e.g. billing_phone. Read more: <a href="https://snippet-shortcodes.yeken.uk/shortcodes/sc-woocommerce" rel="noopener" target="_blank">[sv slug="woocommerce" field="billing_phone"]</a>', SH_CD_SLUG ), 'premium' => true ]
177
178 // '' => [ 'class' => '', 'description' => '', 'premium' => true ]
179 ];
180 }
181
182 /**
183 * Return a list of slugs / titles for free presets
184 * @return array
185 */
186 function sh_cd_shortcode_presets_free_list() {
187
188 return [
189 'todays-date' => [ 'class' => 'SC_TODAYS_DATE', 'description' => __( 'Displays today\'s date. Default is UK format (DD/MM/YYYY). Format can be changed by adding the parameter format="m/d/Y" onto the shortcode. Format syntax is based upon PHP date: <a href="http://php.net/manual/en/function.date.php" target="_blank">http://php.net/manual/en/function.date.php</a>', SH_CD_SLUG ) ],
190 'user-ip' => [ 'class' => 'SC_USER_IP', 'description' => __( 'Display the current user\'s IP address.', SH_CD_SLUG )],
191 'user-agent' => [ 'class' => 'SC_USER_AGENT', 'description' => __( 'Display the current user\'s User Agent', SH_CD_SLUG ) ],
192 'site-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The Site address (URL) (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'url' ] ],
193 'site-title' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Displays the site title.', SH_CD_SLUG ) ],
194 'admin-email' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Admin email (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'admin_email' ] ],
195 'page-title' => [ 'class' => 'SC_PAGE_TITLE', 'description' => __( 'Displays the page title.', SH_CD_SLUG ) ],
196 'login-page' => [ 'class' => 'SC_LOGIN_PAGE', 'description' => __( 'Wordpress login page. Add the parameter "redirect" to specify where the user is taken after a successful login e.g. redirect="http://www.google.co.uk".', SH_CD_SLUG ) ],
197 'privacy-url' => [ 'class' => 'SC_POLICY_URL', 'description' => __( 'Displays the privacy page URL.', SH_CD_SLUG ) ],
198 'username' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the logged in username.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_login' ] ],
199 'user-id' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s ID.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'ID' ] ],
200 'user-email' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s email address.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_email' ] ],
201 'first-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s username.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_firstname' ] ],
202 'last-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s last name.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_lastname' ] ],
203 'display-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s display name.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'display_name' ] ]
204 ];
205
206 // '' => [ 'class' => '', 'description' => '', 'args' => [ '_sh_cd_func' => 'admin_email' ] ]
207 }
208
209 /**
210 * Display a table of premium features
211 *
212 * @return string
213 */
214 function sh_cd_display_premium( $list = false ) {
215
216 $premium_user = sh_cd_is_premium();
217 $upgrade_link = sprintf( '<a class="button sh-cd-upgrade-button" href="%1$s"><i class="fas fa-check"></i> %2$s</a>', sh_cd_license_upgrade_link(), __('Upgrade now', SH_CD_SLUG ) );
218
219 $html = ( $list ) ? '<ul class="sh-cd-promo-list">' :
220 sprintf('<table class="widefat sh-cd-table" width="100%%">
221 <tr class="row-title">
222 <th class="row-title" width="30%%">%s</th>
223 <th width="*">%s</th>
224 </tr>
225 ', __('Premium Feature', SH_CD_SLUG ),
226 __('Description', SH_CD_SLUG )
227 );
228
229 $class = '';
230
231 foreach ( sh_cd_premium_features_list() as $feature ) {
232
233 $class = ($class == 'alternate') ? '' : 'alternate';
234
235 $title = ( empty( $feature[ 'read-more-url' ] ) ) ? esc_html( $feature[ 'title' ] ) : sprintf( '<a href="%s" target="_blank" rel="noopener">%s</a>', esc_url( $feature[ 'read-more-url' ] ), esc_html( $feature[ 'title' ] ) );
236
237 $template = ( $list ) ? '<li class="%s"><span>%s</span> - %s</li>' :
238 '<tr class="%s">
239 <td class="sh-cd-bold">%s</td>
240 <td>%s</td>
241 </tr>';
242
243 $html .= sprintf( $template,
244 $class,
245 $title,
246 esc_html( $feature[ 'description' ] )
247 );
248 }
249
250 $html .= ( $list ) ? '</ul>' : '</table>';
251
252 return $html;
253 }
254
255 /**
256 * Display a table of premade shortcodes
257 *
258 * @param string $display
259 * @return string
260 */
261 function sh_cd_display_premade_shortcodes( $display = 'all' ) {
262
263 $premium_user = sh_cd_is_premium();
264 $upgrade_link = sprintf( '<a class="button sh-cd-upgrade-button" href="%1$s"><i class="fa-regular fa-star"></i> %2$s</a>', sh_cd_license_upgrade_link(), __('Upgrade now', SH_CD_SLUG ) );
265
266 switch ( $display ) {
267 case 'free':
268 $shortcodes = sh_cd_shortcode_presets_free_list();
269 $show_premium_col = false;
270 break;
271 case 'premium':
272 $shortcodes = sh_cd_shortcode_presets_premium_list();
273 $show_premium_col = false;
274 break;
275 default:
276 $shortcodes = sh_cd_presets_both_lists();
277 $show_premium_col = true;
278 }
279
280 $html = sprintf('<table class="widefat sh-cd-table" width="100%%">
281 <tr class="row-title">
282 <th class="row-title" width="30%%">%s</th>', __('Shortcode', SH_CD_SLUG ) );
283
284 if ( true === $show_premium_col) {
285 $html .= sprintf( '<th class="row-title">%s</th>', __('Premium', SH_CD_SLUG ) );
286 }
287
288 $html .= sprintf( '<th width="*">%s</th>
289 </tr>', __('Description', SH_CD_SLUG ) );
290
291 $class = '';
292
293 foreach ( $shortcodes as $key => $data ) {
294
295 $class = ($class == 'alternate') ? '' : 'alternate';
296
297 $shortcode = '[' . SH_CD_SHORTCODE. ' slug=&quot;' . $key . '&quot;]';
298
299 $premium_shortcode = ( true === isset( $data['premium'] ) && true === $data['premium'] );
300
301 $html .= sprintf( '<tr class="%s"><td>%s <i class="far fa-copy sh-cd-copy-trigger sh-cd-tooltip" data-clipboard-text="%2$s" title="%3$s"></i></td>',
302 $class,
303 esc_html( $shortcode ),
304 __( 'Copy to clipboard', SH_CD_SLUG )
305 );
306
307
308 if ( true === $show_premium_col) {
309
310 $html .= sprintf( '<td align="middle">%s%s</td>',
311 ( true === $premium_shortcode && true === $premium_user ) ? '<i class="fas fa-star"></i>' : '',
312 ( true == $premium_shortcode && false === $premium_user ) ? $upgrade_link : ''
313 );
314 }
315
316 $html .= sprintf( '<td>%s</td></tr>', wp_kses_post( $data['description'] ) );
317
318 }
319
320 $html .= '</table>';
321
322 return $html;
323 }
324
325 /**
326 * Display admin notice for notification from yeken.uk
327 */
328 function sh_cd_get_marketing_message() {
329
330 if ( $cache = get_transient( '_yeken_shortcode_variables_update1' ) ) {
331 return $cache;
332 }
333
334 $response = wp_remote_get( SH_CD_YEKEN_UPDATES_URL );
335
336 // All ok?
337 if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
338
339 $body = wp_remote_retrieve_body( $response );
340
341 if ( false === empty( $body ) ) {
342
343 $body = json_decode( $body, true );
344
345 set_transient( '_yeken_shortcode_variables_update', $body, HOUR_IN_SECONDS );
346
347 return $body;
348 }
349 }
350
351 return NULL;
352 }
353
354 /**
355 * Get/Set key of notice last dismissed.
356 */
357 function sh_cd_marketing_update_key_last_dismissed( $key = NULL ) {
358
359 if ( NULL !== $key ) {
360 update_option( '_yeken_shortcode_variables_update_key_last_dismissed', $key );
361 }
362
363 return (int) get_option( '_yeken_shortcode_variables_update_key_last_dismissed' ) ;
364
365 }
366
367 /**
368 * Display HTML for admin notice
369 */
370 function sh_cd_updates_display_notice( $json ) {
371
372 if ( false === is_array( $json ) ) {
373 return;
374 }
375
376 $button = '';
377
378 if ( !empty( $json[ 'url'] ) && !empty( $json[ 'url-title' ] ) ) {
379 $button = sprintf( '<p>
380 <a href="%1$s" class="button button-primary" target="_blank" rel="noopener">%2$s</a>
381 </p>',
382 esc_url( $json[ 'url' ] ),
383 sh_cd_wp_kses( $json[ 'url-title' ] )
384 );
385 }
386
387
388 printf('<div class="updated notice is-dismissible sh-cd-update-notice" data-update-key="%4$s" data-nonce="%5$s">
389 <p><strong>%1$s</strong>: %2$s</p>
390 %3$s
391 </div>',
392 esc_html( SH_CD_PLUGIN_NAME ),
393 !empty( $json[ 'message' ] ) ? esc_html( $json[ 'message' ] ) : '',
394 $button,
395 esc_html( $json[ '_update_key' ] ),
396 esc_attr( wp_create_nonce( 'sh-cd-nonce' ) )
397 );
398 }
399
400 /**
401 * display and admin notice if one exists and hasn't been dismissed already.
402 */
403 function sh_cd_updates_admin_notice() {
404
405 $json = sh_cd_get_marketing_message();
406
407 if ( true === empty( $json ) ) {
408 return false;
409 }
410
411 if ( $json[ '_update_key' ] <> sh_cd_marketing_update_key_last_dismissed() ) {
412 sh_cd_updates_display_notice( $json );
413 }
414 }
415 add_action( 'admin_notices', 'sh_cd_updates_admin_notice' );
416
417 /**
418 * Ajax handler to dismiss setup wizard
419 */
420 function sh_cd_updates_ajax_dismiss() {
421
422 check_ajax_referer( 'sh-cd-nonce', 'security' );
423
424 if ( true === empty( $_POST[ 'update_key' ] ) ) {
425 return;
426 }
427
428 $update_key = (int) $_POST[ 'update_key' ];
429
430 if ( false === empty( $update_key ) ) {
431 sh_cd_marketing_update_key_last_dismissed( $update_key );
432 }
433 }
434 add_action( 'wp_ajax_sh_cd_dismiss_notice', 'sh_cd_updates_ajax_dismiss' );
435
436 /**
437 * Text to display on upgrade and license page
438 */
439 function sh_cd_marketing_upgrade_page_text() {
440 ?>
441 <h4 class="sh-cd-promo"><i class="fa-regular fa-star"></i> <?php echo __( 'Unlock these extra features when you upgrade:', SH_CD_SLUG ); ?></h4>
442 <?php echo sh_cd_display_premium(); ?>
443 <h4 class="sh-cd-promo"><i class="fa-regular fa-star"></i> <?php echo __( 'Extra Premium shortcodes', SH_CD_SLUG ); ?>:</h4>
444 <p><?php echo __( 'Upgrade to the Premium version of Snippet Shortcodes to unlock these additional shortcodes.', SH_CD_SLUG ); ?>:</p>
445 <?php echo sh_cd_display_premade_shortcodes( 'premium' ); ?>
446 <?php
447 }