Skip to content

enhancement(header): link site name to wp-admin#151

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:enhancement/4-site-link-to-admin
Open

enhancement(header): link site name to wp-admin#151
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:enhancement/4-site-link-to-admin

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

The site name in the Press This header linked to the site front-end (home_url()) instead of wp-admin, leaving no quick way back to the dashboard. The header site name now opens wp-admin, and the link is filterable.

Resolves #4

Changes

class-wp-press-this-plugin.php

Before:

'siteUrl' => home_url( '/' ),

After:

$site_link_url = apply_filters( 'press_this_site_link_url', admin_url() );

$press_this_data = array(
	// ...
	'siteUrl' => home_url( '/' ),
	'adminUrl' => $site_link_url,

Why: Adds a new adminUrl key defaulting to the dashboard, with a press_this_site_link_url filter so the link target can be changed without overriding the data array. The existing siteUrl key is untouched, so the standalone-mode "View Site" menu item still points to the front-end.

src/App.js + src/components/Header.js

Before:

<a href={ siteUrl } target="_blank" rel="noopener noreferrer" className="press-this-header__site-link">

After:

<a href={ adminUrl || siteUrl } target="_blank" rel="noopener noreferrer" className="press-this-header__site-link">

Why: The site name link uses adminUrl with a siteUrl fallback for backward compatibility. App passes adminUrl={ data.adminUrl } through to the Header.

Also guarding html() so it returns instead of die() when PRESS_THIS_PHPUNIT is defined, which lets the existing test helper capture window.pressThisData. This fixed a broken JSON-extraction regex in two test helpers that never ran to completion before.

Testing

Test 1: Site name opens wp-admin

  1. Open Press This (Tools → Press This, or bookmarklet)
  2. Click the WordPress icon / site name in the header
  3. Confirm a new tab opens …/wp-admin/ (dashboard)

Result: link points to wp-admin, not the front-end

Test 2: View Site still opens front-end

  1. Open Press This in standalone mode
  2. Open the header overflow menu (⋮)
  3. Click View Site (only shown in standalone mode)

Result: opens the public front-end (home_url)

Test 3: Filter override (optional)

  1. Add to a theme functions.php or mu-plugin:
    add_filter( 'press_this_site_link_url', function () {
        return home_url( '/' );
    } );
  2. Reload Press This and click the site name

Result: link follows the filtered URL

Tests already passing

  • composer test:php — new adminUrl tests pass (1 pre-existing unrelated failure in test_generic_error_messages_hide_details, a DNS/environment artifact)
  • npm run test:unit — 368 pass, including new Header site-link tests
  • npm run build — assets rebuilt

- Add adminUrl to pressThisData, defaulting to admin_url()
- New press_this_site_link_url filter lets the link be customized
- Header site name now opens the dashboard; View Site menu item keeps the front-end URL
- Guard html() with die() only outside PHPUnit so helper tests can capture output

Resolves WordPress#4

Signed-off-by: Faisal Ahammad <faisalahammad24@gmail.com>
@faisalahammad
faisalahammad force-pushed the enhancement/4-site-link-to-admin branch from c2f1131 to 986b08f Compare July 11, 2026 20:21
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.

Easy way back to wp-admin

1 participant