コード例 #1
0
ファイル: api-helpers.php プロジェクト: sdh100shaun/pantheon
function acf_decode_choices($string = '')
{
    // validate
    if (is_numeric($string)) {
        // force array on single numeric values
        return array($string);
    } elseif (!is_string($string)) {
        // bail early if not a a string
        return $string;
    }
    // vars
    $array = array();
    // explode
    $lines = explode("\n", $string);
    // key => value
    foreach ($lines as $line) {
        // vars
        $k = trim($line);
        $v = trim($line);
        // look for ' : '
        if (acf_str_exists(' : ', $line)) {
            $line = explode(' : ', $line);
            $k = trim($line[0]);
            $v = trim($line[1]);
        }
        // append
        $array[$k] = $v;
    }
    // return
    return $array;
}
コード例 #2
0
 function update_value($value, $post_id, $field)
 {
     // no formatting needed for empty value
     if (empty($value)) {
         return $value;
     }
     // remove ','
     if (acf_str_exists(',', $value)) {
         $value = str_replace(',', '', $value);
     }
     // return
     return $value;
 }
コード例 #3
0
function acf_decode_choices($string = '')
{
    // bail early if already array
    if (is_array($string)) {
        return $string;
    }
    // vars
    $array = array();
    // bail ealry if not string
    if (!is_string($string)) {
        return $array;
    }
    // explode choices from each line
    if (!empty($string)) {
        // stripslashes ("")
        $string = stripslashes_deep($string);
        // explode
        $temp = explode("\n", $string);
        // key => value
        foreach ($temp as $v) {
            if (acf_str_exists(' : ', $v)) {
                $v = explode(' : ', $v);
                $array[trim($v[0])] = trim($v[1]);
            } else {
                $array[trim($v)] = trim($v);
            }
        }
    }
    // return
    return $array;
}
コード例 #4
0
ファイル: api-helpers.php プロジェクト: Garth619/Femi9
function acf_decode_choices($string = '', $array_keys = false)
{
    // bail early if already array
    if (is_array($string)) {
        return $string;
        // allow numeric values (same as string)
    } elseif (is_numeric($string)) {
        // do nothing
        // bail early if not a string
    } elseif (!is_string($string)) {
        return array();
        // bail early if is empty string
    } elseif ($string === '') {
        return array();
    }
    // vars
    $array = array();
    // explode
    $lines = explode("\n", $string);
    // key => value
    foreach ($lines as $line) {
        // vars
        $k = trim($line);
        $v = trim($line);
        // look for ' : '
        if (acf_str_exists(' : ', $line)) {
            $line = explode(' : ', $line);
            $k = trim($line[0]);
            $v = trim($line[1]);
        }
        // append
        $array[$k] = $v;
    }
    // return only array keys? (good for checkbox default_value)
    if ($array_keys) {
        return array_keys($array);
    }
    // return
    return $array;
}
コード例 #5
0
ファイル: api-helpers.php プロジェクト: eea76/hammer
function acf_decode_choices($string = '')
{
    // bail early if nota a string
    if (!is_string($string)) {
        return $string;
    }
    // vars
    $array = array();
    // explode choices from each line
    //if( !empty($string) ) {
    // stripslashes ("")
    //$string = stripslashes_deep($string);
    // explode
    $lines = explode("\n", $string);
    // key => value
    foreach ($lines as $line) {
        // vars
        $k = trim($line);
        $v = trim($line);
        // look for ' : '
        if (acf_str_exists(' : ', $line)) {
            $line = explode(' : ', $line);
            $k = trim($line[0]);
            $v = trim($line[1]);
        }
        // append
        $array[$k] = $v;
    }
    //}
    // bail early if no choices
    if (empty($array)) {
        return '';
    }
    // return
    return $array;
}