correct bg menus

This commit is contained in:
argoexpert press
2025-02-04 00:19:35 +03:00
parent 19f12627a0
commit 06f2f95ae8
7 changed files with 75 additions and 77 deletions

View File

@@ -19,7 +19,7 @@ function redirect_non_admin_users() {
$current_user = wp_get_current_user();
// Проверяем, если пользователь не является администратором
if (in_array('subscriber', $current_user->roles) || in_array('author', $current_user->roles)) {
if (in_array('subscriber', $current_user->roles)) {
// Если это запрос к административной панели или если пользователь пытается получить доступ к wp-admin
if (is_admin()) {
// Перенаправляем на главную страницу сайта
@@ -613,92 +613,75 @@ function get_category_name_en($post = null)
}
// Добавляем функцию для формирования мета-тегов страницы
function custom_meta_tags() {
$sitename = get_bloginfo('name');
$meta_tags = '';
$og_tags = '';
$og_tags .= '<meta property="og:locale" content="ru_RU">';
$og_tags .= '<meta property="og:site_name" content="'. $sitename .'">'. PHP_EOL;
$og_tags .= '<meta property="og:locale" content="ru_RU">' . PHP_EOL;
$og_tags .= '<meta property="og:site_name" content="' . esc_html($sitename) . '">' . PHP_EOL;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
// Получаем заголовок страницы
if (is_single() || is_page()) {
if (is_home() || is_front_page()) {
$title = 'Федеральное издание «Агроэксперт» - новости в сфере сельского хозяйства России';
$description = get_bloginfo('description');
$current_url = get_permalink();
$meta_tags .= '<title>' . esc_html($title) . '</title>' . PHP_EOL;
$meta_tags .= '<meta name="description" content="' . esc_attr($description) . '">' . PHP_EOL;
$og_tags .= '<meta property="og:title" content="' . esc_html($title) . '" />' . PHP_EOL;
$og_tags .= '<meta property="og:description" content="' . esc_attr($description) . '" />' . PHP_EOL;
$post = get_post(); // Получаем объект текущего поста или страницы
$title = get_the_title($post).' - '.$sitename; // Получаем заголовок текущего поста или страницы
$excerpt = get_the_excerpt($post);
} elseif (is_category() || is_tag()) {
$term = get_queried_object();
$canonical_url = get_term_link($term);
if (has_excerpt()) {
$description = $excerpt;
} elseif (strlen($excerpt) > 300) {
$description = wp_trim_words($excerpt, 30, '...');
if ($paged > 1) {
$meta_tags .= '<link rel="canonical" href="' . esc_url($canonical_url) . '" />' . PHP_EOL;
}
$title = $term->name . ' - ' . $sitename;
$description = !empty(trim($term->description)) ? $term->description : $term->name;
if ($paged > 1) {
$title .= ', страница ' . $paged;
$description .= '. Страница ' . $paged;
}
$og_tags .= '<meta property="og:url" content="' . esc_url($canonical_url) . '" />' . PHP_EOL;
$meta_tags .= '<title>' . esc_html($title) . '</title>' . PHP_EOL;
$meta_tags .= '<meta name="description" content="' . esc_attr($description) . '">' . PHP_EOL;
$og_tags .= '<meta property="og:title" content="' . esc_html($title) . '" />' . PHP_EOL;
$og_tags .= '<meta property="og:description" content="' . esc_attr($description) . '" />' . PHP_EOL;
} elseif (is_single() || is_page()) {
$post = get_queried_object();
if (is_page('kontakty')) { //конкретные страницы
$title = get_the_title($post).' '. $sitename;
} else {
$description = $excerpt;
}
$title = get_the_title($post) . ' - ' . $sitename;
}
$description = has_excerpt($post) ? get_the_excerpt($post) : wp_trim_words(strip_shortcodes($post->post_content), 30);
$tags = get_the_tags($post); // Получаем теги текущего поста или страницы
$keywords = ''; // Переменная для хранения ключевых слов
if ($tags) {
$keywords = implode(', ', wp_list_pluck($tags, 'name')); // Формируем строку с тегами через запятую
}
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_image_src($post_thumbnail_id, 'full');
if ($post_thumbnail_url) {
$og_image = esc_url($post_thumbnail_url[0]);
$og_tags .= '<meta property="og:image" content="' . $og_image . '">'. PHP_EOL;
$og_tags .= '<meta name="twitter:card" content="summary_large_image">'. PHP_EOL;
}
$og_tags .= '<meta property="og:type" content="article">'. PHP_EOL;
} elseif (is_category()) {
$category = get_queried_object(); // Получаем объект текущей рубрики
$current_url = get_term_link($category);
$title = $category->name.': Новости, комментарии по теме - '.$sitename; // Получаем название текущей рубрики
$description = $category->description; // Получаем описание текущей рубрики
$keywords = $category->name; // Ключевые слова - название рубрики
} elseif (is_home()) {
$current_url = get_site_url();
$title = $sitename; // Получаем название сайта для главной страницы
$description = get_bloginfo('description'); // Получаем описание сайта для главной страницы
$keywords = ''; // Для главной страницы ключевые слова оставляем пустыми
$og_tags .= '<meta property="og:type" content="website">'. PHP_EOL;
$og_tags .= '<meta property="og:url" content="' . esc_url($canonical_url) . '" />' . PHP_EOL;
$meta_tags .= '<title>' . esc_html($title) . '</title>' . PHP_EOL;
$meta_tags .= '<meta name="description" content="' . esc_attr($description) . '">' . PHP_EOL;
$og_tags .= '<meta property="og:title" content="' . esc_html($title) . '" />' . PHP_EOL;
$og_tags .= '<meta property="og:description" content="' . esc_attr($description) . '" />' . PHP_EOL;
}
// Добавляем мета-теги только в случае, если их значения не пусты
if (!empty($current_url)) {
$og_tags .= '<meta property="og:url" content="' . esc_url($current_url) . '" />' . PHP_EOL;
}
if (!empty($title)) {
$meta_tags .= '<title>' . esc_html($title) . '</title>'. PHP_EOL;
$og_tags .= '<meta property="og:title" content="'. esc_html($title) .'" />'. PHP_EOL;
}
if (!empty($description)) {
$description = wp_strip_all_tags($description);
$meta_tags .= '<meta name="description" content="' . esc_attr($description) . '">'. PHP_EOL;
$og_tags .= '<meta property="og:description" content="' . esc_attr($description) . '" />'. PHP_EOL;
}
if (!empty($keywords)) {
$meta_tags .= '<meta name="keywords" content="' . esc_attr($keywords) . '">'. PHP_EOL;
}
// Выводим мета-теги
echo $meta_tags;
echo $og_tags;
}
add_action('wp_head', 'custom_meta_tags');
add_action('wpcf7_before_send_mail', 'my_custom_contact_form_handler', 10, 3);
function my_custom_contact_form_handler($contact_form, $abort, $submission) {
@@ -1176,7 +1159,7 @@ function change_author_name($author) {
add_filter('the_author', 'change_author_name');
// подписчики на главную
add_action('admin_init', 'restrict_subscriber_admin_access');
//add_action('admin_init', 'restrict_subscriber_admin_access');
function restrict_subscriber_admin_access() {
// Проверяем, что пользователь вошел в систему и имеет роль 'subscriber'
if (current_user_can('subscriber')) {
@@ -1186,4 +1169,16 @@ function restrict_subscriber_admin_access() {
}
}
//авторы только в черновики
function restrict_author_publish_posts( $data ) {
// Проверяем, что текущий пользователь - автор
if ( current_user_can( 'author' ) && $data['post_status'] == 'publish' ) {
// Отключаем публикацию для авторов
$data['post_status'] = 'draft'; // Сохраняем как черновик
}
return $data;
}
add_filter( 'wp_insert_post_data', 'restrict_author_publish_posts' );