KeithW Posted March 12, 2019 Share Posted March 12, 2019 Hi All, Im new to here, so a big HI to all I have been pulling my hair out trying to remove some errors from a wordpress plugin, the vendor says its fine but when you end up with log files over 40MB and have to delete each few days I'm not convinced From the many lines of my log file I have these [12-Mar-2019 20:48:23 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/xxxxxxx/public_html/wp-content/plugins/streamline-core/resortpro.php on line 202 Line starting 199 to 205 of the addressed file function streamshare_rewrite_rules(){ $resortPro = ResortPro(); $rules = $resortPro->ssml_routes_for_search_results_pages(); foreach($rules as $page_s_id => $rule) { add_rewrite_rule(''.$rule.'/(.+)/?','index.php?page_id='.$page_s_id.'&stream_search=$matches[1]','top'); } } Can anyone help me here Regards Keith Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/ Share on other sites More sharing options...
Barand Posted March 12, 2019 Share Posted March 12, 2019 The first thing to do is var_dump($rules); It should be an array. If it isn't then you need to invstigate why $resortPro->ssml_routes_for_search_results_pages() isn't returning an array. Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565181 Share on other sites More sharing options...
KeithW Posted March 12, 2019 Author Share Posted March 12, 2019 Hi Barand, Not sure where to start with this one, Im new to php Where would I put the Var dump Regards Keith Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565182 Share on other sites More sharing options...
Barand Posted March 12, 2019 Share Posted March 12, 2019 $rules does not exist prior to $rules = $resortPro->ssml_routes_for_search_results_pages(); so no point putting it before that line. Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565183 Share on other sites More sharing options...
KeithW Posted March 12, 2019 Author Share Posted March 12, 2019 Hi I got up on screen NULL Keith Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565184 Share on other sites More sharing options...
KeithW Posted March 12, 2019 Author Share Posted March 12, 2019 This is what Ive put Not sure if its right function streamshare_rewrite_rules(){ $resortPro = ResortPro(); $rules = $resortPro->ssml_routes_for_search_results_pages(); if(is_array($rules) || is_object($rules)){ foreach($rules as $page_s_id => $rule) { add_rewrite_rule(''.$rule.'/(.+)/?','index.php?page_id='.$page_s_id.'&stream_search=$matches[1]','top'); } } } Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565185 Share on other sites More sharing options...
ginerjm Posted March 12, 2019 Share Posted March 12, 2019 Where's the "var_dump" call? Or have you jumped past that and are checking for a valid result before calling the loop? If skipping the loop what are returning to the caller of this function? Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565186 Share on other sites More sharing options...
KeithW Posted March 12, 2019 Author Share Posted March 12, 2019 The var dump showed "NULL" on white screen So I assumed that the value isn't set so the foreach shouldn't be ran But when the result is defined it should pass and complete the foreach PS Im not a programmer, just starting out :-( Keith Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565187 Share on other sites More sharing options...
ginerjm Posted March 12, 2019 Share Posted March 12, 2019 (edited) So if your function isn't doing the loop, what purpose will it serve if it doesn't return some kind of answer? Or as Barand already told you - why don't you find out why the function ISN'T finding an array result? Could be a hidden problem. Edited March 12, 2019 by ginerjm "isn't" not 'is' Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565188 Share on other sites More sharing options...
KeithW Posted March 13, 2019 Author Share Posted March 13, 2019 Hi The function calls up extra pages when the streamshare function is live The visual side of the site has the function to browse these but its disabled at the vendor The plugin connects to them via an API - so whilst the values aint defined its trying to parse them Keith Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565207 Share on other sites More sharing options...
ginerjm Posted March 13, 2019 Share Posted March 13, 2019 That is what I was asking. If your api is providing data your function needs to feed that back (return 'true' or 'false') so that the script can avoid having an error. Quote Link to comment https://forums.phpfreaks.com/topic/308454-php-errors-help-needed/#findComment-1565212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.