Functions.php is one of the two mandatory files in any WordPress system (the other is style.css). It contains system level functions and others which are used by more than one script (template or other PHP code). It also includes WordPress hooks (actions and filters). It has eight sections:
Section 1 Utility functions
Section 2 Dashboard customisation functions
Section 3 Basic functionality
Section 4 Widget and sidebar functions
Section 5 Page formatting functions
Section 6 List page generation functions
Section 7 WPForms functions
Section 8 Member App functions
Section 99 at the end of the file is commented out. It contains redundant code that has been removed from operational use but which has been retained in case it is ever needed again.
Section 1 – Utility functions
Name
Type
Purpose
mgf_start_session
Action
Starts a PHP session.
my_enqueue_function
Action
Permits AJAX calls from a front-end process. Not currently used by MGF but should be kept.
send_email_change_email
Filter
Disables the default WordPress process which sends an email to users when their email address or password is changed. For MGF, these emails are sent by the Member App.
wp_is_application_passwords_available
Filter
Disables the Application Passwords feature which allows applications (rather than users) to log into the system. For MGF, the feature is not required and is therefore disabled on the basis of ‘least privilege’.
show_private_pages_menu_selection
Filter
Allows the addition of private pages to menus.
Section 2 – Dashboard customisation functions
Name
Type
Purpose
remove_from_admin_bar
Action
Removes items from front-end admin bar.
my_remove_menu_pages
Action
Removes items from dashboard sidebar.
loginout_text_change
Filter
Changes the text of the login/logout menu item to a bilingual one.
mgf_redirect_logout
Action
Redirects logout to MGF home page rather the standard WP login page.
hook_new_media_columns
Action
Adds file name as a column in the media library list and makes it sortable. Calls 3 other functions ‘filename_xxx’.
list_maint_menu
Action
Adds ‘List Generation’ to Pages menu in dashboard.
Section 3 – Basic functionality
Name
Type
Purpose
add_theme_support(‘xxx’)*
Action
Initiates basic functionality to the MGF theme.
register_my_menu
Action
Registers the main menu (called by header.php).
* These actions were added at the start of the development of the MGF site and some or all of them are possibly redundant.
Content for widgets is added via the dashboard: Appearance -> Widgets. This will displa a list of available widgets by the name assigned to them in the registration entry.
Section 5 – Page formatting functions
This section contains functions that are used to format pages.
Name
Type
Purpose
get_attachment_url_by_slug
Function
Gets an image url from a slug, used for plant list pages.
format_comment
Function
Styles comments (not currently used by MGF).
custom_widget_title
Filter
Inserts a line break into a widget title.*
* The widget editor does not allow the insertion of HTML tags in the title. If the title is to be shown on two lines then insert ‘brnl’ where the line break is to occur. The filter will replace this with a <br> tag.
Section 6 – List page generation functions
This section contains the code for creating the List Generation page and for calling the generation of specific pages. It also contains functions used by the various list generation plugins.
Name
Type
Purpose
list_maintenance_contents
Function
Creates the list generation page in the dashboard and initiates the list generation process when a list is selected.
fplantname
Function
Inserts HTML tags where necessary to format plant name correctly (i.e. Latin words in italics).
mgf_strip_tags
Function
Strips all HTML tags except those specified in the second parameter. Used in list page plugins to control HTML inserted by wpdatatables HTML editor (TinyMCE).
please2_login
Function
Displays error message to logged out users if they try to generate a list page (called in all create-xxxx.php plugins).
Section 7 – WPForms functions
WPForms is a commercial plugin that allows the easy creation of forms. Each form created is given a unique number by which it is identified. MGF uses the plugin for:
adding new members (membership form and admin new member form)
bulk communications with members (broadcast and subscription renewals)
user login.
It has a number of filters and actions which allow supplementary processing.
Name
Type
Purpose
wpf_dev_user_registration_username_exists
Filter
Changes the plugin default User Registration Form error message for an already existing user name to a bilingual one.
wpf_dev_user_registration_email_exists
Filter
Changes the plugin default User Registration Form error message for an already existing email address to a bilingual one.
wpf_dev_user_registration_login_error
Filter
Changes the plugin default User Login Form error message to a bilingual one.
wpf_dev_process_redirect_url
Filter
If the form is the sign in form (15048), redirects the user to the dashboard.
wpf_dev_process
Action
For the Membership Form (15047), checks that the password and confirm password fields are equal.
wpf_dev_process_complete
Action
For different forms, performs additional processing required by the Member App. For details, see the WPForms page.
Section 8 – Member App functions
This section contains various functions used by the Member App.
Name
Type
Purpose
mgf_new_member_email
Function
Sends an email to new members when their registration is complete and to the management team informing them of this.
check_sign_in
Function
Checks that a user is properly signed in before allowing access to the script which calls it. Must be called in all Member App scripts.
check_privilege
Function
For management functions, checks that the user has sufficient privilege to use it.
mgf_profile_update
Function
Updates a member profile and send the member an appropriate email.
member_change_log
Function
Following a change to a member’s profile, adds a record to the member change log table.
remove_additional_capabilities_func
Filter
Removes ‘Additional capabilities’ from the standard WordPress profile page (redundant as this is not used by MGF).
check_send
Function
For contractual reasons with Brevo, we can only send one broadcast message per day. This function checks to see if one has already been sent today. If so, the user is invited to try again tomorrow.
remove_member
Function
Removes a former member’s details from the active member file and transfers the appropriate details to the former member table.
testblocklist
Function
Checks if the member is unsubscribed in Brevo.
dept_name_lookup
Function
Returns the name of a French département from number input.
Although the wp-content folder does contain some WordPress core code (see items marked * in the table below), its principal function is to house the additional code provided by third parties or developed in-house. It also stores the Media Library.
Third Party Code – Plugins
The WordPress core only provides basic functionality. Additional features can be added by means of plugins. There are thousands of these which will do most of what you might want to do but if all else fails, you can write your own. Many plugins are free but most have a premium version for which you have to pay. Maintenance of plugins is via the ‘Plugins’ item of the dashboard sidebar. Here you can see which plugins you have installed and whether or not they are activated. You can also search for new plugins in the WordPress Plugin Directory (and, for security reasons) nowhere else. The MGF site uses some 40 plugins (not counting in-house developments). Some of the functionality provided by these plugins is relatively simple (e.g. ones which provide additional blocks for the Gutenberg editor); others provide sophisticated and necessary functionalities such as site security and backup. MGF pays for five plugins; for the rest, the functionality provided by the free version is sufficient. Plugins are located in the wp-content/plugins folder. A full list of the plugins used by MGF can be found here.
Third Party Code – Additional Libraries
Additional functionality can also be provided by external code libraries. MGF uses two, both installed via the dependency manager, Composer. Brevo API links the Member App to the Brevo messaging system which MGF uses to send emails to members. The phpspreadsheet library allows WordPress code to interface with an Excel spreadsheet. This is used in a number in-house developed plugins that generate list pages. The code for these two libraries is stored in the wp-content/library-brevo and wp-content/phpspreadsheet folders, respectively.
Theme-related code
Plugins and libraries can be used across a site; other code will be limited to a given theme. Such code is stored in the wp-contents/themes/[themename] folder. The MGF site uses an in-house developed theme, mgftheme. Theme-related code can be grouped into five categories:
templates;
headers, footers and sidebars;
style sheets (CSS);
functions;
scripts.
When creating a WordPress page, the user assigns to it a template. This frames the content of the page and, together with the CSS files of the theme, determines its appearance. Templates are executable files which WordPress runs when the page is selected for display. WordPress has a default set of templates but users can create their own and the MGF site makes extensive use of these. For more details, see here.
Headers, footers and sidebars define the outline of a page. For more details, see here.
The principal style file for a WordPress theme is the style.css file. For more details on the style files used by the MGF theme, see here.
Although it is inadvisable to change the WordPress core code, the system does provide a means to add functionality at different points in its execution. This functionality is provided by filters and actions which are fired when certain events (such as a page load) occur. Both filters and actions cause code to be executed. Such code is stored in the functions.php file of the theme. This file also contains functions which are used in more than one template or plugin.
Most in-house developed code will be in either a template or in the functions.php file. However, some code modules will be used in more than one template and so these are stored in a separate folder: wp-content/scripts.
Media Library
Images and other files such as PDFs that are uploaded into the Media Library are stored in the wp-contents/uploads folder. This further subdivided by year and month of the upload. Thus, images uploaded in June 2022 will be found in the wp-content/uploads/2022/06 folder. When images are uploaded, WordPress automatically makesthree copies of them, correlating to the three image sizes in WordPress: thumbnail, medium, and large.
Some plugins also make use of the wp-content/uploads folder for their own purposes with folders of their own which should not be modified.
Content of wp-content folder as of 8 December 2023
Directory
Purpose
_js
JavaScript & jQuery code*
cache
WordPress cache folder*
Discarded files
Redundant in-house code kept in case needed again
images
A place to store images that are not part of the media library. For contents, see below.
languages
WordPress core directory*
library-brevo
API for Brevo mailing system plugin
library-phpspreadsheet
API for reading Excel spreadsheets in WordPress
logs
WordPress error log folder*
Nature
All the content relating to the ‘Gardening for Wildlife’ pages which were not converted from the format of the old site.
other_files
Non WordPress files used by in-house code
plugins
Additional modules, not part of the core, which provide additional functionality. See separate page (Plugins) for details.
scripts
A place to store independent code modules not included in the core, a plugin or a theme.
themes
Sets of files which define the look-and-feel of the site (layout, page tempates, styling and so on).
upgrade
WordPress system directory to rollback failed updates*
upgrade-temp-backup
WordPress system directory to rollback failed updates*
uploads
The Media Library and other files used by plugins and the Member App
wflogs
Folder used by WordFence security plugin*
* System files/folders that must not be modified
Content of wp-content/images folder as of 8 December 2023
The public_html folder contains all the code for the operation of the site; it also contains the Media Library. With one exception, all the site-specific content is in the wp-content folder and anything outside of this folder should not be modified other than by the standard update procedures (see the Site Management and Administration page). The exception is the group of three composer files, together with the accompanying vendor folder. These constitute the Brevo API which is used to send communications to members. There is a new version of this API which, when installed, will be placed in the wp-content folder. At this point the files and folder containing the old API can be deleted.
Contents of the public_html folder as of 8 December 2023
With the exception of the media items such as images and PDF files, the WordPress database contains all the information relating to the site:
the content of the public pages;
information regarding the structure of the site;
member information and their roles;
information used by plugins;
information used by MGF functions.
List of database tables as of 27 November 2023
NOTE: In a standard WP database the table names begin with ‘wp_’ – e.g. ‘wp_users’. For the MGF site, the prefix is ‘wp_mgf_’, so wp_mgf_users’. The prefix is defined in public_html/wp-config.php.
(Items marked with an asterisk indicate that there are several tables beginning with the text shown)
A WordPress installation has two components: a MySQL (MariaDB) database and a collection of folders in the site’s public_html folder.
The Database
The database is the heart of the system. Other than images and items like PDF documents, the database includes all of the site’s content. WordPress installations have no permanent HTML files; they are all generated dynamically from the database when called. All changes to a page are stored in the database, meaning that the Gutenberg editor can be used to go back to earlier versions if necessary. In addition to the page content, the database contains all user information. There are also tables which are inserted and used by plugins, both commercial and those developed by MGF. For example, the tables used to generate list pages are a combination of tables generated by the wpdatatables plugin and MGF information imported from the spreadsheet system used on the old site. For more details on the database see the WordPress Database page.
The public_html folder
The public_html folder contains all the code needed for the installation and operation of the site: This includes:
the standard WordPress code (the ‘core’);
plugins (additional code provided by external suppliers or developed by MGF);
code for themes;
other MGF-developed code (principally for the Member App).
WordPress code is written in PHP. The standard code (the ‘core’) can be found in the root public_HTML folder as well as the subfolders wp-admin and wp-includes. Some core code and all site-specific code and content can be found in the wp-content subfolder.
The public_html folder also contains the Media Library where images and other self-standing files such as PDFs are stored.