Make WordPress Core

Opened 8 years ago

Last modified 3 years ago

#36582 assigned enhancement

Export main query from Customizer preview

Reported by: westonruter's profile westonruter Owned by:
Milestone: Future Release Priority: low
Severity: normal Version: 4.0
Component: Customize Keywords: needs-patch
Focuses: javascript Cc:

Description (last modified by westonruter)

Controls, sections, and panels in the Customizer support the concept of an active state (#27993) which controls whether or not the control is contextual to the current query. Controls may want more information than whether to hide/show, but to show contextual information based on which kind of query is loaded in the Customizer preview, such as if it is_singular or which post specifically was queried. This information should be exposed from the Customizer preview to the pane as well.

An initial implementation of this has been implemented in the Customize Posts feature plugin: https://github.com/xwp/wp-customize-posts

When the preview syncs the WP_Query data from the preview to the pane, the data should get sent along with the ready message along with the activeControls, activeSections, and activePanels data. When the data is received by the pane, it should get populated into a model which can have events attached to it. For example, a wp.customize.Values instance could be used as a collection to represent the query_vars. Or there could be one single wp.customize.Value that stores the exported WP_Query data in like wp.customize.previewedQuery which plugins could then listen to changes on. For example:

wp.customize.previewedQuery.bind( function( newQuery, oldQuery ) {
    if ( newQuery.is_singular !== oldQuery.is_singular ) {
        if ( newQuery.is_singular ) {
            // We switched to a singular template!
        } else {
            // We switched to a non-singular template!
        }
    }
} );

Some thought will need to be given to how a JavaScript object is used to represent WP_Query.

See Slack: https://wordpress.slack.com/archives/core-customize/p1461011732000103

Change History (12)

#1 @westonruter
8 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.


8 years ago

#3 @westonruter
8 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


8 years ago

#5 @chriscct7
8 years ago

  • Owner set to westonruter
  • Status changed from new to assigned

This ticket was mentioned in Slack in #core by voldemortensen. View the logs.


8 years ago

#7 @voldemortensen
8 years ago

  • Milestone changed from 4.6 to Future Release

Punting for now, if a patch comes forth before the deadline it can definitely be moved back to the milestone.

#8 @westonruter
8 years ago

  • Milestone changed from Future Release to 4.7

This ticket was mentioned in Slack in #core by jorbin. View the logs.


8 years ago

This ticket was mentioned in Slack in #core-customize by celloexpressions. View the logs.


7 years ago

#11 @celloexpressions
7 years ago

  • Milestone changed from 4.7 to Future Release

Plugins such as customize posts can implement this in the meantime as needed.

#12 @celloexpressions
3 years ago

  • Focuses javascript added
  • Keywords needs-patch added
  • Milestone set to Future Release
  • Owner westonruter deleted
  • Priority changed from normal to low
  • Version set to 4.0

This would be a nice improvement to the customize API but appears to be generally low-impact for users since the occasional plugin that needs this can implement the fix.

Note: See TracTickets for help on using tickets.