Make WordPress Core

Changeset 31131


Ignore:
Timestamp:
01/10/2015 09:20:01 PM (10 years ago)
Author:
wonderboymusic
Message:

In edit-form-advanced.php:

  • get_permalink( $post_ID ) can return false, set it to a variable and check it
  • Using the variable allows us to replace 11 separate calls to get_permalink( $post_ID ) in the file
  • These notices were triggered by the potential for false to be passed to esc_url()

See #30799.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-advanced.php

    r31121 r31131  
    6666 * @todo Document the $messages array(s).
    6767 */
     68$permalink = get_permalink( $post_ID );
     69if ( ! $permalink ) {
     70    $permalink = '';
     71}
     72
    6873$messages = array();
    6974$messages['post'] = array(
    7075     0 => '', // Unused. Messages start at index 1.
    71      1 => sprintf( __('Post updated. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ),
     76     1 => sprintf( __('Post updated. <a href="%s">View post</a>'), esc_url( $permalink ) ),
    7277     2 => __('Custom field updated.'),
    7378     3 => __('Custom field deleted.'),
     
    7580    /* translators: %s: date and time of the revision */
    7681     5 => isset($_GET['revision']) ? sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    77      6 => sprintf( __('Post published. <a href="%s">View post</a>'), esc_url( get_permalink($post_ID) ) ),
     82     6 => sprintf( __('Post published. <a href="%s">View post</a>'), esc_url( $permalink ) ),
    7883     7 => __('Post saved.'),
    79      8 => sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     84     8 => sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
    8085     9 => sprintf( __('Post scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview post</a>'),
    8186        /* translators: Publish box date format, see http://php.net/date */
    82         date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    83     10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     87        date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ),
     88    10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
    8489);
    8590$messages['page'] = array(
    8691     0 => '', // Unused. Messages start at index 1.
    87      1 => sprintf( __('Page updated. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ),
     92     1 => sprintf( __('Page updated. <a href="%s">View page</a>'), esc_url( $permalink ) ),
    8893     2 => __('Custom field updated.'),
    8994     3 => __('Custom field deleted.'),
    9095     4 => __('Page updated.'),
    9196     5 => isset($_GET['revision']) ? sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    92      6 => sprintf( __('Page published. <a href="%s">View page</a>'), esc_url( get_permalink($post_ID) ) ),
     97     6 => sprintf( __('Page published. <a href="%s">View page</a>'), esc_url( $permalink ) ),
    9398     7 => __('Page saved.'),
    94      8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    95      9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    96     10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
     99     8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
     100     9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ),
     101    10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
    97102);
    98103$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now.
     
    486491$sample_permalink_html = $post_type_object->public ? get_sample_permalink_html($post->ID) : '';
    487492$shortlink = wp_get_shortlink($post->ID, 'post');
    488 $permalink = get_permalink( $post->ID );
     493
    489494if ( !empty( $shortlink ) && $shortlink !== $permalink && $permalink !== home_url('?page_id=' . $post->ID) )
    490495    $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>';
Note: See TracChangeset for help on using the changeset viewer.