PluginProbe
Snippet Shortcodes / 5.1.6
Snippet Shortcodes v5.1.6
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.1.6, at includes/marketing.php

521 lines 28.9 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 $latest_version = sh_cd_get_latest_premium_version();
55
56 if ( true === empty( $latest_version ) ) {
57 return;
58 }
59
60 if ( $latest_version === YK_SS_PLUGIN_VERSION ) {
61 return;
62 }
63
64 if ( false === empty( $_GET[ 'dismiss-premium-upgrade' ] ) ) {
65 sh_cd_marketing_prompt_been_dismissed( '_yeken_shortcode_variables_upgrade_premium_has_been_dismissed', $_GET[ 'dismiss-premium-upgrade' ] );
66 return;
67 }
68
69 $version_dismissed = sh_cd_marketing_prompt_been_dismissed( '_yeken_shortcode_variables_upgrade_premium_has_been_dismissed' );
70
71 if ( false === empty( $version_dismissed ) && $version_dismissed === $latest_version ) {
72 return;
73 }
74
75 $dismiss_url = add_query_arg( [ 'dismiss-premium-upgrade' => $latest_version ], sh_cd_get_current_url() );
76
77 printf('<div class="notice notice-warning">
78 <p><strong>%1$s</strong>: %2$s</p>
79 <p>
80 <a href="%3$s" class="button">%6$s</a>
81 %7$s
82 <a href="%4$s" class="button">%5$s</a>
83 </p>
84 </div>',
85 esc_html( SH_CD_PLUGIN_NAME ),
86 __( '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 ),
87 esc_url( admin_url('plugins.php') ),
88 $dismiss_url,
89 __( 'Dismiss', SH_CD_SLUG ),
90 __( 'Update both plugins via plugin screen', SH_CD_SLUG ),
91 sh_cd_premium_shortcode_download( true ),
92 );
93 }
94 add_action( 'admin_notices', 'sh_cd_prompt_to_upgrade_premium' );
95
96 /**
97 * Save the fact the user has dismissed the prompt to install the premium plugin
98 */
99 function sh_cd_marketing_prompt_been_dismissed( $key, $value = NULL ) {
100
101 if ( NULL !== $value ) {
102 update_option( $key, $value );
103 }
104
105 return get_option( $key ) ;
106 }
107
108 /**
109 * Return a link to the upgrade page
110 *
111 * @return string
112 */
113 function sh_cd_license_upgrade_link() {
114
115 $link = admin_url('admin.php?page=sh-cd-shortcode-variables-upgrade');
116
117 return esc_url( $link );
118 }
119
120 /**
121 * Return a list of all premium features
122 * @return array
123 */
124 function sh_cd_premium_features_list() {
125
126 return [
127 [ 'title' => 'Insert into header or footer', 'description' => 'Automaically insert your custom shortcode’s content into either your site’s header and/or footer.', 'read-more-url' => '' ],
128 [ 'title' => 'Limit header/footer to specific pages', 'description' => 'Restrict an auto-inserted header/footer shortcode to a chosen list of page slugs, instead of it appearing on every page.', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/interactive-blocks/auto-insert-into-header-footer' ],
129 [ 'title' => 'Limit to certain device types', 'description' => 'Specify whether your custom shortcode should only be visible on Mobile, Tablet, Desktop or all three.', 'read-more-url' => '' ],
130 [ 'title' => 'Limit to user roles', 'description' => 'Show a custom shortcode only to guests or to specific WordPress user roles.', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/role-targeting' ],
131 [ 'title' => 'Schedule visibility', 'description' => 'Optionally limit a custom shortcode to a start/end date and time window.', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/visibility-scheduling' ],
132 [ 'title' => 'Render-count analytics', 'description' => 'See how many times each custom shortcode has been rendered, right on the edit screen.', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/render-analytics' ],
133 [ 'title' => 'Content revision history', 'description' => 'Every save is kept as a revision (last 20 per shortcode), with one-click restore.', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/revision-history' ],
134 [ 'title' => 'No limits', 'description' => 'Create unlimited custom shortcodes.', 'read-more-url' => '' ],
135 [ 'title' => 'Inline editor', 'description' => 'Ability to edit custom shortcodes without having to use a full editor.', 'read-more-url' => '' ],
136 [ 'title' => 'Duplicator', 'description' => 'Ability to duplicate custom shortcodes.', 'read-more-url' => '' ],
137 [ 'title' => 'Enable/Disable', 'description' => 'Ability to enable or disable custom shortcodes.', 'read-more-url' => '' ],
138 [ 'title' => 'Multi-site', 'description' => 'Use custom shortcodes throughout your entire multi-site, not just limited to the one child site', 'read-more-url' => '' ],
139 [ 'title' => 'CSV import & export', 'description' => 'Bulk import your custom shortcodes, or export your entire collection to CSV.', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/csv-import' ],
140 [ 'title' => 'WooCommerce fields', 'description' => 'A ready-made shortcode to display WooCommerce fields.', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/ready-made/premium/woocommerce-meta-fields' ],
141 [ 'title' => 'Fetch values from database', 'description' => 'A ready-made shortcode to fetch a value from any database table', 'read-more-url' => 'https://yeken.gitbook.io/snippet-shortcodes/features/ready-made/premium/database-values-by-id' ],
142 [ 'title' => 'More ready-made 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://yeken.gitbook.io/snippet-shortcodes/features/ready-made/premium' ]
143
144 // [ 'title' => '', 'description' => '', 'read-more-url' => '' ],
145 ];
146
147 }
148 /**
149 * Return a list of slugs / titles for free presets
150 * @return array
151 */
152 function sh_cd_shortcode_presets_premium_list() {
153
154 return [
155 '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://yeken.gitbook.io/snippet-shortcodes/features/ready-made/premium/database-values-by-id" 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' ] ],
156 '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 ],
157 'site-language' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Language code for the current site', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'language' ], 'premium' => true ],
158 'site-description' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Site tagline (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'description' ], 'premium' => true ],
159 '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 ],
160 '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 ],
161 'site-wp-version' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The current WordPress version', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'version' ], 'premium' => true ],
162 '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 ],
163 '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 ],
164 '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 ],
165 'site-current-url' => [ 'class' => 'SC_CURRENT_URL', 'description' => __( 'Get the current URL.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'current_url' ], 'premium' => true],
166 '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],
167 '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],
168 '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 ],
169 '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 ],
170 '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 ],
171 '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 ],
172 '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 ],
173 '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 ],
174 '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 ],
175 '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 ],
176 '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 ],
177 '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 ],
178 '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 ],
179 '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 ],
180 '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 ],
181 '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 ],
182 'php-info' => [ 'class' => 'SC_PHP_INFO', 'description' => __( 'Display PHP Info', SH_CD_SLUG ), 'premium' => true ],
183 'post-id' => [ 'class' => 'SC_POST_ID', 'description' => __( 'Display ID for the current post.', SH_CD_SLUG ), 'premium' => true ],
184 '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 ],
185 '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 ],
186 '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 ],
187 '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 ],
188 '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://yeken.gitbook.io/snippet-shortcodes/features/ready-made/premium/wordpress-user-fields" rel="noopener" target="_blank">[sv slug="user-meta" field="last_name"]</a>', SH_CD_SLUG ), 'premium' => true ],
189 'woocommerce' => [ 'class' => 'SC_USER_META', 'description' => __( 'Display a Woocommerce user profile field e.g. billing_phone. Read more: <a href="https://yeken.gitbook.io/snippet-shortcodes/features/ready-made/premium/woocommerce-meta-fields" rel="noopener" target="_blank">[sv slug="woocommerce" field="billing_phone"]</a>', SH_CD_SLUG ), 'premium' => true ]
190
191 // '' => [ 'class' => '', 'description' => '', 'premium' => true ]
192 ];
193 }
194
195 /**
196 * Return a list of slugs / titles for free presets
197 * @return array
198 */
199 function sh_cd_shortcode_presets_free_list() {
200
201 return [
202 '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 ) ],
203 'user-ip' => [ 'class' => 'SC_USER_IP', 'description' => __( 'Display the current user\'s IP address.', SH_CD_SLUG )],
204 'user-agent' => [ 'class' => 'SC_USER_AGENT', 'description' => __( 'Display the current user\'s User Agent', SH_CD_SLUG ) ],
205 'site-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The Site address (URL) (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'url' ] ],
206 'site-title' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Displays the site title.', SH_CD_SLUG ) ],
207 'admin-email' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Admin email (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'admin_email' ] ],
208 'page-title' => [ 'class' => 'SC_PAGE_TITLE', 'description' => __( 'Displays the page title.', SH_CD_SLUG ) ],
209 '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 ) ],
210 'privacy-url' => [ 'class' => 'SC_POLICY_URL', 'description' => __( 'Displays the privacy page URL.', SH_CD_SLUG ) ],
211 'username' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the logged in username.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_login' ] ],
212 'user-id' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s ID.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'ID' ] ],
213 'user-email' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s email address.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_email' ] ],
214 'first-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s username.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_firstname' ] ],
215 'last-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s last name.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_lastname' ] ],
216 'display-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s display name.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'display_name' ] ]
217 ];
218
219 // '' => [ 'class' => '', 'description' => '', 'args' => [ '_sh_cd_func' => 'admin_email' ] ]
220 }
221
222 /**
223 * Display a table of premium features
224 *
225 * @return string
226 */
227 function sh_cd_display_premium( $list = false ) {
228
229 $premium_user = sh_cd_is_premium();
230 $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 ) );
231
232 $html = ( $list ) ? '<ul class="sh-cd-promo-list">' :
233 sprintf('<table class="widefat sh-cd-table" width="100%%">
234 <tr class="row-title">
235 <th class="row-title" width="30%%">%s</th>
236 <th width="*">%s</th>
237 </tr>
238 ', __('Premium Feature', SH_CD_SLUG ),
239 __('Description', SH_CD_SLUG )
240 );
241
242 $class = '';
243
244 foreach ( sh_cd_premium_features_list() as $feature ) {
245
246 $class = ($class == 'alternate') ? '' : 'alternate';
247
248 $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' ] ) );
249
250 $template = ( $list ) ? '<li class="%s"><span>%s</span> - %s</li>' :
251 '<tr class="%s">
252 <td class="sh-cd-bold">%s</td>
253 <td>%s</td>
254 </tr>';
255
256 $html .= sprintf( $template,
257 $class,
258 $title,
259 esc_html( $feature[ 'description' ] )
260 );
261 }
262
263 $html .= ( $list ) ? '</ul>' : '</table>';
264
265 return $html;
266 }
267
268 /**
269 * Display a table of premade shortcodes
270 *
271 * @param string $display
272 * @return string
273 */
274 function sh_cd_display_premade_shortcodes( $display = 'all' ) {
275
276 $premium_user = sh_cd_is_premium();
277 $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 ) );
278
279 switch ( $display ) {
280 case 'free':
281 $shortcodes = sh_cd_shortcode_presets_free_list();
282 $show_premium_col = false;
283 break;
284 case 'premium':
285 $shortcodes = sh_cd_shortcode_presets_premium_list();
286 $show_premium_col = false;
287 break;
288 default:
289 $shortcodes = sh_cd_presets_both_lists();
290 $show_premium_col = true;
291 }
292
293 $html = sprintf('<table class="widefat sh-cd-table" width="100%%">
294 <tr class="row-title">
295 <th class="row-title" width="30%%">%s</th>', __('Shortcode', SH_CD_SLUG ) );
296
297 if ( true === $show_premium_col) {
298 $html .= sprintf( '<th class="row-title">%s</th>', __('Premium', SH_CD_SLUG ) );
299 }
300
301 $html .= sprintf( '<th width="*">%s</th>
302 </tr>', __('Description', SH_CD_SLUG ) );
303
304 $class = '';
305
306 foreach ( $shortcodes as $key => $data ) {
307
308 $class = ($class == 'alternate') ? '' : 'alternate';
309
310 $shortcode = '[' . SH_CD_SHORTCODE. ' slug=&quot;' . $key . '&quot;]';
311
312 $premium_shortcode = ( true === isset( $data['premium'] ) && true === $data['premium'] );
313
314 $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>',
315 $class,
316 esc_html( $shortcode ),
317 __( 'Copy to clipboard', SH_CD_SLUG )
318 );
319
320
321 if ( true === $show_premium_col) {
322
323 $html .= sprintf( '<td align="middle">%s%s</td>',
324 ( true === $premium_shortcode && true === $premium_user ) ? '<i class="fas fa-star"></i>' : '',
325 ( true == $premium_shortcode && false === $premium_user ) ? $upgrade_link : ''
326 );
327 }
328
329 $html .= sprintf( '<td>%s</td></tr>', wp_kses_post( $data['description'] ) );
330
331 }
332
333 $html .= '</table>';
334
335 return $html;
336 }
337
338 /**
339 * Fetch the latest version of the premium plugin
340 */
341 function sh_cd_get_latest_premium_version() {
342
343 if ( $cache = get_transient( '_yeken_shortcode_variables_latest_premium_version' ) ) {
344 return $cache;
345 }
346
347 $response = wp_remote_get( SH_CD_YEKEN_PREMIUM_RELEASE_MANIFEST );
348 $version = NULL;
349
350 // All ok?
351 if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
352
353 $body = wp_remote_retrieve_body( $response );
354
355 if ( false === empty( $body ) ) {
356
357 $body = json_decode( $body, true );
358
359 $version = ( false === empty( $body[ 'version' ] ) ) ? $body[ 'version' ] : NULL;
360
361 set_transient( '_yeken_shortcode_variables_latest_premium_version', $version, DAY_IN_SECONDS );
362 }
363 }
364
365 return $version;
366 }
367
368 /**
369 * Display admin notice for notification from yeken.uk
370 */
371 function sh_cd_get_marketing_message() {
372
373 if ( $cache = get_transient( '_yeken_shortcode_variables_update' ) ) {
374 return $cache;
375 }
376
377 $response = wp_remote_get( SH_CD_YEKEN_UPDATES_URL );
378
379 // All ok?
380 if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
381
382 $body = wp_remote_retrieve_body( $response );
383
384 if ( false === empty( $body ) ) {
385 $body = json_decode( $body, true );
386
387 set_transient( '_yeken_shortcode_variables_update', $body, DAY_IN_SECONDS );
388
389 return $body;
390 }
391 }
392
393 return NULL;
394 }
395
396 /**
397 * Get/Set key of notice last dismissed.
398 */
399 function sh_cd_marketing_update_key_last_dismissed( $key = NULL ) {
400
401 if ( NULL !== $key ) {
402 update_option( '_yeken_shortcode_variables_update_key_last_dismissed', $key );
403 }
404
405 return (int) get_option( '_yeken_shortcode_variables_update_key_last_dismissed' ) ;
406
407 }
408
409 /**
410 * Display HTML for admin notice
411 */
412 function sh_cd_updates_display_notice( $json ) {
413
414 if ( false === is_array( $json ) ) {
415 return;
416 }
417
418 $button = '';
419
420 if ( !empty( $json[ 'url'] ) && !empty( $json[ 'url-title' ] ) ) {
421 $button = sprintf( '<p>
422 <a href="%1$s" class="button button-primary" target="_blank" rel="noopener">%2$s</a>
423 </p>',
424 esc_url( $json[ 'url' ] ),
425 sh_cd_wp_kses( $json[ 'url-title' ] )
426 );
427 }
428
429
430 printf('<div class="updated notice is-dismissible sh-cd-update-notice" data-update-key="%4$s" data-nonce="%5$s">
431 <p><strong>%1$s</strong>: %2$s</p>
432 %3$s
433 </div>',
434 esc_html( SH_CD_PLUGIN_NAME ),
435 !empty( $json[ 'message' ] ) ? esc_html( $json[ 'message' ] ) : '',
436 $button,
437 esc_html( $json[ '_update_key' ] ),
438 esc_attr( wp_create_nonce( 'sh-cd-nonce' ) )
439 );
440 }
441
442 /**
443 * display and admin notice if one exists and hasn't been dismissed already.
444 */
445 function sh_cd_updates_admin_notice() {
446
447 $json = sh_cd_get_marketing_message();
448
449 if ( true === empty( $json ) ) {
450 return false;
451 }
452
453 if ( $json[ '_update_key' ] <> sh_cd_marketing_update_key_last_dismissed() ) {
454 sh_cd_updates_display_notice( $json );
455 }
456 }
457 add_action( 'admin_notices', 'sh_cd_updates_admin_notice' );
458
459 /**
460 * Ajax handler to dismiss setup wizard
461 */
462 function sh_cd_updates_ajax_dismiss() {
463
464 check_ajax_referer( 'sh-cd-nonce', 'security' );
465
466 if ( true === empty( $_POST[ 'update_key' ] ) ) {
467 return;
468 }
469
470 $update_key = (int) $_POST[ 'update_key' ];
471
472 if ( false === empty( $update_key ) ) {
473 sh_cd_marketing_update_key_last_dismissed( $update_key );
474 }
475 }
476 add_action( 'wp_ajax_sh_cd_dismiss_notice', 'sh_cd_updates_ajax_dismiss' );
477
478 /**
479 * Text to display on upgrade and license page
480 */
481 function sh_cd_marketing_upgrade_page_text() {
482 ?>
483 <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>
484 <?php echo sh_cd_display_premium(); ?>
485 <h4 class="sh-cd-promo"><i class="fa-regular fa-star"></i> <?php echo __( 'Extra Premium shortcodes', SH_CD_SLUG ); ?>:</h4>
486 <p><?php echo __( 'Upgrade to the Premium version of Snippet Shortcodes to unlock these additional shortcodes.', SH_CD_SLUG ); ?>:</p>
487 <?php echo sh_cd_display_premade_shortcodes( 'premium' ); ?>
488 <?php
489 }
490
491 /**
492 * Marketing prompt to upgrade on Edit page to get additional shortcode options
493 *
494 * @return void
495 */
496 function sh_cd_marketing_page_edit_additional_options() {
497
498 $title = __( 'Unlock these additional settings by upgrading to Premium', SH_CD_SLUG ) ;
499
500 // A plain list rather than a fixed sprintf() placeholder count, so adding/removing an
501 // item later doesn't also require recounting %s tokens - see CLAUDE.md's note on keeping
502 // this in sync with new features.
503 $items = [
504 __( '<span>Insert into Header / Footer</span> - specify whether to automatically insert the shortcode content into the WP Header or Footer.', SH_CD_SLUG ),
505 __( '<span>Limit header/footer to specific pages</span> - restrict automatic header/footer insertion to a chosen list of page slugs, instead of it appearing on every page.', SH_CD_SLUG ),
506 __( '<span>Limit to mobile or desktop</span> - specify whether a shortcode should only appear on mobile or desktop devices.', SH_CD_SLUG ),
507 __( '<span>Limit to user roles</span> - show a shortcode only to guests or to specific WordPress user roles.', SH_CD_SLUG ),
508 __( '<span>Schedule visibility</span> - limit a shortcode to a start and/or end date and time window.', SH_CD_SLUG ),
509 __( '<span>Global shortcodes</span> - specify whether a shortcode should be available across all sites in your multisite network.', SH_CD_SLUG ),
510 __( '<span>Disable shortcodes</span> - have the ability to disable shortcodes so content will not appear at the location of the shortcode in the public facing site.', SH_CD_SLUG ),
511 __( '<span>Edit Slug</span> - have the ability to change the slug of an existing shortcode.', SH_CD_SLUG ),
512 __( '<span>Render-count analytics</span> - see how many times each shortcode has been rendered, right on this screen.', SH_CD_SLUG ),
513 __( '<span>Revision history</span> - restore a previous version of a shortcode\'s content, with the last 20 revisions kept automatically.', SH_CD_SLUG ),
514 ];
515
516 $content = '<ul><li>' . implode( '</li><li>', $items ) . '</li></ul>';
517
518 sh_cd_display_pro_upgrade_notice( $title, $content, 'sh-cd-page-edit-marketing-prompt' );
519 }
520
521