コード例 #1
0
ファイル: plugin.php プロジェクト: Omuze/barakat
 function validate($user_val)
 {
     $prefix = $this->group['prefix'];
     $options = $this->group['options'];
     # apply validation/sanitation filter(s) on the new values
     # prefix-based filter
     $user_val = apply_filters("kcv_settings_{$prefix}", $user_val);
     if (empty($user_val)) {
         return apply_filters('kc_psv', $user_val);
     }
     $nu_val = array();
     foreach ($user_val as $section_id => $section_value) {
         # section-based filter
         $nu_val[$section_id] = apply_filters("kcv_setting_{$prefix}_{$section_id}", $section_value);
         if (!isset($options[$section_id]['fields'])) {
             continue;
         }
         foreach ($nu_val[$section_id] as $field_id => $field_value) {
             $type = $options[$section_id]['fields'][$field_id]['type'];
             # default sanitation
             $field_value = _kc_sanitize_value($field_value, $type);
             # type-based filter
             $field_value = apply_filters("kcv_setting_{$prefix}_{$type}", $field_value);
             # field-based filter
             $field_value = apply_filters("kcv_setting_{$prefix}_{$section_id}_{$field_id}", $field_value);
             # insert the filtered value to our new array
             $nu_val[$section_id][$field_id] = $field_value;
         }
     }
     return apply_filters("kc_psv", $nu_val);
 }
コード例 #2
0
ファイル: helper.php プロジェクト: Omuze/barakat
/**
 * Update posts & terms metadata
 *
 * @param string $meta_type post|term|user The type of metadata, post, term or user
 * @param string $object_type_name The taxonomy or post type name
 * @param int $object_id The ID of the object (post/term) that we're gonna update
 * @param array $section The meta section array
 * @param array $field The meta field array
 */
function _kc_update_meta($meta_type = 'post', $object_type_name, $object_id, $section, $field)
{
    if (isset($_POST['action']) && $_POST['action'] == 'inline-save') {
        return;
    }
    # Set the meta key and get the value based on the $meta_type and screen
    switch ($meta_type) {
        case 'post':
            $meta_key = "_{$field['id']}";
            $action = 'editpost';
            break;
        case 'term':
            $meta_key = $field['id'];
            $action = 'editedtag';
            break;
        case 'user':
            $meta_key = $field['id'];
            $action = 'update';
            break;
    }
    # Current value
    $db_val = get_metadata($meta_type, $object_id, $meta_key, true);
    # Hold new value
    $nu_val = '';
    # Get the new meta value from user
    if (isset($_POST["kc-{$meta_type}meta"][$section['id']][$field['id']])) {
        $nu_val = $_POST["kc-{$meta_type}meta"][$section['id']][$field['id']];
        if ($meta_type == 'post' && $object_type_name == 'nav_menu_item' && isset($nu_val[$object_id])) {
            $nu_val = $nu_val[$object_id];
        }
    }
    # default sanitation
    $nu_val = _kc_sanitize_value($nu_val, $field['type']);
    $filter_prefix = "kcv_{$meta_type}meta";
    if ($meta_type != 'user' && $object_type_name != '') {
        $filter_prefix .= "_{$object_type_name}";
    }
    # apply validation/sanitation filters on the new values
    # 	0. Taxonomy / Post type
    $nu_val = apply_filters($filter_prefix, $nu_val, $section, $field);
    # 	1. Field type
    $nu_val = apply_filters("{$filter_prefix}_{$field['type']}", $nu_val, $section, $field);
    #		2. Section
    $nu_val = apply_filters("{$filter_prefix}_{$section['id']}", $nu_val, $section, $field);
    # 	3. Field
    $nu_val = apply_filters("{$filter_prefix}_{$section['id']}_{$field['id']}", $nu_val, $section, $field);
    if (!$nu_val) {
        delete_metadata($meta_type, $object_id, $meta_key);
    } else {
        update_metadata($meta_type, $object_id, $meta_key, $nu_val);
    }
}