Add author to the generated permalink?

29 views
Skip to first unread message

Michael Mahoney

unread,
Jun 6, 2012, 4:41:15 PM6/6/12
to wp-documen...@googlegroups.com
Hi, firstly, this plugin is making my life nice. Thanks. :)

I've got a bunch of authors, each of whom is likely to submit documents with the same name (e.g. "Biography.doc"). The problem is that then I just get a bunch of permalinks that look like:

http://mysite.com/documents/biography-97.doc

which is kind of ugly and non-informative. I'd love to have be able to have them look like:

http://mysite.com/documents/username-biography.doc

I've been playing around with your "document_permalink" filter, but I'm having trouble making it work the way I want, and I thought you might be able to help.

Ideally, what I would want is for WordPress, when you first publish the document, to prepend the username to the $post->post_name (and then of course the file extension). But I'd like to be able to still manually modify it afterwards, so it's really just a matter of adding the username to the initial, automatically created permalink. Is that possible?

If that can't be done, I would be almost as happy with a situation where the permalink just has the username at the beginning of the permalink and that part is not editable.

Thanks in advance for any help with this.

Benjamin J. Balter

unread,
Jun 7, 2012, 8:15:25 AM6/7/12
to wp-documen...@googlegroups.com
I would take a look at the filter `wp_insert_post_data` -> http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data.

It fires on every post save, so you'll want to check if it's the first save or an update, but it shouldn't be hard to grab the current user nicename and prepend it to the post_name field.

Mucking around with `document_permalink` would require changing the rewrite rules most likely, which is overkill for this, in my opinion.

Hope that helps,
- Ben


--
You received this message because you are subscribed to the Google Groups "WP Document Revisions" group.
To view this discussion on the web visit https://groups.google.com/d/msg/wp-document-revisions/-/6eNEREu4PrcJ.
To post to this group, send email to wp-documen...@googlegroups.com.
To unsubscribe from this group, send email to wp-document-revi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wp-document-revisions?hl=en.

Michael Mahoney

unread,
Jun 7, 2012, 4:29:06 PM6/7/12
to wp-documen...@googlegroups.com
Excellent, thanks for the pointer. It took some figuring out, but I got it.
Reply all
Reply to author
Forward
0 new messages