Custom – sMyles Plugins https://plugins.smyl.es WordPress and WHMCS Plugins Mon, 31 Mar 2025 18:52:15 +0000 en-US hourly 1 https://wordpress.org/?v=4.6.29 Admin Only Fields in Conditional Logic https://plugins.smyl.es/docs-kb/admin-only-fields-in-conditional-logic/ Wed, 11 Apr 2018 22:32:54 +0000 https://plugins.smyl.es/?post_type=bwl_kb&p=152820 As of version 1.8.1 of the Field Editor WP Job Manager addon, you can now use the filters below to allow any admin only field, or only specific ones you define … along with a default value for that field (if you want).  Version 1.8.0 or older you were able to select an admin only field, but that was only due to me overlooking those fields and making sure they weren’t selectable (see blog post for more details about this).

By default, admin only fields can NOT be selected anymore in the conditional logic configuration area.  This can easily be changed by using a filter.

Enable/Expose ALL Admin Only Fields

WARNING: this exposes all admin only field values on the frontend of your website in a JavaScript object. It is STRONGLY recommended that you ALSO use the filter below this one to ONLY output specific admin only field values.  I assume NO LIABILITY if you do not heed this warning!

add_filter( 'field_editor_conditional_logic_enable_admin_logic_fields', '__return_true' );

The above code added to your child theme’s functions.php file, or using the Code Snippets plugin, will now allow you to select from any of your configured Admin Only fields, for use in conditional logic checks.

Customize Specific Admin Only Fields to Expose/Enable

It is STRONGLY recommended that you add this filter as well, to specify ONLY what meta keys of admin only fields you want to be used for conditional logic, as to only output those values on the frontend javascript object storage:

There are two filters available for this.  One is for Jobs/Listings:

field_editor_conditional_logic_custom_value_job_admin_fields

The other is for Resumes:

field_editor_conditional_logic_custom_value_resume_admin_fields

Here’s an example using the job/listing filter:

add_filter( 'field_editor_conditional_logic_custom_value_job_admin_fields', 'smyles_logic_admin_only_job_meta_keys' );

function smyles_logic_admin_only_job_meta_keys( $admin_only ){
	$admin_only = array( 'job_admin_only' );
	return $admin_only;
}

As you can see in the example above, I am ONLY returning the job_admin_only  meta key through the filter, specifying I only want that one to be used for logic and to be output on the frontend javascript object storage (the value of that field for the listing).

Multiple meta keys can be specified by simply adding another one in the array:

$admin_only = array( 'job_admin_only', 'job_admin_only_2' );

The values passed to the example function above $admin_only , is an array of all the admin only fields on your site.  By simply redefining that array and returning our new one, you are instructing my plugin to ONLY allow that field for use.

Specifying Default Values

You can also specify a default value you want to be used whenever a new listing is being created, or when an existing listing is being edited, that does not have a value saved to the listing, for that field.  To do this, we just create a nested array on the meta key we want to set the default value for:

$admin_only = array( 'job_admin_only' => array( 'default' => 'VALUE' ) );

This will result in any logic you have setup on that field, to use that VALUE  as default.  For example, a user is creating a new listing, and you have logic configured to show job_salary  when job_admin_only  is VALUE  … when the page loads, the job_salary  field will be showing, because you have set VALUE as a default value for that field.  If you then edit that listing as an administrator in the admin backend and change that value to something else … when the frontend user goes to edit the listing again, they will no longer see the job_salary  field.

Here’s a full example with all the features described above:

add_filter( 'field_editor_conditional_logic_enable_admin_logic_fields', '__return_true' );
add_filter( 'field_editor_conditional_logic_custom_value_job_admin_fields', 'smyles_logic_admin_only_job_meta_keys' );

function smyles_logic_admin_only_job_meta_keys( $admin_only ){

	$admin_only = array(
		'job_admin_only' => array(
			'default' => 'yes'
		),
		'job_admin_only_2' => array(
			'default' => 'no'
		),
	);

	return $admin_only;
}

 

]]>
Give user free/trial visibility package on registration https://plugins.smyl.es/docs-kb/give-user-freetrial-visibility-package-on-registration/ Mon, 02 Apr 2018 21:29:33 +0000 https://plugins.smyl.es/?post_type=bwl_kb&p=152404 After a few request from clients, I have come up with a method that you can automagically give a user a package when they register on your site, which can be used as a way to provide a “free trial” or “free” package initially.  This does require adding some PHP code to your child theme’s functions.php file (or using the Code Snippets plugin).

As of  version 1.2.1+ a feature has been added to “give” a package to user on registration in the product configuration page.  You can then set the product  as hidden, and users won’t be able to select the package from package selection page, but will be given the package on registration.

I have been looking at different ways to integrate this into the plugin for a future update, probably when creating a new visibility package you can select a checkbox that says something like “Hide from cart, and assign to new users on registration”, but if you would like this functionality before I can release this update, here’s some example code to do this:

You will notice there are two actions, one for Job and one for Resumes … if you only need this for Job packages, or only for Resume packages, you can omit the add_action and the associated function (do not omit the function to check user roles).  As an example, if you only needed this for Job Packages, you would use this code instead:

You will also notice in the code that there is a check for the User Role before assigning a package.  You can change this to any specific user role you want, but in these examples the user role of employer is used for Job Visibility packages, and candidate for Resume Visibility Packages.

]]>
Using custom template overrides for form input fields (form-fields) https://plugins.smyl.es/docs-kb/using-custom-template-overrides-for-input-fields/ Wed, 07 Feb 2018 19:21:39 +0000 https://plugins.smyl.es/?post_type=bwl_kb&p=149517 If you plan to use Template Overrides for WP Job Manager, and those template overrides are for any of the input fields (any files inside the form-fields  directory), and you are using the Field Editor plugin, there are a few things you need to be aware of.

This documentation is only applicable for any of the FORM FIELD templates (found inside form-fields directory), all other template overrides will work like normal and you should follow the WP Job Manager Template Overrides documentation for that.

Template Files

Because WP Job Manager Field Editor adds many features to the existing field types included with WP Job Manager, as well as, numerous custom field types, if you want to customize these templates, you MUST use the template files from the wp-content/plugins/wp-job-manager-field-editor/templates/form-fields  directory to retain the enhancements and added features.  If you do not, features such as, max selected images, max selected categories, max image size, etc, will not work correctly if you use the default form field templates from the WP Job Manager templates directory.

So first, you will need to look in that directory, wp-content/plugins/wp-job-manager-field-editor/templates/form-fields, and see if the form field template file exists that you want to customize (if it does not, you can just follow the default WP Job Manager template overrides documentation).

Template Directory

Next you will need to create a new directory inside your CHILD THEME directory to store these template override files.   Just like in the documentation for WP Job Manager template override files, everything is exactly the same, except instead of using job_manager  as the directory, you MUST use field_editor  instead.  You can then create another directory inside field_editor  directory, named form-fields  (just like in WP Job Manager documentation).

Examples

So as an example, if you’re using the Jobify theme, and want to customize the multiselect field template file, you need to create two directories inside your jobify child theme:

/wp-content/themes/jobify-child/field_editor/
/wp-content/themes/jobify-child/field_editor/form-fields

You would then copy the /wp-content/plugins/wp-job-manager-field-editor/templates/form-fields/multiselect-field.php  file to the form-fields directory we just created, ultimately resulting in this file:

/wp-content/themes/jobify-child/field_editor/form-fields/multiselect-field.php

You can then edit that file, make any modifications you would like, and that template file will be used instead of the default WP Job Manager Field Editor one.

This is exactly the same as the WP Job Manager Template Overrides, with the exception of using field_editor as the root directory in your child theme’s directory, instead of job_manager.

Why not just use job_manager structure?

The reason I decided to take priority of field editor templates over the default WP Job Manager form field templates, is as explained above, because WP Job Manager Field Editor adds many features to existing form fields, and as such, to prevent errors on sites, features from not working, etc, I configured it so you must use the field_editor directory to specify that you are in fact, using the field editor template files.  This was also done to prevent backwards compatibility issues with older, out-dated template files that may still exist on client sites.

]]>
How to customize the phone field type https://plugins.smyl.es/docs-kb/how-to-customize-the-phone-field-type/ Mon, 13 Apr 2015 18:19:48 +0000 https://plugins.smyl.es/?post_type=bwl_kb&p=60443 Want to auto detect the user’s country based on their IP?  Maybe you want to have the phone field type default to a specific country?  What about putting preferred countries at the top of the dropdown list?  You can do all of this and more with the new filter added in WP Job Manager Field Editor version 1.2.6.

Overview

The open source jQuery plugin used for the phone field type is called International Telephone Input, and you can find all the information you would need about it (including details on the available configuration and options) on GitHub:

https://github.com/Bluefieldscom/intl-tel-input

As the latest version from above is newer than the current version included with the field editor, please see this URL for documentation on the version included with the field editor:

https://github.com/jackocnr/intl-tel-input/tree/8a2364bc0459fce934d7cf04a82823db63e7944b

In order to modify any of the default options you will need to use a WordPress Filter that is placed in your theme’s functions.php  file.  The filter you will need to use to override the default arguments is:

job_manager_field_editor_phone_args

Below you will see the code directly from the plugin that shows the currently supported options/configurations:

$phone_args = apply_filters( 'job_manager_field_editor_phone_args', array(
	'allowExtensions'    => false,
	'autoFormat'         => true,
	'autoHideDialCode'   => true,
	'autoPlaceholder'    => true,
	'defaultCountry'     => '',
	'ipinfoToken'        => '',
	'nationalMode'       => false,
	'numberType'         => 'MOBILE',
	'preferredCountries' => array('us', 'gb'),
	'utilsScript'        => WPJM_FIELD_EDITOR_PLUGIN_URL . '/assets/js/phoneutils.min.js'
	)
);

 

You should never need to modify the utilsScript value (unless you really know what you’re doing).  Make sure to read the GitHub page for specific details on the values before changing them.

Example Configuration

Note: any options that take country codes should be ISO 3166-1 alpha-2 codes

For this example we will be changing the phone field type to automatically detect and select the user’s country based on their IP.  If the location can not be determined by IP, we will have it default to France.  We will also set the countries to show at the top of the dropdown list to France, and Germany.

Phone Field Type Custom Configuration

If you read the documentation from the GitHub page, you will see that if we set the value of defaultCountry to auto it will automatically attempt to detect the user’s location based on their IP.  That is why in the example screenshot above you can see the country shows USA, but the other countries at the top are France and Germany.  This is because my IP address is located in the USA and it automatically set it to USA.

To set the countries at the top of the dropdown list, we will use preferredCountries

This would be the final code you would need to add to your functions.php file, I will go over each part below.

add_filter( 'job_manager_field_editor_phone_args', 'my_custom_phone_args' );

function my_custom_phone_args( $args ){

	$args['preferredCountries'] = array( 'fr', 'de' );
	$args['defaultCountry'] = 'auto';

	return $args;
}

 Example Breakdown

So the first code we need to add is the add_filter  which tells WordPress to run our custom function so we are able to modify the values:

add_filter( 'job_manager_field_editor_phone_args', 'my_custom_phone_args' );

The code above adds a hook to the field editor filter, and then runs my_custom_phone_args  function whenever the filter is called from the plugin.

The next code added is the function that is called:

function my_custom_phone_args( $args ){

	$args['preferredCountries'] = array( 'fr', 'de' );
	$args['defaultCountry'] = 'auto';

	return $args;
}

As you can see in the function above, $args  is passed to the function which includes all of the default arguments.  Using standard PHP we can modify those values as needed, and as you see at the bottom, then return the $args  back to the hook.  You MUST return the $args  otherwise you will have issues.  Using the country codes obtained from the ISO 3166-1 alpha-2 codes, the possibilities are endless!

This same method can be used to override any of the other default configuration values, but PLEASE make sure to read the documentation on the GitHub page to make sure you use the right values.

If you change any of the boolean values (true or false), do not place them in quotes, they should be just like the values you see above in the default configuration.

]]>
How to output custom fields on job and/or resume listings https://plugins.smyl.es/docs-kb/how-to-output-custom-fields-on-job-andor-resume-listings/ Mon, 25 Aug 2014 20:38:11 +0000 https://plugins.smyl.es/?post_type=bwl_kb&p=2734 As of version 1.1.9 there is an integrated auto output feature!:

https://plugins.smyl.es/docs-kb/field-output-configuration/

As of version 1.1.5 there is an integrated widget you can use to output a custom field:

https://plugins.smyl.es/blog/widget-now-included-with-wp-job-manager-field-editor/

As of version 1.2.0 the widget has undergone a huge overhaul and should have all the same options as auto output:

https://plugins.smyl.es/docs-kb/using-the-integrated-widget/

You can also customize your own job/resume listing template file, and use a Shortcode or PHP Function to output the value of the custom field.

You can find more information about templates from the WP Job Manager Wiki.

