Make WordPress Core

Opened 13 years ago

Closed 11 years ago

#18490 closed enhancement (duplicate)

When installing a new theme, check if parent theme is required.

Reported by: sterlo's profile sterlo Owned by: nacin's profile nacin
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Upgrade/Install Keywords: needs-patch
Focuses: Cc:

Description

Currently I am able to do the following:

  1. Upload a child theme.
  2. Do not have the parent theme installed (for instance, Genesis Framework).
  3. After the child theme is uploaded...I am presented with the option to activate the child theme. Even though the parent theme does not exist.

The child theme can check this by doing something like this...

function genesis_failed_to_load() {
  echo '<div id="message" class="error"><p>Unable to locate the Genesis Framework!</p></div>';
}

/** Start the engine */
if( file_exists( TEMPLATEPATH . '/lib/init.php' ) ) { 
  require_once( TEMPLATEPATH . '/lib/init.php' );
} else {
  add_action( 'admin_notices' , 'genesis_failed_to_load' );
  return false;
}

But knowing most people are not using such code, allowing the activation of a child theme without it's parent theme can lead to site breakage.

Fatal errors, etc.

I propose that upon uploading, prior to providing the activation option, we check to see if the parent theme is installed, if it's not...then mark the theme as broken and don't allow them to activate.

Attachments (5)

allowed-to-activate.png (51.2 KB) - added by sterlo 13 years ago.
Here I have the option to activate a theme without the parent theme installed.
example-handler-for-fatal-error.png (161.9 KB) - added by sterlo 13 years ago.
Example of the code in the description stopping a fatal error from happening. require_once would have failed.
class-wp-upgrader.patch (1.8 KB) - added by sterlo 13 years ago.
My first stab at a patch. svn diff > class-wp-upgrader.patch (root of trunk)
example-of-patch.png (231.2 KB) - added by sterlo 13 years ago.
Example of the patch in action.
another-example.png (245.1 KB) - added by sterlo 13 years ago.
Another example, different parent theme required.

Download all attachments as: .zip

Change History (16)

@sterlo
13 years ago

Here I have the option to activate a theme without the parent theme installed.

@sterlo
13 years ago

Example of the code in the description stopping a fatal error from happening. require_once would have failed.

#1 @sterlo
13 years ago

Example of what it can produce:

Failed opening required '/wp-content/themes/genesis/lib/init.php' (include_path='.:/usr/share/php:/usr/share/pear') in /wp-content/themes/child/functions.php on line 3, referer: /wp-admin/update.php?action=upload-theme

#2 @nacin
13 years ago

  • Milestone changed from Awaiting Review to 3.3
  • Owner set to nacin
  • Status changed from new to accepted

We should be able to hide the action link and comment that the parent theme isn't there, if detected.

#3 @nacin
13 years ago

  • Keywords needs-patch added

@sterlo
13 years ago

My first stab at a patch. svn diff > class-wp-upgrader.patch (root of trunk)

#4 @sterlo
13 years ago

  • Keywords has-patch needs-testing added

#5 @sterlo
13 years ago

  • Keywords needs-patch removed

@sterlo
13 years ago

Example of the patch in action.

@sterlo
13 years ago

Another example, different parent theme required.

#6 @dd32
13 years ago

The string needs a bit of tweaking IMO, and it should probably be inserted after the Network Enable section too (I'm thinking Network Enabling shouldn't be possible unless the template exists)

#7 @GaryJ
13 years ago

  • Cc gary@… added

#7 @GaryJ
13 years ago

  • Cc gary@… added

#8 @dd32
13 years ago

  • Component changed from Themes to Upgrade/Install
  • Keywords needs-patch added; has-patch needs-testing removed

Quick patch review:

  • Can't use $wp_filesystem->wp_themes_dir() with get_theme_data - better to just use get_themes() and iterate through.
  • Block should be moved further down to unset network enable too

This ticket will be superseded by #13774 (Automatically install the parent theme if possible) and a similar message would probably be included there in the event of the parent not being installable.

It's either this, or #13774 for 3.3

#9 @jane
12 years ago

  • Milestone changed from 3.3 to Future Release

This seems like it should have been punted as we're already in beta and are supposed to be doing bug fixes/finishing touches only at this point, not still adding features. The month-old needs-patch keyword seals its fate.

#10 @dd32
11 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from accepted to closed

Duplicate of #13774.

Note: See TracTickets for help on using tickets.