WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#28505 closed enhancement (worksforme)

Allow button manipulation in `get_sample_permalink_html()`

Reported by: ericmann Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch
Focuses: administration Cc:

Description

Currently, default buttons (Edit, View {Post Type}, Get Shortlink) are added directly as html strings within the get_sample_permalink_html filter. This makes it highly difficult for developers to re-order, remove, or otherwise manipulate these buttons.

I propose adding a new filter within the get_sample_permalink_html() function that builds these extra buttons as an array, allowing plugins/themes to hook in and manipulate them cleanly before they're converted to a long HTML string.

Attachments (3)

sample-permalink.patch (2.1 KB) - added by ericmann 4 years ago.
Converts HTML concatenation to first a filterable array. Also adds brackets around one-line conditionals to stay inline with WP coding standards.
sample-permalink.2.patch (3.7 KB) - added by lkwdwrd 4 years ago.
Adds filtering to the buttons array for both default permalinks and pretty permalinks.
28505.diff (5.1 KB) - added by ericmann 4 years ago.
Break the buttons out into a separate action (for edit-slug-buttons) and filter the array there instead of forcing things into the sample permalink html.

Download all attachments as: .zip

Change History (13)

@ericmann
4 years ago

Converts HTML concatenation to first a filterable array. Also adds brackets around one-line conditionals to stay inline with WP coding standards.

This ticket was mentioned in IRC in #wordpress-dev by ericmann. View the logs.


4 years ago

#2 @helen
4 years ago

  • Milestone changed from Awaiting Review to 4.0

Sounds good to me, have needed this in the past and present. Patch looks good at a glance, but somebody other than ericmann should probably actually apply and test it first. :)

#3 @lkwdwrd
4 years ago

The original patch only allows filtering the buttons if the default permalink structure is chosen. In most cases I would want this filter regardless of permalink structure. The get_sample_permalink_html filter is applied to both cases, it stands to reason that the get_sample_permalink_buttons would as well.

@lkwdwrd
4 years ago

Adds filtering to the buttons array for both default permalinks and pretty permalinks.

#4 follow-up: @DrewAPicture
4 years ago

  • Keywords needs-patch added

This looks like a pretty good start, though there's still a bit of work to do here.

For instance, the 'Get Shortlink' button is actually appended to the end of the get_sample_permalink_html() output in edit-form-advanced.php. So I'd suggest bringing that logic into get_sample_permalink_html() so the button is included with the filter.

Also, this is just a readability nitpick, but the multi-conditional and subsequent link buttons string, could probably be broken up into multiple lines, a la:

<?php
if ( '' == get_option( 'permalink_structure' )
        && current_user_can( 'manage_options' )
        && ! ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
) {
        $link_buttons['change-permalinks']  = '<span id="change-permalinks">';
        $link_buttons['change-permalinks'] .= '<a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . '</a>';
        $link_buttons['change-permalinks'] .= "</span>\n";
}

Last, not sure what if any concerns the accessibility team might have with keeping or removing the target=blank on that link, either. Seems like lately we've been in the habit of removing blank targets on links in the back-end.

#5 @nacin
4 years ago

See 7:ticket:22980, #16477, #16478. I'm not convinced of an particular approach here. Whatever we do, it should not be shoved inside get_sample_permalink_html().

@ericmann
4 years ago

Break the buttons out into a separate action (for edit-slug-buttons) and filter the array there instead of forcing things into the sample permalink html.

#6 @lkwdwrd
4 years ago

The new patch looks sensible to me. I'll try to apply this sooner than later to test it.

#7 in reply to: ↑ 4 @sharonaustin
4 years ago

Replying to DrewAPicture:

Last, not sure what if any concerns the accessibility team might have with keeping or removing the target=blank on that link, either. Seems like lately we've been in the habit of removing blank targets on links in the back-end.<

Hi, we really appreciate the accessibility considerations! target=blank is indeed problematic for accessibility, so a change to that would be welcome. Thanks so much!

#8 @helen
4 years ago

  • Milestone changed from 4.0 to Future Release

#9 @iseulde
3 years ago

  • Keywords has-patch added; needs-patch removed
  • Version 3.9.1 deleted

#10 @swissspidy
3 years ago

  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from new to closed

As of 4.4, there are no buttons anymore next to the permalink. Instead, the permalink was made clickable. See #18306

Note: See TracTickets for help on using tickets.