Table of Contents
Elementor Page Builder is an extendable plugin, you can add your own extensions and addons on top of Elementor, just like WordPress core. Elementor extensions are the same as regular WordPress plugins, they extend the basic functionality.
But before we start, let’s examine the proper way to write code for Elementor. In this page you can find the best practice for Elementor developers.
Coding Standards
Websites use Elementor daily, any extension developed for Elementor should have an unified and pleasant experience while maintaining WordPress plugin guidelines, coding standards, best practice, and not do anything malicious.
Note that you can also define a check for code standard in PHPStorm.
Plugin File Name
The name of the file that runs the plugin should be in-tune with the plugin folder name. For example: plugin-name/plugin-name.php.
Domain Names
We recommend using autoloader and namespace according to the PSR-2 standard.
Translation
The texts oriented for the user should be written in English, while using the WordPress translation function: __() / _e(). The translation text domain should be consistent with the plugin name. For example plugin-name and not initials like pn.
Testing
The code should be tested with WP_DEBUG mode on, this way you can see the the PHP notices and warnings. This will make sure you catch bugs before releasing your extension to the general public.
Prevent Data Leaks
Elementor extensions should try to prevent direct access to PHP files. This can be done by adding the following code after the opening PHP tag in each PHP file:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Extending Elementor
How can you extend Elementor? See the following tutorials: