-
Notifications
You must be signed in to change notification settings - Fork 11
Issue #17 : Enable deleting settings in snapshot wp-admin/post page. #84
Conversation
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 ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
… into feature/allow-deleting-settings
} | ||
|
||
$setting_ids_to_unset = $_REQUEST[ $key_for_settings ]; | ||
$data = json_decode( $post->post_content ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
.addClass( 'snapshot-setting-removed' ); | ||
}; | ||
|
||
this.constructHiddenInputWithValue = function() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@kienstra the functionality works well! Beyond my inline feedback, something else that should be done is a unit test on |
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.
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.
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 }.
…tent. Also, wp_unslash() the $content. Otherwise, the json_decode function will return null.
Before iterating through the settings to unset, Ensure that the settings are in an array, as expected.
Thanks For Waiting Hi @westonruter, |
@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>'; |
There was a problem hiding this comment.
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' )
In e5accee I've resolved conflict with develop. |
Request For Code Review
Hi @westonruter,
Could you please review this pull request for Issue #17?
'Remove setting'
, which toggles to'Restore setting'
on click.It also sets a hidden input field for each setting to be removed.
On saving, these appear in
$_REQUEST[ 'customize_snapshot_remove_settings' ]
.Filter post content on content_save_pre when this is saved.
If
$_REQUEST
has settings to be removed, filter them out.Also, add simple styling of this 'Remove setting' link.
It appears red when it has the text "Remove setting, and blue otherwise.