wordpress - How to show a class only for a specific user ID -


i have below line of code includes link edit attachment. want user ids able see edit link. how can make link, class=edit-attachment, show specific user id?

<div class="details">             <div class="filename">29982792291_9e1fc5b238_k-1.jpg</div>             <div class="uploaded">november 9, 2016</div>             <div class="file-size">1 mb</div>             <div class="dimensions">2048 × 1365</div>             <a class="edit-attachment" href="https://www.citynarrative.com/wp-admin/post.php?post=308&amp;action=edit&amp;image-editor" target="_blank">edit image</a>             <button type="button" class="button-link delete-attachment">delete permanently</button>             <div class="compat-meta">             </div>         </div> 

depending on mean when talk user ids.

you maybe can use function edit_post_link( $link, $before, $after, $id, $class ); $id post (or attachment) id

this show link according user capatibilities.

more details edit_post_link

$user = wp_get_current_user(); $allowed_roles = array('editor', 'administrator', 'author'); // can authorized ids  // you'll need replace $user->roles $user->id in array_intersect     if( array_intersect($allowed_roles, $user->roles ) ) {  ?>          <div class="details">             <div class="filename">29982792291_9e1fc5b238_k-1.jpg</div>             <div class="uploaded">november 9, 2016</div>             <div class="file-size">1 mb</div>             <div class="dimensions">2048 × 1365</div>             <?php echo edit_post_link( __('edit image', text-domain), '', '', $id );?>             <button type="button" class="button-link delete-attachment">delete permanently</button>             <div class="compat-meta">             </div>        </div>    <?php } ?> 

you can check if user logged , role display link current_user_can()


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -