| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: URL Params |
| 4 |
Plugin URI: http://asandia.com/wordpress-plugins/urlparams/ |
| 5 |
Description: Short Code to grab any URL Parameter |
| 6 |
Version: 1.8 |
| 7 |
Author: Jeremy B. Shapiro |
| 8 |
Author URI: http://www.asandia.com/ |
| 9 |
*/ |
| 10 |
|
| 11 |
/* |
| 12 |
URL Params (Wordpress Plugin) |
| 13 |
Copyright (C) 2011-2015 Jeremy Shapiro |
| 14 |
|
| 15 |
*/ |
| 16 |
|
| 17 |
//tell wordpress to register the shortcodes |
| 18 |
add_shortcode("urlparam", "urlparam"); |
| 19 |
add_shortcode("ifurlparam", "ifurlparam"); |
| 20 |
|
| 21 |
function urlparam($atts) { |
| 22 |
$atts = shortcode_atts(array( |
| 23 |
'param' => '', |
| 24 |
'default' => '', |
| 25 |
'dateformat' => '', |
| 26 |
'attr' => '' |
| 27 |
), $atts); |
| 28 |
|
| 29 |
$params = preg_split('/\,\s*/',$atts['param']); |
| 30 |
|
| 31 |
$return = false; |
| 32 |
|
| 33 |
foreach($params as $param) |
| 34 |
{ |
| 35 |
if(!$return and ($rawtext = $_REQUEST[$param])) |
| 36 |
{ |
| 37 |
if(($atts['dateformat'] != '') && strtotime($rawtext)) |
| 38 |
{ |
| 39 |
$return = date($atts['dateformat'], strtotime($rawtext)); |
| 40 |
} else { |
| 41 |
$return = esc_html($rawtext); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if(!$return) { |
| 47 |
$return = $atts['default']; |
| 48 |
} |
| 49 |
|
| 50 |
if($atts['attr']) { |
| 51 |
return ' '.$atts['attr'].'="'.$return.'" '; |
| 52 |
} else { |
| 53 |
return $return; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
/* |
| 58 |
* If 'param' is found and 'is' is set, compare the two and display the contact if they match |
| 59 |
* If 'param' is found and 'is' isn't set, display the content between the tags |
| 60 |
* If 'param' is not found and 'empty' is set, display the content between the tags |
| 61 |
* |
| 62 |
*/ |
| 63 |
function ifurlparam($atts, $content) { |
| 64 |
$atts = shortcode_atts(array( |
| 65 |
'param' => '', |
| 66 |
'empty' => false, |
| 67 |
'is' => false, |
| 68 |
), $atts); |
| 69 |
|
| 70 |
$params = preg_split('/\,\s*/',$atts['param']); |
| 71 |
|
| 72 |
foreach($params as $param) |
| 73 |
{ |
| 74 |
if($_REQUEST[$param]) |
| 75 |
{ |
| 76 |
if($atts['empty']) |
| 77 |
{ |
| 78 |
return ''; |
| 79 |
} elseif(!$atts['is'] or ($_REQUEST[$param] == $atts['is'])) { |
| 80 |
return do_shortcode($content); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
if ($atts['empty']) |
| 86 |
{ |
| 87 |
return do_shortcode($content); |
| 88 |
} |
| 89 |
|
| 90 |
return ''; |
| 91 |
} |
| 92 |
|
| 93 |
?> |
| 94 |
|