I am trying to replace the publish button text to Submit for review only for specific user role. But I can't find anything which can specify current user role and apply the filter. Here's my code, it's not working.
add_filter( 'gettext', 'change_publish_button', 10, 2 ); function change_publish_button( $translation, $text ) { if( !current_user_can('administrator') ) { if ( $text == 'Publish' ) return 'Submit for review'; }; return $translation; }I also tried using
$current_user = wp_get_current_user();It didn't work either. With my little knowledge, I could understand that calling capabilities.php would require code like this -
if (in_array('level-1-contributor', $current_user->roles))
add_action('init','do_stuff');But I don't understand how can I achieve what I want. Need your help.
Edit for people trying to make stupid comments - gettext is used to change wordpress dashboard text's without hard-coding that. You can use gettext as functions.php function or in a plugin. Wordpress publish button in the dashboard - it's the universal post/page/custom post type publish button. So what I want - I want to use gettext filter so that I can replace publish button text to something else without editing wordpress core files. I could achieve that. But I am trying to make this function work only for specific user role. Suppose "Author". I tried adding
if (current_user_can('author'))but it gives me error. I can't call anything that gives me user information inside gettext filter. How can I bypass that or do it in different way so that I can achieve what I want?
publish_posts
capability then the button and behaviour will automatically.