The problem is that you aren’t declaring $dg_options
as global here:
define('DG_OPTION_NAME', 'document_gallery');
$dg_options = get_option(DG_OPTION_NAME);
During uninstall you aren’t in the global scope, your file is being included by uninstall_plugin()
.
So you need to add this at the top of the main plugin file:
global $dg_options;
Really, any time you want a variable to be global, you should be sure to use the global
statement. Don’t take scope for granted.