# jashjacob/credits-shortcode-plugin-for-wordpress architecture

> Architecture diagram of the GitHub repository jashjacob/credits-shortcode-plugin-for-wordpress, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jashjacob/credits-shortcode-plugin-for-wordpress
- Repository: https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress

## Overview

#### 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`](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php) (Plugin bootstrap), [`js/credits-block.js`](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/js/credits-block.js) (Gutenberg block UI), [`block.json`](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/block.json) (Block metadata), [`credits_shortcode_plugin.js`](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode_plugin.js) (TinyMCE button)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_wordpress["WordPress Runtime"]
  node_wp{{"WordPress<br/>CMS runtime"}}
  node_bootstrap["Plugin bootstrap<br/>PHP integration"]
  node_post_content["Saved post content<br/>WordPress content"]
end

subgraph group_authoring["Authoring Surfaces"]
  node_block_metadata["Block metadata<br/>Gutenberg manifest<br/>[block.json]"]
  node_block_editor["Gutenberg block UI<br/>browser editor script<br/>[credits-block.js]"]
  node_classic_editor["TinyMCE button<br/>browser editor script"]
  node_raw_shortcode["Raw shortcode<br/>post content"]
end

subgraph group_presentation["Rendering &amp; Presentation"]
  node_renderer["Attribution renderer<br/>PHP render contract"]
  node_security{{"Sanitization &amp; escaping<br/>trust boundary"}}
  node_markup["Attribution markup<br/>frontend HTML"]
  node_styles["Badge styles<br/>frontend stylesheet<br/>[style.css]"]
  node_frontend["Rendered page<br/>WordPress frontend"]
end

node_wp -->|"loads plugin"| node_bootstrap
node_bootstrap -->|"registers block"| node_block_metadata
node_block_metadata -->|"declares editor script"| node_block_editor
node_bootstrap -->|"enqueues integration"| node_classic_editor
node_block_editor -->|"serializes attributes"| node_post_content
node_classic_editor -->|"inserts shortcode"| node_post_content
node_raw_shortcode -->|"is saved as content"| node_post_content
node_post_content -->|"block or shortcode render"| node_renderer
node_bootstrap -->|"registers callbacks"| node_renderer
node_renderer -->|"sanitizes inputs"| node_security
node_security -->|"safe output"| node_markup
node_markup -->|"renders on page"| node_frontend
node_styles -->|"styles markup"| node_frontend
node_bootstrap -->|"enqueues frontend asset"| node_styles
node_block_editor -.->|"compatible preview structure"| node_markup

click node_bootstrap "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php"
click node_block_metadata "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/block.json"
click node_block_editor "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/js/credits-block.js"
click node_classic_editor "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode_plugin.js"
click node_renderer "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php"
click node_security "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php"
click node_markup "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php"
click node_styles "https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/css/style.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_wp,node_bootstrap,node_post_content toneBlue
class node_block_metadata,node_block_editor,node_classic_editor,node_raw_shortcode toneAmber
class node_renderer,node_security,node_markup,node_styles,node_frontend toneMint
```

## Components

### WordPress Runtime

Platform APIs for hooks, editors, rendering, and assets.

- **WordPress**: CMS runtime · Supplies shortcode, block, editor, sanitization, and enqueue APIs.
- [Plugin bootstrap](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php): PHP integration · Registers plugin integrations and owns server rendering. · `credits_shortcode.php`
- **Saved post content**: WordPress content · Stores block serialization or shortcode syntax.

### Authoring Surfaces

- [Block metadata](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/block.json): Gutenberg manifest · Declares the credits/shortcode block. · `block.json`
- [Gutenberg block UI](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/js/credits-block.js): browser editor script · Edits attribution attributes and provides a preview. · `js/credits-block.js`
- [TinyMCE button](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode_plugin.js): browser editor script · Collects input and inserts compatible shortcode text. · `credits_shortcode_plugin.js`
- **Raw shortcode**: post content · Direct [credits] authoring input.

### Rendering & Presentation

- [Attribution renderer](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php): PHP render contract · Normalizes inputs and emits safe attribution markup. · `credits_shortcode.php`
- [Sanitization & escaping](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php): trust boundary · Constrains colors and protects URL, text, style, and HTML output. · `credits_shortcode.php`
- [Attribution markup](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/credits_shortcode.php): frontend HTML · Shared structural contract for rendered and editor-preview output. · `credits_shortcode.php`
- [Badge styles](https://github.com/jashjacob/credits-shortcode-plugin-for-wordpress/blob/master/css/style.css): frontend stylesheet · Applies colors, alignment, responsiveness, and hover treatment. · `css/style.css`
- **Rendered page**: WordPress frontend

## Connections

- 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
