| @@ -1,177 +1,177 @@ | ||
| 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_free_list() { | |
| 10 | - | |
| 11 | - return [ | |
| 12 | - 'sc-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>' ], | |
| 13 | - 'sc-user-ip' => [ 'class' => 'SC_USER_IP', 'description' => 'Display the current user\'s IP address.'], | |
| 14 | - 'sc-user-agent' => [ 'class' => 'SC_USER_AGENT', 'description' => 'Display the current user\'s User Agent' ], | |
| 15 | - 'sc-site-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'The Site address (URL) (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'url' ] ], | |
| 16 | - 'sc-site-title' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Displays the site title.' ], | |
| 17 | - 'sc-admin-email' => [ 'class' => 'SC_BLOG_INFO', 'description' => 'Admin email (set in Settings > General)', 'args' => [ '_sh_cd_func' => 'admin_email' ] ], | |
| 18 | - 'sc-page-title' => [ 'class' => 'SC_PAGE_TITLE', 'description' => 'Displays the page title.' ], | |
| 19 | - 'sc-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".' ], | |
| 20 | - 'sc-privacy-url' => [ 'class' => 'SC_POLICY_URL', 'description' => 'Displays the privacy page URL.' ], | |
| 21 | - 'sc-username' => [ 'class' => 'SC_USER_INFO', 'description' => 'Display the logged in username.', 'args' => [ '_sh_cd_func' => 'user_login' ] ], | |
| 22 | - 'sc-user-id' => [ 'class' => 'SC_USER_INFO', 'description' => 'Display the current user\'s ID.', 'args' => [ '_sh_cd_func' => 'ID' ] ], | |
| 23 | - 'sc-user-email' => [ 'class' => 'SC_USER_INFO', 'description' => 'Display the current user\'s email address.', 'args' => [ '_sh_cd_func' => 'user_email' ] ], | |
| 24 | - 'sc-first-name' => [ 'class' => 'SC_USER_INFO', 'description' => 'Display the current user\'s username.', 'args' => [ '_sh_cd_func' => 'user_firstname' ] ], | |
| 25 | - 'sc-last-name' => [ 'class' => 'SC_USER_INFO', 'description' => 'Display the current user\'s last name.', 'args' => [ '_sh_cd_func' => 'user_lastname' ] ], | |
| 26 | - 'sc-display-name' => [ 'class' => 'SC_USER_INFO', 'description' => 'Display the current user\'s display name.', 'args' => [ '_sh_cd_func' => 'display_name' ] ] | |
| 27 | - ]; | |
| 28 | - | |
| 29 | - // '' => [ 'class' => '', 'description' => '', 'args' => [ '_sh_cd_func' => 'admin_email' ] ] | |
| 30 | -} | |
| 31 | - | |
| 32 | -/** | |
| 33 | - * Get a user's ID | |
| 34 | - * | |
| 35 | - * Class SV_SC_USER_IP | |
| 36 | - */ | |
| 37 | -class SV_SC_USER_IP extends SV_Preset { | |
| 38 | - | |
| 39 | - protected function unsanitised() { | |
| 40 | - | |
| 41 | - // Code based on WP Beginner article: http://www.wpbeginner.com/wp-tutorials/how-to-display-a-users-ip-address-in-wordpress/ | |
| 42 | - if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { | |
| 43 | - $ip = $_SERVER['HTTP_CLIENT_IP']; | |
| 44 | - } | |
| 45 | - elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { | |
| 46 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| 47 | - } | |
| 48 | - else { | |
| 49 | - $ip = $_SERVER['REMOTE_ADDR']; | |
| 50 | - } | |
| 51 | - return $ip; | |
| 52 | - | |
| 53 | - } | |
| 54 | -} | |
| 55 | - | |
| 56 | -/** | |
| 57 | - * Today's date | |
| 58 | - * | |
| 59 | - * Class SV_SC_TODAYS_DATE | |
| 60 | - */ | |
| 61 | -class SV_SC_TODAYS_DATE extends SV_Preset { | |
| 62 | - | |
| 63 | - protected function unsanitised() { | |
| 64 | - | |
| 65 | - $args = $this->get_arguments(); | |
| 66 | - | |
| 67 | - $date_format = ( false === empty( $args['format'] ) ) ? $args['format'] : 'd/m/Y'; | |
| 68 | - | |
| 69 | - return date( $date_format ); | |
| 70 | - | |
| 71 | - } | |
| 72 | -} | |
| 73 | - | |
| 74 | -/** | |
| 75 | - * User Agent | |
| 76 | - * | |
| 77 | - * Class SV_SC_USER_AGENT | |
| 78 | - */ | |
| 79 | -class SV_SC_USER_AGENT extends SV_Preset { | |
| 80 | - protected function unsanitised() { | |
| 81 | - return $_SERVER['HTTP_USER_AGENT']; | |
| 82 | - } | |
| 83 | -} | |
| 84 | - | |
| 85 | -/** | |
| 86 | - * Page title | |
| 87 | - * | |
| 88 | - * Class SV_SC_PAGE_TITLE | |
| 89 | - */ | |
| 90 | -class SV_SC_PAGE_TITLE extends SV_Preset { | |
| 91 | - | |
| 92 | - protected function unsanitised() { | |
| 93 | - return the_title('', '', false); | |
| 94 | - } | |
| 95 | -} | |
| 96 | - | |
| 97 | -/** | |
| 98 | - * Login Page | |
| 99 | - * | |
| 100 | - * Class SV_SC_LOGIN_PAGE | |
| 101 | - */ | |
| 102 | -class SV_SC_LOGIN_PAGE extends SV_Preset { | |
| 103 | - | |
| 104 | - public function init() { | |
| 105 | - $this->escape_method = 'esc_url_raw'; | |
| 106 | - } | |
| 107 | - | |
| 108 | - protected function unsanitised() { | |
| 109 | - | |
| 110 | - $args = $this->get_arguments(); | |
| 111 | - | |
| 112 | - $redirect = ( false === empty( $args['redirect'] ) ) ? $args['redirect'] : ''; | |
| 113 | - | |
| 114 | - return wp_login_url( $redirect ); | |
| 115 | - } | |
| 116 | -} | |
| 117 | -/** | |
| 118 | - * Policy URL | |
| 119 | - * | |
| 120 | - * Class SV_SC_POLICY_URL | |
| 121 | - */ | |
| 122 | -class SV_SC_POLICY_URL extends SV_Preset { | |
| 123 | - | |
| 124 | - public function init() { | |
| 125 | - $this->escape_method = 'esc_url_raw'; | |
| 126 | - } | |
| 127 | - | |
| 128 | - protected function unsanitised() { | |
| 129 | - return get_privacy_policy_url(); | |
| 130 | - } | |
| 131 | -} | |
| 132 | - | |
| 133 | -/** | |
| 134 | - * User Info | |
| 135 | - * | |
| 136 | - * Class SV_USER_INFO | |
| 137 | - */ | |
| 138 | -class SV_SC_USER_INFO extends SV_Preset { | |
| 139 | - | |
| 140 | - protected function unsanitised() { | |
| 141 | - | |
| 142 | - $args = $this->get_arguments(); | |
| 143 | - | |
| 144 | - $key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'ID'; | |
| 145 | - | |
| 146 | - $current_user = wp_get_current_user(); | |
| 147 | - | |
| 148 | - // Not logged in? | |
| 149 | - if ( false === $current_user->exists() ) { | |
| 150 | - return ''; | |
| 151 | - } | |
| 152 | - | |
| 153 | - switch ( $key ) { | |
| 154 | - | |
| 155 | - case 'user_login': | |
| 156 | - return $current_user->user_login; | |
| 157 | - break; | |
| 158 | - case 'user_email': | |
| 159 | - return $current_user->user_email; | |
| 160 | - break; | |
| 161 | - case 'user_firstname': | |
| 162 | - return $current_user->user_firstname; | |
| 163 | - break; | |
| 164 | - case 'user_lastname': | |
| 165 | - return $current_user->user_lastname; | |
| 166 | - break; | |
| 167 | - case 'display_name': | |
| 168 | - return $current_user->display_name; | |
| 169 | - break; | |
| 170 | - default: | |
| 171 | - return $current_user->ID; | |
| 172 | - | |
| 173 | - } | |
| 174 | - | |
| 175 | - return ''; | |
| 176 | - } | |
| 177 | -} | |
| 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_free_list() { | |
| 10 | + | |
| 11 | + return [ | |
| 12 | + 'sc-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 ) ], | |
| 13 | + 'sc-user-ip' => [ 'class' => 'SC_USER_IP', 'description' => __( 'Display the current user\'s IP address.', SH_CD_SLUG )], | |
| 14 | + 'sc-user-agent' => [ 'class' => 'SC_USER_AGENT', 'description' => __( 'Display the current user\'s User Agent', SH_CD_SLUG ) ], | |
| 15 | + 'sc-site-url' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'The Site address (URL) (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'url' ] ], | |
| 16 | + 'sc-site-title' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Displays the site title.', SH_CD_SLUG ) ], | |
| 17 | + 'sc-admin-email' => [ 'class' => 'SC_BLOG_INFO', 'description' => __( 'Admin email (set in Settings > General)', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'admin_email' ] ], | |
| 18 | + 'sc-page-title' => [ 'class' => 'SC_PAGE_TITLE', 'description' => __( 'Displays the page title.', SH_CD_SLUG ) ], | |
| 19 | + 'sc-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 ) ], | |
| 20 | + 'sc-privacy-url' => [ 'class' => 'SC_POLICY_URL', 'description' => __( 'Displays the privacy page URL.', SH_CD_SLUG ) ], | |
| 21 | + 'sc-username' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the logged in username.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_login' ] ], | |
| 22 | + 'sc-user-id' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s ID.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'ID' ] ], | |
| 23 | + 'sc-user-email' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s email address.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_email' ] ], | |
| 24 | + 'sc-first-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s username.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_firstname' ] ], | |
| 25 | + 'sc-last-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s last name.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'user_lastname' ] ], | |
| 26 | + 'sc-display-name' => [ 'class' => 'SC_USER_INFO', 'description' => __( 'Display the current user\'s display name.', SH_CD_SLUG ), 'args' => [ '_sh_cd_func' => 'display_name' ] ] | |
| 27 | + ]; | |
| 28 | + | |
| 29 | + // '' => [ 'class' => '', 'description' => '', 'args' => [ '_sh_cd_func' => 'admin_email' ] ] | |
| 30 | +} | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Get a user's ID | |
| 34 | + * | |
| 35 | + * Class SV_SC_USER_IP | |
| 36 | + */ | |
| 37 | +class SV_SC_USER_IP extends SV_Preset { | |
| 38 | + | |
| 39 | + protected function unsanitised() { | |
| 40 | + | |
| 41 | + // Code based on WP Beginner article: http://www.wpbeginner.com/wp-tutorials/how-to-display-a-users-ip-address-in-wordpress/ | |
| 42 | + if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { | |
| 43 | + $ip = $_SERVER['HTTP_CLIENT_IP']; | |
| 44 | + } | |
| 45 | + elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { | |
| 46 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| 47 | + } | |
| 48 | + else { | |
| 49 | + $ip = $_SERVER['REMOTE_ADDR']; | |
| 50 | + } | |
| 51 | + return $ip; | |
| 52 | + | |
| 53 | + } | |
| 54 | +} | |
| 55 | + | |
| 56 | +/** | |
| 57 | + * Today's date | |
| 58 | + * | |
| 59 | + * Class SV_SC_TODAYS_DATE | |
| 60 | + */ | |
| 61 | +class SV_SC_TODAYS_DATE extends SV_Preset { | |
| 62 | + | |
| 63 | + protected function unsanitised() { | |
| 64 | + | |
| 65 | + $args = $this->get_arguments(); | |
| 66 | + | |
| 67 | + $date_format = ( false === empty( $args['format'] ) ) ? $args['format'] : 'd/m/Y'; | |
| 68 | + | |
| 69 | + return date( $date_format ); | |
| 70 | + | |
| 71 | + } | |
| 72 | +} | |
| 73 | + | |
| 74 | +/** | |
| 75 | + * User Agent | |
| 76 | + * | |
| 77 | + * Class SV_SC_USER_AGENT | |
| 78 | + */ | |
| 79 | +class SV_SC_USER_AGENT extends SV_Preset { | |
| 80 | + protected function unsanitised() { | |
| 81 | + return $_SERVER['HTTP_USER_AGENT']; | |
| 82 | + } | |
| 83 | +} | |
| 84 | + | |
| 85 | +/** | |
| 86 | + * Page title | |
| 87 | + * | |
| 88 | + * Class SV_SC_PAGE_TITLE | |
| 89 | + */ | |
| 90 | +class SV_SC_PAGE_TITLE extends SV_Preset { | |
| 91 | + | |
| 92 | + protected function unsanitised() { | |
| 93 | + return the_title('', '', false); | |
| 94 | + } | |
| 95 | +} | |
| 96 | + | |
| 97 | +/** | |
| 98 | + * Login Page | |
| 99 | + * | |
| 100 | + * Class SV_SC_LOGIN_PAGE | |
| 101 | + */ | |
| 102 | +class SV_SC_LOGIN_PAGE extends SV_Preset { | |
| 103 | + | |
| 104 | + public function init() { | |
| 105 | + $this->escape_method = 'esc_url_raw'; | |
| 106 | + } | |
| 107 | + | |
| 108 | + protected function unsanitised() { | |
| 109 | + | |
| 110 | + $args = $this->get_arguments(); | |
| 111 | + | |
| 112 | + $redirect = ( false === empty( $args['redirect'] ) ) ? $args['redirect'] : ''; | |
| 113 | + | |
| 114 | + return wp_login_url( $redirect ); | |
| 115 | + } | |
| 116 | +} | |
| 117 | +/** | |
| 118 | + * Policy URL | |
| 119 | + * | |
| 120 | + * Class SV_SC_POLICY_URL | |
| 121 | + */ | |
| 122 | +class SV_SC_POLICY_URL extends SV_Preset { | |
| 123 | + | |
| 124 | + public function init() { | |
| 125 | + $this->escape_method = 'esc_url_raw'; | |
| 126 | + } | |
| 127 | + | |
| 128 | + protected function unsanitised() { | |
| 129 | + return get_privacy_policy_url(); | |
| 130 | + } | |
| 131 | +} | |
| 132 | + | |
| 133 | +/** | |
| 134 | + * User Info | |
| 135 | + * | |
| 136 | + * Class SV_USER_INFO | |
| 137 | + */ | |
| 138 | +class SV_SC_USER_INFO extends SV_Preset { | |
| 139 | + | |
| 140 | + protected function unsanitised() { | |
| 141 | + | |
| 142 | + $args = $this->get_arguments(); | |
| 143 | + | |
| 144 | + $key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'ID'; | |
| 145 | + | |
| 146 | + $current_user = wp_get_current_user(); | |
| 147 | + | |
| 148 | + // Not logged in? | |
| 149 | + if ( false === $current_user->exists() ) { | |
| 150 | + return ''; | |
| 151 | + } | |
| 152 | + | |
| 153 | + switch ( $key ) { | |
| 154 | + | |
| 155 | + case 'user_login': | |
| 156 | + return $current_user->user_login; | |
| 157 | + break; | |
| 158 | + case 'user_email': | |
| 159 | + return $current_user->user_email; | |
| 160 | + break; | |
| 161 | + case 'user_firstname': | |
| 162 | + return $current_user->user_firstname; | |
| 163 | + break; | |
| 164 | + case 'user_lastname': | |
| 165 | + return $current_user->user_lastname; | |
| 166 | + break; | |
| 167 | + case 'display_name': | |
| 168 | + return $current_user->display_name; | |
| 169 | + break; | |
| 170 | + default: | |
| 171 | + return $current_user->ID; | |
| 172 | + | |
| 173 | + } | |
| 174 | + | |
| 175 | + return ''; | |
| 176 | + } | |
| 177 | +} | |