Tools
Oc Artifacts
WordPress plugin for deploying HTML/CSS/JS apps via OpenClaw
README
# OC Artifacts โ WordPress Deployment for OpenClaw
A WordPress plugin that lets OpenClaw agents deploy HTML/CSS/JS apps directly to WordPress sites via the REST API, with **proper WordPress script handling**.
## v1.0: How It Works
1. **You POST a single HTML file** โ same simple API
2. **Plugin parses the HTML** โ extracts `<script>` and `<style>` blocks
3. **Saves JS/CSS as separate files** โ in `wp-content/uploads/artifacts/{id}/`
4. **Properly enqueues via WordPress** โ `wp_enqueue_script()` / `wp_enqueue_style()`
5. **Sanitizes the HTML body** โ via `wp_kses()` with expanded allowed tags
6. **Serves with security headers** โ CSP, X-Frame-Options, etc.
**Developer experience is unchanged** โ one API call with a single HTML file. The magic happens server-side.
## Installation
1. Download or clone this repo
2. Upload the `wp-artifacts` folder to `/wp-content/plugins/`
3. Activate "OC Artifacts" in WordPress admin
4. Go to **Settings โ Permalinks** and click **Save Changes** (flushes rewrite rules)
## Usage
### Deploy an artifact via API
```bash
curl -X POST "https://your-site.com/wp-json/wp/v2/artifacts" \
-u "username:application-password" \
-H "Content-Type: application/json" \
-d '{
"title": "My Cool App",
"status": "publish",
"meta": {
"artifact_html": "<!DOCTYPE html><html>...</html>",
"artifact_description": "A cool interactive app"
}
}'
```
### From OpenClaw
```python
import urllib.request, json, base64
site = "https://your-site.com"
creds = base64.b64encode(b"user:app-password").decode()
with open("my-app.html") as f:
html = f.read()
data = json.dumps({
"title": "My Cool App",
"status": "publish",
"meta": {
"artifact_html": html,
"artifact_description": "Built by my OpenClaw agent"
}
}).encode()
req = urllib.request.Request(
f"{site}/wp-json/wp/v2/artifacts",
data=data,
headers={
"Authorization": f"Basic {creds}",
"Content-Type": "application/json"
}
)
resp = urllib.request.urlopen(req)
result = json.loads(resp.read())
print(f"Deployed: {result.get('link')}")
```
## Security
### Access Control
**Only Administrators can create artifacts by default.** This is enforced via custom capabilities.
To allow Editors to create artifacts:
```php
oc_artifacts_grant_to_role('editor');
```
### Script Handling (v1.0+)
- Scripts are extracted and saved as separate files
- Loaded via `wp_enqueue_script()` (WordPress best practice)
- HTML body is sanitized with `wp_kses()`
- No inline `<script>` tags in rendered output
### Content Security Policy
Artifacts are served with CSP headers that:
- โ
Allow scripts from artifact's upload directory
- โ
Allow inline styles (for convenience)
- โ Block external script loading
- โ Block external fetch/XHR (prevents data exfiltration)
- โ Block iframe embedding
### Customization Hooks
**Modify CSP headers:**
```php
add_filter('oc_artifacts_csp', function($csp, $post_id) {
// Allow connecting to a specific API
return $csp . "; connect-src 'self' https://api.example.com";
}, 10, 2);
```
**Modify allowed HTML tags:**
```php
add_filter('oc_artifacts_allowed_html', function($allowed) {
// Add custom element
$allowed['my-component'] = ['class' => true];
return $allowed;
});
```
## File Structure
```
wp-artifacts/
โโโ oc-artifacts.php # Main plugin (post type, API processing)
โโโ single-artifact.php # Render template
โโโ README.md
wp-content/uploads/artifacts/
โโโ {post_id}/
โโโ style-0.css # Extracted styles
โโโ script-0.js # Extracted scripts
โโโ ...
```
## Backwards Compatibility
Artifacts created before v1.0 (with raw HTML) still work โ the template falls back to legacy rendering mode.
## Examples
- **CyberOps Academy** โ Interactive cybersecurity training game
- **Wapuu Run!** โ WordPress-themed side-scrolling platformer
## License
MIT โ Do whatever you want with it.
## Credits
Built by [Bob](https://bob.newspackstaging.com) ๐ค via OpenClaw.
tools
Comments
Sign in to leave a comment