All the Places You Can Include Your Plugin Files in The FOJ And How to Include the Files
You can include files of your plugin of The FOJ in both the admin and public part of the website.
NOTE: It is important to read this tutorial step by step as it could be difficult to understand the various parts if you jump the steps.
In the admin part of The FOJ website, the places you can include the files of your plugin are as follows:
-
$aInAjaxPage_[]
Files will be included inadmin/ajax.php
.$aInAjaxPage_[]
is used when you want your method or function to be called in response to ajax calls.
-
$aInsideFooter_[]
Files will be included in the body of the admin part of the site just before the</body>
tag. Normally, CSS and JavaScript files are included in the body through$aInsideFooter_[]
-
$aInsideHeader_[]
Files will be included between the<head>
and</head>
of the admin part of the site. Normally, CSS and JavaScript files are included in the head of the admin part of The FOJ website through$aInsideHeader_[]
-
$aPrivatePageMiddle_[]
Files will be included in the middle ofadmin/account.php
. Methods and functions of admin pages are called here.
In the public part of The FOJ website, the places you can include the files of your plugin are as follows:
-
$aAllPagesTop_[]
Files are included at the top ofaccount.php
,auth.php
,index.php
,login.php
, andregister.php
(including pages, posts and categories created in admin) before any plugin file includes and outside of the page's HTML. When files are included via$aAllPagesTop_[]
, it is as if the files were included via$aAuthPageTop_[]
$aLoginPageTop_[]
,$aPageTop_[]
,$aPrivatePageTop_[]
and$aRegisterPageTop_[]
. So when a file is included using$aAllPagesTop_[]
, the same file should not be included using$aAuthPageTop_[]
$aLoginPageTop_[]
,$aPageTop_[]
,$aPrivatePageTop_[]
or$aRegisterPageTop_[]
.
-
$aAllPagesMiddle_[]
Files are included in the middle ofaccount.php
,auth.php
,index.php
,login.php
, andregister.php
(including pages, posts and categories created in admin). When files are included using$aAllPagesMiddle_[]
, it is as if the files were included via$aAuthPageMiddle_[]
$aLoginPageMiddle_[]
,$aPageMiddle_[]
,$aPrivatePageMiddle_[]
and$aRegisterPageMiddle_[]
. So when a file is included using$aAllPagesMiddle_[]
, the same file should not be included using$aAuthPageMiddle_[]
$aLoginPageMiddle_[]
,$aPageMiddle_[]
,$aPrivatePageMiddle_[]
or$aRegisterPageMiddle_[]
.
-
$aAuthPageTop_[]
Files are included at the top ofauth.php
beforerequire_once('header.php')
outside of the page's HTML code.
-
$aAuthPageMiddle_[]
Files are included in middle ofauth.php
within the page's HTML
-
$aInAjaxPage_[]
Files will be included inajax.php
.$aInAjaxPage_[]
is used when you want your method or function to be called in response to ajax calls.
-
$aInCronPage_[]
Files will be included incron.php
.$aInCronPage_[]
is used when you want your method or function to be called when cron job runs.
-
$aInsideFooter_[]
Files will be included in the body just before the</body>
tag. Normally CSS and JavaScript files are included in the body via$aInsideFooter_[]
-
$aInsideHeader_[]
Files will be included between<head>
and</head>
. Normally CSS and JavaScript files are included in the head via$aInsideHeader_[]
-
$aLoginPageTop_[]
Files will be included at the top oflogin.php
beforerequire_once('header.php');
outside of the page's HMTL.
-
$aLoginPageMiddle_[]
Files will be included in the middle oflogin.php
within the page's HMTL.
-
$aMaintenancePageTop_[]
Files will be included at the top of maintenance page inthemes/{current_theme_name}/maintenance.php
outside of the page's HTML.
-
$aMaintenancePageMiddle_[]
Files will be included at the middle of maintenance page inthemes/{current_theme_name}/maintenance.php
within the page's HTML.
-
$aPageTop_[]
Files will be included at the top of pages, posts and categories created in the admin outside of the page's HTML.
-
$aPageMiddle_[]
Files will be included in the middle of pages, posts and categories created in the admin after the content of the page but within the page's HTML.
-
$aPrivatePageTop_[]
Files will be included at the top ofaccount.php
beforeheader-fluid.php
outside of the page's HTML.account.php
is where users are redirected to after they have logged in with password and email address.
-
$aPrivatePageMiddle_[]
Files will be included in the middle ofaccount.php
.account.php
is where users are redirected to after they have logged in with password and email address.
-
$aRegisterPageTop_[]
Files are included at the top ofregister.php
beforerequire_once('header.php')
outside of the page's HTML.
-
$aRegisterPageMiddle_[]
Files are included in the middle ofregister.php
within the page's HTML
How to Include Your Plugin Files in The FOJ
To include files of your plugin in the FOJ website, let's learn the structure of a plugin of The FOJ
Below is the directory structure of a simple plugin:
The directories are:
plugins > my_plugin >
- classes
- css
- includes
- js
The
my_plugin
directory is the name of an example plugin and the main directory that contains the other directories which are classes
, css
, includes
and js
. The my_plugin
directory is inside the plugins
directory of The FOJ like so plugins/my_plugin
.
Not all the directories may be neccessary in your plugin. Also the names of the directories of your plugin don't have to be the same as listed above. You can change them except the
inlcudes
directory which must remain the same name. Creating the directories of Your Plugin
To learn how to include your plugin files in The FOJ, create the directories of your plugin:
-
Inside the
plugins
directory of The FOJ, create the directory of your plugin. For the sake of this example, name itmy_plugin
.
-
Inside the
my_plugin
directory, create other directories namedclasses
,css
,includes
andjs
.
- Now that you have created the directories of your plugin, let's move to how to include the files of your plugin in The FOJ
How to Include the Files of Your Plugin in the Admin Part of a Website of The FOJ
In the admin part of a website of The FOJ, you can include the files of your plugin via $aInAjaxPage_[]
, $aInsideFooter_[]
, $aInsideHeader_[]
and $aPrivatePageMiddle_[]:
. Let's look at them one by one:
-
$aInAjaxPage_[]
To include files of your plugin via$aInAjaxPage_[]
, please refer to this tutorial Calling a method or function of your plugin inside ajax.php in the admin
-
$aInsideFooter_[]
and$aInsideHeader_[]
To include files of your plugin in The FOJ website via$aInsideFooter_[]
and$aInsideHeader_[]
, please, refer to this tutorial: Including CSS and JavaScript files of Your Plugin in the Head and Body of The FOJ Website
-
$aPrivatePageMiddle_[]:
To include the files of your plugin in The FOJ website via$aPrivatePageMiddle_[]:
, please refer to this tutorial: Calling a method or function of a plugin as admin page
How to Include the Files of Your Plugin in the Public Part of a Website of The FOJ
Let us create the file that will be included in The FOJ website. This file will be a class and will be named My_Plugin.php
. You can name this file any name but for the sake of this example, let it be My_Plugin.php
. Put this file in the classes
directory like so: plugins/my_plugin/classes/My_Plugin.php
. In the My_Plugin.php
write the methods of the class like so:
Editing plugins/my_plugin/classes/My_Plugin.php
<?php
class My_Plugin{ //Class name
//To be called inside a page or post
function write_a_paragraph(){
echo '<p>This is a paragraph</p>';
}
//Protected page
function protected_page(){
if(isset($_GET['ipage']) && $_GET['ipage'] === 'protected-page'){
//get user id
$iUserId = thefoj_get('user_id');
//check if user id is available
if(!empty($iUserId)){
?>
<div class = "col-12 section-col">
<h1 class = "fsize-28">This is a Protected Page </h1>
<p>
Hello <?php echo thefoj_user('user_full_name');?>, welcome to a protected page.
</p>
</div>
<?php
}
}
}
}
?>
Next, create a PHP file named
includes.php
. The name of this file should not be changed; it must remain includes.php
. Put this file inside the includes
directory of your plugin like so plugins/my_plugin/includes/includes.php
. Write a multi-line comment in this file like so: Editing
plugins/my_plugin/includes/includes.php
<?php
/**
* @Author : Kyei Osei Yaw
* @Company : Nationton Information Technology
* @Website : https://thefoj.net
* @Email : info@thefoj.net
* @Copyright : Your copyright notice,
* @Version : 1.0
* @Year : 2023
*/
?>
It is important to maintain the multi-line comment. But modify its parameters to suit your plugin. The comment must have @Author, @Company, @Website, @Email, @Copyright, @Version and @Year in the parttern as in the example above.
Now, let's look at the various places in The FOJ website where you can include the files of your plugin in the public part of the website.
Various Places in The FOJ Website Where You can Include the Files of Your Plugin in the Public Part of the Website.
-
$aAllPagesTop_[]
If files of your plugin are included in The FOJ website via$aAllPagesTop_[]
, the files will be included at the top ofaccount.php
,auth.php
,index.php
,login.php
, andregister.php
(including pages, posts and categories created in admin) as if the files were included via$aAuthPageTop_[]
$aLoginPageTop_[]
,$aPageTop_[]
,$aPrivatePageTop_[]
and$aRegisterPageTop_[]
. Suppose that, from theMy_Plugin.php
file, we want to call the methodwrite_a_paragraph()
. Then, create a PHP file and name itcall_methods.php
. You can name this file any name you want but for the sake of this example, name itcall_methods.php
. Put this file in theincludes
directory of your plugin like so:plugins/my_plugin/includes/call_methods.php
. In thecall_methods.php
, call the methodwrite_a_paragraph()
like so:
Editingplugins/my_plugin/includes/call_methods.php
<?php //Call the write_a_paragraph() method $oMyPlugin = new My_Plugin(); $oMyPlugin->write_a_paragraph(); ?>
In the above code, the class name in theMy_Plugin.php
isMy_Plugin
. Also,write_a_paragraph()
is a method in this class. So the above code is how to call thewrite_a_paragraph()
method.
Next, in theincludes.php
, make reference to theMy_Plugin.php
and thecall_methods.php
like so:
<?php /** * @Author : Kyei Osei Yaw * @Company : Nationton Information Technology * @Website : https://thefoj.net * @Email : info@thefoj.net * @Copyright : Your copyright notice, * @Version : 1.0 * @Year : 2023 */ //This will include My_Plugin.php at the top of account.php, auth.php, index.php, login.php, and register.php (including pages, posts and categories created in admin) $aAllPagesTop_[] = 'plugins/my_plugin/classes/My_Plugin.php'; //This will include call_methods.php in the middle of auth.php, index.php, and call the method write_a_paragraph() $aAuthPageMiddle_[] = 'plugins/my_plugin/includes/call_methods.php'; //This will include call_methods.php in the middle of login.php, and register.php and call the method write_a_paragraph() $aLoginPageMiddle_[] = 'plugins/my_plugin/includes/call_methods.php'; //This will include call_methods.php in the middle of pages, posts and categories created in admin and call the method write_a_paragraph() $aPageMiddle_[] = 'plugins/my_plugin/includes/call_methods.php'; //This will include call_methods.php in the middle of account.php and call the method write_a_paragraph() $aPrivatePageMiddle_[] = 'plugins/my_plugin/includes/call_methods.php'; //This will include call_methods.php in the middle of register.php and call the method write_a_paragraph() $aRegisterPageMiddle_[] = 'plugins/my_plugin/includes/call_methods.php'; ?>
Once you have made reference toMy_Plugin.php
andcall_methods.php
in theincludes.php
as in the above, theMy_Plugin.php
will be included at the top ofaccount.php
,auth.php
,index.php
,login.php
, andregister.php
andcall_methods.php
will be included in the middle ofaccount.php
,auth.php
,index.php
,login.php
, andregister.php
where the methodwrite_a_paragraph()
will also be called.
-
$aAuthPageTop_[]
and$aAuthPageMiddle_[]
Suppose that, from theMy_Plugin.php
file, we want to call the methodwrite_a_paragraph()
. Then, create a PHP file and name itcall_methods_in auth.php
. You can name this file any name you want but for the sake of this example, name itcall_methods_in_auth.php
. Put this file in theincludes
directory of your plugin like so:plugins/my_plugin/includes/call_methods_in_auth.php
. In thecall_methods_in_auth.php
, call the methodwrite_a_paragraph()
like so:
Editingplugins/my_plugin/includes/call_methods_in_auth.php
<?php //Call the write_a_paragraph() method $oMyPlugin = new My_Plugin(); $oMyPlugin->write_a_paragraph(); ?>
In the above code, the class name in theMy_Plugin.php
isMy_Plugin
. Also,write_a_paragraph()
is a method in this class. So the above code is how to call thewrite_a_paragraph()
method.
Next, in theincludes.php
, make reference to theMy_Plugin.php
and thecall_methods_in_auth.php
like so:
<?php /** * @Author : Kyei Osei Yaw * @Company : Nationton Information Technology * @Website : https://thefoj.net * @Email : info@thefoj.net * @Copyright : Your copyright notice, * @Version : 1.0 * @Year : 2023 */ //This will include My_Plugin.php at the top of auth.php $aAuthPageTop_[] = 'plugins/my_plugin/classes/My_Plugin.php'; //This will include call_methods_in_auth.php in the middle of auth.php and call the method write_a_paragraph() $aAuthPageMiddle_[] = 'plugins/my_plugin/includes/call_methods_in_auth.php'; ?>
Once you have made reference toMy_Plugin.php
andcall_methods_in_auth.php
in theincludes.php
as in the above, theMy_Plugin.php
will be included at the top ofauth.php
andcall_methods_in_auth.php
will be included in the middle ofauth.php
where the methodwrite_a_paragraph()
will also be called.
-
$aInAjaxPage_[]
To include files of your plugin via$aInAjaxPage_[]
, please refer to this tutorial: Calling a method or function of your plugin inside ajax.php at the public part of the site
-
$aInCronPage_[]
To include files of your plugin via$aInCronPage_[]
, please refer to this tutorial: Calling a method or function of your plugin inside cron.php
-
$aInsideFooter_[]
and$aInsideHeader_[]
To include files of your plugin via$aInsideFooter_[]
and$aInsideHeader_[]
, please refer to this tutorial: Including CSS and JavaScript files of Your Plugin in the Head and Body of The FOJ Website
-
$aLoginPageTop_[]
and$aLoginPageMiddle_[]
Suppose that, from theMy_Plugin.php
file, we want to call the methodwrite_a_paragraph()
. Then, create a PHP file and name itcall_methods_in_login.php
. You can name this file any name you want but for the sake of this example, name itcall_methods_in_login.php
. Put this file in theincludes
directory of your plugin like so:plugins/my_plugin/includes/call_methods_in_login.php
. In thecall_methods_in_login.php
, call the methodwrite_a_paragraph()
like so:
Editingplugins/my_plugin/includes/call_methods_in_login.php
<?php //Call the write_a_paragraph() method $oMyPlugin = new My_Plugin(); $oMyPlugin->write_a_paragraph(); ?>
In the above code, the class name in theMy_Plugin.php
isMy_Plugin
. Also,write_a_paragraph()
is a method in this class. So the above code is how to call thewrite_a_paragraph()
method.
Next, in theincludes.php
, make reference to theMy_Plugin.php
and thecall_methods_in_login.php
like so:
<?php /** * @Author : Kyei Osei Yaw * @Company : Nationton Information Technology * @Website : https://thefoj.net * @Email : info@thefoj.net * @Copyright : Your copyright notice, * @Version : 1.0 * @Year : 2023 */ //This will include My_Plugin.php at the top of login.php $aLoginPageTop_[] = 'plugins/my_plugin/classes/My_Plugin.php'; //This will include call_methods_in_login.php in the middle of login.php and call the method write_a_paragraph() $aLoginPageMiddle_[] = 'plugins/my_plugin/includes/call_methods_in_login.php'; ?>
Once you have made reference toMy_Plugin.php
andcall_methods_in_login.php
in theincludes.php
as in the above, theMy_Plugin.php
will be included at the top oflogin.php
andcall_methods_in_login.php
will be included in the middle oflogin.php
where the methodwrite_a_paragraph()
will also be called.
-
$aMaintenancePageTop_[]
and$aMaintenancePageMiddle_[]
Suppose that, from theMy_Plugin.php
file, we want to call the methodwrite_a_paragraph()
. Then, create a PHP file and name itcall_methods_in_maintenance.php
. You can name this file any name you want but for the sake of this example, name itcall_methods_in_maintenance.php
. Put this file in theincludes
directory of your plugin like so:plugins/my_plugin/includes/call_methods_in_maintenance.php
. In thecall_methods_in_maintenance.php
, call the methodwrite_a_paragraph()
like so:
Editingplugins/my_plugin/includes/call_methods_in_maintenance.php
<?php //Call the write_a_paragraph() method $oMyPlugin = new My_Plugin(); $oMyPlugin->write_a_paragraph(); ?>
In the above code, the class name in theMy_Plugin.php
isMy_Plugin
. Also,write_a_paragraph()
is a method in this class. So the above code is how to call thewrite_a_paragraph()
method.
Next, in theincludes.php
, make reference to theMy_Plugin.php
and thecall_methods_in_maintenance.php
like so:
<?php /** * @Author : Kyei Osei Yaw * @Company : Nationton Information Technology * @Website : https://thefoj.net * @Email : info@thefoj.net * @Copyright : Your copyright notice, * @Version : 1.0 * @Year : 2023 */ //This will include My_Plugin.php at the top of themes/{current_theme_name}/maintenance.php $aMaintenancePageTop_[] = 'plugins/my_plugin/classes/My_Plugin.php'; //This will include call_methods_in_maintenance.php in the middle of themes/{current_theme_name}/maintenance.php and call the method write_a_paragraph() $aMaintenancePageMiddle_[] = 'plugins/my_plugin/includes/call_methods_in_maintenance.php'; ?>
Once you have made reference toMy_Plugin.php
andcall_methods_in_maintenance.php
in theincludes.php
as in the above, theMy_Plugin.php
will be included at the top ofthemes/{current_theme_name}/maintenance.php
andcall_methods_in_maintenance.php
will be included in the middle ofthemes/{current_theme_name}/maintenance.php
where the methodwrite_a_paragraph()
will also be called.
-
$aPageTop_[]
and$aPageMiddle_[]
Suppose that, from theMy_Plugin.php
file, we want to call the methodwrite_a_paragraph()
. Then, create a PHP file and name itcall_methods_in_pages_and_posts.php
. You can name this file any name you want but for the sake of this example, name itcall_methods_in_pages_and_posts.php
. Put this file in theincludes
directory of your plugin like so:plugins/my_plugin/includes/call_methods_in_pages_and_posts.php
. In thecall_methods_in_pages_and_posts.php
, call the methodwrite_a_paragraph()
like so:
Editingplugins/my_plugin/includes/call_methods_in_pages_and_posts.php
<?php //Call the write_a_paragraph() method $oMyPlugin = new My_Plugin(); $oMyPlugin->write_a_paragraph(); ?>
In the above code, the class name in theMy_Plugin.php
isMy_Plugin
. Also,write_a_paragraph()
is a method in this class. So the above code is how to call thewrite_a_paragraph()
method.
Next, in theincludes.php
, make reference to theMy_Plugin.php
and thecall_methods_in_pages_and_posts.php
like so:
<?php /** * @Author : Kyei Osei Yaw * @Company : Nationton Information Technology * @Website : https://thefoj.net * @Email : info@thefoj.net * @Copyright : Your copyright notice, * @Version : 1.0 * @Year : 2023 */ //This will include My_Plugin.php at the top of pages and posts and categories $aPageTop_[] = 'plugins/my_plugin/classes/My_Plugin.php'; //This will include call_methods_in_pages_and_posts.php in the middle of pages and posts and categories and call the method write_a_paragraph() $aPageMiddle_[] = 'plugins/my_plugin/includes/call_methods_in_pages_and_posts.php'; ?>
Once you have made reference toMy_Plugin.php
andcall_methods_in_pages_and_posts.php
in theincludes.php
as in the above, theMy_Plugin.php
will be included at the top ofpages and posts and categories
andcall_methods_in_pages_and_posts.php
will be included in the middle ofpages and posts and categories
where the methodwrite_a_paragraph()
will also be called.
-
$aPrivatePageTop_[]
and$aPrivatePageMiddle_[]
Suppose that, from theMy_Plugin.php
file, we want to call the methodprotected_page()
. Then, create a PHP file and name itcall_methods_in_private_page.php
. You can name this file any name you want but for the sake of this example, name itcall_methods_in_private_page.php
. Put this file in theincludes
directory of your plugin like so:plugins/my_plugin/includes/call_methods_in_private_page.php
. In thecall_methods_in_private_page.php
, call the methodprotected_page()
like so:
Editingplugins/my_plugin/includes/call_methods_in_private_page.php
<?php //Call the write_a_paragraph() method $oMyPlugin = new My_Plugin(); $oMyPlugin->protected_page(); ?>
In the above code, the class name in theMy_Plugin.php
isMy_Plugin
. Also,protected_page()
is a method in this class. So the above code is how to call theprotected_page()
method.
Next, in theincludes.php
, make reference to theMy_Plugin.php
and thecall_methods_in_private_page.php
like so:
<?php /** * @Author : Kyei Osei Yaw * @Company : Nationton Information Technology * @Website : https://thefoj.net * @Email : info@thefoj.net * @Copyright : Your copyright notice, * @Version : 1.0 * @Year : 2023 */ //This will include My_Plugin.php at the top of account.php $aPageTop_[] = 'plugins/my_plugin/classes/My_Plugin.php'; //This will include call_methods_in_private_page.php in the middle of account.php and call the method protected_page() $aPageMiddle_[] = 'plugins/my_plugin/includes/call_methods_in_private_page.php'; ?>
Once you have made reference toMy_Plugin.php
andcall_methods_in_private_page.php
in theincludes.php
as in the above, theMy_Plugin.php
will be included at the top ofaccount.php
andcall_methods_in_private_page.php
will be included in the middle ofaccount.php
where the methodprotected_page()
will also be called.
-
$aRegisterPageTop_[]
and$aRegisterPageMiddle_[]
Suppose that, from theMy_Plugin.php
file, we want to call the methodwrite_a_paragraph()
. Then, create a PHP file and name itcall_methods_in_register_page.php
. You can name this file any name you want but for the sake of this example, name itcall_methods_in_register_page.php
. Put this file in theincludes
directory of your plugin like so:plugins/my_plugin/includes/call_methods_in_register_page.php
. In thecall_methods_in_register_page.php
, call the methodwrite_a_paragraph()
like so:
Editingplugins/my_plugin/includes/call_methods_in_register_page.php
<?php //Call the write_a_paragraph() method $oMyPlugin = new My_Plugin(); $oMyPlugin->write_a_paragraph(); ?>
In the above code, the class name in theMy_Plugin.php
isMy_Plugin
. Also,write_a_paragraph()
is a method in this class. So the above code is how to call thewrite_a_paragraph()
method.
Next, in theincludes.php
, make reference to theMy_Plugin.php
and thecall_methods_in_register_page.php
like so:
<?php /** * @Author : Kyei Osei Yaw * @Company : Nationton Information Technology * @Website : https://thefoj.net * @Email : info@thefoj.net * @Copyright : Your copyright notice, * @Version : 1.0 * @Year : 2023 */ //This will include My_Plugin.php at the top of register.php $aRegisterPageTop_[] = 'plugins/my_plugin/classes/My_Plugin.php'; //This will include call_methods_in_register_page.php in the middle of register.php and call the method write_a_paragraph() $aRegisterPageMiddle_[] = 'plugins/my_plugin/includes/call_methods_in_register_page.php'; ?>
Once you have made reference toMy_Plugin.php
andcall_methods_in_register_page.php
in theincludes.php
as in the above, theMy_Plugin.php
will be included at the top ofregister.php
andcall_methods_in_register_page.php
will be included in the middle ofregister.php
where the methodwrite_a_paragraph()
will also be called.