Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Remember preview url query params #129

Merged
merged 22 commits into from
Mar 10, 2017

Conversation

mohdsayed
Copy link
Contributor

@mohdsayed mohdsayed commented Mar 4, 2017

Fixes #107

@PatelUtkarsh PatelUtkarsh changed the title [WIP]Rememeber preview url query params [WIP]Remember preview url query params Mar 6, 2017
@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-0.9%) to 75.339% when pulling 6a44a47 on enhancement/remember-preview-url into 973480f on develop.

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-1.04%) to 75.24% when pulling 95e139b on enhancement/remember-preview-url into 973480f on develop.

@mohdsayed mohdsayed changed the title [WIP]Remember preview url query params Remember preview url query params Mar 6, 2017
@mohdsayed
Copy link
Contributor Author

Ready for review.

I am not sure if preg_match( '/[a-z|\[|\]|_|-|0-9]+/', $value ) would be the correct choice for validating the panel/section/control id , please suggest

@coveralls
Copy link

coveralls commented Mar 6, 2017

Coverage Status

Coverage decreased (-1.06%) to 75.226% when pulling 108c865 on enhancement/remember-preview-url into 973480f on develop.

@@ -226,6 +226,11 @@

api.previewer.query = function() {
var retval = originalQuery.apply( this, arguments );

if ( 'undefined' !== typeof CustomizerBrowserHistory ) {
retval.customize_preview_url_query_vars = JSON.stringify( CustomizerBrowserHistory.getQueryParams( location.href ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that Customizer Browser History should be made a dependency for this feature.

This can be replaced with:

retval.customize_preview_url_query_vars = wp.customize.utils.parseQueryString( location.search.substr( 1 ) );

though on 4.6 a polyfill for wp.customize.utils.parseQueryString would be needed.

@@ -966,6 +966,11 @@

api.previewer.query = function() {
var retval = originalQuery.apply( this, arguments );

if ( 'undefined' !== typeof CustomizerBrowserHistory ) {
retval.customize_preview_url_query_vars = JSON.stringify( CustomizerBrowserHistory.getQueryParams( location.href ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

$allowed_devices = array(
'mobile',
'desktop',
'tablet',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list needn't be hard-coded. You can use \WP_Customize_Manager::get_previewable_devices().

(
in_array( $param, $allowed_panel_section_control_params )
&&
preg_match( '/[a-z|\[|\]|_|-|0-9]+/', $value )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex seems to be missing the initial ^( and ending )$ if it is doing what I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The panel/sections/control ids can be like
post[post][1437]
title_tagline
blogname
nav_menu-61
postmeta[posttype][27450][keywords]

It doesn't follow any initial or ending pattern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the purpose to validate that the $param is a valid ID string? If you want to ensure that only the valid characters are included then you should do:

preg_match( '/^[a-z|\[|\]|_|-|0-9]+$/', $value )

Adding the ^ and $ anchors, as otherwise a user could supply an ID like: !@#$%^&*()title_tagline⁄€‹›fifl‡°·‚

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter I think I am not able to get it, Can you see this http://regexr.com/3ffv4 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably be \[a-z|\[|\]|_|\-|0-9]+\ ( escaped - sign ) but /^[a-z|\[|\]|_|-|0-9]+$/ doesn't match anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayedtaqui from that example, you can see that it is matching all of those strings, the last one incorrect.

Compare:

image

and

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it.

@@ -104,7 +104,8 @@ function hooks() {
add_action( 'admin_bar_menu', array( $this, 'remove_all_non_snapshot_admin_bar_links' ), 100000 );
add_action( 'wp_before_admin_bar_render', array( $this, 'print_admin_bar_styles' ) );
add_filter( 'removable_query_args', array( $this, 'filter_removable_query_args' ) );
add_action( 'save_post_customize_changeset', array( $this, 'create_initial_changeset_revision' ) );
add_action( 'save_post_' . $this->get_post_type(), array( $this, 'create_initial_changeset_revision' ) );
add_action( 'save_post_' . $this->get_post_type() , array( $this, 'save_customize_preview_url_query_vars' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra space before the comment here.

$preview_url_query_vars = array();

// If customizer browser history plugin is active.
if ( function_exists( 'customizer_browser_history_enqueue_scripts' ) && $post_id ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per above, I think Customizer Browser History shouldn't be made a dependency.

@coveralls
Copy link

coveralls commented Mar 8, 2017

Coverage Status

Coverage decreased (-0.9%) to 75.395% when pulling 1774137 on enhancement/remember-preview-url into 973480f on develop.

$preview_url_query_vars = array();

if ( $post_id ) {
$preview_url_query_vars = (array) get_post_meta( $post_id, '_preview_url_query_vars', true );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no postmeta on the changeset post, where get_post_meta() returns false, this will result in $preview_url_query_vars === array( false ).

So this should probably be:

$preview_url_query_vars = get_post_meta( $post_id, '_preview_url_query_vars', true );
if ( ! is_array( $preview_url_query_vars ) ) {
    $preview_url_query_vars = array();
}

@mohdsayed
Copy link
Contributor Author

Class 'PHPUnit_Framework_TestCase' not found in /tmp/wordpress/tests/phpunit/includes/testcase.

Not sure why the build is failing.

@westonruter
Copy link
Contributor

westonruter commented Mar 9, 2017

Not sure why the build is failing.

@sayedtaqui it looks like an issue with PHPUnit 6.0. I'm noticing the same thing locally after upgrading from 5.x.

See also WordPress/WordPress-Coding-Standards#870 (comment)

See also:

Looks like travis-ci just updated its PHP 7 images to use PHPUnit 6+, so our PHP 7 builds are failing. We should either fast-track #39822 or install + use and older version of PHPUnit in our travis script
https://wordpress.slack.com/archives/core/p1489073667330796

@westonruter westonruter force-pushed the enhancement/remember-preview-url branch from cccae03 to 83dc09f Compare March 10, 2017 00:22
@westonruter westonruter force-pushed the enhancement/remember-preview-url branch from 83dc09f to 4caa963 Compare March 10, 2017 00:30
@coveralls
Copy link

coveralls commented Mar 10, 2017

Coverage Status

Coverage decreased (-0.8%) to 75.479% when pulling 83dc09f on enhancement/remember-preview-url into 973480f on develop.

@coveralls
Copy link

coveralls commented Mar 10, 2017

Coverage Status

Coverage decreased (-0.8%) to 75.479% when pulling 4caa963 on enhancement/remember-preview-url into 973480f on develop.

@@ -104,7 +104,8 @@ function hooks() {
add_action( 'admin_bar_menu', array( $this, 'remove_all_non_snapshot_admin_bar_links' ), 100000 );
add_action( 'wp_before_admin_bar_render', array( $this, 'print_admin_bar_styles' ) );
add_filter( 'removable_query_args', array( $this, 'filter_removable_query_args' ) );
add_action( 'save_post_customize_changeset', array( $this, 'create_initial_changeset_revision' ) );
add_action( 'save_post_' . $this->get_post_type(), array( $this, 'create_initial_changeset_revision' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@westonruter westonruter added this to the 0.6.0 milestone Mar 10, 2017
@westonruter
Copy link
Contributor

@sayedtaqui Ready for merge after you give a final review of my tweaks.

@coveralls
Copy link

coveralls commented Mar 10, 2017

Coverage Status

Coverage decreased (-26.1%) to 50.176% when pulling f5b55cd on enhancement/remember-preview-url into 973480f on develop.

@coveralls
Copy link

coveralls commented Mar 10, 2017

Coverage Status

Coverage decreased (-26.1%) to 50.176% when pulling 6d9e9a9 on enhancement/remember-preview-url into 973480f on develop.

@coveralls
Copy link

coveralls commented Mar 10, 2017

Coverage Status

Coverage increased (+0.3%) to 76.554% when pulling 43bee5b on enhancement/remember-preview-url into 973480f on develop.

@mohdsayed
Copy link
Contributor Author

👍 Lets merge.

@westonruter westonruter merged commit 7f02238 into develop Mar 10, 2017
@valendesigns valendesigns deleted the enhancement/remember-preview-url branch August 23, 2017 01:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants