PHP Notice: Undefined index: group
-
Since I started using URLParams I see hundreds of notices in my debug log as follows:
[17-Feb-2017 11:10:16 UTC] PHP Notice: Undefined index: group in /home/SITENAME/public_html/wp-content/plugins/url-params/urlparams.php on line 39
-
Same here:
Notice: Undefined index: SelPlatform in /xxxxx/xxxxx/xxxxxx.dev/wp-content/plugins/url-params/urlparams.php on line 39
Did you find a workaround (I see this question was left unanswered for 4 months+)
I run WordPress 4.8.
ChrisNo, we haven’t found a workaround and never heard from the developer.
Thanks for your reply.
I was able to auto-answer my own question:
After researching, I found that the problem comes from the $_REQUEST[$param] instructions (there are 2 of them)..
When there is no query string on the URL, trying to use $_REQUEST[$param] generates an “Undefined index:” warning.
In order to avoid this, you need to check if $_REQUEST is set before to use it by doing:
if(isset($_REQUEST[$param])){}
I updated the code of the plugin accordingly and no more warnings.
I copy and paste it below hoping the code will survive the editor formatting.
Simply edit the plugin form WordPress and copy paste this code in replacement of the existing code.
I suggest the author of the plugin to validate this update and to make a new version.<?php /* Plugin Name: URL Params Plugin URI: https://asandia.com/wordpress-plugins/urlparams/ Description: Short Code to grab any URL Parameter Version: 2.1 Author: Jeremy B. Shapiro Author URI: https://www.asandia.com/ ---------------------------------------------------------------------- Updated by chrisK200 on July 4 2017 (search chrisK200 comments in the code) to avoid Undefined index notices. See this trhead in the support forum: https://www.ads-software.com/support/topic/php-notice-undefined-index-group/ ---------------------------------------------------------------------- */ /* URL Params (WordPress Plugin) Copyright (C) 2011-2016 Jeremy Shapiro */ //tell wordpress to register the shortcodes add_shortcode("urlparam", "urlparam"); add_shortcode("ifurlparam", "ifurlparam"); function urlparam($atts, $content) { $defaults = array( 'param' => '', 'default' => '', 'dateformat' => '', 'attr' => '', 'htmltag' => false, ); # 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. $atts = array_merge($defaults, $atts); $params = preg_split('/\,\s*/',$atts['param']); $return = false; foreach($params as $param) { // chrisK200 ------------------- if(isset($_REQUEST[$param])){ // chrisK200 ------------------- if(!$return and ($rawtext = $_REQUEST[$param])) { if(($atts['dateformat'] != '') && strtotime($rawtext)) { $return = date($atts['dateformat'], strtotime($rawtext)); } else { $return = esc_html($rawtext); } } // chrisK200 } // chrisK200 } if(!$return) { $return = $atts['default']; } if($atts['attr']) { $return = ' ' . $atts['attr'] . '="' . $return . '" '; if($atts['htmltag']) { $tagname = $atts['htmltag']; foreach(array_keys($defaults) as $key) { unset($atts[$key]); } $otheratts = ""; foreach($atts as $key => $val) { $otheratts .= " $key=\"$val\""; } $return = "<$tagname $otheratts $return".($content ? ">$content</$tagname>" : "/>"); } } return $return; } /* * If 'param' is found and 'is' is set, compare the two and display the contact if they match * If 'param' is found and 'is' isn't set, display the content between the tags * If 'param' is not found and 'empty' is set, display the content between the tags * */ function ifurlparam($atts, $content) { $atts = shortcode_atts(array( 'param' => '', 'empty' => false, 'is' => false, ), $atts); $params = preg_split('/\,\s*/',$atts['param']); foreach($params as $param) { // chrisK200 ------------------- if(isset($_REQUEST[$param])){ // chrisK200 ------------------- if($_REQUEST[$param]) { if($atts['empty']) { return ''; } elseif(!$atts['is'] or ($_REQUEST[$param] == $atts['is'])) { return do_shortcode($content); } } // chrisK200 } // chrisK200 } if ($atts['empty']) { return do_shortcode($content); } return ''; } ?>
Seriously, this plugin author doesn’t seem to bother answering any support requests, so you should perhaps fork the plugin with this bug fix.
- The topic ‘PHP Notice: Undefined index: group’ is closed to new replies.