Title: [Plugin: Custom permalinks] Bugs
Last modified: August 24, 2016

---

# [Plugin: Custom permalinks] Bugs

 *  [mponiek](https://wordpress.org/support/users/mponiek/)
 * (@mponiek)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/plugin-custom-permalinks-bugs/)
 * Hello,
 * I have installed plugin [Custom Permalinks](https://wordpress.org/plugins/custom-permalinks/)
   in a project which is under development.
 * The project has enabled the PHP errors and I have found two “bugs” in the file
   plugins/custom-permalinks/custom-permalinks.php of the plugin.
 * **1) Line 267**
 *     ```
       function custom_permalinks_trailingslash($string, $type) {
         global $_CPRegisteredURL;
   
         $url = parse_url(get_bloginfo('url'));
         $request = ltrim(isset($url['path']) ? substr($string, strlen($url['path'])) : $string, '/');
   
         if ( !trim($request) ) return $string;
   
         if ( trim($_CPRegisteredURL,'/') == trim($request,'/') ) {
           return ($string{0} == '/' ? '/' : '') . trailingslashit($url['path']) . $_CPRegisteredURL;
         }
         return $string;
       }
       ```
   
 * WordPress function get_bloginfo(‘url’) gets home url.
 * In case the option home_url is the same with domain i.e. [http://www.domain.com](http://www.domain.com),
   the $url[‘path’] is not set.
 * So, the expression
 * `return ($string{0} == '/' ? '/' : '') . trailingslashit($url['path']) . $_CPRegisteredURL;`
 * produces the warning
    _Undefined index: path_
 * In case the home_url points to a subfolder of the domain i.e.
    [http://www.domain.com/subfolder](http://www.domain.com/subfolder),
   the $url[‘path’] is set and the function is working properly.
 * I updated the function like this:
 *     ```
       function custom_permalinks_trailingslash($string, $type) {
         global $_CPRegisteredURL;
   
         $url = parse_url(get_bloginfo('url'));
         $request = ltrim(isset($url['path']) ? substr($string, strlen($url['path'])) : $string, '/');
   
         if ( !trim($request) ) return $string;
   
         if ( trim($_CPRegisteredURL,'/') == trim($request,'/') && isset($url['path']) ) {
           return ($string{0} == '/' ? '/' : '') . trailingslashit($url['path']) . $_CPRegisteredURL;
         }
         return $string;
       }
       ```
   
 * and it **seems** that is working for both cases.
 * **2) Line 292**
 *     ```
       function custom_permalink_get_sample_permalink_html($html, $id, $new_title, $new_slug) {
           $permalink = get_post_meta( $id, 'custom_permalink', true );
         $post = &get_post($id);
   
         ob_start();
         ?>
         <?php custom_permalinks_form($permalink, ($post->post_type == "page" ? custom_permalinks_original_page_link($id) : custom_permalinks_original_post_link($id)), false); ?>
         <?php
         $content = ob_get_contents();
         ob_end_clean();
   
           if ( 'publish' == $post->post_status ) {
               $view_post = 'page' == $post->post_type ? __('View Page') : __('View Post');
         }
   
         if ( preg_match("@view-post-btn.*?href='([^']+)'@s", $html, $matches) ) {
             $permalink = $matches[1];
           } else {
               list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
               if ( false !== strpos($permalink, '%postname%') || false !== strpos($permalink, '%pagename%') ) {
                   $permalink = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
               }
           }
   
         return '<strong>' . __('Permalink:') . "</strong>\n" . $content .
              ( isset($view_post) ? "<span id='view-post-btn'><a href='$permalink' class='button button-small' target='_blank'>$view_post</a></span>\n" : "" );
       }
       ```
   
 * In the second line of the function, the result of the WP function get_post() 
   assigned to a variable by reference.
    `$post = &get_post($id);`
 * This produces the error:
    _Only variables should be assigned by reference_
 * * NOTE: I am using PHP 5.5
 * I updated the above line to:
    `$post = get_post($id);`
 * and again it **seems** the plugin is working properly.
 * Can you please confirm that the two above changes are correct and they do not
   affect the functionality of the plugin?
 * In case that the changes are correct and they needed, can you please update the
   plugin accordingly?
 * Thank you for your time
 * Best regards
 * Mponiek

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [WPyogi](https://wordpress.org/support/users/wpyogi/)
 * (@wpyogi)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/plugin-custom-permalinks-bugs/#post-6025639)
 * You’re posting in the wrong forum – try here:
    [https://wordpress.org/support/plugin/custom-permalinks#postform](https://wordpress.org/support/plugin/custom-permalinks#postform)
 * Don’t add brackets to your topic line, please – it doesn’t do anything – when
   you post in the sub-forum they are added automatically.
 *  Thread Starter [mponiek](https://wordpress.org/support/users/mponiek/)
 * (@mponiek)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/plugin-custom-permalinks-bugs/#post-6025653)
 * Thank you for the information.
 * I will post my question there.
 * Is there any way to remove it from here to avoid any confusion?
 *  [WPyogi](https://wordpress.org/support/users/wpyogi/)
 * (@wpyogi)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/plugin-custom-permalinks-bugs/#post-6025656)
 * I’ll close this one and include a link to the new one :)!
 * [https://wordpress.org/support/topic/php-warnings-30?replies=1](https://wordpress.org/support/topic/php-warnings-30?replies=1)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘[Plugin: Custom permalinks] Bugs’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [WPyogi](https://wordpress.org/support/users/wpyogi/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/plugin-custom-permalinks-bugs/#post-6025656)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
