Plugin Directory

Changeset 1607837


Ignore:
Timestamp:
03/04/2017 03:05:11 PM (9 years ago)
Author:
junaidpv
Message:

Improve Router API. Now we can use smooth router without special query var.

Location:
wtools/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wtools/trunk/includes/router.php

    r1606332 r1607837  
    11<?php
    2 
    3 if (!defined('WTOOLS_ROUTE')) {
    4     define('WTOOLS_ROUTE', 'wroute');
    5 }
    62
    73/**
     
    2723
    2824    private function __construct() {
    29         add_filter('query_vars', array($this, 'wp_query_vars'));
    3025        add_action('parse_request', array($this, 'wp_parse_request'));
    3126    }
    3227
    33     public function wp_query_vars($vars) {
    34         $vars[] = WTOOLS_ROUTE;
    35         return $vars;
    36     }
    37 
    3828    public function wp_parse_request(&$wp) {
    39         if (empty($wp->query_vars[WTOOLS_ROUTE])) {
     29        if (empty($wp->request)) {
     30            // Early exit. We do not handle home page noway.
    4031            return;
    4132        }
    42         $current_route = $wp->query_vars[WTOOLS_ROUTE];
    4333        foreach ($this->routes as $path => $route_info) {
    44             if (preg_match("@^$path@", $current_route)) {
     34            if (preg_match("@^$path@", $wp->request)) {
    4535                if (isset($route_info['file'])) {
    4636                    require_once($route_info['file']);
     
    7969function wtools_get_url($route, $query = array()) {
    8070    if (count($query)) {
    81         $query_string = '&' . http_build_query($query);
     71        $query_string = http_build_query($query);
    8272    }
    8373    else {
    8474        $query_string = '';
    8575    }
    86     return site_url("index.php?" . WTOOLS_ROUTE . "={$route}{$query_string}");
     76    return site_url("index.php/{$route}?{$query_string}");
    8777}
  • wtools/trunk/wtools.php

    r1607090 r1607837  
    88  Plugin URI: https://wordpress.org/plugins/wtools/
    99  Description: WTools brings various functions and classes to make developing other plugins faster.
    10   Version: 0.7
     10  Version: 0.8
    1111  Author: Junaid
    1212  License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.