Discovering what life is about

Add and Remove Profile Fields to WordPress User Form

 

 

 

Add and Remove Profile Fields to WordPress User Form

https://davidwalsh.name/add-profile-fields

 

function modify_contact_methods($profile_fields) {

 

// Add new fields

$profile_fields['email2'] = 'Adresse secondaire';

$profile_fields['shares'] = 'Nombre de parts';

 

// Remove old fields

unset($profile_fields['twitter']);

unset($profile_fields['facebook']);

unset($profile_fields['googleplus']);

 

return $profile_fields;

}

add_filter('user_contactmethods', 'modify_contact_methods');

 

 

 

Retrieving Custom Field Values

To retrieve custom field values, use the get_the_author_meta method:

 

// Retrieve a custom field value

$twitterHandle = get_the_author_meta('twitter');

 

 


 

 

 

 

Removing “Website” Field from the contact info

http://wordpress.stackexchange.com/questions/94963/removing-website-field-from-the-contact-info

 

 

 

function remove_website_row_wpse_94963_css()

{

echo "<style>tr.user-url-wrap { display: none; }</style>";

echo "<style>tr.user-comment-shortcuts-wrap { display: none; }</style>";

echo "<style>tr.user-rich-editing-wrap { display: none; }</style>";

echo "<style>tr.user-admin-color-wrap { display: none; }</style>";

echo "<style>tr.user-display-name-wrap { display: none; }</style>";

echo "<style>.form-table td { padding: 2px 5px !important; }</style>";

echo "<style>.form-table th { padding: 2px 5px !important; width:250px !important;}</style>";

}

add_action( 'admin_head-user-edit.php', 'remove_website_row_wpse_94963_css' );

add_action( 'admin_head-profile.php', 'remove_website_row_wpse_94963_css' );

 

 

 

 


 

Update user list with custom columns


Ref : https://tareq.co/2011/07/add-your-custom-columns-to-wordpress-admin-panel-tables/

 

 

// ========= Update user list with custom columns
// Ref : https://tareq.co/2011/07/add-your-custom-columns-to-wordpress-admin-panel-tables/
function test_modify_user_table( $column ) {
$column['shares'] = 'Nombre de parts';
$column['email2'] = 'Adresse secondaire';
unset($column['posts']);
return $column;
}
add_filter( 'manage_users_columns', 'test_modify_user_table' );
function test_modify_user_table_row( $val, $column_name, $user_id ) {
$user = get_userdata( $user_id );
switch ($column_name) {
case 'shares' :
return $user->shares;
break;
case 'email2' :
return $user->email2;
break;
default:
}
return $return;
}
add_filter( 'manage_users_custom_column', 'test_modify_user_table_row', 10, 3 );

 

// ========= Update user list with custom columns

// Ref : https://tareq.co/2011/07/add-your-custom-columns-to-wordpress-admin-panel-tables/

function test_modify_user_table( $column ) {

$column['shares'] = 'Nombre de parts';

$column['email2'] = 'Adresse secondaire';

unset($column['posts']);

return $column;

}

add_filter( 'manage_users_columns', 'test_modify_user_table' );

 

function test_modify_user_table_row( $val, $column_name, $user_id ) {

$user = get_userdata( $user_id );

switch ($column_name) {

case 'shares' :

return $user->shares;

break;

case 'email2' :

return $user->email2;

break;

default:

}

return $return;

}

add_filter( 'manage_users_custom_column', 'test_modify_user_table_row', 10, 3 );

 

 

 

 

 

 

 

 

 

Code to add to functions.php or functions_custom.php

=============================================================

 

function modify_contact_methods($profile_fields) {

 

// Add new fields

$profile_fields['email2'] = 'Adresse secondaire';

$profile_fields['shares'] = 'Nombre de parts';

 

// Remove old fields

unset($profile_fields['twitter']);

unset($profile_fields['facebook']);

unset($profile_fields['googleplus']);

 

return $profile_fields;

}

add_filter('user_contactmethods', 'modify_contact_methods');

 

 

 

 

function hide_wp_fields_fields_css()

{

echo "<style>tr.user-url-wrap { display: none; }</style>";

echo "<style>tr.user-comment-shortcuts-wrap { display: none; }</style>";

echo "<style>tr.user-rich-editing-wrap { display: none; }</style>";

echo "<style>tr.user-admin-color-wrap { display: none; }</style>";

echo "<style>tr.user-display-name-wrap { display: none; }</style>";

echo "<style>.form-table td { padding: 2px 5px !important; }</style>";

echo "<style>.form-table th { padding: 2px 5px !important; width:250px !important;}</style>";

}

add_action( 'admin_head-user-edit.php', 'hide_wp_fields_fields_css' );

add_action( 'admin_head-profile.php', 'hide_wp_fields_fields_css' );

 

 

// ========= Update user list with custom columns

// Ref : https://tareq.co/2011/07/add-your-custom-columns-to-wordpress-admin-panel-tables/

function test_modify_user_table( $column ) {

$column['shares'] = 'Nombre de parts';

$column['email2'] = 'Adresse secondaire';

unset($column['posts']);

return $column;

}

add_filter( 'manage_users_columns', 'test_modify_user_table' );

 

function test_modify_user_table_row( $val, $column_name, $user_id ) {

$user = get_userdata( $user_id );

switch ($column_name) {

case 'shares' :

return $user->shares;

break;

case 'email2' :

return $user->email2;

break;

default:

}

return $return;

}

add_filter( 'manage_users_custom_column', 'test_modify_user_table_row', 10, 3 );

 

---
Categories : Online business    Themes : Tools
Share |
add a comment...

0 Comment

Leave a Comment