WordPress Freelancer Hooks API

WordPress Freelancer Hooks API allows you to hook into and alter almost any aspect of the WordPress Freelancer Plugin. Be it either customizing the front end appearance of a widget or back end options of a widget, just hook into the correct filter with your custom function to do whatever you want. WordPress Freelancer Hooks API consists of ten main hooks. The following is a detailed explanation of them.

WordPress Freelancer Hooks for customizing Widget Frond End Appearance

WordPress Freelancer Plugin provides three main widgets for your sidebars. ‘Profile’, ‘Feedback’ and ‘Affiliate’ widgets. You can customize the styling of these widgets via theme customizer section that comes with this plugin. Those customizations apply to all three widgets.

In addition to theme customizer, each tab in the Freelancer Plugin Dashboard allows you to turn on/off components in each widget. With those settings you are given enough options to customize the widgets. Do you need even more flexibility in altering the widgets?

WordPress Freelancer Hooks API gives you the power and freedom to completely customize the widget appearance. e.g. You can filter the total front end output of a widget by hooking into the relevant hooks and output whatever you need to output as the widget front end. You will be given all the details that were used to generate the widget front end output.

Customizing Widget Front End Appearance using WordPress Freelancer Hooks

API

The following three filter hooks give you the complete control over the widget front end output.

  1. ‘uwf-profile-front’ for profile widget front end
  2. ‘uwf-feedback-front’ for feedback widget front end
  3. ‘uwf-affiliate-front’ for affiliate widget front end

‘UW_Freelancer_Profile’ class extends ‘WP_Widget’ class to generate the profile widget. ‘widget’ method in that class calls a view called ‘profile-front.php’. At the end of this file, after processing the output, the widget front end content is echoed.

Just before echoing the output it apply filters ‘uwf-profile-front’ to the output. This is where you should hook into the widget front end appearance.

echo apply_filters(‘uwf-profile-front’, $output, $user, $uw_freelancer_options, $instance);

What Resources are passed into the Filter Function

Upon hooking, you are given a ‘$user’ variable and ‘$uw_freelancer_options’ variable ($instance variable for widget localization). Those two variables are used generate the widget output. You too can use those variables to extend/generate the widget front end appearance. The following is an skeleton code which you can use in your theme functions.php

1
2
3
4
5
6
add_filter('uwf-affiliate-front', 'customize_uwf_profile_front', 10, 3);

function customize_uwf_profile_front($output, $user, $uw_freelancer_options,
$instance){

}

WordPress Freelancer Hooks API - A Working Example

The API Query Response for a user profile contain two fields that were not used in Profile Widget output generation. (There are couple of other fields as well). ‘id’ field which stands for userid - a numeric value. ‘gold’ field is for gold members. ‘gold’ is a Boolean.

Suppose now we want to extend WordPress Freelancer Profile Widget by adding extra line/section to the profile widget to indicate the user is a gold member or not of freelancer.com (Only if ‘gold’ is true). The following is the default. Without any extra section at bottom of the Profile Widget.

Put the following in your theme funtions.php

1
2
3
4
5
6
7
8
9
add_filter('uwf-profile-front', 'customize_uwf_profile_front', 10, 4);
 
function customize_uwf_profile_front($output, $user, $uw_freelancer_options, $instance){
    
    $gold_member = '<img src="' . plugins_url() . '/uw-freelancer/images/uw-freelancer-gold-member.png" />';
    $output .= $user->gold ? $gold_member : 'Not a Gold Member!';
    
    return $output;
}

After hooking into the widget front appearance filters via WordPress Freelancer Hooks API.

The above example demonstrates how to customize WordPress Freelancer Profile Widget front end using ‘uwf-profile-front’ filter hook. ‘uwf-feedback-front’ can be used to filter and alter WordPress Freelancer Feedback Widget front end. ‘uwf-affliate-front’ hook can be used to customize the WordPress Freelancer Affiliate Widget.

This is the end of the first article on WordPress Freelancer Hooks API. Read more about altering widget back end appearance and adding settings to the admin back end of a widget with WordPress Freelancer Hooks API in the second article.