174 lines
4.7 KiB
PHP
174 lines
4.7 KiB
PHP
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
add_action( 'init', 'sev_tort_register_rewrite_rules' );
|
|
function sev_tort_register_rewrite_rules() {
|
|
foreach ( sev_tort_pages() as $slug => $page ) {
|
|
add_rewrite_rule( '^' . preg_quote( $slug, '/' ) . '/?$', 'index.php?sev_tort_page=' . $slug, 'top' );
|
|
}
|
|
}
|
|
|
|
add_filter( 'query_vars', 'sev_tort_query_vars' );
|
|
function sev_tort_query_vars( $vars ) {
|
|
$vars[] = 'sev_tort_page';
|
|
return $vars;
|
|
}
|
|
|
|
add_filter( 'wp_sitemaps_enabled', '__return_false' );
|
|
|
|
add_filter( 'redirect_canonical', 'sev_tort_disable_static_seo_redirects', 10, 2 );
|
|
function sev_tort_disable_static_seo_redirects( $redirect_url, $requested_url ) {
|
|
if ( sev_tort_is_static_seo_path() ) {
|
|
return false;
|
|
}
|
|
|
|
return $redirect_url;
|
|
}
|
|
|
|
add_action( 'init', 'sev_tort_static_seo_files', 0 );
|
|
function sev_tort_static_seo_files() {
|
|
if ( ! sev_tort_is_static_seo_path() ) {
|
|
return;
|
|
}
|
|
|
|
$path = isset( $_SERVER['REQUEST_URI'] ) ? parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : '';
|
|
$path = trim( (string) $path, '/' );
|
|
|
|
if ( 'sitemap_index.xml' === $path ) {
|
|
sev_tort_send_sitemap_index();
|
|
}
|
|
|
|
if ( 'sitemap.xml' === $path ) {
|
|
sev_tort_send_sitemap();
|
|
}
|
|
|
|
if ( 'robots.txt' === $path ) {
|
|
sev_tort_send_robots();
|
|
}
|
|
}
|
|
|
|
function sev_tort_is_static_seo_path() {
|
|
$path = isset( $_SERVER['REQUEST_URI'] ) ? parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : '';
|
|
$path = trim( (string) $path, '/' );
|
|
|
|
return in_array( $path, array( 'sitemap.xml', 'sitemap_index.xml', 'robots.txt' ), true );
|
|
}
|
|
|
|
function sev_tort_send_sitemap_index() {
|
|
status_header( 200 );
|
|
header( 'Content-Type: application/xml; charset=UTF-8' );
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
|
|
echo "\t" . '<sitemap>' . "\n";
|
|
echo "\t\t" . '<loc>' . esc_url( home_url( '/sitemap.xml' ) ) . '</loc>' . "\n";
|
|
echo "\t\t" . '<lastmod>' . esc_html( gmdate( 'Y-m-d' ) ) . '</lastmod>' . "\n";
|
|
echo "\t" . '</sitemap>' . "\n";
|
|
echo '</sitemapindex>';
|
|
exit;
|
|
}
|
|
|
|
function sev_tort_send_sitemap() {
|
|
status_header( 200 );
|
|
header( 'Content-Type: application/xml; charset=UTF-8' );
|
|
|
|
$pages = sev_tort_pages();
|
|
$urls = array(
|
|
array(
|
|
'loc' => home_url( '/' ),
|
|
'changefreq' => 'weekly',
|
|
'priority' => '1.0',
|
|
),
|
|
);
|
|
|
|
foreach ( $pages as $page ) {
|
|
if ( empty( $page['indexable'] ) ) {
|
|
continue;
|
|
}
|
|
|
|
$priority = in_array( $page['slug'], array( 'torty-na-zakaz', 'bento', 'detskie', 'svadebnye', 'na-den-rozhdeniya', 'ceny' ), true ) ? '0.9' : '0.8';
|
|
|
|
$urls[] = array(
|
|
'loc' => home_url( '/' . $page['slug'] . '/' ),
|
|
'changefreq' => 'weekly',
|
|
'priority' => $priority,
|
|
);
|
|
}
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
|
|
|
|
foreach ( $urls as $url ) {
|
|
echo "\t" . '<url>' . "\n";
|
|
echo "\t\t" . '<loc>' . esc_url( $url['loc'] ) . '</loc>' . "\n";
|
|
echo "\t\t" . '<lastmod>' . esc_html( gmdate( 'Y-m-d' ) ) . '</lastmod>' . "\n";
|
|
echo "\t\t" . '<changefreq>' . esc_html( $url['changefreq'] ) . '</changefreq>' . "\n";
|
|
echo "\t\t" . '<priority>' . esc_html( $url['priority'] ) . '</priority>' . "\n";
|
|
echo "\t" . '</url>' . "\n";
|
|
}
|
|
|
|
echo '</urlset>';
|
|
exit;
|
|
}
|
|
|
|
function sev_tort_send_robots() {
|
|
status_header( 200 );
|
|
header( 'Content-Type: text/plain; charset=UTF-8' );
|
|
|
|
echo "User-agent: *\n";
|
|
echo "Disallow: /wp-admin/\n";
|
|
echo "Allow: /wp-admin/admin-ajax.php\n";
|
|
echo "Disallow: /wp-includes/\n";
|
|
echo "Disallow: /wp-content/plugins/\n";
|
|
echo "Disallow: /wp-content/cache/\n";
|
|
echo "Disallow: /wp-json/\n";
|
|
echo "Disallow: /*?s=\n\n";
|
|
echo 'Sitemap: ' . esc_url( home_url( '/sitemap.xml' ) ) . "\n";
|
|
exit;
|
|
}
|
|
|
|
add_action( 'template_redirect', 'sev_tort_route_status' );
|
|
function sev_tort_route_status() {
|
|
if ( sev_tort_current_page_config() ) {
|
|
status_header( 200 );
|
|
}
|
|
}
|
|
|
|
add_filter( 'template_include', 'sev_tort_template_include' );
|
|
function sev_tort_template_include( $template ) {
|
|
$page = sev_tort_current_page_config();
|
|
|
|
if ( ! $page ) {
|
|
return $template;
|
|
}
|
|
|
|
if ( 'politika-konfidencialnosti' === $page['slug'] ) {
|
|
return get_stylesheet_directory() . '/page-templates/page-policy.php';
|
|
}
|
|
|
|
if ( 'portfolio' === $page['slug'] ) {
|
|
return get_stylesheet_directory() . '/page-templates/page-portfolio.php';
|
|
}
|
|
|
|
return get_stylesheet_directory() . '/page-templates/page-service.php';
|
|
}
|
|
|
|
function sev_tort_current_page_config() {
|
|
$slug = get_query_var( 'sev_tort_page' );
|
|
|
|
if ( ! $slug && is_front_page() ) {
|
|
return false;
|
|
}
|
|
|
|
if ( ! $slug && is_page() ) {
|
|
$slug = get_post_field( 'post_name', get_queried_object_id() );
|
|
}
|
|
|
|
$pages = sev_tort_pages();
|
|
|
|
return isset( $pages[ $slug ] ) ? $pages[ $slug ] : false;
|
|
}
|