As WordPress assembles a list of all available plugins to display them in the administration interface, it does not check to see if each plugin's PHP code is valid. This check is actually done when a plugin is activated. At that time, any syntax error will be caught immediately and the newly-activated plugin will remain inactive, preventing a failure of the entire website.
That being said, once a plugin is activated, its code is evaluated every time WordPress renders a web page, and any subsequent code error that gets saved to the plugin file will cause the site to stop working correctly. For this reason, it is highly recommended to set up a local development environment, as shown in Chapter 1, Preparing a Local Development Environment, to avoid affecting a live site when an inevitable error creeps up in your plugin code. On a live website, to avoid potential outages, a safer method is to deactivate plugins before making changes to them, then reactivating them once changes have been made so that they are revalidated before their functionality is enabled. It should be noted that, with this method, the plugin's functionality won't be available on your site while you make changes, so it is not an optimal way to modify deployed code.
Once the code is working correctly, the second part of this recipe shows us how to visualize the information that is received by a custom filter function. While the WordPress Codex website provides great documentation about the purpose of most filters available, it does not go into details about the structure of the information that is sent to each filter function. Thankfully, the PHP print_r function comes in very handy, since it can display the content of any variable on the screen, no matter what information is stored in the variable it receives as an argument.
Last, but not least, the implementation of the custom filter function uses the WordPress API function is_user_logged_in() to see whether the person viewing the site has provided login credentials, and then goes on to parse all the menu items and remove the Private Area menu item if the visitor is not logged in.