Support » Plugin: WP Document Revisions » Automatic Post title from filename

  • Resolved neocreo

    (@neocreo)


    I have a client who prefers to upload first and ask questions later – for instance “what was the name of that file I just uploaded?”

    Does anyone know of a way to grab the filename on upload and populate the post-title field (if empty of course).

    I have a little idea of how this could be done via jQuery, but am not sure on how I can hook it to run when the file has uploaded.

    Any suggestions or better solutions are welcome.

    https://wordpress.org/plugins/wp-document-revisions/

Viewing 1 replies (of 1 total)
  • neocreo

    (@neocreo)

    OK, if anyone is interested, I solved it the following way – and hopefully the author sees this – might add this to the next version of the plugin.

    I only needed this run when first uploading a document, so I hacked the following file: wp-content/plugins/wp-document-revisions/js/wp-document-revisions.js
    I ran the code through jspretty to find the correct place.
    find the prototype
    WPDocumentRevisions.prototype.postDocumentUpload = function (file, attachmentID)
    At the end of the function I added the following jQuery

    var filename = file.split(".")[0];
                if (this.window.jQuery('#title').val() == '') {
                	 this.window.jQuery('#title').focus().val(filename);
                };

    What is does is simply checking whether the document title is empty, if so it will set the focus on the field and fill it with the file-name with the file ending removed.

    I think it could be useful for new users, especially since the filename is not visible anywhere after upload.

Viewing 1 replies (of 1 total)
  • The topic ‘Automatic Post title from filename’ is closed to new replies.