Created
November 15, 2017 18:15
-
-
Save dartiss/2097c32dda644499a40980c517054c0e to your computer and use it in GitHub Desktop.
WordPress Plugin to List all Site Cookies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_cookies( $paras = '', $content = '' ) { | |
if ( strtolower( $paras[ 0 ] ) == 'novalue' ) { $novalue = true; } else { $novalue = false; } | |
if ( $content == '' ) { $seperator = ' : '; } else { $seperator = $content; } | |
$cookie = $_COOKIE; | |
ksort( $cookie ); | |
$content = "<ul>n"; | |
foreach ( $cookie as $key => $val ) { | |
$content .= '<li>' . $key; | |
if ( !$novalue ) { $content .= $seperator . $val; } | |
$content .= "</li>n"; | |
} | |
$content .= "</ul>n"; | |
return do_shortcode( $content ); | |
} | |
add_shortcode( 'cookies', 'get_cookies' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this plugin. It works like a charm. I slightly modified your code as it displayed a lot of superfluous 'n' characters and I preferred to display cookie names in bold font.
One question: here on GitHub you write
whereas your blog says
What's the correct location for adding your plugin: functions.php in the root folder or functions.php in the theme folder?
Thanks in advance for your answer
Modified code:
<?php // Modified WordPress Plugin to List all Site Cookies from https://gist.github.com/dartiss/2097c32dda644499a40980c517054c0e // Add this to your site's functions.php and then use the shortcode [cookies] on a post or page to display all the site's cookies. function get_cookies( $paras = '', $content = '' ) { if ( strtolower( $paras[ 0 ] ) == 'novalue' ) { $novalue = true; } else { $novalue = false; } if ( $content == '' ) { $seperator = ' : '; } else { $seperator = $content; } $cookie = $_COOKIE; ksort( $cookie ); $content = "<ul>"; foreach ( $cookie as $key => $val ) { $content .= '<li><b>' . $key . '</b>'; if ( !$novalue ) { $content .= $seperator . $val; } $content .= "</li>"; } $content .= "</ul>"; return do_shortcode( $content ); } add_shortcode( 'cookies', 'get_cookies' ); // End of plugin ?>