PluginProbe
URL Params / 1.7
URL Params v1.7
trunk 1.6 1.7 1.8 2.0 2.1 2.2 2.3 2.4 2.5 2.5-review
url-params / urlparams.php

urlparams.php in URL Params 1.7, at urlparams.php

83 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.7
7 Author: Jeremy B. Shapiro
8 Author URI: http://www.asandia.com/
9 */
10
11 /*
12 URL Params (Wordpress Plugin)
13 Copyright (C) 2011-2014 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 ), $atts);
27
28 $params = preg_split('/\,\s*/',$atts['param']);
29
30 foreach($params as $param)
31 {
32 if($rawtext = $_REQUEST[$param])
33 {
34 if(($atts['dateformat'] != '') && strtotime($rawtext))
35 {
36 return date($atts['dateformat'], strtotime($rawtext));
37 } else {
38 return esc_html($rawtext);
39 }
40 }
41 }
42
43 return $atts['default'];
44 }
45
46 /*
47 * If 'param' is found and 'is' is set, compare the two and display the contact if they match
48 * If 'param' is found and 'is' isn't set, display the content between the tags
49 * If 'param' is not found and 'empty' is set, display the content between the tags
50 *
51 */
52 function ifurlparam($atts, $content) {
53 $atts = shortcode_atts(array(
54 'param' => '',
55 'empty' => false,
56 'is' => false,
57 ), $atts);
58
59 $params = preg_split('/\,\s*/',$atts['param']);
60
61 foreach($params as $param)
62 {
63 if($_REQUEST[$param])
64 {
65 if($atts['empty'])
66 {
67 return '';
68 } elseif(!$atts['is'] or ($_REQUEST[$param] == $atts['is'])) {
69 return do_shortcode($content);
70 }
71 }
72 }
73
74 if ($atts['empty'])
75 {
76 return do_shortcode($content);
77 }
78
79 return '';
80 }
81
82 ?>
83