@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,597 @@
|
|
|
1
|
+
# Plugin Creation Workflow Example
|
|
2
|
+
|
|
3
|
+
This example demonstrates the complete workflow for creating a new WordPress plugin from scratch using OpenSpec and Beads.
|
|
4
|
+
|
|
5
|
+
## Scenario
|
|
6
|
+
|
|
7
|
+
Creating a "Reading Time Estimator" plugin that displays estimated reading time for posts and pages.
|
|
8
|
+
|
|
9
|
+
## Plugin Concept
|
|
10
|
+
|
|
11
|
+
- **Plugin Name**: Reading Time Estimator
|
|
12
|
+
- **Plugin Slug**: reading-time-estimator
|
|
13
|
+
- **Text Domain**: reading-time-estimator
|
|
14
|
+
- **Purpose**: Calculate and display estimated reading time for WordPress posts/pages
|
|
15
|
+
- **Features**:
|
|
16
|
+
- Automatic reading time calculation (words per minute configurable)
|
|
17
|
+
- Display reading time before/after content
|
|
18
|
+
- Shortcode support: `[reading_time]`
|
|
19
|
+
- Settings page for customization
|
|
20
|
+
- Support for custom post types
|
|
21
|
+
|
|
22
|
+
## Workflow Steps
|
|
23
|
+
|
|
24
|
+
### Step 1: Create OpenSpec Proposal
|
|
25
|
+
|
|
26
|
+
**File**: `openspec/changes/reading-time-plugin/proposal.md`
|
|
27
|
+
|
|
28
|
+
```markdown
|
|
29
|
+
---
|
|
30
|
+
id: reading-time-plugin
|
|
31
|
+
relatedTasks: []
|
|
32
|
+
relatedRules: [module-development.md]
|
|
33
|
+
status: draft
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
# Reading Time Estimator Plugin
|
|
37
|
+
|
|
38
|
+
## Motivation
|
|
39
|
+
|
|
40
|
+
Many content-heavy websites want to display estimated reading time to help users
|
|
41
|
+
gauge time commitment before reading. This is a common feature on Medium, blogs,
|
|
42
|
+
and documentation sites.
|
|
43
|
+
|
|
44
|
+
## Changes
|
|
45
|
+
|
|
46
|
+
1. Create new WordPress plugin from scratch
|
|
47
|
+
2. Add reading time calculation algorithm
|
|
48
|
+
3. Add settings page for customization
|
|
49
|
+
4. Add display options (before/after content, shortcode)
|
|
50
|
+
5. Add support for custom post types
|
|
51
|
+
|
|
52
|
+
## Impact
|
|
53
|
+
|
|
54
|
+
### New Plugin Structure
|
|
55
|
+
- Main plugin file with header
|
|
56
|
+
- Core calculation class
|
|
57
|
+
- Settings page class
|
|
58
|
+
- Display handler class
|
|
59
|
+
- Admin CSS/JS
|
|
60
|
+
- Frontend CSS
|
|
61
|
+
|
|
62
|
+
### WordPress Integration
|
|
63
|
+
- Settings page under Settings > Reading Time
|
|
64
|
+
- Automatic display via content filter
|
|
65
|
+
- Shortcode: `[reading_time]`
|
|
66
|
+
- Widget support (optional)
|
|
67
|
+
|
|
68
|
+
## Timeline
|
|
69
|
+
|
|
70
|
+
- Plugin scaffolding: 1 day
|
|
71
|
+
- Core implementation: 1-2 days
|
|
72
|
+
- Settings page: 1 day
|
|
73
|
+
- Testing and polish: 1 day
|
|
74
|
+
|
|
75
|
+
## Dependencies
|
|
76
|
+
|
|
77
|
+
- None (standalone plugin)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Step 2: Create OpenSpec Spec
|
|
81
|
+
|
|
82
|
+
**File**: `openspec/changes/reading-time-plugin/specs/plugin-features/reading-time.md`
|
|
83
|
+
|
|
84
|
+
```markdown
|
|
85
|
+
---
|
|
86
|
+
id: plugin-features/reading-time
|
|
87
|
+
status: active
|
|
88
|
+
relatedTasks: []
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
# Reading Time Estimator
|
|
92
|
+
|
|
93
|
+
## Overview
|
|
94
|
+
Calculate and display estimated reading time for WordPress content.
|
|
95
|
+
|
|
96
|
+
## Requirements
|
|
97
|
+
|
|
98
|
+
### Functional Requirements
|
|
99
|
+
- Calculate reading time based on word count
|
|
100
|
+
- Default: 200 words per minute (configurable)
|
|
101
|
+
- Display format: "X min read" or "X minute read"
|
|
102
|
+
- Display options:
|
|
103
|
+
- Before content
|
|
104
|
+
- After content
|
|
105
|
+
- Both
|
|
106
|
+
- Manual via shortcode only
|
|
107
|
+
- Support for posts, pages, and custom post types
|
|
108
|
+
- Exclude HTML tags and shortcodes from word count
|
|
109
|
+
|
|
110
|
+
### Settings Requirements
|
|
111
|
+
- Settings page under Settings > Reading Time
|
|
112
|
+
- Options:
|
|
113
|
+
- Words per minute (default: 200)
|
|
114
|
+
- Display position (before/after/both/manual)
|
|
115
|
+
- Post types to include
|
|
116
|
+
- Display format template
|
|
117
|
+
- Enable/disable for specific post types
|
|
118
|
+
|
|
119
|
+
### Performance Requirements
|
|
120
|
+
- Cache reading time as post meta
|
|
121
|
+
- Recalculate on post save
|
|
122
|
+
- No performance impact on frontend
|
|
123
|
+
|
|
124
|
+
## User Stories
|
|
125
|
+
|
|
126
|
+
**As a** content creator
|
|
127
|
+
**I want** to display reading time on my posts
|
|
128
|
+
**So that** readers know how long content will take
|
|
129
|
+
|
|
130
|
+
**As a** site admin
|
|
131
|
+
**I want** to customize reading time settings
|
|
132
|
+
**So that** I can match my site's needs
|
|
133
|
+
|
|
134
|
+
## Technical Approach
|
|
135
|
+
|
|
136
|
+
### Calculation Algorithm
|
|
137
|
+
```
|
|
138
|
+
words = strip_tags(strip_shortcodes(content))
|
|
139
|
+
word_count = count(explode(' ', words))
|
|
140
|
+
minutes = ceil(word_count / words_per_minute)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### WordPress Integration
|
|
144
|
+
- Filter: `the_content` for automatic display
|
|
145
|
+
- Shortcode: `reading_time` for manual placement
|
|
146
|
+
- Post meta: `_reading_time_minutes` (cached)
|
|
147
|
+
- Action: `save_post` to recalculate
|
|
148
|
+
|
|
149
|
+
### Files to Create
|
|
150
|
+
- `reading-time-estimator.php` - Main plugin file
|
|
151
|
+
- `includes/class-calculator.php` - Reading time calculation
|
|
152
|
+
- `includes/class-display.php` - Display logic
|
|
153
|
+
- `admin/class-settings.php` - Settings page
|
|
154
|
+
- `admin/css/settings.css` - Admin styles
|
|
155
|
+
- `public/css/display.css` - Frontend styles
|
|
156
|
+
|
|
157
|
+
## Testing Requirements
|
|
158
|
+
|
|
159
|
+
### Unit Tests
|
|
160
|
+
- Test word count calculation
|
|
161
|
+
- Test reading time calculation
|
|
162
|
+
- Test different words-per-minute values
|
|
163
|
+
- Test HTML/shortcode stripping
|
|
164
|
+
|
|
165
|
+
### Manual Testing
|
|
166
|
+
- Test on posts with various lengths
|
|
167
|
+
- Test on pages
|
|
168
|
+
- Test on custom post types
|
|
169
|
+
- Test settings page
|
|
170
|
+
- Test shortcode
|
|
171
|
+
- Test with different themes
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Step 3: Create Beads Tasks
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Create epic
|
|
178
|
+
bd create "Build Reading Time Estimator Plugin" -p 0 --type epic --label wordpress --label plugin
|
|
179
|
+
# Returns: bd-rte
|
|
180
|
+
|
|
181
|
+
# Scaffolding
|
|
182
|
+
bd create "Create plugin structure and main file" -p 0 --parent bd-rte --label scaffolding
|
|
183
|
+
# Returns: bd-rte.1
|
|
184
|
+
|
|
185
|
+
bd create "Create readme.txt for WordPress.org" -p 0 --parent bd-rte --label scaffolding
|
|
186
|
+
# Returns: bd-rte.2
|
|
187
|
+
|
|
188
|
+
# Core implementation
|
|
189
|
+
bd create "Create Calculator class" -p 1 --parent bd-rte --label implementation
|
|
190
|
+
# Returns: bd-rte.3
|
|
191
|
+
|
|
192
|
+
bd create "Create Display class" -p 1 --parent bd-rte --label implementation
|
|
193
|
+
# Returns: bd-rte.4
|
|
194
|
+
|
|
195
|
+
bd create "Add shortcode support" -p 1 --parent bd-rte --label implementation
|
|
196
|
+
# Returns: bd-rte.5
|
|
197
|
+
|
|
198
|
+
# Settings
|
|
199
|
+
bd create "Create Settings class" -p 1 --parent bd-rte --label admin --label settings
|
|
200
|
+
# Returns: bd-rte.6
|
|
201
|
+
|
|
202
|
+
bd create "Add settings page UI" -p 1 --parent bd-rte --label admin --label settings
|
|
203
|
+
# Returns: bd-rte.7
|
|
204
|
+
|
|
205
|
+
bd create "Add settings CSS" -p 2 --parent bd-rte --label admin
|
|
206
|
+
# Returns: bd-rte.8
|
|
207
|
+
|
|
208
|
+
# Frontend
|
|
209
|
+
bd create "Add frontend display CSS" -p 2 --parent bd-rte --label frontend
|
|
210
|
+
# Returns: bd-rte.9
|
|
211
|
+
|
|
212
|
+
# Testing
|
|
213
|
+
bd create "Write unit tests" -p 1 --parent bd-rte --label testing
|
|
214
|
+
# Returns: bd-rte.10
|
|
215
|
+
|
|
216
|
+
bd create "Manual testing" -p 2 --parent bd-rte --label testing
|
|
217
|
+
# Returns: bd-rte.11
|
|
218
|
+
|
|
219
|
+
# Documentation
|
|
220
|
+
bd create "Add inline documentation" -p 2 --parent bd-rte --label documentation
|
|
221
|
+
# Returns: bd-rte.12
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Step 4: Add Task Dependencies
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# Display depends on Calculator
|
|
228
|
+
bd dep add bd-rte.4 bd-rte.3
|
|
229
|
+
|
|
230
|
+
# Shortcode depends on Calculator
|
|
231
|
+
bd dep add bd-rte.5 bd-rte.3
|
|
232
|
+
|
|
233
|
+
# Settings UI depends on Settings class
|
|
234
|
+
bd dep add bd-rte.7 bd-rte.6
|
|
235
|
+
|
|
236
|
+
# Settings CSS depends on Settings UI
|
|
237
|
+
bd dep add bd-rte.8 bd-rte.7
|
|
238
|
+
|
|
239
|
+
# Frontend CSS depends on Display
|
|
240
|
+
bd dep add bd-rte.9 bd-rte.4
|
|
241
|
+
|
|
242
|
+
# Testing depends on core implementation
|
|
243
|
+
bd dep add bd-rte.10 bd-rte.5
|
|
244
|
+
bd dep add bd-rte.11 bd-rte.10
|
|
245
|
+
|
|
246
|
+
# Documentation depends on everything
|
|
247
|
+
bd dep add bd-rte.12 bd-rte.11
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Step 5: Implementation
|
|
251
|
+
|
|
252
|
+
#### Task bd-rte.1: Create Plugin Structure
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
bd update bd-rte.1 --status in_progress
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Create directory structure**:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
mkdir -p reading-time-estimator/{includes,admin/{css,js},public/css,tests,languages}
|
|
262
|
+
cd reading-time-estimator
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**File**: `reading-time-estimator.php`
|
|
266
|
+
|
|
267
|
+
```php
|
|
268
|
+
<?php
|
|
269
|
+
/**
|
|
270
|
+
* Plugin Name: Reading Time Estimator
|
|
271
|
+
* Plugin URI: https://example.com/reading-time-estimator
|
|
272
|
+
* Description: Display estimated reading time for posts and pages
|
|
273
|
+
* Version: 1.0.0
|
|
274
|
+
* Author: Your Name
|
|
275
|
+
* Author URI: https://example.com
|
|
276
|
+
* License: GPL-2.0+
|
|
277
|
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
|
278
|
+
* Text Domain: reading-time-estimator
|
|
279
|
+
* Domain Path: /languages
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
if (!defined('ABSPATH')) {
|
|
283
|
+
exit;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
define('RTE_VERSION', '1.0.0');
|
|
287
|
+
define('RTE_PATH', plugin_dir_path(__FILE__));
|
|
288
|
+
define('RTE_URL', plugin_dir_url(__FILE__));
|
|
289
|
+
|
|
290
|
+
// Autoload classes
|
|
291
|
+
spl_autoload_register(function ($class) {
|
|
292
|
+
$prefix = 'RTE_';
|
|
293
|
+
$base_dir = RTE_PATH . 'includes/';
|
|
294
|
+
|
|
295
|
+
$len = strlen($prefix);
|
|
296
|
+
if (strncmp($prefix, $class, $len) !== 0) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
$relative_class = substr($class, $len);
|
|
301
|
+
$file = $base_dir . 'class-' . strtolower(str_replace('_', '-', $relative_class)) . '.php';
|
|
302
|
+
|
|
303
|
+
if (file_exists($file)) {
|
|
304
|
+
require $file;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Initialize plugin
|
|
309
|
+
function rte_init() {
|
|
310
|
+
// Load text domain
|
|
311
|
+
load_plugin_textdomain('reading-time-estimator', false, dirname(plugin_basename(__FILE__)) . '/languages');
|
|
312
|
+
|
|
313
|
+
// Initialize classes
|
|
314
|
+
$calculator = new RTE_Calculator();
|
|
315
|
+
$display = new RTE_Display($calculator);
|
|
316
|
+
$display->init();
|
|
317
|
+
|
|
318
|
+
if (is_admin()) {
|
|
319
|
+
$settings = new RTE_Settings();
|
|
320
|
+
$settings->init();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
add_action('plugins_loaded', 'rte_init');
|
|
324
|
+
|
|
325
|
+
// Activation hook
|
|
326
|
+
register_activation_hook(__FILE__, 'rte_activate');
|
|
327
|
+
function rte_activate() {
|
|
328
|
+
// Set default options
|
|
329
|
+
add_option('rte_words_per_minute', 200);
|
|
330
|
+
add_option('rte_display_position', 'before');
|
|
331
|
+
add_option('rte_post_types', array('post', 'page'));
|
|
332
|
+
add_option('rte_display_format', '%d min read');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Deactivation hook
|
|
336
|
+
register_deactivation_hook(__FILE__, 'rte_deactivate');
|
|
337
|
+
function rte_deactivate() {
|
|
338
|
+
// Cleanup if needed
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
```bash
|
|
343
|
+
bd comment bd-rte.1 "Created plugin structure with autoloader and activation hooks"
|
|
344
|
+
bd close bd-rte.1
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
#### Task bd-rte.2: Create readme.txt
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
bd update bd-rte.2 --status in_progress
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
**File**: `readme.txt`
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
=== Reading Time Estimator ===
|
|
357
|
+
Contributors: yourname
|
|
358
|
+
Tags: reading time, estimated time, content, posts
|
|
359
|
+
Requires at least: 6.0
|
|
360
|
+
Tested up to: 6.4
|
|
361
|
+
Requires PHP: 7.4
|
|
362
|
+
Stable tag: 1.0.0
|
|
363
|
+
License: GPLv2 or later
|
|
364
|
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
|
365
|
+
|
|
366
|
+
Display estimated reading time for your posts and pages.
|
|
367
|
+
|
|
368
|
+
== Description ==
|
|
369
|
+
|
|
370
|
+
Reading Time Estimator calculates and displays the estimated reading time for your WordPress content. Help your readers gauge the time commitment before diving into your articles.
|
|
371
|
+
|
|
372
|
+
**Features:**
|
|
373
|
+
|
|
374
|
+
* Automatic reading time calculation
|
|
375
|
+
* Customizable words per minute
|
|
376
|
+
* Display before or after content
|
|
377
|
+
* Shortcode support: [reading_time]
|
|
378
|
+
* Settings page for easy configuration
|
|
379
|
+
* Support for custom post types
|
|
380
|
+
* Lightweight and fast
|
|
381
|
+
|
|
382
|
+
== Installation ==
|
|
383
|
+
|
|
384
|
+
1. Upload the plugin files to `/wp-content/plugins/reading-time-estimator`
|
|
385
|
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
|
386
|
+
3. Go to Settings > Reading Time to configure options
|
|
387
|
+
|
|
388
|
+
== Frequently Asked Questions ==
|
|
389
|
+
|
|
390
|
+
= How is reading time calculated? =
|
|
391
|
+
|
|
392
|
+
Reading time is calculated based on word count divided by words per minute (default: 200).
|
|
393
|
+
|
|
394
|
+
= Can I customize the display format? =
|
|
395
|
+
|
|
396
|
+
Yes! Go to Settings > Reading Time to customize the format and position.
|
|
397
|
+
|
|
398
|
+
= Does it work with custom post types? =
|
|
399
|
+
|
|
400
|
+
Yes, you can enable it for any post type in the settings.
|
|
401
|
+
|
|
402
|
+
== Changelog ==
|
|
403
|
+
|
|
404
|
+
= 1.0.0 =
|
|
405
|
+
* Initial release
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
bd comment bd-rte.2 "Created WordPress.org readme with description and FAQ"
|
|
410
|
+
bd close bd-rte.2
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
#### Task bd-rte.3: Create Calculator Class
|
|
414
|
+
|
|
415
|
+
```bash
|
|
416
|
+
bd ready # Shows bd-rte.3 is ready
|
|
417
|
+
bd update bd-rte.3 --status in_progress
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**File**: `includes/class-calculator.php`
|
|
421
|
+
|
|
422
|
+
```php
|
|
423
|
+
<?php
|
|
424
|
+
class RTE_Calculator {
|
|
425
|
+
private $words_per_minute;
|
|
426
|
+
|
|
427
|
+
public function __construct() {
|
|
428
|
+
$this->words_per_minute = get_option('rte_words_per_minute', 200);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Calculate reading time for content
|
|
433
|
+
*
|
|
434
|
+
* @param string $content Post content
|
|
435
|
+
* @return int Reading time in minutes
|
|
436
|
+
*/
|
|
437
|
+
public function calculate($content) {
|
|
438
|
+
$word_count = $this->count_words($content);
|
|
439
|
+
$minutes = ceil($word_count / $this->words_per_minute);
|
|
440
|
+
return max(1, $minutes); // Minimum 1 minute
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Count words in content
|
|
445
|
+
*
|
|
446
|
+
* @param string $content Post content
|
|
447
|
+
* @return int Word count
|
|
448
|
+
*/
|
|
449
|
+
public function count_words($content) {
|
|
450
|
+
// Strip HTML tags and shortcodes
|
|
451
|
+
$text = strip_tags(strip_shortcodes($content));
|
|
452
|
+
|
|
453
|
+
// Remove extra whitespace
|
|
454
|
+
$text = preg_replace('/\s+/', ' ', $text);
|
|
455
|
+
|
|
456
|
+
// Count words
|
|
457
|
+
$words = explode(' ', trim($text));
|
|
458
|
+
return count(array_filter($words));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Get or calculate reading time for a post
|
|
463
|
+
*
|
|
464
|
+
* @param int $post_id Post ID
|
|
465
|
+
* @return int Reading time in minutes
|
|
466
|
+
*/
|
|
467
|
+
public function get_reading_time($post_id) {
|
|
468
|
+
// Check cache
|
|
469
|
+
$cached = get_post_meta($post_id, '_reading_time_minutes', true);
|
|
470
|
+
if ($cached) {
|
|
471
|
+
return (int) $cached;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Calculate and cache
|
|
475
|
+
$post = get_post($post_id);
|
|
476
|
+
if (!$post) {
|
|
477
|
+
return 0;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
$minutes = $this->calculate($post->post_content);
|
|
481
|
+
update_post_meta($post_id, '_reading_time_minutes', $minutes);
|
|
482
|
+
|
|
483
|
+
return $minutes;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Recalculate reading time on post save
|
|
488
|
+
*
|
|
489
|
+
* @param int $post_id Post ID
|
|
490
|
+
*/
|
|
491
|
+
public function recalculate_on_save($post_id) {
|
|
492
|
+
// Skip autosave
|
|
493
|
+
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Delete cache to force recalculation
|
|
498
|
+
delete_post_meta($post_id, '_reading_time_minutes');
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
bd comment bd-rte.3 "Created Calculator class with word counting and caching"
|
|
505
|
+
bd close bd-rte.3
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
## Step 6: Continue Implementation
|
|
509
|
+
|
|
510
|
+
Following the dependency chain, implement remaining tasks:
|
|
511
|
+
|
|
512
|
+
- **bd-rte.4**: Display class with content filter
|
|
513
|
+
- **bd-rte.5**: Shortcode handler
|
|
514
|
+
- **bd-rte.6**: Settings class with options API
|
|
515
|
+
- **bd-rte.7**: Settings page UI
|
|
516
|
+
- **bd-rte.8**: Admin CSS
|
|
517
|
+
- **bd-rte.9**: Frontend CSS
|
|
518
|
+
- **bd-rte.10**: Unit tests
|
|
519
|
+
- **bd-rte.11**: Manual testing
|
|
520
|
+
- **bd-rte.12**: Inline documentation
|
|
521
|
+
|
|
522
|
+
## Step 7: Testing and Completion
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
# Run tests
|
|
526
|
+
./vendor/bin/phpunit
|
|
527
|
+
|
|
528
|
+
# Manual testing
|
|
529
|
+
bd update bd-rte.11 --status in_progress
|
|
530
|
+
bd comment bd-rte.11 "Manual testing completed:
|
|
531
|
+
- ✓ Reading time displays correctly
|
|
532
|
+
- ✓ Settings page works
|
|
533
|
+
- ✓ Shortcode works
|
|
534
|
+
- ✓ Caching works (no performance impact)
|
|
535
|
+
- ✓ Works with different post types
|
|
536
|
+
- ✓ Works with different themes"
|
|
537
|
+
bd close bd-rte.11
|
|
538
|
+
|
|
539
|
+
# Add documentation
|
|
540
|
+
bd update bd-rte.12 --status in_progress
|
|
541
|
+
bd comment bd-rte.12 "Added PHPDoc comments to all classes and methods"
|
|
542
|
+
bd close bd-rte.12
|
|
543
|
+
|
|
544
|
+
# Close epic
|
|
545
|
+
bd close bd-rte
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
## Step 8: Archive OpenSpec Change
|
|
549
|
+
|
|
550
|
+
```bash
|
|
551
|
+
# Move to archive
|
|
552
|
+
mv openspec/changes/reading-time-plugin openspec/archive/reading-time-plugin
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
## AI Agent Workflow
|
|
556
|
+
|
|
557
|
+
### Initial Prompt
|
|
558
|
+
|
|
559
|
+
```
|
|
560
|
+
Create a WordPress plugin called "Reading Time Estimator" that displays estimated reading time for posts and pages.
|
|
561
|
+
|
|
562
|
+
Requirements:
|
|
563
|
+
- Plugin slug: reading-time-estimator
|
|
564
|
+
- Text domain: reading-time-estimator
|
|
565
|
+
- Minimum WordPress version: 6.0
|
|
566
|
+
- PHP version: 7.4+
|
|
567
|
+
|
|
568
|
+
Features:
|
|
569
|
+
- Calculate reading time based on word count (200 words/min default)
|
|
570
|
+
- Display before or after content (configurable)
|
|
571
|
+
- Shortcode support: [reading_time]
|
|
572
|
+
- Settings page under Settings > Reading Time
|
|
573
|
+
- Support for custom post types
|
|
574
|
+
- Cache reading time as post meta for performance
|
|
575
|
+
|
|
576
|
+
Use object-oriented architecture with separate classes for calculation, display, and settings.
|
|
577
|
+
Follow WordPress coding standards and best practices.
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
### Implementation Approach
|
|
581
|
+
|
|
582
|
+
1. **Create OpenSpec proposal and spec** with detailed requirements
|
|
583
|
+
2. **Break down into Beads tasks** with clear dependencies
|
|
584
|
+
3. **Implement incrementally** starting with scaffolding
|
|
585
|
+
4. **Test thoroughly** with unit and manual tests
|
|
586
|
+
5. **Document** with inline comments and readme.txt
|
|
587
|
+
|
|
588
|
+
## Key Takeaways
|
|
589
|
+
|
|
590
|
+
- **Start with scaffolding** to establish plugin structure
|
|
591
|
+
- **Use OpenSpec** to define clear requirements before coding
|
|
592
|
+
- **Break down into small tasks** with Beads for tracking
|
|
593
|
+
- **Follow WordPress standards** for plugin structure and naming
|
|
594
|
+
- **Cache expensive operations** (reading time calculation)
|
|
595
|
+
- **Test thoroughly** before release
|
|
596
|
+
- **Document well** for users and developers
|
|
597
|
+
|