WordPress.org

Plugin Directory

Changeset 1637264


Ignore:
Timestamp:
04/14/17 00:01:29 (11 days ago)
Author:
mbis
Message:

Dev version 1.0.4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • permalink-manager/tags/1.0.4/includes/core/permalink-manager-uri-functions-post.php

    r1637229 r1637264  
    101101        $post_id = $post->ID; 
    102102        $post_type = $post->post_type; 
    103         $post_name = $post->post_name; 
     103        $post_name = (empty($post->post_name)) ? sanitize_title($post->post_title) : $post->post_name; 
    104104 
    105105        // Get the permastruct 
     
    125125        // 2. Fix for hierarchical CPT (start) 
    126126        $full_slug = ($native_uri == false) ? apply_filters('permalink_manager_filter_default_post_slug', get_page_uri($post), $post, $post_name) : get_page_uri($post); 
     127        $full_slug = (empty($full_slug)) ? $post_name : $full_slug; 
    127128        $post_type_tag = Permalink_Manager_Helper_Functions::get_post_tag($post_type); 
    128129 
     
    389390        global $permalink_manager_uris, $sitepress_settings; 
    390391 
     392        // Detect auto drafts 
     393        $autosave = (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) ? true : false; 
     394 
    391395        // Get the post object 
    392396        $post = get_post($id); 
    393397 
    394         // Try to alter the slug in auto-drafts ... 
    395         $new_slug = (empty($new_slug) && !empty($new_title)) ? sanitize_title($new_title) : $new_slug; 
    396         // ... and saved drafts 
    397         $new_slug = (empty($new_slug) && !empty($post->post_title)) ? sanitize_title($post->post_title) : $new_slug; 
    398  
    399398        // Do not do anything if new slug is empty or page is front-page 
    400         if(empty($new_slug) || get_option('page_on_front') == $id) { return $html; } 
     399        if( get_option('page_on_front') == $id) { return $html; } 
    401400 
    402401        $html = preg_replace("/(<strong>(.*)<\/strong>)(.*)/is", "$1 ", $html); 
    403402        $default_uri = self::get_default_post_uri($id); 
    404         $default_uri .= (empty($post->post_name)) ? apply_filters("permalink_manager_filter_default_post_draft_slug", "/{$new_slug}", $post) : ""; 
     403 
    405404        // Make sure that home URL ends with slash 
    406405        $home_url = trim(get_option('home'), "/") . "/"; 
     
    427426 
    428427        // Do not change anything if post is not saved yet (display sample permalink instead) 
    429         if(empty($post->post_status) || empty($post->post_name)) { 
     428        if($autosave || empty($post->post_status)) { 
    430429            $sample_permalink = $home_url . str_replace("//", "/", trim("{$language_code}{$default_uri}", "/")); 
    431430 
     
    458457    */ 
    459458    function update_post_uri($post_id, $post, $update) { 
    460         global $permalink_manager_uris, $permalink_manager_options, $permalink_manager_before_sections_html;; 
     459        global $permalink_manager_uris, $permalink_manager_options, $permalink_manager_before_sections_html; 
    461460 
    462461        // Fix for revisions 
     
    466465 
    467466        // Ignore auto-drafts & removed posts 
    468         if(in_array($post->post_status, array('auto-draft', 'trash')) || !isset($_POST['custom_uri'])) { return; } 
     467        if(in_array($post->post_status, array('auto-draft', 'trash')) || empty($post->post_name) || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) { return; } 
    469468 
    470469        $default_uri = self::get_default_post_uri($post_id); 
Note: See TracChangeset for help on using the changeset viewer.