How jashjacob/credits-shortcode-plugin-for-wordpress works
1. Purpose and Runtime
This is a WordPress plugin that renders “Source”/“Via” attribution links through three authoring surfaces: a legacy shortcode, a Gutenberg block, and a Classic Editor/TinyMCE button. It runs inside WordPress on PHP 7.4+ and WordPress 5.0+, using browser-side WordPress editor globals rather than a compiled JS toolchain.
Primary plugin entry point: credits_shortcode.php.
2. PHP Plugin Bootstrap and Registration
credits_shortcode.php is the server-side integration boundary. It registers the [credits]...[/credits] shortcode, hooks WordPress actions/filters, loads frontend assets, and connects editor integrations. It is also the likely owner of block registration and render behavior.
Key paths:
• credits_shortcode.php
• block.json
3. Canonical Attribution Rendering and Security Boundary
The shortcode/rendering path accepts attribution type, label/content, URL, and optional colors, then produces the frontend markup. This is the critical trust boundary: URL, text, type, and color inputs are sanitized on ingestion and escaped when emitted. Color values are constrained to hex values; final inline style/HTML output is additionally filtered through WordPress-safe mechanisms.
All authoring mechanisms should converge on this server-controlled rendering contract rather than independently constructing trusted frontend HTML.
Key path:
• credits_shortcode.php
4. Gutenberg Block Authoring Flow
The native credits/shortcode block is declared via metadata and registered into Gutenberg. Its editor script defines block attributes and edit UI: credit type, attribution name, target URL, and three accent colors. The UI provides an editor preview and Inspector/sidebar controls; persisted attributes are serialized into post content and interpreted by the PHP-side rendering path.
Key paths:
• block.json
• js/credits-block.js
• credits_shortcode.php
5. Classic Editor Compatibility
A separate browser script integrates with TinyMCE for sites using the Classic Editor. It adds the legacy toolbar interaction, gathers author input, and inserts compatible shortcode content into the editor. The shortcode renderer remains the compatibility and execution boundary after content is saved.
Key paths:
• credits_shortcode_plugin.js
• credits_shortcode.php
6. Frontend Presentation
Frontend styling defines the badge/link visual structure, configurable color targets, responsive/block-theme alignment behavior, and hover transitions. Rendered markup from PHP and preview markup from the block editor must retain compatible class names and structural assumptions.
Key path:
• css/style.css
7. Content and Control Flow
1. An author creates attribution content through Gutenberg, TinyMCE, or raw shortcode text.
2. Gutenberg persists block attributes; TinyMCE generates shortcode syntax; raw shortcodes directly supply attributes/content.
3. On page rendering, WordPress invokes the plugin’s registered shortcode/block renderer in credits_shortcode.php.
4. The renderer sanitizes and normalizes inputs, emits safe attribution markup, and frontend CSS applies the visual treatment.
5. WordPress provides all platform services: hooks, shortcode parsing, block registration, asset enqueueing, sanitization/escaping, and TinyMCE/Gutenberg APIs.
Main entry points: credits_shortcode.php Plugin bootstrap · credits-block.js Gutenberg block UI · block.json Block metadata · credits_shortcode_plugin.js TinyMCE button
Components 12
WordPress Runtime
Platform APIs for hooks, editors, rendering, and assets.
- WordPress · Supplies shortcode, block, editor, sanitization, and enqueue APIs.
- Plugin bootstrap · Registers plugin integrations and owns server rendering.
credits_shortcode.php - Saved post content · Stores block serialization or shortcode syntax.
Authoring Surfaces
- Block metadata · Declares the credits/shortcode block.
block.json - Gutenberg block UI · Edits attribution attributes and provides a preview.
js/credits-block.js - TinyMCE button · Collects input and inserts compatible shortcode text.
credits_shortcode_plugin.js - Raw shortcode · Direct [credits] authoring input.
Rendering & Presentation
- Attribution renderer · Normalizes inputs and emits safe attribution markup.
credits_shortcode.php - Sanitization & escaping · Constrains colors and protects URL, text, style, and HTML output.
credits_shortcode.php - Attribution markup · Shared structural contract for rendered and editor-preview output.
credits_shortcode.php - Badge styles · Applies colors, alignment, responsiveness, and hover treatment.
css/style.css - Rendered page
Connections 15
- WordPress → Plugin bootstrap: loads plugin
- Plugin bootstrap → Block metadata: registers block
- Block metadata → Gutenberg block UI: declares editor script
- Plugin bootstrap → TinyMCE button: enqueues integration
- Gutenberg block UI → Saved post content: serializes attributes
- TinyMCE button → Saved post content: inserts shortcode
- Raw shortcode → Saved post content: is saved as content
- Saved post content → Attribution renderer: block or shortcode render
- Plugin bootstrap → Attribution renderer: registers callbacks
- Attribution renderer → Sanitization & escaping: sanitizes inputs
- Sanitization & escaping → Attribution markup: safe output
- Attribution markup → Rendered page: renders on page
- Badge styles → Rendered page: styles markup
- Plugin bootstrap → Badge styles: enqueues frontend asset
- Gutenberg block UI → Attribution markup: compatible preview structure