Here is the solution, for anyone using their own custom table of data and using that data to determine what fields should be displayed.
Add the following to your field definition. Does not matter if it is a group field or single.
'show_on_cb' => 'YourPrefix_set_field_data_attr',
then customized the call back to your particular conditions:
function YourPrefix_set_field_data_attr($field)
{
$Fieldid = $field->args( 'id' );
$CMB2Fieldname = $field->args( '_name' );
$Prefix = 'YourPrefix';
if($Prefix == $Fieldid) // Whole table Id, skip it
return 1;
$SearchPrefix = 'YourPrefix' . '_';
$pieces = explode($SearchPrefix, $Fieldid);
$pieces = explode('_', $pieces[1]);
$RowId = $pieces[0];
$CMB2Leader = $SearchPrefix . $RowId . '_';
$pieces = explode($CMB2Leader, $Fieldid);
$StandardFieldName = $pieces[1]; // This should match the fields table name
// These are my conditions, use your own conditions.
$current_user = wp_get_current_user();
$DatabaseData = FindListing($current_user->user_email);
if($DatabaseData[$RowId]['SubscriptionName'] == "YOUR DATABASE KEY")
{
// Get the input fields
$input_fields = GetTemplateFields(1); // Table of fields
for($i=0; $i<sizeof($input_fields); $i++)
{
$Field = $input_fields[$i]; // CMB2 Field Name without prefix
$FieldId = $Field['id'];
$bDisplayText = $Field['textdisplay'];
if($FieldId == $StandardFieldName && $bDisplayText == 0)
{
unset($DatabaseData);
return 0; // Turn off the field
}
}
}
unset($DatabaseData);
return 1; // Display the field
}
<code></code>
-
This reply was modified 5 years, 9 months ago by
dkurth.
-
This reply was modified 5 years, 9 months ago by
dkurth.
-
This reply was modified 5 years, 9 months ago by
dkurth.