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