Last active
January 25, 2018 02:34
-
-
Save tripflex/79178f9f3696e61ebb8efe80ecfb84ef to your computer and use it in GitHub Desktop.
Allow featured_image to be set as admin only field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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