0

What is the best/proper way to implement multiple filters from one function or using my add_filter one time? If I can not combine multiple functions or actions in my one filter what is the proper naming I should use to avoid conflicts?

I am modifying the "Add Resume" Page for the wp-job-manager-resume add-on plugin. I am following the tutorial on their website for adding, removing, and (right now) renaming fields. Editing Resume Form. I am using add_filter and I want to see how I can optimize what I am doing by combining the many filters I want to make into 1 function. I want to see if there is some way to combine multiple filters into one:

// Add our own function to filter the fields
add_filter( 'submit_resume_form_fields', 'custom_submit_resume_form_fields' );

// This is the function which takes the fields, modifies them, and returns them
function custom_submit_resume_form_fields( $fields ) {

    $fields['resume_fields']['candidate_title']['label'] = "Job Type";

    return $fields;
}

add_filter( 'submit_resume_form_fields', 'custom_submit_resume_form_fields' );

function custom_submit_resume_form_fields( $fields ) {

    $fields['resume_fields']['candidate_photo']['label'] = "Profile Image";

    return $fields;
}

So I want to end up with something like

add_filter( 'submit_resume_form_fields', 'custom_submit_resume_form_fields' );

function custom_submit_resume_form_fields( $fields ) {
   $fields['resume_fields'] array(['candidate_title']['label'] = "Job Type",
   ['candidate_photo']['label'] = "Profile Image");

   return $fields;
}
0

Perhaps I'm missing something in your question, but just move the line from one function to the other...

function custom_submit_resume_form_fields( $fields ) {

    $fields['resume_fields']['candidate_title']['label'] = "Job Type";
    $fields['resume_fields']['candidate_photo']['label'] = "Profile Image";

    return $fields;
}
1
  • Ok I actually just found an example of this in some other code. I didn't realize this was a legal way to do it.
    – mrhobbeys
    Nov 6 '15 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.