diff --git a/functions.php b/functions.php index 51c5675..78665b0 100644 --- a/functions.php +++ b/functions.php @@ -14,6 +14,10 @@ require "inc/meta_keywords.php"; require "inc/journal_issue.php"; //номера журналов require "inc/rank-description.php"; //подменяем дескрипшт от соцсетей +require "inc/graphql.php"; //graphql + + + require "inc/replace_old_copyright.php"; //подменяем фото для старых картинок с "плохим" копирайтом //scheduler @@ -26,10 +30,14 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) { include "inc/get_cached_alm.php"; + + if (is_admin()) { require "inc/add_adv_checked.php"; // рекламная статья require "inc/admin/auto_check.php"; // помечакм не отправлять в Дзен require "inc/admin/lock-terms.php"; // banned и keys + require "inc/admin/coauthors_filter.php"; //поиск по соавторам + } diff --git a/inc/admin/coauthors_filter.php b/inc/admin/coauthors_filter.php new file mode 100644 index 0000000..ce87be2 --- /dev/null +++ b/inc/admin/coauthors_filter.php @@ -0,0 +1,209 @@ + + select[name="author"] { display: none !important; } + + /* Фиксируем расположение фильтров в одну строку */ + .tablenav .actions { + display: flex !important; + align-items: center !important; + flex-wrap: nowrap !important; + gap: 5px !important; + } + + .tablenav .actions > * { + flex-shrink: 0 !important; + margin: 0 !important; + } + + #author-filter-wrapper { + display: inline-flex !important; + align-items: center !important; + gap: 3px !important; + flex-shrink: 0 !important; + } + + #author_name_filter { + width: 140px !important; + } + + .select2-container { + flex-shrink: 0 !important; + } + + #cap-filter-submit { + flex-shrink: 0 !important; + white-space: nowrap !important; + } + '; + } +} + +// Добавляем наш фильтр по Co-Authors Plus +add_action('restrict_manage_posts', 'cap_filter_by_coauthor'); +function cap_filter_by_coauthor($post_type) { + if ($post_type !== 'profile_article') { + return; + } + + global $wpdb; + + $authors = $wpdb->get_results(" + SELECT DISTINCT t.term_id, t.name, t.slug + FROM {$wpdb->terms} t + INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id + INNER JOIN {$wpdb->term_relationships} tr ON tt.term_taxonomy_id = tr.term_taxonomy_id + INNER JOIN {$wpdb->posts} p ON tr.object_id = p.ID + WHERE tt.taxonomy = 'author' + AND p.post_type = 'profile_article' + AND p.post_status = 'publish' + ORDER BY t.name ASC + "); + + if (!empty($authors)) { + $current = isset($_GET['author_name']) ? $_GET['author_name'] : ''; + + // Обертка для фильтра и кнопки + echo '
'; + } +} + +// Модифицируем запрос для фильтрации +add_filter('parse_query', 'cap_filter_posts_by_coauthor'); +function cap_filter_posts_by_coauthor($query) { + global $pagenow, $typenow; + + if (!is_admin() || $pagenow !== 'edit.php' || $typenow !== 'profile_article') { + return; + } + + if (isset($_GET['author_name']) && !empty($_GET['author_name'])) { + $query->query_vars['tax_query'] = [ + [ + 'taxonomy' => 'author', + 'field' => 'slug', + 'terms' => sanitize_text_field($_GET['author_name']) + ] + ]; + } +} + +// Подключаем Select2 и стили +add_action('admin_enqueue_scripts', 'cap_enqueue_select2'); +function cap_enqueue_select2($hook) { + if ($hook !== 'edit.php') { + return; + } + + global $typenow; + if ($typenow !== 'profile_article') { + return; + } + + wp_enqueue_style('select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css'); + wp_enqueue_script('select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js', ['jquery'], null, true); + + wp_add_inline_script('select2', ' + jQuery(document).ready(function($) { + // Удаляем дублированные обертки + $("#author-filter-wrapper").not(":first").remove(); + + var $select = $("#author_name_filter").first(); + + $select.select2({ + placeholder: "Все авторы", + allowClear: true, + width: "140px" + }); + + // Обработка очистки + $select.on("select2:clear", function(e) { + $(this).val("").trigger("change"); + $(this).closest("form").submit(); + }); + + // Обработка выбора + $select.on("select2:select", function(e) { + $(this).closest("form").submit(); + }); + + // Enter в поиске + $(document).on("keypress", ".select2-search__field", function(e) { + if (e.which === 13) { + e.preventDefault(); + $select.closest("form").submit(); + } + }); + }); + '); + + wp_add_inline_style('select2', ' + .select2-container--default .select2-selection--single { + height: 32px; + border-color: #8c8f94; + border-radius: 3px; + background: #fff; + } + .select2-container--default .select2-selection--single .select2-selection__rendered { + line-height: 30px; + color: #50575e; + padding-left: 8px; + font-size: 13px; + } + .select2-container--default .select2-selection--single .select2-selection__arrow { + height: 30px; + } + .select2-container--default.select2-container--focus .select2-selection--single { + border-color: #2271b1; + box-shadow: 0 0 0 1px #2271b1; + } + .select2-dropdown { + border-color: #8c8f94; + } + .select2-container--default .select2-results__option--highlighted[aria-selected] { + background-color: #2271b1; + } + .select2-container--default .select2-search--dropdown .select2-search__field { + border-color: #8c8f94; + font-size: 13px; + } + '); +}