2014-03-13 36 views
1

如何在不編輯WP的核心功能的情況下隱藏用戶配置文件(/wp-admin/profile.php)中的一些字段?WordPress的:在用戶配置文件中禁用字段

例如,我想隱藏(或禁用,如果我不能把它放在'隱藏')電子郵件字段。我就使這個插件,但我不知道這是否是一個很好的做法:

<?php 
/** 
* Plugin Name: Disabled Email Modification 
* Plugin URI: 
* Description: Permet de désactiver la modification d'un email par un utilisateur 
* Version: 0.0.1 
* Author: Portekoi 
* Author URI: http://blog.portekoi.com 
*/ 

/* Hook pour 'plugins_loaded' */ 
add_action('plugins_loaded', 'dem_setup'); // Disabled Email Modification 

function dem_setup() { 
    add_action('admin_footer', 'dem_options'); 
} 

/** 
* Ajout Hack en JQuery pour rendre Disabled l'ID 'Email' 
*/ 
function dem_options($user) { 
    $screen = get_current_screen(); 
    if($screen->id == "profile"){ 
     ?> 
     <script> 
      jQuery(function() { 
       jQuery(document).ready(function() { 
        jQuery("#email").prop('disabled', true); 
       }); 
      }); 
     </script> 
    <?php 
    } 
} 
?> 

回答

1

據我所知,只有三個在編輯用戶過濾器鉤和配置文件頁面:user_contactmethods,admin_color_scheme_pickershow_password_fields。其他一切都必須用jQuery完成。

您的代碼可以定位在admin_footer-$hook_suffix那些特定的網頁並且還加入了$作爲快捷方式jQuery的改善:

add_action('plugins_loaded', 'dem_setup'); 

function dem_setup() { 
    foreach(array('profile','user-edit') as $hook) 
     add_action("admin_footer-$hook.php", 'dem_options'); 
} 

function dem_options() { 
    ?> 
    <script> 
     jQuery(document).ready(function ($) { 
      $("#email,#url").prop('disabled', true); 
     }); 
    </script> 
    <?php 
} 

我的一個插件有許多選項,對用戶隱藏的網頁的東西,你可以檢查一些針對here的jQuery示例。

1

試試這個

function modify_contact_methods($profile_fields) { 

    // Remove old fields 
    unset($profile_fields['aim']); 

    return $profile_fields; 
} 
add_filter('user_contactmethods', 'modify_contact_methods'); 
+0

這不僅是聯繫方式。例如,我想刪除工具欄的複選框。我怎樣才能做到這一點? – Portekoi

相關問題