Change WordPress user roles and capabilities Forums Bug Reports Content View Restrictions Redirect to URL

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5265
    jastelpac
    Participant

    When a page with a content view restriction is opened, rather than redirecting to the URL set on the page, I get a 404 error. It seems that the function get_page_path_from_url is failing because it is using a full path and relative path.

    The location of the file is /var/www/html/wp-content/plugins/user-role-editor-pro/pro/includes/classes/content-view-restrictions.php line 924.

    I was able to make the functionality work with the changes below and seek your opinion on whether the changes will have any undesired outcomes?

    private static function get_page_path_from_url() {
    $url = substr(untrailingslashit( parse_url( $_SERVER[‘REQUEST_URI’], PHP_URL_PATH) ), 1 );
    $home_url = basename( untrailingslashit( parse_url( home_url(), PHP_URL_PATH) ) );
    $path = substr($url, strlen($home_url));
    return $path;
    }

    #5269
    Vladimir
    Keymaster

    Thanks for suggestion. It makes code more universal. I accept it with a little addition to remove a beginning slash from a resulting value, if it’s there:

    
        private static function get_page_path_from_url() {
    
            $url = substr( untrailingslashit( parse_url( $_SERVER['REQUEST_URI'] , PHP_URL_PATH) ), 1);
            $home_url = basename( untrailingslashit( parse_url( home_url(), PHP_URL_PATH ) ) );
            $path = substr( $url, strlen( $home_url ) );
            if (substr( $path, 0, 1)==DIRECTORY_SEPARATOR) {
                $path = substr( $path, 1);
            }        
            
            return $path;
        }
        // end of get_page_path_from_url()
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.