Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_stop_product_uri($bool, $post) {
- if(!empty($post) && $post->post_type == 'product' && empty($post->post_content)) {
- return false;
- }
- return $bool;
- }
- add_filter('permalink_manager_allow_new_post_uri', 'pm_stop_product_uri', 9, 2);
- add_filter('permalink_manager_allow_update_post_uri', 'pm_stop_product_uri', 9, 2);
- function pm_set_custom_permalink($post_id, $post) {
- global $permalink_manager_uris;
- // Update only selected product post type permalinks
- if(!empty($post->post_type) && $post->post_type !== 'product') { return; }
- // Do not do anything if post is autosaved
- if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; }
- // Do not do anything if the post is manually updated/saved from "Edit product" page
- if(isset($_POST['custom_uri']) || isset($_POST['permalink-manager-edit-uri-element-id'])) { return; }
- if(!empty($permalink_manager_uris)) {
- $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id);
- if($default_uri) {
- $permalink_manager_uris[$post_id] = $default_uri;
- update_option('permalink-manager-uris', $permalink_manager_uris);
- }
- }
- }
- add_action('save_post', 'pm_set_custom_permalink', 100, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement