Viewing 5 reply threads
  • Author
    Posts
    • #3669
      mcmaster
      Participant

      I have a “section_name” field that I want to show only for top-level pages. Was first looking at using a template but then I saw the tutorial https://piklist.com/user-guide/tutorials/hide-meta-boxes-page-template/ and modified it for my use. I’m sharing the code in case someone else might find it handy. Suggestions for improvement are also welcome. 🙂

      https://gist.github.com/mcdonna/7324cba06b375ef35b5b

    • #3670
      mcmaster
      Participant

      Heads up … I’m using the Beta version of Piklist. In the current Piklist 0.9.4.24 release, the piklist_get_file_data filter passes only one parameter, the $data array. This leads to an error message for the missing $type parameter.

      In the Beta version, the $type parameter is there.

      Donna

    • #5419
      abmcr
      Participant

      In the last 0.9.9.6 the
      piklist_get_file_data filter don’t exist?
      I have try to use the code

      add_filter('piklist_get_file_data', 'my_custom_comment_block', 10, 2);
      function my_custom_comment_block($data, $type)
      {
           // If not a Meta-box section than bail
        if($type != 'meta-boxes')
        {
          return $data;
        }
       
        // Allow Piklist to read our custom comment block attribute: "Hide for Template", and set it to hide_for_template
        $data['hide_for_template'] = 'Hide for Template';
      
        return $data;
      }
      
      add_filter('piklist_add_part', 'my_hide_for_template', 10, 2);
      function my_hide_for_template($data, $type)
      {
        global $post;
       
        // If not a meta box than bail
        if($type != 'meta-boxes')
        {
          return $data;
        }
       
        // Check if any page template is set in the comment block
        if (!empty($data['hide_for_template'])) 
        {
          // Get the active page template
          $active_template = pathinfo(get_page_template_slug($post->ID), PATHINFO_FILENAME);
          //valuta se pagina è front page
      
           if($post->ID !== get_option( 'show_on_front' ) ){
       
              // Change meta-box access to user role: no-role
              $data['role'] = 'no-role'; 
            
          }
        }
        return $data;
      }

      And it not work; i have serached the filter and i have not found it

    • #5420
      mcmaster
      Participant

      The beta I was using back then was 0.9.5.x, so it could have changed. The Gist URL has changed, BTW, it is now https://gist.github.com/donnamcmaster/7324cba06b375ef35b5b.

    • #5421
      abmcr
      Participant

      Yes: i confirm
      In the new 0.9.9.6 the code you post and my also are not working
      The filter don’t exist

    • #5423
      mcmaster
      Participant

      Yes, it’s clear that tutorial at https://piklist.com/user-guide/tutorials/hide-meta-boxes-page-template/ needs updating. Neither piklist_get_file_data nor piklist_add_part filters are executed in 0.9.9.x.

      I think they may be replaced with piklist_part_data along with some of the variants in Piklist::process_parts, and also piklist_part_data_parameter? (See file plugins/piklist/includes/class-piklist.php.)

      No time to test right now, but let us know if you find the magic formula. 😉

      Cheers,
      Donna

Viewing 5 reply threads
  • You must be logged in to reply to this topic.