raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * The custom header image script.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * The custom header image class.
mp-wp_genesis 11 *
mp-wp_genesis 12 * @since unknown
mp-wp_genesis 13 * @package WordPress
mp-wp_genesis 14 * @subpackage Administration
mp-wp_genesis 15 */
mp-wp_genesis 16 class Custom_Image_Header {
mp-wp_genesis 17
mp-wp_genesis 18 /**
mp-wp_genesis 19 * Callback for administration header.
mp-wp_genesis 20 *
mp-wp_genesis 21 * @var callback
mp-wp_genesis 22 * @since unknown
mp-wp_genesis 23 * @access private
mp-wp_genesis 24 */
mp-wp_genesis 25 var $admin_header_callback;
mp-wp_genesis 26
mp-wp_genesis 27 /**
mp-wp_genesis 28 * PHP4 Constructor - Register administration header callback.
mp-wp_genesis 29 *
mp-wp_genesis 30 * @since unknown
mp-wp_genesis 31 * @param callback $admin_header_callback
mp-wp_genesis 32 * @return Custom_Image_Header
mp-wp_genesis 33 */
mp-wp_genesis 34 function Custom_Image_Header($admin_header_callback) {
mp-wp_genesis 35 $this->admin_header_callback = $admin_header_callback;
mp-wp_genesis 36 }
mp-wp_genesis 37
mp-wp_genesis 38 /**
mp-wp_genesis 39 * Setup the hooks for the Custom Header admin page.
mp-wp_genesis 40 *
mp-wp_genesis 41 * @since unknown
mp-wp_genesis 42 */
mp-wp_genesis 43 function init() {
mp-wp_genesis 44 $page = add_theme_page(__('Custom Image Header'), __('Custom Image Header'), 'edit_themes', 'custom-header', array(&$this, 'admin_page'));
mp-wp_genesis 45
mp-wp_genesis 46 add_action("admin_print_scripts-$page", array(&$this, 'js_includes'));
mp-wp_genesis 47 add_action("admin_print_styles-$page", array(&$this, 'css_includes'));
mp-wp_genesis 48 add_action("admin_head-$page", array(&$this, 'take_action'), 50);
mp-wp_genesis 49 add_action("admin_head-$page", array(&$this, 'js'), 50);
mp-wp_genesis 50 add_action("admin_head-$page", $this->admin_header_callback, 51);
mp-wp_genesis 51 }
mp-wp_genesis 52
mp-wp_genesis 53 /**
mp-wp_genesis 54 * Get the current step.
mp-wp_genesis 55 *
mp-wp_genesis 56 * @since unknown
mp-wp_genesis 57 *
mp-wp_genesis 58 * @return int Current step
mp-wp_genesis 59 */
mp-wp_genesis 60 function step() {
mp-wp_genesis 61 if ( ! isset( $_GET['step'] ) )
mp-wp_genesis 62 return 1;
mp-wp_genesis 63
mp-wp_genesis 64 $step = (int) $_GET['step'];
mp-wp_genesis 65 if ( $step < 1 || 3 < $step )
mp-wp_genesis 66 $step = 1;
mp-wp_genesis 67
mp-wp_genesis 68 return $step;
mp-wp_genesis 69 }
mp-wp_genesis 70
mp-wp_genesis 71 /**
mp-wp_genesis 72 * Setup the enqueue for the JavaScript files.
mp-wp_genesis 73 *
mp-wp_genesis 74 * @since unknown
mp-wp_genesis 75 */
mp-wp_genesis 76 function js_includes() {
mp-wp_genesis 77 $step = $this->step();
mp-wp_genesis 78
mp-wp_genesis 79 if ( 1 == $step )
mp-wp_genesis 80 wp_enqueue_script('farbtastic');
mp-wp_genesis 81 elseif ( 2 == $step )
mp-wp_genesis 82 wp_enqueue_script('cropper');
mp-wp_genesis 83 }
mp-wp_genesis 84
mp-wp_genesis 85 /**
mp-wp_genesis 86 * Setup the enqueue for the CSS files
mp-wp_genesis 87 *
mp-wp_genesis 88 * @since 2.7
mp-wp_genesis 89 */
mp-wp_genesis 90 function css_includes() {
mp-wp_genesis 91 $step = $this->step();
mp-wp_genesis 92
mp-wp_genesis 93 if ( 1 == $step ) {
mp-wp_genesis 94 wp_enqueue_style('farbtastic');
mp-wp_genesis 95 }
mp-wp_genesis 96 }
mp-wp_genesis 97
mp-wp_genesis 98 /**
mp-wp_genesis 99 * Execute custom header modification.
mp-wp_genesis 100 *
mp-wp_genesis 101 * @since unknown
mp-wp_genesis 102 */
mp-wp_genesis 103 function take_action() {
mp-wp_genesis 104 if ( isset( $_POST['textcolor'] ) ) {
mp-wp_genesis 105 check_admin_referer('custom-header');
mp-wp_genesis 106 if ( 'blank' == $_POST['textcolor'] ) {
mp-wp_genesis 107 set_theme_mod('header_textcolor', 'blank');
mp-wp_genesis 108 } else {
mp-wp_genesis 109 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['textcolor']);
mp-wp_genesis 110 if ( strlen($color) == 6 || strlen($color) == 3 )
mp-wp_genesis 111 set_theme_mod('header_textcolor', $color);
mp-wp_genesis 112 }
mp-wp_genesis 113 }
mp-wp_genesis 114 if ( isset($_POST['resetheader']) ) {
mp-wp_genesis 115 check_admin_referer('custom-header');
mp-wp_genesis 116 remove_theme_mods();
mp-wp_genesis 117 }
mp-wp_genesis 118 }
mp-wp_genesis 119
mp-wp_genesis 120 /**
mp-wp_genesis 121 * Execute Javascript depending on step.
mp-wp_genesis 122 *
mp-wp_genesis 123 * @since unknown
mp-wp_genesis 124 */
mp-wp_genesis 125 function js() {
mp-wp_genesis 126 $step = $this->step();
mp-wp_genesis 127 if ( 1 == $step )
mp-wp_genesis 128 $this->js_1();
mp-wp_genesis 129 elseif ( 2 == $step )
mp-wp_genesis 130 $this->js_2();
mp-wp_genesis 131 }
mp-wp_genesis 132
mp-wp_genesis 133 /**
mp-wp_genesis 134 * Display Javascript based on Step 1.
mp-wp_genesis 135 *
mp-wp_genesis 136 * @since unknown
mp-wp_genesis 137 */
mp-wp_genesis 138 function js_1() { ?>
mp-wp_genesis 139 <script type="text/javascript">
mp-wp_genesis 140 var buttons = ['#name', '#desc', '#pickcolor', '#defaultcolor'];
mp-wp_genesis 141 var farbtastic;
mp-wp_genesis 142
mp-wp_genesis 143 function pickColor(color) {
mp-wp_genesis 144 jQuery('#name').css('color', color);
mp-wp_genesis 145 jQuery('#desc').css('color', color);
mp-wp_genesis 146 jQuery('#textcolor').val(color);
mp-wp_genesis 147 farbtastic.setColor(color);
mp-wp_genesis 148 }
mp-wp_genesis 149
mp-wp_genesis 150 jQuery(document).ready(function() {
mp-wp_genesis 151 jQuery('#pickcolor').click(function() {
mp-wp_genesis 152 jQuery('#colorPickerDiv').show();
mp-wp_genesis 153 });
mp-wp_genesis 154
mp-wp_genesis 155 jQuery('#hidetext').click(function() {
mp-wp_genesis 156 toggle_text();
mp-wp_genesis 157 });
mp-wp_genesis 158
mp-wp_genesis 159 farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); });
mp-wp_genesis 160 pickColor('#<?php echo get_theme_mod('header_textcolor', HEADER_TEXTCOLOR); ?>');
mp-wp_genesis 161
mp-wp_genesis 162 <?php if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) ) { ?>
mp-wp_genesis 163 toggle_text();
mp-wp_genesis 164 <?php } ?>
mp-wp_genesis 165 });
mp-wp_genesis 166
mp-wp_genesis 167 jQuery(document).mousedown(function(){
mp-wp_genesis 168 // Make the picker disappear, since we're using it in an independant div
mp-wp_genesis 169 hide_picker();
mp-wp_genesis 170 });
mp-wp_genesis 171
mp-wp_genesis 172 function colorDefault() {
mp-wp_genesis 173 pickColor('#<?php echo HEADER_TEXTCOLOR; ?>');
mp-wp_genesis 174 }
mp-wp_genesis 175
mp-wp_genesis 176 function hide_picker(what) {
mp-wp_genesis 177 var update = false;
mp-wp_genesis 178 jQuery('#colorPickerDiv').each(function(){
mp-wp_genesis 179 var id = jQuery(this).attr('id');
mp-wp_genesis 180 if (id == what) {
mp-wp_genesis 181 return;
mp-wp_genesis 182 }
mp-wp_genesis 183 var display = jQuery(this).css('display');
mp-wp_genesis 184 if (display == 'block') {
mp-wp_genesis 185 jQuery(this).fadeOut(2);
mp-wp_genesis 186 }
mp-wp_genesis 187 });
mp-wp_genesis 188 }
mp-wp_genesis 189
mp-wp_genesis 190 function toggle_text(force) {
mp-wp_genesis 191 if(jQuery('#textcolor').val() == 'blank') {
mp-wp_genesis 192 //Show text
mp-wp_genesis 193 jQuery( buttons.toString() ).show();
mp-wp_genesis 194 jQuery('#textcolor').val('<?php echo HEADER_TEXTCOLOR; ?>');
mp-wp_genesis 195 jQuery('#hidetext').val('<?php _e('Hide Text'); ?>');
mp-wp_genesis 196 }
mp-wp_genesis 197 else {
mp-wp_genesis 198 //Hide text
mp-wp_genesis 199 jQuery( buttons.toString() ).hide();
mp-wp_genesis 200 jQuery('#textcolor').val('blank');
mp-wp_genesis 201 jQuery('#hidetext').val('<?php _e('Show Text'); ?>');
mp-wp_genesis 202 }
mp-wp_genesis 203 }
mp-wp_genesis 204
mp-wp_genesis 205
mp-wp_genesis 206
mp-wp_genesis 207 </script>
mp-wp_genesis 208 <?php
mp-wp_genesis 209 }
mp-wp_genesis 210
mp-wp_genesis 211 /**
mp-wp_genesis 212 * Display Javascript based on Step 2.
mp-wp_genesis 213 *
mp-wp_genesis 214 * @since unknown
mp-wp_genesis 215 */
mp-wp_genesis 216 function js_2() { ?>
mp-wp_genesis 217 <script type="text/javascript">
mp-wp_genesis 218 function onEndCrop( coords, dimensions ) {
mp-wp_genesis 219 jQuery( '#x1' ).val(coords.x1);
mp-wp_genesis 220 jQuery( '#y1' ).val(coords.y1);
mp-wp_genesis 221 jQuery( '#x2' ).val(coords.x2);
mp-wp_genesis 222 jQuery( '#y2' ).val(coords.y2);
mp-wp_genesis 223 jQuery( '#width' ).val(dimensions.width);
mp-wp_genesis 224 jQuery( '#height' ).val(dimensions.height);
mp-wp_genesis 225 }
mp-wp_genesis 226
mp-wp_genesis 227 // with a supplied ratio
mp-wp_genesis 228 jQuery(document).ready(function() {
mp-wp_genesis 229 var xinit = <?php echo HEADER_IMAGE_WIDTH; ?>;
mp-wp_genesis 230 var yinit = <?php echo HEADER_IMAGE_HEIGHT; ?>;
mp-wp_genesis 231 var ratio = xinit / yinit;
mp-wp_genesis 232 var ximg = jQuery('#upload').width();
mp-wp_genesis 233 var yimg = jQuery('#upload').height();
mp-wp_genesis 234 if ( yimg < yinit || ximg < xinit ) {
mp-wp_genesis 235 if ( ximg / yimg > ratio ) {
mp-wp_genesis 236 yinit = yimg;
mp-wp_genesis 237 xinit = yinit * ratio;
mp-wp_genesis 238 } else {
mp-wp_genesis 239 xinit = ximg;
mp-wp_genesis 240 yinit = xinit / ratio;
mp-wp_genesis 241 }
mp-wp_genesis 242 }
mp-wp_genesis 243 new Cropper.Img(
mp-wp_genesis 244 'upload',
mp-wp_genesis 245 {
mp-wp_genesis 246 ratioDim: { x: xinit, y: yinit },
mp-wp_genesis 247 displayOnInit: true,
mp-wp_genesis 248 onEndCrop: onEndCrop
mp-wp_genesis 249 }
mp-wp_genesis 250 )
mp-wp_genesis 251 });
mp-wp_genesis 252 </script>
mp-wp_genesis 253 <?php
mp-wp_genesis 254 }
mp-wp_genesis 255
mp-wp_genesis 256 /**
mp-wp_genesis 257 * Display first step of custom header image page.
mp-wp_genesis 258 *
mp-wp_genesis 259 * @since unknown
mp-wp_genesis 260 */
mp-wp_genesis 261 function step_1() {
mp-wp_genesis 262 if ( $_GET['updated'] ) { ?>
mp-wp_genesis 263 <div id="message" class="updated fade">
mp-wp_genesis 264 <p><?php _e('Header updated.') ?></p>
mp-wp_genesis 265 </div>
mp-wp_genesis 266 <?php } ?>
mp-wp_genesis 267
mp-wp_genesis 268 <div class="wrap">
mp-wp_genesis 269 <?php screen_icon(); ?>
mp-wp_genesis 270 <h2><?php _e('Your Header Image'); ?></h2>
mp-wp_genesis 271 <p><?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?></p>
mp-wp_genesis 272
mp-wp_genesis 273 <div id="headimg" style="background-image: url(<?php clean_url(header_image()) ?>);">
mp-wp_genesis 274 <h1><a onclick="return false;" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>" id="name"><?php bloginfo('name'); ?></a></h1>
mp-wp_genesis 275 <div id="desc"><?php bloginfo('description');?></div>
mp-wp_genesis 276 </div>
mp-wp_genesis 277 <?php if ( !defined( 'NO_HEADER_TEXT' ) ) { ?>
mp-wp_genesis 278 <form method="post" action="<?php echo admin_url('themes.php?page=custom-header&amp;updated=true') ?>">
mp-wp_genesis 279 <input type="button" value="<?php _e('Hide Text'); ?>" onclick="hide_text()" id="hidetext" />
mp-wp_genesis 280 <input type="button" value="<?php _e('Select a Text Color'); ?>" id="pickcolor" /><input type="button" value="<?php _e('Use Original Color'); ?>" onclick="colorDefault()" id="defaultcolor" />
mp-wp_genesis 281 <?php wp_nonce_field('custom-header') ?>
mp-wp_genesis 282 <input type="hidden" name="textcolor" id="textcolor" value="#<?php attribute_escape(header_textcolor()) ?>" /><input name="submit" type="submit" value="<?php _e('Save Changes'); ?>" /></form>
mp-wp_genesis 283 <?php } ?>
mp-wp_genesis 284
mp-wp_genesis 285 <div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"> </div>
mp-wp_genesis 286 </div>
mp-wp_genesis 287 <div class="wrap">
mp-wp_genesis 288 <h2><?php _e('Upload New Header Image'); ?></h2><p><?php _e('Here you can upload a custom header image to be shown at the top of your blog instead of the default one. On the next screen you will be able to crop the image.'); ?></p>
mp-wp_genesis 289 <p><?php printf(__('Images of exactly <strong>%1$d x %2$d pixels</strong> will be used as-is.'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); ?></p>
mp-wp_genesis 290
mp-wp_genesis 291 <form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo attribute_escape(add_query_arg('step', 2)) ?>" style="margin: auto; width: 50%;">
mp-wp_genesis 292 <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" />
mp-wp_genesis 293 <input type="hidden" name="action" value="save" />
mp-wp_genesis 294 <?php wp_nonce_field('custom-header') ?>
mp-wp_genesis 295 <p class="submit">
mp-wp_genesis 296 <input type="submit" value="<?php _e('Upload'); ?>" />
mp-wp_genesis 297 </p>
mp-wp_genesis 298 </form>
mp-wp_genesis 299
mp-wp_genesis 300 </div>
mp-wp_genesis 301
mp-wp_genesis 302 <?php if ( get_theme_mod('header_image') || get_theme_mod('header_textcolor') ) : ?>
mp-wp_genesis 303 <div class="wrap">
mp-wp_genesis 304 <h2><?php _e('Reset Header Image and Color'); ?></h2>
mp-wp_genesis 305 <p><?php _e('This will restore the original header image and color. You will not be able to retrieve any customizations.') ?></p>
mp-wp_genesis 306 <form method="post" action="<?php echo attribute_escape(add_query_arg('step', 1)) ?>">
mp-wp_genesis 307 <?php wp_nonce_field('custom-header'); ?>
mp-wp_genesis 308 <input type="submit" name="resetheader" value="<?php _e('Restore Original Header'); ?>" />
mp-wp_genesis 309 </form>
mp-wp_genesis 310 </div>
mp-wp_genesis 311 <?php endif;
mp-wp_genesis 312
mp-wp_genesis 313 }
mp-wp_genesis 314
mp-wp_genesis 315 /**
mp-wp_genesis 316 * Display second step of custom header image page.
mp-wp_genesis 317 *
mp-wp_genesis 318 * @since unknown
mp-wp_genesis 319 */
mp-wp_genesis 320 function step_2() {
mp-wp_genesis 321 check_admin_referer('custom-header');
mp-wp_genesis 322 $overrides = array('test_form' => false);
mp-wp_genesis 323 $file = wp_handle_upload($_FILES['import'], $overrides);
mp-wp_genesis 324
mp-wp_genesis 325 if ( isset($file['error']) )
mp-wp_genesis 326 die( $file['error'] );
mp-wp_genesis 327
mp-wp_genesis 328 $url = $file['url'];
mp-wp_genesis 329 $type = $file['type'];
mp-wp_genesis 330 $file = $file['file'];
mp-wp_genesis 331 $filename = basename($file);
mp-wp_genesis 332
mp-wp_genesis 333 // Construct the object array
mp-wp_genesis 334 $object = array(
mp-wp_genesis 335 'post_title' => $filename,
mp-wp_genesis 336 'post_content' => $url,
mp-wp_genesis 337 'post_mime_type' => $type,
mp-wp_genesis 338 'guid' => $url);
mp-wp_genesis 339
mp-wp_genesis 340 // Save the data
mp-wp_genesis 341 $id = wp_insert_attachment($object, $file);
mp-wp_genesis 342
mp-wp_genesis 343 list($width, $height, $type, $attr) = getimagesize( $file );
mp-wp_genesis 344
mp-wp_genesis 345 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
mp-wp_genesis 346 // Add the meta-data
mp-wp_genesis 347 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
mp-wp_genesis 348
mp-wp_genesis 349 set_theme_mod('header_image', clean_url($url));
mp-wp_genesis 350 do_action('wp_create_file_in_uploads', $file, $id); // For replication
mp-wp_genesis 351 return $this->finished();
mp-wp_genesis 352 } elseif ( $width > HEADER_IMAGE_WIDTH ) {
mp-wp_genesis 353 $oitar = $width / HEADER_IMAGE_WIDTH;
mp-wp_genesis 354 $image = wp_crop_image($file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
mp-wp_genesis 355 $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
mp-wp_genesis 356
mp-wp_genesis 357 $url = str_replace(basename($url), basename($image), $url);
mp-wp_genesis 358 $width = $width / $oitar;
mp-wp_genesis 359 $height = $height / $oitar;
mp-wp_genesis 360 } else {
mp-wp_genesis 361 $oitar = 1;
mp-wp_genesis 362 }
mp-wp_genesis 363 ?>
mp-wp_genesis 364
mp-wp_genesis 365 <div class="wrap">
mp-wp_genesis 366
mp-wp_genesis 367 <form method="POST" action="<?php echo attribute_escape(add_query_arg('step', 3)) ?>">
mp-wp_genesis 368
mp-wp_genesis 369 <p><?php _e('Choose the part of the image you want to use as your header.'); ?></p>
mp-wp_genesis 370 <div id="testWrap" style="position: relative">
mp-wp_genesis 371 <img src="<?php echo $url; ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
mp-wp_genesis 372 </div>
mp-wp_genesis 373
mp-wp_genesis 374 <p class="submit">
mp-wp_genesis 375 <input type="hidden" name="x1" id="x1" />
mp-wp_genesis 376 <input type="hidden" name="y1" id="y1" />
mp-wp_genesis 377 <input type="hidden" name="x2" id="x2" />
mp-wp_genesis 378 <input type="hidden" name="y2" id="y2" />
mp-wp_genesis 379 <input type="hidden" name="width" id="width" />
mp-wp_genesis 380 <input type="hidden" name="height" id="height" />
mp-wp_genesis 381 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo $id; ?>" />
mp-wp_genesis 382 <input type="hidden" name="oitar" id="oitar" value="<?php echo $oitar; ?>" />
mp-wp_genesis 383 <?php wp_nonce_field('custom-header') ?>
mp-wp_genesis 384 <input type="submit" value="<?php _e('Crop Header'); ?>" />
mp-wp_genesis 385 </p>
mp-wp_genesis 386
mp-wp_genesis 387 </form>
mp-wp_genesis 388 </div>
mp-wp_genesis 389 <?php
mp-wp_genesis 390 }
mp-wp_genesis 391
mp-wp_genesis 392 /**
mp-wp_genesis 393 * Display third step of custom header image page.
mp-wp_genesis 394 *
mp-wp_genesis 395 * @since unknown
mp-wp_genesis 396 */
mp-wp_genesis 397 function step_3() {
mp-wp_genesis 398 check_admin_referer('custom-header');
mp-wp_genesis 399 if ( $_POST['oitar'] > 1 ) {
mp-wp_genesis 400 $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
mp-wp_genesis 401 $_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
mp-wp_genesis 402 $_POST['width'] = $_POST['width'] * $_POST['oitar'];
mp-wp_genesis 403 $_POST['height'] = $_POST['height'] * $_POST['oitar'];
mp-wp_genesis 404 }
mp-wp_genesis 405
mp-wp_genesis 406 $original = get_attached_file( $_POST['attachment_id'] );
mp-wp_genesis 407
mp-wp_genesis 408 $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);
mp-wp_genesis 409 $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication
mp-wp_genesis 410
mp-wp_genesis 411 $parent = get_post($_POST['attachment_id']);
mp-wp_genesis 412 $parent_url = $parent->guid;
mp-wp_genesis 413 $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
mp-wp_genesis 414
mp-wp_genesis 415 // Construct the object array
mp-wp_genesis 416 $object = array(
mp-wp_genesis 417 'ID' => $_POST['attachment_id'],
mp-wp_genesis 418 'post_title' => basename($cropped),
mp-wp_genesis 419 'post_content' => $url,
mp-wp_genesis 420 'post_mime_type' => 'image/jpeg',
mp-wp_genesis 421 'guid' => $url
mp-wp_genesis 422 );
mp-wp_genesis 423
mp-wp_genesis 424 // Update the attachment
mp-wp_genesis 425 wp_insert_attachment($object, $cropped);
mp-wp_genesis 426 wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) );
mp-wp_genesis 427
mp-wp_genesis 428 set_theme_mod('header_image', $url);
mp-wp_genesis 429
mp-wp_genesis 430 // cleanup
mp-wp_genesis 431 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
mp-wp_genesis 432 @unlink( apply_filters( 'wp_delete_file', $medium ) );
mp-wp_genesis 433 @unlink( apply_filters( 'wp_delete_file', $original ) );
mp-wp_genesis 434
mp-wp_genesis 435 return $this->finished();
mp-wp_genesis 436 }
mp-wp_genesis 437
mp-wp_genesis 438 /**
mp-wp_genesis 439 * Display last step of custom header image page.
mp-wp_genesis 440 *
mp-wp_genesis 441 * @since unknown
mp-wp_genesis 442 */
mp-wp_genesis 443 function finished() {
mp-wp_genesis 444 ?>
mp-wp_genesis 445 <div class="wrap">
mp-wp_genesis 446 <h2><?php _e('Header complete!'); ?></h2>
mp-wp_genesis 447
mp-wp_genesis 448 <p><?php _e('Visit your site and you should see the new header now.'); ?></p>
mp-wp_genesis 449
mp-wp_genesis 450 </div>
mp-wp_genesis 451 <?php
mp-wp_genesis 452 }
mp-wp_genesis 453
mp-wp_genesis 454 /**
mp-wp_genesis 455 * Display the page based on the current step.
mp-wp_genesis 456 *
mp-wp_genesis 457 * @since unknown
mp-wp_genesis 458 */
mp-wp_genesis 459 function admin_page() {
mp-wp_genesis 460 $step = $this->step();
mp-wp_genesis 461 if ( 1 == $step )
mp-wp_genesis 462 $this->step_1();
mp-wp_genesis 463 elseif ( 2 == $step )
mp-wp_genesis 464 $this->step_2();
mp-wp_genesis 465 elseif ( 3 == $step )
mp-wp_genesis 466 $this->step_3();
mp-wp_genesis 467 }
mp-wp_genesis 468
mp-wp_genesis 469 }
mp-wp_genesis 470 ?>