Ejemplo n.º 1
0
/**
 * Prefix of meta keys (optional)
 * Use underscore (_) at the beginning to make keys hidden
 * Alt.: You also can make prefix empty to disable it
*/
function sd_register_meta_boxes($meta_boxes)
{
    if (post_type_exists('professors')) {
        $types = get_terms('course_discipline', 'hide_empty=0');
        $types_array[0] = 'All Disciplines';
        if ($types) {
            foreach ($types as $type) {
                $types_array[$type->term_id] = $type->name;
            }
        }
    }
    $prefix = 'sd_';
    if (post_type_exists('professors')) {
        $meta_boxes[] = array('id' => 'professors_page_options', 'title' => 'Professors Template Options', 'pages' => array('page'), 'context' => 'normal', 'fields' => array(array('name' => 'Select Professors Disciplines', 'id' => $prefix . "professors-taxonomies", 'type' => 'checkbox_list', 'options' => $types_array, 'desc' => 'Optional. Only if you use this page as a professors page. Choose which professors discipline you want to display on this page (If Professors Template is chosen).')));
    }
    if (post_type_exists('events')) {
        $meta_boxes[] = array('id' => 'events_page_options', 'title' => 'Professors Template Options', 'pages' => array('events'), 'context' => 'normal', 'fields' => array(array('name' => __('Event Date', 'sd-framework'), 'id' => $prefix . "event_date", 'type' => 'date', 'desc' => __('Insert the event date', 'sd-framework'), 'js_options' => array('autoSize' => true, 'dateFormat' => __('MM d, yy', 'sd-framework'), 'showButtonPanel' => true)), array('name' => __('From', 'sd-framework'), 'id' => $prefix . "event_time_from", 'type' => 'time', 'js_options' => array('timeFormat' => 'hh:mm tt', 'ampm' => true)), array('name' => __('To', 'sd-framework'), 'id' => $prefix . "event_time_to", 'type' => 'time', 'js_options' => array('timeFormat' => 'hh:mm tt', 'ampm' => true))));
    }
    if (post_type_exists('professors')) {
        $meta_boxes[] = array('id' => 'professors_meta_options', 'title' => 'Professor Options', 'pages' => array('professors'), 'context' => 'normal', 'fields' => array(array('name' => 'Email Address', 'id' => $prefix . "professor_email", 'type' => 'text', 'desc' => 'Professor\'s Email Address.'), array('name' => 'Facebook URL', 'id' => $prefix . "professor_facebook", 'type' => 'text', 'desc' => 'Professor\'s Facebook URL.'), array('name' => 'Twitter URL', 'id' => $prefix . "professor_twitter", 'type' => 'text', 'desc' => 'Professor\'s Twitter URL.'), array('name' => 'Google Plus URL', 'id' => $prefix . "professor_google", 'type' => 'text', 'desc' => 'Professor\'s Google Plus URL.'), array('name' => 'Skype Id', 'id' => $prefix . "professor_skype", 'type' => 'text', 'desc' => 'Professor\'s Skype Id.')));
    }
    $meta_boxes[] = array('id' => 'page_options', 'title' => 'Page Options', 'pages' => array('page', 'post', 'professors', 'courses', 'events'), 'context' => 'normal', 'priority' => 'high', 'fields' => array(array('name' => 'Insert a Custom Page title or leave blank for default page title.', 'id' => $prefix . "page-title", 'type' => 'textarea', 'desc' => 'HTML code accepted.'), array('name' => 'Custom Header Page Background', 'desc' => 'Upload your custom header page background (optimal size 2170x213 for full image)', 'id' => $prefix . "header_page_bg", 'type' => 'image_advanced'), array('name' => 'Background No Repeat', 'id' => $prefix . "no_repeat", 'type' => 'checkbox', 'std' => '0', 'desc' => 'Header background no repeat'), array('name' => 'Background Repeat Horizontally', 'id' => $prefix . "repeat_x", 'type' => 'checkbox', 'std' => '0', 'desc' => 'Header background repeat horizontaly'), array('name' => 'Background Repeat Vertically', 'id' => $prefix . "repeat_y", 'type' => 'checkbox', 'std' => '0', 'desc' => 'Header background repeat vertically')));
    if (function_exists('smk_sidebar')) {
        $the_sidebars = smk_get_all_sidebars();
        $sidebar_options = array();
        foreach ($the_sidebars as $key => $value) {
            $sidebar_options[] = array($key => $value);
        }
        $sidebar_options = call_user_func_array('array_merge', $sidebar_options);
        $meta_boxes[] = array('id' => 'sidebar_options', 'title' => 'Sidebars', 'pages' => array('page', 'post', 'professors', 'courses'), 'context' => 'side', 'priority' => 'low', 'fields' => array(array('name' => 'Sidebar', 'id' => $prefix . "smk_sidebar", 'type' => 'select', 'desc' => 'Assign a custom sidebar to your page', 'options' => $sidebar_options)));
    }
    return $meta_boxes;
}
Ejemplo n.º 2
0
 function show()
 {
     global $post;
     // Use nonce for verification
     echo '<input type="hidden" name="wp_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
     echo '<table class="form-table cmb_metabox">';
     foreach ($this->_meta_box['fields'] as $field) {
         // Set up blank or default values for empty ones
         if (!isset($field['name'])) {
             $field['name'] = '';
         }
         if (!isset($field['desc'])) {
             $field['desc'] = '';
         }
         if (!isset($field['std'])) {
             $field['std'] = '';
         }
         if ('file' == $field['type'] && !isset($field['allow'])) {
             $field['allow'] = array('url', 'attachment');
         }
         if ('file' == $field['type'] && !isset($field['save_id'])) {
             $field['save_id'] = false;
         }
         if ('multicheck' == $field['type']) {
             $field['multiple'] = true;
         }
         $meta = get_post_meta($post->ID, $field['id'], 'multicheck' != $field['type']);
         echo '<tr>';
         if ($field['type'] == "title") {
             echo '<td colspan="2">';
         } else {
             if ($this->_meta_box['show_names'] == true) {
                 echo '<th style="width:18%"><label for="', $field['id'], '">', $field['name'], '</label></th>';
             }
             echo '<td>';
         }
         switch ($field['type']) {
             case 'text':
                 echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" />', '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'icon':
                 echo '<input type="text" class="iconname" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /> <a href="#" class="button crum-icon-add" title="' . __('Add Icon', 'dfd') . '">' . __('Add Icon', 'dfd') . '</a>', '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'sidebar_select':
                 if (class_exists('SMK_Sidebar_Generator')) {
                     $the_sidebars = smk_get_all_sidebars();
                     if (is_array($the_sidebars)) {
                         $select_str = __('-- Select a sidebar --', 'dfd');
                         $the_sidebars = array_merge(array('' => $select_str), $the_sidebars);
                     }
                     if (empty($meta) && !empty($field['std'])) {
                         $meta = $field['std'];
                     }
                     echo '<select name="', $field['id'], '" id="', $field['id'], '">';
                     foreach ($the_sidebars as $key => $value) {
                         echo '<option value="', $key, '"', $meta == $key ? ' selected="selected"' : '', '>', $value, '</option>';
                     }
                     echo '</select>';
                     echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 } else {
                     _e('Please install SMK Sidebar Generator plugin in Apperance -> Install plugins', 'dfd');
                 }
                 break;
             case 'header_select':
                 $the_headers = dfd_headers_type();
                 if (is_array($the_headers)) {
                     $select_str = __('-- Select a header --', 'dfd');
                     array_unshift($the_headers, $select_str);
                 }
                 if (empty($meta) && !empty($field['std'])) {
                     $meta = $field['std'];
                 }
                 echo '<select name="', $field['id'], '" id="', $field['id'], '">';
                 foreach ($the_headers as $key => $value) {
                     echo '<option value="', $key, '"', $meta == $key ? ' selected="selected"' : '', '>', $value, '</option>';
                 }
                 echo '</select>';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'text_small':
                 echo '<input class="cmb_text_small" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'text_medium':
                 echo '<input class="cmb_text_medium" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'text_date':
                 echo '<input class="cmb_text_small cmb_datepicker" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'text_date_timestamp':
                 echo '<input class="cmb_text_small cmb_datepicker" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? date('m\\/d\\/Y', $meta) : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'text_datetime_timestamp':
                 echo '<input class="cmb_text_small cmb_datepicker" type="text" name="', $field['id'], '[date]" id="', $field['id'], '_date" value="', '' !== $meta ? date('m\\/d\\/Y', $meta) : $field['std'], '" />';
                 echo '<input class="cmb_timepicker text_time" type="text" name="', $field['id'], '[time]" id="', $field['id'], '_time" value="', '' !== $meta ? date('h:i A', $meta) : $field['std'], '" /><span class="cmb_metabox_description" >', $field['desc'], '</span>';
                 break;
             case 'text_time':
                 echo '<input class="cmb_timepicker text_time" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'text_money':
                 echo '$ <input class="cmb_text_money" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'colorpicker':
                 $meta = '' !== $meta ? $meta : $field['std'];
                 $hex_color = '(([a-fA-F0-9]){3}){1,2}$';
                 if (preg_match('/^' . $hex_color . '/i', $meta)) {
                     // Value is just 123abc, so prepend #.
                     $meta = '#' . $meta;
                 } elseif (!preg_match('/^#' . $hex_color . '/i', $meta)) {
                     // Value doesn't match #123abc, so sanitize to just #.
                     $meta = "#";
                 }
                 echo '<input class="cmb_colorpicker cmb_text_small" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta, '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'textarea':
                 echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="10">', '' !== $meta ? $meta : $field['std'], '</textarea>', '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'textarea_small':
                 echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4">', '' !== $meta ? $meta : $field['std'], '</textarea>', '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'textarea_code':
                 echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="10" class="cmb_textarea_code">', '' !== $meta ? $meta : $field['std'], '</textarea>', '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'select':
                 if (empty($meta) && !empty($field['std'])) {
                     $meta = $field['std'];
                 }
                 echo '<select name="', $field['id'], '" id="', $field['id'], '">';
                 foreach ($field['options'] as $option) {
                     echo '<option value="', $option['value'], '"', $meta == $option['value'] ? ' selected="selected"' : '', '>', $option['name'], '</option>';
                 }
                 echo '</select>';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'radio_inline':
                 if (empty($meta) && !empty($field['std'])) {
                     $meta = $field['std'];
                 }
                 echo '<div class="cmb_radio_inline">';
                 $i = 1;
                 foreach ($field['options'] as $option) {
                     echo '<div class="cmb_radio_inline_option"><input type="radio" name="', $field['id'], '" id="', $field['id'], $i, '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' /><label for="', $field['id'], $i, '">', $option['name'], '</label></div>';
                     $i++;
                 }
                 echo '</div>';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'radio':
                 if (empty($meta) && !empty($field['std'])) {
                     $meta = $field['std'];
                 }
                 echo '<ul>';
                 $i = 1;
                 foreach ($field['options'] as $option) {
                     echo '<li><input type="radio" name="', $field['id'], '" id="', $field['id'], $i, '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' /><label for="', $field['id'], $i, '">', $option['name'] . '</label></li>';
                     $i++;
                 }
                 echo '</ul>';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'checkbox':
                 echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
                 echo '<span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'multicheck':
                 echo '<ul>';
                 $i = 1;
                 foreach ($field['options'] as $value => $name) {
                     // Append `[]` to the name to get multiple values
                     // Use in_array() to check whether the current option should be checked
                     echo '<li><input type="checkbox" name="', $field['id'], '[]" id="', $field['id'], $i, '" value="', $value, '"', in_array($value, $meta) ? ' checked="checked"' : '', ' /><label for="', $field['id'], $i, '">', $name, '</label></li>';
                     $i++;
                 }
                 echo '</ul>';
                 echo '<span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'title':
                 echo '<h5 class="cmb_metabox_title">', $field['name'], '</h5>';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'wysiwyg':
                 wp_editor($meta ? $meta : $field['std'], $field['id'], isset($field['options']) ? $field['options'] : array());
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'taxonomy_select':
                 echo '<select name="', $field['id'], '" id="', $field['id'], '">';
                 $names = wp_get_object_terms($post->ID, $field['taxonomy']);
                 $terms = get_terms($field['taxonomy'], 'hide_empty=0');
                 foreach ($terms as $term) {
                     if (!is_wp_error($names) && !empty($names) && !strcmp($term->slug, $names[0]->slug)) {
                         echo '<option value="' . $term->slug . '" selected>' . $term->name . '</option>';
                     } else {
                         echo '<option value="' . $term->slug . '  ', $meta == $term->slug ? $meta : ' ', '  ">' . $term->name . '</option>';
                     }
                 }
                 echo '</select>';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'taxonomy_radio':
                 $names = wp_get_object_terms($post->ID, $field['taxonomy']);
                 $terms = get_terms($field['taxonomy'], 'hide_empty=0');
                 echo '<ul>';
                 foreach ($terms as $term) {
                     if (!is_wp_error($names) && !empty($names) && !strcmp($term->slug, $names[0]->slug)) {
                         echo '<li><input type="radio" name="', $field['id'], '" value="' . $term->slug . '" checked>' . $term->name . '</li>';
                     } else {
                         echo '<li><input type="radio" name="', $field['id'], '" value="' . $term->slug . '  ', $meta == $term->slug ? $meta : ' ', '  ">' . $term->name . '</li>';
                     }
                 }
                 echo '</ul>';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 break;
             case 'taxonomy_multicheck':
                 echo '<ul>';
                 $names = wp_get_object_terms($post->ID, $field['taxonomy']);
                 $terms = get_terms($field['taxonomy'], 'hide_empty=0');
                 foreach ($terms as $term) {
                     echo '<li><input type="checkbox" name="', $field['id'], '[]" id="', $field['id'], '" value="', $term->name, '"';
                     foreach ($names as $name) {
                         if ($term->slug == $name->slug) {
                             echo ' checked="checked" ';
                         }
                     }
                     echo ' /><label>', $term->name, '</label></li>';
                 }
                 echo '</ul>';
                 echo '<span class="cmb_metabox_description">', $field['desc'], '</span>';
                 break;
             case 'file_list':
                 echo '<input class="cmb_upload_file" type="text" size="36" name="', $field['id'], '" value="" />';
                 echo '<input class="cmb_upload_button button" type="button" value="Upload File" />';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 $args = array('post_type' => 'attachment', 'numberposts' => null, 'post_status' => null, 'post_parent' => $post->ID);
                 $attachments = get_posts($args);
                 if ($attachments) {
                     echo '<ul class="attach_list">';
                     foreach ($attachments as $attachment) {
                         echo '<li>' . wp_get_attachment_link($attachment->ID, 'thumbnail', 0, 0, 'Download');
                         echo '<span>';
                         echo apply_filters('the_title', '&nbsp;' . $attachment->post_title);
                         echo '</span></li>';
                     }
                     echo '</ul>';
                 }
                 break;
             case 'file':
                 $input_type_url = "hidden";
                 if ('url' == $field['allow'] || is_array($field['allow']) && in_array('url', $field['allow'])) {
                     $input_type_url = "text";
                 }
                 echo '<input class="cmb_upload_file" type="' . $input_type_url . '" size="45" id="', $field['id'], '" name="', $field['id'], '" value="', $meta, '" />';
                 echo '<input class="cmb_upload_button button" type="button" value="Upload File" />';
                 echo '<input class="cmb_upload_file_id" type="hidden" id="', $field['id'], '_id" name="', $field['id'], '_id" value="', get_post_meta($post->ID, $field['id'] . "_id", true), '" />';
                 echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 echo '<div id="', $field['id'], '_status" class="cmb_media_status">';
                 if ($meta != '') {
                     $check_image = preg_match('/(^.*\\.jpg|jpeg|png|gif|ico*)/i', $meta);
                     if ($check_image) {
                         echo '<div class="img_status">';
                         echo '<img src="', $meta, '" alt="" />';
                         echo '<a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">Remove Image</a>';
                         echo '</div>';
                     } else {
                         $parts = explode('/', $meta);
                         for ($i = 0; $i < count($parts); ++$i) {
                             $title = $parts[$i];
                         }
                         echo 'File: <strong>', $title, '</strong>&nbsp;&nbsp;&nbsp; (<a href="', $meta, '" target="_blank" rel="external">Download</a> / <a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">Remove</a>)';
                     }
                 }
                 echo '</div>';
                 break;
             case 'oembed':
                 echo '<input class="cmb_oembed" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" />', '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                 echo '<p class="cmb-spinner spinner"></p>';
                 echo '<div id="', $field['id'], '_status" class="cmb_media_status ui-helper-clearfix embed_wrap">';
                 if ($meta != '') {
                     $check_embed = $GLOBALS['wp_embed']->run_shortcode('[embed]' . esc_url($meta) . '[/embed]');
                     if ($check_embed) {
                         echo '<div class="embed_status">';
                         echo $check_embed;
                         echo '<a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">Remove Embed</a>';
                         echo '</div>';
                     } else {
                         echo 'URL is not a valid oEmbed URL.';
                     }
                 }
                 echo '</div>';
                 break;
             default:
                 do_action('cmb_render_' . $field['type'], $field, $meta);
         }
         echo '</td>', '</tr>';
     }
     echo '</table>';
 }
Ejemplo n.º 3
0
function dfd_sidebar_list()
{
    $arr = array();
    if (class_exists('SMK_Sidebar_Generator')) {
        $the_sidebars = smk_get_all_sidebars();
        if (is_array($the_sidebars)) {
            $select_str = __('-- Select a sidebar --', 'crum');
            $the_sidebars = array_merge(array('' => $select_str), $the_sidebars);
        }
        foreach ($the_sidebars as $key => $value) {
            $arr[$key] = $value;
        }
    } else {
        $arr[] = __('Please install SMK Sidebar Generator plugin in Apperance -> Install plugins', 'crum');
    }
    return $arr;
}