0

When I return in the function $setfound, I become a white screen and when I return $setlink, it works fine.

function editsteamlink(){
$setlink = $_POST['steamlink']."/?xml=1";
$setresponse = wp_remote_get($setlink);
$setbody    = wp_remote_retrieve_body($setresponse);
$setxml = simplexml_load_string($setbody);
$setfound = $setxml->steamID64;
return $setfound;
}


function be_save_custom_avatar_field( $user_id ) {

    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }

        update_usermeta( $user_id, 'steamid64',editsteamlink());
        update_usermeta( $user_id, 'steamlink', $_POST['steamlink'] );

}
0

You should enable WP_DEBUG mode, so that the white screen of death will give you a more useful error message.

The white screen could be caused by a typo, but it looks ok to me. Does your host have simplexml_load_string()? If you don't have the simple XML library, that could be why returning $setlink works, while returning $setfound causes WSOD.

I've re-written your code a bit so that it has isset() checks and so that you aren't relying on $_POST in your editsteamlink() function and it checks that the simplexml_load_string function exists.

function editsteamlink( $setlink = '' ){

    if( $setlink == '' || ! function_exists( 'simplexml_load_string' ) ){
        return '';
    }

    $setlink = untrailingslashit( $setlink ) ."/?xml=1";
    $setresponse = wp_remote_get($setlink);
    $setbody    = wp_remote_retrieve_body($setresponse);
    $setxml = simplexml_load_string($setbody);
    $setfound = (string)$setxml->steamID64;
    return $setfound;
}


function be_save_custom_avatar_field( $user_id ) {

    if ( !current_user_can( 'edit_user', $user_id ) ) { 
        return false; 
    }

    $steam_link = isset( $_POST['steamlink'] ) ? $_POST['steamlink'] : '';
    $steam_id = editsteamlink( $steam_link );

    update_usermeta( $user_id, 'steamlink', $steam_link );
    update_usermeta( $user_id, 'steamid64', $steam_id ); 

}

Untested, so your mileage may vary! :)

  • I habe found my mistakte thats the edit line $setfound = (string)$setxml->steamID64; – user57172 Jul 26 '14 at 14:23
  • Adjusted my answer to include that. – helgatheviking Jul 26 '14 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.