isEnabled check does not accurately target correct post object
-
Hi,
The current version of the plugin has a bug in the ProtectTheChildren_Helpers::isEnabled() function that causes the code to target the wrong post object when certain conditions are met.
The error is most visible under these conditions:
- Create a password protected page, enable Protect the Children on it and then set the Parent for this new page to an existing page.
- Ensure WP_DEBUG is enabled and output is visible
- View the front end page
- Observe a PHP Notice is shown: <b>Notice</b>: Trying to get property ‘ID’ of non-object in <b>/Users/adamtaylor/Sites/whs-wp/wp-content/plugins/protect-the-children/_inc/helpers.php</b> on line <b>57</b>
This is caused because the plugin checks the new pages ancestors and does not find a password protected ancestor among them.
Tracking this error back, it appears to be because a conditional statement is allowed to fall through in the isEnabled function mentioned earlier.
In that function the passed $post argument is handled differently if an array of post IDs is passed, i.e. the return value from get_post_ancestors(). However, if that check fails to find a password protected ancestor, the foreach loop never returns a value and therefore the code falls through to the second if statement (line 39) that cannot handle being passed an array.
There are 2 possible fixes for this issue.
You can either add a ‘return false;’ after the foreach loop finishes, or use an elseif on line 39 to ensure it is only executed for non-array arguments.
I’ve prepared a patch (I hope correctly!) adding the ‘return false;’ line which can be seen here:
Patch ataylor-isEnabledThanks,
Adam
- The topic ‘isEnabled check does not accurately target correct post object’ is closed to new replies.