I use a plugin called “Live Edit” to let authors and editors edit the content front-end. But the issue is that the plugin lets any logged in users to edit the content. I want the edit(specified by plugin. Not the WP’s default edit button) button be accessed based on their roles. I don’t know how to make it accessible based on roles. So trying to make it appear only for the authors and higher roles to that.
I want to do something like this in loop.php:
<?php
global $current_user;
get_currentuserinfo();
if ( user_can( $current_user, "author" ) ){
// Show Role
// Show Subscriber Image
}
Here is the code:
<?php post_class( 'post clearfix ' . $themify->get_categories_as_classes(get_the_ID()) . ' ' . $themify->get_post_color_class(get_the_ID()) ); if(function_exists("live_edit")){ live_edit('post_title, field1'); } ?>
and
<div <?php if(function_exists("live_edit")){ live_edit('post_content, myfield2'); }?>>
<?php if( function_exists('the_field') ) the_field('myfield1'); ?> </div>
<?php if( function_exists('the_field') ) the_field('myfield2'); ?>
</div>
I am unsure how to do it in the template or through functions.php. Could any one help me or guide through that to achieve what I want?
Here is the loop.php at pastebin – http://pastebin.com/9MVY64LJ
The live edit class is used in line 8 and line 57.
You can check if current user is an Author (WP-Codex)
And use it in the if-statement at the point where you implement the Live Edit function.
Here is the whole code (for user roles): http://pastebin.com/fY7UPcB1
EDIT:
Here is the new code (check for user role and if it’s his own post):
http://pastebin.com/NFtNVAGE
EDIT #2:
Now the button will appear only for users who written the post (Authors) and every user with higher user role (Editor, Admin).
Code: http://pastebin.com/8u6bV018