Skip to content

Instantly share code, notes, and snippets.

@hmbashar
Created October 2, 2019 22:06
Show Gist options
  • Save hmbashar/0efade1843603a70a734f484505c6dc4 to your computer and use it in GitHub Desktop.
Save hmbashar/0efade1843603a70a734f484505c6dc4 to your computer and use it in GitHub Desktop.
<?php
function post_format_metabox_js() {
if( get_post_type() === 'post'): ?>
<script type="text/javascript">
jQuery(document).ready(function(){
$id = jQuery('input[name="post_format"]:checked').attr('id');
// video
if( $id == 'post-format-video'){
jQuery('.cs-element.cs-element-video-link.cs-field-text').show();
}else{
jQuery('.cs-element.cs-element-video-link.cs-field-text').hide();
}
// Link
if( $id == 'post-format-link'){
jQuery('.cs-element.cs-element-link').show();
jQuery('.cs-element.cs-element-text').show();
}else{
jQuery('.cs-element.cs-element-link').hide();
jQuery('.cs-element.cs-element-text').hide();
}
// Audio
if( $id == 'post-format-audio'){
jQuery('.cs-element.cs-element-audio-link').show();
}else{
jQuery('.cs-element.cs-element-audio-link').hide();
}
// Gallery
if( $id == 'post-format-gallery'){
jQuery('.cs-element.cs-element-gallery-image').show();
}else{
jQuery('.cs-element.cs-element-gallery-image').hide();
}
// video & link & Audio
if( $id == 'post-format-video' || $id == 'post-format-link' || $id == 'post-format-audio' || $id == 'post-format-gallery' ){
jQuery('#ration_post_format_metabox').show();
}else{
jQuery('#ration_post_format_metabox').hide();
}
/**
*
* 2nd step
*
*/
jQuery('input[name="post_format"]').on('change', function(){
$id = jQuery('input[name="post_format"]:checked').attr('id');
// video
if( $id == 'post-format-video'){
jQuery('.cs-element.cs-element-video-link.cs-field-text').show();
}else{
jQuery('.cs-element.cs-element-video-link.cs-field-text').hide();
}
// Link
if( $id == 'post-format-link'){
jQuery('.cs-element.cs-element-link').show();
jQuery('.cs-element.cs-element-text').show();
}else{
jQuery('.cs-element.cs-element-link').hide();
jQuery('.cs-element.cs-element-text').hide();
}
// Audio
if( $id == 'post-format-audio'){
jQuery('.cs-element.cs-element-audio-link').show();
}else{
jQuery('.cs-element.cs-element-audio-link').hide();
}
// Gallery
if( $id == 'post-format-gallery'){
jQuery('.cs-element.cs-element-gallery-image').show();
}else{
jQuery('.cs-element.cs-element-gallery-image').hide();
}
// standard & gallery & link & image & quote
if( $id == 'post-format-video' || $id == 'post-format-link' || $id == 'post-format-audio' || $id == 'post-format-gallery' ){
jQuery('#ration_post_format_metabox').show();
}else{
jQuery('#ration_post_format_metabox').hide();
}
});
});
</script>
<?php
endif;
}
add_action('admin_print_scripts', 'post_format_metabox_js', 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment