Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active January 25, 2018 02:34
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/79178f9f3696e61ebb8efe80ecfb84ef to your computer and use it in GitHub Desktop.
Save tripflex/79178f9f3696e61ebb8efe80ecfb84ef to your computer and use it in GitHub Desktop.
Allow featured_image to be set as admin only field
<?php
add_filter( 'job_manager_field_editor_js_conf_meta_keys', 'smyles_allow_featured_image_admin_only' );
function smyles_allow_featured_image_admin_only( $js_config ) {
if ( ! array_key_exists( 'featured_image', $js_config ) || ! array_key_exists( 'disable_fields', $js_config['featured_image'] ) ) {
return $js_config;
}
$found_index = array_search( 'admin_only_0', $js_config['featured_image']['disable_fields'] );
if ( $found_index ) {
unset( $js_config['featured_image']['disable_fields'][ $found_index ] );
}
return $js_config;
}
//
//
// OR YOUR CAN USE THIS ONE BELOW, THEY BOTH DO THE SAME THING, ONLY USE ONE OR THE OTHER!
//
//
add_filter( 'job_manager_field_editor_js_conf_meta_keys', 'smyles_allow_featured_image_admin_only' );
/**
* Allow featured_image to be set as admin only
*/
function smyles_allow_featured_image_admin_only( $config ){
// Make sure admin_only_0 is in disabled fields first (_0 added for any checkboxes)
if( isset( $config['featured_image'], $config['featured_image']['disable_fields'] ) ){
// Flip values to array keys so we can unset admin_only_0 and still retain other values
$flipped = array_flip( $config['featured_image']['disable_fields'] );
// Remove admin_only_0 from array
unset( $flipped['admin_only_0'] );
// Flip back to values
$unflipped = array_flip( $flipped );
// Set modified values
$config['featured_image']['disable_fields'] = $unflipped;
}
return $config;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment