Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'init', 'codex_team_init' );
- function codex_team_init() {
- $labels = array(
- 'name' => _x( 'team', 'post type general name', 'your-plugin-textdomain' ),
- 'singular_name' => _x( 'teams', 'post type singular name', 'your-plugin-textdomain' ),
- 'menu_name' => _x( 'Team', 'admin menu', 'your-plugin-textdomain' ),
- 'name_admin_bar' => _x( 'team', 'add new on admin bar', 'your-plugin-textdomain' ),
- 'add_new' => _x( 'Add New', 'team', 'your-plugin-textdomain' ),
- 'add_new_item' => __( 'Add New team', 'your-plugin-textdomain' ),
- 'new_item' => __( 'New team', 'your-plugin-textdomain' ),
- 'edit_item' => __( 'Edit team', 'your-plugin-textdomain' ),
- 'view_item' => __( 'View team', 'your-plugin-textdomain' ),
- 'all_items' => __( 'All team', 'your-plugin-textdomain' ),
- 'search_items' => __( 'Search team', 'your-plugin-textdomain' ),
- 'parent_item_colon' => __( 'Parent team:', 'your-plugin-textdomain' ),
- 'not_found' => __( 'No team found.', 'your-plugin-textdomain' ),
- 'not_found_in_trash' => __( 'No team found in Trash.', 'your-plugin-textdomain' )
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'team' ),
- 'supports' => array( 'title', 'editor','page-attributes','thumbnail' ),
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => false,
- 'menu_position' => null,
- 'menu_icon' => get_bloginfo('template_directory') . '/img/icon4.png'
- );
- register_post_type( 'team', $args );
- }
- $prefix = 'mmc_';
- $post_types = array('post', 'page');
- //set up the box and teh fields inside
- $meta_box = array(
- 'id' => 'meta-box',
- 'title' => 'Social Icon', //title of box
- 'context' => 'side', //normal, advanced or side
- 'priority' => 'default',
- 'fields' => array( //and now for the custom fields in the box
- array(
- 'name' => 'Icon',
- 'id' => $prefix . 'icon',
- 'type' => 'select',
- 'options' => array('fa-google' => 'google',
- 'fa-facebook' => 'facebook',
- 'fa-skype' => 'skype',
- 'fa-twitter' => 'twitter',
- 'fa-yahoo' => 'yahoo',
- 'fa-youtube' => 'youtube',
- )
- )
- )
- );
- add_action('admin_menu', 'theme_add_box');
- // Add meta box
- function theme_add_box() {
- global $meta_box;
- global $post_types;
- foreach($post_types as $type){
- //(id, title, callback, post type, context, priority, callback args)
- add_meta_box($meta_box['id'], $meta_box['title'], 'social_meta_box', $type='team', $meta_box['context'], $meta_box['priority']);
- }
- }
- function social_meta_box() {
- global $meta_box, $post;
- // Use nonce for verification
- echo '<input type="hidden" name="theme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
- echo '<table class="form-table">';
- foreach ($meta_box['fields'] as $field) {
- // get current post meta data
- $meta = get_post_meta($post->ID, $field['id'], true);
- $title = get_post_meta($post->ID, '_title', true);
- echo '<tr>',
- '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
- '<td>';
- switch ($field['type']) {
- case 'text':
- echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',
- '<br />', $field['desc'];
- break;
- case 'textarea':
- echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',
- '<br />', $field['desc'];
- break;
- case 'select':
- echo '<select name="', $field['id'], '" id="', $field['id'], '">';
- foreach ($field['options'] as $value => $name) {
- echo '<option value="'.$value.'" ';
- echo $meta == $value ? ' selected="selected"' : '', '>', $name, '</option>';
- }
- echo '</select>';
- break;
- case 'radio':
- foreach ($field['options'] as $option) {
- echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];
- }
- break;
- case 'checkbox':
- echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
- break;
- }
- echo '</tr><tr><td>';
- echo '<i class="fa fa-2x '.$meta.'"></i>';
- echo 'Link:</td><td><input type="text" name="_title" value="' . $title . '" class="widefat"></td></tr>';
- }
- echo '</table>';
- }
- add_action('save_post', 'theme_save_data');
- function theme_save_data($post_id) {
- global $meta_box;
- // verify nonce
- if (!wp_verify_nonce($_POST['theme_meta_box_nonce'], basename(__FILE__))) {
- return $post_id;
- }
- // check autosave
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $post_id;
- }
- // check permissions
- if ('page' == $_POST['post_type']) {
- if (!current_user_can('edit_page', $post_id)) {
- return $post_id;
- }
- } elseif (!current_user_can('edit_post', $post_id)) {
- return $post_id;
- }
- foreach ($meta_box['fields'] as $field) {
- $old = get_post_meta($post_id, $field['id'], true);
- $new = $_POST[$field['id']];
- if ($new && $new != $old) {
- update_post_meta($post_id, $field['id'], $new);
- } elseif ('' == $new && $old) {
- delete_post_meta($post_id, $field['id'], $old);
- }
- }
- $events_meta['_title'] = $_POST['_title'];
- foreach ($events_meta as $key => $value) { // Cycle through the $events_meta array!
- if( $post->post_type == 'revision' ) return; // Don't store custom data twice
- $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
- if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value
- update_post_meta($post->ID, $key, $value);
- } else { // If the custom field doesn't have a value
- add_post_meta($post->ID, $key, $value);
- }
- if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
- }
- }
- $events_meta['_title'] = $_POST['_title'];
- function social_style(){
- $style_url = plugins_url('css/font-awesome.css', __FILE__);
- wp_enqueue_style( 'fontawesome', $style_url );
- ?>
- <?php
- }
- add_action('wp_enqueue_scripts','social_style');
- add_action('admin_enqueue_scripts','social_style');
- //theme template tag
- function social_icon(){
- global $prefix;
- global $post;
- $icon = get_post_meta($post->ID, $prefix.'icon', true);
- $link=get_post_meta($post->ID, '_title', true);
- if($icon && $link != ''): ?>
- <a href="<?php echo $link; ?> " class="fa <?php echo $icon; ?> mmc-fontawesome-meta-icon"></a>
- <?php endif;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement