Advertisement
Guest User

WordPress Trac 12966

a guest
Apr 30th, 2010
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Idealien Manager Bios
  4. Plugin URI: http://idealienstudios.com
  5. Description: Add manager biography information to posts
  6. Author: Jamie Oastler
  7. Version: 0.1
  8. Author URI: http://idealienstudios.com
  9. */
  10.  
  11. class Idealien_Manager {
  12. var $meta_fields = array("idealien_mgr_position",
  13. "idealien_mgr_quote",
  14. "idealien_mgr_education",
  15. "idealien_mgr_background",
  16. "idealien_mgr_involvement");
  17.  
  18. function Idealien_Manager()
  19. {
  20. // Register custom post types
  21. register_post_type('manager', array(
  22. 'label' => __('Managers'),
  23. 'singular_label' => __('Manager'),
  24. 'public' => true,
  25. 'show_ui' => true, // UI in admin panel
  26. '_builtin' => false, // It's a custom post type, not built in
  27. '_edit_link' => 'post.php?post=%d',
  28. 'capability_type' => 'post',
  29. 'hierarchical' => false,
  30. 'rewrite' => array("slug" => "manager"), // Permalinks
  31. 'query_var' => "manager", // This goes to the WP_Query schema
  32. 'supports' => array('title' ,'author', 'thumbnail'/*'excerpt', 'editor' ,'custom-fields'*/) // Let's use custom fields for debugging purposes only
  33. ));
  34.  
  35. add_filter("manage_edit-manager_columns", array(&$this, "edit_columns"));
  36. add_action("manage_posts_custom_column", array(&$this, "custom_columns"));
  37.  
  38. // Admin interface init
  39. add_action("admin_init", array(&$this, "admin_init"));
  40. add_action("template_redirect", array(&$this, 'template_redirect'));
  41.  
  42. // Insert post hook
  43. add_action("wp_insert_post", array(&$this, "wp_insert_post"), 10, 2);
  44.  
  45. //End Idealien_Manager constructor function
  46. }
  47.  
  48. function edit_columns($columns)
  49. {
  50. $columns = array(
  51. "cb" => "<input type=\"checkbox\" />",
  52. "title" => "Manager",
  53. "idealien_mgr_position" => "Position",
  54. "thumbnail" => "Photo",
  55. "date"=>"Date"
  56. );
  57.  
  58. return $columns;
  59. }
  60.  
  61. function custom_columns($column)
  62. {
  63. global $post;
  64. switch ($column)
  65. {
  66. case "idealien_mgr_position":
  67. echo get_post_meta($post->ID, "idealien_mgr_position", "true");
  68. break;
  69. case "thumbnail":
  70. $width = (int) 60;
  71. $height = (int) 60;
  72. $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
  73. $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
  74. if ( isset($thumb) && $thumb )
  75. {
  76. echo $thumb;
  77. } else {
  78. echo __('None');
  79. }
  80. break;
  81. }
  82. }
  83.  
  84. function admin_init()
  85. {
  86. // Custom meta boxes for the edit reservation screen
  87. add_meta_box("idealienManager-meta", "Manager Details", array(&$this, "meta_options"), "manager", "normal", "high");
  88. }
  89.  
  90. // Admin post meta contents
  91. function meta_options()
  92. {
  93. //include_once('helpers.php');
  94. global $post;
  95. $custom = get_post_custom($post->ID);
  96. $position = $custom["idealien_mgr_position"][0];
  97. $quote = $custom["idealien_mgr_quote"][0];
  98. $education = $custom["idealien_mgr_education"][0];
  99. $background = $custom["idealien_mgr_background"][0];
  100. $involvement = $custom["idealien_mgr_involvement"][0];
  101. ?>
  102.  
  103. <style type="text/css">
  104. label.mgr {
  105. width: 15em;
  106. float: left;
  107. text-align: right;
  108. margin-right: 0.5em;
  109. display: block
  110. }
  111.  
  112. span.addInfo {
  113. margin-left: 15.5em;
  114. font-style: italic;
  115. }
  116.  
  117. .mgr_inputLine {
  118. width: 70%;
  119. }
  120.  
  121. .mgr_inputBox {
  122. width: 75%;
  123. height: 7em;
  124. }
  125. </style>
  126.  
  127. <p>
  128. <label class="mgr">Position:</label>
  129. <input name="idealien_mgr_position" class="mgr_inputLine" value="<?php echo $position; ?>" /><br />
  130. <span class="addInfo">What is their role in the company?</span>
  131. </p>
  132.  
  133. <p>
  134. <label class="mgr">Quote:</label>
  135. <textarea name="idealien_mgr_quote" class="mgr_inputBox"><?php echo $quote; ?></textarea><br />
  136. <span class="addInfo">Do they have any inspired words of wisdom to share?</span>
  137. </p>
  138.  
  139.  
  140. <p>
  141. <label class="mgr">Education:</label>
  142. <textarea name="idealien_mgr_education" class="mgr_inputBox"><?php echo $education; ?></textarea>
  143. <span class="addInfo">Put each education entry on a new line (bullets will be added in presentation layer) </span>
  144. </p>
  145.  
  146. <p>
  147. <label class="mgr">Business Background:</label>
  148. <textarea name="idealien_mgr_background" class="mgr_inputBox"><?php echo $background; ?></textarea>
  149. <span class="addInfo">What did they do before joining the company?</span>
  150. </p>
  151.  
  152. <p>
  153. <label class="mgr">Innovapost Involvement:</label>
  154. <textarea name="idealien_mgr_involvement" class="mgr_inputBox"><?php echo $involvement; ?></textarea>
  155. <span class="addInfo">What projects are they working on in their current role?</span>
  156. </p>
  157.  
  158. <?php
  159. }
  160.  
  161. // When a post is inserted or updated
  162. function wp_insert_post($post_id, $post = null)
  163. {
  164. // don't run this for quickedit
  165. if ( defined('DOING_AJAX') )
  166. return;
  167. if ($post->post_type == "manager")
  168. {
  169.  
  170. // Loop through the POST data
  171. foreach ($this->meta_fields as $key)
  172. {
  173. $value = @$_POST[$key];
  174. if (empty($value))
  175. {
  176. delete_post_meta($post_id, $key);
  177. continue;
  178. }
  179.  
  180. // If value is a string it should be unique
  181. if (!is_array($value))
  182. {
  183.  
  184. // Update meta
  185. if (!update_post_meta($post_id, $key, $value))
  186. {
  187. // Or add the meta data
  188. add_post_meta($post_id, $key, $value);
  189. }
  190. }
  191. else
  192. {
  193. // If passed along is an array, we should remove all previous data
  194. delete_post_meta($post_id, $key);
  195.  
  196. // Loop through the array adding new values to the post meta as different entries with the same name
  197. foreach ($value as $entry)
  198. add_post_meta($post_id, $key, $entry);
  199. }
  200. }
  201. }
  202. }
  203.  
  204. // Template selection
  205. function template_redirect()
  206. {
  207. global $wp, $wp_query;
  208.  
  209. if ($wp->query_vars["post_type"] == "manager" )
  210. {
  211. get_header();
  212. ?>
  213. <div id="container">
  214. <div id="content">
  215. <?php
  216. // Determine which kind of redirect we're doing and display the correct info in the layout
  217.  
  218. if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  219.  
  220. <?php
  221. $width = (int) 60;
  222. $height = (int) 60;
  223. $thumbnail_id = get_post_meta( get_the_ID(), '_thumbnail_id', true );
  224. $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
  225. if ( isset($thumb) && $thumb )
  226. {
  227. echo "<div style='float: left;'>" . $thumb . "</div>";
  228. } ?>
  229. <strong><?php the_title(); ?></strong><br />
  230. <?php $custom = get_post_custom($post->ID);
  231. $position = $custom["idealien_mgr_position"][0];
  232. if($position ) { echo "Position: " . $position; }?>
  233. <div style="clear: both;"></div>
  234.  
  235. <?php endwhile; else: ?>
  236. <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  237. <?php endif; ?>
  238. </div><!-- #content -->
  239. </div><!-- #container -->
  240. <?php
  241. get_sidebar();
  242. get_footer();
  243.  
  244. die();
  245. } // end if to determine if we're doing anything with this redirect
  246. }
  247. }
  248.  
  249. // Initiate the plugin
  250. add_action("init", "Idealien_ManagerInit");
  251. function Idealien_ManagerInit() { global $idealienManager; $idealienManager = new Idealien_Manager(); }
  252. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement