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