Fix lesson order being changed when saving lesson #3951
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3921
Changes proposed in this Pull Request
In analysing the problem that on single lesson save, the entire lesson order can be changed, I found that the php usort function changes the lesson order when all lessons return a 0 value.
Note: The entry with value 0 is the result of the way $order is filled from the (empty) $order_string parameter in
Sensei_Admin->save_lesson_order()
.$order = array_map( 'absint', explode( ',', $order_string ) );
In those cases the lesson order will already be sorted correctly and the intention of the callback function used in this method is to leave the structure unaffected.
This PR just makes the usort-call conditional so it skips sorting when there is nothing to sort ( e.g. $order equals [0] ).
Testing instructions
New/Updated Hooks
Deprecated Code
Screenshot / Video