Yoast\WP\SEO\Initializers
Crawl_Cleanup_Permalinks::utm_redirect
Redirect utm variables away.
Метод класса: Crawl_Cleanup_Permalinks{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Crawl_Cleanup_Permalinks = new Crawl_Cleanup_Permalinks(); $Crawl_Cleanup_Permalinks->utm_redirect();
Код Crawl_Cleanup_Permalinks::utm_redirect() Crawl Cleanup Permalinks::utm redirect Yoast 26.5
public function utm_redirect() {
// Prevents WP CLI from throwing an error.
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
if ( ! isset( $_SERVER['REQUEST_URI'] ) || \strpos( $_SERVER['REQUEST_URI'], '?' ) === false ) {
return;
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
if ( ! \stripos( $_SERVER['REQUEST_URI'], 'utm_' ) ) {
return;
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$parsed = \wp_parse_url( $_SERVER['REQUEST_URI'] );
$query = \explode( '&', $parsed['query'] );
$utms = [];
$other_args = [];
foreach ( $query as $query_arg ) {
if ( \stripos( $query_arg, 'utm_' ) === 0 ) {
$utms[] = $query_arg;
continue;
}
$other_args[] = $query_arg;
}
if ( empty( $utms ) ) {
return;
}
$other_args_str = '';
if ( \count( $other_args ) > 0 ) {
$other_args_str = '?' . \implode( '&', $other_args );
}
$new_path = $parsed['path'] . $other_args_str . '#' . \implode( '&', $utms );
$message = \sprintf(
/* translators: %1$s: Yoast SEO */
\__( '%1$s: redirect utm variables to #', 'wordpress-seo' ),
'Yoast SEO'
);
$this->redirect_helper->do_safe_redirect( \trailingslashit( $this->url_helper->recreate_current_url( false ) ) . \ltrim( $new_path, '/' ), 301, $message );
}