From d0ec5405542059fdbb3c4f072050c59b944530e3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 23 Sep 2026 11:31:44 +0000 Subject: [PATCH 1/4] Fix TinyMCE name spaces, trim CSS !important, align editor URL schemes with PHP. Co-authored-by: Jash Jacob --- credits_shortcode_plugin.js | 22 +++++++++++++++++----- css/style.css | 27 +++++++++++++++------------ js/credits-block.js | 2 +- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/credits_shortcode_plugin.js b/credits_shortcode_plugin.js index a08ab64..ddafb84 100644 --- a/credits_shortcode_plugin.js +++ b/credits_shortcode_plugin.js @@ -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, '') @@ -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; diff --git a/css/style.css b/css/style.css index c0c2bf3..b810dd4 100644 --- a/css/style.css +++ b/css/style.css @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/js/credits-block.js b/js/credits-block.js index 372cd50..34b1282 100644 --- a/js/credits-block.js +++ b/js/credits-block.js @@ -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 '#'; } } From 2f0f50f8a157cea6deb46dc129fc44fbbe848c72 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 23 Sep 2026 11:31:46 +0000 Subject: [PATCH 2/4] Regenerate POT with wp i18n and add scripts/generate-pot.sh. Co-authored-by: Jash Jacob --- languages/credits-shortcode.pot | 132 +++++++++++++++++++++++++++++++- scripts/generate-pot.sh | 24 ++++++ tests/test_languages.php | 11 ++- 3 files changed, 160 insertions(+), 7 deletions(-) create mode 100755 scripts/generate-pot.sh diff --git a/languages/credits-shortcode.pot b/languages/credits-shortcode.pot index 620faf1..a183a7e 100644 --- a/languages/credits-shortcode.pot +++ b/languages/credits-shortcode.pot @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/scripts/generate-pot.sh b/scripts/generate-pot.sh new file mode 100755 index 0000000..e43fbb9 --- /dev/null +++ b/scripts/generate-pot.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Regenerate languages/credits-shortcode.pot from PHP and block editor JS. +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT" + +if ! command -v wp >/dev/null 2>&1; then + if [ -x "$ROOT/.cursor/bin/wp" ]; then + export PATH="$ROOT/.cursor/bin:$PATH" + else + echo "wp-cli required (install via .cursor/cloud-agent-install.sh or PATH)" >&2 + exit 1 + fi +fi + +mkdir -p "$ROOT/languages" + +wp i18n make-pot "$ROOT" "$ROOT/languages/credits-shortcode.pot" \ + --domain=credits-shortcode \ + --exclude=vendor,tests,.wordpress,.cursor,node_modules \ + --headers='{"Report-Msgid-Bugs-To":"https://github.com/jashjacob/Credits-Shortcode-Plugin-for-Wordpress/issues"}' + +echo "Wrote languages/credits-shortcode.pot" diff --git a/tests/test_languages.php b/tests/test_languages.php index 3ee1e36..81dc8c4 100644 --- a/tests/test_languages.php +++ b/tests/test_languages.php @@ -10,9 +10,14 @@ final class LanguagesTest extends TestCase { public function test_languages_directory_exists_for_textdomain(): void { $dir = dirname( __DIR__ ) . '/languages'; $this->assertDirectoryExists( $dir, 'languages/ must exist when Domain Path is set in the plugin header' ); - $this->assertFileExists( - $dir . '/credits-shortcode.pot', - 'Provide at least a POT template for translators' + $pot = $dir . '/credits-shortcode.pot'; + $this->assertFileExists( $pot, 'Provide at least a POT template for translators' ); + $contents = file_get_contents( $pot ); + $this->assertIsString( $contents ); + $this->assertGreaterThan( + 5, + substr_count( $contents, 'msgid "' ), + 'POT should list plugin strings (run scripts/generate-pot.sh after copy changes)' ); } } From 69bab58a585d812ec208be8273e867a48f112151 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 23 Sep 2026 11:31:46 +0000 Subject: [PATCH 3/4] Document full-stack testing and add optional WordPress smoke workflow. Co-authored-by: Jash Jacob --- .github/workflows/wordpress-smoke.yml | 32 +++++++++++++++++++++++++++ README.md | 32 ++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/wordpress-smoke.yml diff --git a/.github/workflows/wordpress-smoke.yml b/.github/workflows/wordpress-smoke.yml new file mode 100644 index 0000000..a4911df --- /dev/null +++ b/.github/workflows/wordpress-smoke.yml @@ -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 diff --git a/README.md b/README.md index 843afd0..2a307e9 100644 --- a/README.md +++ b/README.md @@ -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 ``` --- From 58bcd25319918e4162c4534498c3698ca2872b3d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 23 Sep 2026 11:31:50 +0000 Subject: [PATCH 4/4] Fix block E2E WP paths and assert against live site default type. Co-authored-by: Jash Jacob --- .cursor/run-block-editor-e2e.sh | 16 +++++++++++----- .cursor/test-block-editor.mjs | 17 ++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.cursor/run-block-editor-e2e.sh b/.cursor/run-block-editor-e2e.sh index 7e34841..9201ab2 100755 --- a/.cursor/run-block-editor-e2e.sh +++ b/.cursor/run-block-editor-e2e.sh @@ -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 diff --git a/.cursor/test-block-editor.mjs b/.cursor/test-block-editor.mjs index e79d74b..91fd818 100644 --- a/.cursor/test-block-editor.mjs +++ b/.cursor/test-block-editor.mjs @@ -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) { @@ -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); @@ -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(() => {