function get_categories_tree(string $taxonomy = 'category'): array
{
$terms = get_terms([
'taxonomy' => $taxonomy,
'parent' => false,
'hide_empty' => false,
]);
if (empty($terms) || $terms instanceof WP_Error) {
return [];
}
$categories = [];
foreach ($terms as $term) {
$categories[] = (object) [
'value' => $term->term_id,
'name' => $term->name,
'children' => get_children_categories($term->term_id, $category_id),
];
}
return $categories;
}
function get_children_categories(int $parent_term_id, int $category_id): array
{
$children = array();
$child_terms = get_terms([
'taxonomy' => 'category',
'parent' => $parent_term_id,
'hide_empty' => false,
]);
foreach ($child_terms as $child_term) {
$child = (object) [
'term_id' => $child_term->term_id,
'name' => $child_term->name,
'value' => $child_term->term_id,
];
$grandchildren = get_children_categories($child_term->term_id, $category_id);
if (!empty($grandchildren)) {
$child->children = $grandchildren;
}
$children[] = $child;
}
return $children;
}
$list = get_categories_tree();
class CloudPayments
{
public function systemEndpoint(): void
{
// адрес будет https://site.com/wp-json/cloudpayments/payment-notification
register_rest_route('cloudpayments', '/payment-notification', [
'methods' => 'POST',
'callback' => [$this, 'handleCloudpaymentsPaymentNotification'],
'permission_callback' => '__return_true',
]);
}
public function handleCloudpaymentsPaymentNotification(WP_REST_Request $request): WP_REST_Response
{
$params = $request->get_params(); // данные уведомления
return new WP_REST_Response(['code' => 0], 200); // нужно вернуть нужный ответ (смотреть в доках платежки)
}
}
$udata = get_userdata( $user->ID );
$registered = $udata->user_registered;
под каждый блок подключается свой файл стилей
do_action("my_content");
class AuthorPage {
public function __construct()
{
add_action('content', [$this, 'template']);
}
public function data(): array
{
global $wp_query;
$user = $wp_query->get_queried_object();
if (!($user instanceof WP_User)) {
return [];
}
return [
'title' => $user->first_name,
];
}
public function template(): void
{
if (!is_author()) {
return;
}
get_template_part("template-parts/author", null, [...$this->data()]);
}
}
<?php echo esc_html($args['title'] ?? ''); ?>
wp_insert_post
wp_enqueue_script('main', 'path', [], null, true);
wp_localize_script('main', 'php_data', ['homeUrl' => home_url()]);
const url = php_data.homeUrl;