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;
}
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • 4
    Could you please identify what line 55 is? – Jon Tan Oct 13 '15 at 13:02
  • 1
    I think it's related to this line: `if (!empty (get_query_var('vendor'))):`. Maybe this topic will help you: http://stackoverflow.com/questions/1532693/weird-php-error-cant-use-function-return-value-in-write-context – David Alsbright Oct 13 '15 at 13:10
  • http://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() – Sir_Faenor Oct 13 '15 at 13:26
  • Here is line 55 code if (!empty (get_query_var('vendor'))): – JohnsonMktg Oct 13 '15 at 14:06

1 Answers1

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)):
Skatox
  • 4,237
  • 12
  • 42
  • 47
  • 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 – JohnsonMktg Oct 13 '15 at 14:13
  • 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? – JohnsonMktg Oct 13 '15 at 14:56
  • 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. – Skatox Oct 13 '15 at 19:42
  • You're welcome. Then select my answer as the answer of this question. – Skatox Oct 14 '15 at 21:41