• Resolved davidrevo

    (@davidrevo)


    Hi Mike,

    We are experiencing problems every time when we update your plugin. For customization purpose, we have made some modifications to your plugin files in root directory and include directory. I don’t know how to override them in child theme so that every time the plugin is updated, our site is broken. Thanks a lot if you could help me a way to solve it. Cheers!

    Best Regards,
    Wei

    https://www.ads-software.com/plugins/wp-job-manager/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mike Jolley

    (@mikejolley)

    Can you provide 1 example of a customisation you have made and I’ll tell you if there is an upgrade safe method of doing the same change.

    Thread Starter davidrevo

    (@davidrevo)

    Hi Mike,

    One example would be adding a “job region” field ajax search, I changed both some code in “ajax-filter.min.js” (in assets/js/ folder) and “class-wp-job-manager-ajax.php” (in include/ folder). To do this, one more field is added to the ajax search in order to get a concise search based on our scenario.

    The code snippet of the customization is below with changes in bold:

    <——– class-wp-job-manager-ajax.php ———–>

    $result            = array();
    $search_location   = sanitize_text_field( stripslashes( $_POST['search_location'] ) );
    $search_keywords   = sanitize_text_field( stripslashes( $_POST['search_keywords'] ) );
    <strong>$search_regions     = isset( $_POST['search_regions'] ) ? $_POST['search_regions'] : '';</strong>
    $search_categories = isset( $_POST['search_categories'] ) ? $_POST['search_categories'] : '';
    $filter_job_types  = isset( $_POST['filter_job_type'] ) ? array_filter( array_map( 'sanitize_title', (array) $_POST['filter_job_type'] ) ) : null;
    
    if ( is_array( $search_categories ) ) {
    	$search_categories = array_filter( array_map( 'sanitize_text_field', array_map( 'stripslashes', $search_categories ) ) );
    } else {
    	$search_categories = array_filter( array( sanitize_text_field( stripslashes( $search_categories ) ) ) );
    }
    
    <strong>if ( is_array( $search_regions ) ) {
    	$search_regions = array_filter( array_map( 'sanitize_text_field', array_map( 'stripslashes', $search_regions ) ) );
    } else {
    	$search_regions = array_filter( array( sanitize_text_field( stripslashes( $search_regions ) ) ) );
    }	</strong>	
    
    $args = array(
    	'search_location'   => $search_location,
    	'search_keywords'   => $search_keywords,
    	<strong>'search_regions'  	=> $search_regions,</strong>
    	'search_categories' => $search_categories,
    	'job_types'         => is_null( $filter_job_types ) ? '' : $filter_job_types + array( 0 ),
    	'orderby'           => sanitize_text_field( $_POST['orderby'] ),
    	'order'             => sanitize_text_field( $_POST['order'] ),
    	'offset'            => ( absint( $_POST['page'] ) - 1 ) * absint( $_POST['per_page'] ),
    	'posts_per_page'    => absint( $_POST['per_page'] )
    );

    <—————— ajax-filter.min.js ——————->

    jQuery(document).ready(function(a){var b;a(".job_listings").on("update_results",function(c,d,e){b&&b.abort();var f="",g=a(this),h=g.find(".job_filters"),i=g.find(".showing_jobs"),j=g.find(".job_listings"),k=g.data("per_page"),l=g.data("orderby"),m=g.data("order");if(e?a(".load_more_jobs",g).addClass("loading"):(a(j).addClass("loading"),a("li.job_listing",j).css("visibility","hidden")),g.data("show_filters")){var n=[];a(':input[name="filter_job_type[]"]:checked, :input[name="filter_job_type[]"][type="hidden"]',h).each(function(){n.push(a(this).val())});var o=h.find(":input[name^=search_categories], :input[name^=search_categories]").map(function(){return a(this).val()}).get();var z=h.find(":input[name^=search_regions], :input[name^=search_regions]").map(function(){return a(this).val()}).get(),p="",q="",r=h.find(":input[name=search_keywords]"),s=h.find(":input[name=search_location]");r.val()!==r.attr("placeholder")&&(p=r.val()),s.val()!==s.attr("placeholder")&&(q=s.val()),f={action:"job_manager_get_listings",search_keywords:p,search_location:q,search_categories:o,search_regions:z,filter_job_type:n,per_page:k,orderby:l,order:m,page:d,form_data:h.serialize()}}else f={action:"job_manager_get_listings",search_categories:g.data("categories").split(","),search_regions:g.data("regions").split(","),search_keywords:g.data("keywords"),search_location:g.data("location"),per_page:k,orderby:l,order:m,page:d};b=a.ajax({type:"POST",url:job_manager_ajax_filters.ajax_url,data:f,success:function(b){if(b)try{b.indexOf("<!--WPJM-->")>=0&&(b=b.split("<!--WPJM-->")[1]),b.indexOf("<!--WPJM_END-->")>=0&&(b=b.split("<!--WPJM_END-->")[0]);var c=a.parseJSON(b);c.showing?a(i).show().html("").append("<span>"+c.showing+"</span>"+c.showing_links):a(i).hide(),c.html&&(e?a(j).append(c.html):a(j).html(c.html)),c.found_jobs&&c.max_num_pages!==d?a(".load_more_jobs",g).show().data("page",d):a(".load_more_jobs",g).hide(),a(j).removeClass("loading"),a(".load_more_jobs",g).removeClass("loading"),a("li.job_listing",j).css("visibility","visible")}catch(f){}}})}),a("#search_keywords, #search_location, .job_types input, #search_categories, #search_regions").change(function(){var b=a(this).closest("div.job_listings");b.trigger("update_results",[1,!1])}).change(),a(".job_filters").on("click",".reset",function(){var b=a(this).closest("div.job_listings"),c=a(this).closest("form");return c.find(":input[name=search_keywords]").val(""),c.find(":input[name=search_location]").val(""),c.find(":input[name^=search_categories]").val(0),c.find(":input[name^=search_regions]").val(0),a(':input[name="filter_job_type[]"]',c).attr("checked","checked"),b.trigger("reset"),b.trigger("update_results",[1,!1]),!1}),a(".load_more_jobs").click(function(){var b=a(this).closest("div.job_listings"),c=a(this).data("page");return c=c?parseInt(c):1,a(this).data("page",c+1),b.trigger("update_results",[c+1,!0]),!1})});

    Thanks for help, Mike

    Plugin Author Mike Jolley

    (@mikejolley)

    Right. Looks like it removed your bold, but just as an example lets take the line:

    'search_regions' => $search_regions,

    which you add to the args array.

    A few lines below this you’ll see:

    $jobs = get_job_listings( apply_filters( 'job_manager_get_listings_args', $args ) );

    So you actually have the potential there to hook in a custom function instead of modifying the code. I’ll provide this one as an example so you can reference for other changes and learn:

    function custom_job_manager_get_listings_args( $args ) {
    
       // Get your field value here for $search_regions
    
       $args['search_regions'] = $search_regions;
    
      return $args;
    }
    
    add_filter( 'job_manager_get_listings_args', 'custom_job_manager_get_listings_args' );

    Does that make sense? You can then build your extra functionality outside of the core plugin, either inside your theme functions.php file or in a custom plugin of your own.

    Thats what I do with all my addons.

    Thread Starter davidrevo

    (@davidrevo)

    Thanks for your detailed explanation, Mike. That’s easy to understand. Basically, adding custom functions to existing filter is the way to solve out breaking the original code. I will give it a try. This info really helps a lot. Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Override root files and files in "include" folder’ is closed to new replies.