Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active December 12, 2017 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/a71be4c627589c474ac60e9c2391427d to your computer and use it in GitHub Desktop.
Save tripflex/a71be4c627589c474ac60e9c2391427d to your computer and use it in GitHub Desktop.
Visibility integration for Field Editor placeholder output to output placeholder for custom fields
<?php
// ^ DISREGARD THIS, ONLY FOR SYNTAX HIGHLIGHTING ON GITHUB
// THIS IS ONLY REQUIRED FOR WP JOB MANAGER FIELD EDITOR VERSION 1.7.10 OR OLDER, 1.7.11+ THIS IS ALREADY INTEGRATED
// EDIT THE FILE LOCATED AT:
// wp-content/plugins/wp-job-manager-field-editor/includes/functions.php
// ON/AROUND LINE NUMBER 539, YOU SHOULD SEE CODE THAT LOOKS EXACTLY LIKE THIS:
if( $enable_vw ) {
echo "<{$value_wrapper} id=\"jmfe-custom-{$field_slug}\" class=\"jmfe-custom-field {$value_wrap_classes}\" {$vw_atts}>";
}
switch( $output_as ){
<?php
// ^ DISREGARD THIS, ONLY FOR SYNTAX HIGHLIGHTING ON GITHUB
// THIS IS THE BLOCK OF CODE YOU NEED TO ADD RIGHT ABOVE THE "switch( $output_as )":
$post_type = get_post_type( $job_id );
// Change output_as to value if we're outputting a visibility placeholder (to prevent handling custom output on placeholder value)
if ( $post_type && $visibility_placeholder = apply_filters( "field_editor_output_{$post_type}_visibility_placeholder", false, $field_slug, $field_value, $args, $job_id ) ) {
$output_as = 'value';
}
<?php
// ^ DISREGARD THIS, ONLY FOR SYNTAX HIGHLIGHTING ON GITHUB
// THIS IS HOW IT SHOULD LOOK BELOW AFTER ADDING THE NEW CODE BLOCK:
// Output value wrapper if enabled
if( $enable_vw ) {
echo "<{$value_wrapper} id=\"jmfe-custom-{$field_slug}\" class=\"jmfe-custom-field {$value_wrap_classes}\" {$vw_atts}>";
}
$post_type = get_post_type( $job_id );
// Change output_as to value if we're outputting a visibility placeholder (to prevent handling custom output on placeholder value)
if ( $post_type && $visibility_placeholder = apply_filters( "field_editor_output_{$post_type}_visibility_placeholder", false, $field_slug, $field_value, $args, $job_id ) ) {
$output_as = 'value';
}
switch( $output_as ){
@tripflex
Copy link
Author

To explain a little more in detail, when a custom field is set with "Output As" to something other than value or standard (like gallery, link, image, oembed, etc), the placeholder value was previously used when field editor attempts to output. With this update, this tells Field Editor to output as value regardless of what the output as configuration is set as.

This will allow you to customize your own placeholders to output, so for example, if a field was set to output as link ... no longer will the placeholder be set inside the link HTML, you can now output your own custom HTML or whatever you want, as only the value is output, and not the HTML markup generated by the Field Editor plugin.

This requires WP Job Manager Visibility version 1.4.7 or newer, and this update is only required for WP Job Manager Field Editor 1.7.10 or older (1.7.11+ has this integrated already)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment