Here are some starting rules to keep in mind:
Although WordPress recommends php 7, the code should work on php 5.3. Don’t use php 5.4+ features (such as short array syntax, array dereference on call), because some hosting providers don’t have php 5.4+ installed on the servers.
Follow WordPress Coding Standards.
Note
If you already have some code written with spaces indentation (that does not follow WordPress Coding Standards), use this RegExp to replace spaces with tabs:
(?<=^\s*) {4}
replace with\t
-
, _
etc. Examples of project names are: disrupt
, estato
.projectnametheme
and not contain any special characters such as -
, _
etc. Examples of theme names and theme folder names are disrupttheme
, estatotheme
.projectname-plugin
, examples: disrupt-plugin
, estato-plugin
. Plugin class name should be FW_CT_Bee_Projectname_Plugin
, examples: FW_CT_Bee_Disrupt_Plugin
, FW_CT_Bee_Estato_Plugin
.projectname-demo-plugin
, examples: disrupt-demo-plugin
, estato-demo-plugin
. Demo Plugin class name should be FW_CT_Bee_Projectname_Demo_Plugin
, examples: FW_CT_Bee_Disrupt_Demo_Plugin
, FW_CT_Bee_Estato_Demo_Plugin
.In every theme, the text domain to use is ct_theme
which at later point is automatically changed to theme name.
$label = __( 'This text is translatable', 'ct_theme' );
Important
Do not use ct_theme
as a part of variable name or function name or anywhere besides text-domain as it will be replaced during the build.
In both theme and plugin everything is prefixed to prevent naming conflicts and to give a meaning to functions, classes and methods names. See the guidelines below.
Important
Prefix everything! Lack of proper prefixes is a frequent theme reject reason. Read more: Reject Reasons
In theme development, a unique and more than 2 letters prefix is required by ThemeForest reviewers, therefore the prefix to use in a theme is fw_ct_bee_
for variables, functions, classes, and fw-ct-bee-
for styles, image sizes, db options etc.
Functions and classes should be prefixed with:
fw_ct_bee_
for functionsFW_Ct_Bee
for classesfunction fw_ct_bee_head() { // ... } class FW_Ct_Bee_Pagination { // ... }
Private functions and classes should be prefixed the same way due to ThemeForest standards
Functions used for hooks should be prefixed with:
fw_ct_bee_action_
foradd_action()
fw_ct_bee_filter_
foradd_filter()
/** * @internal */ function fw_ct_bee_filter_the_content($content) { // ... return $content; } add_filter('the_content', 'fw_ct_bee_filter_the_content'); /** * @internal */ function fw_ct_bee_action_init() { // ... } add_action('init', 'fw_ct_bee_action_init');
Filters and actions should be prefixed with fw_ct_bee_
.
$data = apply_filters('fw_ct_bee_whatever', $data); do_action('fw_ct_bee_whatever');
Public functions and classes should be prefixed with:
fw_ext_<extension-name>_
for functionsFW_Ext_<extension-name>_
for classes
Private functions and classes should be prefixed the same way due to ThemeForest standards
Functions used for hooks should be prefixed with:
fw_ext_<extension-name>_action_
foradd_action()
fw_ext_<extension-name>_filter_
foradd_filter()
For e.g. if extension name is
demo
:/** * @internal */ function fw_ext_demo_filter_the_content($content) { // ... return $content; } add_filter('the_content', 'fw_ext_demo_filter_the_content'); /** * @internal */ function fw_ext_demo_action_init() { // ... } add_action('init', 'fw_ext_demo_action_init');
Filters and actions should be prefixed with 'fw_ext_<extension-name>_'
.
For e.g. if extension name is
demo
:$data = apply_filters('fw_ext_demo_whatever', $data); do_action('fw_ext_demo_whatever');
Public functions and classes should be prefixed with:
fw_
for functionsFW_
for classesfunction fw_useful_function() { // ... } class FW_Useful_Class { // ... }Note
A Public function is meant to be used by anyone. Usually it’s a helper function that does something useful.
Private functions and classes should be prefixed with:
_fw_
for functions_FW_
for classes/** * @internal */ function _fw_private_function() { // ... } /** * @internal */ class _FW_Private_Class { // ... }Note
A private function is used somewhere internally. Don’t forget to use the @internal tag in your PhpDoc in order to make it clear to other developers that this is a private function. It will also remove the function from your documentation (if you are using an automatic documentation generator)
Functions and methods used for hooks should be prefixed with:
_action_
foradd_action()
_filter_
foradd_filter()
/** * @internal */ function _action_init_something() { // ... } add_action('init', '_action_init_something');Important
Be sure the function name is unique enough in order to minimize the chances to be defined by someone else. Do not use too simple function names like
_action_init
.class FW_Example { public function __construct() { add_filter('the_content', array($this, '_filter_the_content')); } /** * @internal */ public function _filter_the_content($content) { // ... return $content; } }
Filters and actions should be prefixed with 'fw_'
.
$data = apply_filters('fw_whatever', $data); do_action('fw_whatever');