function document($show_description = true)
{
global $wpdb;
$original_post = isset($GLOBALS['post']) ? $GLOBALS['post'] : 'unset';
unset($GLOBALS['post']);
$doc = $this->generate_documentation();
if ($show_description) {
?>
<caption>
<h1><?php
echo wp_kses_post($doc['method']);
?>
<?php
echo wp_kses_post($doc['path_labeled']);
?>
</h1>
<p><?php
echo wp_kses_post($doc['description']);
?>
</p>
</caption>
<?php
}
?>
<?php
if (true === $this->deprecated) {
?>
<p><strong>This endpoint is deprecated in favor of version <?php
echo floatval($this->new_version);
?>
</strong></p>
<?php
}
?>
<section class="resource-info">
<h2 id="apidoc-resource-info">Resource Information</h2>
<table class="api-doc api-doc-resource-parameters api-doc-resource">
<thead>
<tr>
<th class="api-index-title" scope="column"> </th>
<th class="api-index-title" scope="column"> </th>
</tr>
</thead>
<tbody>
<tr class="api-index-item">
<th scope="row" class="parameter api-index-item-title">Method</th>
<td class="type api-index-item-title"><?php
echo wp_kses_post($doc['method']);
?>
</td>
</tr>
<tr class="api-index-item">
<th scope="row" class="parameter api-index-item-title">URL</th>
<?php
$version = WPCOM_JSON_API__CURRENT_VERSION;
if (!empty($this->max_version)) {
$version = $this->max_version;
}
?>
<td class="type api-index-item-title">https://public-api.wordpress.com/rest/v<?php
echo floatval($version);
echo wp_kses_post($doc['path_labeled']);
?>
</td>
</tr>
<tr class="api-index-item">
<th scope="row" class="parameter api-index-item-title">Requires authentication?</th>
<?php
$requires_auth = $wpdb->get_row($wpdb->prepare("SELECT requires_authentication FROM rest_api_documentation WHERE `version` = %s AND `path` = %s AND `method` = %s LIMIT 1", $version, untrailingslashit($doc['path_labeled']), $doc['method']));
?>
<td class="type api-index-item-title"><?php
echo true === (bool) $requires_auth->requires_authentication ? 'Yes' : 'No';
?>
</td>
</tr>
</tbody>
</table>
</section>
<?php
foreach (array('path' => 'Method Parameters', 'query' => 'Query Parameters', 'body' => 'Request Parameters', 'response' => 'Response Parameters') as $doc_section_key => $label) {
$doc_section = 'response' === $doc_section_key ? $doc['response']['body'] : $doc['request'][$doc_section_key];
if (!$doc_section) {
continue;
}
$param_label = strtolower(str_replace(' ', '-', $label));
?>
<section class="<?php
echo $param_label;
?>
">
<h2 id="apidoc-<?php
echo esc_attr($doc_section_key);
?>
"><?php
echo wp_kses_post($label);
?>
</h2>
<table class="api-doc api-doc-<?php
echo $param_label;
?>
-parameters api-doc-<?php
echo strtolower(str_replace(' ', '-', $doc['group']));
?>
">
<thead>
<tr>
<th class="api-index-title" scope="column">Parameter</th>
<th class="api-index-title" scope="column">Type</th>
<th class="api-index-title" scope="column">Description</th>
</tr>
</thead>
<tbody>
<?php
foreach ($doc_section as $key => $item) {
?>
<tr class="api-index-item">
<th scope="row" class="parameter api-index-item-title"><?php
echo wp_kses_post($key);
?>
</th>
<td class="type api-index-item-title"><?php
echo wp_kses_post($item['type']);
// @todo auto-link?
?>
</td>
<td class="description api-index-item-body"><?php
$this->generate_doc_description($item['description']);
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</section>
<?php
}
?>
<?php
if ('unset' !== $original_post) {
$GLOBALS['post'] = $original_post;
}
}