Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#30594 closed enhancement (fixed)

New function to network enable a theme

Reported by: igmoweb's profile igmoweb Owned by: jeremyfelt's profile jeremyfelt
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch has-unit-tests
Focuses: administration, multisite Cc:

Description

I haven't found any ticket asking about this but what if we create a new function to network enable/disable a theme?

Right now, wp-admin/themes.php is doing the following thing to enable themes in a network:

...
$allowed_themes = get_site_option( 'allowedthemes' );
	switch ( $action ) {
		case 'enable':
			check_admin_referer('enable-theme_' . $_GET['theme']);
			$allowed_themes[ $_GET['theme'] ] = true;
			update_site_option( 'allowedthemes', $allowed_themes );
...

We could encapsulate that in new functions, one to enabling and another to disabling.

Just in case, the code was pretty easy so I upload here a patch.

Thanks.

Attachments (7)

enable_themes_function.diff (3.1 KB) - added by igmoweb 9 years ago.
Enable/Disable themes network widly functions
enable_themes_function_2.diff (4.1 KB) - added by igmoweb 9 years ago.
Patch updated
enable_themes_function_3.diff (4.2 KB) - added by igmoweb 8 years ago.
Updated patch
enable_themes_function_3_unit_tests.diff (2.0 KB) - added by igmoweb 8 years ago.
Unit tests
30594.diff (7.3 KB) - added by igmoweb 8 years ago.
New functions + Unit tests
30594.2.diff (7.2 KB) - added by igmoweb 8 years ago.
Patch + Unit tests splited into 4 cases
30594.3.diff (7.0 KB) - added by jeremyfelt 8 years ago.

Download all attachments as: .zip

Change History (24)

@igmoweb
9 years ago

Enable/Disable themes network widly functions

#1 @helen
9 years ago

  • Version trunk deleted

#2 @jeremyfelt
9 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from New function to network activate a theme to New function to network enable a theme

Thanks for the ticket igmoweb, this seems pretty sensible.

  • I'd go with the singular wp_network_enable_theme() and wp_network_disable_theme().
  • We may be able to attach these as static methods to WP_Theme.

@igmoweb
9 years ago

Patch updated

#3 @igmoweb
9 years ago

Patch updated (enable_themes_function_2.diff). Now using WP_Theme and also improved the comments.

Thanks.

This ticket was mentioned in Slack in #core by igmoweb. View the logs.


8 years ago

#5 @swissspidy
8 years ago

  • Keywords has-patch needs-unit-tests added

@igmoweb
8 years ago

Updated patch

#6 @igmoweb
8 years ago

I've updated the patch (enable_themes_function_3.diff), as it needed some refreshment and also attached two unit tests.

Thanks.

This ticket was mentioned in Slack in #core by igmoweb. View the logs.


8 years ago

#8 @igmoweb
8 years ago

@jeremyfelt As discussed in #core, I'm attaching new patch: Functions + unit tests in the same patch

I've also added a few more asserts that make sure that network enabling/disabling the same theme twice works as expected.

@igmoweb
8 years ago

New functions + Unit tests

#9 @ericlewis
8 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

#10 @jeremyfelt
8 years ago

  • Milestone changed from Future Release to 4.5
  • Owner set to igmoweb
  • Status changed from new to assigned

Thanks @igmoweb, this is looking good.

Some minor adjustments:

  • I think we can follow how WP_Theme is setup in general and use WP_Theme::network_enable_theme() and WP_Theme::network_disable_theme() directly without providing the wp_network_* wrapper functions.
  • The additions to class-wp-theme.php need to be formatted per core code style. It looks like spacing is a bit off in the methods and the if statements need braces.
  • Let's split the tests up into 4 parts: network enable a single theme, network enable an array of themes, network disable a single theme, and network disable an array of themes.
Last edited 8 years ago by jeremyfelt (previous) (diff)

#11 @igmoweb
8 years ago

Hi @jeremyfelt

Here's the new patch.

Thanks.

@igmoweb
8 years ago

Patch + Unit tests splited into 4 cases

This ticket was mentioned in Slack in #core by jorbin. View the logs.


8 years ago

#13 @jorbin
8 years ago

  • Milestone changed from 4.5 to Future Release

Due to lack of activity and the upcoming 4.5 beta 1 deadline, this is going to be punted.

@jeremyfelt
8 years ago

#14 @jeremyfelt
8 years ago

  • Keywords 4.6-early added

Excellent stuff @igmoweb, thank you.

I've refreshed and adjusted the tests a bit in 30594.3.diff and added an is_multisite() check to each of the new methods. I think we'll be able to get this in early for 4.6.

#15 @igmoweb
8 years ago

Awesome. Thanks!

#16 @jeremyfelt
8 years ago

  • Keywords 4.6-early removed
  • Milestone changed from Future Release to 4.6
  • Owner changed from igmoweb to jeremyfelt
  • Status changed from assigned to accepted

#17 @jeremyfelt
8 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 37202:

Multisite: Introduce WP_Theme methods to network enable/disable themes.

  • WP_Theme::network_enable_theme() can be used to enable a theme or array of themes on a network.
  • WP_Theme::network_disable_theme() can be used to disable a theme or array of themes on a network.
  • Use these new methods in the network admin vs direct update_site_option() calls.
  • Add tests.

Props igmoweb.
Fixes #30594.

Note: See TracTickets for help on using tickets.