Providing your wordpress plugin users with smart n easy interface and functionality has always been difficult for wordpress developers.
Topic Covered:
In this tutorial, We will learn – How to de-activate a wordpress plugin using a php code within the plugin itself.
Basic Question:
Why would someone be interested in providing such a functionality in their plugin when such a feature is already available on wordpress Plugin page.
The reason for above functionality can be illustrated by considering a situation in which you have a plugin using an additional new database table to store data regarding your plugin or it uses any new entry in Options table in your wordpress.
Now you are providing your user with uninstaller, which will delete all those tables, etc when user is not interested in using your plugin anymore.
Interface is always been addition of small – small functionality which remove the burden off your users.
Such a small functionality is de-activating the plugin automatically when user clicks on uninstall.
How to Code This in Your WordPress Plugin:
Your Uninstall function should have a Form with Post Method like this (Plus additional fields according to your need):
<form action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
<p style="color:#F00">Warning! This will delete this plugin`s settings and will De-activate the plugin.</p>
<input type="submit" id="iRUninstall" name="iRUninstall" class="button-primary" value="Uninstall" />
<p><input type="hidden" name="plugin" id="plugin" value="iredlof_ajax_login/iredlof_ajax_login.php" /></p>
</form>
Code Description With Line Nos.:
We have a form with post method with action back on same requesting page.
Showing Warning Message
Submit Button to trigger form action with name=id=”iRUninstall”.
Hidden input field with name=id=”plugin” and value=”iredlof_ajax_login/iredlof_ajax_login.php” which is your plugin foldername/filename ( Note: Take care of all the values indicated here. )
Now, The following code should also be in the same file with above code, Because we are passing all field`s values to the same requesting file.
We check for ”iRUninstall” value from previous form code, if it is set (that form is submitted) then the code in brackets will execute.
Here we are deleting Options row in database which we created to store our plugin`s data previously in plugin. (Change ”iredlof_atp_options” according to your needs)
Get the list of currently active plugins using ”active_plugins” row in options table of wordpress.
Search for our plugin in the above list
( Note: $_POST[''plugin'']=”iredlof_ajax_login/iredlof_ajax_login.php” ) and disable it.
Save ”active_plugins” option back to db. (Plugin Disabled)
Redirect to plugins page of wordpress and show plugin disabled message.
VN:F [1.9.3_1094]
please wait...
Rating: 1.5/10 (2 votes cast)
VN:F [1.9.3_1094]
Rating: -1 (from 1 vote)
How To De-Activate WordPress Plugin Using PHP Code, 1.5 out of 10 based on 2 ratings
How To De-Activate WordPress Plugin Using PHP Code
Providing your wordpress plugin users with smart n easy interface and functionality has always been difficult for wordpress developers.
Topic Covered:
In this tutorial, We will learn – How to de-activate a wordpress plugin using a php code within the plugin itself.
Basic Question:
Why would someone be interested in providing such a functionality in their plugin when such a feature is already available on wordpress Plugin page.
The reason for above functionality can be illustrated by considering a situation in which you have a plugin using an additional new database table to store data regarding your plugin or it uses any new entry in Options table in your wordpress.
Now you are providing your user with uninstaller, which will delete all those tables, etc when user is not interested in using your plugin anymore.
Interface is always been addition of small – small functionality which remove the burden off your users.
Such a small functionality is de-activating the plugin automatically when user clicks on uninstall.
How to Code This in Your WordPress Plugin:
Your Uninstall function should have a Form with Post Method like this (Plus additional fields according to your need):
Code Description With Line Nos.:
Now, The following code should also be in the same file with above code, Because we are passing all field`s values to the same requesting file.
if ( isset($_POST["iRUninstall"] )){ deleteOptions("iredlof_atp_options"); $current = get_settings(''active_plugins''); array_splice($current, array_search( $_POST[''plugin''], $current), 1 ); // Array-function! update_option(''active_plugins'', $current); header(''Location: plugins.php?deactivate=true''); }Code Description With Line Nos.:
( Note: $_POST[''plugin'']=”iredlof_ajax_login/iredlof_ajax_login.php” ) and disable it.