| 1485 | * Enables a theme for a site. |
| 1486 | * |
| 1487 | * @since 5.0.0 |
| 1488 | * |
| 1489 | * @param int $site_id Site ID. |
| 1490 | * @param string|string[] $stylesheets Stylesheet name or array of stylesheet names. |
| 1491 | */ |
| 1492 | public static function site_enable_theme( $site_id = null, $stylesheets ) { |
| 1493 | if ( ! is_multisite() ) { |
| 1494 | return; |
| 1495 | } |
| 1496 | |
| 1497 | if ( ! is_array( $stylesheets ) ) { |
| 1498 | $stylesheets = array( $stylesheets ); |
| 1499 | } |
| 1500 | |
| 1501 | $current_site_id = get_current_blog_id(); |
| 1502 | if ( ! $site_id ) { |
| 1503 | $site_id = $current_site_id; |
| 1504 | } |
| 1505 | |
| 1506 | if ( $site_id !== $current_site_id ) { |
| 1507 | switch_to_blog( $site_id ); |
| 1508 | } |
| 1509 | |
| 1510 | $allowed_themes = get_option( 'allowedthemes' ); |
| 1511 | foreach ( $stylesheets as $stylesheet ) { |
| 1512 | $allowed_themes[ $stylesheet ] = true; |
| 1513 | } |
| 1514 | update_option( 'allowedthemes', $allowed_themes ); |
| 1515 | |
| 1516 | if ( $site_id !== $current_site_id ) { |
| 1517 | restore_current_blog(); |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * Disables a theme for a site. |
| 1523 | * |
| 1524 | * @since 5.0.0 |
| 1525 | * |
| 1526 | * @param int $site_id Site ID. |
| 1527 | * @param string|string[] $stylesheets Stylesheet name or array of stylesheet names. |
| 1528 | */ |
| 1529 | public static function site_disable_theme( $site_id = null, $stylesheets ) { |
| 1530 | if ( ! is_multisite() ) { |
| 1531 | return; |
| 1532 | } |
| 1533 | |
| 1534 | if ( ! is_array( $stylesheets ) ) { |
| 1535 | $stylesheets = array( $stylesheets ); |
| 1536 | } |
| 1537 | |
| 1538 | $current_site_id = get_current_blog_id(); |
| 1539 | if ( ! $site_id ) { |
| 1540 | $site_id = $current_site_id; |
| 1541 | } |
| 1542 | |
| 1543 | if ( $site_id !== $current_site_id ) { |
| 1544 | switch_to_blog( $site_id ); |
| 1545 | } |
| 1546 | |
| 1547 | $allowed_themes = get_option( 'allowedthemes' ); |
| 1548 | foreach ( $stylesheets as $stylesheet ) { |
| 1549 | if ( isset( $allowed_themes[ $stylesheet ] ) ) { |
| 1550 | unset( $allowed_themes[ $stylesheet ] ); |
| 1551 | } |
| 1552 | } |
| 1553 | update_option( 'allowedthemes', $allowed_themes ); |
| 1554 | |
| 1555 | if ( $site_id !== $current_site_id ) { |
| 1556 | restore_current_blog(); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | /** |