@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,503 @@
|
|
|
1
|
+
# Simple Procedural Plugin Example
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This example demonstrates **Pattern 1: Simple Procedural Plugin** - the simplest WordPress plugin architecture for single-feature plugins, utility functions, and quick prototypes.
|
|
6
|
+
|
|
7
|
+
**Complexity**: Low
|
|
8
|
+
**File Count**: 1-3 files
|
|
9
|
+
**Team Size**: 1 developer
|
|
10
|
+
**Use Case**: Single feature, utility functions, quick prototypes
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Complete Plugin Code
|
|
15
|
+
|
|
16
|
+
### Main Plugin File: `disable-comments-simple.php`
|
|
17
|
+
|
|
18
|
+
```php
|
|
19
|
+
<?php
|
|
20
|
+
/**
|
|
21
|
+
* Plugin Name: Disable Comments Simple
|
|
22
|
+
* Plugin URI: https://example.com/disable-comments-simple
|
|
23
|
+
* Description: A simple plugin to disable comments site-wide with one click
|
|
24
|
+
* Version: 1.0.0
|
|
25
|
+
* Author: Your Name
|
|
26
|
+
* Author URI: https://example.com
|
|
27
|
+
* License: GPL-2.0+
|
|
28
|
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
|
29
|
+
* Text Domain: disable-comments-simple
|
|
30
|
+
* Domain Path: /languages
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// Exit if accessed directly
|
|
34
|
+
if (!defined('ABSPATH')) {
|
|
35
|
+
exit;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Define plugin constants
|
|
39
|
+
define('DCS_VERSION', '1.0.0');
|
|
40
|
+
define('DCS_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
|
41
|
+
define('DCS_PLUGIN_URL', plugin_dir_url(__FILE__));
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Disable comments and trackbacks site-wide
|
|
45
|
+
*/
|
|
46
|
+
function dcs_disable_comments_post_types_support() {
|
|
47
|
+
$post_types = get_post_types();
|
|
48
|
+
foreach ($post_types as $post_type) {
|
|
49
|
+
if (post_type_supports($post_type, 'comments')) {
|
|
50
|
+
remove_post_type_support($post_type, 'comments');
|
|
51
|
+
remove_post_type_support($post_type, 'trackbacks');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
add_action('init', 'dcs_disable_comments_post_types_support');
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Close comments on the front-end
|
|
59
|
+
*/
|
|
60
|
+
function dcs_disable_comments_status() {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
add_filter('comments_open', 'dcs_disable_comments_status', 20, 2);
|
|
64
|
+
add_filter('pings_open', 'dcs_disable_comments_status', 20, 2);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Hide existing comments
|
|
68
|
+
*/
|
|
69
|
+
function dcs_disable_comments_hide_existing_comments($comments) {
|
|
70
|
+
return array();
|
|
71
|
+
}
|
|
72
|
+
add_filter('comments_array', 'dcs_disable_comments_hide_existing_comments', 10, 2);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Remove comments page in menu
|
|
76
|
+
*/
|
|
77
|
+
function dcs_disable_comments_admin_menu() {
|
|
78
|
+
remove_menu_page('edit-comments.php');
|
|
79
|
+
}
|
|
80
|
+
add_action('admin_menu', 'dcs_disable_comments_admin_menu');
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Redirect any user trying to access comments page
|
|
84
|
+
*/
|
|
85
|
+
function dcs_disable_comments_admin_menu_redirect() {
|
|
86
|
+
global $pagenow;
|
|
87
|
+
if ($pagenow === 'edit-comments.php') {
|
|
88
|
+
wp_safe_redirect(admin_url());
|
|
89
|
+
exit;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
add_action('admin_init', 'dcs_disable_comments_admin_menu_redirect');
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Remove comments metabox from dashboard
|
|
96
|
+
*/
|
|
97
|
+
function dcs_disable_comments_dashboard() {
|
|
98
|
+
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
|
|
99
|
+
}
|
|
100
|
+
add_action('admin_init', 'dcs_disable_comments_dashboard');
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Remove comments links from admin bar
|
|
104
|
+
*/
|
|
105
|
+
function dcs_disable_comments_admin_bar() {
|
|
106
|
+
if (is_admin_bar_showing()) {
|
|
107
|
+
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
add_action('init', 'dcs_disable_comments_admin_bar');
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Remove comment-reply script for themes that include it
|
|
114
|
+
*/
|
|
115
|
+
function dcs_disable_comments_remove_comment_reply() {
|
|
116
|
+
wp_deregister_script('comment-reply');
|
|
117
|
+
}
|
|
118
|
+
add_action('wp_enqueue_scripts', 'dcs_disable_comments_remove_comment_reply');
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Add settings link on plugin page
|
|
122
|
+
*/
|
|
123
|
+
function dcs_add_settings_link($links) {
|
|
124
|
+
$settings_link = '<a href="' . admin_url('options-general.php') . '">' . __('Settings', 'disable-comments-simple') . '</a>';
|
|
125
|
+
array_unshift($links, $settings_link);
|
|
126
|
+
return $links;
|
|
127
|
+
}
|
|
128
|
+
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'dcs_add_settings_link');
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Display admin notice on activation
|
|
132
|
+
*/
|
|
133
|
+
function dcs_activation_notice() {
|
|
134
|
+
if (get_transient('dcs_activation_notice')) {
|
|
135
|
+
?>
|
|
136
|
+
<div class="notice notice-success is-dismissible">
|
|
137
|
+
<p><?php _e('Comments have been disabled site-wide!', 'disable-comments-simple'); ?></p>
|
|
138
|
+
</div>
|
|
139
|
+
<?php
|
|
140
|
+
delete_transient('dcs_activation_notice');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
add_action('admin_notices', 'dcs_activation_notice');
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Activation hook
|
|
147
|
+
*/
|
|
148
|
+
function dcs_activate() {
|
|
149
|
+
set_transient('dcs_activation_notice', true, 5);
|
|
150
|
+
}
|
|
151
|
+
register_activation_hook(__FILE__, 'dcs_activate');
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Deactivation hook
|
|
155
|
+
*/
|
|
156
|
+
function dcs_deactivate() {
|
|
157
|
+
// Clean up if needed
|
|
158
|
+
}
|
|
159
|
+
register_deactivation_hook(__FILE__, 'dcs_deactivate');
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## WordPress.org readme.txt
|
|
165
|
+
|
|
166
|
+
### File: `readme.txt`
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
=== Disable Comments Simple ===
|
|
170
|
+
Contributors: yourusername
|
|
171
|
+
Tags: comments, disable comments, remove comments, spam
|
|
172
|
+
Requires at least: 5.0
|
|
173
|
+
Tested up to: 6.4
|
|
174
|
+
Requires PHP: 7.4
|
|
175
|
+
Stable tag: 1.0.0
|
|
176
|
+
License: GPLv2 or later
|
|
177
|
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
|
178
|
+
|
|
179
|
+
Disable comments site-wide with one click. No configuration needed.
|
|
180
|
+
|
|
181
|
+
== Description ==
|
|
182
|
+
|
|
183
|
+
Disable Comments Simple is a lightweight plugin that completely disables comments on your WordPress site. Perfect for sites that don't need commenting functionality.
|
|
184
|
+
|
|
185
|
+
**Features:**
|
|
186
|
+
|
|
187
|
+
* Disables comments on all post types
|
|
188
|
+
* Hides existing comments from display
|
|
189
|
+
* Removes comments from admin menu
|
|
190
|
+
* Removes comments from admin bar
|
|
191
|
+
* Removes comment metabox from dashboard
|
|
192
|
+
* No configuration required - just activate!
|
|
193
|
+
|
|
194
|
+
**Why Use This Plugin?**
|
|
195
|
+
|
|
196
|
+
* Reduce spam and moderation overhead
|
|
197
|
+
* Improve site performance by removing comment queries
|
|
198
|
+
* Clean up admin interface
|
|
199
|
+
* Simple and lightweight (single file)
|
|
200
|
+
|
|
201
|
+
== Installation ==
|
|
202
|
+
|
|
203
|
+
1. Upload the plugin files to `/wp-content/plugins/disable-comments-simple`
|
|
204
|
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
|
205
|
+
3. That's it! Comments are now disabled site-wide
|
|
206
|
+
|
|
207
|
+
== Frequently Asked Questions ==
|
|
208
|
+
|
|
209
|
+
= Will this delete my existing comments? =
|
|
210
|
+
|
|
211
|
+
No, it only hides them from display. If you deactivate the plugin, comments will reappear.
|
|
212
|
+
|
|
213
|
+
= Can I enable comments on specific posts? =
|
|
214
|
+
|
|
215
|
+
Not with this simple version. This plugin disables comments site-wide.
|
|
216
|
+
|
|
217
|
+
= Does this work with custom post types? =
|
|
218
|
+
|
|
219
|
+
Yes, it disables comments on all post types including custom post types.
|
|
220
|
+
|
|
221
|
+
== Changelog ==
|
|
222
|
+
|
|
223
|
+
= 1.0.0 =
|
|
224
|
+
* Initial release
|
|
225
|
+
* Disable comments site-wide
|
|
226
|
+
* Remove comments from admin interface
|
|
227
|
+
|
|
228
|
+
== Upgrade Notice ==
|
|
229
|
+
|
|
230
|
+
= 1.0.0 =
|
|
231
|
+
Initial release.
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Uninstall Script (Optional)
|
|
237
|
+
|
|
238
|
+
### File: `uninstall.php`
|
|
239
|
+
|
|
240
|
+
```php
|
|
241
|
+
<?php
|
|
242
|
+
/**
|
|
243
|
+
* Uninstall script for Disable Comments Simple
|
|
244
|
+
*
|
|
245
|
+
* @package Disable_Comments_Simple
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
// Exit if accessed directly or not uninstalling
|
|
249
|
+
if (!defined('WP_UNINSTALL_PLUGIN')) {
|
|
250
|
+
exit;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Clean up options (if any were stored)
|
|
254
|
+
delete_option('dcs_settings');
|
|
255
|
+
|
|
256
|
+
// Clean up transients
|
|
257
|
+
delete_transient('dcs_activation_notice');
|
|
258
|
+
|
|
259
|
+
// Optional: Clean up comment metadata
|
|
260
|
+
// global $wpdb;
|
|
261
|
+
// $wpdb->query("DELETE FROM {$wpdb->commentmeta} WHERE meta_key LIKE 'dcs_%'");
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Directory Structure
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
disable-comments-simple/
|
|
270
|
+
├── disable-comments-simple.php # Main plugin file (all code)
|
|
271
|
+
├── readme.txt # WordPress.org readme
|
|
272
|
+
└── uninstall.php # Optional uninstall cleanup
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Key Features Demonstrated
|
|
278
|
+
|
|
279
|
+
### 1. **Security Best Practices**
|
|
280
|
+
|
|
281
|
+
✅ **ABSPATH check**: Prevents direct file access
|
|
282
|
+
```php
|
|
283
|
+
if (!defined('ABSPATH')) {
|
|
284
|
+
exit;
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
✅ **Proper escaping**: Uses WordPress translation functions
|
|
289
|
+
```php
|
|
290
|
+
__('Settings', 'disable-comments-simple')
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
✅ **Safe redirects**: Uses `wp_safe_redirect()`
|
|
294
|
+
```php
|
|
295
|
+
wp_safe_redirect(admin_url());
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### 2. **WordPress Hooks**
|
|
299
|
+
|
|
300
|
+
✅ **Actions**: `init`, `admin_menu`, `admin_init`, `admin_notices`, `wp_enqueue_scripts`
|
|
301
|
+
✅ **Filters**: `comments_open`, `pings_open`, `comments_array`, `plugin_action_links_*`
|
|
302
|
+
✅ **Activation/Deactivation**: `register_activation_hook()`, `register_deactivation_hook()`
|
|
303
|
+
|
|
304
|
+
### 3. **WordPress APIs**
|
|
305
|
+
|
|
306
|
+
✅ **Post Types API**: `get_post_types()`, `post_type_supports()`, `remove_post_type_support()`
|
|
307
|
+
✅ **Admin API**: `remove_menu_page()`, `remove_meta_box()`, `admin_url()`
|
|
308
|
+
✅ **Transients API**: `set_transient()`, `get_transient()`, `delete_transient()`
|
|
309
|
+
✅ **Plugin API**: `plugin_basename()`, `plugin_dir_path()`, `plugin_dir_url()`
|
|
310
|
+
|
|
311
|
+
### 4. **Internationalization (i18n)**
|
|
312
|
+
|
|
313
|
+
✅ **Text Domain**: Defined in plugin header
|
|
314
|
+
✅ **Translation Functions**: `__()` for translatable strings
|
|
315
|
+
✅ **Domain Path**: `/languages` directory specified
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## When to Use This Pattern
|
|
320
|
+
|
|
321
|
+
### ✅ Good Use Cases
|
|
322
|
+
|
|
323
|
+
- **Single feature plugins**: Disable comments, add custom CSS, redirect users
|
|
324
|
+
- **Utility functions**: Custom shortcodes, simple widgets
|
|
325
|
+
- **Quick prototypes**: Testing ideas before building complex plugins
|
|
326
|
+
- **Learning**: Understanding WordPress plugin basics
|
|
327
|
+
- **Micro-plugins**: Very specific, focused functionality
|
|
328
|
+
|
|
329
|
+
### ❌ Not Suitable For
|
|
330
|
+
|
|
331
|
+
- **Multiple features**: Use Organized Procedural (Pattern 2)
|
|
332
|
+
- **Complex logic**: Use Object-Oriented (Pattern 3)
|
|
333
|
+
- **Team collaboration**: Use WPPB (Pattern 4)
|
|
334
|
+
- **Extensibility needed**: Use Namespace-Based (Pattern 5)
|
|
335
|
+
- **Enterprise plugins**: Use Service Container (Pattern 6)
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Advantages
|
|
340
|
+
|
|
341
|
+
✅ **Simple**: All code in one file, easy to understand
|
|
342
|
+
✅ **Fast**: No autoloading, minimal overhead
|
|
343
|
+
✅ **Portable**: Single file, easy to share
|
|
344
|
+
✅ **Beginner-friendly**: Great for learning WordPress plugin development
|
|
345
|
+
✅ **Quick to develop**: No boilerplate, straight to functionality
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## Limitations
|
|
350
|
+
|
|
351
|
+
❌ **Not scalable**: Hard to maintain as features grow
|
|
352
|
+
❌ **No separation of concerns**: All code mixed together
|
|
353
|
+
❌ **Hard to test**: No class structure for unit testing
|
|
354
|
+
❌ **No namespacing**: Risk of function name conflicts
|
|
355
|
+
❌ **Limited reusability**: Functions not easily reusable
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Best Practices for Simple Procedural Plugins
|
|
360
|
+
|
|
361
|
+
### 1. **Use Unique Function Prefixes**
|
|
362
|
+
|
|
363
|
+
Always prefix functions to avoid conflicts:
|
|
364
|
+
```php
|
|
365
|
+
// Good
|
|
366
|
+
function dcs_disable_comments() { }
|
|
367
|
+
|
|
368
|
+
// Bad
|
|
369
|
+
function disable_comments() { } // Too generic
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### 2. **Define Constants**
|
|
373
|
+
|
|
374
|
+
Use constants for version, paths, and URLs:
|
|
375
|
+
```php
|
|
376
|
+
define('DCS_VERSION', '1.0.0');
|
|
377
|
+
define('DCS_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
|
378
|
+
define('DCS_PLUGIN_URL', plugin_dir_url(__FILE__));
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### 3. **Check ABSPATH**
|
|
382
|
+
|
|
383
|
+
Always prevent direct access:
|
|
384
|
+
```php
|
|
385
|
+
if (!defined('ABSPATH')) {
|
|
386
|
+
exit;
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### 4. **Use WordPress APIs**
|
|
391
|
+
|
|
392
|
+
Don't reinvent the wheel:
|
|
393
|
+
```php
|
|
394
|
+
// Good
|
|
395
|
+
wp_safe_redirect(admin_url());
|
|
396
|
+
|
|
397
|
+
// Bad
|
|
398
|
+
header('Location: /wp-admin/'); // Don't do this
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### 5. **Sanitize and Escape**
|
|
402
|
+
|
|
403
|
+
Even simple plugins need security:
|
|
404
|
+
```php
|
|
405
|
+
// Sanitize input
|
|
406
|
+
$value = sanitize_text_field($_POST['value']);
|
|
407
|
+
|
|
408
|
+
// Escape output
|
|
409
|
+
echo esc_html($value);
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### 6. **Use Activation/Deactivation Hooks**
|
|
413
|
+
|
|
414
|
+
Clean up after yourself:
|
|
415
|
+
```php
|
|
416
|
+
register_activation_hook(__FILE__, 'dcs_activate');
|
|
417
|
+
register_deactivation_hook(__FILE__, 'dcs_deactivate');
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### 7. **Internationalization**
|
|
421
|
+
|
|
422
|
+
Make your plugin translatable:
|
|
423
|
+
```php
|
|
424
|
+
__('Text to translate', 'text-domain');
|
|
425
|
+
_e('Text to echo', 'text-domain');
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
## Testing the Plugin
|
|
431
|
+
|
|
432
|
+
### Manual Testing
|
|
433
|
+
|
|
434
|
+
1. **Install**: Copy to `wp-content/plugins/disable-comments-simple/`
|
|
435
|
+
2. **Activate**: Go to Plugins > Activate "Disable Comments Simple"
|
|
436
|
+
3. **Verify**: Check that comments are disabled on posts
|
|
437
|
+
4. **Admin**: Verify comments menu is removed
|
|
438
|
+
5. **Deactivate**: Verify comments reappear
|
|
439
|
+
|
|
440
|
+
### Checklist
|
|
441
|
+
|
|
442
|
+
- [ ] Plugin activates without errors
|
|
443
|
+
- [ ] Comments are disabled on all post types
|
|
444
|
+
- [ ] Existing comments are hidden
|
|
445
|
+
- [ ] Comments menu is removed from admin
|
|
446
|
+
- [ ] Admin bar comments link is removed
|
|
447
|
+
- [ ] Activation notice appears
|
|
448
|
+
- [ ] Settings link appears on plugins page
|
|
449
|
+
- [ ] Plugin deactivates cleanly
|
|
450
|
+
- [ ] Comments reappear after deactivation
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## Extending This Plugin
|
|
455
|
+
|
|
456
|
+
If you need to add features, consider upgrading to **Pattern 2: Organized Procedural**:
|
|
457
|
+
|
|
458
|
+
```
|
|
459
|
+
disable-comments-simple/
|
|
460
|
+
├── disable-comments-simple.php # Main file (loader)
|
|
461
|
+
├── includes/
|
|
462
|
+
│ ├── functions.php # Core functions
|
|
463
|
+
│ ├── hooks.php # Hook callbacks
|
|
464
|
+
│ └── admin.php # Admin functions
|
|
465
|
+
├── readme.txt
|
|
466
|
+
└── uninstall.php
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## Related Patterns
|
|
472
|
+
|
|
473
|
+
- **Pattern 2**: [Organized Procedural Plugin](organized-procedural-plugin.md) - For medium complexity
|
|
474
|
+
- **Pattern 3**: [Object-Oriented Plugin](object-oriented-plugin.md) - For complex plugins
|
|
475
|
+
- **Pattern 4**: [WPPB Plugin](wppb-plugin.md) - For professional plugins
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## Additional Resources
|
|
480
|
+
|
|
481
|
+
- [WordPress Plugin Handbook](https://developer.wordpress.org/plugins/)
|
|
482
|
+
- [WordPress Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/)
|
|
483
|
+
- [Plugin Security Best Practices](https://developer.wordpress.org/plugins/security/)
|
|
484
|
+
- [Internationalization](https://developer.wordpress.org/plugins/internationalization/)
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
## Summary
|
|
489
|
+
|
|
490
|
+
This simple procedural plugin demonstrates:
|
|
491
|
+
|
|
492
|
+
✅ Complete working plugin in a single file
|
|
493
|
+
✅ WordPress security best practices
|
|
494
|
+
✅ Proper use of hooks and filters
|
|
495
|
+
✅ WordPress APIs (Post Types, Admin, Transients, Plugin)
|
|
496
|
+
✅ Internationalization support
|
|
497
|
+
✅ Activation/deactivation hooks
|
|
498
|
+
✅ Clean, readable code structure
|
|
499
|
+
|
|
500
|
+
**Perfect for**: Single-feature plugins, utilities, prototypes, and learning WordPress plugin development.
|
|
501
|
+
|
|
502
|
+
**Next steps**: When your plugin grows beyond 200-300 lines, consider upgrading to Pattern 2 (Organized Procedural) for better code organization.
|
|
503
|
+
|