Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( is_admin() ) {
- function my_admin_footer() {
- ?>
- <script type="text/javascript">
- (function($) {
- // hide "Mygroup" fieldgroup on custom post type aaaa or bbbb posts if not xxxx or yyyy in slug
- var post_type_arr = [ 'aaaa', 'bbbb' ]; // custom post types where "Mygroup" fieldgroup is shown
- var post_name_search_arr = [ 'xxxx', 'yyyy' ]; // look for these parts within post_name
- var acf_fieldgroup_id_arr = [ 'acf-mygroup', 'acf-mygroup-2' ]; // "Mygroup" + translation
- $.each( post_type_arr, function( idx, post_type ) {
- if ( $( 'body' ).hasClass( 'post-type-' + post_type ) ) {
- var found = false;
- var sel = 'span#editable-post-name-full';
- if ( $( sel ).length > 0 ) {
- var post_name = $( sel ).text();
- if ( post_name ) {
- $.each( post_name_search_arr, function( idx, search ) {
- if ( post_name.indexOf( search ) != -1 ) {
- found = true;
- }
- });
- }
- }
- if ( !found ) {
- $.each( acf_fieldgroup_id_arr, function( idx, fieldgroup_id ) {
- // hide fieldgroup
- $( 'div#' + fieldgroup_id ).addClass( 'acf-hidden' );
- // hide postbox-toggle
- $( 'label.acf-postbox-toggle[for="' + fieldgroup_id + '-hide"]' ).addClass( 'acf-hidden' );
- });
- }
- }
- });
- })(jQuery);
- </script>
- <?php
- }
- add_action('admin_footer', 'my_admin_footer');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement