一、修改媒体文件路径为相对路径
文件:/wp-includes/post.php
函数名:wp_get_attachment_url
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
function wp_get_attachment_url( $post_id = 0 ) { $file_dir=dirname(__FILE__); $server_root=$_SERVER[DOCUMENT_ROOT]; $file_dir=substr($file_dir,strlen($server_root)); $file_dir=substr($file_dir,0,-12); if($file_dir!=''){ $file_dir='/'.substr($file_dir,1); } $post_id = (int) $post_id; if ( !$post = get_post( $post_id ) ) return false; if ( 'attachment' != $post->post_type ) return false; $url = ''; // Get attached file. if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { // Get upload directory. if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Check that the upload base exists in the file location. if ( 0 === strpos( $file, $uploads['basedir'] ) ) { // Replace file location with url location. //$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); $url = $file_dir.'/wp-content/uploads/'.$file; } elseif ( false !== strpos($file, 'wp-content/uploads') ) { //$url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 ); $url = $file_dir.'/wp-content/uploads/'.$file; } else { // It's a newly-uploaded file, therefore $file is relative to the basedir. //$url = $uploads['baseurl'] . "/$file"; $url = $file_dir.'/wp-content/uploads/'.$file; } } } /* * If any of the above options failed, Fallback on the GUID as used pre-2.7, * not recommended to rely upon this. */ if ( empty($url) ) { $url = get_the_guid( $post->ID ); } // On SSL front-end, URLs should be HTTPS. if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow'] ) { $url = set_url_scheme( $url ); } /** * Filter the attachment URL. * * @since 2.1.0 * * @param string $url URL for the given attachment. * @param int $post_id Attachment ID. */ $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); if ( empty( $url ) ) return false; return $url; } |
二、修改域名自动获取
文件:/wp-config.php
增加以下代码
1 2 3 4 |
$home = 'http://'.$_SERVER['HTTP_HOST']; $siteurl = 'http://'.$_SERVER['HTTP_HOST']; define('WP_HOME', $home); define('WP_SITEURL', $siteurl); |
三、修改侧边栏最新评论显示为评论内容
文件:/wp-includes/widgets/class-wp-widget-recent-comments.php
找到以下代码
1 2 3 |
$output .= sprintf( _x( '%1$s on %2$s', 'widgets' ), '<span class="comment-author-link">' . get_comment_author_link( $comment ) . '</span>', '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>' |
修改为以下代码
1 2 3 4 |
$output .= sprintf( _x( '%1$s说:%2$s', 'widgets' ), '<span class="comment-author-link">' . get_comment_author_link( $comment ) . '</span>', '<a href="' . esc_url( get_comment_link( $comment ) ) . '" title="' . strip_tags($comment->comment_content) . '">' . wp_trim_words( strip_tags($comment->comment_content), 16, '...' ) . '</a>' ); |
转载请注明:追风逐雨 » 对系统内核文件的修改记录 For WordPress v4.4