Make WordPress Core

Opened 14 years ago

Closed 12 years ago

#18504 closed enhancement (fixed)

Allow filtering of "Add New [Post Type]" URL on edit.php

Reported by: tbuteler's profile tbuteler Owned by: helen's profile helen
Milestone: 3.7 Priority: normal
Severity: trivial Version: 3.2.1
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

I've recently attempted to use add_filter('admin_url','filter_function'), only to discover that there are many URLs in the admin area that are not passed through the admin_url() function. While there may be a good reason for that to happen, I figured it wouldn't hurt to check the possibility of changing one of them.

The one URL I haven't been able to find a workaround to is the "Add New [Post Type]" button on the edit.php screen, on top the post table, which also appears when editing an existing post. From what I gather, it is generated in the following file/line http://core.trac.wordpress.org/browser/trunk/wp-admin/edit.php#L189 for the first case, and on this one http://core.trac.wordpress.org/browser/trunk/wp-admin/edit-form-advanced.php#L198 for the second case.

Fixing this, assuming it's possible without compromising a functionality I'm not aware of, would be as simple as replacing this:

<a href="<?php echo $post_new_file ?>" ...

And this:

<a href="<?php echo esc_url( $post_new_file ) ?>" ...

With this:

<a href="<?php echo admin_url($post_new_file); ?>" ...

And this:

<a href="<?php echo esc_url( admin_url($post_new_file) ) ?>" ...

Attachments (2)

18504.patch (1.6 KB) - added by SergeyBiryukov 14 years ago.
18504.2.patch (1.5 KB) - added by c3mdigital 12 years ago.
Refresh of original patch

Download all attachments as: .zip

Change History (13)

#1 @scribu
14 years ago

  • Type changed from feature request to enhancement

Sidenote: esc_url() is either necessary or it isn't, so one of the usages is incorrect.

Otherwise, using admin_url() there seems like a good idea.

#2 @scribu
14 years ago

  • Component changed from General to Administration

#3 @kawauso
14 years ago

$post_new_file is set around http://core.trac.wordpress.org/browser/trunk/wp-admin/edit.php#L38, so assuming we trust the post type slug is valid since it's in get_post_types(), the esc_url() instance is the incorrect one.

#4 @SergeyBiryukov
14 years ago

  • Keywords has-patch added

#5 @c3mdigital
12 years ago

  • Keywords needs-refresh added

@c3mdigital
12 years ago

Refresh of original patch

#6 @c3mdigital
12 years ago

  • Keywords needs-refresh removed

#7 @SergeyBiryukov
12 years ago

  • Milestone changed from Awaiting Review to 3.7

#8 @desrosj
12 years ago

Patch worked fine for me. Was able to filter the link in both cases described.

#9 @jeremyfelt
12 years ago

Patch still applies cleanly in src. Would esc_url( admin_url() ) be overkill here?

#10 @nacin
12 years ago

+1 on the patch. esc_url() makes sense here — not for security concerns, but for the distinct possibility that the filtering of post-new.php would add an ampersand to it, and that should be encoded.

#11 @helen
12 years ago

  • Owner set to helen
  • Resolution set to fixed
  • Status changed from new to closed

In 25527:

Allow the "Add New" URL on post edit screens to be filtered via admin_url(). props SergeyBiryukov, jeremyfelt, c3mdigital. fixes #18504.

Note: See TracTickets for help on using tickets.