钩子文档

rest_endpoints

💡 云策文档标注

概述

rest_endpoints 过滤器用于修改 WordPress REST API 中可用的端点数组。它允许开发者自定义或扩展 API 路由,通常在 WP_REST_Server::get_routes() 方法中被调用。

关键要点

  • 过滤器名称:rest_endpoints,用于过滤 REST API 端点数组。
  • 参数:$endpoints,一个数组,包含匹配的正则表达式模式映射到端点回调函数和位掩码。
  • 格式:'/path/regex' => array( $callback, $bitmask ) 或 '/path/regex' => array( array( $callback, $bitmask ) )。
  • 相关函数:WP_REST_Server::get_routes() 用于检索路由映射。
  • 引入版本:WordPress 4.4.0。

📄 原文内容

Filters the array of available REST API endpoints.

Parameters

$endpointsarray
The available endpoints. An array of matching regex patterns, each mapped to an array of callbacks for the endpoint. These take the format '/path/regex' => array( $callback, $bitmask ) or `'/path/regex' => array( array( $callback, $bitmask ).

Source

$endpoints = apply_filters( 'rest_endpoints', $endpoints );

Changelog

Version Description
4.4.0 Introduced.