'ids', 'number' => self::ACTIVATE_NOW, 'archived' => 0, 'deleted' => 0, ) ); foreach ( $sites as $site_id ) { switch_to_blog( $site_id ); Install::activate_site(); restore_current_blog(); } } /** * A site of a network-activated install that hasn't been set up yet * (beyond the first sites at activation) is set up on its first request. */ public function maybe_setup() { if ( self::network_active() && ! get_option( 'kdocs_installed_at' ) ) { Install::activate_site( false ); } } /** * New site in a network where the plugin is network-active. * * @param \WP_Site $site Site. */ public function new_site( $site ) { if ( ! self::network_active() ) { return; } switch_to_blog( (int) $site->blog_id ); Install::activate_site( false ); restore_current_blog(); } /** * Drops the plugin tables with a deleted site. * * @param string[] $tables Tables WordPress will drop. * @param int $site_id Site. * @return string[] */ public function drop_tables( $tables, $site_id ) { global $wpdb; $prefix = $wpdb->get_blog_prefix( $site_id ); foreach ( Install::tables() as $table ) { $tables[] = $prefix . 'kdocs_' . $table; } return $tables; } /** * Network Admin → Karma Docs. */ public function menu() { add_menu_page( __( 'Karma Docs', 'karma-docs' ), Admin\Admin::menu_label(), 'manage_network_options', 'karma-docs', array( $this, 'render' ), 'dashicons-book-alt', 30 ); } /** * Documentation per site. * * @return array[] id, name, url, admin, kbs, articles, ready. */ public static function overview() { $rows = array(); foreach ( get_sites( array( 'number' => 200, 'deleted' => 0, ) ) as $site ) { switch_to_blog( (int) $site->blog_id ); $counts = wp_count_posts( PostTypes::ARTICLE ); $kbs = wp_count_terms( array( 'taxonomy' => Taxonomies::KB, 'hide_empty' => false, ) ); $rows[] = array( 'id' => (int) $site->blog_id, 'name' => get_bloginfo( 'name' ), 'url' => home_url( '/' ), 'admin' => admin_url( 'admin.php?page=karma-docs' ), 'kbs' => is_wp_error( $kbs ) ? 0 : (int) $kbs, 'articles' => (int) ( $counts->publish ?? 0 ), 'ready' => (bool) get_option( 'kdocs_installed_at' ), ); restore_current_blog(); } return $rows; } /** * Network page. */ public function render() { $rows = self::overview(); echo '

' . esc_html__( 'Karma Docs on this network', 'karma-docs' ) . '

'; echo '

' . esc_html__( 'Each site has its own knowledge bases, settings and analytics. Open a site to manage its documentation.', 'karma-docs' ) . '

'; if ( ! self::network_active() ) { echo '

' . esc_html__( 'The plugin is activated per site. Network-activate it to set it up on every site, including new ones.', 'karma-docs' ) . '

'; } echo ''; foreach ( array( __( 'Site', 'karma-docs' ), __( 'Knowledge bases', 'karma-docs' ), __( 'Published articles', 'karma-docs' ), __( 'Status', 'karma-docs' ) ) as $label ) { echo ''; } echo ''; foreach ( $rows as $row ) { echo ''; echo ''; echo ''; } echo '
' . esc_html__( 'Sites', 'karma-docs' ) . '
' . esc_html( $label ) . '
' . esc_html( $row['name'] ) . '
' . esc_html( $row['url'] ) . '
' . (int) $row['kbs'] . '' . (int) $row['articles'] . '' . ( $row['ready'] ? esc_html__( 'Set up', 'karma-docs' ) : esc_html__( 'Not set up yet (on first visit)', 'karma-docs' ) ) . '
'; } }