/** * Print a field. * * @since 3.0.0 * * @param array $args * @param string $name * * @return void */ function simcal_print_field($args, $name = '') { $field = simcal_get_field($args, $name); if ($field instanceof \SimpleCalendar\Abstracts\Field) { $field->html(); } }
/** * Print fields in a panel. * * @since 3.0.0 * * @param array $array * @param int $post_id * * @return void */ public static function print_panel_fields($array, $post_id) { foreach ($array as $section => $fields) { if ($fields && is_array($fields)) { ?> <tbody class="simcal-panel-section simcal-panel-section-<?php echo esc_attr($section); ?> "> <?php foreach ($fields as $key => $field) { $value = get_post_meta($post_id, $key, true); $field['value'] = $value ? $value : (isset($field['default']) ? $field['default'] : ''); $the_field = simcal_get_field($field); ?> <?php if ($the_field instanceof Field) { ?> <tr class="simcal-panel-field"> <th><label for="<?php echo $the_field->id; ?> "><?php echo $the_field->title; ?> </label></th> <td><?php $the_field->html(); ?> </td> </tr> <?php } ?> <?php } ?> </tbody> <?php } } }
/** * Register settings. * * Adds settings sections and fields to settings pages. * * @since 3.0.0 * * @param array $settings */ public function register_settings($settings = array()) { $settings = $settings ? $settings : $this->get_settings(); if (!empty($settings) && is_array($settings)) { foreach ($settings as $tab_id => $settings_page) { if (isset($settings_page['sections'])) { $sections = $settings_page['sections']; if (!empty($sections) && is_array($sections)) { foreach ($sections as $section_id => $section) { add_settings_section($section_id, isset($section['title']) ? $section['title'] : '', isset($section['callback']) ? $section['callback'] : '', 'simple-calendar_' . $this->page . '_' . $tab_id); if (isset($section['fields'])) { $fields = $section['fields']; if (!empty($fields) && is_array($fields)) { foreach ($fields as $field) { if (isset($field['id']) && isset($field['type'])) { $field_object = simcal_get_field($field, $field['type']); if ($field_object instanceof Field) { add_settings_field($field['id'], isset($field['title']) ? $field['title'] : '', array($field_object, 'html'), 'simple-calendar_' . $this->page . '_' . $tab_id, $section_id); } // add field } // is field valid? } // loop fields } // are fields non empty? } // are there fields? $page = simcal_get_admin_page($tab_id); register_setting('simple-calendar_' . $this->page . '_' . $tab_id, 'simple-calendar_' . $this->page . '_' . $tab_id, $page instanceof Admin_Page ? array($page, 'validate') : ''); } // loop sections } // are sections non empty? } // are there sections? } // loop settings } // are there settings? }