View difference between Paste ID: SLyup8Z4 and GZH3N247
SHOW: | | - or go back to the newest paste.
1
function pm_stop_product_uri($bool, $post) {
2-
	if(!empty($post) && $post->post_type == 'product' && $post->post_title == 'Product') {
2+
	if(!empty($post) && $post->post_type == 'product' && empty($post->post_content)) {
3
		return false;
4
	}
5
	
6
	return $bool;
7
}
8
add_filter('permalink_manager_allow_new_post_uri', 'pm_stop_product_uri', 9, 2);
9
add_filter('permalink_manager_allow_update_post_uri', 'pm_stop_product_uri', 9, 2);
10
11
function pm_set_custom_permalink($post_id, $post) {
12
    global $permalink_manager_uris;
13
 
14
    // Update only selected product post type permalinks
15
    if(!empty($post->post_type) && $post->post_type !== 'product') { return; }
16
17
	// Do not do anything if post is autosaved
18
	if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; }
19
20
	// Do not do anything if the post is manually updated/saved from "Edit product" page
21
	if(isset($_POST['custom_uri']) || isset($_POST['permalink-manager-edit-uri-element-id'])) { return; }
22
 
23
    if(!empty($permalink_manager_uris)) {
24
        $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id);
25
 
26
        if($default_uri) {
27
            $permalink_manager_uris[$post_id] = $default_uri;
28
            update_option('permalink-manager-uris', $permalink_manager_uris);
29
        }
30
    }
31
}
32
add_action('save_post', 'pm_set_custom_permalink', 100, 2);