You can also find tons of video tutorials on YouTube here:

https://www.youtube.com/playlist?list=PLa5IXe9CvtRhvmXN1QHIIh73bOyOA8fO5

If you have any questions or need help, feel free to open a support ticket or contact me for further assistance.

]]>
Output custom field values using PHP https://plugins.smyl.es/docs-kb/output-custom-field-values-using-php/ Mon, 25 Aug 2014 15:51:30 +0000 https://plugins.smyl.es/?post_type=bwl_kb&p=2735 To output any custom fields you have created you can either use Shortcodes or one of the following PHP functions to output the custom field values.

Right now there are multiple functions available, one for job fields, company fields, resume fields, etc. This is for any future enhancements, but currently all functions do the same thing (so technically you could use get_resume_field and with details for a job listing and it will still display right. My Suggestion is to use job, company, or resume for the specific field, and if you are not sure then you can use custom field function.

You can find all of these functions and details on them in the includes/functions.php file under the wp-job-manager-field-editor plugin directory.

I also recommending looking through my Gist on GitHub as this is where I frequently post examples (PHP, JS, etc) for support tickets and I may already have some example code you need:

https://gist.github.com/tripflex

Available Functions


get_job_field / the_job_field

get_job_field( $field_slug, $job_id, $args ) or the_job_field( $field_slug, $job_id, $args )

  • $field_slug is the meta key for the field
  • $job_id optional The job ID you want to get the value from, if $job_id is not specified it will use the current job listing.
  • $args optional Array with key => value configuration (can be any configuration attribute available in shortcodes). See below for more details.
  • Using get_job_field will return the value, using the_job_field will echo/print out the field.

get_company_field / the _company_field

get_company_field( $field_slug, $job_id, $args ) or the_company_field( $field_slug, $job_id, $args )

  • $field_slug is the meta key for the field
  • $job_id optional The job ID you want to get the value from, if $job_id is not specified it will use the current job listing.
  • $args optional Array with key => value configuration (can be any configuration attribute available in shortcodes). See below for more details.
  • Using get_company_field will return the value, using the_company_field will echo/print out the field.

get_resume_field / the_resume_field

get_resume_field( $field_slug, $resume_id, $args ) or the_resume_field( $field_slug, $resume_id, $args )

  • $field_slug is the meta key for the field
  • $resume_id optional The resume ID you want to get the value from, if $resume_id is not specified it will use the current resume listing.
  • Using get_resume_field will return the value, using the_resume_field will echo/print out the field.

get_custom_field / the_custom_field

get_custom_field( $field_slug, $post_id, $args ) or the_custom_field( $field_slug, $post_id, $args )

  • $field_slug is the meta key for the field
  • $post_id optional The resume/job ID you want to get the value from, if not specified it will use the current resume/job listing.
  • $args optional Array with key => value configuration (can be any configuration attribute available in shortcodes). See below for more details.
  • Using get_custom_field will return the value, using the_custom_field will echo/print out the field.

Example Usage

Say I wanted to output a new custom field I created with a meta key of job_salary, this is the PHP code you would add to your job listing template file:

Using `get_job_field`

$salary = get_job_field( 'job_salary' );
echo $salary;

Or you could simply use the_job_field function instead:

Using the_job_field

the_job_field( 'job_salary' );

Both of the examples above would output the value of the field if it was set for the job listing. This same method can be used for company, resumes, or any other custom fields.

Show image from custom upload field

$image_url = get_company_field( 'company_office_photo' );
echo '<img src="' . $image_url '" />';

 

Passing $args configurations

You can pass any configuration arguments/attributes available in shortcodes, when calling PHP functions.  If you do not want to define the listing ID, and want to force my plugin to automagically detect the listing id, just pass null to the listing id, like so:

the_job_field( 'some_job_field', null, array( 'output_as' => 'text' ) );

As you can see above, just pass null as the second parameter, and then in the third parameter you can define configurations.

Here’s a few more examples for reference:

Output “another_custom_field” showing label, and with full wrapper HTML element enabled

the_custom_field( 'another_custom_field', null, array( 'output_show_label' => true, 'output_enable_fw' => true ) );

Define arguments configuration in separate variable

$website_link_args = array(
    'output_as' => 'link',
    'output_show_label' => true,
    'output_classes' => 'some-class another-one',
);

the_custom_field( 'website_link', null, $website_link_args );

 

]]>