WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#39631 closed defect (bug) (invalid)

Pagination prepareLinkPreview() Changesets Customizer

Reported by: nwp_developer Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: Customize Keywords: reporter-feedback
Focuses: javascript, administration Cc:

Description

With the introduction of changesets and disabling external links, pagination urls no longer work in customizer.

In wp-includes>customize-preview.js>prepareLinkPreview() links are detected to alter the href and target _self. Can we add a condition into prepareLinkPreview() that excludes pagination since it's not an external link?

Attachments (1)

working-pagination.mov (5.9 MB) - added by westonruter 4 years ago.

Change History (6)

#1 follow-up: @westonruter
4 years ago

  • Keywords reporter-feedback added
  • Version changed from 4.7.1 to 4.7

@nwp_developer can you clarify what you mean by pagination? Please also give examples.

#2 in reply to: ↑ 1 @nwp_developer
4 years ago

Most sites use paginate_links() for blog home pagination like below

<<Previous [1][2][3] Next>>

See https://codex.wordpress.org/Function_Reference/paginate_links.

However, with the introduction of changesets and disabling external links, the pagination links have their url changed to a changeset url. This prevents previewing blog excerpts in customizer. Since blog pagination is linking internally in the site it should be excluded from prepareLinkPreview(). The only exclusions are admin bar, #, #id.

// Skip links in admin bar.
if ( $( element ).closest( '#wpadminbar' ).length ) {
	return;
}

// Ignore links with href="#" or href="#id".
if ( '#' === $( element ).attr( 'href' ).substr( 0, 1 ) ) {
	return;
} 

Replying to westonruter:

@nwp_developer can you clarify what you mean by pagination? Please also give examples.

#3 follow-up: @westonruter
4 years ago

@nwp_developer I can't reproduce the issue you are describing. See working-pagination.mov.

#4 in reply to: ↑ 3 @nwp_developer
4 years ago

It looks like an issue with the base arg paginate_links(). If you have

<?php
echo paginate_links(array(
    'base'   => get_page_num_link(1) . '%_%', 
    'format' => 'page/%#%',
));

get_page_num_link(1) returns the base page url and %_% is replaced with format. The result is http://mysite.com/blog/page/1/. In customizer the changeset url gets injected between blog and page so the url becomes http://mysite.com/blog/customize_changesetpage_uuid{etc}/page/1/.

If I use

<?php
 $big = 999999999; 
 $pagination_args = array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format'          => 'page/%#%',

The url doesn't get split by the customizer changeset.

Replying to westonruter:

@nwp_developer I can't reproduce the issue you are describing. See working-pagination.mov.

#5 @westonruter
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

@nwp_developer This doesn't seem to be a problem with the customizer but rather is a problem with how you are using get_pagenum_link(). Since it returns a URL which may have a query component, then to me it seems you need to account for this in where you decide to inject %_%. Here's one possible solution:

<?php
$base = get_pagenum_link( 1, false );
$parsed_base_url = parse_url( $base );
$parsed_base_url['path'] .= '%_%';
$base_url = $parsed_base_url['scheme'] . '://' . $parsed_base_url['host'] . trailingslashit( $parsed_base_url['path'] );
if ( ! empty( $parsed_base_url['query'] ) ) {
        $base_url .= '?' . $parsed_base_url['query'];
}
echo paginate_links( array(
        'base' => $base_url,
        'format' => 'page/%#%',
) );
Note: See TracTickets for help on using tickets.