Mediterranean Gardening France

What's New? / Quoi de neuf ?

FAQ
Join / Adhérer
Contact Us / Nous contacter

The functions.php File

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

NameTypePurpose
mgf_start_sessionActionStarts a PHP session.
my_enqueue_functionActionPermits AJAX calls from a front-end process. Not currently used by MGF but should be kept.
send_email_change_emailFilterDisables 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_availableFilterDisables 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_selectionFilterAllows the addition of private pages to menus.

Section 2 – Dashboard customisation functions

NameTypePurpose
remove_from_admin_barActionRemoves items from front-end admin bar.
my_remove_menu_pagesActionRemoves items from dashboard sidebar.
loginout_text_changeFilterChanges the text of the login/logout menu item to a bilingual one.
mgf_redirect_logoutActionRedirects logout to MGF home page rather the standard WP login page.
hook_new_media_columnsActionAdds file name as a column in the media library list and makes it sortable. Calls 3 other functions ‘filename_xxx’.
list_maint_menuActionAdds ‘List Generation’ to Pages menu in dashboard.

Section 3 – Basic functionality

NameTypePurpose
add_theme_support(‘xxx’)*ActionInitiates basic functionality to the MGF theme.
register_my_menuActionRegisters 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.

Section 4 – Widget and sidebar functions

This section registers the widgets to be used in sidebars and the footer. Example:

function diaries_widgets_init() {
	register_sidebar( array(
		'name'          => 'Garden Diaries',
		'id'            => 'garden-diaries',
		'before_title'	=> '<h5>',
		'after_title'	=> '</h5>',
	    'before_widget' => '<span>',
		'after_widget'  => '</span>',
	) );
}
add_action( 'widgets_init', 'diaries_widgets_init' );

To insert a widget in a sidebar, its id as registered here must be called in the appropriate sidebar-xxx.php file:

<div class="sidebar-right-325 sidebar-style">
<?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'garden-diaries' ) ) : ?>
<?php endif; ?>
</div>

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.

NameTypePurpose
get_attachment_url_by_slugFunctionGets an image url from a slug, used for plant list pages.
format_commentFunctionStyles comments (not currently used by MGF).
custom_widget_titleFilterInserts 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.

NameTypePurpose
list_maintenance_contentsFunctionCreates the list generation page in the dashboard and initiates the list generation process when a list is selected.
fplantnameFunctionInserts HTML tags where necessary to format plant name correctly (i.e. Latin words in italics).
mgf_strip_tagsFunctionStrips 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_loginFunctionDisplays 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.

NameTypePurpose
wpf_dev_user_registration_username_existsFilterChanges the plugin default User Registration Form error message for an already existing user name to a bilingual one.
wpf_dev_user_registration_email_existsFilterChanges the plugin default User Registration Form error message for an already existing email address to a bilingual one.
wpf_dev_user_registration_login_errorFilterChanges the plugin default User Login Form error message to a bilingual one.
wpf_dev_process_redirect_urlFilterIf the form is the sign in form (15048), redirects the user to the dashboard.
wpf_dev_processActionFor the Membership Form (15047), checks that the password and confirm password fields are equal.
wpf_dev_process_completeActionFor 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.

NameTypePurpose
mgf_new_member_emailFunctionSends an email to new members when their registration is complete and to the management team informing them of this.
check_sign_inFunctionChecks 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_privilegeFunctionFor management functions, checks that the user has sufficient privilege to use it.
mgf_profile_updateFunctionUpdates a member profile and send the member an appropriate email.
member_change_logFunctionFollowing a change to a member’s profile, adds a record to the member change log table.
remove_additional_capabilities_funcFilterRemoves ‘Additional capabilities’ from the standard WordPress profile page (redundant as this is not used by MGF).
check_sendFunctionFor 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_memberFunctionRemoves a former member’s details from the active member file and transfers the appropriate details to the former member table.
testblocklistFunctionChecks if the member is unsubscribed in Brevo.
dept_name_lookupFunctionReturns the name of a French département from number input.
find_folder_idFunctionReturns the id. of a Brevo list folder name

Loading

The wp-content Folder

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 makes three 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

