Viewing 2 reply threads
  • Author
    Posts
    • #5360
      jcrist
      Member

      Hi Steve,

      Maybe I’m missing it somewhere but how do I add and process custom data in the comment block (in a settings field if that makes a difference)? I thought it would be the filter ‘piklist_part_data_parameter’ but when I print_r, I don’t see my custom comment. Example:

      <?php
      /*
      Title: Staff
      Order: 10
      Tab: Organization
      Setting: site_functionality
      Flow: Functionality Workflow
      Site Type: attorney
      */
      ?>

      Thanks!

    • #5369
      jcrist
      Member

      I should have given more background…What I’d like to do is conditionally show meta-boxes based on the Site Type which the user selects on tab 1. I found this this thread which pointed me in the right direction.

      Here’s what I’m trying:

      add_filter('piklist_part_data_parameter', 'site_type_filter', 10, 2);
      function site_type_filter($value, $parameter) {
      if($parameter == 'site_type') {
          $value = piklist::explode(',', $value, 'strtolower');
          $value = array_filter($value);
          $value = empty($value) ? null : $value;
        }
      return $value;
      }

      Then I’m printing out the part array:

      add_filter('piklist_part_process-settings', 'show_part_array', 20, 2);
      function show_part_array( $part ) {
        print_r($part);
        return $part;
      }

      But ‘site_type’ is not in the array. Looks like I don’t know how to properly use this filter, could you post a code sample?

      Also, once I this this working, I would use the ‘piklist_part_process’ filter to unset the part if it shouldn’t be shown?

    • #8335
      cdcorey
      Member

      For anyone else who comes across this on Google, it’s actually very simple to do:

      add_filter('piklist_part_data', function ($data, $folder) {
      	$data['foo'] = 'Foo';
      	return $data;
      }, 10, 2);

      In this example, ‘Foo’ is the text you’ll include in comment blocks, like so:

      /*
      Foo: Bar
      */

      While ‘foo’ will be the key in the part’s data array:

      add_filter('piklist_part_process', function ($part, $folder) {
      	if ($part['data']['foo'] == 'Bar') {
      		// Do something...
      	}
      }, 10, 2);
Viewing 2 reply threads
  • You must be logged in to reply to this topic.