Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My theme has a custom.css file that I use to allow designer's to customize the it to their liking.

However, when clicking on "Appearance > Editor", the style.css file is loaded there by default.

Since I don't want custom edits done on this file, I'd like to minimize the chances that someone edits it by placing custom.css there instead.

Is this possible? Perhaps with the shiny new 3.2 codebase?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

Unfortunately you can't control what files are loaded on that page...

But you can disable the editor page and provide the user with theme options that allow him to include his own CSS.

To deal with this I'm creating and activating a child theme automatically if possible:

if(!is_child_theme()){

  require_once(ABSPATH.'wp-admin/includes/file.php');
  if(!WP_Filesystem()){
    // fail, proably no write-access, use the parent theme...
  }else{

    $parent = get_theme_data(TEMPLATEPATH.'/style.css');
    $name = get_stylesheet().'-extend';
    $destination = trailingslashit($GLOBALS['wp_filesystem']->wp_themes_dir()).$name;

    $style = "/*\n"
            ."Theme Name: {$parent['Name']} - Extend\n"
            ."Theme URI: {$parent['URI']}\n"
            ."Description: Automatically generated child theme of {$parent['Name']}. Please leave this one activated for proper customizations to {$parent['Name']}.\n"
            ."Version: 1.0\n"
            ."Author: {$parent['Author']}\n"
            ."Author URI: {$parent['AuthorURI']}\n"
            ."Template: ".get_template()."\n"
            ."*/\n\n"
            ."/* You can safely edit this file, but keep the Template tag above unchanged! */\n";

    if(!$GLOBALS['wp_filesystem']->is_dir($destination))
      if($GLOBALS['wp_filesystem']->mkdir($destination, FS_CHMOD_DIR) && $GLOBALS['wp_filesystem']->put_contents($destination.'/style.css', $style, FS_CHMOD_FILE)){

        // copy screenshot and license.txt
        $GLOBALS['wp_filesystem']->copy(TEMPLATEPATH.'/screenshot.png', $destination.'/screenshot.png');
        $GLOBALS['wp_filesystem']->copy(TEMPLATEPATH.'/license.txt', $destination.'/license.txt');

        switch_theme(get_template(), $name);
        wp_redirect(admin_url("themes.php"));
        die(); // stop execution of the current page
      }else{
        // fail again...
      }
  }
}
share|improve this answer
add comment

I would instead encourage your users to create Child Themes.

Among other advantages, if using Appearance -> Editor, the Child Theme's style.css will be the default file available for edit, rather than your (i.e. the Parent) Theme's.

share|improve this answer
add comment

After browsing the code a bit, it looks to me like WordPress doesn't provide an API hook to cleanly change the default file that gets loaded on that page.

As an alternative, you can (from within your theme's functons.php or in a plugin) remove certain menus and sub-menus. These blog posts should be useful if you decide to go that route (removing the Appearance -> Editor menu all together).

Personally, I'd be a little annoyed if I installed a theme and it took away functionality. (But I'm a developer). If you're worried that your users will monkey with style.css, they might not need access to the admin control panel at all.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.