Skip to:
Content
Pages
Categories
Search
Top
Bottom

Alternative Usage of a Profile Field


  • draganbabic
    Member

    @draganbabic

    Hi guys, me again.

    I want to give my users some personalization options for their profiles, so this is what I was thinking:

    Upon registration there would be a non-required field where people can input a URL for an image, now what I’d like to do is use the value of that field within a style=”” attribute of an element, so I could attach it as a background image.

    My questions would be:

    * Is using profile fields the right way to do it?

    * Can a non-required field (or rather field group) be hidden from the register screen? They are not required after all, so my guess is that this can be accomplished via CSS alone.

    * Is there a way to check the value of the field? I’d like to allow only .jpg, .gif and .png files.

    I guess the last two are considered “extravagant” so I’d settle for a bare-bones solution (i.e. just enabling the option).

Viewing 6 replies - 1 through 6 (of 6 total)

  • r-a-y
    Keymaster

    @r-a-y

    You can use an xprofile field, I see no harm in it.

    Of course, there are other ways.

    I believe, by default, all xprofile fields under “Base” are required.

    If you don’t want it required, create a new xprofile group to house this new field.

    To check the xprofile value of this new field, you’ll have to do a little manipulation in PHP with it. You could use substr() to check for file extensions.

    r-a-y’s right, but I can’t help but feel that what you’re proposing could potentially be trouble with regards to XSS and people trying to break your site.

    Another approach, with different benefits and drawbacks, would be to utilise either WordPress 2.9’s custom post types or just upload a number of background images using the Media Uploader; you’d still use the xProfile field to get users to select which image they want, but you write some code that switches the image selected with the actual image URL from the media library.


    r-a-y
    Keymaster

    @r-a-y

    Forgot to mention if you’re going with the xprofile field route, you should check the mime-type for the URL.

    This would provide some additional security.

    DJPaul’s idea is good as well!


    draganbabic
    Member

    @draganbabic

    Hi guys,

    thanks for the ideas. So far I got this running:

    <?php if ( bp_has_profile('profile_group_id=2') ) : ?>

    <?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

    <?php if ( bp_profile_group_has_fields() ) : ?>

    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

    <?php if ( bp_field_has_data() ) : ?>

    style="<?php bp_the_profile_field_value() ?>"

    <?php endif; ?>

    <?php endwhile; ?>

    <?php endif; ?>

    <?php endwhile; ?>

    <?php else: ?>

    <?php endif;?>

    And this indeed outputs the desired value, but it is also wrapped in a paragraph and autolinked. Please do note that I have no idea what I am doing here, weather it is valid, good or anything else, this just got the job done, so it’s a starting point.

    I have searched the forum and found this code that is supposed to remove the autolinking:

    <?php

    function remove_links(){

    remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 2 );

    }

    add_action( 'plugins_loaded', 'remove_links' );

    ?>

    However it doesn’t do that once placed in bp-custom.php

    Any pointers?


    r-a-y
    Keymaster

    @r-a-y

    You shouldn’t need the xprofile field loop.

    Use something like this to grab the value directly:

    $background_url = xprofile_get_field_data( 'ENTER YOUR XPROFILE FIELD VALUE', bp_get_the_site_member_user_id() );


    draganbabic
    Member

    @draganbabic

    Thanks for the help r-a-y, I found this solution:

    [IN BP_CUSTOM.PHP]:

    function custom_xprofile( $field ) {

    echo bp_custom_get_member_list_xprofile_data( $field );

    }

    function bp_custom_get_member_list_xprofile_data( $field ) {

    global $site_members_template;

    return xprofile_get_field_data( $field, $site_members_template->member->id );

    }

    [IN CHILD THEME FILE]:

    <?php custom_xprofile('Header Image') ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Alternative Usage of a Profile Field’ is closed to new replies.
Skip to toolbar