[wp-hackers] what function creates the post slug?

Ricardo Moraleida moraleida at gmail.com
Tue Aug 23 16:25:08 UTC 2011


While 3.3 isn't here, though, i got into Dion's wp_insert_post_data filter
suggestion and got this to work:

*function rm_martins_cpt_permalink_change($data, $postarr) {*
* *
* if ($data['post_type'] == 'post_type_name') {*
*
*
*                $time = time();*
* $data['post_name'] = md5($time);*
* return $data;*
* } else {*
*            return $data;*
*        }*
*}*
*add_filter('wp_insert_post_data','rm_martins_cpt_permalink_change',10,2);*

this solution was partly borrowed from a function in wp-includes\ms.php
(line 590 or so) that checks for colliding permalinks over a blog network,
pretty neat.

It just replaces the original post slug with the md5 hash for the unix
timestamp of the last post data insertion, which seems random enough for me
and i hope won't cause me trouble when listing posts in the future.

So, just thought it might be useful to post my result function here, though
it has not been thoroughly tested so far.

thanks for the help!

Ricardo Moraleida



2011/8/23 Ricardo Moraleida <moraleida at gmail.com>

> Just found this http://core.trac.wordpress.org/ticket/14111 saying 3.3
> will have it's own unique post slug filter, so thanks, i believe this case
> is closed.
>
>
> Ricardo Moraleida
>
>
>
> 2011/8/23 Dion Hulse (dd32) <wordpress at dd32.id.au>
>
> I'd be looking into the wp_insert_post_data filter in wp_insert_post()
>> and the "{$field_no_prefix}_save_pre" filter in sanitize_post_field()
>> function, however the latter provides no $context or post object for
>> reference, so you're probably better off filtering on the raw post
>> data..
>>
>> On 24 August 2011 00:19, Ricardo Moraleida <moraleida at gmail.com> wrote:
>> > Hi guys, quick question here...
>> >
>> > i wanted to create a hook to change how WordPress creates slugs on a
>> > specific custom post type that handles quite sensitive data.
>> >
>> > I've just spent a few hours looking at rewrites and such but although
>> the
>> > information is pretty helpful, i just don't think rewriting the slug
>> display
>> > is the way to go, as it would be much safer to just have wp save a fixed
>> md5
>> > slug for that specific post type.
>> >
>> > I imagine there's a simple sanitizing function that takes the post title
>> and
>> > transforms it, and then saves it to the db as slug, but i can't seem to
>> find
>> > it.
>> >
>> > Any help?
>> >
>> > thanks!
>> >
>> > Ricardo Moraleida
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>


More information about the wp-hackers mailing list