/** * Verifies the settings associated with a given Doc * * @since 1.2 * @param array $settings Settings passed from the Edit form * @param int $doc_id The numeric ID of the doc * @param int $user_id The id of the user * @return array $is_allowed Keyed by settings names, with boolean values */ function bp_docs_verify_settings($settings, $doc_id, $user_id = 0) { $verified_settings = array(); foreach ($settings as $setting_name => $setting_value) { $allowed_values = bp_docs_get_access_options($setting_name, $doc_id); $verified_settings[$setting_name] = array('original_value' => $setting_value, 'verified_value' => '', 'setting_default' => ''); // Loop through to collect whitelisted values as well as the // default setting, which will be used if the user-provided // value doesn't match the whitelist foreach ($allowed_values as $allowed_value) { if (empty($verified_settings[$setting_name]['verified_value']) && $setting_value == $allowed_value['name']) { $verified_settings[$setting_name]['verified_value'] = $setting_value; } if (empty($verified_settings[$setting_name]['setting_default']) && 1 == $allowed_value['default']) { $verified_settings[$setting_name]['setting_default'] = 1; } } // If no whitelisted value has been found, attempt to fall // back on a default value for that option if (empty($verified_settings[$setting_name])) { $verified_settings[$setting_name]['verified_value'] = $verified_settings[$setting_name]['setting_default']; } } return $verified_settings; }
function bp_docs_access_options_helper($settings_field, $doc_id = 0, $group_id = 0) { if ($group_id) { $settings_type = 'raw'; } else { $settings_type = 'default'; } $doc_settings = bp_docs_get_doc_settings($doc_id, $settings_type); // If this is a failed form submission, check the submitted values first if (!empty(buddypress()->bp_docs->submitted_data->settings->{$settings_field['name']})) { $setting = buddypress()->bp_docs->submitted_data->settings->{$settings_field['name']}; } else { $setting = isset($doc_settings[$settings_field['name']]) ? $doc_settings[$settings_field['name']] : ''; } ?> <tr class="bp-docs-access-row bp-docs-access-row-<?php echo esc_attr($settings_field['name']); ?> "> <td class="desc-column"> <label for="settings-<?php echo esc_attr($settings_field['name']); ?> "><?php echo esc_html($settings_field['label']); ?> </label> </td> <td class="content-column"> <select name="settings[<?php echo esc_attr($settings_field['name']); ?> ]" id="settings-<?php echo esc_attr($settings_field['name']); ?> "> <?php $access_options = bp_docs_get_access_options($settings_field['name'], $doc_id, $group_id); ?> <?php foreach ($access_options as $key => $option) { ?> <?php $selected = selected($setting, $option['name'], false); if (empty($setting) && !empty($option['default'])) { $selected = selected(1, 1, false); } ?> <option value="<?php echo esc_attr($option['name']); ?> " <?php echo $selected; ?> ><?php echo esc_attr($option['label']); ?> </option> <?php } ?> </select> </td> </tr> <?php }
function bp_docs_access_options_helper($settings_field, $doc_id = 0, $group_id = 0) { $doc_settings = get_post_meta($doc_id, 'bp_docs_settings', true); $setting = isset($doc_settings[$settings_field['name']]) ? $doc_settings[$settings_field['name']] : ''; ?> <tr class="bp-docs-access-row bp-docs-access-row-<?php echo esc_attr($settings_field['name']); ?> "> <td class="desc-column"> <label for="settings[<?php echo esc_attr($settings_field['name']); ?> ]"><?php echo esc_html($settings_field['label']); ?> </label> </td> <td class="content-column"> <select name="settings[<?php echo esc_attr($settings_field['name']); ?> ]"> <?php $access_options = bp_docs_get_access_options($settings_field['name'], $doc_id, $group_id); ?> <?php foreach ($access_options as $key => $option) { ?> <?php $selected = selected($setting, $option['name'], false); if (empty($setting) && !empty($option['default'])) { $selected = selected(1, 1, false); } ?> <option value="<?php echo esc_attr($option['name']); ?> " <?php echo $selected; ?> ><?php echo esc_attr($option['label']); ?> </option> <?php } ?> </select> </td> </tr> <?php }