Skip to content

Fix specialty keytags showing by default when the setting is off (#24)#28

Merged
pjaudiomv merged 2 commits into
mainfrom
feature/nacc-24-special-keytags-default-off
Jul 17, 2026
Merged

Fix specialty keytags showing by default when the setting is off (#24)#28
pjaudiomv merged 2 commits into
mainfrom
feature/nacc-24-special-keytags-default-off

Conversation

@dgershman

Copy link
Copy Markdown
Contributor

Closes #24

Problem

On a fresh install, the specialty (over-2-years) keytags render on the frontend even though Settings → NACC → Show Special Keytags is unchecked and the label says "Default is false."

The settings UI and the frontend disagreed on the default:

  • DEFAULT_SHOW_SPECIAL was the string 'true', and both render paths read get_option( 'nacc_special', self::DEFAULT_SHOW_SPECIAL ). The 2nd get_option() arg only applies when the option row is absent (any install where the form was never saved), so the JS constructor received a truthy "true" and specialty tags rendered.
  • register_settings() registered nacc_special without a 'default' key (unlike nacc_theme/nacc_language/nacc_layout), so get_option('nacc_special') in draw_settings() returned false and the checkbox rendered unchecked.

Net: checkbox off, frontend on.

Fix (scoped to the default-state bug)

  • DEFAULT_SHOW_SPECIAL → boolean false.
  • Register 'default' => false on the nacc_special setting so draw_settings() and the frontend get_option fallback agree.
  • Normalize the value handed to the JS constructor to a real JSON boolean: wp_json_encode( (bool) $args['special'] ) in render_keytags() (shared by both the shortcode and legacy nacc_content() paths). This also removes the stringified "0"/"true" truthiness trap flagged in the ticket — the JS side does a truthy check (nacc2/src/nacc.js:59), and a real JSON false renders no specialty tags.

No JS source change was needed (the constructor already treats the 4th arg as a boolean/truthy check), so the shipped bundle is unchanged.

Verification

  • Fresh/unsaved install (no nacc_special row): get_option('nacc_special', false) → registered default falsewp_json_encode( (bool) '' ) → JS falseno specialty tags, and the checkbox reads the same false default → unchecked. Consistent.
  • Box checked + saved: option stored true → JS true → tags show; checkbox checked.
  • php -l clean; phpcs (.phpcs.xml) passes with no findings.

Shared version / readme bump (see #24/#25/#26)

This is the base of the #24/#25/#26 release set. Per the ticket comment, the version bump and readme.txt changelog are meant to be managed once for the combined set. Since #25/#26 aren't merged yet, this PR makes the smallest correct change: version 6.0.1 → 6.0.2 (plugin header + Stable tag) and a single changelog entry. Reviewer/mergers: please treat the version + changelog as shared with #25/#26 and avoid double-bumping when those land — fold their notes into the same 6.0.2 entry rather than adding another bump.

The settings UI and frontend disagreed on the default for
'Show Special Keytags':

- DEFAULT_SHOW_SPECIAL was the string 'true', so on any install
  where the settings form was never saved, get_option('nacc_special',
  self::DEFAULT_SHOW_SPECIAL) fell back to 'true' and specialty tags
  rendered.
- register_settings() registered nacc_special without a 'default',
  so draw_settings() rendered the checkbox unchecked.

Result: the box showed off while the frontend behaved as on.

Fixes:
- Set DEFAULT_SHOW_SPECIAL to boolean false and register
  'default' => false on nacc_special so both code paths agree.
- Normalize the value handed to the JS constructor to a real JSON
  boolean via wp_json_encode( (bool) $args['special'] ), removing the
  stringified '0'/'true' truthiness trap on the JS side.

Bumps plugin version to 6.0.2 and adds a readme.txt changelog entry
(shared with #25/#26).

Closes #24

Crow-Session: ED282F8A-4220-4B42-8842-460C56B4C61E
Co-Authored-By: Claude <noreply@anthropic.com>
@dgershman
dgershman requested a review from pjaudiomv July 17, 2026 00:25
@pjaudiomv
pjaudiomv merged commit c39cdb6 into main Jul 17, 2026
1 check passed
@pjaudiomv
pjaudiomv deleted the feature/nacc-24-special-keytags-default-off branch July 17, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specialty keytags show by default even when the setting is unchecked

2 participants