Jump to content
KeithW

PHP errors Help needed

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Hi Barand,

 

Not sure where to start with this one, Im new to php

Where would I put the Var dump

 

Regards

 

Keith

Share this post


Link to post
Share on other sites

$rules does not exist prior to

$rules = $resortPro->ssml_routes_for_search_results_pages();

so no point putting it before that line.

Share this post


Link to post
Share on other sites

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');
	    }
	}
}

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
Posted (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 by ginerjm
"isn't" not 'is'

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.