static function replace_image_meta_info_temp_dir($gallery_id) { //Get the image IDs so we can start updating the wp_post and wp_post_meta tables $image_ids = WPPGPhotoGallery::get_gallery_image_ids($gallery_id); //Now cycle through each image_id (ie, post_id) foreach ($image_ids as $post_id) { //Get _wp_attachment_metadata $wp_attachment_meta_data = get_post_meta($post_id, '_wp_attachment_metadata'); $old_meta_data_string = $wp_attachment_meta_data[0]['file']; $new_meta_data_string = preg_replace('/' . WPPG_UPLOAD_TEMP_DIRNAME . '/', $gallery_id, $old_meta_data_string, 1); //Get _wp_attached_file $wp_attached_file = get_post_meta($post_id, '_wp_attached_file'); $old_post_meta_string = $wp_attached_file[0]; $new_post_meta_string = preg_replace('/' . WPPG_UPLOAD_TEMP_DIRNAME . '/', $gallery_id, $old_post_meta_string, 1); //Get post $post_info = get_post($post_id, ARRAY_A); $old_post_guid_string = $post_info['guid']; $new_post_guid_string = preg_replace('/' . WPPG_UPLOAD_TEMP_DIRNAME . '/', $gallery_id, $old_post_guid_string, 1); //Update _wp_attachment_metadata $wp_attachment_meta_data[0]['file'] = $new_meta_data_string; update_post_meta($post_id, '_wp_attachment_metadata', $wp_attachment_meta_data[0]); //Update _wp_attached_file $wp_attached_file[0] = $new_post_meta_string; update_post_meta($post_id, '_wp_attached_file', $wp_attached_file[0]); //Update post with new guid $post_info['guid'] = $new_post_guid_string; $res = wp_update_post($post_info, true); if (is_wp_error($res)) { //TODO } } }
function fetch_gallery_images($gallery_id, $orderby, $order) { global $wpdb; //$posts = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wppg_gallery_id' AND meta_value = $gallery_id" ); $gallery_image_ids_array = WPPGPhotoGallery::get_gallery_image_ids($gallery_id); $gallery_images_array = array(); foreach ($gallery_image_ids_array as $image_id) { $thumb_url = wp_get_attachment_thumb_url($image_id); $attachment_img = wp_get_attachment_image($image_id); $alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true); $image_post = get_post($image_id); $image_desc = $image_post->post_content; $upload_date = $image_post->post_date; //if the alt text meta is blank, let's set it to the image name if ($alt_text == '' || $alt_text == NULL) { $alt_text = $image_post->post_name; update_post_meta($image_id, '_wp_attachment_image_alt', $alt_text); //update the post_meta table } $image_info = array('id' => $image_id, 'thumb_url' => $thumb_url, 'alt_text' => $alt_text, 'description' => $image_desc, 'date_uploaded' => $upload_date); $gallery_images_array[] = $image_info; } //Let's take care of sorting $sortArray = array(); foreach ($gallery_images_array as $g_img) { $sortArray[] = $g_img[$orderby]; } //$sort_order = strtoupper('SORT_'.$order); if (strtoupper($order) == 'DESC') { array_multisort($sortArray, SORT_DESC, $gallery_images_array); } else { array_multisort($sortArray, SORT_ASC, $gallery_images_array); } return $gallery_images_array; }