PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/inleague/lib/custom-portfolio-posts.php

https://bitbucket.org/joelkriteman/argento
PHP | 140 lines | 101 code | 29 blank | 10 comment | 6 complexity | 1d8fe35bcbab28d9ab2e41acaeaf703b MD5 | raw file
  1. <?php
  2. // ===== Create the Custom Post Type ===== //
  3. add_action('init', 'portfolio_register');
  4. function portfolio_register() {
  5. //Arguments to create post type.
  6. $args = array(
  7. 'label' => 'Portfolio',
  8. 'public' => true,
  9. 'show_ui' => true,
  10. 'menu_icon' => get_template_directory_uri() . '/images/icon-portfolio.png',
  11. 'show_in_menu' => true,
  12. 'capability_type' => 'post',
  13. 'hierarchical' => true,
  14. 'rewrite' => array('slug' => ''),
  15. 'menu_position' => 4,
  16. 'supports' => array('title','editor','revisions','thumbnail',),
  17. 'labels' => array (
  18. 'name' => 'Portfolio',
  19. 'singular_name' => 'Portfolio Item',
  20. 'menu_name' => 'Portfolio',
  21. 'add_new' => 'Add New Item',
  22. 'add_new_item' => 'Add New Item',
  23. 'edit' => 'Edit',
  24. 'edit_item' => 'Edit Portfolio Item',
  25. 'new_item' => 'New Portfolio Item',
  26. 'view' => 'View Portfolio Item',
  27. 'view_item' => 'View Portfolio Item',
  28. 'search_items' => 'Search Portfolio',
  29. 'not_found' => 'No Portfolio Found',
  30. 'not_found_in_trash' => 'No Portfolio Found in Trash',
  31. ),
  32. );
  33. //Register type and custom taxonomy for type.
  34. register_post_type( 'portfolio' , $args );
  35. }
  36. // ===== Portfolio messages ===== //
  37. function portfolio_messages($messages) {
  38. $messages[__( 'portfolio', 'inLEAGUE' )] =
  39. array(
  40. 0 => '',
  41. 1 => sprintf(('Portfolio Item Updated. <a href="%s">View portfolio</a>'), esc_url(get_permalink($post_ID))),
  42. 2 => __('Custom Field Updated.', 'inLEAGUE'),
  43. 3 => __('Custom Field Deleted.', 'inLEAGUE'),
  44. 4 => __('Portfolio Item Updated.', 'inLEAGUE'),
  45. 5 => isset($_GET['revision']) ? sprintf( __('Portfolio Item Restored To Revision From %s', 'inLEAGUE'), wp_post_revision_title((int)$_GET['revision'], false)) : false,
  46. 6 => sprintf(__('Portfolio Item Published. <a href="%s">View Portfolio</a>', 'inLEAGUE'), esc_url(get_permalink($post_ID))),
  47. 7 => __('Portfolio Item Saved.', 'inLEAGUE'),
  48. 8 => sprintf(__('Portfolio Item Submitted. <a target="_blank" href="%s">Preview Portfolio</a>', 'inLEAGUE'), esc_url( add_query_arg('preview', 'true', get_permalink($post_ID)))),
  49. 9 => sprintf(__('Portfolio Item Scheduled For: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Portfolio Item</a>', 'inLEAGUE'), date_i18n( __( 'M j, Y @ G:i', 'inLEAGUE' ), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
  50. 10 => sprintf(__('Portfolio Item Draft Updated. <a target="_blank" href="%s">Preview Portfolio</a>', 'inLEAGUE'), esc_url( add_query_arg('preview', 'true', get_permalink($post_ID)))),
  51. );
  52. return $messages;
  53. }
  54. add_filter( 'post_updated_messages', 'portfolio_messages' );
  55. // ===== Porfolio Filter ===== //
  56. function portfolio_filter() {
  57. register_taxonomy(
  58. __( 'filter', 'inLEAGUE' ),
  59. array(__( 'portfolio', 'inLEAGUE' )),
  60. array(
  61. "hierarchical" => true,
  62. "label" => __( 'Filter', 'inLEAGUE' ),
  63. "singular_label" => __( 'Filter', 'inLEAGUE' ),
  64. "rewrite" => array(
  65. 'slug' => 'filter',
  66. 'hierarchical' => true
  67. )
  68. )
  69. );
  70. }
  71. add_action( 'init', 'portfolio_filter', 0 );
  72. // ===== Visit Site Link ===== //
  73. // creates the meta box
  74. function add_meta_site_link() {
  75. add_meta_box('portfolio-meta', __('Project Link', 'inLEAGUE'),
  76. 'portfolio_meta_options', 'portfolio',
  77. 'normal', 'high');
  78. }
  79. add_action('admin_init', 'add_meta_site_link');
  80. // Build the metta box content
  81. function portfolio_meta_options() {
  82. global $post;
  83. if ( define('DOING_AUTOSAVE', '') && DOING_AUTOSAVE )
  84. return $post_id;
  85. $custom = get_post_custom($post->ID);
  86. $website = $custom['website'][0];
  87. ?>
  88. <div class="portfolio-extras">
  89. <?php
  90. $website = ($website == '') ? 'http://' : $website;
  91. ?>
  92. <div>
  93. <label>Project Link: </label><input name="website" value="<?php echo $website ?>" />
  94. </div>
  95. </div>
  96. <style>
  97. .portfolio-extras label {width: 100px; float: left;line-height: 1.4em;}
  98. </style>
  99. <?php
  100. }
  101. // save portfolio meta data
  102. add_action('save_post', 'portfolio_save_meta');
  103. function portfolio_save_meta() {
  104. global $post;
  105. if ( define('DOING_AUTOSAVE', '') && DOING_AUTOSAVE ) {
  106. // if you remove this the sky will fall on your head.
  107. return $post_id;
  108. } else {
  109. update_post_meta($post->ID, 'website', $_POST['website']);
  110. }
  111. }