Main Content

AIOS All-in-One: How to Create Modules

This article will walk you through creating modules.

The first thing you need to do is to create a folder under wp-content/plugins/aios-all-in-one/modules you need to add the prefix aios- before the desired folder name. Keep in mind that whatever your folder name will be your module id.

Now that you have your aios-my-modules folder, create a new file inside and name it module.php the plugin runs only module.php inside the folder you created. This will be your main module file and its name should be the same as your module id.

Open your module main file and paste in the following code:

/**
 * Plugin Name: AIOS My Modules Name
 * Description: AIOS My Modules Description
 * Version: 1.0.0
 *
 * @package AIOS All-in-One
 * @subpackage AIOS My Modules Name
 * @since 1.0.0
 */

We need to defined module path add the following code.

defined( 'ABSPATH' ) or die( 'Plugin file cannot be accessed directly.' );
if ( !defined( 'AIOS_MY_MODULE_URL' ) ) define( 'AIOS_MY_MODULE_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'AIOS_MY_MODULE_DIR' ) ) define( 'AIOS_MY_MODULE_DIR', realpath( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR );

Modules are required to use object oriented language we need to check if class is exists, take note that you need a unique class.

if ( !class_exists( 'aios_my_module' ) ) {
	class aios_my_module {
	}
}

We will now add the basic functions to add your module under options