Check profile author's role and apply image based on it2019 Community Moderator ElectionPHP Class variable questionCodeIgniter global functionphp Parse user inputGetting an author's role in WordpressPHP with MYSQL DB Role based login redirectAssign Roles to my PHP Session?How can I put a slider plugin in homepage using Jquery?Symfony ACL role based check permission on both class and objectcheck permission in custom workflow function
Can I negotiate a patent idea for a raise, under French law?
Can we track matter through time by looking at different depths in space?
MySQL importing CSV files really slow
Does an unused member variable take up memory?
Why restrict private health insurance?
Does "Until when" sound natural for native speakers?
Can the alpha, lambda values of a glmnet object output determine whether ridge or Lasso?
What will happen if my luggage gets delayed?
Why does cron require MTA for logging?
Making a kiddush for a girl that has hard time finding shidduch
Doesn't allowing a user mode program to access kernel space memory and execute the IN and OUT instructions defeat the purpose of having CPU modes?
Is it safe to abruptly remove Arduino power?
Why is a very small peak with larger m/z not considered to be the molecular ion?
Power Strip for Europe
Windows Server Data Center Edition - Unlimited Virtual Machines
How do we create new idioms and use them in a novel?
Getting the || sign while using Kurier
Finitely many repeated replacements
Vocabulary for giving just numbers, not a full answer
Why do we say ‘pairwise disjoint’, rather than ‘disjoint’?
I can't die. Who am I?
Why is there an extra space when I type "ls" in the Desktop directory?
Why couldn't the separatists legally leave the Republic?
Having the player face themselves after the mid-game
Check profile author's role and apply image based on it
2019 Community Moderator ElectionPHP Class variable questionCodeIgniter global functionphp Parse user inputGetting an author's role in WordpressPHP with MYSQL DB Role based login redirectAssign Roles to my PHP Session?How can I put a slider plugin in homepage using Jquery?Symfony ACL role based check permission on both class and objectcheck permission in custom workflow function
I have this code that checks the user role and adds an image to the page based on the current logged in user browsing the page:
global $current_user;
get_currentuserinfo();
switch (true)
case ( user_can( $current_user, "talento_pro") ):
echo '<i class="fa fa-bolt" title="Agência PRO+"></i>';
break;
case ( user_can( $current_user, "talento_pro_plus") ):
echo '<i class="fa fa-rocket" title="Agência PRO+"></i>';
break;
How can I reproduce the same, but instead of checking the current logged in user, it checks the role of the user who originally created the page the logged in one is browsing?
EDITED
I've tweaked the code a little bit but it isn't working, I think it's headed on the right direction?
global $authordata;
get_the_author_meta( "user_level" = "talento_pro" );
switch (true)
case ( user_can( $authordata, "talento_pro") ):
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case ( user_can( $author, "talento_pro_plus") ):
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
Thanks.
php html wordpress
add a comment |
I have this code that checks the user role and adds an image to the page based on the current logged in user browsing the page:
global $current_user;
get_currentuserinfo();
switch (true)
case ( user_can( $current_user, "talento_pro") ):
echo '<i class="fa fa-bolt" title="Agência PRO+"></i>';
break;
case ( user_can( $current_user, "talento_pro_plus") ):
echo '<i class="fa fa-rocket" title="Agência PRO+"></i>';
break;
How can I reproduce the same, but instead of checking the current logged in user, it checks the role of the user who originally created the page the logged in one is browsing?
EDITED
I've tweaked the code a little bit but it isn't working, I think it's headed on the right direction?
global $authordata;
get_the_author_meta( "user_level" = "talento_pro" );
switch (true)
case ( user_can( $authordata, "talento_pro") ):
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case ( user_can( $author, "talento_pro_plus") ):
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
Thanks.
php html wordpress
add a comment |
I have this code that checks the user role and adds an image to the page based on the current logged in user browsing the page:
global $current_user;
get_currentuserinfo();
switch (true)
case ( user_can( $current_user, "talento_pro") ):
echo '<i class="fa fa-bolt" title="Agência PRO+"></i>';
break;
case ( user_can( $current_user, "talento_pro_plus") ):
echo '<i class="fa fa-rocket" title="Agência PRO+"></i>';
break;
How can I reproduce the same, but instead of checking the current logged in user, it checks the role of the user who originally created the page the logged in one is browsing?
EDITED
I've tweaked the code a little bit but it isn't working, I think it's headed on the right direction?
global $authordata;
get_the_author_meta( "user_level" = "talento_pro" );
switch (true)
case ( user_can( $authordata, "talento_pro") ):
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case ( user_can( $author, "talento_pro_plus") ):
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
Thanks.
php html wordpress
I have this code that checks the user role and adds an image to the page based on the current logged in user browsing the page:
global $current_user;
get_currentuserinfo();
switch (true)
case ( user_can( $current_user, "talento_pro") ):
echo '<i class="fa fa-bolt" title="Agência PRO+"></i>';
break;
case ( user_can( $current_user, "talento_pro_plus") ):
echo '<i class="fa fa-rocket" title="Agência PRO+"></i>';
break;
How can I reproduce the same, but instead of checking the current logged in user, it checks the role of the user who originally created the page the logged in one is browsing?
EDITED
I've tweaked the code a little bit but it isn't working, I think it's headed on the right direction?
global $authordata;
get_the_author_meta( "user_level" = "talento_pro" );
switch (true)
case ( user_can( $authordata, "talento_pro") ):
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case ( user_can( $author, "talento_pro_plus") ):
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
Thanks.
php html wordpress
php html wordpress
asked Mar 5 at 22:36
Rui FarinhaRui Farinha
10417
10417
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to change a few things:
You don't need both the
global $authordata
andget_the_author_meta
. You can pick one to use.The way you are trying to get the author meta is incorrect. You just need to pass
user_level
likeget_the_author_meta( 'user_level' );
Try this:
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
This assigns the role
array property to the $author_role
variable so you can check against it in the switch
statement.
Here's what the $authordata
object looks like:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 25
[user_login] => Name
[user_pass] => hashedpassword
[user_nicename] => name
[user_email] => name@example.com
[user_url] =>
[user_registered] => 2015-03-27 00:00:00
[user_activation_key] =>
[user_status] => 0
[display_name] => Name
)
[ID] => 25
[caps] => Array
(
[author] => 1
)
[cap_key] => wp_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
[edit_attachments] => 1
[delete_attachments] => 1
[read_others_attachments] => 1
[edit_others_attachments] => 1
[delete_others_attachments] => 1
[edit_aggregator-records] => 1
[edit_published_aggregator-records] => 1
[delete_aggregator-records] => 1
[delete_published_aggregator-records] => 1
[publish_aggregator-records] => 1
[author] => 1
)
[filter] =>
[site_id:WP_User:private] => 1
)
EDIT:
If you want to use this as a function on a template:
function wp03052019_get_user_role()
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
You can then just put this in your functions.php
and then call the function on any template you want this to output echo wp03052019_get_user_role()
;
SHORTCODE
For a shortcode version, that you can call in the content editor, use the same function as above - only adding a single argument $atts
- because it's required.
function wp03052019_get_user_role( $atts )
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
add_shortcode( 'userroleoutput', 'wp03052019_get_user_role');
Now, in your content editor, you can do [userroleoutput /]
My man! Thank you very much :)
– Rui Farinha
Mar 6 at 0:18
Do you know how can I use the code above as a shortcode? Should I put the code on functions.php and pull it to other page through a shortcode? Is it possible with theadd_action()
? Thanks
– Rui Farinha
Mar 6 at 0:31
Added more information and use cases.
– disinfor
Mar 6 at 14:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55012725%2fcheck-profile-authors-role-and-apply-image-based-on-it%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to change a few things:
You don't need both the
global $authordata
andget_the_author_meta
. You can pick one to use.The way you are trying to get the author meta is incorrect. You just need to pass
user_level
likeget_the_author_meta( 'user_level' );
Try this:
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
This assigns the role
array property to the $author_role
variable so you can check against it in the switch
statement.
Here's what the $authordata
object looks like:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 25
[user_login] => Name
[user_pass] => hashedpassword
[user_nicename] => name
[user_email] => name@example.com
[user_url] =>
[user_registered] => 2015-03-27 00:00:00
[user_activation_key] =>
[user_status] => 0
[display_name] => Name
)
[ID] => 25
[caps] => Array
(
[author] => 1
)
[cap_key] => wp_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
[edit_attachments] => 1
[delete_attachments] => 1
[read_others_attachments] => 1
[edit_others_attachments] => 1
[delete_others_attachments] => 1
[edit_aggregator-records] => 1
[edit_published_aggregator-records] => 1
[delete_aggregator-records] => 1
[delete_published_aggregator-records] => 1
[publish_aggregator-records] => 1
[author] => 1
)
[filter] =>
[site_id:WP_User:private] => 1
)
EDIT:
If you want to use this as a function on a template:
function wp03052019_get_user_role()
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
You can then just put this in your functions.php
and then call the function on any template you want this to output echo wp03052019_get_user_role()
;
SHORTCODE
For a shortcode version, that you can call in the content editor, use the same function as above - only adding a single argument $atts
- because it's required.
function wp03052019_get_user_role( $atts )
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
add_shortcode( 'userroleoutput', 'wp03052019_get_user_role');
Now, in your content editor, you can do [userroleoutput /]
My man! Thank you very much :)
– Rui Farinha
Mar 6 at 0:18
Do you know how can I use the code above as a shortcode? Should I put the code on functions.php and pull it to other page through a shortcode? Is it possible with theadd_action()
? Thanks
– Rui Farinha
Mar 6 at 0:31
Added more information and use cases.
– disinfor
Mar 6 at 14:25
add a comment |
You need to change a few things:
You don't need both the
global $authordata
andget_the_author_meta
. You can pick one to use.The way you are trying to get the author meta is incorrect. You just need to pass
user_level
likeget_the_author_meta( 'user_level' );
Try this:
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
This assigns the role
array property to the $author_role
variable so you can check against it in the switch
statement.
Here's what the $authordata
object looks like:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 25
[user_login] => Name
[user_pass] => hashedpassword
[user_nicename] => name
[user_email] => name@example.com
[user_url] =>
[user_registered] => 2015-03-27 00:00:00
[user_activation_key] =>
[user_status] => 0
[display_name] => Name
)
[ID] => 25
[caps] => Array
(
[author] => 1
)
[cap_key] => wp_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
[edit_attachments] => 1
[delete_attachments] => 1
[read_others_attachments] => 1
[edit_others_attachments] => 1
[delete_others_attachments] => 1
[edit_aggregator-records] => 1
[edit_published_aggregator-records] => 1
[delete_aggregator-records] => 1
[delete_published_aggregator-records] => 1
[publish_aggregator-records] => 1
[author] => 1
)
[filter] =>
[site_id:WP_User:private] => 1
)
EDIT:
If you want to use this as a function on a template:
function wp03052019_get_user_role()
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
You can then just put this in your functions.php
and then call the function on any template you want this to output echo wp03052019_get_user_role()
;
SHORTCODE
For a shortcode version, that you can call in the content editor, use the same function as above - only adding a single argument $atts
- because it's required.
function wp03052019_get_user_role( $atts )
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
add_shortcode( 'userroleoutput', 'wp03052019_get_user_role');
Now, in your content editor, you can do [userroleoutput /]
My man! Thank you very much :)
– Rui Farinha
Mar 6 at 0:18
Do you know how can I use the code above as a shortcode? Should I put the code on functions.php and pull it to other page through a shortcode? Is it possible with theadd_action()
? Thanks
– Rui Farinha
Mar 6 at 0:31
Added more information and use cases.
– disinfor
Mar 6 at 14:25
add a comment |
You need to change a few things:
You don't need both the
global $authordata
andget_the_author_meta
. You can pick one to use.The way you are trying to get the author meta is incorrect. You just need to pass
user_level
likeget_the_author_meta( 'user_level' );
Try this:
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
This assigns the role
array property to the $author_role
variable so you can check against it in the switch
statement.
Here's what the $authordata
object looks like:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 25
[user_login] => Name
[user_pass] => hashedpassword
[user_nicename] => name
[user_email] => name@example.com
[user_url] =>
[user_registered] => 2015-03-27 00:00:00
[user_activation_key] =>
[user_status] => 0
[display_name] => Name
)
[ID] => 25
[caps] => Array
(
[author] => 1
)
[cap_key] => wp_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
[edit_attachments] => 1
[delete_attachments] => 1
[read_others_attachments] => 1
[edit_others_attachments] => 1
[delete_others_attachments] => 1
[edit_aggregator-records] => 1
[edit_published_aggregator-records] => 1
[delete_aggregator-records] => 1
[delete_published_aggregator-records] => 1
[publish_aggregator-records] => 1
[author] => 1
)
[filter] =>
[site_id:WP_User:private] => 1
)
EDIT:
If you want to use this as a function on a template:
function wp03052019_get_user_role()
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
You can then just put this in your functions.php
and then call the function on any template you want this to output echo wp03052019_get_user_role()
;
SHORTCODE
For a shortcode version, that you can call in the content editor, use the same function as above - only adding a single argument $atts
- because it's required.
function wp03052019_get_user_role( $atts )
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
add_shortcode( 'userroleoutput', 'wp03052019_get_user_role');
Now, in your content editor, you can do [userroleoutput /]
You need to change a few things:
You don't need both the
global $authordata
andget_the_author_meta
. You can pick one to use.The way you are trying to get the author meta is incorrect. You just need to pass
user_level
likeget_the_author_meta( 'user_level' );
Try this:
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
echo '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
echo '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
This assigns the role
array property to the $author_role
variable so you can check against it in the switch
statement.
Here's what the $authordata
object looks like:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 25
[user_login] => Name
[user_pass] => hashedpassword
[user_nicename] => name
[user_email] => name@example.com
[user_url] =>
[user_registered] => 2015-03-27 00:00:00
[user_activation_key] =>
[user_status] => 0
[display_name] => Name
)
[ID] => 25
[caps] => Array
(
[author] => 1
)
[cap_key] => wp_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
[edit_attachments] => 1
[delete_attachments] => 1
[read_others_attachments] => 1
[edit_others_attachments] => 1
[delete_others_attachments] => 1
[edit_aggregator-records] => 1
[edit_published_aggregator-records] => 1
[delete_aggregator-records] => 1
[delete_published_aggregator-records] => 1
[publish_aggregator-records] => 1
[author] => 1
)
[filter] =>
[site_id:WP_User:private] => 1
)
EDIT:
If you want to use this as a function on a template:
function wp03052019_get_user_role()
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
You can then just put this in your functions.php
and then call the function on any template you want this to output echo wp03052019_get_user_role()
;
SHORTCODE
For a shortcode version, that you can call in the content editor, use the same function as above - only adding a single argument $atts
- because it's required.
function wp03052019_get_user_role( $atts )
$user_role = '';
global $authordata;
// This assumes that each user only has one role. You might have to adjust what array value you get
$author_role = $authordata->roles[0];
switch( $author_role )
case 'talento_pro':
$user_role = '<i title="Talento PRO" class="fa fa-bolt"></i>';
break;
case 'talento_pro_plus':
$user_role = '<i title="Talento PRO+" class="fa fa-rocket"></i>';
break;
return $user_role;
add_shortcode( 'userroleoutput', 'wp03052019_get_user_role');
Now, in your content editor, you can do [userroleoutput /]
edited Mar 6 at 14:24
answered Mar 5 at 23:46
disinfordisinfor
3,04411828
3,04411828
My man! Thank you very much :)
– Rui Farinha
Mar 6 at 0:18
Do you know how can I use the code above as a shortcode? Should I put the code on functions.php and pull it to other page through a shortcode? Is it possible with theadd_action()
? Thanks
– Rui Farinha
Mar 6 at 0:31
Added more information and use cases.
– disinfor
Mar 6 at 14:25
add a comment |
My man! Thank you very much :)
– Rui Farinha
Mar 6 at 0:18
Do you know how can I use the code above as a shortcode? Should I put the code on functions.php and pull it to other page through a shortcode? Is it possible with theadd_action()
? Thanks
– Rui Farinha
Mar 6 at 0:31
Added more information and use cases.
– disinfor
Mar 6 at 14:25
My man! Thank you very much :)
– Rui Farinha
Mar 6 at 0:18
My man! Thank you very much :)
– Rui Farinha
Mar 6 at 0:18
Do you know how can I use the code above as a shortcode? Should I put the code on functions.php and pull it to other page through a shortcode? Is it possible with the
add_action()
? Thanks– Rui Farinha
Mar 6 at 0:31
Do you know how can I use the code above as a shortcode? Should I put the code on functions.php and pull it to other page through a shortcode? Is it possible with the
add_action()
? Thanks– Rui Farinha
Mar 6 at 0:31
Added more information and use cases.
– disinfor
Mar 6 at 14:25
Added more information and use cases.
– disinfor
Mar 6 at 14:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55012725%2fcheck-profile-authors-role-and-apply-image-based-on-it%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown