示例#1
0
/**
 * Get the value of a settings field
 *
 * @since 0.4
 * @param string $option option field name
 * @return mixed
 */
function cpm_get_option($option)
{
    $fields = CPM_Admin::get_settings_fields();
    $prepared_fields = array();
    //prepare the array with the field as key
    //and set the section name on each field
    foreach ($fields as $section => $field) {
        foreach ($field as $fld) {
            $prepared_fields[$fld['name']] = $fld;
            $prepared_fields[$fld['name']]['section'] = $section;
        }
    }
    // bail if option not found
    if (!isset($prepared_fields[$option])) {
        return;
    }
    //get the value of the section where the option exists
    $opt = get_option($prepared_fields[$option]['section']);
    $opt = is_array($opt) ? $opt : array();
    //return the value if found, otherwise default
    if (array_key_exists($option, $opt)) {
        return $opt[$option];
    } else {
        $val = isset($prepared_fields[$option]['default']) ? $prepared_fields[$option]['default'] : '';
        return $val;
    }
}
示例#2
0
 function page_settings($settings_fields)
 {
     $pages_array = CPM_Admin::get_post_type('page');
     $settings_fields['cpm_page'] = array(array('name' => 'project', 'label' => __('Project', 'cpmf'), 'type' => 'select', 'options' => $pages_array), array('name' => 'my_task', 'label' => __('My Task', 'cpmf'), 'type' => 'select', 'options' => $pages_array), array('name' => 'calendar', 'label' => __('Calendar', 'cpmf'), 'type' => 'select', 'options' => $pages_array));
     return $settings_fields;
 }