public static function init() { self::$sections = kcSettings::get_data('settings', 'menu_item'); kcSettings::add_page('nav-menus.php'); add_filter('wp_edit_nav_menu_walker', array(__CLASS__, '_walker')); add_action('wp_update_nav_menu_item', array(__CLASS__, '_save'), 10, 3); }
public static function init() { self::$sections = kcSettings::get_data('settings', 'menu_nav'); kcSettings::add_page('nav-menus.php'); add_action('admin_footer', array(__CLASS__, 'meta_box_print'), 0); add_action('wp_update_nav_menu', array(__CLASS__, '_save'), 10, 2); }
function create_menu() { extract($this->group, EXTR_OVERWRITE); $this->page = add_submenu_page($menu_location, $page_title, $menu_title, 'manage_options', "kc-settings-{$prefix}", array($this, 'settings_page')); $this->url = menu_page_url("kc-settings-{$prefix}", false); kcSettings::add_page($this->page); add_action("load-{$this->page}", array($this, 'load_actions'), 99); if ($display == 'metabox') { require_once dirname(__FILE__) . '/plugin-metabox.php'; $this->metabox = new kcSettings_plugin_metabox($this); } }
public static function init() { self::$settings = kcSettings::get_data('settings', 'term'); kcSettings::add_page('edit-tags.php'); foreach (array_keys(self::$settings) as $tax) { add_action("{$tax}_add_form_fields", array(__CLASS__, '_fields'), 20, 1); add_action("{$tax}_edit_form_fields", array(__CLASS__, '_fields'), 20, 2); } add_action('edit_term', array(__CLASS__, '_save'), 10, 3); add_action('create_term', array(__CLASS__, '_save'), 10, 3); add_action('delete_term', array(__CLASS__, '_delete'), 10, 3); }
public static function init() { self::$settings = kcSettings::get_data('settings', 'user'); kcSettings::add_page('profile.php'); kcSettings::add_page('user-edit.php'); # Display additional fields in user profile page add_action('show_user_profile', array(__CLASS__, '_fields')); add_action('edit_user_profile', array(__CLASS__, '_fields')); # Save the additional data add_action('personal_options_update', array(__CLASS__, '_save')); add_action('edit_user_profile_update', array(__CLASS__, '_save')); }
public static function _create($post_type, $post) { if (empty(self::$settings[$post_type])) { return; } $sections = self::_bootstrap_sections(self::$settings[$post_type], $post); if (empty($sections)) { return; } kcSettings::add_page('post.php'); kcSettings::add_page('post-new.php'); foreach ($sections as $section_index => $section) { add_meta_box("kc-metabox-{$post_type}-{$section['id']}", $section['title'], array(__CLASS__, '_fill'), $post_type, $section['metabox']['context'], $section['metabox']['priority'], $section); } }
public static function init() { if (class_exists('kcSettings')) { $settings = kcSettings::get_data('settings', 'theme'); } else { $settings = apply_filters('kc_theme_settings', array()); } if (empty($settings)) { return false; } self::$settings = $settings; # Add menu under Appearance add_action('admin_menu', array(__CLASS__, 'create_menu')); add_action('customize_register', array(__CLASS__, 'register')); }
/** * Field: media */ function _kc_field_media($args) { $args['field']['multiple'] = (bool) $args['field']['multiple']; kcSettings::add_media_field($args['id'], $args['field']); if (!is_array($args['db_value'])) { $args['db_value'] = array($args['db_value']); } foreach ($args['db_value'] as $idx => $attachment_id) { if (empty($attachment_id)) { unset($args['db_value'][$idx]); continue; } $attachment = get_post($attachment_id); if (empty($attachment) || !is_object($attachment)) { unset($args['db_value'][$idx]); } } $wrap_class = 'kc-media-selector'; $list_class = 'kc-media-list attachments'; if (empty($args['db_value'])) { $list_class .= ' hidden'; $args['db_value'][] = ''; // Needed to print out the item template. } if ($args['field']['multiple']) { $args['name'] .= '[]'; $list_class .= ' multiple'; } else { $wrap_class .= ' single-file'; } $list_attr = ' id="' . esc_attr($args['id']) . '"'; $list_attr .= ' class="' . esc_attr($list_class) . '"'; $list_attr .= ' data-size="' . esc_attr($args['field']['preview_size']) . '"'; $list_attr .= ' data-animate="' . esc_attr($args['field']['animate']) . '"'; $did_once = false; ob_start(); ?> <div class="<?php echo esc_attr($wrap_class); ?> "> <ul<?php echo $list_attr; ?> > <?php foreach ($args['db_value'] as $attachment_id) { $item_class = 'attachment'; $thumb_style = ''; if (!empty($attachment_id)) { $image = wp_get_attachment_image($attachment_id, $args['field']['preview_size'], true); $title = get_the_title($attachment_id); $mime_type = substr(get_post_mime_type($attachment_id), 0, strpos($attachment->post_mime_type, '/')); $item_class .= sprintf(' type-%s', $mime_type); if ('image' === $mime_type && $args['field']['preview_size'] !== 'thumbnail' && ($image_src = wp_get_attachment_image_src($attachment_id, $args['field']['preview_size'], false))) { $thumb_style = ' style="width:' . $image_src[1] . 'px;height:' . $image_src[2] . 'px"'; } } else { if ($did_once) { // Skip, we already printed the template. continue; } $image = '<img />'; $title = ''; } $did_once = true; ?> <li class="<?php echo esc_attr($item_class); ?> "> <div class="attachment-preview"<?php echo $thumb_style; ?> > <div class="thumbnail"<?php echo $thumb_style; ?> > <div class="centered"> <?php echo $image; ?> </div> <div class="filename"> <div><?php echo esc_html($title); ?> </div> </div> </div> <a title="<?php esc_attr_e('Deselect'); ?> " href="#" class="check"><div class="media-modal-icon"></div></a> </div> <input type="hidden" name="<?php echo esc_attr($args['name']); ?> " value="<?php echo esc_attr($attachment_id); ?> " /> </li> <?php } ?> </ul> <p><a href="#" class="button-primary kc-media-select" data-fieldid="<?php echo esc_attr($args['id']); ?> "><?php echo esc_html($args['field']['select_button']); ?> </a></p> </div> <?php $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Get default value * * @param string $type Options type, required * @param string $prefix Options prefix, required * @param string $section Section id, optional * @param string $field Field id, optional * * @return bool|array|string * * @since 2.5 */ function kc_get_default($type, $prefix, $section = '', $field = '') { $defaults = kcSettings::get_data('defaults', $type, $prefix); if (!$defaults || func_num_args() < 3) { return $defaults; } $keys = func_get_args(); unset($keys[0]); unset($keys[1]); return kc_array_multi_get_value($defaults, $keys); }
public static function load() { self::$data['options'] = self::_options(); $temp = get_transient('kcsb'); if ($temp) { self::$item_to_edit = $temp; delete_transient('kcsb'); } require_once dirname(__FILE__) . '/builder-table.php'; $table = new kcSettings_builder_table(array('plural' => 'kcsb-table', 'kcsb' => array('settings' => self::$data['kcsb']['settings'], 'options' => self::$data['options']))); self::$table = $table; $action = $table->current_action(); if (!$action || !in_array($action, array('delete', 'edit', 'purge', 'empty', 'clone', 'activate', 'deactivate', 'export'))) { return; } $update = false; # Singular if (isset($_REQUEST['id']) && in_array($_REQUEST['id'], self::$data['kcsb']['settings'][$_REQUEST['id']])) { check_admin_referer("__kcsb__{$_REQUEST['id']}"); $items = array($_REQUEST['id']); } elseif (isset($_REQUEST['ids']) && is_array($_REQUEST['ids']) && !empty($_REQUEST['ids'])) { check_admin_referer('bulk-kcsb-table'); $items = $_REQUEST['ids']; } $single = count($items) < 2 ? true : false; switch ($action) { case 'activate': foreach ($items as $item) { self::$data['kcsb']['settings'][$item]['status'] = '1'; } $update = true; self::$update_message = $single ? __('Setting succesfully activated.', 'kc-settings') : __('Settings succesfully activated.', 'kc-settings'); break; case 'deactivate': foreach ($items as $item) { self::$data['kcsb']['settings'][$item]['status'] = '0'; } $update = true; self::$update_message = $single ? __('Setting succesfully deactivated.', 'kc-settings') : __('Settings succesfully deactivated.', 'kc-settings'); break; case 'delete': foreach ($items as $item) { unset(self::$data['kcsb']['settings'][$item]); } $update = true; self::$update_message = $single ? __('Setting succesfully deleted.', 'kc-settings') : __('Settings succesfully deleted.', 'kc-settings'); break; case 'empty': $result = 0; foreach ($items as $item) { if (self::$data['kcsb']['settings'][$item]['type'] === 'plugin' && delete_option(self::$data['kcsb']['settings'][$item]['prefix'] . '_settings')) { $result++; } } if ($result) { $message = $result === 1 ? __('Setting values succesfully removed from database.', 'kc-settings') : __('Settings values succesfully removed from database.', 'kc-settings'); kcSettings::add_notice('updated', "<strong>{$message}</strong>"); } break; case 'clone': if (isset($_REQUEST['new']) && !empty($_REQUEST['new'])) { $new_id = sanitize_html_class($_REQUEST['new']); if ($new_id && !isset(self::$data['kcsb']['settings'][$new_id])) { $new = self::$data['kcsb']['settings'][$_REQUEST['id']]; $new['id'] = $new_id; self::$data['kcsb']['settings'][$new_id] = $new; $update = true; self::$update_message = __('Setting succesfully cloned.', 'kc-settings'); } } break; case 'edit': self::$item_to_edit = wp_parse_args(self::$data['kcsb']['settings'][$_REQUEST['id']], self::$data['defaults']); break; case 'export': if (isset($_REQUEST['type']) && isset(self::$data['kcsb']['items'][$_REQUEST['type']][$_REQUEST['id']])) { self::$item_to_export = self::_exporter($_REQUEST['type'], self::$data['kcsb']['items'][$_REQUEST['type']][$_REQUEST['id']]); } break; } if ($update) { update_option('kcsb', self::$data['kcsb']['settings']); } }