Configuration – sMyles Plugins https://plugins.smyl.es WordPress and WHMCS Plugins Tue, 17 Dec 2024 22:26:17 +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;
}

 

]]>
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 only allow admin specified skills to be selected https://plugins.smyl.es/docs-kb/how-to-only-allow-admin-specified-skills-to-be-selected/ Thu, 29 Jan 2015 16:27:24 +0000 https://plugins.smyl.es/?post_type=bwl_kb&p=39675 By default WP Job Manager Resumes Skills field will show a textbox for users to enter a comma separated list of skills.  If you decide you do not want users to be able to specify their own skills, you can use WP Job Manager Field Editor to change the field type which will only allow them to select skills that you have added under the Candidate Skills taxonomy section for Resumes.

Change Resume Candidate Skills Field

Change Resume Candidate Skills Field

Head on over to the Resume fields section and locate the resume_skills meta key in the list table (you must have Resume Skills enabled in the WP Job Manager Resume Settings), and click on the Edit link.

This will bring up the configuration for the Resume Skills field, the key items you want to update will be the Type and Taxonomy.

Type – click on the dropdown and select Taxonomy Multi-Select Dropdown

Taxonomy – enter in resume_skill (you must enter resume_skill exactly as you can see in the screenshot)

 

Candidate Skills Frontend Demo

Candidate Skills Frontend Demo

 

Click save, head on over to your site and you will see that now users can only select from items you added to the Candidate Skills section!

Profit!

]]>