Welcome to Blog – iRedlof

Random Post Refresh

Best Traffic Day Ever

Just a perfect day i have been looking for from a long-long time. Last 2 days have been the best days of my life concerning iRedlof....
Read More ...
Help

If you need any help, leave a comment here or mail me »

Member Login
Not a member yet? Sign Up!

Math Required!
What is the sum of: 8 + 4    

Forgot Password !

Powered by

10

Jun

2009

How To De-Activate Wordpress Plugin Using PHP Code

By admin. Posted in Wordpress

2 Comments »   |   Share   |  


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):

[php]<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>[/php]

Code Description With Line Nos.:

  1. We have a form with post method with action back on same requesting page.
  2. Showing Warning Message
  3. Submit Button to trigger form action with name=id=”iRUninstall”.
  4. 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.

[php]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’);
}[/php]

Code Description With Line Nos.:

  1. We check for ‘iRUninstall’ value from previous form code, if it is set (that form is submitted) then the code in brackets will execute.
  2. 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)
  3. Get the list of currently active plugins using ‘active_plugins’ row in options table of wordpress.
  4. Search for our plugin in the above list
    ( Note: $_POST['plugin']=”iredlof_ajax_login/iredlof_ajax_login.php” ) and disable it.
  5. Save ‘active_plugins’ option back to db. (Plugin Disabled)
  6. Redirect to plugins page of wordpress and show plugin disabled message.

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)

admin Email this author | All posts by admin | Subscribe to Entries (RSS)

 

2 Responses to “How To De-Activate Wordpress Plugin Using PHP Code”

  1. 1
    Daily Digest for August 16th | More Than Scratch The Surface Says:

    [...] Shared Blog – iRedlof |  How To De-Activate Wordpress Plugin Using PHP Code 0 [...]

  2. 2
    catfish86 Says:

    Thank you for that.

    -catfish

    UN:F [1.8.4_1055]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.4_1055]
    Rating: 0 (from 0 votes)
 

Leave a Reply

You must be logged in to post a comment.

You can buy xeloda here