Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#12195 closed enhancement (worksforme)

add filter for get_themes function

Reported by: maxaud's profile maxaud Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch
Focuses: Cc:

Description

Would be nice to have a filter added to the get_themes function so plugin authors can manipulate the theme information before it is passed to the page.

Example:
With the new multisite setup I'll be needing to limit certain themes viewable for certain sites and this would be the most ideal approach.

Attachments (1)

get_themes.diff (296 bytes) - added by scribu 15 years ago.

Download all attachments as: .zip

Change History (9)

@scribu
15 years ago

#1 @scribu
15 years ago

  • Keywords has-patch added; add_filter get_themes plugins removed
  • Milestone changed from Unassigned to 3.0

#2 @ryan
15 years ago

Note that themes can already be disabled/enabled per site via the Network admin.

#3 @wpmuguru
15 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

In a network environment the themes can already be filtered with the allowed_themes filter.

#4 @maxaud
15 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

I don't believe this is possible on a per site basis though.
When I say site, I don't mean blog.

Example:
ms-themes.php shows the themes available to that site.
What if I only want certain themes available/visible to certain sites (even to site admins)?

My reasoning:
My Multisite setup has restricted 'Site Admins' so they cannot go beyond the bounds of their 'Site'. If a user's main blog belongs on a different 'Site' they cannot edit all their details or delete them. They also cannot edit blogs that don't reside on their site. I then made it so 'Site Admins' of site_id=1 have full control over everything (how it's currently set up).

What if I want to upload a custom theme on site #1 and I don't even want site #2 to know that it's an option?

I believe this cannot be done without making a filter on the get_themes function.

example code for making a theme available to only one site:
(uses scribu's add_filter patch)

function remove_themes($wp_themes) {

	// get current site
	global $current_site;

	// set themes that are site specific by unsetting them on all other sites
	if($current_site->id != 1) {

		// unset theme from array
		unset($wp_themes['Theme Name']);
	}

	// return theme
	return $wp_themes;
}
add_filter("get_themes", "remove_themes");

#5 @wpmuguru
15 years ago

Have a look at register_theme_directory();

#6 @maxaud
15 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

awesome, works great. thanks for directing me to this function I didn't know existed.

I appreciate your time, not only on this but on WordPress in general.

#7 @nacin
15 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

#8 @nacin
15 years ago

  • Milestone 3.0 deleted
  • Resolution set to worksforme
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.