Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Buddypress prevent name change WordPress

  • SOLVED

I am currently usign the latest version installed buddypress. But i dont want the users of my site to be able to change the "name" field.

But the field is required and i cant remove it. Any solution?

Answers (3)

2014-06-10

Romel Apuya answers:

set the attribute to readonly
add this in your header.php
just above the

<?php wp_head(); ?>

<?php
if( bp_is_my_profile()) {
?>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type='text/javascript'>
/* <![CDATA[ */
jQuery.noConflict();
jQuery( document ).ready(function( $ ) {
$( "#field_1" ).prop('readonly', true);
});
/* ]]> */
</script>
<?php
}
?>

2014-06-08

Kyle answers:

Simplest solution would be to just hide the field, it will still submit etc.

display: none;


Onur YILMAZ comments:

It is text box, how will i hide it?

And there is not a specific name for the box (field_1) thus I cant use it in css

I didnt understand


Kyle comments:

Is there someway to view the form? There should be a unique name, id, or parent element.

input[name="field_1"] {
display: none;
}

Won't work with IE6 and less though if you have to use the name field


Kyle comments:

timDesain has a more proper answer, I would go his route.

2014-06-08

timDesain Nanang answers:

first: crate bp-custom.php file at /wp-content/plugins/ folder
second: put this code in bp-custom.php file

add_action( 'xprofile_data_before_save', 'disable_name_change' );
function disable_name_change( $data ) {
if ( 1 == $data->field_id )
$data->field_id = false;
return $data;
}


sources:
[[LINK href="http://codex.buddypress.org/plugindev/bp-custom-php/"]]http://codex.buddypress.org/plugindev/bp-custom-php/[[/LINK]]
[[LINK href="http://buddypress.org/support/topic/disable-name-change-in-profile/"]]http://buddypress.org/support/topic/disable-name-change-in-profile/[[/LINK]]


<strong>update:</strong>
if get this error:
<blockquote>Warning: Cannot modify header information - headers already sent by (output started at /home/gfxpusul/public_html/wp-content/plugins/bp-custom.php:2) in /home/gfxpusul/public_html/wp-includes/pluggable.php on line 1121</blockquote>

then, <strong>delete the bp-custom.php</strong> file


Onur YILMAZ comments:

it works but it gives an error even though i try to change another field. It may be confusing for users. Any way to disable this message if i dont try to change the name field?


Onur YILMAZ comments:

Warning: Cannot modify header information - headers already sent by (output started at /home/gfxpusul/public_html/wp-content/plugins/bp-custom.php:2) in /home/gfxpusul/public_html/wp-includes/pluggable.php on line 1121

Now i get this error. Help!


timDesain Nanang comments:

try this method: (as my anwer for your Q: http://wpquestions.com/question/showChronoLoggedIn/id/9635)
- create folders : xbuddypress\members\single\profile under your theme folder ([[LINK href="http://wpquestions.com/uploads/timDesain_phpSKIPBk.png"]]see attachment[[/LINK]])
- create edit.php under profile folder ([[LINK href="http://wpquestions.com/uploads/timDesain_phpSKIPBk.png"]]see attachment[[/LINK]])
- put this code in edit.php file
<?php do_action( 'bp_before_profile_edit_content' ); ?>

<?php if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) :
while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

<?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
<?php
//display user's profile name
bp_the_profile_field_edit_value();
?>
<?php endwhile; ?>

<?php endwhile; endif; ?>

<?php do_action( 'bp_after_profile_edit_content' ); ?>


note: i am using twentytwelve child & buddypress 2.0.1 & wp 3.9.1



timDesain Nanang comments:

i mean :
- create folders : buddypress\members\single\profile


timDesain Nanang comments:

if you get error :
simply rename/delete the buddypress folder,
as like rename/delete bp-custom.php file