Skip to content

Fix attachment-page & direct-access fatal errors in osi theme#221

Merged
nickpagz merged 1 commit into
mainfrom
fix/attachment-sprintf-fatal-main
Jul 25, 2026
Merged

Fix attachment-page & direct-access fatal errors in osi theme#221
nickpagz merged 1 commit into
mainfrom
fix/attachment-sprintf-fatal-main

Conversation

@nickpagz

Copy link
Copy Markdown
Collaborator

Problem

Two PHP fatal errors reported in the osi theme:

  1. ArgumentCountError: 43 arguments are required, 1 given in inc/template-tags.php:36 (osi_posted_on()), triggered when rendering attachment pages (single.php → get_template_part('template-parts/content','attachment') → osi_posted_on()). This is visitor-facing and white-screens the page.
  2. Call to undefined function get_header() in index.php:15, triggered by direct HTTP requests to the theme file (bots/scanners hitting /wp-content/themes/osi/index.php), where WordPress is never bootstrapped. Log noise, not visitor-facing.

Root cause

#1osi_posted_on() called sprintf() with only a format string and no arguments:

$posted_on = sprintf(
    '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);

The "format string" contains the permalink. On attachment pages the URL can contain a literal % (e.g. %43), which sprintf interprets as positional placeholder %43$…ArgumentCountError. There were never any placeholders to substitute.

Fix

  • Replace the pointless sprintf() with plain string concatenation.
  • Add defined( 'ABSPATH' ) || exit; guard to index.php so direct file requests exit cleanly instead of fataling.

Both files pass php -l.

🤖 Generated with Claude Code

- osi_posted_on(): remove argument-less sprintf() that treated the
  permalink HTML as a format string. On attachment pages the URL can
  contain a literal % (e.g. %43), which sprintf read as positional
  placeholder %43$ and threw ArgumentCountError, white-screening the
  page. Replaced with plain concatenation (there were no placeholders).
- index.php: add defined( 'ABSPATH' ) || exit; guard so direct HTTP
  requests to the theme file no longer fatal on undefined get_header().

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nickpagz
nickpagz merged commit bc5e55b into main Jul 25, 2026
1 check failed
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.

1 participant