Title: can_i_read function returns true for draft post
Last modified: April 5, 2024

---

# can_i_read function returns true for draft post

 *  Resolved [Antony Booker](https://wordpress.org/support/users/antonynz/)
 * (@antonynz)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/can_i_read-function-returns-true-for-draft-post/)
 * I’m using a search plugin which hooks into Simple membership with the code below
   to determine if a page should be shown in the results or not.
 * However the can_i_read function in Simple membership is returning true for posts
   that are in a draft / private status which results in them showing in search 
   results.
 *     ```wp-block-code
       $access_ctrl = SwpmAccessControl::get_instance();
       $post        = get_post( $post_id );
       $post_ok     = $access_ctrl->can_i_read_post( $post );
       ```
   
 * Would this be the appropriate code to test if SM allows access to a page?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Support [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/can_i_read-function-returns-true-for-draft-post/#post-17557244)
 * Thank you for reaching out to us.
 * Sorry but any custom coding related stuff needs to be handled as a custom development
   job so dedicated time can be allocated by the developer and a proper response
   can be given. Otherwise, we won’t be able to really investigate the requirement
   and check the code then respond with a solution.
 * You can use the following contact form to get in contact with us.
 * [https://simple-membership-plugin.com/contact/](https://simple-membership-plugin.com/contact/)
 * Kind regards.
 *  Thread Starter [Antony Booker](https://wordpress.org/support/users/antonynz/)
 * (@antonynz)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/can_i_read-function-returns-true-for-draft-post/#post-17557263)
 * Sorry for the confusion. I’m not requesting any custom code as I can code this
   per site. But hopefully it will be possible to get this plugin compatible with
   the relevanssi search plugin in general for other sites.
 * Currently when both plugins are installed draft statuses show in search results
   due to how the relevanssi plugin checks if a user can access a post in Simple
   Membership using the can_i_read_post function. 
   Other membership plugins have
   similar filters to check if a user should have access to a post that isn’t in
   a draft/private status, however using the can_i_read_post it doesn’t check if
   a post is published or not. Should the can_i_read_post function be set to check
   that?I have reached out to Relevanssi regarding this but they couldn’t say why
   the SM plugin did this. If this isn’t a suitable filter to use in general for
   other plugins I can reach out to Relevanssi again to recommend they change their
   code to prevent draft posts showing in search results.
 *  Plugin Support [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/can_i_read-function-returns-true-for-draft-post/#post-17558258)
 * Thank you for clarifying your question further. Currently we have the following
   filters and hooks available. Please check them and let me know if they help you
   in any way.
 * Filter hooks = [https://simple-membership-plugin.com/simple-membership-filter-hook-reference/](https://simple-membership-plugin.com/simple-membership-filter-hook-reference/)
 * Action hooks = [https://simple-membership-plugin.com/simple-membership-action-hook-reference/](https://simple-membership-plugin.com/simple-membership-action-hook-reference/)
 * Kind regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘can_i_read function returns true for draft post’ is closed to new replies.

 * ![](https://ps.w.org/simple-membership/assets/icon-128x128.png?rev=974529)
 * [Simple Membership](https://wordpress.org/plugins/simple-membership/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-membership/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-membership/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-membership/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-membership/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-membership/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * Last activity: [2 years, 2 months ago](https://wordpress.org/support/topic/can_i_read-function-returns-true-for-draft-post/#post-17558258)
 * Status: resolved