add coauthor endpoint
This commit is contained in:
36
api/coauthor.php
Normal file
36
api/coauthor.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
add_action('rest_api_init', function() {
|
||||||
|
register_rest_route('my/v1', '/author/(?P<slug>[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'
|
||||||
|
]);
|
||||||
|
});
|
||||||
@@ -38,6 +38,7 @@ if (is_admin()) {
|
|||||||
|
|
||||||
#api
|
#api
|
||||||
require "api/newstop.php"; // управление REST 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 = 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(
|
wp_enqueue_style(
|
||||||
'profile-style', // уникальный идентификатор
|
'profile-style', // уникальный идентификатор
|
||||||
|
|||||||
@@ -1,67 +1,67 @@
|
|||||||
<!--[header/header]-->
|
<!--[header/header]-->
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html class="no-js" <?= language_attributes(); ?>>
|
<html class="no-js" <?= language_attributes(); ?>>
|
||||||
|
|
||||||
<?php get_template_part("template-parts/header/head"); ?>
|
<?php get_template_part("template-parts/header/head"); ?>
|
||||||
|
|
||||||
<body
|
<body
|
||||||
class="default page-index js-stickybit-parent parent
|
class="default page-index js-stickybit-parent parent
|
||||||
<?= is_branding() ? " branding" : "" ?>
|
<?= is_branding() ? " branding" : "" ?>
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
|
|
||||||
<noscript><div><img loading="lazy" src="https://mc.yandex.ru/watch/24504371" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
<noscript><div><img loading="lazy" src="https://mc.yandex.ru/watch/24504371" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||||
|
|
||||||
<?php if( is_branding() ) : ?>
|
<?php if( is_branding() ) : ?>
|
||||||
|
|
||||||
<?php get_template_part("template-parts/header/branding-erid") ?>
|
<?php get_template_part("template-parts/header/branding-erid") ?>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if( wp_is_mobile() ) : ?>
|
<?php if( wp_is_mobile() ) : ?>
|
||||||
|
|
||||||
<?php get_template_part("template-parts/header/uparrow") ?>
|
<?php get_template_part("template-parts/header/uparrow") ?>
|
||||||
|
|
||||||
<?php //get_template_part("template-parts/cell-promo") ?>
|
<?php //get_template_part("template-parts/cell-promo") ?>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<header class="header">
|
<header class="header">
|
||||||
|
|
||||||
<?php get_template_part("template-parts/header/header-top-line"); ?>
|
<?php get_template_part("template-parts/header/header-top-line"); ?>
|
||||||
|
|
||||||
<?php get_template_part("template-parts/nav/header-nav"); ?>
|
<?php get_template_part("template-parts/nav/header-nav"); ?>
|
||||||
|
|
||||||
<?php if( !wp_is_mobile() ) : ?>
|
<?php if( !wp_is_mobile() ) : ?>
|
||||||
|
|
||||||
<?php get_template_part("template-parts/ad/revive/top") ?>
|
<?php get_template_part("template-parts/ad/revive/top") ?>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main class="main js-stickybit-parent parent">
|
<main class="main js-stickybit-parent parent">
|
||||||
|
|
||||||
<?php if( wp_is_mobile() ) : ?>
|
<?php if( wp_is_mobile() ) : ?>
|
||||||
|
|
||||||
<?php get_template_part("template-parts/ad/revive/top-mobile") ?>
|
<?php get_template_part("template-parts/ad/revive/top-mobile") ?>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php get_template_part("template-parts/header/breadcrumbs") ?>
|
<?php get_template_part("template-parts/header/breadcrumbs") ?>
|
||||||
|
|
||||||
|
<!--[ zone 14 ]-->
|
||||||
<?php if( !wp_is_mobile() and is_home() ) : ?>
|
<?php if( !wp_is_mobile() and is_home() ) : ?>
|
||||||
<div style="margin-bottom: 18px; text-align: center;">
|
<div style="margin-bottom: 18px; text-align: center;">
|
||||||
<?php get_template_part("template-parts/ad/revive/ad", "", [ "zone" => 12, "show_on_mobile" => false ]); ?>
|
<?php get_template_part("template-parts/ad/revive/ad", "", [ "zone" => 14, "show_on_mobile" => false ]); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
<!--[/ zone 14 ]-->
|
||||||
|
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
|
|
||||||
|
|
||||||
<div class="row clearfix d-block">
|
<div class="row clearfix d-block">
|
||||||
|
|
||||||
<!--[/header/header]-->
|
<!--[/header/header]-->
|
||||||
@@ -134,9 +134,13 @@
|
|||||||
|
|
||||||
<ul class="news__list__top">
|
<ul class="news__list__top">
|
||||||
|
|
||||||
<?php if($top_query->have_posts()): ?>
|
<?php
|
||||||
|
$nntop = 0;
|
||||||
|
if($top_query->have_posts()): ?>
|
||||||
|
|
||||||
<?php while ($top_query->have_posts()): ?>
|
<?php while ($top_query->have_posts()):
|
||||||
|
$nntop++;
|
||||||
|
if ($nntop > 10){ break;}?>
|
||||||
|
|
||||||
<?php $top_query->the_post(); ?>
|
<?php $top_query->the_post(); ?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user