How to Declare a function in functions.php
-
I have written a custom function that is then called inside another function. The aim of these functions is to filter posts/pages seen by the user and also provide them with a roaming profile functionality where they can choose where they are and it will show them the posts/pages associated with their site code.
I have written code snippets where these two functions work together and everything works well! However, when I try and put it into my functions.php file it doesnt seem to like the “Sites()” function and it is breaking the site.
Is there a certain way a function needs to be set up so that it doesnt break the site?
I have checked the syntax multiple times and there are no errors.Here is my function:
function Sites() { global $strLocations; $current_user = wp_get_current_user(); $current_user_Location= get_metadata( 'user', $current_user->ID, 'mo_ldap_local_custom_attribute_l', true ); $strLocations = "'All'"; if ($current_user_Location == 'CR'){ $strLocations .= ",'Craigavon'"; $strLocations .= ",'UK'"; } if ($current_user_Location == 'BE'){ $strLocations .= ",'Belfast'"; $strLocations .= ",'UK'"; } if ($current_user_Location == 'CH'){ $strLocations .= ",'Charnwood'"; $strLocations .= ",'UK'"; } if ($current_user_Location == 'EL'){ $strLocations .= ",'Edinburgh'"; $strLocations .= ",'UK'"; } if ($current_user_Location == 'MA'){ $strLocations .= ",'Manchester'"; $strLocations .= ",'UK'"; } if ($current_user_Location == 'AT'){ $strLocations .= ",'Arran'"; $strLocations .= ",'Ireland'"; } if ($current_user_Location == 'DK'){ $strLocations .= ",'Dundalk'"; $strLocations .= ",'Ireland'"; } if ($current_user_Location == 'GC'){ $strLocations .= ",'Garrycastle'"; $strLocations .= ",'Ireland'"; } if ($current_user_Location == 'NC'){ $strLocations .= ",'North Carolina'"; $strLocations .= ",'US'"; } if ($current_user_Location == 'PA'){ $strLocations .= ",'Pennsylvania'"; $strLocations .= ",'US'"; } if ($current_user_Location == 'SF'){ $strLocations .= ",'San Francisco'"; $strLocations .= ",'US'"; } if ($current_user_Location == 'SG'){ $strLocations .= ",'Singapore'"; $strLocations .= ",'Asia-Pac'"; } if ($current_user_Location == 'JP'){ $strLocations .= ",'Japan'"; $strLocations .= ",'Asia-Pac'"; } return $strLocations; }
Then this is called below in another function. When I remove my Sites() function, the site is back up and running again, so therefore the problem must lie here?
Can anyone guide me on why this would be breaking my site?
- The topic ‘How to Declare a function in functions.php’ is closed to new replies.