Automattic / ad-code-manager

Easily manage the ad codes that need to appear in your templates
https://wordpress.org/plugins/ad-code-manager/
GNU General Public License v2.0
117 stars 51 forks source link

Check post type of the received post ID before deletion #140

Closed rbcorrales closed 2 years ago

rbcorrales commented 2 years ago

Validate that the post type of the received post ID matches acm-code before attempting a deletion to prevent deleting other types of posts.

This function gets called when deleting a single ad code or doing a bulk deletion.

GaryJones commented 2 years ago

Logic looks sound, but it would be good to try and get an integration test added for this deletion, to show that it is working correctly.

GaryJones commented 2 years ago

The test is relatively simple - create a generic post post, and an ad-code ad, and then try to delete both of them - one will succeed with this patch in place, and will fail (returns null from the delete method).

Before (with the fix not applied):

Screenshot 2022-03-15 at 22 01 37

After (with the fix applied):

Screenshot 2022-03-15 at 22 02 08