add_menu(array(
'id' => 'theme-settings',
'title' => apply_filters('cfct_admin_settings_menu', __('Theme Settings', 'carrington')),
'href' => admin_url('themes.php?page=carrington-settings'),
'parent' => 'appearance'
));
}
}
add_action('wp_before_admin_bar_render', 'cfct_admin_bar');
/**
* Deprecated in favor of WP Core Settings API
**/
function cfct_admin_request_handler() {
_deprecated_function(__FUNCTION__, '3.2');
}
/**
* Deprecated in favor of WP Core Settings API
**/
function cfct_update_settings() {
_deprecated_function(__FUNCTION__, '3.2');
}
/**
* Register Theme Settings screen options using WP Settings API
*/
function cfct_register_options() {
global $cfct_hidden_fields;
$yn_options = array(
'yes' => __('Yes', 'carrington'),
'no' => __('No', 'carrington')
);
$cfct_options = array(
'cfct' => array(
'label' => '',
//This is a callback, use cfct_options_blank to display nothing
'description' => 'cfct_options_blank',
'fields' => array(
'about' => array(
'type' => 'textarea',
'label' => __('About text (shown in sidebar)', 'carrington'),
'cols' => 60,
'rows' => 5,
'name' => 'about_text',
),
'copyright' => array(
'type' => 'text',
'label' => __('Copyright / legal footer text', 'carrington'),
'name' => 'copyright',
'help' => '
'.__('(add %Y to output the current year)', 'carrington').'',
'class' => 'cfct-text-long',
),
'login' => array(
'type' => 'radio',
'label' => __('Show log in/out links in footer', 'carrington'),
'name' => 'login_link_enabled',
'options' => $yn_options,
),
'credit' => array(
'type' => 'radio',
'label' => __('Give credit in footer', 'carrington'),
'name' => 'credit',
'options' => $yn_options,
),
/**
'radio' => array(
'type' => 'radio',
'label' => __('Radio Buttons', 'carrington'),
'name' => 'radio_test',
'options' => array(
'value_one' => 'Radio Bar',
'value_two' => 'Radio Bar 2',
),
),
'checkbox' => array(
'type' => 'checkbox',
'label' => __('Checkboxes', 'carrington'),
'name' => 'checkbox_test',
'options' => array(
'value_one' => 'Check Bar',
'value_two' => 'Check Bar 2',
),
),
*/
),
),
);
$cfct_options = apply_filters('cfct_options', $cfct_options);
foreach ($cfct_options as $section_name => $section) {
if (empty($section['description'])) {
$section['description'] = 'cfct_options_blank';
}
add_settings_section($section_name, $section['label'], $section['description'], 'cfct');
foreach ($section['fields'] as $key => $option) {
// Prefix the option name
$option['name'] = cfct_option_name($option['name']);
// Support for serialized options
// First we want to match on the name of the option. (everything up to the first []). Only matchs on alpha-numeric, dashes and underscores
if (preg_match('/^([a-zA-Z0-9-_]+)\[[a-zA-Z0-9-_]+\]/', $option['name'], $basename_match)) {
$basename = $basename_match[1];
register_setting('cfct', $basename, 'cfct_sanitize_options');
$serialize_option = cfct_get_option($basename);
// match on any subsequent [] with at least one character to determine the value of the option. Only matchs on alpha-numeric, dashes and underscores.
if(preg_match_all('/\[([a-zA-Z0-9-_]+)\]/', $option['name'], $key_matches)) {
$value = $serialize_option;
foreach ($key_matches[1] as $key_match) {
if (is_array($value) && array_key_exists($key_match, $value)) {
$value = $value[$key_match];
}
}
$option['value'] = $value;
}
}
else {
register_setting('cfct', $option['name'], 'cfct_sanitize_options');
$option['value'] = cfct_get_option($option['name']);
}
$option['label_for'] = $section_name.'_'.$key;
if ($option['type'] != 'hidden') {
add_settings_field($key, $option['label'], 'cfct_options_input', 'cfct', $section_name, $option);
}
else {
$cfct_hidden_fields[] = $option;
}
}
}
}
add_action('admin_init', 'cfct_register_options', 10);
/**
* Display hidden fields registered in `cfct_register_options()`. WP Forces padding when using `do_settings_sections`, so it cannot be truly hidden using that method.
*/
function cfct_hidden_fields() {
global $cfct_hidden_fields;
if (is_array($cfct_hidden_fields)) {
foreach ($cfct_hidden_fields as $field_options) {
echo cfct_options_input($field_options);
}
}
}
add_action('cfct_settings_form', 'cfct_hidden_fields', 10);
/**
* Empty callback, callback required by WP core function add_settings_section
*/
function cfct_options_blank() {
}
/**
* Prints an input field based on arguments passed.
* @param array $args Array of arguments used to generate the markup.
* 'type' => Type of input
* 'value' => Value of input
* 'name' => Name of input sent in post
* 'label_for' => ID attached to the input. Also used when generating the label in `add_settings_field`
* 'class' => CSS classes for the input
* 'cols' => Textarea specific
* 'rows' => Textarea specific
* 'options' => Radio button, Checkbox, Select specific. Used to define options
* 'help' => Help markup for the option.
* @return void
*/
function cfct_options_input($args) {
$type = $args['type'];
$value = $args['value'];
$name = $args['name'];
$id = empty($args['label_for']) ? $args['name'] : $args['label_for'];
$class = empty($args['class']) ? '' : ' class="'.esc_attr($args['class']).'"';
$html = '';
switch ($type) {
case 'text':
$html .= '';
break;
case 'password':
$html .= '';
break;
case 'textarea':
empty($args['cols']) ? $cols = 60 : $cols = (int) $args['cols'];
empty($args['rows']) ? $rows = 5 : $rows = (int) $args['rows'];
$html .= '';
break;
case 'select':
$html .= '';
break;
case 'radio':
$options = $args['options'];
if (is_array($options)) {
$html .= '
'.sprintf(__('Header Image — Upload Images', 'carrington-core'), $upload_url).'