[wp-trac] [WordPress Trac] #32766: customize_register fires twice, cannot pass query args properly
WordPress Trac
noreply at wordpress.org
Tue Aug 25 00:12:18 UTC 2015
#32766: customize_register fires twice, cannot pass query args properly
-------------------------------+------------------------------
Reporter: eherman24 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version: 4.2.2
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses: administration
-------------------------------+------------------------------
Changes (by westonruter):
* keywords: => reporter-feedback
Comment:
The `customize_register` action fires in the admin for the Customizer pane
(`customize.php`); the second time it fires it is in the context of the
Customizer preview, which is in the frontend.
So even if you load the Customizer via `customize.php?foo=bar`, then this
`$_GET['foo']` variable will always be empty in the context of the
`customize_register` that happens in the preview.
So what you need to do is ensure that query params passed into the
Customizer also get amended to any URL being previewed. You should be able
to accomplish this with some plugin JS like the following that runs in
`customize.php`:
{{{#!js
wp.customize.bind( 'ready', function () {
var oldValidate = wp.customize.previewer.previewUrl.validate;
wp.customize.previewer.previewUrl.validate = function ( url ) {
url = oldValidate.call( this, url );
if ( url && location.search.length > 1 ) {
url = url.replace( /#.*/, '' ); // Remove URL
fragment
if ( -1 === url.indexOf( '?' ) ) {
url += '?'; // Make sure query string is
provided
}
url += '&' + location.search.substr( 1 ); //
Append query args from customize.php
}
return url;
};
} );
}}}
If this is roughly what you're looking for, please close this ticket as
it's not a Core bug and a different forum should be used for hashing
through this.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32766#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list