Skip to content

Commit 58afeff

Browse files
committed
Change HTML heading tags to markdown tags
1 parent 561256a commit 58afeff

File tree

1 file changed

+26
-26
lines changed
  • wordpress-coding-standards

1 file changed

+26
-26
lines changed

wordpress-coding-standards/php.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Keep the following points in mind when writing PHP code for WordPress, whether f
66

77
See also: <a href="https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/">PHP Documentation Standards</a>.
88

9-
<h2>PHP</h2>
9+
## PHP
1010

11-
<h3>Single and Double Quotes</h3>
11+
### Single and Double Quotes
1212

1313
Use single and double quotes when appropriate. If you're not evaluating anything in the string, use single quotes. You should almost never have to escape quotes in a string, because you can just alternate your quoting style, like so:
1414

@@ -19,7 +19,7 @@ echo "<a href='$link' title='$linktitle'>$linkname</a>";
1919

2020
Text that goes into attributes should be run through <code>esc_attr()</code> so that single or double quotes do not end the attribute value and invalidate the HTML and cause a security issue. See <a href="http://codex.wordpress.org/Data_Validation">Data Validation</a> in the Codex for further details.
2121

22-
<h3>Indentation</h3>
22+
### Indentation
2323

2424
Your indentation should always reflect logical structure. Use <strong>real tabs</strong> and <strong>not spaces</strong>, as this allows the most flexibility across clients.
2525

