Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: wp_create_file_in_uploads

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 3 times in this file.

Line Code
349           $id = wp_insert_attachment($object, $file);
350
351           list($width, $height, $type, $attr) = getimagesize( $file );
352
353           if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
354                // Add the meta-data
355                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
356
357                set_theme_mod('header_image', esc_url($url));
358                do_action('wp_create_file_in_uploads', $file, $id); // For replication
359                return $this->finished();
360           } elseif ( $width > HEADER_IMAGE_WIDTH ) {
361                $oitar = $width / HEADER_IMAGE_WIDTH;
362                $image = wp_crop_image($file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
363                $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
364
365                $url = str_replace(basename($url), basename($image), $url);
366                $width = $width / $oitar;
367                $height = $height / $oitar;
368           } else {
369                $oitar = 1;
370           }
371           ?>
372
 
Line Code
408                $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
409                $_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
410                $_POST['width'] = $_POST['width'] * $_POST['oitar'];
411                $_POST['height'] = $_POST['height'] * $_POST['oitar'];
412           }
413
414           $original = get_attached_file( $_POST['attachment_id'] );
415
416           $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);
417           $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication
418
419           $parent = get_post($_POST['attachment_id']);
420           $parent_url = $parent->guid;
421           $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
422
423           // Construct the object array
424           $object = array(
425                'ID' => $_POST['attachment_id'],
426                'post_title' => basename($cropped),