Guest User

Rule for selected posts within a custom post type

a guest
Jul 15th, 2014
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if ( is_admin() ) {
  2.     function my_admin_footer() {
  3. ?>
  4. <script type="text/javascript">
  5. (function($) {
  6.     // hide "Mygroup" fieldgroup on custom post type aaaa or bbbb posts if not xxxx or yyyy in slug
  7.     var post_type_arr = [ 'aaaa', 'bbbb' ]; // custom post types where "Mygroup" fieldgroup is shown
  8.     var post_name_search_arr = [ 'xxxx', 'yyyy' ];  // look for these parts within post_name
  9.     var acf_fieldgroup_id_arr = [ 'acf-mygroup', 'acf-mygroup-2' ]; // "Mygroup" + translation
  10.     $.each( post_type_arr, function( idx, post_type ) {
  11.         if ( $( 'body' ).hasClass( 'post-type-' + post_type ) ) {
  12.             var found = false;
  13.             var sel = 'span#editable-post-name-full';
  14.             if ( $( sel ).length > 0 ) {
  15.                 var post_name = $( sel ).text();
  16.                 if ( post_name ) {
  17.                     $.each( post_name_search_arr, function( idx, search ) {
  18.                         if ( post_name.indexOf( search ) != -1 ) {
  19.                             found = true;
  20.                         }
  21.                     });
  22.                 }
  23.             }
  24.             if ( !found ) {
  25.                 $.each( acf_fieldgroup_id_arr, function( idx, fieldgroup_id ) {
  26.                     // hide fieldgroup
  27.                     $( 'div#' + fieldgroup_id ).addClass( 'acf-hidden' );
  28.                     // hide postbox-toggle
  29.                     $( 'label.acf-postbox-toggle[for="' + fieldgroup_id + '-hide"]' ).addClass( 'acf-hidden' );
  30.                 });
  31.             }
  32.         }
  33.     });
  34. })(jQuery);
  35. </script>
  36. <?php
  37.     }
  38.     add_action('admin_footer', 'my_admin_footer');
  39. }
RAW Paste Data