Permalink
Browse files

minor bugfixes and a sample page

  • Loading branch information...
1 parent ae35c00 commit 3c59e001f909e370471eee8210bc797be54866e6 @jbrinley committed May 22, 2011
Showing with 43 additions and 3 deletions.
  1. +1 −1 WP_Route.class.php
  2. +1 −1 WP_Router.class.php
  3. +6 −0 WP_Router_Page.class.php
  4. +30 −0 WP_Router_Sample.class.php
  5. +5 −1 wp-router.php
View
@@ -12,7 +12,7 @@ class WP_Route extends WP_Router_Utility {
private $wp_rewrite = '';
private $title = '';
private $title_callback = '__';
- private $title_arguments = array('');
+ private $title_arguments = array();
private $page_callback = '';
private $page_arguments = array();
private $access_callback = TRUE;
View
@@ -241,7 +241,7 @@ private function rewrite_rules() {
private function query_vars() {
$vars = array();
foreach ( $this->routes as $id => $route ) {
- $vars = array_merge($vars, $route->rewrite_rules());
+ $vars = array_merge($vars, $route->get_query_vars());
}
$vars[] = self::QUERY_VAR;
return $vars;
View
@@ -92,6 +92,7 @@ public function __construct( $contents, $title ) {
add_action('pre_get_posts', array($this, 'edit_query'), 10, 1);
add_action('the_post', array($this, 'set_post_contents'), 10, 1);
add_filter('the_title', array($this, 'get_title'), 10, 2);
+ add_filter('single_post_title', array($this, 'get_single_post_title'), 10, 2);
}
/**
@@ -108,6 +109,7 @@ public function edit_query( WP_Query $query ) {
// override any vars WordPress set based on the original query
$query->is_single = TRUE;
+ $query->is_singular = TRUE;
$query->is_404 = FALSE;
$query->is_home = FALSE;
}
@@ -138,4 +140,8 @@ public function get_title( $title, $post_id ) {
}
return $title;
}
+
+ public function get_single_post_title( $title, $post ) {
+ return $this->get_title($title, $post->ID);
+ }
}
View
@@ -0,0 +1,30 @@
+<?php
+/**
+ * User: jbrinley
+ * Date: 5/22/11
+ * Time: 4:14 PM
+ */
+
+class WP_Router_Sample {
+ public static function init() {
+ add_action('wp_router_generate_routes', array(get_class(), 'generate_routes'), 10, 1);
+ }
+
+ public static function generate_routes( WP_Router $router ) {
+ $router->add_route('wp-router-sample', array(
+ 'path' => '^wp_router/(.*?)$',
+ 'query_vars' => array(
+ 'sample_argument' => 1,
+ ),
+ 'page_callback' => array(get_class(), 'sample_callback'),
+ 'page_arguments' => array('sample_argument'),
+ 'access_callback' => TRUE,
+ 'title' => 'WP Router Sample Page',
+ ));
+ }
+
+ public static function sample_callback( $argument ) {
+ echo '<p>Welcome to the WP Router sample page. You can find the code that generates this page in '.__FILE__.'</p>';
+ echo '<p>This page helpfully tells you the value of the <code>sample_argument</code> query variable: '.esc_html($argument).'</p>';
+ }
+}
View
@@ -41,14 +41,18 @@ function WP_Router_load() {
// load the base class
require_once 'WP_Router_Utility.class.php';
- if ( WP_Router::prerequisites_met(phpversion(), get_bloginfo('version')) ) {
+ if ( WP_Router_Utility::prerequisites_met(phpversion(), get_bloginfo('version')) ) {
// we can continue. Load all supporting files and hook into wordpress
require_once 'WP_Router.class.php';
require_once 'WP_Route.class.php';
require_once 'WP_Router_Page.class.php';
add_action('init', array('WP_Router_Utility', 'init'), -100, 0);
add_action(WP_Router_Utility::PLUGIN_INIT_HOOK, array('WP_Router_Page', 'init'), 0, 0);
add_action(WP_Router_Utility::PLUGIN_INIT_HOOK, array('WP_Router', 'init'), 1, 0);
+
+
+ require_once 'WP_Router_Sample.class.php';
+ add_action(WP_Router_Utility::PLUGIN_INIT_HOOK, array('WP_Router_Sample', 'init'), 1, 0);
} else {
// let the user know prerequisites weren't met
add_action('admin_head', array('WP_Router_Utility', 'failed_to_load_notices'), 0, 0);

0 comments on commit 3c59e00

Please sign in to comment.