| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Fruitb Clients |
|---|
| 4 | Plugin URI: http://www.fruitbowlmedia.com |
|---|
| 5 | Description: Adds ability to manage 'Clients' |
|---|
| 6 | Author: Fruitbowl Media |
|---|
| 7 | Version: 1.0 |
|---|
| 8 | Author URI: http://www.fruitbowlmedia.com |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | class Fruitb_Clients { |
|---|
| 12 | var $meta_fields = array("fruitb-clients-website", "fruitb-clients-logo", "fruitb-clients-screens", "fruitb-clients-thumbnail", "fruitb-clients-quote"); // add more depending on meta fields. This saves time later |
|---|
| 13 | |
|---|
| 14 | function Fruitb_Clients() |
|---|
| 15 | { |
|---|
| 16 | // Register custom post types |
|---|
| 17 | register_post_type('client', array( |
|---|
| 18 | 'label' => __('Clients'), |
|---|
| 19 | 'singular_label' => __('Client'), |
|---|
| 20 | 'public' => true, |
|---|
| 21 | 'show_ui' => true, // UI in admin panel |
|---|
| 22 | '_builtin' => false, // It's a custom post type, not built in |
|---|
| 23 | '_edit_link' => 'post.php?post=%d', |
|---|
| 24 | 'capability_type' => 'post', |
|---|
| 25 | 'hierarchical' => false, |
|---|
| 26 | 'rewrite' => array("slug" => "client"), // Permalinks |
|---|
| 27 | 'query_var' => "client", // This goes to the WP_Query schema |
|---|
| 28 | 'supports' => array('title', 'editor', 'excerpt', 'revisions' /*,'custom-fields'*/) // Let's use custom fields for debugging purposes only |
|---|
| 29 | )); |
|---|
| 30 | |
|---|
| 31 | add_filter("manage_edit-client_columns", array(&$this, "edit_columns")); |
|---|
| 32 | add_action("manage_posts_custom_column", array(&$this, "custom_columns")); |
|---|
| 33 | |
|---|
| 34 | // Register custom taxonomy |
|---|
| 35 | //register_taxonomy("type", array("sponsor"), array("hierarchical" => true, "label" => "Sponsor Types", "singular_label" => "Sponsor Type", "rewrite" => true)); |
|---|
| 36 | |
|---|
| 37 | // Admin interface init |
|---|
| 38 | add_action("admin_init", array(&$this, "admin_init")); |
|---|
| 39 | add_action("template_redirect", array(&$this, 'template_redirect')); |
|---|
| 40 | |
|---|
| 41 | // Insert post hook |
|---|
| 42 | add_action("wp_insert_post", array(&$this, "wp_insert_post"), 10, 2); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | function edit_columns($columns) |
|---|
| 46 | { |
|---|
| 47 | $columns = array( |
|---|
| 48 | "cb" => "<input type=\"checkbox\" />", |
|---|
| 49 | "title" => "Client Name", |
|---|
| 50 | "fruitb-clients-website" => "Website" |
|---|
| 51 | ); |
|---|
| 52 | |
|---|
| 53 | return $columns; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | function custom_columns($column) |
|---|
| 57 | { |
|---|
| 58 | global $post; |
|---|
| 59 | switch ($column) |
|---|
| 60 | { |
|---|
| 61 | case "fruitb-clients-website": |
|---|
| 62 | $custom = get_post_custom(); |
|---|
| 63 | echo $custom["fruitb-clients-website"][0]; |
|---|
| 64 | break; |
|---|
| 65 | /* For taxonomy |
|---|
| 66 | case "fc_speakers_company": |
|---|
| 67 | $types = get_the_terms(0, "type"); |
|---|
| 68 | $types_html = array(); |
|---|
| 69 | if(is_array($types)) |
|---|
| 70 | { |
|---|
| 71 | foreach ($types as $t) |
|---|
| 72 | array_push($types_html, '<a href="' . get_term_link($t->slug, "type") . '">' . $t->name . '</a>'); |
|---|
| 73 | |
|---|
| 74 | echo implode($types_html, ", "); |
|---|
| 75 | } |
|---|
| 76 | break; |
|---|
| 77 | */ |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | // Template selection |
|---|
| 82 | function template_redirect() |
|---|
| 83 | { |
|---|
| 84 | global $wp; |
|---|
| 85 | if ($wp->query_vars["post_type"] == "client") |
|---|
| 86 | { |
|---|
| 87 | include(STYLESHEETPATH . "/client-single.php"); |
|---|
| 88 | die(); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // When a post is inserted or updated |
|---|
| 93 | function wp_insert_post($post_id, $post = null) |
|---|
| 94 | { |
|---|
| 95 | if ($post->post_type == "client") // you should only need to edit this line |
|---|
| 96 | { |
|---|
| 97 | // Loop through the POST data |
|---|
| 98 | foreach ($this->meta_fields as $key) |
|---|
| 99 | { |
|---|
| 100 | $value = @$_POST[$key]; |
|---|
| 101 | if (empty($value)) |
|---|
| 102 | { |
|---|
| 103 | delete_post_meta($post_id, $key); |
|---|
| 104 | continue; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | // If value is a string it should be unique |
|---|
| 110 | if (!is_array($value)) |
|---|
| 111 | { |
|---|
| 112 | // Update meta |
|---|
| 113 | if (!update_post_meta($post_id, $key, $value)) |
|---|
| 114 | { |
|---|
| 115 | // Or add the meta data |
|---|
| 116 | add_post_meta($post_id, $key, $value); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | else |
|---|
| 120 | { |
|---|
| 121 | // delete old |
|---|
| 122 | delete_post_meta($post_id, $key); |
|---|
| 123 | |
|---|
| 124 | update_post_meta($post_id, $key, $value); |
|---|
| 125 | |
|---|
| 126 | /* |
|---|
| 127 | // If passed along is an array, we should remove all previous data |
|---|
| 128 | delete_post_meta($post_id, $key); |
|---|
| 129 | |
|---|
| 130 | // Loop through the array adding new values to the post meta as different entries with the same name |
|---|
| 131 | foreach ($value as $entry) |
|---|
| 132 | add_post_meta($post_id, $key, $entry); |
|---|
| 133 | */ |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | function admin_init() |
|---|
| 141 | { |
|---|
| 142 | // Custom meta boxes for each meta field specified |
|---|
| 143 | add_meta_box("fruitb-clients-meta-website", "The Clients Website", array(&$this, "meta_options_website"), "client", "normal", "high"); |
|---|
| 144 | add_meta_box("fruitb-clients-meta-logo", "The Clients Company Logo", array(&$this, "meta_options_logo"), "client", "normal", "high"); |
|---|
| 145 | add_meta_box("fruitb-clients-meta-quote", "A Featured Quote From The Case Study To Feature In Large Bold Type", array(&$this, "meta_options_quote"), "client", "normal", "high"); |
|---|
| 146 | add_meta_box("fruitb-clients-meta-screens", "Screenshots For The Case Study", array(&$this, "meta_options_screens"), "client", "normal", "high"); |
|---|
| 147 | add_meta_box("fruitb-clients-meta-thumbnail", "Featured Homepage Thumbnail", array(&$this, "meta_options_thumbnail"), "client", "normal", "high"); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | // Admin post meta contents |
|---|
| 151 | function meta_options_website() |
|---|
| 152 | { |
|---|
| 153 | global $post; |
|---|
| 154 | $custom = get_post_custom($post->ID); |
|---|
| 155 | $val = $custom["fruitb-clients-website"][0]; |
|---|
| 156 | |
|---|
| 157 | ?> |
|---|
| 158 | <input name="fruitb-clients-website" value="<?php echo $val; ?>" type="text" style="width:100%" /> |
|---|
| 159 | <p>Enter the clients website, i.e. <em>http://www.acmewidgets.com</em></p> |
|---|
| 160 | |
|---|
| 161 | <?php |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | // Admin post meta contents |
|---|
| 165 | function meta_options_quote() |
|---|
| 166 | { |
|---|
| 167 | global $post; |
|---|
| 168 | $custom = get_post_custom($post->ID); |
|---|
| 169 | $val = $custom["fruitb-clients-quote"][0]; |
|---|
| 170 | |
|---|
| 171 | ?> |
|---|
| 172 | <input name="fruitb-clients-quote" value="<?php echo $val; ?>" type="text" style="width:100%" /> |
|---|
| 173 | <p>Enter a short (i.e. 1 sentence) quote from the case study text that will feature in large bold type on the case study page</p> |
|---|
| 174 | <p><strong>This is different to client testimonials, and you should still enter a separate <em>Testimonial</em> post from the client if possible</p> |
|---|
| 175 | |
|---|
| 176 | <?php |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | // Admin post meta contents |
|---|
| 180 | function meta_options_logo() |
|---|
| 181 | { |
|---|
| 182 | global $post; |
|---|
| 183 | $custom = get_post_custom($post->ID); |
|---|
| 184 | $val = $custom["fruitb-clients-logo"][0]; |
|---|
| 185 | |
|---|
| 186 | ?> |
|---|
| 187 | <input name="fruitb-clients-logo" value="<?php echo $val; ?>" type="text" style="width:100%" /> |
|---|
| 188 | <p>Enter the URL to the clients logo 150px x 120px, i.e. <em>http://www.fruitbowlmedia.com/wp-content/uploads/logo.jpg</em></p> |
|---|
| 189 | |
|---|
| 190 | <?php |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | // Admin post meta contents |
|---|
| 194 | function meta_options_thumbnail() |
|---|
| 195 | { |
|---|
| 196 | global $post; |
|---|
| 197 | $custom = get_post_custom($post->ID); |
|---|
| 198 | $val = $custom["fruitb-clients-thumbnail"][0]; |
|---|
| 199 | |
|---|
| 200 | ?> |
|---|
| 201 | <input name="fruitb-clients-thumbnail" value="<?php echo $val; ?>" type="text" style="width:100%" /> |
|---|
| 202 | <p>Enter the URL to a thumbnail for this case study (perhaps a funky collection of screenshots?) 300px x 200px, i.e. <em>http://www.fruitbowlmedia.com/wp-content/uploads/logo.jpg</em></p> |
|---|
| 203 | |
|---|
| 204 | <?php |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | // Admin post meta contents |
|---|
| 208 | function meta_options_screens() |
|---|
| 209 | { |
|---|
| 210 | global $post; |
|---|
| 211 | $custom = get_post_custom($post->ID); |
|---|
| 212 | $val = @unserialize($custom["fruitb-clients-screens"][0]); |
|---|
| 213 | ?> |
|---|
| 214 | |
|---|
| 215 | <p>Enter 3 sets of screenshots (with matching thumbnails) to showcase this case study. Thumbnails should be 210px x 158px and full size images should be 800px x 600px exactly</p> |
|---|
| 216 | <h4>Screenshot 1</h4> |
|---|
| 217 | <div style="width:50%; float:left;"> |
|---|
| 218 | <input name="fruitb-clients-screens[0][thumb]" value="<?php echo $val[0]['thumb']; ?>" type="text" style="width:90%" /> |
|---|
| 219 | <p>Thumb (210px x 158px)</p> |
|---|
| 220 | </div> |
|---|
| 221 | |
|---|
| 222 | <div style="width:50%; float:left;"> |
|---|
| 223 | <input name="fruitb-clients-screens[0][full]" value="<?php echo $val[0]['full']; ?>" type="text" style="width:90%" /> |
|---|
| 224 | <p>Full Size (800px x 600px)</p> |
|---|
| 225 | </div> |
|---|
| 226 | <br clear="both" /> |
|---|
| 227 | |
|---|
| 228 | <h4>Screenshot 2</h4> |
|---|
| 229 | <div style="width:50%; float:left;"> |
|---|
| 230 | <input name="fruitb-clients-screens[1][thumb]" value="<?php echo $val[1]['thumb']; ?>" type="text" style="width:90%" /> |
|---|
| 231 | <p>Thumb (210px x 158px)</p> |
|---|
| 232 | </div> |
|---|
| 233 | |
|---|
| 234 | <div style="width:50%; float:left;"> |
|---|
| 235 | <input name="fruitb-clients-screens[1][full]" value="<?php echo $val[1]['full']; ?>" type="text" style="width:90%" /> |
|---|
| 236 | <p>Full Size (800px x 600px)</p> |
|---|
| 237 | </div> |
|---|
| 238 | <br clear="both" /> |
|---|
| 239 | |
|---|
| 240 | <h4>Screenshot 3</h4> |
|---|
| 241 | <div style="width:50%; float:left;"> |
|---|
| 242 | <input name="fruitb-clients-screens[2][thumb]" value="<?php echo $val[2]['thumb']; ?>" type="text" style="width:90%" /> |
|---|
| 243 | <p>Thumb (210px x 158px)</p> |
|---|
| 244 | </div> |
|---|
| 245 | |
|---|
| 246 | <div style="width:50%; float:left;"> |
|---|
| 247 | <input name="fruitb-clients-screens[2][full]" value="<?php echo $val[2]['full']; ?>" type="text" style="width:90%" /> |
|---|
| 248 | <p>Full Size (800px x 600px)</p> |
|---|
| 249 | </div> |
|---|
| 250 | <br clear="both" /> |
|---|
| 251 | |
|---|
| 252 | <?php |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | // Initiate the plugin |
|---|
| 260 | add_action("init", "FruitbClientsInit"); |
|---|
| 261 | function FruitbClientsInit() { global $fruitb_clients; $fruitb_clients = new Fruitb_Clients(); } |
|---|