Disabling ‘Take Over Post’ Button
-
For a long time I’ve used a snippet of code in custom plugin that disables the “Take Over Post” button for all users except Admins, it recently caused a fatal error (I think after updating WP to a minor version update) and the theory I have based on reading very old posts here and on StackExchange is that the function I’m using was moved and is now loading *after* my code instead of before as previously, so I need some help fixing this so it will work again.
Current WP version on the site where I am having this problem is 5.2.3
Here’s what I’ve used that worked perfectly in the past:if(is_admin()) { if ( !current_user_can('update_core') ) { add_filter( 'override_post_lock', create_function("", 'return false;' )); } }
The error I now get is this:
Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in …
…followed by a list of core files and my plugin.
While I believe I can wrap it in another if statement to test if current_user_can exists (yet) as a function, which would eliminate the error, I don’t know how to then have the code run or to load the dependent function first, because I also read on StackExchange that calling the necessary file using require_once (before WP wants to load it) can introduce security vulnerabilities.
So how can I maintain security and let WP load in its preferred order, and still block all users except Admins from the ability to take over a post from someone else who is editing it?
- The topic ‘Disabling ‘Take Over Post’ Button’ is closed to new replies.