check_ajax('img_query_nonce', 'nonce'); $result = array(); $attachments = $_POST['attachments']; foreach ($attachments as $key=>$attach) { if ($attach == 0) $result[$key] = ""; else { $result[$key] = array(); $result[$key]['image'] = wp_get_attachment_image($attach); $result[$key]['img_info'] = $this->clean_output(wp_get_attachment_metadata($attach)); $result[$key]['img_path_dir'] = dirname(wp_get_attachment_image_src($attach)[0])."/"; } } echo json_encode($result); } exit(); } //Getting image alt through ajax public function get_image_alt_info(){ if (isset($_POST['alt_save_ajax'])) { $this->check_ajax('img_alt_query_nonce', 'nonce'); $result = array(); $attachments = $_POST['attachments']; foreach ($attachments as $key=>$attach) { if ($attach == 0) $result[$key] = ""; else { $result[$key] = ""; $swp = $this->wp_get_attachment($attach); $result[$key] = $swp['alt']; } } echo json_encode($result); } exit(); } //Clean and prepare data public function clean_output($data){ $result = ''; $last_key = array_reverse(array_keys($data['sizes']))[0]; foreach ($data['sizes'] as $key=>$size){ if ($last_key != $key)$delim="+"; else $delim=""; $result .= $size['width']."*".$size['file'].$delim; } return $result; } //Front attachment info public function wp_get_attachment( $attachment_id ) { $attachment = get_post( $attachment_id ); return array( 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), 'title' => $attachment->post_title ); } } ?>