How to change the theme programmatically? I've just applied a theme and got an error such that I cannot even change the theme back to a working one (like Bartik).

I've read other threads but I could use hook_custom theme but I don't know how to get it to work.

What I'm doing is to edit the system.api.php and change the original lines of hook_custom_theme to this:

function hook_custom_theme() {
  // Allow the user to request a particular theme via a query parameter.
  if (1)) { 
    return 'bartik';
  }
}


I've tried several variations but I don't know what I'm missing. Can anyone help me with this please?

Edit: I've realised that I need to write my own module to run that line of code, is it true? Is there a simpler way to just change the default theme or the weight of the themes programmatically somewhere?
You can install drush on your system and then from drush command you can change the theme using 

drush vset theme_default &lt;theme_name&gt;


You can do the changes from database also. Either on the commandline, or via an administration interface (eg PHPMyAdmin) enter the following query

UPDATE system SET status=1 WHERE name = '&lt;theme_name&gt;';


Then either:

UPDATE variable SET value='s:7:"garland"' WHERE name = 'theme_default';
TRUNCATE cache;
TRUNCATE cache_bootstrap;
TRUNCATE cache_block;


Source: https://drupal.org/node/200774