1.01.1 Shared Functions - andperry256/my-base-theme-and-dbadmin Wiki

This section describes the functions contained within the file shared/functions.php. This file contains those functions which need to be accessed:-

  1. By scripts running outside the WordPress environment.
  2. By scripts in the wp-custom-scripts directory.
  3. By child theme scripts.


This and the following four functions are used both inside and outside the WordPress environment. The need for these functions arose from the fact that running an active session can cause issues within WordPress. They operate by saving session variables in the global array $GlobalSessionVars and logging any subsequent updates in the database table wp_session_updates. When the session variables are loaded on loading the next page, any updates from the database are then applied. In the WordPress environment, the active session is closed once the session variables have been saved/updated.

This function must be run immediately on loading the page. Within WordPress this script is automatically loaded by the theme. The following statement must be run at the end of the main theme functions.php script:-

add_action( 'init', 'run_session', 1);

The following four functions provide an interface that acts transparently with respect to how the session variable are being accessed. In each case the $name parameter specifies the name of the session variable and can be one of the following:-

  1. A string for a simple index to the session variable in the array.
  2. An array of two strings for a two-dimensional index to the session variable in the array.


This returns a boolean result to indicate if the given session variable is set.


This returns the value of a given session variable. The parameter $check is a boolean to indicate if the function first actively checks that the given variable is set.


This updates the value of a given session variable.


This deletes a give session variable.




This is described under My Base Theme.


This is described under My Base Theme.


This is called to set up HTML meta tags during page load. Please see Handling of Meta Data for further details.


This function is called to load the stylesheet from a given point in the page/category hierarchy. The directory location is determined from the two parameters - $path is typically the base directory of the page/category hierarchy and $sub_path is therefore the appropriate sub-directory. It will always load the styles.css script from the given path/sub-path if found. Additionally it may also load styles-light.css or styles-dark.css if the 'theme_mode' session variable is set to indicate a light or dark theme.


This function will cause the contents of a given stylesheet to be output within the text of a page, enclosed within a set of <style></style> tags. If the 'theme_mode' session variable is set to indicate a light or dark theme, it will also look for a <filename>-light.css or <filename>-dark.css script as appropriate.




Please see the separate sub-section for this file.