[wp-trac] [WordPress Trac] #16303: Improve documentation and usability of WP_Rewrite Endpoint support
WordPress Trac
wp-trac at lists.automattic.com
Thu Jan 26 16:32:45 UTC 2012
#16303: Improve documentation and usability of WP_Rewrite Endpoint support
-------------------------------------------------+-------------------------
Reporter: westi | Owner: westi
Type: defect (bug) | Status: new
Priority: lowest | Milestone: Future
Component: Rewrite Rules | Release
Severity: normal | Version: 3.1
Keywords: westi-likes has-patch commit dev- | Resolution:
feedback |
-------------------------------------------------+-------------------------
Changes (by lgedeon):
* cc: luke.gedeon@… (added)
Comment:
Here is another example that might help with documenting end-points:
This code adds an endpoint of the form /embed/xxxx/ to the end of any
post. We then load a separate template to render the article in one of
several embeddable formats.
class plugin_embeddable_post {
public function __construct() {
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_filter( 'query_vars', array( $this, 'query_vars' ) );
add_filter( 'template_include', array( $this,
'template_include' ) );
}
/**
* add_rewrite_endpoint just adds an endpoint to the pool of
endpoints that
* will be used when generate_rewrite_rules is run. It does
nothing on it's
* own but generate_rewrite_rules fires too late, so we use
admin_init to
* make sure it is there when rules are flushed.
*/
public function admin_init() {
add_rewrite_endpoint( 'embed', array( EP_PERMALINK ) );
}
public function query_vars( $public_query_vars ) {
$public_query_vars[] = 'embed';
return $public_query_vars;
}
public function template_include( $template ) {
if ( 'format1' == get_query_var( 'embed' ) )
$template = locate_template( 'embed-format1.php'
);
// add additional embeddable formats here or use one
template for all
return $template;
}
}
$plugin_embeddable_post = new plugin_embeddable_post;
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16303#comment:19>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list