| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: URL Params |
| 4 | 4 | Plugin URI: http://asandia.com/wordpress-plugins/urlparams/ |
| 5 | 5 | Description: Short Code to grab any URL Parameter |
| 6 | -Version: 2.1 | |
| 6 | +Version: 2.3 | |
| 7 | 7 | Author: Jeremy B. Shapiro |
| 8 | 8 | Author URI: http://www.asandia.com/ |
| 9 | 9 | */ |
| 10 | 10 | |
| @@ -9,17 +9,19 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | /* |
| 12 | 12 | URL Params (Wordpress Plugin) |
| 13 | -Copyright (C) 2011-2016 Jeremy Shapiro | |
| 13 | +Copyright (C) 2011-2022 Jeremy Shapiro | |
| 14 | 14 | |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -//tell wordpress to register the shortcodes | |
| 17 | +// error_reporting(E_ALL); // Helpful for checking for warnings that are TYPICALLY hidden but may be present on some installs | |
| 18 | + | |
| 19 | +// Tell WordPress to register the shortcodes | |
| 18 | 20 | add_shortcode("urlparam", "urlparam"); |
| 19 | 21 | add_shortcode("ifurlparam", "ifurlparam"); |
| 20 | 22 | |
| 21 | -function urlparam($atts, $content) { | |
| 23 | +function urlparam($attributes, $content) { | |
| 22 | 24 | $defaults = array( |
| 23 | 25 | 'param' => '', |
| 24 | 26 | 'default' => '', |
| 25 | 27 | 'dateformat' => '', |
| @@ -26,48 +28,51 @@ | ||
| 26 | 28 | 'attr' => '', |
| 27 | 29 | 'htmltag' => false, |
| 28 | 30 | ); |
| 29 | 31 | |
| 30 | - # we used to use shortcode_atts(), but that would nuke an extra attributes that we don't know about but want. array_merge() keeps them all. | |
| 31 | - $atts = array_merge($defaults, $atts); | |
| 32 | + // We used to use shortcode_atts(), but that would nuke an extra attributes that we don't know about but want. array_merge() keeps them all. | |
| 33 | + $attributes = array_merge($defaults, $attributes); | |
| 32 | 34 | |
| 33 | - $params = preg_split('/\,\s*/',$atts['param']); | |
| 35 | + $params = preg_split('/,\s*/',$attributes['param']); | |
| 34 | 36 | |
| 35 | 37 | $return = false; |
| 36 | 38 | |
| 37 | 39 | foreach($params as $param) |
| 38 | 40 | { |
| 39 | - if(!$return and ($rawtext = $_REQUEST[$param])) | |
| 40 | - { | |
| 41 | - if(($atts['dateformat'] != '') && strtotime($rawtext)) | |
| 42 | - { | |
| 43 | - $return = date($atts['dateformat'], strtotime($rawtext)); | |
| 41 | + if(!$return | |
| 42 | + && array_key_exists($param, $_REQUEST) | |
| 43 | + && ($rawText = $_REQUEST[$param]) | |
| 44 | + ) { | |
| 45 | + if(($attributes['dateformat'] != '') | |
| 46 | + && strtotime($rawText) | |
| 47 | + ) { | |
| 48 | + $return = date($attributes['dateformat'], strtotime($rawText)); | |
| 44 | 49 | } else { |
| 45 | - $return = esc_html($rawtext); | |
| 50 | + $return = esc_html($rawText); | |
| 46 | 51 | } |
| 47 | 52 | } |
| 48 | 53 | } |
| 49 | 54 | |
| 50 | 55 | if(!$return) { |
| 51 | - $return = $atts['default']; | |
| 56 | + $return = $attributes['default']; | |
| 52 | 57 | } |
| 53 | 58 | |
| 54 | - if($atts['attr']) { | |
| 55 | - $return = ' ' . $atts['attr'] . '="' . $return . '" '; | |
| 59 | + if($attributes['attr']) { | |
| 60 | + $return = ' ' . $attributes['attr'] . '="' . $return . '" '; | |
| 56 | 61 | |
| 57 | - if($atts['htmltag']) { | |
| 58 | - $tagname = $atts['htmltag']; | |
| 62 | + if($attributes['htmltag']) { | |
| 63 | + $tagName = $attributes['htmltag']; | |
| 59 | 64 | |
| 60 | 65 | foreach(array_keys($defaults) as $key) { |
| 61 | - unset($atts[$key]); | |
| 66 | + unset($attributes[$key]); | |
| 62 | 67 | } |
| 63 | 68 | |
| 64 | - $otheratts = ""; | |
| 65 | - foreach($atts as $key => $val) { | |
| 66 | - $otheratts .= " $key=\"$val\""; | |
| 69 | + $otherAttributes = ""; | |
| 70 | + foreach($attributes as $key => $val) { | |
| 71 | + $otherAttributes .= " $key=\"$val\""; | |
| 67 | 72 | } |
| 68 | 73 | |
| 69 | - $return = "<$tagname $otheratts $return".($content ? ">$content</$tagname>" : "/>"); | |
| 74 | + $return = "<$tagName $otherAttributes $return".($content ? ">$content</$tagName>" : "/>"); | |
| 70 | 75 | } |
| 71 | 76 | } |
| 72 | 77 | |
| 73 | 78 | return $return; |
| @@ -78,31 +83,33 @@ | ||
| 78 | 83 | * If 'param' is found and 'is' isn't set, display the content between the tags |
| 79 | 84 | * If 'param' is not found and 'empty' is set, display the content between the tags |
| 80 | 85 | * |
| 81 | 86 | */ |
| 82 | -function ifurlparam($atts, $content) { | |
| 83 | - $atts = shortcode_atts(array( | |
| 87 | +function ifurlparam($attributes, $content) { | |
| 88 | + $attributes = shortcode_atts(array( | |
| 84 | 89 | 'param' => '', |
| 85 | 90 | 'empty' => false, |
| 86 | 91 | 'is' => false, |
| 87 | - ), $atts); | |
| 92 | + ), $attributes); | |
| 88 | 93 | |
| 89 | - $params = preg_split('/\,\s*/',$atts['param']); | |
| 94 | + $params = preg_split('/,\s*/',$attributes['param']); | |
| 90 | 95 | |
| 91 | 96 | foreach($params as $param) |
| 92 | 97 | { |
| 93 | 98 | if($_REQUEST[$param]) |
| 94 | 99 | { |
| 95 | - if($atts['empty']) | |
| 100 | + if($attributes['empty']) | |
| 96 | 101 | { |
| 97 | 102 | return ''; |
| 98 | - } elseif(!$atts['is'] or ($_REQUEST[$param] == $atts['is'])) { | |
| 103 | + } elseif(!$attributes['is'] | |
| 104 | + || ($_REQUEST[$param] == $attributes['is']) | |
| 105 | + ) { | |
| 99 | 106 | return do_shortcode($content); |
| 100 | 107 | } |
| 101 | 108 | } |
| 102 | 109 | } |
| 103 | 110 | |
| 104 | - if ($atts['empty']) | |
| 111 | + if ($attributes['empty']) | |
| 105 | 112 | { |
| 106 | 113 | return do_shortcode($content); |
| 107 | 114 | } |
| 108 | 115 | |