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.

run_session()

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.

session_var_is_set($name)

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

get_session_var($name,$check=true)

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.

update_session_var($name,$value)

This updates the value of a given session variable.

delete_session_var($name)

This deletes a give session variable.

set_default_header_image_paths()

set_header_image_paths($slug,$type)

output_page_header()

This is described under My Base Theme.

get_content_part($part_no)

This is described under My Base Theme.

output_meta_data()

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

output_stylesheet_link($path,$sub_path)

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.

include_inline_stylesheet($path)

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.

output_to_access_log($user='',$add_info='')

readable_markup($str)

coded_text_to_html($url)

Please see the separate sub-section for this file.