SHOW:
|
|
- or go back to the newest paste.
1 | function pm_set_custom_permalink($post_id, $post, $update) { | |
2 | global $permalink_manager_uris; | |
3 | ||
4 | // Do not trigger when the post is updated | |
5 | // if($update) { return; } | |
6 | ||
7 | // Do not do anything if post is autosaved | |
8 | if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } | |
9 | ||
10 | // Ignore auto-drafts & removed posts | |
11 | if(in_array($post->post_status, array('auto-draft', 'trash'))) { return; } | |
12 | ||
13 | // Update only selected product post type permalinks | |
14 | - | if(!empty($post->post_type) && $post->post_type !== 'product') { return; } |
14 | + | if(empty($post->post_type) || $post->post_type !== 'product') { return; } |
15 | ||
16 | - | if(!empty($permalink_manager_uris) && empty($permalink_manager_uris[$post_id])) { |
16 | + | if(!empty($permalink_manager_uris)) { |
17 | $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id); | |
18 | ||
19 | if($default_uri) { | |
20 | $permalink_manager_uris[$post_id] = $default_uri; | |
21 | update_option('permalink-manager-uris', $permalink_manager_uris); | |
22 | } | |
23 | } | |
24 | } | |
25 | add_action('save_post', 'pm_set_custom_permalink', 100, 3); |