WordPress ignores line breaks in user description - php

I have a problem where WordPress isn't showing line breaks when I echo the user description. The text shows in one line.
I'm using this line of code to show the user description:
<?php $user = get_user_by( 'slug', 'admin' ); echo $user->description ?>
Any idea what could be causing the problem and how to get WordPress to show the line breaks in the user description? Adding <br /> to the description box on user profile settings page doesn't help.

I think you could do something like this:
echo nl2br($user->description);
To optimize things, you could plug it up so that your user description saves the string using nl2br when saved in the database.

Related

Wordpress - Access a custom field value with PHP

I am having trouble accessing a custom field on my Wordpress page.
I have a field for a user to upload an image file. The theme that I am using then displays the value of that image as just the image ID, instead of an image link. I display it using {CUSTOM_FIELD_TestFile} in the page editor.
I want it to display the actual image though, not the ID.
So, I created a PHP snippet that runs on the page, to do the converting.
If I use <img src=" <?php echo wp_get_attachment_url( 1013 )?> "> and I have the image ID hard coded (1013), it works perfectly.
However, I have had no luck getting the value of 'TestFile' into the PHP snippet.
I double checked the user_meta table and the meta_key for this file is indeed TestFile.
The viewing of the page is done usually when a user is not logged in. So, get_current_user_id() isn't an option, which means, I also can't use get_user_meta().
If I use:
<?php
$postId = get_the_ID();
echo $postId;
$fileLink = get_metadata( "user", $postId, "TestFile");
echo $fileLink;
?>
I get "array" as a response. If I change it to get_metadata( "user", $postId, "TestFile", true); I get nothing.
The exact same results if I use get_post_meta($postId, 'TestFile'); or get_post_meta($postId, 'TestFile', true);.
Am I on the completely wrong track? Is there an easier way to do this? Or is there something that I should be doing with that "array" value that is being returned.
Thanks so much for any help you can offer.
If you have added a custom field called TestFile in the editor, you should be able to get that in your template with:
$value = get_post_meta($postId, 'TestFile', true);
I'm not sure what you mean about the user being logged in or out, because custom fields belong to the post and have nothing to do with the user.
Assuming that works, you should be able to add the ID to your image element:
<img src="<?= wp_get_attachment_url($value); ?>">

How to use PHP code In a Plugin's Short Code on Wordpress

The shortcode is:
[sp-client-document-manager uid=]
uid= need to display wp user id to display user files.
I am using another wp plugin (Ultimate Member) which can pull the user ID from the profile page using this code:
$profile_id = um_profile_id();
I tried this along with sever other variations:
[sp-client-document-manager uid=$profile_id = um_profile_id();]
To see shortcode output, You must use do_shorcode function , update your last line to below:
$profile_id = um_profile_id();
echo do_shortcode("[sp-client-document-manager uid='$profile_id']");
Got it working by using
<?php echo do_shortcode("[sp-client-document-manager uid='".um_profile_id()."']"); ?>
Added it to bottom of templates/profile.php in the Ultilate Member plugin folder

Buddypress get full name print to new wordpress page

Referring to How to get username/display name in Buddypress?
I have tried putting this code to an added new page
<?php
$string = bp_get_displayed_user_fullname();
echo $string;
?>
But when i tried previewing the page it prints empty only. Is there something I missed on the plugin to make it working? TIA
bp_get_displayed_user_fullname() will work only on pages, that are displaying some user. That means your profile or profiles of other users. On all other pages you will always see an empty string (forums, ordinary WordPress pages and posts, groups etc).
To display a name of any user on any page you need to use something like bp_core_get_user_displayname( $user_id ), where $user_id is, obviously, the ID of a user you want the name of.

How can find wordpress admin screen option inside the wp-admin folder

I am not using any plugin i want to make bootstrap admin dashboard on word press admin.
how i can change Word press welcome message ?
how i can change word press screen option ?
You can turn the welcome panel off, incidentally resulting in the removal of the welcome message, by doing the following:
Locate the file: /wp-admin/index.php
Just before wp_dashboard() is called, add the following line:
<?php remove_action( 'welcome_panel', 'wp_welcome_panel' ); ?>
This will also remove the corresponding screen option.
As far as changing the text from "Welcome Text" to "Some Other Welcome Message", this is not set in any php file. You will need to have access to the MySql database. You will likely find the welcome text in the wp_options table. A simple SQL query will help you to find the exact location.
References:
Welcome Panel:
https://codex.wordpress.org/Plugin_API/Action_Reference/welcome_panel
Database Diagram:
https://codex.wordpress.org/images/2/2a/WP3.9.4-ERD.png

Bio line beneath pp in BuddyPress?

I’m new to BP and WP! I have a quick question:
How can I show a one-line bio beneath usernames in the list of members in the ‘Members’ page of my BuddyPress website? For example, Facebook has a similar feature; it shows a name with a description beneath, e.g. ‘John Smith’ with ‘Engineer at Nuts & Bolts Co’ right beneath it.
I found the following line of code in member-header.php:
<h2 class=”user-nicename”>#<?php bp_displayed_user_username(); ?></h2>1
I thought about adding another line beneath for the bio field, but I’m not sure what to replace “bp_displayed_user_username();” with – I don’t think there is a “bp_displayed_user_bio();”. Should I create it? If so, how?
Thank you for your time!
'member-header.php' is for single member pages.
If you want the bio to display on singe member pages, create a template overload.
Then add this:
<?php
$bio = xprofile_get_field_data('Bio');
//If the field is not called Bio, then change it above
if( !empty( $bio )
echo 'Bio: ' . $bio;
?>
If you want Bio to display on the members page that shows all members, then create a template overload of this page:
\buddypress\bp-templates\bp-legacy\buddypress\members\members-loop.php
And look for this: bp_member_profile_data( 'field=the field name' );
Uncomment it and change to to, for example, bp_member_profile_data( 'field=Bio' );

Categories