Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Created December 21, 2011 00:50
Show Gist options
  • Save mikeschinkel/1504012 to your computer and use it in GitHub Desktop.
Save mikeschinkel/1504012 to your computer and use it in GitHub Desktop.
Extending WordPress the WordPress Way vs. the Sunrise Way
<?php
/**
* This is a hypothetical example showing how to add two columns to a 'person' post type using
* WordPress' way vs. the a potential future Sunrise Way:
*/
/**
* Here is how you might do it in the WordPress way.
*/
add_filter( 'manage_person_posts_columns', 'mysite_manage_person_posts_columns' );
add_action( 'manage_person_posts_custom_column', 'mysite_manage_person_posts_custom_column', 10, 2 );
function mysite_manage_person_posts_columns( $columns ) {
$columns = array();
$columns['title'] = 'Title';
$columns['practice-areas'] = 'Practice Areas';
$columns['positions'] = 'Position';
$columns['status'] = 'Status';
return $columns;
}
function mysite_manage_person_posts_custom_column( $column, $post_id ) {
switch ( $column ) {
case 'practice-areas':
// Code to get practice areas here
break;
case 'positions':
// Code to get positions here
break;
case 'status':
echo ucfirst( get_post_status( $post_id ) );
break;
}
}
/**
* Here is the potential approach Sunrise is likely to use (this
* part is not yet implemented which is why I type "potential.")
*/
add_action( 'init', 'mysite_init' );
function mysite_init() {
sr_register_post_column( 'person', 'title', array(
'label' => 'Title',
));
sr_register_post_column( 'person', 'practice-areas', array(
'label' => 'Practice Areas',
'source' => 'related_post',
'related_type' => 'practice-area',
));
sr_register_post_column( 'person', 'positions', array(
'label' => 'Position',
'source' => 'taxonomy',
'taxonomy' => 'person-position',
));
sr_register_post_column( 'person', 'status', array(
'label' => 'Status',
));
);
/**
* Here's another more streamlined approach
*/
function mysite_init() {
sr_register_post_columns( 'person', array(
'title' => array(
'label' => 'Title',
),
'practice-areas' => array(
'label' => 'Practice Areas',
'source' => 'related_post',
'related_type' => 'practice-area',
),
'positions' => array(
'label' => 'Position',
'source' => 'taxonomy',
'taxonomy' => 'person-position',
),
'status' => array(
'label' => 'Status',
),
);
);
/**
* We are also planning YAML configuration file support, which will
* allow us to allow configurations something like this:
*/
----
columns:
- post_type: person
- title:
- label: Title
- practice-areas:
- label: Practice Areas
- source: related_post
- related_type: practice-area
- positions:
- label: Position
- source: taxonomy
- taxonomy: person-position
- status:
- label: Status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment