Files
User A0264400 a766acdc90 first commit
2026-04-01 23:20:16 +03:00

53 lines
1.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Класс для работы в multisite режиме.
*
* @version 1.0
*/
class WIO_Multisite {
/**
* Инициализация хуков
*/
public function initHooks() {
add_action( 'wbcr/rio/multisite_current_blog', [ $this, 'setCurrentBlog' ] );
add_action( 'wbcr/rio/multisite_restore_blog', [ $this, 'restoreBlog' ] );
}
/**
* Устанавливает текущий блог в соответствии с выбором пользователя
*/
public function setCurrentBlog() {
$current_blog_id = WRIO_Plugin::app()->getPopulateOption( 'current_blog', 1 );
switch_to_blog( $current_blog_id );
}
/**
* Сбрасывает текущий блог
*/
public function restoreBlog() {
restore_current_blog();
}
/**
* Получает список блогов в зависимости от контекста
*
* @param string $context контекст. Например media-library или nextgen
*
* @return array $blogs
*/
public static function getBlogs( $context = 'media-library' ) {
global $wpdb;
$blogs = $wpdb->get_results( "SELECT blog_id, domain, path FROM {$wpdb->blogs}" );
$blogs = apply_filters( 'wbcr/rio/multisite_blogs', $blogs, $context );
return $blogs;
}
}