php – Show icon on frontend if current user is the author of post

html - Animation after toggling doesn't apply the second style

When a user registers on my website, a single post is automatically created (under a custom post type) with the user assigned as the author to that post. This post is essentially the user’s “profile page”.

Any user is able to see any other users profile page. However, I would like a button to appear on the profile page if it belongs to the logged in user.

In other words: if the logged-in user is the author of the post that is currently being viewed (on the frontend), then display the button.

The below is the closest I have come to achieving what I need to do – I have created a button with css id #profile_edit_button and hidden it by default using display:none. The code below “unhides” the button, but on all profile pages. It also throws out the following errors:

Warning: Undefined variable $user_session_id
Warning: Undefined variable $author_id

The code I’ve used is as follows. Any guidance would be greatly appreciated.

 if($user_session_id == $author_id) {
    <style type="text/css">
        #profile_edit_button {
            display: flex !important;
    <?php } ?>

Source link

Leave a reply

Please enter your comment!
Please enter your name here