PluginProbe
Snippet Shortcodes / 4.2.2
Snippet Shortcodes v4.2.2
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
← All changes | includes/shortcode.presets.premium.php +524 -273 2.04.2.2 View file →
@@ -1,273 +1,524 @@
1 -<?php
2 -
3 -defined('ABSPATH') or die("Jog on!");
4 -
5 -/**
6 - * Return a list of slugs / titles for free presets
7 - * @return array
8 - */
9 -function sh_cd_shortcode_presets_premium_list() {
10 -
11 - return [
12 - 'sc-site-language' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Language code for the current site', 'args' => [ '_sh_cd_func' => 'language' ], 'premium' => true ],
13 - 'sc-site-description' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Site tagline (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'description' ], 'premium' => true ],
14 - 'sc-site-wp-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The WordPress address (URL) (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'wpurl' ], 'premium' => true ],
15 - 'sc-site-charset' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The "Encoding for pages and feeds" (set in Settings > Reading)', 'args' => [ '_sh_cd_func' => 'charset' ], 'premium' => true ],
16 - 'sc-site-wp-version' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The current WordPress version', 'args' => [ '_sh_cd_func' => 'version' ], 'premium' => true ],
17 - 'sc-site-html-type' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The content-type (default: "text/html"). Themes and plugins', 'args' => [ '_sh_cd_func' => 'html_type' ], 'premium' => true ],
18 - 'sc-site-stylesheet-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'URL to the stylesheet for the active theme.', 'args' => [ '_sh_cd_func' => 'stylesheet_url' ], 'premium' => true ],
19 - 'sc-site-stylesheet_directory' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Directory path for the active theme.', 'args' => [ '_sh_cd_func' => 'stylesheet_directory' ], 'premium' => true ],
20 - 'sc-site-template-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The URL of the active theme\'s directory.', 'args' => [ '_sh_cd_func' => 'template_url' ], 'premium' => true],
21 - 'sc-site-pingback-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The pingback XML-RPC file URL (xmlrpc.php)', 'args' => [ '_sh_cd_func' => 'pingback_url' ], 'premium' => true ],
22 - 'sc-site-atom-feed' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The Atom feed URL (/feed/atom)', 'args' => [ '_sh_cd_func' => 'atom_url' ], 'premium' => true ],
23 - 'sc-site-rdf-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The RDF/RSS 1.0 feed URL (/feed/rfd)', 'args' => [ '_sh_cd_func' => 'rdf_url' ], 'premium' => true ],
24 - 'sc-site-rss-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The RSS 0.92 feed URL (/feed/rss)', 'args' => [ '_sh_cd_func' => 'rss_url' ], 'premium' => true ],
25 - 'sc-site-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The RSS 2.0 feed URL (/feed)', 'args' => [ '_sh_cd_func' => 'rss2_url' ], 'premium' => true ],
26 - 'sc-site-comments-atom-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The comments Atom feed URL (/comments/feed)', 'args' => [ '_sh_cd_func' => 'comments_atom_url' ], 'premium' => true ],
27 - 'sc-site-comments-rss2-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The comments RSS 2.0 feed URL (/comments/feed)', 'args' => [ '_sh_cd_func' => 'comments_rss2_url' ], 'premium' => true ],
28 - 'sc-php-server-info' => [ 'class' => 'SC_SERVER_INFO', 'description' => 'Display data from the PHP $_SERVER global e.g. [sv slug="sc-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>.', 'premium' => true ],
29 - 'sc-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="sc-php-unique-id" prefix="yeken"]', 'premium' => true ],
30 - 'sc-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>.', 'premium' => true ],
31 - 'sc-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="sc-php-random-number" min="5" max="20" ]', 'premium' => true ],
32 - 'sc-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="sc-php-random-string" length="15"]', 'premium' => true ],
33 - 'sc-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="sc-php-post-value" key="username" default="Not Found"]', 'premium' => true ],
34 - 'sc-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="sc-php-get-value" key="username" default="Not Found"]', 'premium' => true ],
35 - 'sc-php-info' => [ 'class' => 'SC_PHP_INFO', 'description' => 'Display PHP Info', 'premium' => true ],
36 - 'sc-post-id' => [ 'class' => 'SC_POST_ID', 'description' => 'Display ID for the current post.', 'premium' => true ],
37 - 'sc-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="sc-post-author" field="id" ]', 'premium' => true ],
38 - 'sc-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="sc-post-counts" status="draft"]', 'premium' => true ]
39 -
40 - // '' => [ 'class' => '', 'description' => '', 'premium' => true ]
41 - ];
42 -}
43 -
44 -
45 -/**
46 - * Get data from get_bloginfo()
47 - *
48 - * Class SV_SC_SITE_TITLE
49 - */
50 -class SV_SC_BLOG_INFO extends SV_Preset {
51 -
52 - protected function unsanitised() {
53 -
54 - $args = $this->get_arguments();
55 -
56 - $key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'name';
57 -
58 - return get_bloginfo( $key );
59 - }
60 -}
61 -
62 -/**
63 - * Get data from $_SERVER
64 - *
65 - * Class SV_SC_SERVER_INFO
66 - */
67 -class SV_SC_SERVER_INFO extends SV_Preset {
68 -
69 - protected function unsanitised() {
70 -
71 - $args = $this->get_arguments();
72 -
73 - return ( false === empty( $_SERVER[ $args['field'] ] ) ) ? $_SERVER[ $args['field'] ] : '';
74 - }
75 -}
76 -
77 -/**
78 - * Get a unique ID
79 - *
80 - * Class SV_SC_UNIQUE_ID
81 - */
82 -class SV_SC_UNIQUE_ID extends SV_Preset {
83 -
84 - protected function unsanitised() {
85 -
86 - $args = $this->get_arguments();
87 -
88 - $prefix = ( false === empty( $args['prefix'] ) ) ? $args['prefix'] : '';
89 -
90 - return uniqid ( $prefix, true );
91 - }
92 -}
93 -
94 -/**
95 - * Get timestamp
96 - *
97 - * Class SV_SC_TIMESTAMP
98 - */
99 -class SV_SC_TIMESTAMP extends SV_Preset {
100 -
101 - protected function unsanitised() {
102 - return time();
103 - }
104 -}
105 -
106 -/**
107 - * Display PHP INFO
108 - *
109 - * Class SV_SC_PHP_INFO
110 - */
111 -class SV_SC_PHP_INFO extends SV_Preset {
112 -
113 - protected function unsanitised() {
114 - return phpinfo();
115 - }
116 -}
117 -
118 -/**
119 - * Random number
120 - *
121 - * Class SV_SC_RAND_NUMBER
122 - */
123 -class SV_SC_RAND_NUMBER extends SV_Preset {
124 -
125 - protected function unsanitised() {
126 -
127 - $args = $this->get_arguments();
128 -
129 - $min = ( false === empty( $args['min'] ) ) ? (int) $args['min'] : 0;
130 -
131 - $max = ( false === empty( $args['max'] ) ) ? (int) $args['max'] : getrandmax();
132 -
133 - return rand( $min, $max );
134 - }
135 -}
136 -
137 -/**
138 - * Random string
139 - *
140 - * Based upon: https://stackoverflow.com/questions/4356289/php-random-string-generator
141 - *
142 - * Class SV_SC_RAND_STRING
143 - */
144 -class SV_SC_RAND_STRING extends SV_Preset {
145 -
146 - protected function unsanitised() {
147 -
148 - $args = $this->get_arguments();
149 -
150 - $length = ( false === empty( $args['length'] ) ) ? (int) $args['length'] : 10;
151 -
152 - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
153 - $no_characters = strlen( $characters );
154 - $random_string = '';
155 -
156 - for ($i = 0; $i < $length; $i++) {
157 - $random_string .= $characters[ rand( 0, $no_characters - 1 ) ];
158 - }
159 -
160 - return $random_string;
161 - }
162 -}
163 -
164 -/**
165 - * Fetch an item from the $_POST array
166 - *
167 - * Class SV_SC_POST_VALUE
168 - */
169 -class SV_SC_POST_VALUE extends SV_Preset {
170 -
171 - protected function unsanitised() {
172 -
173 - $args = $this->get_arguments();
174 -
175 - $post_value = ( false === empty( $_POST[ $args['key'] ] ) ) ? $_POST[ $args['key'] ] : NULL;
176 -
177 - if ( null !== $post_value ) {
178 - return $post_value;
179 - }
180 -
181 - // Do we have a fall back default?
182 - return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
183 -
184 - }
185 -}
186 -
187 -/**
188 - * Fetch an item from the $_GET array
189 - *
190 - * Class SV_SC_GET_VALUE
191 - */
192 -class SV_SC_GET_VALUE extends SV_Preset {
193 -
194 - protected function unsanitised() {
195 -
196 - $args = $this->get_arguments();
197 -
198 - $post_value = ( false === empty( $_GET[ $args['key'] ] ) ) ? $_GET[ $args['key'] ] : NULL;
199 -
200 - if ( null !== $post_value ) {
201 - return $post_value;
202 - }
203 -
204 - // Do we have a fall back default?
205 - return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
206 -
207 - }
208 -}
209 -
210 -/**
211 - * Display current Post ID
212 - *
213 - * Class SV_SC_POST_ID
214 - */
215 -class SV_SC_POST_ID extends SV_Preset {
216 -
217 - protected function unsanitised() {
218 - return get_the_ID();
219 - }
220 -}
221 -
222 -/**
223 - * Display author of current post
224 - *
225 - * Class SV_SC_POST_AUTHOR
226 - */
227 -class SV_SC_POST_AUTHOR extends SV_Preset {
228 -
229 - protected function unsanitised() {
230 -
231 - $args = $this->get_arguments();
232 -
233 - switch ( $args['field'] ) {
234 - case 'id':
235 - return get_the_author_meta( 'ID' );
236 - break;
237 - default:
238 - return get_the_author();
239 - }
240 - }
241 -}
242 -
243 -/**
244 - * Display post counts
245 - *
246 - * Class SV_SC_POST_COUNTS
247 - */
248 -class SV_SC_POST_COUNTS extends SV_Preset {
249 -
250 - protected function unsanitised() {
251 -
252 - $args = $this->get_arguments();
253 -
254 - $counts = wp_count_posts();
255 -
256 - switch ( $args['status'] ) {
257 - case 'future':
258 - return $counts->future;
259 - break;
260 - case 'draft':
261 - return $counts->draft;
262 - break;
263 - case 'pending':
264 - return $counts->pending;
265 - break;
266 - case 'private':
267 - return $counts->private;
268 - break;
269 - default:
270 - return $counts->publish;
271 - }
272 - }
273 -}
1 +<?php
2 +
3 +defined('ABSPATH') or die("Jog on!");
4 +
5 +/**
6 + * Return a list of slugs / titles for free presets
7 + * @return array
8 + */
9 +function sh_cd_shortcode_presets_premium_list() {
10 +
11 + return [
12 + 'sc-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="sc-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' ] ],
13 + 'sc-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="sc-date" interval="-1 year"], [sv slug="sc-date" interval="+5 days"], [sv slug="sc-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 ],
14 + 'sc-site-language' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Language code for the current site', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'language' ], 'premium' => true ],
15 + 'sc-site-description' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Site tagline (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'description' ], 'premium' => true ],
16 + 'sc-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 ],
17 + 'sc-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 ],
18 + 'sc-site-wp-version' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The current WordPress version', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'version' ], 'premium' => true ],
19 + 'sc-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 ],
20 + 'sc-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 ],
21 + 'sc-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 ],
22 + 'sc-site-current-url' => [ 'class' => 'SC_CURRENT_URL', 'description' => __( 'Get the current URL.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'current_url' ], 'premium' => true],
23 + 'sc-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],
24 + 'sc-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],
25 + 'sc-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 ],
26 + 'sc-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 ],
27 + 'sc-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 ],
28 + 'sc-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 ],
29 + 'sc-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 ],
30 + 'sc-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 ],
31 + 'sc-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 ],
32 + 'sc-php-server-info' => [ 'class' => 'SC_SERVER_INFO', 'description' => __( 'Display data from the PHP $_SERVER global e.g. [sv slug="sc-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 ],
33 + 'sc-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="sc-php-unique-id" prefix="yeken"]', SH_CD_SLUG ), 'premium' => true ],
34 + 'sc-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 ],
35 + 'sc-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="sc-php-random-number" min="5" max="20" ]', SH_CD_SLUG ), 'premium' => true ],
36 + 'sc-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="sc-php-random-string" length="15"]', SH_CD_SLUG ), 'premium' => true ],
37 + 'sc-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="sc-php-post-value" key="username" default="Not Found"]', SH_CD_SLUG ), 'premium' => true ],
38 + 'sc-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="sc-php-get-value" key="username" default="Not Found"]', SH_CD_SLUG ), 'premium' => true ],
39 + 'sc-php-info' => [ 'class' => 'SC_PHP_INFO', 'description' => __( 'Display PHP Info', SH_CD_SLUG ), 'premium' => true ],
40 + 'sc-post-id' => [ 'class' => 'SC_POST_ID', 'description' => __( 'Display ID for the current post.', SH_CD_SLUG ), 'premium' => true ],
41 + 'sc-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="sc-post-author" field="id" ]', SH_CD_SLUG ), 'premium' => true ],
42 + 'sc-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="sc-post-counts" status="draft"]', SH_CD_SLUG ), 'premium' => true ],
43 + 'sc-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="sc-user-counts" role="subscriber"] or [sv slug="sc-user-counts"]', SH_CD_SLUG ), 'premium' => true ],
44 + 'sc-user-profile-photo' => [ 'class' => 'SC_AVATAR', 'description' => __( 'Display the WordPress profile photo for the logged in user e.g. [sv slug="sc-user-profile-photo" width="150"] or [sv slug="sc-user-profile-photo"]. Please note, width defaults to 96px.', SH_CD_SLUG ), 'premium' => true ],
45 + 'sc-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="sc-user-meta" field="last_name"]</a>', SH_CD_SLUG ), 'premium' => true ],
46 + 'sc-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="sc-woocommerce" field="billing_phone"]</a>', SH_CD_SLUG ), 'premium' => true ]
47 +
48 + // '' => [ 'class' => '', 'description' => '', 'premium' => true ]
49 + ];
50 +}
51 +
52 +
53 +/**
54 + * Get data from get_bloginfo()
55 + *
56 + * Class SV_SC_SITE_TITLE
57 + */
58 +class SV_SC_BLOG_INFO extends SV_Preset {
59 +
60 + protected function unsanitised() {
61 +
62 + $args = $this->get_arguments();
63 +
64 + $key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'name';
65 +
66 + return get_bloginfo( $key );
67 + }
68 +}
69 +
70 +/**
71 + * Get data from $_SERVER
72 + *
73 + * Class SV_SC_SERVER_INFO
74 + */
75 +class SV_SC_SERVER_INFO extends SV_Preset {
76 +
77 + protected function unsanitised() {
78 +
79 + $args = $this->get_arguments();
80 +
81 + return ( false === empty( $_SERVER[ $args['field'] ] ) ) ? $_SERVER[ $args['field'] ] : '';
82 + }
83 +}
84 +
85 +/**
86 + * Get a unique ID
87 + *
88 + * Class SV_SC_UNIQUE_ID
89 + */
90 +class SV_SC_UNIQUE_ID extends SV_Preset {
91 +
92 + protected function unsanitised() {
93 +
94 + $args = $this->get_arguments();
95 +
96 + $prefix = ( false === empty( $args['prefix'] ) ) ? $args['prefix'] : '';
97 +
98 + return uniqid ( $prefix, true );
99 + }
100 +}
101 +
102 +/**
103 + * Get timestamp
104 + *
105 + * Class SV_SC_TIMESTAMP
106 + */
107 +class SV_SC_TIMESTAMP extends SV_Preset {
108 +
109 + protected function unsanitised() {
110 + return time();
111 + }
112 +}
113 +
114 +/**
115 + * Display PHP INFO
116 + *
117 + * Class SV_SC_PHP_INFO
118 + */
119 +class SV_SC_PHP_INFO extends SV_Preset {
120 +
121 + protected function unsanitised() {
122 + return phpinfo();
123 + }
124 +}
125 +
126 +/**
127 + * Current URL
128 + *
129 + * Class SV_SC_CURRENT_URL
130 + */
131 +class SV_SC_CURRENT_URL extends SV_Preset {
132 +
133 + protected function unsanitised() {
134 +
135 + $protocol = (
136 + ( isset($_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
137 + ( isset($_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
138 + ) ? 'https://' : 'http://';
139 +
140 + return $protocol . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
141 + }
142 +}
143 +
144 +/**
145 + * Register URL
146 + *
147 + * Class SV_SC_REGISTER_URL
148 + */
149 +class SV_SC_REGISTER_URL extends SV_Preset {
150 +
151 + protected function unsanitised() {
152 + return wp_registration_url();
153 + }
154 +}
155 +
156 +/**
157 + * Random number
158 + *
159 + * Class SV_SC_RAND_NUMBER
160 + */
161 +class SV_SC_RAND_NUMBER extends SV_Preset {
162 +
163 + protected function unsanitised() {
164 +
165 + $args = $this->get_arguments();
166 +
167 + $min = ( false === empty( $args['min'] ) ) ? (int) $args['min'] : 0;
168 +
169 + $max = ( false === empty( $args['max'] ) ) ? (int) $args['max'] : getrandmax();
170 +
171 + return rand( $min, $max );
172 + }
173 +}
174 +
175 +/**
176 + * Avatar URL
177 + *
178 + * Class SV_SC_AVATAR
179 + */
180 +class SV_SC_AVATAR extends SV_Preset {
181 +
182 + public function init() {
183 +
184 + $this->escape_method = false;
185 + }
186 +
187 + protected function unsanitised() {
188 +
189 + $args = $this->get_arguments();
190 + $user_id = get_current_user_id();
191 +
192 +// if ( true === empty( $user_id ) ) {
193 +// return '';
194 +// }
195 +
196 + $width = ( false === empty( $args['width'] ) ) ? (int) $args['width'] : 96;
197 + $profile_url = get_avatar_url( $user_id, [ 'size' => $width ] );
198 +
199 + if ( true === empty( $profile_url ) ){
200 + return '';
201 + }
202 +
203 + return sprintf( '<img src="%1$s" />', esc_url( $profile_url ) );
204 + }
205 +}
206 +
207 +/**
208 + * Random string
209 + *
210 + * Based upon: https://stackoverflow.com/questions/4356289/php-random-string-generator
211 + *
212 + * Class SV_SC_RAND_STRING
213 + */
214 +class SV_SC_RAND_STRING extends SV_Preset {
215 +
216 + protected function unsanitised() {
217 +
218 + $args = $this->get_arguments();
219 +
220 + $length = ( false === empty( $args['length'] ) ) ? (int) $args['length'] : 10;
221 +
222 + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
223 + $no_characters = strlen( $characters );
224 + $random_string = '';
225 +
226 + for ($i = 0; $i < $length; $i++) {
227 + $random_string .= $characters[ rand( 0, $no_characters - 1 ) ];
228 + }
229 +
230 + return $random_string;
231 + }
232 +}
233 +
234 +/**
235 + * Fetch an item from the $_POST array
236 + *
237 + * Class SV_SC_POST_VALUE
238 + */
239 +class SV_SC_POST_VALUE extends SV_Preset {
240 +
241 + protected function unsanitised() {
242 +
243 + $args = $this->get_arguments();
244 +
245 + $post_value = ( false === empty( $_POST[ $args['key'] ] ) ) ? $_POST[ $args['key'] ] : NULL;
246 +
247 + if ( null !== $post_value ) {
248 + return $post_value;
249 + }
250 +
251 + // Do we have a fall back default?
252 + return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
253 +
254 + }
255 +}
256 +
257 +/**
258 + * Fetch an item from the $_GET array
259 + *
260 + * Class SV_SC_GET_VALUE
261 + */
262 +class SV_SC_GET_VALUE extends SV_Preset {
263 +
264 + protected function unsanitised() {
265 +
266 + $args = $this->get_arguments();
267 +
268 + $post_value = ( false === empty( $_GET[ $args['key'] ] ) ) ? $_GET[ $args['key'] ] : NULL;
269 +
270 + if ( null !== $post_value ) {
271 + return $post_value;
272 + }
273 +
274 + // Do we have a fall back default?
275 + return ( false === empty( $args['default'] ) ) ? $args['default'] : '';
276 +
277 + }
278 +}
279 +
280 +/**
281 + * Display current Post ID
282 + *
283 + * Class SV_SC_POST_ID
284 + */
285 +class SV_SC_POST_ID extends SV_Preset {
286 +
287 + protected function unsanitised() {
288 + return get_the_ID();
289 + }
290 +}
291 +
292 +/**
293 + * Display author of current post
294 + *
295 + * Class SV_SC_POST_AUTHOR
296 + */
297 +class SV_SC_POST_AUTHOR extends SV_Preset {
298 +
299 + protected function unsanitised() {
300 +
301 + $args = $this->get_arguments();
302 +
303 + switch ( $args['field'] ) {
304 + case 'id':
305 + return get_the_author_meta( 'ID' );
306 + break;
307 + default:
308 + return get_the_author();
309 + }
310 + }
311 +}
312 +
313 +/**
314 + * Display post counts
315 + *
316 + * Class SV_SC_POST_COUNTS
317 + */
318 +class SV_SC_POST_COUNTS extends SV_Preset {
319 +
320 + protected function unsanitised() {
321 +
322 + $args = $this->get_arguments();
323 +
324 + $counts = wp_count_posts();
325 +
326 + switch ( $args['status'] ) {
327 + case 'future':
328 + return $counts->future;
329 + break;
330 + case 'draft':
331 + return $counts->draft;
332 + break;
333 + case 'pending':
334 + return $counts->pending;
335 + break;
336 + case 'private':
337 + return $counts->private;
338 + break;
339 + default:
340 + return $counts->publish;
341 + }
342 + }
343 +}
344 +
345 +/**
346 + * Get a User counts
347 + *
348 + * Class SV_SC_USER_COUNTS
349 + */
350 +class SV_SC_USER_COUNTS extends SV_Preset {
351 +
352 + protected function unsanitised() {
353 +
354 + $args = $this->get_arguments();
355 +
356 + $role = ( false === empty( $args['role'] ) ) ? $args['role'] : NULL;
357 +
358 + $users = count_users();
359 +
360 + if ( false === empty( $role ) && true === isset( $users['avail_roles'][ $role ] ) ) {
361 + return $users['avail_roles'][ $role ];
362 + } if ( true === isset( $users['total_users'] ) ) {
363 + return $users['total_users'];
364 + }
365 +
366 + return '';
367 + }
368 +}
369 +
370 +/**
371 + * Display a date and also support date arithmetic
372 + *
373 + * Class SV_SC_DATE
374 + */
375 +class SV_SC_DATE extends SV_Preset {
376 +
377 + protected function unsanitised() {
378 +
379 + $args = $this->get_arguments();
380 +
381 + $todays_date = date_create();
382 +
383 + // Do we have an interval?
384 + if ( false === empty( $args['interval'] ) ) {
385 +
386 + $interval = date_interval_create_from_date_string( $args['interval'] );
387 +
388 + if ( $interval !== false ) {
389 + $todays_date = date_add( $todays_date, $interval );
390 + }
391 +
392 + }
393 +
394 + $date_format = ( false === empty( $args['format'] ) ) ? $args['format'] : 'd/m/Y';
395 +
396 + return date_format( $todays_date, $date_format );
397 + }
398 +}
399 +
400 +/**
401 + * Fetch a column from a MySQL database by ID
402 + *
403 + * Min example:
404 + *
405 + * [sv slug="sc-db-value-by-id" table="users" column="user_login" column-to-search="id" key="3"]
406 + *
407 + * Full example:
408 + *
409 + * [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" message-not-found="User not found" cache=false cache-duration=3600 ]
410 + *
411 + * Another example is to fetch the key we're searching for from the query string:
412 + *
413 + * e.g. https://[url]/?user-id=3
414 + *
415 + * [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key-query-string="user-id" key-format="%d" message-not-found="User not found" cache=false cache-duration=3600 ]
416 + *
417 + * SC_DB_VALUE_BY_ID
418 + */
419 +class SV_SC_DB_VALUE_BY_ID extends SV_Preset {
420 +
421 + protected function unsanitised() {
422 +
423 + $args = wp_parse_args( $this->get_arguments(), [ 'key-format' => '%d', 'key-query-string' => NULL, 'message-not-found' => '', 'cache' => true, 'cache-duration' => 1 * HOUR_IN_SECONDS ] );
424 +
425 + if ( $validation_error = $this->validate_arguments( $args ) ) {
426 + return $validation_error;
427 + }
428 +
429 + $cache_key = md5( print_r( $args, true ) );
430 +
431 + if( true === sh_cd_to_bool( $args[ 'cache'] )
432 + && $cache = sh_cd_cache_get( $cache_key ) ) {
433 + return $cache;
434 + }
435 +
436 + global $wpdb;
437 +
438 + // Load key to look for from querystring?
439 + $key = ( false === empty( $args['key-query-string'] ) ) ?
440 + $_GET[ $args['key-query-string'] ] : $args['key'];
441 +
442 + $sql = sprintf( 'Select %s from %s where %s = %s',
443 + $args['column'],
444 + $args['table'],
445 + $args['column-to-search'],
446 + $args['key-format']
447 + );
448 +
449 + $sql = $wpdb->prepare( $sql, $key );
450 + $value = $wpdb->get_var( $sql );
451 +
452 + if ( true === empty( $value )) {
453 + $value = $args['message-not-found'] ;
454 + }
455 +
456 + sh_cd_cache_set( $cache_key, $value, (int) $args[ 'cache-duration'] );
457 +
458 + return $value;
459 + }
460 +
461 + protected function validate_arguments( $args = [] ) {
462 +
463 + if ( false === sh_cd_is_shortcode_db_value_by_id_enabled() ) {
464 + return 'This shortcode has been disabled by admin. See "WP Admin" > "Snippet Shortcodes" > "Settings" to enable.';
465 + }
466 +
467 + if ( true === empty( $args['table'] ) ) {
468 + return 'No MySQL table specified (i.e. "table" argument is missing).';
469 + }
470 +
471 + if ( true === empty( $args['column'] ) ) {
472 + return 'No MySQL column specified (i.e. "column" argument is missing).';
473 + }
474 +
475 + if ( true === empty( $args['column-to-search'] ) ) {
476 + return 'The MySQL column to search for given key has not been specified (i.e. "column-to-search" argument is missing).';
477 + }
478 +
479 + if ( false === empty( $args['key-query-string'] ) ) {
480 + if( true === empty( $_GET[ $args['key-query-string'] ] ) ) {
481 + return sprintf('A querystring key ( "%1$s" ) has been specified but no value was been passed within the URL? (e.g. https://[website-address]/?%1$s=some-value).', esc_html( $args['key-query-string'] ) );
482 + }
483 + } elseif ( true === empty( $args['key'] ) ) {
484 + return 'No key has been specified (i.e. the "key" and "key-query-string" arguments are both missing).';
485 + }
486 +
487 + if ( true === empty( $args['key-format'] ) ) {
488 + return 'No key format has been specified (i.e. "key-format" argument is missing). If the "key" field is numeric, then use %d otherwise use %s.';
489 + }
490 +
491 + if ( false === in_array( $args['key-format'], [ '%s', '%d' ] ) ) {
492 + return 'The key format is invalid. If the "key" field is numeric, then use %d otherwise use %s.';
493 + }
494 +
495 + }
496 +}
497 +
498 +/**
499 + * User Info
500 + *
501 + * Class SV_USER_INFO
502 + */
503 +class SV_SC_USER_META extends SV_Preset {
504 +
505 + protected function unsanitised() {
506 +
507 + $user_id = get_current_user_id();
508 +
509 + // Not logged in?
510 + if ( true === empty( $user_id ) ) {
511 + return '';
512 + }
513 +
514 + $args = wp_parse_args( $this->get_arguments(), [ 'field' => NULL, 'message-not-found' => '' ] );
515 +
516 + if ( true === empty( $args[ 'field' ] ) ) {
517 + return 'Field not specified';
518 + }
519 +
520 + $value = get_user_meta( $user_id, $args[ 'field' ], true );
521 +
522 + return !empty( $value ) ? $value : $args[ 'message-not-found' ];
523 + }
524 +}