問題描述
我想從個人資料頁面中刪除或隱藏 「傳記」 輸入字段。你怎麼做到這一點?我已經從此頁面中刪除了一些聯繫方式,但我不知道如何擺脱傳記。
最佳解決方案
沒有專用的鈎子 – 用户管理在 WordPress 中是一個低優先級。你必須使用輸出緩衝 (是的,不太好) 。
這是一個簡單的演示如何做到這一點:
add_action( 'personal_options', array ( 'T5_Hide_Profile_Bio_Box', 'start' ) );
/**
* Captures the part with the biobox in an output buffer and removes it.
*
* @author Thomas Scholz, <info@toscho.de>
*
*/
class T5_Hide_Profile_Bio_Box
{
/**
* Called on 'personal_options'.
*
* @return void
*/
public static function start()
{
$action = ( IS_PROFILE_PAGE ? 'show' : 'edit' ) . '_user_profile';
add_action( $action, array ( __CLASS__, 'stop' ) );
ob_start();
}
/**
* Strips the bio box from the buffered content.
*
* @return void
*/
public static function stop()
{
$html = ob_get_contents();
ob_end_clean();
// remove the headline
$headline = __( IS_PROFILE_PAGE ? 'About Yourself' : 'About the user' );
$html = str_replace( '<h2>' . $headline . '</h2>', '', $html );
// remove the table row
$html = preg_replace( '~<tr>s*<th><label for="description".*</tr>~imsUu', '', $html );
print $html;
}
}
您可以將代碼作為獨立插件下載:Plugin Remove Bio Box 。
Before
After
密碼字段現在位於聯繫信息… 下,如果您不喜歡,請在 stop()中添加標題,並關注 I18n 。 😉
次佳解決方案
由於最近的班級改變這個工作:
add_action( 'personal_options', array ( 'T5_Hide_Profile_Bio_Box', 'start' ) );
/**
* Captures the part with the biobox in an output buffer and removes it.
*
* @author Thomas Scholz, <info@toscho.de>
*
*/
class T5_Hide_Profile_Bio_Box
{
/**
* Called on 'personal_options'.
*
* @return void
*/
public static function start()
{
$action = ( IS_PROFILE_PAGE ? 'show' : 'edit' ) . '_user_profile';
add_action( $action, array ( __CLASS__, 'stop' ) );
ob_start();
}
/**
* Strips the bio box from the buffered content.
*
* @return void
*/
public static function stop()
{
$html = ob_get_contents();
ob_end_clean();
// remove the headline
$headline = __( IS_PROFILE_PAGE ? 'About Yourself' : 'About the user' );
$html = str_replace( '<h3>' . $headline . '</h3>', '', $html );
// remove the table row
$html = preg_replace( '~<tr class="user-description-wrap">s*<th><label for="description".*</tr>~imsUu', '', $html );
print $html;
}
}
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。

