Coding Standards - Mashikul-islam-Pranto/Blood-Bank-Management-System GitHub Wiki
Some parts of the WordPress code structure for PHP markup are inconsistent in their style. WordPress is working to gradually improve this by helping users maintain a consistent style so the code can become clean and easy to read at a glance.
Single and double quotes are using when it is appropriate. Evaluating anything in the string, using single quotes.
echo '<a href="/static/link" title="Yeah yeah!">Link name</a>';
echo "<a href='$link' title='$linktitle'>$linkname</a>";
Indentation should always reflect the logical structure.
[tab]$foo = 'somevalue';
[tab]$foo2 = 'somevalue2';
[tab]$foo34 = 'somevalue3';
[tab]$foo5 = 'somevalue4';
Braces shall be used for all blocks.
if ( condition ) {
action1();
action2();
} elseif ( condition2 && condition3 ) {
action3();
action4();
} else {
defaultaction();
}
if ( condition ) {
action1();
action2();
} elseif ( condition2 && condition3 ) {
action3();
action4();
} else {
defaultaction();
}
Where appropriate, closures may be used as an alternative to creating new functions to pass as callbacks.
$caption = preg_replace_callback(
'/<[a-zA-Z0-9]+(?: [^<>]+>)*/',
function ( $matches ) {
return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
},
$caption
);
When splitting a function call over multiple lines, each parameter must be on a separate line. Single line inline comments can take up their own line.
$bar = array(
'use_this' => true,
'meta_key' => 'field_name',
);
$baz = sprintf(
/* translators: %s: Friend's name */
esc_html__( 'Hello, %s!', 'yourtextdomain' ),
$friend_name
);
$a = foo(
$bar,
$baz,
/* translators: %s: cat */
sprintf( __( 'The best pet is a %s.' ), 'cat' )
);
When embedding multi-line PHP snippets within an HTML block, the PHP open and close tags must be on a line by themselves
function foo() {
?>
<div>
<?php
echo bar(
$baz,
$bat
);
?>
</div>
<?php
}
variable name should in lower case.
function some_name( $some_variable ) { [...] }
Files should be named descriptively using lowercase letters. Hyphens should separate words.
my-plugin-name.php