WordPress.org

Ready to get started?Download WordPress

Forums

WP Hashed IDs
Support for custom post types (3 posts)

  1. tsahil
    Member
    Posted 1 year ago #

    Hi,

    It would be great if you could add support for custom post types for this one.

    The closest I got with it is by adding this code:

    function hashed_id() {
        global $wp_rewrite;
        add_rewrite_tag('%hashed_id%','([^/]+)');
        $permalink = $wp_rewrite->permalink_structure;
        if (!empty($permalink) && false !== strpos( $permalink, '%hashed_id%' )) {
            add_filter('pre_post_link', '_hashed_id_post_link', 10, 2);
            add_filter('post_type_link', '_hashed_id_custom_link', 1, 2);
            add_filter('parse_request', '_hashed_id_parse_request');
        }
    }
    
    function _hashed_id_post_link($permalink, $post) {
        $hashids = new hashids(AUTH_KEY, HASHED_IDS_MIN_LENGTH);
        $permalink = str_replace('%hashed_id%', $hashids->encrypt((int)$post->ID), $permalink);
        return $permalink;
    }
    
    function _hashed_id_custom_link($permalink, $post) {
        $hashids = new hashids(AUTH_KEY, HASHED_IDS_MIN_LENGTH);
        $permalink = str_replace('%hashed_id%', $hashids->encrypt((int)$post->ID), $permalink);
        return $permalink;
    }

    http://wordpress.org/extend/plugins/wp-hashed-ids/

  2. palicao
    Member
    Plugin Author

    Posted 1 year ago #

    Hi tsahil, thanks for yor suggestion!
    Tomorrow I'll test your code and eventually include in the plugin.
    Best,
    palicao

  3. idosius
    Member
    Posted 1 year ago #

    Will the solution be added to the next plugin version?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic