SHOW:
|
|
- or go back to the newest paste.
| 1 | /** | |
| 2 | - | * Use %store% in Products' permastructure settings |
| 2 | + | * Random string in permastructure |
| 3 | * Use %random% in "Permastructure" settings | |
| 4 | - | function pm_dokan_store_field($default_uri, $native_slug, $post, $slug, $native_uri) {
|
| 4 | + | |
| 5 | function pm_random_string_field($default_uri, $native_slug, $post, $slug, $native_uri) {
| |
| 6 | - | if($native_uri == true || empty($post->post_type) || $post->post_type !== 'product') { return $default_uri; }
|
| 6 | + | |
| 7 | - | |
| 7 | + | if($native_uri == true || empty($post->post_type)) { return $default_uri; }
|
| 8 | - | if(strpos($default_uri, '%store%') !== false) {
|
| 8 | + | |
| 9 | - | $store_name = get_user_meta($post->post_author, 'dokan_store_name', true); |
| 9 | + | if(strpos($default_uri, '%random%') !== false) {
|
| 10 | - | $default_uri = str_replace('%store%', sanitize_title($store_name), $default_uri);
|
| 10 | + | $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 11 | $length = 12; | |
| 12 | - | |
| 12 | + | $random_string = substr(str_shuffle($chars), 0, $length); |
| 13 | ||
| 14 | $default_uri = str_replace('%random%', $random_string, $default_uri);
| |
| 15 | - | add_filter('permalink_manager_filter_default_post_uri', 'pm_dokan_store_field', 3, 5); |
| 15 | + | |
| 16 | ||
| 17 | return $default_uri; | |
| 18 | } | |
| 19 | add_filter('permalink_manager_filter_default_post_uri', 'pm_random_string_field', 3, 5); |