Viewing 3 replies - 1 through 3 (of 3 total)
  • Sometimes, unexplainable 404’s can be solved by resaving the Permalink Settings within WordPress.

    Thread Starter neocreo

    (@neocreo)

    This is not a permalink issue.
    This is a question of the link to the file being wrong.

    If you change the file type, all previous versions are assumed to have the same filetype – and then the links won’t work.

    Why is it that when putting together the permalink that it can’t look on the mime-type and do the file ending from there? Or save the file ending in the post-meta, or even check the file that it links to and grab the file ending from there?

    If you do not believe me, try it yourself – upload a .doc file, then upload a .xls file and finally a .pdf.

    This is an issue that must be fixed.

    I have traced this now to the function

    function filename_rewrite( $file ) {
    
    		//verify this is a document
    		if ( !$this->verify_post_type( $_POST['post_id'] ) )
    			return $file;
    
    		//hash and replace filename, appending extension
    		$file['name'] = md5( $file['name'] .time() ) . $this->get_extension( $file['name'] );
    
    		$file = apply_filters( 'document_internal_filename', $file );
    
    		return $file;
    
    	}

    in wp-document-revisions.php

    $this->get_extension( $file['name'] ) seem to take the extension from the filename, and that filename is the name of the current version.

    I am not a PHP-developer, but if anyone has a solution to this I would very much appreciate this.

    Ok I believe what you are looking for is this:
    Unfortunately there isn’t a filter or action I can just use, but here is the solution… hopefully Ben will add this in, because mime type and file extension mismatches are a problem for IE security settings and some proxy servers…

    In the file:
    \wp-content\plugins\wp-document-revisions\includes\admin.php
    @line 405 just after the line that says: “continue;”

    Add this code:

    if(is_numeric($revision->post_content)){
    	$fn = get_post_meta( $revision->post_content, '_wp_attached_file', true );
    	$fno = pathinfo($fn);
    	$info = pathinfo(get_permalink( $revision->ID ));
    	$fn = $info['dirname'].'/'.$info['filename'].'.'.$fno['extension'];
    	}else{ $fn = get_permalink( $revision->ID ); }

    Then just below there you will find the code where the revisions list is generated…
    Change
    <td><a href="<?php echo get_permalink( $revision->ID ); ?>"
    To
    <td><a href="<?php echo $fn; ?>"

    Then each revision link will have the proper extension.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Previous versions of document give 404 not found’ is closed to new replies.