Coding Standards - Mashikul-islam-Pranto/Blood-Bank-Management-System GitHub Wiki

Coding Standards: (PHP)

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.

PHP

Single and Double Quotes:

Single and double quotes are using when it is appropriate. Evaluating anything in the string, using single quotes.

Example:

 echo '<a href="/static/link" title="Yeah yeah!">Link name</a>';
 echo "<a href='$link' title='$linktitle'>$linkname</a>";

Indentation

Indentation should always reflect the logical structure.

Example

 [tab]$foo   = 'somevalue';
 [tab]$foo2  = 'somevalue2';
 [tab]$foo34 = 'somevalue3';
 [tab]$foo5  = 'somevalue4';

Brace Style

Braces shall be used for all blocks.

Example

 if ( condition ) {
   action1();
   action2();
} elseif ( condition2 && condition3 ) {
   action3();
   action4();
 } else {
   defaultaction();
 }
 if ( condition ) {
    action1();
    action2();
 } elseif ( condition2 && condition3 ) {
    action3();
    action4();
 } else {
    defaultaction();
 }

Closures (Anonymous Functions)

Where appropriate, closures may be used as an alternative to creating new functions to pass as callbacks.

Example

 $caption = preg_replace_callback(
    '/<[a-zA-Z0-9]+(?: [^<>]+>)*/',
     function ( $matches ) {
        return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
    },
    $caption
 );

Multiline Function Calls

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.

Example

 $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' )
 );

Opening and Closing PHP Tags

When embedding multi-line PHP snippets within an HTML block, the PHP open and close tags must be on a line by themselves

Example

 function foo() {
    ?>
        <div>
        <?php
        echo bar(
            $baz,
            $bat
        );
        ?>
        </div>
    <?php
 }

Naming Conventions

variable name should in lower case.

Example

 function some_name( $some_variable ) { [...] }

Files should be named descriptively using lowercase letters. Hyphens should separate words.

Example

 my-plugin-name.php
⚠️ **GitHub.com Fallback** ⚠️