刚刚升级到 WordPress 4.4,我现在注意到我的用户在管理中的个人资料页面,有一个名为“个人资料图片”的部分,其中包含指向 Gravatar 的链接。
我正在开发的插件限制了 profile.php 中的很多东西; 不幸的是,通过 jQuery 从 DOM 中删除:
jQuery( document ).ready(function() {
jQuery( "h2:contains('Personal Options')" ).remove();
jQuery( "h2:contains('Name')" ).remove();
jQuery( "h2:contains('Contact Info')" ).remove();
jQuery( "h2:contains('About Yourself')" ).remove();
jQuery( "h2:contains('Account Management')" ).remove();
jQuery( "tr.show-admin-bar" ).parents("table:first").remove();
jQuery( "tr.user-first-name-wrap" ).remove();
jQuery( "tr.user-last-name-wrap" ).remove();
jQuery( "tr.user-nickname-wrap" ).remove();
jQuery( "tr.user-display-name-wrap" ).remove();
jQuery( "tr.user-url-wrap" ).remove();
jQuery( "tr.user-description-wrap").parents("table:first").remove();
jQuery( ".user-sessions-wrap" ).remove();
});
在我继续沉迷于 jQuery 之前,有没有更好的方法(除了输出缓冲区替换)? 此外,是否还有其他一些专门针对用户个人资料图片的设置,或者这个 jQuery 解决方案将成为目前的答案?
我们可以使用 show_avatars
选项删除 头像 部分。
-
我们可以参观
/wp-admin/options.php
手动关闭它。 -
或者更新它:
update_option( 'show_avatars', 0 );
-
或者通过过滤器修改它:
add_filter( 'option_show_avatars', '__return_false' );
-
我们也可以将其限制在
profile.php
页:add_action( 'load-profile.php', function() { add_filter( 'option_show_avatars', '__return_false' ); } );
有一些钩子可以删除个人资料页面的某些部分。 此外,您可以只使用 php 来缓冲页面输出,然后去除相关内容。
// Remove fields from Admin profile page
if (!function_exists('CCK_remove_profile_options')) {
function CCK_remove_profile_options($subject)
{
$subject = preg_replace('#<h2>' . __("Personal Options") . '</h2>#s', '', $subject, 1); // Remove the "Personal Options" title
$subject = preg_replace('#<tr class="user-syntax-highlighting-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Syntax Highlighting" field
$subject = preg_replace('#<tr class="user-rich-editing-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Visual Editor" field
$subject = preg_replace('#<tr class="user-comment-shortcuts-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Keyboard Shortcuts" field
$subject = preg_replace('#<tr class="show-admin-bar(.*?)</tr>#s', '', $subject, 1); // Remove the "Toolbar" field
//$subject = preg_replace('#<h2>'.__("Name").'</h2>#s', '', $subject, 1); // Remove the "Name" title
//$subject = preg_replace('#<tr class="user-display-name-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Display name publicly as" field
$subject = preg_replace('#<h2>' . __("Contact Info") . '</h2>#s', '<h2>' . __("Login Management") . '</h2>', $subject, 1); // Remove the "Contact Info" title
$subject = preg_replace('#<tr class="user-url-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Website" field
$subject = preg_replace('#<tr class="user-googleplus-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Google+" field
$subject = preg_replace('#<tr class="user-twitter-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Website" field
$subject = preg_replace('#<tr class="user-facebook-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Website" field
$subject = preg_replace('#<h2>' . __("Account Management") . '</h2>#s', '', $subject, 1); // Remove the "About Yourself" title
$subject = preg_replace('#<h2>' . __("About Yourself") . '</h2>#s', '', $subject, 1); // Remove the "About Yourself" title
$subject = preg_replace('#<h2>' . __("About the user") . '</h2>#s', '', $subject, 1); // Remove the "About Yourself" title
$subject = preg_replace('#<tr class="user-description-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Biographical Info" field
//$subject = preg_replace('#<tr class="user-profile-picture(.*?)</tr>#s', '', $subject, 1); // Remove the "Profile Picture" field
//$subject = preg_replace('#<h3>' . __("User Expiry Information") . '</h3>#s', '', $subject, 1); // Remove the "Expire Users Data" title
return $subject;
}
function CCK_profile_subject_start()
{
//if ( /*!*/ current_user_can('manage_options') ) {
ob_start('CCK_remove_profile_options');
//}
}
function CCK_profile_subject_end()
{
//if ( /*!*/ current_user_can('manage_options') ) {
ob_end_flush();
//}
}
}
add_action('admin_head', 'CCK_profile_subject_start');
add_action('admin_footer', 'CCK_profile_subject_end');
// Removes ability to change Theme color for the users
remove_action('admin_color_scheme_picker', 'admin_color_scheme_picker');
