Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks
LaunchYourStore::possibly_hide_wp_admin_bar
Hide the WP admin bar when the user is previewing the site.
Метод класса: LaunchYourStore{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$LaunchYourStore = new LaunchYourStore(); $LaunchYourStore->possibly_hide_wp_admin_bar( $show );
- $show(true|false) (обязательный)
- Whether to show the admin bar.
Код LaunchYourStore::possibly_hide_wp_admin_bar() LaunchYourStore::possibly hide wp admin bar WC 10.5.2
public function possibly_hide_wp_admin_bar( $show ) {
if ( isset( $_GET['site-preview'] ) ) { // @phpcs:ignore
return false;
}
global $wp;
$http_referer = wp_get_referer() ?? '';
$parsed_url = wp_parse_url( $http_referer, PHP_URL_QUERY );
$query_string = is_string( $parsed_url ) ? $parsed_url : '';
// Check if the user is coming from the site preview link.
if ( strpos( $query_string, 'site-preview' ) !== false ) {
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
return $show;
}
// Redirect to the current URL with the site-preview query string.
$current_url =
add_query_arg(
array(
'site-preview' => 1,
),
esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) )
);
wp_safe_redirect( $current_url );
exit;
}
return $show;
}