Wordpress Subdomain Plugin Issue

Discussion in 'PHP' started by wWhat, Mar 4, 2012.

  1. #1
    I'm using subdomain plugin, it allows me to setup my main categories as subdomains. It is working however I'm having issue when I'm trying to go to second page.

    lets say my category is "pineapple"
    pineapple.myblog.com

    when i'm clicking to 'Older Entries', it is removing to subdomain and is going to "myblog.com/page/2", instead of "pineapple.myblog.com/page/2".

    When I'm going "pineapple.myblog.com/page/2" manually, it is NOT actually second page of the pineapple category, it is second page of the blog!!

    Everything based on rewrite in this plugin and I'm getting confused really easily!

    <?php
    class subSubdomain{
        var $slug;
        var $field;
        function  __construct() {
            $this->field ='category_name';
        } 
    
        function getSubdomain(){
            $url = getenv( 'HTTP_HOST' );
        $domain = explode( ".", $url );
            $this->slug = $domain[0];
            return get_category_by_slug($this->slug);
        } 
    
        function getRewriteRules(){
            $rules = array();
        $rules["feed/(feed|rdf|rss|rss2|atom)/?$"] = "index.php?" . $this->field . "=" . $this->slug . "&feed=\$matches[1]";
        $rules["(feed|rdf|rss|rss2|atom)/?$"] = "index.php?" . $this->field . "=" . $this->slug . "&feed=\$matches[1]";
        $rules["page/?([0-9]{1,})/?$"] = "index.php?" . $this->field . "=" . $this->slug . "&paged=\$matches[1]";
        $rules["$"] = "index.php?" . $this->field . "=" . $this->slug;
            return $rules;
        }
    } 
    
    class initPlugin extends subSubdomain{
        function __construct(){
            parent::__construct();
        }
        function addActions() {
            add_action( 'init', 'wps_init', 2 );
        }
        function addFilters(){
         //   add_filter( 'rewrite_rules_array', 'wps_rewrite_rules' );
            add_filter( 'category_rewrite_rules', 'sub_category_rewrite_rules' );
            add_filter( 'post_rewrite_rules', 'sub_post_rewrite_rules' ); 
    
            add_filter( 'category_link', 'sub_category_link', 10, 2 );
            add_filter( 'post_link', 'sub_post_link', 10, 2 );
        }
    } 
    
    $obj_sub = new initPlugin;
    $obj_sub->addActions();
    $obj_sub->addFilters(); 
    
    function wps_init () {
        if (!is_admin()) {
            // Stuff changed in WP 2.8
            if (function_exists('set_transient')) {
                set_transient('rewrite_rules', "");
                update_option('rewrite_rules', "");
            } else {
                update_option('rewrite_rules', "");
            }
        }
    } 
    
    add_filter( 'root_rewrite_rules', 'wps_root_rewrite_rules' );
    function wps_root_rewrite_rules( $rules ) {
            //$rules = array();
    return $rules;
    }
    function sub_category_rewrite_rules($rules){
        global $obj_sub;
      if($domain = $obj_sub->getSubdomain()){
            $rules = $obj_sub->getRewriteRules();
      }
      return $rules;
    } 
    
    function sub_post_rewrite_rules($rules){
    $rules = array ();
        $rules['[^/]+/attachment/([^/]+)/?$']='index.php?attachment=$matches[1]';
        $rules['[^/]+/attachment/([^/]+)/trackback/?$'] ='index.php?attachment=$matches[1]&tb=1';
        $rules['[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$'] ='index.php?attachment=$matches[1]&feed=$matches[2]';
        $rules['[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$'] ='index.php?attachment=$matches[1]&feed=$matches[2]';
        $rules['[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$'] ='index.php?attachment=$matches[1]&cpage=$matches[2]';
        $rules['([^/]+)/trackback/?$'] ='index.php?name=$matches[1]&tb=1';
        $rules['([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?name=$matches[1]&feed=$matches[2]';
        $rules['([^/]+)/(feed|rdf|rss|rss2|atom)/?$'] ='index.php?name=$matches[1]&feed=$matches[2]';
        $rules['([^/]+)/page/?([0-9]{1,})/?$'] ='index.php?name=$matches[1]&paged=$matches[2]';
        $rules['([^/]+)/comment-page-([0-9]{1,})/?$'] ='index.php?name=$matches[1]&cpage=$matches[2]';
        $rules['([^/]+)(/[0-9]+)?/?$']='index.php?name=$matches[1]&page=$matches[2]';
        $rules['[^/]+/([^/]+)/?$'] ='index.php?attachment=$matches[1]';
        $rules['[^/]+/([^/]+)/trackback/?$'] ='index.php?attachment=$matches[1]&tb=1';
        $rules['[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$'] ='index.php?attachment=$matches[1]&feed=$matches[2]';
        $rules['[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?attachment=$matches[1]&feed=$matches[2]';
        $rules['[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$']= 'index.php?attachment=$matches[1]&cpage=$matches[2]';
        return $rules;
    } 
    
    function sub_category_link( $link, $term_id ) {
        $link = str_replace('www.','',$link);
        $link = preg_replace('/(?<=http\:\/\/)([a-z0-9_\-\.]+)\/category(.*)\/([a-z0-9_\-]+)/','$3.$1', $link);
        return $link;
    } 
    
    function sub_post_link( $link, $id ){
       $link = str_replace('www.','',$link);
       $link = preg_replace('/(?<=http\:\/\/)([a-z0-9_\-\.]+)\/(.*)\/([a-z0-9\-\_]+)\/([a-z0-9\-\_]+)/','$3.$1/$4', $link);
       $link = preg_replace('/(?<=http\:\/\/)([a-z0-9_\-\.]+)\/([a-z0-9\-\_]+)\/([a-z0-9\-\_]+)/','$2.$1/$3', $link);
       return $link;
    }
    ?>
    PHP:

     
    wWhat, Mar 4, 2012 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Your first post in over three years is a big one, which is why I'm sure nobody has bothered to help you ;) I'd suggest you take it up with the plugin maintainer, as it's really their problem - plus, there could be a million things causing it.
     
    Alex Roxon, Mar 5, 2012 IP