Make WordPress Core

Opened 16 months ago

Closed 2 months ago

#63467 closed defect (bug) (fixed)

function do_robots() should use admin_url()

Reported by: Hrohh Owned by: westonruter
Priority: normal Milestone: 7.1
Component: Privacy Version: 6.8
Severity: normal Keywords: has-patch has-unit-tests commit
Cc: Focuses: administration, privacy

Description

Dear all,

we have /wp-admin/ hardcoded in do_robots() function. How can i use filter admin_url('admin-ajax.php') ?

<?php
        $site_url = parse_url( site_url() );
        $path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
        $output  .= "Disallow: $path/wp-admin/\n";
        $output  .= "Allow: $path/wp-admin/admin-ajax.php\n";

Thank you.

Change History (9)

#1 @Hrohh
16 months ago

  • Summary function do_robots() should use admin_url() afunction do_robots() should use admin_url()

This ticket was mentioned in PR #8834 on WordPress/wordpress-develop by @yogeshbhutkar.


16 months ago
#2

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/63467

### Description

This PR introduces the use of the admin_url() function to dynamically retrieve the admin URL, replacing previously hardcoded values.

### Screenshots

InstallationBeforeAfter
Single Sitehttps://github.com/user-attachments/assets/ba7120a7-b553-4d10-a3db-92c8e5d9db42https://github.com/user-attachments/assets/7213c20b-b523-40d5-ae87-abed445fae6c
Multisitehttps://github.com/user-attachments/assets/1ff15b2b-20f9-42d3-bcbd-6c0a6ee7b34fhttps://github.com/user-attachments/assets/239f5a9b-9e33-4188-9957-a4ec34d342bc

This ticket was mentioned in PR #11998 on WordPress/wordpress-develop by @masteradhoc.


4 months ago
#3

  • Keywords has-unit-tests added

Updates do_robots() to use filtered admin URL paths instead of hardcoded /wp-admin/ values.

This changes the default robots.txt output to derive the Disallow and Allow paths from admin_url() and admin_url( 'admin-ajax.php' ), while continuing to output only the path portion. This allows installs that filter admin URLs to generate correct robots.txt directives.

A PHPUnit regression test is included to verify that filtered admin paths are reflected in the do_robots() output.

Trac ticket: https://core.trac.wordpress.org/ticket/63467

## Use of AI Tools
AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): GPT-5.4
Used for: Drafting the initial patch and regression test. The final implementation, test coverage, and PR description were reviewed and edited by me.

#4 @masteradhoc
4 months ago

Hey all

I've just refreshed the PR with test. Thanks to @yogeshbhutkar for the initial PR!
@mukesh27 As you've already checked the initial PR, can i ask you to check the refreshed PR as well?

I think we can Milestone this as we'll for 7.1 now.

Thanks

#5 @masteradhoc
4 months ago

  • Milestone Awaiting Review7.1
  • Owner set to masteradhoc
  • Status newassigned

#6 @westonruter
3 months ago

  • Keywords commit added
  • Owner changed from masteradhoc to westonruter
  • Status assignedreviewing

This ticket was mentioned in Slack in #meta by westonruter. View the logs.


3 months ago

@westonruter commented on PR #8834:


3 months ago
#8

Thank for for the PR. Closing in favor of https://github.com/WordPress/wordpress-develop/pull/11998

#9 @westonruter
2 months ago

  • Resolutionfixed
  • Status reviewingclosed

In 62633:

Robots: Use admin_url() for the robots.txt admin paths.

Derive the Disallow and Allow directives in do_robots() from admin_url() and admin_url( 'admin-ajax.php' ) rather than from a hardcoded /wp-admin/ path built off site_url(). Only the URL path portion is emitted, as before, so installs that relocate or filter their admin URL now produce a correct default robots.txt.

Also guard the Content-Type header with a headers_sent() check to avoid a warning when the headers have already been sent.

Developed in https://github.com/WordPress/wordpress-develop/pull/11998.
Follow-up to r34985.

Props masteradhoc, yogeshbhutkar, hrohh, westonruter, mukeshpanchal27, 1ucay.
Fixes #63467.

Note: See TracTickets for help on using tickets.