Make WordPress Core

Changeset 28947


Ignore:
Timestamp:
07/02/2014 12:03:53 AM (10 years ago)
Author:
SergeyBiryukov
Message:

Simplify logic in get_sample_permalink_html(), remove duplicated code.

see #28350.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r28946 r28947  
    11931193    }
    11941194
    1195     if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
     1195    if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
    11961196        $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
    11971197        if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) {
    11981198            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
    11991199        }
    1200 
    1201         if ( isset( $view_post ) ) {
    1202             if( 'draft' == $post->post_status ) {
    1203                 $preview_link = set_url_scheme( get_permalink( $post->ID ) );
    1204                 /** This filter is documented in wp-admin/includes/meta-boxes.php */
    1205                 $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) );
    1206                 $return .= "<span id='view-post-btn'><a href='" . esc_url( $preview_link ) . "' class='button button-small' target='wp-preview-{$post->ID}'>$view_post</a></span>\n";
     1200    } else {
     1201        if ( function_exists( 'mb_strlen' ) ) {
     1202            if ( mb_strlen( $post_name ) > 30 ) {
     1203                $post_name_abridged = mb_substr( $post_name, 0, 14 ) . '&hellip;' . mb_substr( $post_name, -14 );
    12071204            } else {
    1208                 $return .= "<span id='view-post-btn'><a href='" . get_permalink( $post ) . "' class='button button-small'>$view_post</a></span>\n";
     1205                $post_name_abridged = $post_name;
    12091206            }
    1210         }
    1211 
    1212         /**
    1213          * Filter the sample permalink HTML markup.
    1214          *
    1215          * @since 2.9.0
    1216          *
    1217          * @param string      $return    Sample permalink HTML markup.
    1218          * @param int|WP_Post $id        Post object or ID.
    1219          * @param string      $new_title New sample permalink title.
    1220          * @param string      $new_slug  New sample permalink slug.
    1221          */
    1222         $return = apply_filters( 'get_sample_permalink_html', $return, $id, $new_title, $new_slug );
    1223 
    1224         return $return;
    1225     }
    1226 
    1227     if ( function_exists('mb_strlen') ) {
    1228         if ( mb_strlen($post_name) > 30 ) {
    1229             $post_name_abridged = mb_substr($post_name, 0, 14). '&hellip;' . mb_substr($post_name, -14);
    12301207        } else {
    1231             $post_name_abridged = $post_name;
    1232         }
    1233     } else {
    1234         if ( strlen($post_name) > 30 ) {
    1235             $post_name_abridged = substr($post_name, 0, 14). '&hellip;' . substr($post_name, -14);
    1236         } else {
    1237             $post_name_abridged = $post_name;
    1238         }
    1239     }
    1240 
    1241     $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    1242     $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
    1243 
    1244     $return =  '<strong>' . __('Permalink:') . "</strong>\n";
    1245     $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
    1246     $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
    1247     $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
    1248     $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
     1208            if ( strlen( $post_name ) > 30 ) {
     1209                $post_name_abridged = substr( $post_name, 0, 14 ) . '&hellip;' . substr( $post_name, -14 );
     1210            } else {
     1211                $post_name_abridged = $post_name;
     1212            }
     1213        }
     1214
     1215        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
     1216        $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, $permalink );
     1217
     1218        $return =  '<strong>' . __( 'Permalink:' ) . "</strong>\n";
     1219        $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
     1220        $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
     1221        $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __( 'Edit' ) . "</a></span>\n";
     1222        $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
     1223    }
    12491224
    12501225    if ( isset( $view_post ) ) {
     
    12591234    }
    12601235
    1261     /** This filter is documented in wp-admin/includes/post.php */
     1236    /**
     1237     * Filter the sample permalink HTML markup.
     1238     *
     1239     * @since 2.9.0
     1240     *
     1241     * @param string      $return    Sample permalink HTML markup.
     1242     * @param int|WP_Post $id        Post object or ID.
     1243     * @param string      $new_title New sample permalink title.
     1244     * @param string      $new_slug  New sample permalink slug.
     1245     */
    12621246    $return = apply_filters( 'get_sample_permalink_html', $return, $id, $new_title, $new_slug );
    12631247
Note: See TracChangeset for help on using the changeset viewer.