Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Idealien Manager Bios
- Plugin URI: http://idealienstudios.com
- Description: Add manager biography information to posts
- Author: Jamie Oastler
- Version: 0.1
- Author URI: http://idealienstudios.com
- */
- class Idealien_Manager {
- var $meta_fields = array("idealien_mgr_position",
- "idealien_mgr_quote",
- "idealien_mgr_education",
- "idealien_mgr_background",
- "idealien_mgr_involvement");
- function Idealien_Manager()
- {
- // Register custom post types
- register_post_type('manager', array(
- 'label' => __('Managers'),
- 'singular_label' => __('Manager'),
- 'public' => true,
- 'show_ui' => true, // UI in admin panel
- '_builtin' => false, // It's a custom post type, not built in
- '_edit_link' => 'post.php?post=%d',
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'rewrite' => array("slug" => "manager"), // Permalinks
- 'query_var' => "manager", // This goes to the WP_Query schema
- 'supports' => array('title' ,'author', 'thumbnail'/*'excerpt', 'editor' ,'custom-fields'*/) // Let's use custom fields for debugging purposes only
- ));
- add_filter("manage_edit-manager_columns", array(&$this, "edit_columns"));
- add_action("manage_posts_custom_column", array(&$this, "custom_columns"));
- // Admin interface init
- add_action("admin_init", array(&$this, "admin_init"));
- add_action("template_redirect", array(&$this, 'template_redirect'));
- // Insert post hook
- add_action("wp_insert_post", array(&$this, "wp_insert_post"), 10, 2);
- //End Idealien_Manager constructor function
- }
- function edit_columns($columns)
- {
- $columns = array(
- "cb" => "<input type=\"checkbox\" />",
- "title" => "Manager",
- "idealien_mgr_position" => "Position",
- "thumbnail" => "Photo",
- "date"=>"Date"
- );
- return $columns;
- }
- function custom_columns($column)
- {
- global $post;
- switch ($column)
- {
- case "idealien_mgr_position":
- echo get_post_meta($post->ID, "idealien_mgr_position", "true");
- break;
- case "thumbnail":
- $width = (int) 60;
- $height = (int) 60;
- $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
- $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
- if ( isset($thumb) && $thumb )
- {
- echo $thumb;
- } else {
- echo __('None');
- }
- break;
- }
- }
- function admin_init()
- {
- // Custom meta boxes for the edit reservation screen
- add_meta_box("idealienManager-meta", "Manager Details", array(&$this, "meta_options"), "manager", "normal", "high");
- }
- // Admin post meta contents
- function meta_options()
- {
- //include_once('helpers.php');
- global $post;
- $custom = get_post_custom($post->ID);
- $position = $custom["idealien_mgr_position"][0];
- $quote = $custom["idealien_mgr_quote"][0];
- $education = $custom["idealien_mgr_education"][0];
- $background = $custom["idealien_mgr_background"][0];
- $involvement = $custom["idealien_mgr_involvement"][0];
- ?>
- <style type="text/css">
- label.mgr {
- width: 15em;
- float: left;
- text-align: right;
- margin-right: 0.5em;
- display: block
- }
- span.addInfo {
- margin-left: 15.5em;
- font-style: italic;
- }
- .mgr_inputLine {
- width: 70%;
- }
- .mgr_inputBox {
- width: 75%;
- height: 7em;
- }
- </style>
- <p>
- <label class="mgr">Position:</label>
- <input name="idealien_mgr_position" class="mgr_inputLine" value="<?php echo $position; ?>" /><br />
- <span class="addInfo">What is their role in the company?</span>
- </p>
- <p>
- <label class="mgr">Quote:</label>
- <textarea name="idealien_mgr_quote" class="mgr_inputBox"><?php echo $quote; ?></textarea><br />
- <span class="addInfo">Do they have any inspired words of wisdom to share?</span>
- </p>
- <p>
- <label class="mgr">Education:</label>
- <textarea name="idealien_mgr_education" class="mgr_inputBox"><?php echo $education; ?></textarea>
- <span class="addInfo">Put each education entry on a new line (bullets will be added in presentation layer) </span>
- </p>
- <p>
- <label class="mgr">Business Background:</label>
- <textarea name="idealien_mgr_background" class="mgr_inputBox"><?php echo $background; ?></textarea>
- <span class="addInfo">What did they do before joining the company?</span>
- </p>
- <p>
- <label class="mgr">Innovapost Involvement:</label>
- <textarea name="idealien_mgr_involvement" class="mgr_inputBox"><?php echo $involvement; ?></textarea>
- <span class="addInfo">What projects are they working on in their current role?</span>
- </p>
- <?php
- }
- // When a post is inserted or updated
- function wp_insert_post($post_id, $post = null)
- {
- // don't run this for quickedit
- if ( defined('DOING_AJAX') )
- return;
- if ($post->post_type == "manager")
- {
- // Loop through the POST data
- foreach ($this->meta_fields as $key)
- {
- $value = @$_POST[$key];
- if (empty($value))
- {
- delete_post_meta($post_id, $key);
- continue;
- }
- // If value is a string it should be unique
- if (!is_array($value))
- {
- // Update meta
- if (!update_post_meta($post_id, $key, $value))
- {
- // Or add the meta data
- add_post_meta($post_id, $key, $value);
- }
- }
- else
- {
- // If passed along is an array, we should remove all previous data
- delete_post_meta($post_id, $key);
- // Loop through the array adding new values to the post meta as different entries with the same name
- foreach ($value as $entry)
- add_post_meta($post_id, $key, $entry);
- }
- }
- }
- }
- // Template selection
- function template_redirect()
- {
- global $wp, $wp_query;
- if ($wp->query_vars["post_type"] == "manager" )
- {
- get_header();
- ?>
- <div id="container">
- <div id="content">
- <?php
- // Determine which kind of redirect we're doing and display the correct info in the layout
- if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
- <?php
- $width = (int) 60;
- $height = (int) 60;
- $thumbnail_id = get_post_meta( get_the_ID(), '_thumbnail_id', true );
- $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
- if ( isset($thumb) && $thumb )
- {
- echo "<div style='float: left;'>" . $thumb . "</div>";
- } ?>
- <strong><?php the_title(); ?></strong><br />
- <?php $custom = get_post_custom($post->ID);
- $position = $custom["idealien_mgr_position"][0];
- if($position ) { echo "Position: " . $position; }?>
- <div style="clear: both;"></div>
- <?php endwhile; else: ?>
- <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
- <?php endif; ?>
- </div><!-- #content -->
- </div><!-- #container -->
- <?php
- get_sidebar();
- get_footer();
- die();
- } // end if to determine if we're doing anything with this redirect
- }
- }
- // Initiate the plugin
- add_action("init", "Idealien_ManagerInit");
- function Idealien_ManagerInit() { global $idealienManager; $idealienManager = new Idealien_Manager(); }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement