Make WordPress Core

Ticket #5625: wp-includes_plugin.php.diff

File wp-includes_plugin.php.diff, 2.3 KB (added by arickmann, 17 years ago)

Plugin functions from wp-includes/plugin.php

  • plugin.php

     
    593593                return $function[0].$function[1];
    594594}
    595595
    596 ?>
     596/**
     597* register_plugin_assets() Add the plugin's database tables and option names as assets so they can be removed later.
     598*
     599* Part of the uninstall process.
     600* When a plugin activates, and creates the database tables, and WordPress options it needs to run the plugin author
     601* can register those database tables and WordPress options so that they will be removed when the plugin is uninstalled.
     602* A callback can also be registered to handle more complex uninstall requirements.
     603*
     604* Note: This does not allow files to be registered as there is danger of getting paths wrong and removing
     605* similarly named files in different paths.
     606*
     607* @link http://trac.wordpress.org/ticket/5625
     608*
     609* @param string $plugin_file the path to the plugin file, usually given by __FILE__
     610* @param string|array $callback function name of the plugin's uninstaller, can be NULL
     611* @param array $tables array of table names that should be dropped when the plugin is uninstalled
     612* @param array $options array of option names that should be deleted when the plugin is uninstalled
     613*
     614*/
     615function register_plugin_assets( $plugin_file , $callback , $tables = array() , $options = array() ) {
     616        $plugin_assets = get_option( 'plugin_assets' );
     617        if ( !is_array( $plugin_assets ) )
     618                $plugin_assets = array();
     619        $plugin = plugin_basename( $plugin_file );
     620        $plugin_assets[$plugin] = array( 'callback' => $callback ,
     621                                                                         'tables' => $tables ,
     622                                                                         'options' => $options );
     623        update_option( 'plugin_assets' , $plugin_assets );
     624}
     625
     626/**
     627* unregister_plugin_assets(); Unregisters the plugins uninstallable assets from the option
     628*
     629* @link http://trac.wordpress.org/ticket/5625
     630*
     631* @param string $plugin_file the path to the plugin file, usually given by __FILE__
     632*
     633*/
     634function unregister_plugin_assets( $plugin_file ){
     635        $plugin_assets = get_option( 'plugin_assets' );
     636        $plugin = plugin_basename( $plugin_file );
     637        if ( isset( $plugin_assets[$plugin] ) ) {
     638                unset($plugin_assets[$plugin]);
     639                update_option( 'plugin_assets' , $plugin_assets );
     640        }
     641}
     642
     643?>
     644 No newline at end of file