DirectoryPurpose
_jsJavaScript & jQuery code*
cacheWordPress cache folder*
Discarded filesRedundant in-house code kept in case needed again
imagesA place to store images that are not part of the media library.  For contents, see below.
languagesWordPress core directory*
library-brevoAPI for Brevo mailing system plugin
library-phpspreadsheetAPI for reading Excel spreadsheets in WordPress
logsWordPress error log folder*
NatureAll the content relating to the ‘Gardening for Wildlife’ pages which were not converted from the format of the old site.
other_filesNon WordPress files used by in-house code
pluginsAdditional modules, not part of the core, which provide additional functionality.  See separate page (Plugins) for details.
scriptsA place to store independent code modules not included in the core, a plugin or a theme.
themesSets of files which define the look-and-feel of the site (layout, page tempates, styling and so on).
upgradeWordPress system directory to rollback failed updates*
upgrade-temp-backupWordPress system directory to rollback failed updates*
uploadsThe Media Library and other files used by plugins and the Member App
wflogsFolder used by WordFence security plugin*
* System files/folders that must not be modified

Content of wp-content/images folder as of 8 December 2023

File nameDescription
facebook.pngFacebook icon shown on footer of all pages.
headerlogo.pngLogo that appears on website header pages
instagram.pngInstagram icon shown on footer of all pages.
logopng.pngThe MGF olive branch
MGFlogoemailnew.pngLogo that appears on Member App emails

Loading

The public_html Folder

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

File or Directory namePurpose
.well-knownUsed by the SSL certificate
vendorBrevo API
wp-adminWordPress core directory
wp-contentWordPress core directory and user content
wp-includesWordPress core directory
.htaccessApache (server) configuration file
.htaccess.bkPrevious version of the above
.user.iniUsed by Wordfence
bv_connector_…Used by BlogVault
composer.jsonComposer file for Brevo API
composer.lockComposer file for Brevo API
composer.pharComposer file for Brevo API
google5acbdf7729d6479e.htmlGoogle site verification
index.phpStarts WordPress
license.txtWordPress licence
readme.htmlWordPress introduction
sitemap.xmlGoogle? site map
wordfence-waf.phpUsed by Wordfence
wp-activate.phpWordPress core file
wp-blog-header.phpWordPress core file
wp-comments-post.phpWordPress core file
wp-config-earlier.phpWordPress core file
wp-config.phpWordPress core file
wp-config-sample.phpWordPress core file
wp-cron.phpWordPress core file
wp-links-opml.phpWordPress core file
wp-load.phpWordPress core file
wp-login.phpWordPress core file
wp-mail.phpWordPress core file
wp-settings.phpWordPress core file
wp-signup.phpWordPress core file
wp-trackback.phpWordPress core file
xmlrpc.phpWordPress core file (but blocked by .htaccess)

Loading

The WordPress Database

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)

TablePurpose
noc_autologinUnknown – possibly to do with Mailcube
wp_mgf_actionscheduler*WPForms plugin
wp_mgf_booksMGF list
wp_mgf_cli*GDPR Cookie Consent plugin
wp_mgf_commentmetaWP standard
wp_mgf_commentsWP standard
wp_mgf_departementsMGF member app
wp_mgf_email_addressesMGF member app
wp_mgf_former_membersMGF member app
wp_mgf_gmp*Easy Google Maps plugin
wp_mgf_linksWP standard
wp_mgf_litespeed*Litespeed plugin
wp_mgf_member_change_logMGF member app
wp_mgf_mgmlp_foldersFolders plugin
wp_mgf_optionsWP standard
wp_mgf_plantsMGF list
wp_mgf_postmetaWP standard
wp_mgf_postsWP standard
wp_mgf_privilegesMGF member app
wp_mgf_pvc*Page Views Count plugin
wp_mgf_recommendationsMGF list
wp_mgf_relevanssi*Relevassi plugin
wp_mgf_reviewsMGF list
wp_mgf_sgpb*Popup Builder plugin
wp_mgf_sib*Brevo plugin
wp_mgf_termmetaWP standard
wp_mgf_termsWP standard
wp_mgf_term_relationshipsWP standard
wp_mgf_term_taxonomyWP standard
wp_mgf_usermetaWP standard
wp_mgf_usersWP standard
wp_mgf_visitsMGF list
wp_mgf_wf*Wordfence plugin
wp_mgf_wildlife_plantsMGF list
wp_mgf_wpdata*Wpdatatables plugin
wp_mgf_wpforms*WPForms plugin
wp_mgf_wp_phpmyadmin_extension__errors_logphpMyAdmin plugin
wp_mgf_yoast*Yoast plugin

For a description of the purpose of the WordPress standard tables, see the WordPress Database Description.

To view the database, click ‘WP-phpMyAdmin’ in the dashboard sidebar and then click ‘Enter local phpMyAdmin’.

Loading

Technical Implementation

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.

Loading