Snippets

Keith Crain Custom Site Selection Menu

Created by Keith Crain last modified
<?php

/**
 * @snippet       Custom Site Selection Menu
 * @sourcecode    https://bitbucket.org/keith_crain/workspace/snippets/xnMq4g
 * @author        Keith Crain
 * @author_url    https://kronoslabs.io
 * @testedwith    WordPress v5.5.1
 */

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

// Import classes.
use MainWP\Dashboard\MainWP_DB_Base;
use MainWP\Dashboard\MainWP_DB;
use MainWP\Dashboard\MainWP_Connect;

function quick_form_in_admin_bar( $string ) {

	// Create new MainWP_DB Class Instance.
	$mwp_db = new MainWP_DB;

	// Fetch Child Sites list.
	$websites = $mwp_db->query( $mwp_db->get_sql_websites_for_current_user() );
	$mwp_db->data_seek( $websites, 0 );

	// Build Child Site Admin URL.
	$admin_url = esc_url( admin_url() ) . 'admin.php?page=';

	// Build HTML Container.
	$html = '
		<div class="ui green buttons">
			<a class="ui button" data-inverted="" data-position="bottom right" data-tooltip="Go to websites overview table" href="' . $admin_url . 'managesites">Sites</a>

			<div class="ui dropdown icon floating button" style="z-index: 1000;" data-inverted="" data-position="bottom right" data-tooltip="Choose common child site actions" tabindex="0">
				<i class="dropdown icon"></i>
				<div class="menu">
					<div class="ui icon search input">
						<i class="search icon"></i>
						<input type="text" placeholder="Search child sites...">
					</div>
					<div class="divider"></div>
					<div class="header">
						<div class="item" style="display: inline; margin-right: 5px;"><i class="settings icon"></i><a href="' . $admin_url . 'PluginsInstall">Plugins</a></div>
						<div class="item" style="display: inline; margin-right: 5px;"><i class="settings icon"></i><a href="' . $admin_url . 'Extensions-Mainwp-Bulk-Settings-Manager">Settings</a></div>
						<div class="item" style="display: inline; margin-right: 5px;"><i class="settings icon"></i><a href="' . $admin_url . 'Extensions-Mainwp-Client-Reports-Extension">Reports</a></div>
						<div class="item" style="display: inline; margin-right: 5px;"><i class="settings icon"></i><a href="' . $admin_url . 'Extensions-Mainwp-Code-Snippets-Extension">Snippets</a></div>
					</div>
					<div class="scrolling menu">
	';

	// Build Child Site list HTML.
	while ( $websites && ( $website = $mwp_db->fetch_object( $websites ) ) ) {

		$favi_url = '';
		$siteObj  = (object) $website;
		$favi_url = MainWP_Connect::get_favico_url( $siteObj );

		$html .= '
			<div class="item">
				<img class="ui avatar image" src="' . $favi_url . '" style="vertical-align:middle;">
				<span class="description">' . stripslashes($website->name) . '</span>
				<a href="' . $admin_url . 'managesites&dashboard=' . $website->id . '" data-tooltip="Open MainWP Child-Site-Dashboard" data-position="top left" data-inverted=""><i class="dashboard icon"></i></a>
				<a href="' . $website->url . '" target="_blank" data-tooltip="Open frontend in new tab" data-position="top left" data-inverted=""><i class="external alternate icon"></i></a>
				<a href="/wp-admin/SiteOpen&newtab=yes&websiteid=' . $website->id . '" target="_blank" data-tooltip="Open backend in new tab" data-position="top left" data-inverted=""><i class="sign in icon"></i></a>
			</div>
		';
	}

	// Close Site List HTML container.
	$html .= '</div></div></div></div>';

	// Return concatenated HTML String.
	return $string . $html;

} add_filter( 'mainwp_header_right', 'quick_form_in_admin_bar' );

Comments (0)