Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 305 lines (257 sloc) 15.976 kb
c522c8c @devinsays Initial commit.
authored
1 <?php
2 /*
3 Plugin Name: Portfolio Post Type
4 Plugin URI: http://www.wptheming.com
5 Description: Enables a portfolio post type and taxonomies.
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
6 Version: 0.3
c522c8c @devinsays Initial commit.
authored
7 Author: Devin Price
2e89ccc @devinsays Added website link.
authored
8 Author URI: http://wptheming.com/portfolio-post-type/
c522c8c @devinsays Initial commit.
authored
9 License: GPLv2
10 */
11
f9e9131 @devinsays Flush rewrite rules on activation/deactivation.
authored
12 /**
13 * Flushes rewrite rules on plugin activation to ensure portfolio posts don't 404
14 * http://codex.wordpress.org/Function_Reference/flush_rewrite_rules
15 */
16
17 function portfolioposttype_activation() {
18 portfolioposttype();
19 flush_rewrite_rules();
20 }
21
22 register_activation_hook( __FILE__, 'portfolioposttype_activation' );
23
c522c8c @devinsays Initial commit.
authored
24 function portfolioposttype() {
25
26 /**
27 * Enable the Portfolio custom post type
28 * http://codex.wordpress.org/Function_Reference/register_post_type
29 */
30
31 $labels = array(
32 'name' => __( 'Portfolio', 'portfolioposttype' ),
33 'singular_name' => __( 'Portfolio Item', 'portfolioposttype' ),
34 'add_new' => __( 'Add New Item', 'portfolioposttype' ),
35 'add_new_item' => __( 'Add New Portfolio Item', 'portfolioposttype' ),
36 'edit_item' => __( 'Edit Portfolio Item', 'portfolioposttype' ),
37 'new_item' => __( 'Add New Portfolio Item', 'portfolioposttype' ),
38 'view_item' => __( 'View Item', 'portfolioposttype' ),
39 'search_items' => __( 'Search Portfolio', 'portfolioposttype' ),
40 'not_found' => __( 'No portfolio items found', 'portfolioposttype' ),
41 'not_found_in_trash' => __( 'No portfolio items found in trash', 'portfolioposttype' )
42 );
43
44 $args = array(
45 'labels' => $labels,
46 'public' => true,
47 'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
48 'capability_type' => 'post',
49 'rewrite' => array("slug" => "portfolio"), // Permalinks format
50 'menu_position' => 5,
51 'has_archive' => true
52 );
53
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
54 register_post_type( 'portfolio', $args );
c522c8c @devinsays Initial commit.
authored
55
56 /**
57 * Register a taxonomy for Portfolio Tags
58 * http://codex.wordpress.org/Function_Reference/register_taxonomy
59 */
60
61
62 $taxonomy_portfolio_tag_labels = array(
63 'name' => _x( 'Portfolio Tags', 'portfolioposttype' ),
64 'singular_name' => _x( 'Portfolio Tag', 'portfolioposttype' ),
65 'search_items' => _x( 'Search Portfolio Tags', 'portfolioposttype' ),
66 'popular_items' => _x( 'Popular Portfolio Tags', 'portfolioposttype' ),
67 'all_items' => _x( 'All Portfolio Tags', 'portfolioposttype' ),
68 'parent_item' => _x( 'Parent Portfolio Tag', 'portfolioposttype' ),
69 'parent_item_colon' => _x( 'Parent Portfolio Tag:', 'portfolioposttype' ),
70 'edit_item' => _x( 'Edit Portfolio Tag', 'portfolioposttype' ),
71 'update_item' => _x( 'Update Portfolio Tag', 'portfolioposttype' ),
72 'add_new_item' => _x( 'Add New Portfolio Tag', 'portfolioposttype' ),
73 'new_item_name' => _x( 'New Portfolio Tag Name', 'portfolioposttype' ),
74 'separate_items_with_commas' => _x( 'Separate portfolio tags with commas', 'portfolioposttype' ),
75 'add_or_remove_items' => _x( 'Add or remove portfolio tags', 'portfolioposttype' ),
76 'choose_from_most_used' => _x( 'Choose from the most used portfolio tags', 'portfolioposttype' ),
9dee674 @devinsays Update to make taxonomy labels appear correctly.
authored
77 'menu_name' => _x( 'Portfolio Tags', 'portfolioposttype' )
c522c8c @devinsays Initial commit.
authored
78 );
79
80 $taxonomy_portfolio_tag_args = array(
9dee674 @devinsays Update to make taxonomy labels appear correctly.
authored
81 'labels' => $taxonomy_portfolio_tag_labels,
c522c8c @devinsays Initial commit.
authored
82 'public' => true,
83 'show_in_nav_menus' => true,
84 'show_ui' => true,
85 'show_tagcloud' => true,
86 'hierarchical' => false,
87 'rewrite' => true,
88 'query_var' => true
89 );
90
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
91 register_taxonomy( 'portfolio_tag', array( 'portfolio' ), $taxonomy_portfolio_tag_args );
c522c8c @devinsays Initial commit.
authored
92
93 /**
94 * Register a taxonomy for Portfolio Categories
95 * http://codex.wordpress.org/Function_Reference/register_taxonomy
96 */
97
98 $taxonomy_portfolio_category_labels = array(
99 'name' => _x( 'Portfolio Categories', 'portfolioposttype' ),
100 'singular_name' => _x( 'Portfolio Category', 'portfolioposttype' ),
101 'search_items' => _x( 'Search Portfolio Categories', 'portfolioposttype' ),
102 'popular_items' => _x( 'Popular Portfolio Categories', 'portfolioposttype' ),
103 'all_items' => _x( 'All Portfolio Categories', 'portfolioposttype' ),
104 'parent_item' => _x( 'Parent Portfolio Category', 'portfolioposttype' ),
105 'parent_item_colon' => _x( 'Parent Portfolio Category:', 'portfolioposttype' ),
106 'edit_item' => _x( 'Edit Portfolio Category', 'portfolioposttype' ),
107 'update_item' => _x( 'Update Portfolio Category', 'portfolioposttype' ),
108 'add_new_item' => _x( 'Add New Portfolio Category', 'portfolioposttype' ),
109 'new_item_name' => _x( 'New Portfolio Category Name', 'portfolioposttype' ),
110 'separate_items_with_commas' => _x( 'Separate portfolio categories with commas', 'portfolioposttype' ),
111 'add_or_remove_items' => _x( 'Add or remove portfolio categories', 'portfolioposttype' ),
112 'choose_from_most_used' => _x( 'Choose from the most used portfolio categories', 'portfolioposttype' ),
113 'menu_name' => _x( 'Portfolio Categories', 'portfolioposttype' ),
114 );
115
116 $taxonomy_portfolio_category_args = array(
117 'labels' => $taxonomy_portfolio_category_labels,
118 'public' => true,
119 'show_in_nav_menus' => true,
120 'show_ui' => true,
121 'show_tagcloud' => true,
122 'hierarchical' => true,
123 'rewrite' => true,
124 'query_var' => true
125 );
126
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
127 register_taxonomy( 'portfolio_category', array( 'portfolio' ), $taxonomy_portfolio_category_args );
c522c8c @devinsays Initial commit.
authored
128
129 }
130
131 add_action( 'init', 'portfolioposttype' );
132
133 // Allow thumbnails to be used on portfolio post type
134
135 add_theme_support( 'post-thumbnails', array( 'portfolio' ) );
136
137 /**
138 * Add Columns to Portfolio Edit Screen
139 * http://wptheming.com/2010/07/column-edit-pages/
140 */
141
142 function portfolioposttype_edit_columns($portfolio_columns){
143 $portfolio_columns = array(
144 "cb" => "<input type=\"checkbox\" />",
145 "title" => _x('Title', 'column name'),
146 "thumbnail" => __('Thumbnail', 'portfolioposttype'),
25c46fb @devinsays Added category to column view.
authored
147 "portfolio_category" => __('Category', 'portfolioposttype'),
e155851 @devinsays Fixes for dashboard display of portfolio items.
authored
148 "portfolio_tag" => __('Tags', 'portfolioposttype'),
c522c8c @devinsays Initial commit.
authored
149 "author" => __('Author', 'portfolioposttype'),
150 "comments" => __('Comments', 'portfolioposttype'),
151 "date" => __('Date', 'portfolioposttype'),
152 );
153 $portfolio_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
154 return $portfolio_columns;
155 }
e155851 @devinsays Fixes for dashboard display of portfolio items.
authored
156
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
157 add_filter( 'manage_edit-portfolio_columns', 'portfolioposttype_edit_columns' );
c522c8c @devinsays Initial commit.
authored
158
159 function portfolioposttype_columns_display($portfolio_columns, $post_id){
160
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
161 switch ( $portfolio_columns )
c522c8c @devinsays Initial commit.
authored
162
163 {
164 // Code from: http://wpengineer.com/display-post-thumbnail-post-page-overview
165
166 case "thumbnail":
167 $width = (int) 35;
168 $height = (int) 35;
169 $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
170
171 // Display the featured image in the column view if possible
172 if ($thumbnail_id) {
173 $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
174 }
175 if ( isset($thumb) ) {
176 echo $thumb;
177 } else {
178 echo __('None', 'portfolioposttype');
179 }
180 break;
181
182 // Display the portfolio tags in the column view
25c46fb @devinsays Added category to column view.
authored
183 case "portfolio_category":
184
185 if ( $category_list = get_the_term_list( $post_id, 'portfolio_category', '', ', ', '' ) ) {
186 echo $category_list;
187 } else {
188 echo __('None', 'portfolioposttype');
189 }
190 break;
191
192 // Display the portfolio tags in the column view
e155851 @devinsays Fixes for dashboard display of portfolio items.
authored
193 case "portfolio_tag":
c522c8c @devinsays Initial commit.
authored
194
e155851 @devinsays Fixes for dashboard display of portfolio items.
authored
195 if ( $tag_list = get_the_term_list( $post_id, 'portfolio_tag', '', ', ', '' ) ) {
c522c8c @devinsays Initial commit.
authored
196 echo $tag_list;
197 } else {
198 echo __('None', 'portfolioposttype');
199 }
200 break;
201 }
202 }
203
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
204 add_action( 'manage_posts_custom_column', 'portfolioposttype_columns_display', 10, 2 );
c522c8c @devinsays Initial commit.
authored
205
206 /**
788d62a @devinsays Update readme and version number.
authored
207 * Add Portfolio count to "Right Now" Dashboard Widget
098e2fb @nickhamze Added Portfolio count & default contextual help menu
nickhamze authored
208 */
209
210 function add_portfolio_counts() {
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
211 if ( ! post_type_exists( 'portfolio' ) ) {
098e2fb @nickhamze Added Portfolio count & default contextual help menu
nickhamze authored
212 return;
213 }
214
215 $num_posts = wp_count_posts( 'portfolio' );
216 $num = number_format_i18n( $num_posts->publish );
217 $text = _n( 'Portfolio Item', 'Portfolio Items', intval($num_posts->publish) );
218 if ( current_user_can( 'edit_posts' ) ) {
219 $num = "<a href='edit.php?post_type=portfolio'>$num</a>";
220 $text = "<a href='edit.php?post_type=portfolio'>$text</a>";
221 }
222 echo '<td class="first b b-portfolio">' . $num . '</td>';
223 echo '<td class="t portfolio">' . $text . '</td>';
224 echo '</tr>';
225
226 if ($num_posts->pending > 0) {
227 $num = number_format_i18n( $num_posts->pending );
228 $text = _n( 'Portfolio Item Pending', 'Portfolio Items Pending', intval($num_posts->pending) );
229 if ( current_user_can( 'edit_posts' ) ) {
230 $num = "<a href='edit.php?post_status=pending&post_type=portfolio'>$num</a>";
231 $text = "<a href='edit.php?post_status=pending&post_type=portfolio'>$text</a>";
232 }
233 echo '<td class="first b b-portfolio">' . $num . '</td>';
234 echo '<td class="t portfolio">' . $text . '</td>';
235
236 echo '</tr>';
237 }
238 }
239
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
240 add_action( 'right_now_content_table_end', 'add_portfolio_counts' );
098e2fb @nickhamze Added Portfolio count & default contextual help menu
nickhamze authored
241
242 /**
243 * Add contextual help menu
244 */
245
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
246 function portfolioposttype_add_help_text( $contextual_help, $screen_id, $screen ) {
247 if ( 'portfolio' == $screen->id ) {
248 $contextual_help =
098e2fb @nickhamze Added Portfolio count & default contextual help menu
nickhamze authored
249 '<p>' . __('The title field and the big Post Editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.') . '</p>' .
250 '<p>' . __('<strong>Title</strong> - Enter a title for your post. After you enter a title, you&#8217;ll see the permalink below, which you can edit.') . '</p>' .
251 '<p>' . __('<strong>Post editor</strong> - Enter the text for your post. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your post text. You can insert media files by clicking the icons above the post editor and following the directions. You can go the distraction-free writing screen, new in 3.2, via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular post editor.') . '</p>' .
252 '<p>' . __('<strong>Publish</strong> - You can set the terms of publishing your post in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a post or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a post to be published in the future or backdate a post.') . '</p>' .
253 ( ( current_theme_supports( 'post-formats' ) && post_type_supports( 'post', 'post-formats' ) ) ? '<p>' . __( '<strong>Post Format</strong> - This designates how your theme will display a specific post. For example, you could have a <em>standard</em> blog post with a title and paragraphs, or a short <em>aside</em> that omits the title and contains a short text blurb. Please refer to the Codex for <a href="http://codex.wordpress.org/Post_Formats#Supported_Formats">descriptions of each post format</a>. Your theme could enable all or some of 10 possible formats.' ) . '</p>' : '' ) .
254 '<p>' . __('<strong>Featured Image</strong> - This allows you to associate an image with your post without inserting it. This is usually useful only if your theme makes use of the featured image as a post thumbnail on the home page, a custom header, etc.') . '</p>' .
255 '<p>' . __('<strong>Send Trackbacks</strong> - Trackbacks are a way to notify legacy blog systems that you&#8217;ve linked to them. Enter the URL(s) you want to send trackbacks. If you link to other WordPress sites they&#8217;ll be notified automatically using pingbacks, and this field is unnecessary.') . '</p>' .
256 '<p>' . __('<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the post, you can see them here and moderate them.') . '</p>' .
257 '<p><strong>' . __('For more information:') . '</strong></p>' .
258 '<p>' . __('<a href="http://codex.wordpress.org/Posts_Add_New_Screen" target="_blank">Documentation on Writing and Editing Posts</a>') . '</p>' .
259 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
260 } elseif ( 'edit-portfolio' == $screen->id ) {
261 $contextual_help =
262 '<p>' . __('You can customize the display of this screen in a number of ways:') . '</p>' .
263 '<ul>' .
264 '<li>' . __('You can hide/display columns based on your needs and decide how many posts to list per screen using the Screen Options tab.') . '</li>' .
265 '<li>' . __('You can filter the list of posts by post status using the text links in the upper left to show All, Published, Draft, or Trashed posts. The default view is to show all posts.') . '</li>' .
266 '<li>' . __('You can view posts in a simple title list or with an excerpt. Choose the view you prefer by clicking on the icons at the top of the list on the right.') . '</li>' .
267 '<li>' . __('You can refine the list to show only posts in a specific category or from a specific month by using the dropdown menus above the posts list. Click the Filter button after making your selection. You also can refine the list by clicking on the post author, category or tag in the posts list.') . '</li>' .
268 '</ul>' .
269 '<p>' . __('Hovering over a row in the posts list will display action links that allow you to manage your post. You can perform the following actions:') . '</p>' .
270 '<ul>' .
271 '<li>' . __('Edit takes you to the editing screen for that post. You can also reach that screen by clicking on the post title.') . '</li>' .
272 '<li>' . __('Quick Edit provides inline access to the metadata of your post, allowing you to update post details without leaving this screen.') . '</li>' .
273 '<li>' . __('Trash removes your post from this list and places it in the trash, from which you can permanently delete it.') . '</li>' .
274 '<li>' . __('Preview will show you what your draft post will look like if you publish it. View will take you to your live site to view the post. Which link is available depends on your post&#8217;s status.') . '</li>' .
275 '</ul>' .
276 '<p>' . __('You can also edit multiple posts at once. Select the posts you want to edit using the checkboxes, select Edit from the Bulk Actions menu and click Apply. You will be able to change the metadata (categories, author, etc.) for all selected posts at once. To remove a post from the grouping, just click the x next to its name in the Bulk Edit area that appears.') . '</p>' .
277 '<p><strong>' . __('For more information:') . '</strong></p>' .
278 '<p>' . __('<a href="http://codex.wordpress.org/Posts_Screen" target="_blank">Documentation on Managing Posts</a>') . '</p>' .
279 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
280
281 }
282 return $contextual_help;
283 }
284
285 add_action( 'contextual_help', 'portfolioposttype_add_help_text', 10, 3 );
286
287 /**
c522c8c @devinsays Initial commit.
authored
288 * Displays the custom post type icon in the dashboard
289 */
290
3bd6df5 @devinsays Update code formatting to match Pear standards.
authored
291 function portfolioposttype_portfolio_icons() { ?>
c522c8c @devinsays Initial commit.
authored
292 <style type="text/css" media="screen">
293 #menu-posts-portfolio .wp-menu-image {
294 background: url(<?php echo plugin_dir_url( __FILE__ ); ?>images/portfolio-icon.png) no-repeat 6px 6px !important;
295 }
296 #menu-posts-portfolio:hover .wp-menu-image, #menu-posts-portfolio.wp-has-current-submenu .wp-menu-image {
297 background-position:6px -16px !important;
298 }
299 #icon-edit.icon32-posts-portfolio {background: url(<?php echo plugin_dir_url( __FILE__ ); ?>images/portfolio-32x32.png) no-repeat;}
300 </style>
301 <?php }
302
303 add_action( 'admin_head', 'portfolioposttype_portfolio_icons' );
304
305 ?>
Something went wrong with that request. Please try again.