我想至少是时候尝试一下删除附件页了。
这是我的第一次尝试。。。
add_filter( \'attachment_fields_to_edit\', \'wpse_25144_attachment_fields_to_edit\', 10000, 2 );
function wpse_25144_attachment_fields_to_edit( $form_fields, $post ) {
$url_type = get_option( \'image_default_link_type\' );
if( \'post\' == $url_type ) {
update_option( \'image_default_link_type\', \'file\' );
$url_type = \'file\';
}
$form_fields[\'url\'] = array(
\'label\' => __(\'Link URL\'),
\'input\' => \'html\',
\'html\' => wpse_25144_image_link_input_fields( $post, $url_type ),
\'helps\' => __(\'Enter a link URL or click above for presets.\')
);
return $form_fields;
}
function wpse_25144_image_link_input_fields($post, $url_type = \'\') {
$file = wp_get_attachment_url($post->ID);
if( empty( $url_type ) )
$url_type = get_user_setting( \'urlbutton\', \'file\' );
$url = \'\';
if( $url_type == \'file\' )
$url = $file;
return "
<input type=\'text\' class=\'text urlfield\' name=\'attachments[$post->ID][url]\' value=\'" . esc_attr($url) . "\' /><br />
<button type=\'button\' class=\'button urlnone\' title=\'\'>" . __(\'None\') . "</button>
<button type=\'button\' class=\'button urlfile\' title=\'" . esc_attr($file) . "\'>" . __(\'File URL\') . "</button>
";
}
add_filter( \'query_vars\', \'wpse_25144_query_vars\', 10000, 2 );
function wpse_25144_query_vars( $wp_query_vars ) {
foreach( $wp_query_vars as $i => $qv ) {
if( in_array( $qv, array( \'attachment\', \'attachment_id\' ) ) )
unset( $wp_query_vars[$i] );
}
return $wp_query_vars;
}
add_filter( \'attachment_link\', \'wpse_25144_attachment_link\', 10000, 2 );
function wpse_25144_attachment_link( $link, $id ) {
$link = wp_get_attachment_url( $id );
return $link;
}
add_filter( \'rewrite_rules_array\', \'wpse_25144_rewrite_rules_array\', 10000 );
function wpse_25144_rewrite_rules_array( $rewriteRules ) {
foreach( $rewriteRules as $pattern => $query_string ) {
if( false === strpos( $pattern, \'attachment\' ) && false === strpos( $query_string, \'attachment\' ) )
continue;
unset( $rewriteRules[$pattern] );
}
return $rewriteRules;
}
删除附件重写,更新附件链接以指向附件文件(而不是永久链接),删除附件查询变量,并删除将附件链接到现在不存在的附件永久链接的功能。
接受批评。:)