From 2a88b5573247b5abdb47f4ff72ba3b41e754a4e8 Mon Sep 17 00:00:00 2001 From: Profile Profile Date: Mon, 2 Mar 2026 17:25:21 +0300 Subject: [PATCH] add coauthor endpoint --- api/coauthor.php | 36 +++++++++ functions.php | 3 +- template-parts/header/header.php | 132 +++++++++++++++---------------- template-parts/home/news.php | 8 +- 4 files changed, 110 insertions(+), 69 deletions(-) create mode 100644 api/coauthor.php diff --git a/api/coauthor.php b/api/coauthor.php new file mode 100644 index 0000000..b0234ab --- /dev/null +++ b/api/coauthor.php @@ -0,0 +1,36 @@ +[a-zA-Z0-9-]+)', [ + 'methods' => 'GET', + 'callback' => function($request) { + $slug = $request['slug']; + + if (!function_exists('get_coauthors')) { + return new WP_Error('no_plugin', 'Co-Authors Plus not active', ['status' => 404]); + } + + global $coauthors_plus; + + // Метод 1: Через объект плагина (работает всегда) + if (isset($coauthors_plus) && method_exists($coauthors_plus, 'get_coauthor_by')) { + $coauthor = $coauthors_plus->get_coauthor_by('user_nicename', $slug); + + if ($coauthor) { + return [ + 'id' => $coauthor->user_nicename, + 'name' => $coauthor->display_name, + 'firstName' => $coauthor->first_name ?? '', + 'lastName' => $coauthor->last_name ?? '', + 'description' => $coauthor->description ?? '', + 'avatar' => get_avatar_url($coauthor->user_email, ['size' => 192]), + 'url' => get_author_posts_url($coauthor->ID, $coauthor->user_nicename), + 'type' => $coauthor->type ?? 'guest-author' + ]; + } + } + + return new WP_Error('not_found', 'Author not found', ['status' => 404]); + }, + 'permission_callback' => '__return_true' + ]); +}); \ No newline at end of file diff --git a/functions.php b/functions.php index 9903539..746d2c5 100644 --- a/functions.php +++ b/functions.php @@ -38,6 +38,7 @@ if (is_admin()) { #api require "api/newstop.php"; // управление REST API +require "api/coauthor.php"; // управление REST API @@ -1070,7 +1071,7 @@ add_action('wp_enqueue_scripts', function() { // Добавляем стиль $css_url = get_template_directory_uri() . '/assets/css/profile-style.css'; - //$css_url = 'https://profile.ru//wp-content/themes/profile/assets/css/profile-style.css'; + $css_url = 'https://profile.ru//wp-content/themes/profile/assets/css/profile-style.css'; wp_enqueue_style( 'profile-style', // уникальный идентификатор diff --git a/template-parts/header/header.php b/template-parts/header/header.php index c358545..9c45221 100644 --- a/template-parts/header/header.php +++ b/template-parts/header/header.php @@ -1,67 +1,67 @@ - - - -> - - - - - " - > - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- -
- - - - - - - - - - - -
- 12, "show_on_mobile" => false ]); ?> -
- - - -
- - -
- + + + +> + + + + + " + > + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+ 14, "show_on_mobile" => false ]); ?> +
+ + + +
+ + +
+ \ No newline at end of file diff --git a/template-parts/home/news.php b/template-parts/home/news.php index a0601aa..aec4d14 100644 --- a/template-parts/home/news.php +++ b/template-parts/home/news.php @@ -134,9 +134,13 @@
    - have_posts()): ?> + have_posts()): ?> - have_posts()): ?> + have_posts()): + $nntop++; + if ($nntop > 10){ break;}?> the_post(); ?>