Advertisement
danfolt

custom-type.php

Jul 4th, 2013
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.18 KB | None | 0 0
  1. <?php
  2.  
  3. if ( function_exists( 'add_theme_support' ) ) {
  4.     add_theme_support( 'post-thumbnails' );
  5.     set_post_thumbnail_size( 280, 210, true ); // Normal post thumbnails
  6.     add_image_size( 'screen-shot', 720, 540 ); // Full size screen
  7. }
  8.  
  9. add_action('init', 'custom_register');  
  10.  
  11. function custom_register() {  
  12. register_post_type(
  13.     'portfolio', array(
  14.         'label' => 'Portfolio',
  15.         'description' => '',
  16.         'public' => true,
  17.         'show_ui' => true,
  18.         'show_in_menu' => true,
  19.         'map_meta_cap' => true,
  20.         'capability_type' => 'post',
  21.         'hierarchical' => true,
  22.         'rewrite' => array(
  23.             'slug' => 'portfolio'),
  24.         'query_var' => true,
  25.         'exclude_from_search' => false,
  26.         'menu_position' => 25,
  27.         'supports' => array(
  28.             'title',
  29.             'editor',
  30.             'custom-fields',
  31.             'revisions',
  32.             'thumbnail',
  33.                         'comments',
  34.             'author',
  35.             'page-attributes',),
  36.         'taxonomies' => array(
  37.             'styles',),
  38.         'labels' => array (
  39.             'name' => 'Portfolios',
  40.             'singular_name' => 'Portfolio',
  41.             'menu_name' => 'Portfolios',
  42.             'add_new' => 'Add Portfolio',
  43.             'add_new_item' => 'Add New Portfolio',
  44.             'edit' => 'Edit',
  45.             'edit_item' => 'Edit Portfolio',
  46.             'new_item' => 'New Portfolio',
  47.             'view' => 'View Portfolio',
  48.             'view_item' => 'View Portfolio',
  49.             'search_items' => 'Search Portfolios',
  50.             'not_found' => 'No Portfolios Found',
  51.             'not_found_in_trash' => 'No Portfolios Found in Trash',
  52.             'parent' => 'Parent Portfolio',),
  53.     )
  54. );      
  55. register_post_type(
  56.     'blacklist', array(
  57.         'label' => 'Blacklist',
  58.         'description' => '',
  59.         'public' => true,
  60.         'show_ui' => true,
  61.         'show_in_menu' => true,
  62.         'map_meta_cap' => true,
  63.         'capability_type' => 'post',
  64.         'hierarchical' => true,
  65.         'rewrite' => array(
  66.             'slug' => 'blacklist'),
  67.         'query_var' => true,
  68.         'exclude_from_search' => false,
  69.         'menu_position' => 25,
  70.         'supports' => array(
  71.             'title',
  72.             'editor',
  73.             'custom-fields',
  74.             'revisions',
  75.             'thumbnail',
  76.                         'comments',
  77.             'author',
  78.             'page-attributes',),
  79.         'taxonomies' => array(
  80.             'styles',),
  81.         'labels' => array (
  82.             'name' => 'Blacklist',
  83.             'singular_name' => 'Blacklist',
  84.             'menu_name' => 'Blacklist',
  85.             'add_new' => 'Add Blacklist',
  86.             'add_new_item' => 'Add New Blacklist',
  87.             'edit' => 'Edit',
  88.             'edit_item' => 'Edit Blacklist',
  89.             'new_item' => 'New Blacklist',
  90.             'view' => 'View Blacklist',
  91.             'view_item' => 'View Blacklist',
  92.             'search_items' => 'Search Blacklist',
  93.             'not_found' => 'No Blacklist Found',
  94.             'not_found_in_trash' => 'No Blacklist Found in Trash',
  95.             'parent' => 'Parent Blacklist',),
  96.     )
  97. );
  98. register_post_type(
  99.     'applicant', array(
  100.         'label' => 'Applicants',
  101.         'description' => '',
  102.         'public' => true,
  103.         'show_ui' => true,
  104.         'show_in_menu' => true,
  105.         'map_meta_cap' => true,
  106.         'capability_type' => 'post',
  107.         'hierarchical' => true,
  108.         'rewrite' => array(
  109.             'slug' => ''),
  110.         'query_var' => true,
  111.         'exclude_from_search' => false,
  112.         'menu_position' => 25,
  113.         'supports' => array(
  114.             'title',
  115.             'editor',
  116.             'custom-fields',
  117.             'revisions',
  118.             'thumbnail',
  119.             'author',
  120.                         'comments',
  121.             'page-attributes',),
  122.         'taxonomies' => array(
  123.             'styles',),
  124.         'labels' => array (
  125.             'name' => 'Applicants',
  126.             'singular_name' => 'Applicant',
  127.             'menu_name' => 'Applicants',
  128.             'add_new' => 'Add Applicant',
  129.             'add_new_item' => 'Add New Applicant',
  130.             'edit' => 'Edit',
  131.             'edit_item' => 'Edit Applicant',
  132.             'new_item' => 'New Applicant',
  133.             'view' => 'View Applicant',
  134.             'view_item' => 'View Applicant',
  135.             'search_items' => 'Search Applicants',
  136.             'not_found' => 'No Applicants Found',
  137.             'not_found_in_trash' => 'No Applicants Found in Trash',
  138.             'parent' => 'Parent Applicant',),
  139.     )
  140. );
  141. register_post_type(
  142.     'employer', array(
  143.         'label' => 'Employers',
  144.         'description' => '',
  145.         'public' => true,
  146.         'show_ui' => true,
  147.         'show_in_menu' => true,
  148.         'map_meta_cap' => true,
  149.         'capability_type' => 'post',
  150.         'hierarchical' => true,
  151.         'rewrite' => array(
  152.             'slug' => 'employer'),
  153.         'query_var' => true,
  154.         'exclude_from_search' => false,
  155.         'menu_position' => 25,
  156.         'supports' => array(
  157.             'title',
  158.             'editor',
  159.             'custom-fields',
  160.             'revisions',
  161.             'thumbnail',
  162.             'author',
  163.                         'comments',
  164.             'page-attributes',),
  165.         'taxonomies' => array(
  166.             'styles',),
  167.         'labels' => array (
  168.             'name' => 'Employers',
  169.             'singular_name' => 'Employer',
  170.             'menu_name' => 'Employers',
  171.             'add_new' => 'Add Employer',
  172.             'add_new_item' => 'Add New Employer',
  173.             'edit' => 'Edit',
  174.             'edit_item' => 'Edit Employer',
  175.             'new_item' => 'New Employer',
  176.             'view' => 'View Employer',
  177.             'view_item' => 'View Employer',
  178.             'search_items' => 'Search Employers',
  179.             'not_found' => 'No Employers Found',
  180.             'not_found_in_trash' => 'No Employers Found in Trash',
  181.             'parent' => 'Parent Employer',),
  182.     )
  183. );
  184. }
  185.  
  186. // custom taxonomy for portfolio blacklist employer and applicant
  187. register_taxonomy('job-type', array('portfolio', 'blacklist', 'employer', 'applicant'),  array(
  188.         'label' => __('Job Category'),
  189.         'singular_label' => __('Job Category'),
  190.         'hierarchical' => true,
  191.         'query_var' => 'job-type',
  192.         'rewrite' => false,
  193.         'public' => true,
  194.         'show_ui' => true,
  195.         'show_in_nav_menus' => false,
  196.         ));
  197.        
  198. // custom taxonomy for portfolio blacklist employer and applicant
  199. register_taxonomy('province', array('portfolio', 'blacklist', 'employer', 'applicant'),  array(
  200.         'label' => __('Provincia'),
  201.         'singular_label' => __('Provincia'),
  202.         'hierarchical' => true,
  203.         'query_var' => 'province',
  204.         'rewrite' => false,
  205.         'public' => true,
  206.         'show_ui' => true,
  207.         'show_in_nav_menus' => false,
  208.         ));
  209.        
  210. // custom taxonomy for portfolio blacklist employer and applicant
  211. register_taxonomy('location', array('portfolio', 'blacklist', 'employer', 'applicant'),  array(
  212.         'label' => __('Location'),
  213.         'singular_label' => __('Location'),
  214.         'hierarchical' => true,
  215.         'query_var' => 'location',
  216.         'rewrite' => false,
  217.         'public' => true,
  218.         'show_ui' => true,
  219.         'show_in_nav_menus' => false,
  220.         ));
  221.  
  222.  
  223. add_filter( 'map_meta_cap', 'my_map_meta_cap', 10, 4 );
  224.  
  225. function my_map_meta_cap( $caps, $cap, $user_id, $args ) {
  226.  
  227.     /* If editing, deleting, or reading a portfolio, get the post and post type object. */
  228.     if ( 'edit_portfolio' == $cap || 'delete_portfolio' == $cap || 'read_portfolio' == $cap ) {
  229.         $post = get_post( $args[0] );
  230.         $post_type = get_post_type_object( $post->post_type );
  231.  
  232.         /* Set an empty array for the caps. */
  233.         $caps = array();
  234.     }
  235.  
  236.     /* If editing a portfolio, assign the required capability. */
  237.     if ( 'edit_portfolio' == $cap ) {
  238.         if ( $user_id == $post->post_author )
  239.             $caps[] = $post_type->cap->edit_posts;
  240.         else
  241.             $caps[] = $post_type->cap->edit_others_posts;
  242.     }
  243.  
  244.     /* If deleting a portfolio, assign the required capability. */
  245.     elseif ( 'delete_portfolio' == $cap ) {
  246.         if ( $user_id == $post->post_author )
  247.             $caps[] = $post_type->cap->delete_posts;
  248.         else
  249.             $caps[] = $post_type->cap->delete_others_posts;
  250.     }
  251.  
  252.     /* If reading a private portfolio, assign the required capability. */
  253.     elseif ( 'read_portfolio' == $cap ) {
  254.  
  255.         if ( 'private' != $post->post_status )
  256.             $caps[] = 'read';
  257.         elseif ( $user_id == $post->post_author )
  258.             $caps[] = 'read';
  259.         else
  260.             $caps[] = $post_type->cap->read_private_posts;
  261.     }
  262.  
  263.     /* Return the capabilities required by the user. */
  264.     return $caps;
  265. }
  266.  
  267.  
  268. add_action("admin_init", "portfolio_meta_box");  
  269.  
  270.  
  271. function portfolio_meta_box(){  
  272.     add_meta_box("projInfo-meta", "Project Options", "portfolio_meta_options", "portfolio", "side", "low");  
  273. }  
  274.  
  275.  
  276. function portfolio_meta_options(){  
  277.         global $post;  
  278.         if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
  279.         $custom = get_post_custom($post->ID);  
  280.         $link = $custom["projLink"][0];  
  281. ?>  
  282.     <label>Link:</label><input name="projLink" value="<?php echo $link; ?>" />  
  283. <?php  
  284.     }  
  285.    
  286. add_action('save_post', 'save_project_link');
  287.  
  288. function save_project_link(){  
  289.     global $post;  
  290.    
  291.     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
  292.         return $post_id;
  293.     }else{
  294.         update_post_meta($post->ID, "projLink", $_POST["projLink"]);
  295.     }
  296. }  
  297.  
  298. add_filter("manage_edit-portfolio_columns", "project_edit_columns");  
  299.  
  300. function project_edit_columns($columns){  
  301.         $columns = array(  
  302.             "cb" => "<input type=\"checkbox\" />",  
  303.             "title" => "Project",  
  304.             "description" => "Description",  
  305.             "link" => "Link",  
  306.             "type" => "Type of Project",  
  307.         );  
  308.  
  309.         return $columns;  
  310. }  
  311.  
  312. add_action("manage_posts_custom_column",  "project_custom_columns");
  313.  
  314. function project_custom_columns($column){  
  315.         global $post;  
  316.         switch ($column)  
  317.         {  
  318.             case "description":  
  319.                 the_excerpt();  
  320.                 break;  
  321.             case "link":  
  322.                 $custom = get_post_custom();  
  323.                 echo $custom["projLink"][0];  
  324.                 break;  
  325.             case "type":  
  326.                 echo get_the_term_list($post->ID, 'project-type', '', ', ','');  
  327.                 break;  
  328.         }  
  329. }  
  330.  
  331. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement