PluginProbe
Snippet Shortcodes / 1.6
Snippet Shortcodes v1.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 / shortcode-premade.php

shortcode-premade.php in Snippet Shortcodes 1.6, at includes/shortcode-premade.php

136 lines 3.7 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 function sh_cd_is_shortcode_preset($slug)
6 {
7 if (!empty($slug) && array_key_exists($slug, sh_cd_shortcode_presets())) {
8 return true;
9 }
10
11 return false;
12
13 }
14
15 function sh_cd_shortcode_presets()
16 {
17 return array(
18
19 'sc-todays-date' => '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>',
20 'sc-site-title' => 'Displays the site title.',
21 'sc-site-url' => 'Displays the site URL.',
22 'sc-page-title' => 'Displays the page title.',
23 'sc-admin-email' => 'Displays the admin email address.',
24 'sc-login-page' => '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".',
25 'sc-username' => 'Display the logged in username.',
26 'sc-user-id' => 'Display the current user\'s ID',
27 'sc-user-ip' => 'Display the current user\'s IP address.',
28 'sc-user-email' => 'Display the current user\'s email address.',
29 'sc-username' => 'Display the current user\'s username.',
30 'sc-first-name' => 'Display the current user\'s first name.',
31 'sc-last-name' => 'Display the current user\'s last name.',
32 'sc-display-name' => 'Display the current user\'s display name.',
33 'sc-user-agent' => 'Display the current user\'s user agent'
34 );
35 }
36
37 function sh_cd_render_shortcode_presets($shortcode_args)
38 {
39 $slug = $shortcode_args['slug'];
40
41 switch ($slug) {
42 case 'sc-todays-date':
43 return sh_cd_render_todays_date($shortcode_args['format']);
44 break;
45 case 'sc-user-agent':
46 return $_SERVER['HTTP_USER_AGENT'];
47 break;
48 case 'sc-site-url':
49 return site_url();
50 break;
51 case 'sc-page-title':
52 return the_title('', '', false);
53 break;
54 case 'sc-site-title':
55 return get_bloginfo( 'name');
56 break;
57 case 'sc-admin-email':
58 return get_bloginfo( 'admin_email');
59 break;
60 case 'sc-login-page':
61 $redirect_page = (false == $shortcode_args['redirect']) ? '' : $shortcode_args['redirect'];
62 return wp_login_url($redirect_page);
63 break;
64 case 'sc-user-ip':
65 return sh_cd_get_user_ip();
66 break;
67 default:
68 $user_data = sh_cd_user_data($slug);
69 if (!empty($user_data)) {
70 return $user_data;
71 }
72
73 break;
74 }
75
76
77 }
78
79 function sh_cd_user_data($slug)
80 {
81 global $current_user;
82 get_currentuserinfo();
83
84 if (!empty($current_user->data->ID))
85 {
86 switch ($slug) {
87 case 'sc-username':
88 return $current_user->user_login;
89 break;
90 case 'sc-first-name':
91 return $current_user->user_firstname;
92 break;
93 case 'sc-last-name':
94 return $current_user->user_lastname;
95 break;
96 case 'sc-display-name':
97 return $current_user->display_name;
98 break;
99 case 'sc-user-id':
100 return $current_user->ID;
101 break;
102 case 'sc-user-email':
103 return $current_user->user_email;
104 break;
105 default:
106 break;
107 }
108 }
109
110 return '';
111 }
112
113 function sh_cd_get_user_ip() {
114
115 // Code based on WP Beginner article: http://www.wpbeginner.com/wp-tutorials/how-to-display-a-users-ip-address-in-wordpress/
116 if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
117 $ip = $_SERVER['HTTP_CLIENT_IP'];
118 }
119 elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
120 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
121 }
122 else {
123 $ip = $_SERVER['REMOTE_ADDR'];
124 }
125 return $ip;
126 }
127
128 function sh_cd_render_todays_date($format)
129 {
130 if (false == $format) {
131 $format = 'd/m/Y';
132 }
133
134 return date($format);
135 }
136