Button hide based on author in elementor

13 Views Asked by At

I have a post type i jet engine "Talent Profile". In single "talent profile" page has a button "Edit Profile" that allows to edit this profile. But I want only this post author can see this button. Other users will not see this button.

I tried this but nothing happened.
add_action('wp', 'hide_edit_profile_button');

function hide_edit_profile_button() {
    // Check if viewing a single post of the "Talent Profile" post type
    if (is_singular('talent_profile')) {
        global $post;

        // Check if the current user is the post author or has a specific role
        $current_user = wp_get_current_user();
        $allowed_roles = array('author', 'editor', 'administrator'); // Adjust as needed
        if ($current_user->ID != $post->post_author && !array_intersect($allowed_roles, $current_user->roles))
 {
            // Remove the "Edit Profile" button
            add_filter('the_content', 'remove_edit_profile_button');
        }
    }
}


function remove_edit_profile_button($content) {
    // Replace the button HTML code with an empty string
    $content = preg_replace('a.jet-listing-dynamic-link__link', '', $content);
    return $content;
}
0

There are 0 best solutions below