Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created August 24, 2021 00:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/4a716156576628b939ffa640cd56cb9b to your computer and use it in GitHub Desktop.
Save tripflex/4a716156576628b939ffa640cd56cb9b to your computer and use it in GitHub Desktop.
Remove specific fields from submit form based on current user role when using WP Job Manager Field Editor
<?php
add_filter( 'submit_job_form_fields', 'smyles_remove_fields_by_user_role', 999999999999 );
function smyles_remove_fields_by_user_role( $fields ){
$fields_to_remove = array( 'job_salary', 'some_other_meta_key' );
$user = wp_get_current_user();
if ( in_array( 'employer', (array) $user->roles ) ) {
foreach( $fields_to_remove as $meta_key ){
if( isset( $fields['job'][ $meta_key ] ) ){
unset( $fields['job'][ $meta_key ] );
}
}
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment