@mytechtoday/augment-extensions 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/augment-extensions/domain-rules/wordpress/README.md +163 -0
- package/augment-extensions/domain-rules/wordpress/module.json +32 -0
- package/augment-extensions/domain-rules/wordpress/rules/coding-standards.md +617 -0
- package/augment-extensions/domain-rules/wordpress/rules/directory-structure.md +270 -0
- package/augment-extensions/domain-rules/wordpress/rules/file-patterns.md +423 -0
- package/augment-extensions/domain-rules/wordpress/rules/gutenberg-blocks.md +493 -0
- package/augment-extensions/domain-rules/wordpress/rules/performance.md +568 -0
- package/augment-extensions/domain-rules/wordpress/rules/plugin-development.md +510 -0
- package/augment-extensions/domain-rules/wordpress/rules/project-detection.md +251 -0
- package/augment-extensions/domain-rules/wordpress/rules/rest-api.md +501 -0
- package/augment-extensions/domain-rules/wordpress/rules/security.md +564 -0
- package/augment-extensions/domain-rules/wordpress/rules/theme-development.md +388 -0
- package/augment-extensions/domain-rules/wordpress/rules/woocommerce.md +441 -0
- package/augment-extensions/domain-rules/wordpress-plugin/README.md +139 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/ajax-plugin.md +1599 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/custom-post-type-plugin.md +1727 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/gutenberg-block-plugin.md +428 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/gutenberg-block.md +422 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/mvc-plugin.md +1623 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/object-oriented-plugin.md +1343 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/rest-endpoint.md +734 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/settings-page-plugin.md +1350 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/simple-procedural-plugin.md +503 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/singleton-plugin.md +971 -0
- package/augment-extensions/domain-rules/wordpress-plugin/module.json +53 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/activation-hooks.md +770 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/admin-interface.md +874 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/ajax-handlers.md +629 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/asset-management.md +559 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/context-providers.md +709 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/cron-jobs.md +736 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/database-management.md +1057 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/documentation-standards.md +463 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/frontend-functionality.md +478 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/gutenberg-blocks.md +818 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/internationalization.md +416 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/migration.md +667 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/performance-optimization.md +878 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/plugin-architecture.md +693 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/plugin-structure.md +352 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/rest-api.md +818 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/scaffolding-workflow.md +624 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/security-best-practices.md +866 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/testing-patterns.md +1165 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/testing.md +414 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/vscode-integration.md +751 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/woocommerce-integration.md +949 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/wordpress-org-submission.md +458 -0
- package/augment-extensions/examples/gutenberg-block-plugin/README.md +101 -0
- package/augment-extensions/examples/gutenberg-block-plugin/examples/testimonial-block.md +428 -0
- package/augment-extensions/examples/gutenberg-block-plugin/module.json +40 -0
- package/augment-extensions/examples/rest-api-plugin/README.md +98 -0
- package/augment-extensions/examples/rest-api-plugin/examples/task-manager-api.md +1299 -0
- package/augment-extensions/examples/rest-api-plugin/module.json +40 -0
- package/augment-extensions/examples/woocommerce-extension/README.md +98 -0
- package/augment-extensions/examples/woocommerce-extension/examples/product-customizer.md +763 -0
- package/augment-extensions/examples/woocommerce-extension/module.json +40 -0
- package/augment-extensions/workflows/wordpress-plugin/README.md +232 -0
- package/augment-extensions/workflows/wordpress-plugin/ai-prompts.md +839 -0
- package/augment-extensions/workflows/wordpress-plugin/bead-decomposition-patterns.md +854 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/complete-plugin-example.md +540 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/custom-post-type-example.md +1083 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/feature-addition-workflow.md +669 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/plugin-creation-workflow.md +597 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/secure-form-handler-example.md +925 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/security-audit-workflow.md +752 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/wordpress-org-submission-workflow.md +773 -0
- package/augment-extensions/workflows/wordpress-plugin/module.json +49 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/best-practices.md +942 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/development-workflow.md +702 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/submission-workflow.md +728 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/testing-workflow.md +775 -0
- package/cli/dist/cli.js +5 -1
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/show.d.ts.map +1 -1
- package/cli/dist/commands/show.js +41 -0
- package/cli/dist/commands/show.js.map +1 -1
- package/modules.md +52 -0
- package/package.json +1 -1
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
# WordPress Coding Standards (WPCS)
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document defines WordPress coding standards for PHP, JavaScript, CSS, and HTML. Following these standards ensures code consistency, readability, and compatibility.
|
|
6
|
+
|
|
7
|
+
## PHP Coding Standards
|
|
8
|
+
|
|
9
|
+
### File Structure
|
|
10
|
+
|
|
11
|
+
```php
|
|
12
|
+
<?php
|
|
13
|
+
/**
|
|
14
|
+
* File description
|
|
15
|
+
*
|
|
16
|
+
* @package My_Plugin
|
|
17
|
+
* @subpackage My_Plugin/includes
|
|
18
|
+
* @author Your Name <email@example.com>
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Prevent direct access
|
|
22
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
23
|
+
exit;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Code here
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Naming Conventions
|
|
30
|
+
|
|
31
|
+
#### Functions
|
|
32
|
+
|
|
33
|
+
```php
|
|
34
|
+
// ✅ CORRECT: Lowercase with underscores
|
|
35
|
+
function my_plugin_get_data() {
|
|
36
|
+
// Function code
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ❌ WRONG: CamelCase
|
|
40
|
+
function myPluginGetData() {
|
|
41
|
+
// Function code
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### Classes
|
|
46
|
+
|
|
47
|
+
```php
|
|
48
|
+
// ✅ CORRECT: Capitalized words separated by underscores
|
|
49
|
+
class My_Plugin_Admin {
|
|
50
|
+
// Class code
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ❌ WRONG: CamelCase without underscores
|
|
54
|
+
class MyPluginAdmin {
|
|
55
|
+
// Class code
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Variables
|
|
60
|
+
|
|
61
|
+
```php
|
|
62
|
+
// ✅ CORRECT: Lowercase with underscores
|
|
63
|
+
$user_name = 'John';
|
|
64
|
+
$post_count = 10;
|
|
65
|
+
|
|
66
|
+
// ❌ WRONG: CamelCase
|
|
67
|
+
$userName = 'John';
|
|
68
|
+
$postCount = 10;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Constants
|
|
72
|
+
|
|
73
|
+
```php
|
|
74
|
+
// ✅ CORRECT: Uppercase with underscores
|
|
75
|
+
define( 'MY_PLUGIN_VERSION', '1.0.0' );
|
|
76
|
+
const MY_CONSTANT = 'value';
|
|
77
|
+
|
|
78
|
+
// ❌ WRONG: Lowercase or mixed case
|
|
79
|
+
define( 'my_plugin_version', '1.0.0' );
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Indentation and Spacing
|
|
83
|
+
|
|
84
|
+
#### Indentation
|
|
85
|
+
|
|
86
|
+
```php
|
|
87
|
+
// Use tabs for indentation, not spaces
|
|
88
|
+
function my_function() {
|
|
89
|
+
if ( $condition ) {
|
|
90
|
+
// Code here (one tab)
|
|
91
|
+
foreach ( $items as $item ) {
|
|
92
|
+
// Code here (two tabs)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Spacing
|
|
99
|
+
|
|
100
|
+
```php
|
|
101
|
+
// ✅ CORRECT: Space after control structures, before opening brace
|
|
102
|
+
if ( $condition ) {
|
|
103
|
+
// Code
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
foreach ( $items as $item ) {
|
|
107
|
+
// Code
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ✅ CORRECT: Space around operators
|
|
111
|
+
$sum = $a + $b;
|
|
112
|
+
$result = $value * 2;
|
|
113
|
+
|
|
114
|
+
// ✅ CORRECT: Space after commas
|
|
115
|
+
function_name( $arg1, $arg2, $arg3 );
|
|
116
|
+
|
|
117
|
+
// ❌ WRONG: No spaces
|
|
118
|
+
if($condition){
|
|
119
|
+
// Code
|
|
120
|
+
}
|
|
121
|
+
$sum=$a+$b;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Braces
|
|
125
|
+
|
|
126
|
+
```php
|
|
127
|
+
// ✅ CORRECT: Opening brace on same line
|
|
128
|
+
if ( $condition ) {
|
|
129
|
+
// Code
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function my_function() {
|
|
133
|
+
// Code
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ❌ WRONG: Opening brace on new line
|
|
137
|
+
if ( $condition )
|
|
138
|
+
{
|
|
139
|
+
// Code
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Control Structures
|
|
144
|
+
|
|
145
|
+
#### If/Else
|
|
146
|
+
|
|
147
|
+
```php
|
|
148
|
+
// ✅ CORRECT
|
|
149
|
+
if ( $condition ) {
|
|
150
|
+
// Code
|
|
151
|
+
} elseif ( $other_condition ) {
|
|
152
|
+
// Code
|
|
153
|
+
} else {
|
|
154
|
+
// Code
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ✅ CORRECT: Alternative syntax for templates
|
|
158
|
+
<?php if ( $condition ) : ?>
|
|
159
|
+
<p>Content</p>
|
|
160
|
+
<?php else : ?>
|
|
161
|
+
<p>Other content</p>
|
|
162
|
+
<?php endif; ?>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Loops
|
|
166
|
+
|
|
167
|
+
```php
|
|
168
|
+
// ✅ CORRECT: foreach
|
|
169
|
+
foreach ( $items as $item ) {
|
|
170
|
+
echo esc_html( $item );
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ✅ CORRECT: for
|
|
174
|
+
for ( $i = 0; $i < $count; $i++ ) {
|
|
175
|
+
// Code
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ✅ CORRECT: while
|
|
179
|
+
while ( $condition ) {
|
|
180
|
+
// Code
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Switch
|
|
185
|
+
|
|
186
|
+
```php
|
|
187
|
+
// ✅ CORRECT
|
|
188
|
+
switch ( $value ) {
|
|
189
|
+
case 'option1':
|
|
190
|
+
// Code
|
|
191
|
+
break;
|
|
192
|
+
|
|
193
|
+
case 'option2':
|
|
194
|
+
// Code
|
|
195
|
+
break;
|
|
196
|
+
|
|
197
|
+
default:
|
|
198
|
+
// Code
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Arrays
|
|
204
|
+
|
|
205
|
+
```php
|
|
206
|
+
// ✅ CORRECT: Short array syntax (PHP 5.4+)
|
|
207
|
+
$array = array(
|
|
208
|
+
'key1' => 'value1',
|
|
209
|
+
'key2' => 'value2',
|
|
210
|
+
'key3' => 'value3',
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
// ✅ CORRECT: Trailing comma
|
|
214
|
+
$items = array(
|
|
215
|
+
'item1',
|
|
216
|
+
'item2',
|
|
217
|
+
'item3', // Trailing comma
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// ✅ CORRECT: Associative array alignment
|
|
221
|
+
$config = array(
|
|
222
|
+
'name' => 'My Plugin',
|
|
223
|
+
'version' => '1.0.0',
|
|
224
|
+
'description' => 'Plugin description',
|
|
225
|
+
);
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Function Calls
|
|
229
|
+
|
|
230
|
+
```php
|
|
231
|
+
// ✅ CORRECT: Space after function name, before parenthesis
|
|
232
|
+
function_name( $arg1, $arg2 );
|
|
233
|
+
|
|
234
|
+
// ✅ CORRECT: Multi-line function calls
|
|
235
|
+
wp_insert_post(
|
|
236
|
+
array(
|
|
237
|
+
'post_title' => $title,
|
|
238
|
+
'post_content' => $content,
|
|
239
|
+
'post_status' => 'publish',
|
|
240
|
+
'post_type' => 'post',
|
|
241
|
+
)
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
// ❌ WRONG: No space
|
|
245
|
+
function_name($arg1,$arg2);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### String Concatenation
|
|
249
|
+
|
|
250
|
+
```php
|
|
251
|
+
// ✅ CORRECT: Spaces around concatenation operator
|
|
252
|
+
$message = 'Hello ' . $name . '!';
|
|
253
|
+
$url = home_url() . '/page';
|
|
254
|
+
|
|
255
|
+
// ✅ CORRECT: Use sprintf for complex strings
|
|
256
|
+
$message = sprintf( __( 'Hello %s, you have %d messages', 'my-plugin' ), $name, $count );
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Yoda Conditions
|
|
260
|
+
|
|
261
|
+
```php
|
|
262
|
+
// ✅ CORRECT: Yoda conditions (constant/literal first)
|
|
263
|
+
if ( 'value' === $variable ) {
|
|
264
|
+
// Code
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if ( 10 < $count ) {
|
|
268
|
+
// Code
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ❌ WRONG: Variable first
|
|
272
|
+
if ( $variable === 'value' ) {
|
|
273
|
+
// Code
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Comments
|
|
278
|
+
|
|
279
|
+
#### Single-line Comments
|
|
280
|
+
|
|
281
|
+
```php
|
|
282
|
+
// This is a single-line comment
|
|
283
|
+
$value = 10; // Inline comment
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
#### Multi-line Comments
|
|
287
|
+
|
|
288
|
+
```php
|
|
289
|
+
/**
|
|
290
|
+
* This is a multi-line comment
|
|
291
|
+
* that spans multiple lines.
|
|
292
|
+
*/
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### DocBlocks
|
|
296
|
+
|
|
297
|
+
```php
|
|
298
|
+
/**
|
|
299
|
+
* Function description
|
|
300
|
+
*
|
|
301
|
+
* Longer description if needed.
|
|
302
|
+
*
|
|
303
|
+
* @since 1.0.0
|
|
304
|
+
*
|
|
305
|
+
* @param string $param1 Description of param1.
|
|
306
|
+
* @param int $param2 Description of param2.
|
|
307
|
+
* @return bool True on success, false on failure.
|
|
308
|
+
*/
|
|
309
|
+
function my_function( $param1, $param2 ) {
|
|
310
|
+
// Function code
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Class description
|
|
316
|
+
*
|
|
317
|
+
* @since 1.0.0
|
|
318
|
+
*/
|
|
319
|
+
class My_Class {
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Property description
|
|
323
|
+
*
|
|
324
|
+
* @var string
|
|
325
|
+
*/
|
|
326
|
+
private $property;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Method description
|
|
330
|
+
*
|
|
331
|
+
* @since 1.0.0
|
|
332
|
+
*
|
|
333
|
+
* @param string $param Parameter description.
|
|
334
|
+
* @return void
|
|
335
|
+
*/
|
|
336
|
+
public function method( $param ) {
|
|
337
|
+
// Method code
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Database Queries
|
|
343
|
+
|
|
344
|
+
```php
|
|
345
|
+
// ✅ CORRECT: Use $wpdb->prepare()
|
|
346
|
+
global $wpdb;
|
|
347
|
+
|
|
348
|
+
$results = $wpdb->get_results(
|
|
349
|
+
$wpdb->prepare(
|
|
350
|
+
"SELECT * FROM {$wpdb->prefix}my_table WHERE user_id = %d AND status = %s",
|
|
351
|
+
$user_id,
|
|
352
|
+
$status
|
|
353
|
+
)
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
// ✅ CORRECT: Use WordPress functions when possible
|
|
357
|
+
$posts = get_posts(
|
|
358
|
+
array(
|
|
359
|
+
'post_type' => 'post',
|
|
360
|
+
'posts_per_page' => 10,
|
|
361
|
+
)
|
|
362
|
+
);
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Translation
|
|
366
|
+
|
|
367
|
+
```php
|
|
368
|
+
// ✅ CORRECT: Use translation functions
|
|
369
|
+
__( 'Text to translate', 'my-plugin' );
|
|
370
|
+
_e( 'Text to translate', 'my-plugin' );
|
|
371
|
+
esc_html__( 'Text to translate', 'my-plugin' );
|
|
372
|
+
esc_html_e( 'Text to translate', 'my-plugin' );
|
|
373
|
+
|
|
374
|
+
// ✅ CORRECT: Plural forms
|
|
375
|
+
_n( 'One item', '%d items', $count, 'my-plugin' );
|
|
376
|
+
|
|
377
|
+
// ✅ CORRECT: Context
|
|
378
|
+
_x( 'Post', 'noun', 'my-plugin' );
|
|
379
|
+
_x( 'Post', 'verb', 'my-plugin' );
|
|
380
|
+
|
|
381
|
+
// ✅ CORRECT: Variables in translations
|
|
382
|
+
sprintf( __( 'Hello %s', 'my-plugin' ), $name );
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## JavaScript Coding Standards
|
|
386
|
+
|
|
387
|
+
### Naming Conventions
|
|
388
|
+
|
|
389
|
+
```javascript
|
|
390
|
+
// ✅ CORRECT: camelCase for variables and functions
|
|
391
|
+
const userName = 'John';
|
|
392
|
+
function getUserData() {
|
|
393
|
+
// Code
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// ✅ CORRECT: PascalCase for classes
|
|
397
|
+
class MyClass {
|
|
398
|
+
constructor() {
|
|
399
|
+
// Code
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// ✅ CORRECT: UPPERCASE for constants
|
|
404
|
+
const API_URL = 'https://api.example.com';
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Indentation and Spacing
|
|
408
|
+
|
|
409
|
+
```javascript
|
|
410
|
+
// Use tabs for indentation
|
|
411
|
+
if ( condition ) {
|
|
412
|
+
// Code (one tab)
|
|
413
|
+
if ( otherCondition ) {
|
|
414
|
+
// Code (two tabs)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Spaces around operators
|
|
419
|
+
const sum = a + b;
|
|
420
|
+
const result = value * 2;
|
|
421
|
+
|
|
422
|
+
// Space after keywords
|
|
423
|
+
if ( condition ) {
|
|
424
|
+
// Code
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
for ( let i = 0; i < count; i++ ) {
|
|
428
|
+
// Code
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### jQuery
|
|
433
|
+
|
|
434
|
+
```javascript
|
|
435
|
+
// ✅ CORRECT: Use $ within closure
|
|
436
|
+
( function( $ ) {
|
|
437
|
+
'use strict';
|
|
438
|
+
|
|
439
|
+
$( document ).ready( function() {
|
|
440
|
+
$( '.my-element' ).on( 'click', function() {
|
|
441
|
+
// Code
|
|
442
|
+
} );
|
|
443
|
+
} );
|
|
444
|
+
|
|
445
|
+
} )( jQuery );
|
|
446
|
+
|
|
447
|
+
// ✅ CORRECT: Cache jQuery selectors
|
|
448
|
+
const $element = $( '.my-element' );
|
|
449
|
+
$element.addClass( 'active' );
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## CSS Coding Standards
|
|
453
|
+
|
|
454
|
+
### Formatting
|
|
455
|
+
|
|
456
|
+
```css
|
|
457
|
+
/* ✅ CORRECT: Properties on separate lines */
|
|
458
|
+
.my-class {
|
|
459
|
+
display: block;
|
|
460
|
+
margin: 0 auto;
|
|
461
|
+
padding: 10px 20px;
|
|
462
|
+
color: #333;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/* ✅ CORRECT: Space after colon */
|
|
466
|
+
.my-class {
|
|
467
|
+
color: #333;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/* ✅ CORRECT: Lowercase hex colors */
|
|
471
|
+
.my-class {
|
|
472
|
+
color: #fff;
|
|
473
|
+
background-color: #000;
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Naming
|
|
478
|
+
|
|
479
|
+
```css
|
|
480
|
+
/* ✅ CORRECT: Lowercase with hyphens */
|
|
481
|
+
.my-plugin-container {
|
|
482
|
+
/* Styles */
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.my-plugin-button {
|
|
486
|
+
/* Styles */
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/* ❌ WRONG: CamelCase or underscores */
|
|
490
|
+
.myPluginContainer {
|
|
491
|
+
/* Styles */
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
.my_plugin_container {
|
|
495
|
+
/* Styles */
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### Selectors
|
|
500
|
+
|
|
501
|
+
```css
|
|
502
|
+
/* ✅ CORRECT: Specific selectors */
|
|
503
|
+
.my-plugin .button {
|
|
504
|
+
/* Styles */
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/* ✅ CORRECT: Avoid !important */
|
|
508
|
+
.my-class {
|
|
509
|
+
color: #333;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/* ❌ WRONG: Overly specific */
|
|
513
|
+
body div.container ul li a.link {
|
|
514
|
+
/* Styles */
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
## HTML Coding Standards
|
|
519
|
+
|
|
520
|
+
### Formatting
|
|
521
|
+
|
|
522
|
+
```html
|
|
523
|
+
<!-- ✅ CORRECT: Lowercase tags and attributes -->
|
|
524
|
+
<div class="my-class" id="my-id">
|
|
525
|
+
<p>Content</p>
|
|
526
|
+
</div>
|
|
527
|
+
|
|
528
|
+
<!-- ✅ CORRECT: Self-closing tags -->
|
|
529
|
+
<img src="image.jpg" alt="Description" />
|
|
530
|
+
<br />
|
|
531
|
+
|
|
532
|
+
<!-- ✅ CORRECT: Quoted attributes -->
|
|
533
|
+
<input type="text" name="field_name" value="value" />
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### Semantic HTML
|
|
537
|
+
|
|
538
|
+
```html
|
|
539
|
+
<!-- ✅ CORRECT: Use semantic elements -->
|
|
540
|
+
<header>
|
|
541
|
+
<nav>
|
|
542
|
+
<ul>
|
|
543
|
+
<li><a href="#">Link</a></li>
|
|
544
|
+
</ul>
|
|
545
|
+
</nav>
|
|
546
|
+
</header>
|
|
547
|
+
|
|
548
|
+
<main>
|
|
549
|
+
<article>
|
|
550
|
+
<h1>Title</h1>
|
|
551
|
+
<p>Content</p>
|
|
552
|
+
</article>
|
|
553
|
+
</main>
|
|
554
|
+
|
|
555
|
+
<footer>
|
|
556
|
+
<p>© 2024</p>
|
|
557
|
+
</footer>
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
## Tools and Validation
|
|
561
|
+
|
|
562
|
+
### PHP_CodeSniffer
|
|
563
|
+
|
|
564
|
+
```bash
|
|
565
|
+
# Install WordPress Coding Standards
|
|
566
|
+
composer require --dev wp-coding-standards/wpcs
|
|
567
|
+
|
|
568
|
+
# Run PHPCS
|
|
569
|
+
phpcs --standard=WordPress path/to/file.php
|
|
570
|
+
|
|
571
|
+
# Fix automatically
|
|
572
|
+
phpcbf --standard=WordPress path/to/file.php
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
### ESLint
|
|
576
|
+
|
|
577
|
+
```bash
|
|
578
|
+
# Install ESLint with WordPress config
|
|
579
|
+
npm install --save-dev eslint @wordpress/eslint-plugin
|
|
580
|
+
|
|
581
|
+
# Run ESLint
|
|
582
|
+
npx eslint path/to/file.js
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### Stylelint
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
# Install Stylelint with WordPress config
|
|
589
|
+
npm install --save-dev stylelint stylelint-config-wordpress
|
|
590
|
+
|
|
591
|
+
# Run Stylelint
|
|
592
|
+
npx stylelint "**/*.css"
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
## Best Practices
|
|
596
|
+
|
|
597
|
+
### DO
|
|
598
|
+
|
|
599
|
+
✅ Follow WordPress coding standards
|
|
600
|
+
✅ Use consistent naming conventions
|
|
601
|
+
✅ Add proper documentation
|
|
602
|
+
✅ Use translation functions
|
|
603
|
+
✅ Validate and sanitize input
|
|
604
|
+
✅ Escape output
|
|
605
|
+
✅ Use WordPress functions when available
|
|
606
|
+
✅ Write readable, maintainable code
|
|
607
|
+
|
|
608
|
+
### DON'T
|
|
609
|
+
|
|
610
|
+
❌ Mix coding styles
|
|
611
|
+
❌ Use deprecated functions
|
|
612
|
+
❌ Ignore security best practices
|
|
613
|
+
❌ Skip documentation
|
|
614
|
+
❌ Use global namespace
|
|
615
|
+
❌ Hardcode values
|
|
616
|
+
❌ Write overly complex code
|
|
617
|
+
|