The purpose of the LifterLMS Coding Standards is to create a baseline for collaboration and review within the open source LifterLMS codebase, project, and community.
The WordPress community has developed coding standards and documented them in the WordPress codex. Wherever possible, the LifterLMS Coding Standards aim to obey these coding standards.
LifterLMS avoids camelCase
for class names, class methods, functions, and variables. Words should instead be separated by underscores.
Class names should use capitalized words separated by underscores.
LifterLMS core class names should be prefixed with LLMS_
.
class LLMS_Student extends LLMS_Abstract_User_Data { [...] }
class LLMS_Data { [...] }
LifterLMS add-on class names should be prefixed with LLMS_
as well as an additional add-on prefix.
class LLMS_AQ_Question_Types { [...] }
class LLMS_SL_Story extends LLMS_Abstract_Database_Store { [...] }
Trait names should use capitalized words separated by underscores.
LifterLMS core trait names should be prefixed with LLMS_Trait
.
trait LLMS_Trait_Singleton { [...] }
Constants should be in all upper-case with underscores separating words.
LifterLMS core constants should be prefixed with LLMS_
.
define( 'LLMS_PLUGIN_FILE', __FILE__ );
LifterLMS add-on class names should be prefixed with LLMS_
as well as an additional add-on prefix.
define( 'LLMS_FORMIDABLE_FORMS_PLUGIN_FILE', __FILE__ );
Files should be named descriptively using lower case letters. Hyphens should be used to separate words.
my-plugin-file.php
Class file names should be based on the class name with class-
prepended and the underscores in the class name replaced with hyphens, for example LLMS_Data
becomes:
class-llms-data.php
Files containing model classes should prepend model-
instead of class-
. For example the LLMS_Student
model class becomes:
model-llms-student.php
Trait file names should be based on the trait name with underscores replaced by hyphens and the file stored in the
includes/traits
directory. For example LLMS_Trait_Singleton
becomes:
includes/traits/llms-trait-singleton.php
Lowercase letters should be used for function names and variables. Separate words with underscores.
LifterLMS core functions should be prepended with the prefix llms_
.
llms_current_time( $type, $gmt = 0 ) { [...] }
LifterLMS add-on function names should be prefixed with llms_
as well as an additional add-on prefix.
llms_ck_consent_form_field() { [...] }
Lowercase letters should be used for hook names. Separate words with underscores.
LifterLMS core hooks should be prepended with the prefix llms_
.
do_action( 'llms_user_enrolled_in_course', [...] );
apply_filters( 'llms_get_enrollment_status', [...] );
LifterLMS add-on hook names should be prefixed with llms_
as well as an additional add-on prefix.
do_action( 'llms_pa_post_created_from_automation', [...] );
apply_filters( 'llms_sl_story_can_user_manage', [...] );
When actions are set to run before and after items (templates, as an example) it is acceptable to use additional prefixes before_
and after_
prior to the llms_
prefix.
There are a number of legacy hooks which use the prefix lifterlms_
instead of llms_
. These are retained for backwards compatibility but should not be used as an example of an acceptable naming convention for new code.
Class names and IDs should be lowercase and prefixed with llms-
.
Words should be separated with hyphens (AKA "kebab case").
<div class="llms-element-name" id="llms-element-id"></div>
The name
attribute of HTML form elements should be prefixed with llms_
.
Lowercase letters should be used and words should be separated by underscores.
<form>
<input name="llms_text_field" type="text">
</form>