0

I have recently acquired a new client and migrated his website from the original developers hosting to his own hosting. Prior to transferring to the new hosting, the site was working fine. However, now i get the following error:

Fatal error: Can't use function return value in write context in /home/agingtree/public_html/dev/wp-content/themes/aging-tree/lib/vendor.php on line 55

Nothing has been modified other than the db to reflect the new domain and location etc. Here is the code around the issue that is showing. Any help is appreciated:

 /*
 * Vendor Query Vars
 */
add_filter('query_vars', 'vendor_query_vars');

function vendor_query_vars($vars){
    $vars[] = "vendor";
    $vars[] = "service-category";
    $vars[] = "service-subcategory";
    $vars[] = "city";
    $vars[] = "zip";
    return $vars;
}

/*
 * Vendor API Cache
 */
add_action('pre_get_posts', 'vendor_api_cache');

function vendor_api_cache(){
    if (!empty (get_query_var('vendor'))):

        $data = api_get('vendor',['id' => get_query_var('vendor')]);
        if(!empty($data[0])){
            $vendor = $data[0];
        }
        else{
            $vendor = null;
        }

        wp_cache_set('vendor',$vendor);

    endif;
}
4
  • 4
    Could you please identify what line 55 is? Commented Oct 13, 2015 at 13:02
  • 1
    I think it's related to this line: if (!empty (get_query_var('vendor'))):. Maybe this topic will help you: stackoverflow.com/questions/1532693/… Commented Oct 13, 2015 at 13:10
  • stackoverflow.com/a/2173318/1095913 it is the same link provided by @DavidAlsbright , just to the correct answer. You have to edit the first line of vendor_api_cache() Commented Oct 13, 2015 at 13:26
  • Here is line 55 code if (!empty (get_query_var('vendor'))): Commented Oct 13, 2015 at 14:06

1 Answer 1

3

This might be due to a different PHP version in the server, the problem resides in vendor_api_cache function, you cannot use a function call inside the empty() function, you must assign it to a variable then pass it to the empty() call:

function vendor_api_cache(){
    $vendor = get_query_var('vendor');
    if (!empty ($vendor)):
Sign up to request clarification or add additional context in comments.

4 Comments

When changing it like that, it now passes the following error: Fatal error: Can't use function return value in write context in /home/agingtree/public_html/dev/wp-content/themes/aging-tree/base.php on line 14
I changed the php version on the hosting, and now i can access the Wordpress Admin area (although it takes forever to load); however, when attempting to view the website itself, it gets stuck on a blank white page that is loading (down at the bottom it says waiting for dev.agingtree.com) any ideas what that is about?
About the first error you're having the same error, check that line at theme and you'll see something similar, change it like my answer. It should help the problem.
You're welcome. Then select my answer as the answer of this question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.