Roles or Edit only in the same Location

Home Forums HRM Roles or Edit only in the same Location

Tagged: , , , ,

This topic contains 3 replies, has 2 voices, and was last updated by  Shawon Chowdhury 1 year, 5 months ago.

  • Author
  • #6880


    Hello, first of all, great plugin, I’ve been trying to figure out if its all what i need to implement it in a small business and so far its all good. Planning to buy the extension to add documents.
    BUT!, I’ve a problem, and that would be that I need to create kind of a role, or add some line of code to make/let people only edit employees that are in the same Location.

    If i check the lines of codes in “single php”, in the actions box, i think that i could use something similar to (couldn’t past the whole code, but you get the idea):
    if ( $employee->get_status() != 'Terminated' && current_user_can( 'erp_create_employee' ) ):

    Or add a condition in:
    if ( current_user_can( 'erp_edit_employee', $employee->id ) ) {
    Is it possible ?. Its the only thing that i think that is missing so far.

    • This topic was modified 1 year, 5 months ago by  JuacOHI. Reason: formatting
  • #6901

    Shawon Chowdhury

    Thanks for writing. But I am a little bit confused about the use case.
    It would be great if you can make me clear on the use case of this role 🙂

  • #6905


    Sorry if i wasn’t clear.

    I’m asking if is possible to only let people edit employees that are from the same location. (From ERP Settings -> Locations), which when you add a new employee is this data: (I deleted the part that it says php becaue can’t paste php code)
    <li data-selected="{{ }}">
    erp_html_form_input( array(
    'label' => __( 'Location', 'erp' ),
    'name' => 'work[location]',
    'value' => '{{ }}',
    'custom_attr' => array( 'data-id' => 'erp-company-new-location' ),
    // 'class' => 'erp-hrm-select2-add-more erp-hr-location-drop-down',
    'class' => 'erp-hrm-select2',
    'type' => 'select',
    'options' => erp_company_get_location_dropdown_raw()
    ) );

    So, in resume if I have 3 locations (main location, second and third), and I have an employee that can manage HRM , and this person is from Main Location, only let him edit employees that are from Main Location and NOT from second and third.
    After taking in consideration what i just said, if i go to single.php (where you can find all the code to show the employee), I think that I could add a condition in the button edit to ONLY show that button if i’m from the same Location, and if not, hide the button but i can still see the employee from other locations.

    So I think that the code would be something like… get current user and ask his location, and then ask the location of the employee that i’m seeing, and if both match, let me edit that employee.
    My best guess is that it should be in this line of code, which is when it shows the edit button in the Action Box.
    <h3 class="hndle"><span>( 'Actions', 'erp' ); ?></span></h3>
    <div class="inside">

    if ( current_user_can( 'erp_edit_employee', $employee->id ) ) {

    <span class="edit">id; ?>" data-single="true" href="#">_e( 'Edit', 'erp' ); ?></span>

  • #6911

    Shawon Chowdhury


    This is the file location where the capabilities have been set up.
    modules/hrm/includes/functions-capabilities.php line no 138
    And you can use this filter erp_hr_map_meta_caps and make a plugin to manage custom roles instead of changing the core codes.

    Thanks and feel free to let me know if you need more help from me 🙂

You must be logged in to reply to this topic.