gelembjuk
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: Permalinks for my pluginI have found solution that works for me.
I have get code from plugin “Custom parmelinks”This is part of original code of that plugin:
add_filter( 'request', 'custom_permalinks_request', 10, 1 ); function custom_permalinks_request($query) { // Get request URI, strip parameters and /'s $url = parse_url(get_bloginfo('url')); $url = $url['path']; $request = ltrim(substr($_SERVER['REQUEST_URI'], strlen($url)),'/'); $request = (($pos=strpos($request, '?')) ? substr($request, 0, $pos) : $request); $request_noslash = preg_replace('@/+@','/', trim($request, '/')); if ( !$request ) return $query; //.......................... if ( !$originalUrl ) { $table = get_option('custom_permalink_table'); if ( !$table ) return $query; foreach ( array_keys($table) as $permalink ) { if ( $permalink == substr($request_noslash, 0, strlen($permalink)) || $permalink == substr($request_noslash."/", 0, strlen($permalink)) ) { $term = $table[$permalink]; // Preserve this url for later if it's the same as the permalink (no extra stuff) if ( $request_noslash == trim($permalink,'/') ) $_CPRegisteredURL = $request; if ( $term['kind'] == 'category') { $originalUrl = str_replace(trim($permalink,'/'), custom_permalinks_original_category_link($term['id']), trim($request,'/')); } else { $originalUrl = str_replace(trim($permalink,'/'), custom_permalinks_original_tag_link($term['id']), trim($request,'/')); } } } } if ( $originalUrl ) { if ( ($pos=strpos($_SERVER['REQUEST_URI'], '?')) !== false ) { $queryVars = substr($_SERVER['REQUEST_URI'], $pos+1); $originalUrl .= (strpos($originalUrl, '?') === false ? '?' : '&') . $queryVars; } // Now we have the original URL, run this back through WP->parse_request, in order to // parse parameters properly. We set $_SERVER variables to fool the function. $oldPathInfo = $_SERVER['PATH_INFO']; $oldRequestUri = $_SERVER['REQUEST_URI']; $oldQueryString = $_SERVER['QUERY_STRING']; $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'] = '/'.ltrim($originalUrl,'/'); $_SERVER['QUERY_STRING'] = (($pos=strpos($originalUrl, '?')) !== false ? substr($originalUrl, $pos+1) : ''); parse_str($_SERVER['QUERY_STRING'], $queryArray); $oldValues = array(); if ( is_array($queryArray) ) foreach ( $queryArray as $key => $value ) { $oldValues[$key] = $_REQUEST[$key]; $_REQUEST[$key] = $_GET[$key] = $value; } // Re-run the filter, now with original environment in place remove_filter( 'request', 'custom_permalinks_request', 10, 1 ); global $wp; $wp->parse_request(); $query = $wp->query_vars; add_filter( 'request', 'custom_permalinks_request', 10, 1 ); // Restore values $_SERVER['PATH_INFO'] = $oldPathInfo; $_SERVER['REQUEST_URI'] = $oldRequestUri; $_SERVER['QUERY_STRING'] = $oldQueryString; foreach ( $oldValues as $key => $value ) { $_REQUEST[$key] = $value; } } return $query; }
I modified this for my needs and it works.
Viewing 1 replies (of 1 total)