get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'k2-header-image'"); foreach ($attachment_ids as $id) { $images[] = get_attached_file($id); } return $images; } function random_picture() { $picture_files = K2Header::get_header_images(); $size = count($picture_files); if ($size > 1) { return ($picture_files[rand(0, $size - 1)]); } else { return $picture_files[0]; } } function output_header_css() { if ( 'random' == get_theme_mod('header_image') ) { $picture = K2Header::random_picture(); } else { $picture = get_theme_mod('header_image'); } ?> post_mime_type = 'image/' . $mime; $attachment->post_excerpt = sprintf( __('Custom Header Image for K2 (%1$d x %2$d)', 'k2_domain'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); // Update the attachment $id = wp_insert_attachment( $attachment, $source ); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $source ) ); } // Allows K2 to find the attachment add_post_meta( $id, 'k2-header-image', 'original' ); } elseif ( 3 == $_GET['step'] ) { if ( get_wp_version() < 2.4 ) { // Get original attachment $parent = get_post( $_POST['attachment_id'] ); $parent_url = $parent->guid; $url = str_replace(basename($parent_url), basename($source), $parent_url); // Construct the object array $object = array( 'post_title' => basename($source), 'post_content' => $url, 'post_excerpt' => sprintf( __('Custom Header Image for K2 (%1$d x %2$d)', 'k2_domain'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ), 'post_mime_type' => 'image/jpeg', 'guid' => $url ); // Create a new attachment $id = wp_insert_attachment( $object, $source ); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $source ) ); } // Allows K2 to find the attachment add_post_meta( $id, 'k2-header-image', 'cropped' ); } } return $source; } } add_action('k2_init', array('K2Header', 'init'), 11); //add_action('k2_install', array('K2Header', 'install')); add_action('k2_uninstall', array('K2Header', 'uninstall')); add_action('wp_create_file_in_uploads', array('K2Header', 'process_custom_header_image'), 10, 2); add_filter('wp_create_file_in_uploads', array('K2Header', 'process_custom_header_image'), 10, 2); ?>