[wp-trac] [WordPress Trac] #53025: Change to get_permalink in 5.7 breaks existing code

WordPress Trac noreply at wordpress.org
Tue Apr 13 01:09:57 UTC 2021


#53025: Change to get_permalink in 5.7 breaks existing code
--------------------------+-----------------------------
 Reporter:  turbodb       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Security      |    Version:  5.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 This is a follow-up to #5272.

 I have the following code, which I’ve registered as a custom column on the
 admin pages, to show me the permalink (or what will be the permalink) for
 posts that are not yet published.

 For example, if the post title is “My First Post” then the column will
 show
 {{{
 http://site/my-first-post/
 }}}
  as the permalink, even when the post is in draft state.

 This worked just fine for many versions. I recently updated to 5.7. Now,
 this code is no longer working; it is simply returning a permalink of the
 form
 {{{
 http://site/?p=postID
 }}}


 I’ve check the code and all lines work as expected, except for

 {{{
 $url = get_permalink($my_post);
 }}}

 {{{#!php
 <?php
 function atp_post_permalink_column() {
     add_filter('manage_posts_columns', 'atp_permalink_column_head');
     add_action('manage_posts_custom_column', 'atp_permalink_content', 9,
 2);
 }

 function atp_permalink_column_head($default) {
     $default['permalink'] = 'Permalink';
     return $default;
 }

 function atp_permalink_content($column, $post_id) {
         if ($column == 'permalink') {

                 $post = get_post( $post_id );
                 $url = '';
                 if (in_array($post->post_status, array('draft', 'pending',
 'auto-draft', 'future'))) {
                         $my_post = clone $post;
                         $my_post->post_status = 'published';
                         $my_post->post_name =
 sanitize_title($my_post->post_name ? $my_post->post_name :
 $my_post->post_title, $my_post->ID);

                         $url = get_permalink($my_post);
                 } else {
                         $url = get_permalink($post);
                 }

                 echo $url;
         }
 }
 }}}



 This appears to be due to change 5272.

 This is my first ticket, apologies if I've got any of the fields set
 incorrectly. Please update as appropriate.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53025>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list