Problem deactivating plugins

I know the problem is coming from the deactivate function in our plugin. But I can't figure out why and how to correct it.

This is the function:
/* plugin deactivating */
function ourprofiles_deactivate() {
    if ( !current_user_can( 'activate_plugins' ) )
    $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
    check_admin_referer( "deactivate-plugin_{$plugin}" );

//    delete_option('ourprofiles_links');

register_deactivation_hook( __FILE__, 'ourprofiles_deactivate' );

Open in new window

What happens is if you try to deactivate one or more additional plugins at the same time as this one - that function for some reason is causing wordpress to ask "Are you sure you want to do this?" and of course it doesn't even have a submit button to continue, so you can't complete the deactivation.
If you deactivate it alone it works fine. I assume it must be something with the delete_option lines because the rest of the code is standard from wordpress documentation.

Those two option names are correct and are automatically added in the database upon activation. So it can't be getting tripped up because of missing options.

Any ideas on why this is happening?
LVL 15
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Avinash ZalaWeb ExpertCommented:
What happen if you remove lines of delete_option?

As per my suggestion and general practice I would delete my saved option values when plugin is being deleted/uninstalled and not being deactivated.

Hook link is available here:

Let me know how that goes?
DzynitAuthor Commented:
If I remove the delete option lines it has the same error.
DzynitAuthor Commented:
ok, on line 5 of the above code - the $plugin variable is empty when one or more additional plugins are deactivated along with this one.

Is this line 6 necessary because that's where it's failing since $plugin is blank? :
    check_admin_referer( "deactivate-plugin_{$plugin}" );
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Avinash ZalaWeb ExpertCommented:
try using  wp_verify_nonce function instead
DzynitAuthor Commented:
I'm not sure I understand how that will help. Is it necessary to have any type of checks there during the deactivate function (or activate function).

Those functions are only fired when the plugin is activated or deactivated so I'm kind of confused as to the check_admin_referer or switching and trying wp_verify_nonce is needed for.

I could just remove that line completely, but I don't want to do that if it's important.
DzynitAuthor Commented:
Are there any thoughts on if it matters if I just completely remove that check_admin_referer( "deactivate-plugin_{$plugin}" ); line?

I want to get this question finished, but I'll leave it till the end of today to see if any one can answer that.
Avinash ZalaWeb ExpertCommented:
Well that line is just to verify that request is correct and valid. It has nothing to do with deactivation of plugin. So removing that line will work for you as well. That line makes sure that this process will not perform if referrer is not identified.

That's it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.