Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_update_product_uri($post) {
- global $permalink_manager_uris, $permalink_manager_options;
- // Do not do anything if post is autosaved
- if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post; }
- // Do not do anything if the field with URI or element ID are present
- if(isset($_POST['custom_uri']) || !empty($_POST['permalink-manager-edit-uri-element-id'])) { return $post; }
- // Get the full post object
- $post_object = (!empty($post->ID)) ? $post : get_post($post);
- // Check the post type
- if(empty($post_object->post_type) || $post_object->post_type !== 'product') { return $post; };
- // Ignore auto-drafts, removed posts and posts without title
- if(in_array($post_object->post_status, array('auto-draft', 'trash')) || empty($post_object->post_title)) { return $post_id; }
- // Get the post ID
- $post_id = $post_object->ID;
- // Get auto-update URI setting (if empty use global setting)
- $auto_update_uri = get_post_meta($post_id, "auto_update_uri", true);
- $auto_update_uri = (!empty($auto_update_uri)) ? $auto_update_uri : $permalink_manager_options["general"]["auto_update_uris"];
- if($auto_update_uri == 1) {
- // Get the default URI
- $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id);
- // Save the default URI
- Permalink_Manager_URI_Functions::save_single_uri($post_id, $default_uri, false, true);
- }
- }
- add_action('save_post', 'pm_update_product_uri', 99, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement