Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .cursor/run-block-editor-e2e.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"
export PATH="$ROOT/.cursor/bin:${PATH}"
if [ -f "$ROOT/.wordpress/wp-load.php" ]; then
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
WP_PATH="$REPO_ROOT/.wordpress"
cd "$SCRIPT_DIR"
export PATH="$REPO_ROOT/.cursor/bin:${PATH}"

if [ -f "$WP_PATH/wp-load.php" ]; then
wp option update credits_shortcode_settings \
'{"type":"via","spacing":"standard","badge_color":"","link_color":"","link_text_color":""}' \
--format=json --path="$ROOT/.wordpress" --quiet
--format=json --path="$WP_PATH" --quiet
export CREDITS_E2E_DEFAULT_TYPE="$(wp option get credits_shortcode_settings --path="$WP_PATH" --format=json | php -r '$d=json_decode(stream_get_contents(STDIN),true); echo is_array($d)&&isset($d["type"])?$d["type"]:"via";')"
else
export CREDITS_E2E_DEFAULT_TYPE="${CREDITS_E2E_DEFAULT_TYPE:-via}"
fi
npm install --no-save playwright@1.49.1 >/dev/null 2>&1
npx playwright install chromium >/dev/null 2>&1
Expand Down
17 changes: 10 additions & 7 deletions .cursor/test-block-editor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const BASE = 'http://127.0.0.1:8080';
const ART = '/opt/cursor/artifacts';
mkdirSync(ART, { recursive: true });

const siteDefaultType = (process.env.CREDITS_E2E_DEFAULT_TYPE || 'via').toLowerCase() === 'via' ? 'via' : 'source';
const siteDefaultLabel = siteDefaultType === 'via' ? 'Via' : 'Source';

const results = [];

function pass(msg) {
Expand Down Expand Up @@ -61,14 +64,14 @@ try {
await typeSelect.selectOption('');
await page.waitForTimeout(500);
let badge = await canvas.locator('.wp-block-credits-shortcode .cre_cate').first().innerText();
if (badge.trim() === 'Via') {
pass('Preview shows Via when type is Use site default (site default = via)');
if (badge.trim() === siteDefaultLabel) {
pass(`Preview shows ${siteDefaultLabel} when type is Use site default (site default = ${siteDefaultType})`);
} else {
fail(`Expected Via preview, got "${badge}"`);
fail(`Expected ${siteDefaultLabel} preview for site default ${siteDefaultType}, got "${badge}"`);
}

await page.screenshot({ path: join(ART, 'block-editor-site-default-via.png'), fullPage: false });
pass('Screenshot: block-editor-site-default-via.png');
pass('Screenshot: block-editor-site-default.png');

await typeSelect.selectOption('source');
await page.waitForTimeout(500);
Expand All @@ -85,10 +88,10 @@ try {
await typeSelect.selectOption('');
await page.waitForTimeout(500);
badge = await canvas.locator('.wp-block-credits-shortcode .cre_cate').first().innerText();
if (badge.trim() === 'Via') {
pass('Preview returns to Via after re-selecting Use site default');
if (badge.trim() === siteDefaultLabel) {
pass(`Preview returns to ${siteDefaultLabel} after re-selecting Use site default`);
} else {
fail(`Expected Via again, got "${badge}"`);
fail(`Expected ${siteDefaultLabel} again, got "${badge}"`);
}

const invalidNest = await page.evaluate(() => {
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/wordpress-smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: WordPress smoke

on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'credits_shortcode.php'
- 'css/**'
- 'js/**'
- 'block.json'
- '.cursor/**'
- 'scripts/**'

jobs:
wordpress-smoke:
runs-on: ubuntu-latest
timeout-minutes: 25

steps:
- name: Checkout
uses: actions/checkout@v4

- name: WordPress install and smoke tests
run: |
chmod +x .cursor/cloud-agent-install.sh .cursor/cloud-agent-start.sh \
.cursor/cloud-agent-verify.sh .cursor/cloud-agent-test-variations.sh
./.cursor/cloud-agent-install.sh
./.cursor/cloud-agent-start.sh
./.cursor/cloud-agent-verify.sh
./.cursor/cloud-agent-test-variations.sh
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,41 @@ Copy or symlink the directory into your site's `/wp-content/plugins/` and activa

## 🧪 Development & Testing

The plugin ships with a PHPUnit test suite (34 tests) that runs automatically across PHP 7.4–8.4 in GitHub Actions on every push.
### PHPUnit (runs on every push in GitHub Actions)

The plugin ships with a PHPUnit test suite (**44 tests**, PHP **7.4–8.4** matrix) plus a **WordPress.org release zip** check on PHP 8.3.

```bash
composer install
vendor/bin/phpunit
bash scripts/build-wp-release.sh
```

### Full WordPress stack (local or Cloud Agent)

Stub PHPUnit does not boot WordPress. For runtime shortcode, block, and variation checks, use the Cloud Agent scripts (also under `.cursor/` in this repo):

```bash
./.cursor/cloud-agent-install.sh # PHP, Composer, MariaDB, WP-CLI
./.cursor/cloud-agent-start.sh # WordPress 6.7 + symlinked plugin (admin/admin @ :8080)
./.cursor/cloud-agent-wp-server.sh # optional: wp server on 8080
./.cursor/cloud-agent-verify.sh # lint, PHPUnit, WP shortcode smoke
./.cursor/cloud-agent-test-variations.sh # 21 front-end / block scenarios
./.cursor/run-block-editor-e2e.sh # Playwright block editor (7 checks)
```

The block E2E runner sets site default type to **Via** when `.wordpress/` exists and reads the effective default via `CREDITS_E2E_DEFAULT_TYPE` so tests match **Settings → Credits**.

### Optional CI: WordPress smoke workflow

On GitHub, run **Actions → WordPress smoke → Run workflow** (`workflow_dispatch`) to install MariaDB, boot a fresh WordPress copy, and run verify + variation tests. Day-to-day PRs still use fast PHPUnit only.

### Translation template

Regenerate the POT file after changing translatable strings:

```bash
bash scripts/generate-pot.sh
```

---
Expand Down
22 changes: 17 additions & 5 deletions credits_shortcode_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@
: text;
};

var sanitizeTinyMceShortcodeValue = function (value) {
return String(value || '')
.replace(/[\x00-\x20\x7f]/g, '')
var stripControlChars = function (value) {
return String(value || '').replace(/[\x00-\x1f\x7f]/g, '');
};

var sanitizeTinyMceLinkValue = function (value) {
return stripControlChars(value)
.replace(/"/g, '')
.replace(/[\[\]]/g, '')
.replace(/[<>]/g, '')
.replace(/\s+/g, '')
.trim();
};

var sanitizeTinyMceNameValue = function (value) {
return stripControlChars(value)
.replace(/"/g, '')
.replace(/[\[\]]/g, '')
.replace(/[<>]/g, '')
Expand Down Expand Up @@ -51,8 +63,8 @@
return;
}

clink = sanitizeTinyMceShortcodeValue(clink);
cname = sanitizeTinyMceShortcodeValue(cname);
clink = sanitizeTinyMceLinkValue(clink);
cname = sanitizeTinyMceNameValue(cname);
if (!clink || !cname) {
alert(translate('Link and name are required.'));
return;
Expand Down
27 changes: 15 additions & 12 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ div.credits.wp-block-credits-shortcode {
padding-top: 0 !important;
padding-bottom: 0 !important;
display: block !important;
text-align: left !important;
clear: both !important;
box-sizing: border-box !important;
text-align: left;
clear: both;
box-sizing: border-box;
list-style: none !important;
}

Expand Down Expand Up @@ -91,11 +91,12 @@ div.credits .credits-inner:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

ul.credits span,
div.credits span {
padding: 4px 10px !important;
display: inline-block !important;
box-sizing: border-box !important;
ul.credits.wp-block-credits-shortcode li.credits span,
ul.credits li.credits span,
div.credits .credits-inner span {
padding: 4px 10px;
display: inline-block;
box-sizing: border-box;
transition: filter 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

Expand All @@ -111,8 +112,9 @@ div.credits span {
border-radius: 0 3px 3px 0;
}

.cre_cate_link a {
text-decoration: none !important;
ul.credits .cre_cate_link a,
div.credits .cre_cate_link a {
text-decoration: none;
font-weight: 500;
transition: color 0.2s ease;
}
Expand All @@ -128,6 +130,7 @@ div.credits .credits-inner:hover .cre_cate_link {
filter: brightness(0.95);
}

.cre_cate_link a:hover {
text-decoration: underline !important;
ul.credits .cre_cate_link a:hover,
div.credits .cre_cate_link a:hover {
text-decoration: underline;
}
2 changes: 1 addition & 1 deletion js/credits-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
var schemeMatch = decoded.match(/^([a-zA-Z][a-zA-Z0-9+.\-]*):/);
if (schemeMatch) {
var scheme = schemeMatch[1].toLowerCase();
if (['http', 'https', 'mailto', 'ftp', 'tel'].indexOf(scheme) === -1) {
if (['http', 'https', 'mailto', 'ftp'].indexOf(scheme) === -1) {
return '#';
}
}
Expand Down
132 changes: 128 additions & 4 deletions languages/credits-shortcode.pot
Original file line number Diff line number Diff line change
@@ -1,18 +1,142 @@
# Copyright (C) 2026 Jash Jacob
# This file is distributed under the same license as the Credits Shortcode & Block plugin.
# This file is distributed under the GPLv2 or later.
msgid ""
msgstr ""
"Project-Id-Version: Credits Shortcode & Block 1.6.0\n"
"Report-Msgid-Bugs-To: https://github.com/jashjacob/Credits-Shortcode-Plugin-for-Wordpress\n"
"POT-Creation-Date: 2026-09-23 12:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Report-Msgid-Bugs-To: https://github.com/jashjacob/Credits-Shortcode-Plugin-for-Wordpress/issues\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2026-09-23T11:29:43+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: credits-shortcode\n"

#. Plugin Name of the plugin
#: credits_shortcode.php
msgid "Credits Shortcode & Block"
msgstr ""

#. Plugin URI of the plugin
#: credits_shortcode.php
msgid "https://github.com/jashjacob/Credits-Shortcode-Plugin-for-Wordpress"
msgstr ""

#. Description of the plugin
#: credits_shortcode.php
msgid "Add clean Source and Via attribution links with a Gutenberg block, shortcode, or Classic Editor button."
msgstr ""

#. Author of the plugin
#: credits_shortcode.php
msgid "Jash Jacob"
msgstr ""

#. Author URI of the plugin
#: credits_shortcode.php
msgid "https://jashjacob.com"
msgstr ""

#: credits_shortcode.php:294
msgid "Credit Link"
msgstr ""

#: credits_shortcode.php:312
#: credits_shortcode.php:519
msgid "Via"
msgstr ""

#: credits_shortcode.php:312
#: credits_shortcode.php:518
msgid "Source"
msgstr ""

#: credits_shortcode.php:446
#: credits_shortcode.php:572
msgid "Credits Shortcode"
msgstr ""

#: credits_shortcode.php:447
msgid "Credits"
msgstr ""

#: credits_shortcode.php:467
msgid "Default Credit Appearance"
msgstr ""

#: credits_shortcode.php:474
msgid "Default credit type"
msgstr ""

#: credits_shortcode.php:482
msgid "Default spacing between credits"
msgstr ""

#: credits_shortcode.php:489
msgid "Badge background color"
msgstr ""

#: credits_shortcode.php:490
msgid "Link background color"
msgstr ""

#: credits_shortcode.php:491
msgid "Link text color"
msgstr ""

#: credits_shortcode.php:508
msgid "These defaults apply when a shortcode or block does not set its own values. Individual credits can override spacing and colors. Leave colors empty to inherit neutral plugin styling."
msgstr ""

#: credits_shortcode.php:531
msgid "Compact"
msgstr ""

#: credits_shortcode.php:532
msgid "Standard"
msgstr ""

#: credits_shortcode.php:533
msgid "Spacious"
msgstr ""

#: credits_shortcode.php:535
msgid "Controls the vertical gap between consecutive credits."
msgstr ""

#: block.json
msgctxt "block title"
msgid "Credits Link"
msgstr ""

#: block.json
msgctxt "block description"
msgid "Insert Source or Via credit link into your post with customizable accent colors."
msgstr ""

#: block.json
msgctxt "block keyword"
msgid "credits"
msgstr ""

#: block.json
msgctxt "block keyword"
msgid "source"
msgstr ""

#: block.json
msgctxt "block keyword"
msgid "via"
msgstr ""

#: block.json
msgctxt "block keyword"
msgid "attribution"
msgstr ""

#: block.json
msgctxt "block keyword"
msgid "color"
msgstr ""
Loading
Loading