@@ -74,7 +74,7 @@ switch ( $type ) {
7474

7575
<strong>Rule of thumb:</strong> Tabs should be used at the beginning of the line for indentation, while spaces can be used mid-line for alignment.
7676

77-
<h3>Brace Style</h3>
77+
### Brace Style
7878

7979
Braces shall be used for all blocks in the style shown here:
8080

@@ -125,17 +125,17 @@ Note that requiring the use of braces just means that <em>single-statement inlin
125125
<?php endif; ?>
126126
```
127127

128-
<h3>Use <code>elseif</code>, not <code>else if</code></h3>
128+
### Use <code>elseif</code>, not <code>else if</code>
129129

130130
<code>else if</code> is not compatible with the colon syntax for <code>if|elseif</code> blocks. For this reason, use <code>elseif</code> for conditionals.
131131

132-
<h3>Declaring Arrays</h3>
132+
### Declaring Arrays
133133

134134
Using long array syntax ( <code>array( 1, 2, 3 )</code> ) for declaring arrays is generally more readable than short array syntax ( <code>[ 1, 2, 3 ]</code> ), particularly for those with vision difficulties. Additionally, it's much more descriptive for beginners.
135135

136136
Arrays must be declared using long array syntax.
137137

138-
<h3>Closures (Anonymous Functions)</h3>
138+
### Closures (Anonymous Functions)
139139

140140
Where appropriate, closures may be used as an alternative to creating new functions to pass as callbacks. For example:
141141

@@ -151,7 +151,7 @@ $caption = preg_replace_callback(
151151

152152
Closures must not be passed as filter or action callbacks, as they cannot be removed by <code>remove_action()</code> / <code>remove_filter()</code> (see <a href="https://core.trac.wordpress.org/ticket/46635">#46635</a> for a proposal to address this).
153153

154-
<h3>Multiline Function Calls</h3>
154+
### Multiline Function Calls
155155

156156
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.
157157

@@ -176,13 +176,13 @@ $a = foo(
176176
);
177177
```
178178

179-
<h3>Regular Expressions</h3>
179+
### Regular Expressions
180180

181181
Perl compatible regular expressions (<a href="http://php.net/pcre">PCRE</a>, <code>preg_</code> functions) should be used in preference to their POSIX counterparts. Never use the <code>/e</code> switch, use <code>preg_replace_callback</code> instead.
182182

183183
It's most convenient to use single-quoted strings for regular expressions since, contrary to double-quoted strings, they have only two metasequences: <code>\'</code> and <code>\\</code>.
184184

185-
<h3>Opening and Closing PHP Tags</h3>
185+
### Opening and Closing PHP Tags
186186

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

@@ -217,7 +217,7 @@ if ( $a === $b ) { ?>
217217
<?php }
218218
```
219219

220-
<h3>No Shorthand PHP Tags</h3>
220+
### No Shorthand PHP Tags
221221

222222
<strong>Important:</strong> Never use shorthand PHP start tags. Always use full PHP tags.
223223

@@ -235,11 +235,11 @@ Incorrect:
235235
<?= $var ?>
236236
```
237237

238-
<h3>Remove Trailing Spaces</h3>
238+
### Remove Trailing Spaces
239239

240240
Remove trailing whitespace at the end of each line of code. Omitting the closing PHP tag at the end of a file is preferred. If you use the tag, make sure you remove trailing whitespace.
241241

242-
<h3>Space Usage</h3>
242+
### Space Usage
243243

244244
Always put spaces after commas, and on both sides of logical, comparison, string and assignment operators.
245245

@@ -325,7 +325,7 @@ if ( $foo && ( $bar || $baz ) ) { ...
325325
my_function( ( $x - 1 ) * 5, $y );
326326
```
327327

328-
<h3>Formatting SQL statements</h3>
328+
### Formatting SQL statements
329329

330330
When formatting SQL statements you may break it into several lines and indent if it is sufficiently complex to warrant it. Most statements work well as one line though. Always capitalize the SQL parts of the statement like <code>UPDATE</code> or <code>WHERE</code>.
331331

@@ -344,13 +344,13 @@ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_title = %s WHERE ID
344344

345345
See <a title="Data Validation" href="http://codex.wordpress.org/Data_Validation" target="_blank">Data Validation</a> in the Codex for more information.
346346

347-
<h3>Database Queries</h3>
347+
### Database Queries
348348

349349
Avoid touching the database directly. If there is a defined function that can get the data you need, use it. Database abstraction (using functions instead of queries) helps keep your code forward-compatible and, in cases where results are cached in memory, it can be many times faster.
350350

351351
If you must touch the database, get in touch with some developers by posting a message to the <a title="wp-hackers mailing list" href="http://codex.wordpress.org/Mailing_Lists#Hackers" target="_blank">wp-hackers mailing list</a>. They may want to consider creating a function for the next WordPress version to cover the functionality you wanted.
352352

353-
<h3>Naming Conventions</h3>
353+
### Naming Conventions
354354

355355
Use lowercase letters in variable, action/filter, and function names (never <code>camelCase</code>). Separate words via underscores. Don't abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.
356356

@@ -391,7 +391,7 @@ Files containing template tags in <code>wp-includes</code> should have <code>-te
391391
general-template.php
392392
```
393393

394-
<h3>Only one object structure (class/interface/trait) should be declared per file</h3>
394+
### Only one object structure (class/interface/trait) should be declared per file
395395

396396
For instance, if we have a file called `class-example-class.php` it can only contain one class in that file.
397397

@@ -414,7 +414,7 @@ class Example_Class { [...] }
414414
class Example_Class_Extended { [...] }
415415
```
416416

417-
<h3>Self-Explanatory Flag Values for Function Arguments</h3>
417+
### Self-Explanatory Flag Values for Function Arguments
418418

419419
Prefer string values to just <code>true</code> and <code>false</code> when calling functions.
420420

@@ -450,7 +450,7 @@ function eat( $what, $args ) {
450450
eat ( 'noodles', array( 'speed' => 'moderate' ) );
451451
```
452452

453-
<h3>Interpolation for Naming Dynamic Hooks</h3>
453+
### Interpolation for Naming Dynamic Hooks
454454

455455
Dynamic hooks should be named using interpolation rather than concatenation for readability and discoverability purposes.
456456

@@ -464,7 +464,7 @@ do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
464464

465465
Where possible, dynamic values in tag names should also be as succinct and to the point as possible. <code>$user_id</code> is much more self-documenting than, say, <code>$this-&gt;id</code>.
466466

467-
<h3>Ternary Operator</h3>
467+
### Ternary Operator
468468

469469
<a title="Ternary" href="http://en.wikipedia.org/wiki/Ternary_operation" target="_blank">Ternary</a> operators are fine, but always have them test if the statement is true, not false. Otherwise, it just gets confusing. (An exception would be using <code>! empty()</code>, as testing for false here is generally more intuitive.)
470470

@@ -478,7 +478,7 @@ $musictype = ( 'jazz' === $music ) ? 'cool' : 'blah';
478478
// (if field is not empty ) ? (do this) : (else, do this);
479479
```
480480

481-
<h3>Yoda Conditions</h3>
481+
### Yoda Conditions
482482

483483
```php
484484
if ( true === $the_force ) {
@@ -494,7 +494,7 @@ A little bizarre, it is, to read. Get used to it, you will.
494494

495495
This applies to ==, !=, ===, and !==. Yoda conditions for &lt;, &gt;, &lt;= or &gt;= are significantly more difficult to read and are best avoided.
496496

497-
<h3>Clever Code</h3>
497+
### Clever Code
498498

499499
In general, readability is more important than cleverness or brevity.
500500

@@ -570,27 +570,27 @@ The <code>goto</code> statement must never be used.
570570

571571
The <code>eval()</code> construct is <em>very dangerous</em>, and is impossible to secure. Additionally, the <code>create_function()</code> function, which internally performs an <code>eval()</code>, is deprecated in PHP 7.2. Both of these must not be used.
572572

573-
<h3>Error Control Operator <code>@</code></h3>
573+
### Error Control Operator <code>@</code>
574574

575575
As noted in the <a href="http://www.php.net//manual/en/language.operators.errorcontrol.php">PHP docs</a>:
576576
<blockquote>PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.</blockquote>
577577
While this operator does exist in Core, it is often used lazily instead of doing proper error checking. Its use is highly discouraged, as even the PHP docs also state:
578578
<blockquote>Warning: Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.</blockquote>
579579

580-
<h3>Don't <code>extract()</code></h3>
580+
### Don't <code>extract()</code>
581581

582582
Per <a title="Remove all, or at least most, uses of extract() within WordPress" href="https://core.trac.wordpress.org/ticket/22400">#22400</a>:
583583
<blockquote><code>extract()</code> is a terrible function that makes code harder to debug and harder to understand. We should discourage it's [sic] use and remove all of our uses of it.
584584

585585
Joseph Scott has <a class="ext-link" href="https://blog.josephscott.org/2009/02/05/i-dont-like-phps-extract-function/">a good write-up of why it's bad</a>.</blockquote>
586586

587-
<h2>Credits</h2>
587+
## Credits
588588

589589
<ul>
590590
<li>PHP standards: <a href="http://pear.php.net/manual/en/standards.php" target="_blank">Pear standards</a></li>
591591
</ul>
592592

593-
<h3>Major Changes</h3>
593+
### Major Changes
594594

595595
<ul>
596596
<li>November 13, 2013: <a href="http://make.wordpress.org/core/2013/11/13/proposed-coding-standards-change-always-require-braces/">Braces should always be used, even when they are optional</a></li>

0 commit comments

Comments
 (0)