public function admin_page() { $transient = get_transient('cs-framework-transient'); $has_nav = count($this->options) <= 1 ? ' cs-show-all' : ''; $section_id = !empty($transient['section_id']) ? $transient['section_id'] : $this->sections[0]['name']; $section_id = cs_get_var('cs-section', $section_id); echo '<div class="cs-framework cs-option-framework">'; echo '<form method="post" action="options.php" enctype="multipart/form-data" id="csframework_form">'; echo '<input type="hidden" class="cs-reset" name="cs_section_id" value="' . $section_id . '" />'; if ($this->settings['ajax_save'] !== true && !empty($transient['errors'])) { global $cs_errors; $cs_errors = $transient['errors']; if (!empty($cs_errors)) { foreach ($cs_errors as $error) { if (in_array($error['setting'], array('general', 'cs-errors'))) { echo '<div class="cs-settings-error ' . $error['type'] . '">'; echo '<p><strong>' . $error['message'] . '</strong></p>'; echo '</div>'; } } } } settings_fields($this->unique . '_group'); echo '<header class="cs-header">'; echo '<h1>' . $this->settings['framework_title'] . '</h1>'; echo '<fieldset>'; echo $this->settings['ajax_save'] ? '<span id="cs-save-ajax">' . __('Settings saved.', 'cs-framework') . '</span>' : ''; submit_button(__('Save', 'cs-framework'), 'primary cs-save', 'save', false, array('data-save' => __('Saving...', 'cs-framework'))); submit_button(__('Restore', 'cs-framework'), 'secondary cs-restore cs-reset-confirm', $this->unique . '[reset]', false); if ($this->settings['show_reset_all']) { submit_button(__('Reset All Options', 'cs-framework'), 'secondary cs-restore cs-warning-primary cs-reset-confirm', $this->unique . '[resetall]', false); } echo '</fieldset>'; echo empty($has_nav) ? '<a href="#" class="cs-expand-all"><i class="fa fa-eye-slash"></i> ' . __('show all options', 'cs-framework') . '</a>' : ''; echo '<div class="clear"></div>'; echo '</header>'; // end .cs-header echo '<div class="cs-body' . $has_nav . '">'; echo '<div class="cs-nav">'; echo '<ul>'; foreach ($this->options as $key => $tab) { if (isset($tab['sections'])) { $tab_active = cs_array_search($tab['sections'], 'name', $section_id); $active_style = !empty($tab_active) ? ' style="display: block;"' : ''; $active_list = !empty($tab_active) ? ' cs-tab-active' : ''; $tab_icon = !empty($tab['icon']) ? '<i class="cs-icon ' . $tab['icon'] . '"></i>' : ''; echo '<li class="cs-sub' . $active_list . '">'; echo '<a href="#" class="cs-arrow">' . $tab_icon . $tab['title'] . '</a>'; echo '<ul' . $active_style . '>'; foreach ($tab['sections'] as $tab_section) { $active_tab = $section_id == $tab_section['name'] ? ' class="cs-section-active"' : ''; $icon = !empty($tab_section['icon']) ? '<i class="cs-icon ' . $tab_section['icon'] . '"></i>' : ''; echo '<li><a href="#"' . $active_tab . ' data-section="' . $tab_section['name'] . '">' . $icon . $tab_section['title'] . '</a></li>'; } echo '</ul>'; echo '</li>'; } else { $icon = !empty($tab['icon']) ? '<i class="cs-icon ' . $tab['icon'] . '"></i>' : ''; if (isset($tab['fields'])) { $active_list = $section_id == $tab['name'] ? ' class="cs-section-active"' : ''; echo '<li><a href="#"' . $active_list . ' data-section="' . $tab['name'] . '">' . $icon . $tab['title'] . '</a></li>'; } else { echo '<li><div class="cs-seperator">' . $icon . $tab['title'] . '</div></li>'; } } } echo '</ul>'; echo '</div>'; // end .cs-nav echo '<div class="cs-content">'; echo '<div class="cs-sections">'; foreach ($this->sections as $section) { if (isset($section['fields'])) { $active_content = $section_id == $section['name'] ? ' style="display: block;"' : ''; echo '<div id="cs-tab-' . $section['name'] . '" class="cs-section"' . $active_content . '>'; echo isset($section['title']) && empty($has_nav) ? '<div class="cs-section-title"><h3>' . $section['title'] . '</h3></div>' : ''; $this->do_settings_sections($section['name'] . '_section_group'); echo '</div>'; } } echo '</div>'; // end .cs-sections echo '<div class="clear"></div>'; echo '</div>'; // end .cs-content echo '<div class="cs-nav-background"></div>'; echo '</div>'; // end .cs-body echo '<footer class="cs-footer">'; echo '<div class="cs-block-left">Powered by Codestar Framework.</div>'; echo '<div class="cs-block-right">Version ' . CS_VERSION . '</div>'; echo '<div class="clear"></div>'; echo '</footer>'; // end .cs-footer echo '</form>'; // end form echo '<div class="clear"></div>'; echo '</div>'; // end .cs-framework }
public function save_post($post_id, $post) { if (wp_verify_nonce(cs_get_var('cs-framework-metabox-nonce'), 'cs-framework-metabox')) { $errors = array(); $post_type = cs_get_var('post_type'); foreach ($this->options as $request_value) { if (in_array($post_type, (array) $request_value['post_type'])) { $request_key = $request_value['id']; $request = cs_get_var($request_key, array()); // ignore _nonce if (isset($request['_nonce'])) { unset($request['_nonce']); } foreach ($request_value['sections'] as $key => $section) { if (isset($section['fields'])) { foreach ($section['fields'] as $field) { if (isset($field['type']) && isset($field['id'])) { $field_value = cs_get_vars($request_key, $field['id']); // sanitize options if (isset($field['sanitize']) && $field['sanitize'] !== false) { $sanitize_type = $field['sanitize']; } else { if (!isset($field['sanitize'])) { $sanitize_type = $field['type']; } } if (has_filter('cs_sanitize_' . $sanitize_type)) { $request[$field['id']] = apply_filters('cs_sanitize_' . $sanitize_type, $field_value, $field, $section['fields']); } // validate options if (isset($field['validate']) && has_filter('cs_validate_' . $field['validate'])) { $validate = apply_filters('cs_validate_' . $field['validate'], $field_value, $field, $section['fields']); if (!empty($validate)) { $meta_value = get_post_meta($post_id, $request_key, true); $errors[$field['id']] = array('code' => $field['id'], 'message' => $validate, 'type' => 'error'); $default_value = isset($field['default']) ? $field['default'] : ''; $request[$field['id']] = isset($meta_value[$field['id']]) ? $meta_value[$field['id']] : $default_value; } } } } } } $request = apply_filters('cs_save_post', $request, $request_key, $post); if (empty($request)) { delete_post_meta($post_id, $request_key); } else { if (get_post_meta($post_id, $request_key)) { update_post_meta($post_id, $request_key, $request); } else { add_post_meta($post_id, $request_key, $request); } } $transient['ids'][$request_key] = cs_get_vars('cs_section_id', $request_key); $transient['errors'] = $errors; } } set_transient('cs-metabox-transient', $transient, 10); } }
public function delete_taxonomy($term_id) { $taxonomy = cs_get_var('taxonomy'); if (!empty($taxonomy)) { foreach ($this->options as $request_value) { if ($taxonomy == $request_value['taxonomy']) { $request_key = $request_value['id']; delete_term_meta($term_id, $request_key); } } } }
public function shortcode_generator() { $request = cs_get_var('shortcode'); if (empty($request)) { die; } $shortcode = $this->shortcodes[$request]; if (isset($shortcode['fields'])) { foreach ($shortcode['fields'] as $key => $field) { if (isset($field['id'])) { $field['attributes'] = isset($field['attributes']) ? wp_parse_args(array('data-atts' => $field['id']), $field['attributes']) : array('data-atts' => $field['id']); } $field_default = isset($field['default']) ? $field['default'] : ''; if (in_array($field['type'], array('image_select', 'checkbox')) && isset($field['options'])) { $field['attributes']['data-check'] = true; } echo cs_add_element($field, $field_default, 'shortcode'); } } if (isset($shortcode['clone_fields'])) { $clone_id = isset($shortcode['clone_id']) ? $shortcode['clone_id'] : $shortcode['name']; echo '<div class="cs-shortcode-clone" data-clone-id="' . $clone_id . '">'; echo '<a href="#" class="cs-remove-clone"><i class="fa fa-trash"></i></a>'; foreach ($shortcode['clone_fields'] as $key => $field) { $field['sub'] = true; $field['attributes'] = isset($field['attributes']) ? wp_parse_args(array('data-clone-atts' => $field['id']), $field['attributes']) : array('data-clone-atts' => $field['id']); $field_default = isset($field['default']) ? $field['default'] : ''; if (in_array($field['type'], array('image_select', 'checkbox')) && isset($field['options'])) { $field['attributes']['data-check'] = true; } echo cs_add_element($field, $field_default, 'shortcode'); } echo '</div>'; echo '<div class="cs-clone-button"><a id="shortcode-clone-button" class="button" href="#"><i class="fa fa-plus-circle"></i> ' . $shortcode['clone_title'] . '</a></div>'; } die; }