开发者 | Braad |
---|---|
更新时间 | 2015年12月7日 23:12 |
捐献地址: | 去捐款 |
PHP版本: | 4.0 及以上 |
WordPress版本: | 4.4 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
template_redirect
action will be affected.
Message Output
Rather than contaminate the data structures you might be using for your application (like posts and pages) this plugin includes a settings page with a simple textarea box where you can save any basic message you want to show. The message content is stored in the options table, and the textarea supports all the same HTML that you can use in post content.
You can use the only_rest_api_page_content
filter to include any custom HTML output you want inside the <body>
tags, or you can use the only_rest_api_page_html
filter to completely replace all HTML output of the message page, including the <html>
and <head>
tags.
There is also an only_rest_api_page_css
filter that allows you to override the 5 lines of CSS this plugin includes to center the message on the page.
If you want a hook added or have a feature request let me know. Pull requests are welcome on Github.
Filter Examples
Use custom HTML inside the <body>
tags:
add_filter( 'only_rest_api_page_content', 'xxx_page_content' );
function xxx_page_content( $content ) {
$content = '
Sorry, I Only Speak REST. Please try again at a proper endpoint.';
return $content;
}
Add custom CSS to the default output:
add_filter( 'only_rest_api_page_css', 'xxx_page_css' );
function xxx_page_css( $css ) {
$css .= '.page-content { color: red; font-size: 72px; }';
return $css;
}
Replace the entire HTML output for the page:
add_filter( 'only_rest_api_page_html', 'xxx_page_html' );
function xxx_page_html( $html ) {
ob_start();
?>
Call me back over the REST API yo!
// Do neat stuff...
Ain't nobody got time for non-REST API requests. Please try again at a proper endpoint. :)
<?php
$html = ob_get_clean();
return $html;
}
/only-rest-api
directory to the /wp-content/plugins/
directory.No, this plugin hooks into the template_redirect
action, which only fires when a front end page of some kind is being served.
Yes! This plugin supports both versions of the WP REST API and will support the final version that gets merged into core.