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

Issue #17 : Enable deleting settings in snapshot wp-admin/post page. #84

Merged
merged 16 commits into from
Oct 20, 2016

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Aug 24, 2016

Request For Code Review

Hi @westonruter,
Could you please review this pull request for Issue #17?

Ryan Kienstra added 4 commits August 24, 2016 05:31
Create link 'Remove setting,' which toggles to 'Restore setting' on click.
It also sets a hidden text field for each setting to be removed.
On saving, these appear in [ 'customize_snapshot_remove_settings' ].
Filter post content  on 'content_save_pre,' when this is saved.
If  has settings to be removed, filter them out.
Also, add simple styling of this 'Remove setting' link.
It appears red when setto 'remove,' and blue when set to 'restore.'
Before evaluating ->post_type, pass it to isset().
Short-circuit the conditional if it's not set.
&&
wp_verify_nonce( $_REQUEST[ static::SLUG ], static::SLUG . '_settings' )
&&
! ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be using the new wp_doing_ajax function if it is available, so this can be replaced with:

! ( function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )

This will likely yield benefits for doing unit testing without having to be in a separate Ajax unit test, since the return value of wp_doing_ajax() can be filtered as opposed to being a fixed constant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops. 😊 I misread the constant here. Nevermind 😄

}

$setting_ids_to_unset = $_REQUEST[ $key_for_settings ];
$data = json_decode( $post->post_content );
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of getting $post->post_content should it not be using the $content that is already provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. This commit corrects that.

@coveralls
Copy link

coveralls commented Aug 28, 2016

Coverage Status

Coverage decreased (-0.8%) to 90.191% when pulling 625ff99 on feature/allow-deleting-settings into 7d1e373 on develop.

.addClass( 'snapshot-setting-removed' );
};

this.constructHiddenInputWithValue = function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Better for this function to be more of a pure function that doesn't rely on its closure scope. So it can be at the top level as component.constructHiddenInputWithValue() and it can take a settingId as its argument. It is much easier to test the function like this, and there is only ever one copy, whereas here there is a copy for each time the user clicks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this commit moves constructHiddenInputWithValue into the component object.

@westonruter
Copy link
Contributor

@kienstra the functionality works well! Beyond my inline feedback, something else that should be done is a unit test on filter_out_settings_if_removed_in_metabox.

Instead of attaching methods to 'on' event handler,
Attach them to module-scope components object.
Haven't yet implemented a way to export them, as Weston suggested.
@coveralls
Copy link

coveralls commented Sep 3, 2016

Coverage Status

Coverage decreased (-0.8%) to 90.18% when pulling 83ad0e9 on feature/allow-deleting-settings into 7d1e373 on develop.

Using Weston's snippet, output link title in PHP, with localization.
And attach localized text 'Restore settting' to the link's data-text-restore attribute.
On clicking the link, call method changeLinkText.
This toggles the title to the other value stored in the data attribute.
And stores the old title in the data attribute, for the next time it's clicked.
@coveralls
Copy link

coveralls commented Sep 3, 2016

Coverage Status

Coverage decreased (-0.8%) to 90.18% when pulling 35d5bca on feature/allow-deleting-settings into 7d1e373 on develop.

At Weston's suggestion, pass second argument to json_decode.
This will then return an array, instead of an object.
So access the array value with $data[ $setting_id ].
Instead of previous object access with $data->{ $setting_id }.
@coveralls
Copy link

coveralls commented Sep 3, 2016

Coverage Status

Coverage decreased (-0.8%) to 90.18% when pulling 92f14c0 on feature/allow-deleting-settings into 7d1e373 on develop.

…tent.

Also, wp_unslash() the $content.
Otherwise, the json_decode function will return null.
@coveralls
Copy link

coveralls commented Sep 3, 2016

Coverage Status

Coverage decreased (-0.8%) to 90.18% when pulling f76b4a6 on feature/allow-deleting-settings into 7d1e373 on develop.

Before iterating through the settings to unset,
Ensure that the settings are in an array, as expected.
@coveralls
Copy link

coveralls commented Sep 4, 2016

Coverage Status

Coverage decreased (-0.8%) to 90.189% when pulling d1487c8 on feature/allow-deleting-settings into 7d1e373 on develop.

@coveralls
Copy link

coveralls commented Sep 4, 2016

Coverage Status

Coverage decreased (-0.8%) to 90.189% when pulling 68fa5ae on feature/allow-deleting-settings into 7d1e373 on develop.

@kienstra
Copy link
Contributor Author

kienstra commented Sep 6, 2016

Thanks For Waiting
I Still Need To Write PHPUnit Tests

Hi @westonruter,
Sorry for the delay in applying your feedback here. I addressed all of your comments above, but I still need to write PHPUnit tests.

@PatelUtkarsh PatelUtkarsh mentioned this pull request Sep 16, 2016
3 tasks
@westonruter
Copy link
Contributor

@kienstra no apology will be accepted! It is I who probably should apologize for being slow to review PRs 😞

@@ -360,6 +362,7 @@ public function render_data_metabox( $post ) {
echo '<li>';
echo '<details open>';
echo '<summary><code>' . esc_html( $setting_id ) . '</code> ';
echo '<a href="#" id="' . esc_attr( $setting_id ) . '" data-text-restore="' . esc_attr( 'Restore setting', 'customize-snapshots' ) . '" class="snapshot-toggle-setting-removal remove">' . esc_html( 'Remove setting', 'customize-snapshots' ) . '</a>';
Copy link
Member

Choose a reason for hiding this comment

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

Use translation function esc_attr__ and esc_html__ instade of esc_attr( 'Restore setting', 'customize-snapshots' ) and esc_html( 'Remove setting', 'customize-snapshots' )

@PatelUtkarsh
Copy link
Member

In e5accee I've resolved conflict with develop.

@coveralls
Copy link

coveralls commented Oct 12, 2016

Coverage Status

Coverage decreased (-0.7%) to 90.085% when pulling e5accee on feature/allow-deleting-settings into 59b8b66 on develop.

@PatelUtkarsh
Copy link
Member

I am picking this up as discussed with @jeffpaul and @kienstra.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 90.593% when pulling 8f29076 on feature/allow-deleting-settings into 59b8b66 on develop.

@coveralls
Copy link

coveralls commented Oct 20, 2016

Coverage Status

Coverage decreased (-0.2%) to 90.593% when pulling 88a83de on feature/allow-deleting-settings into 59b8b66 on develop.

@westonruter westonruter merged commit 5900671 into develop Oct 20, 2016
@westonruter westonruter deleted the feature/allow-deleting-settings branch October 20, 2016 00:22
@westonruter westonruter modified the milestone: 0.6.0 Jul 6, 2017
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.

4 participants