public static function load_posts_callback() { global $wpdb; $_POST = stripslashes_deep($_POST); $post_id = intval($_POST['post_id']); $img = trim($_POST['img_name']); $opt_key = strtolower(trim($_POST['opt_key'])); $btn = preg_replace('/[_]+/i', ' ', $opt_key); $btn = ucwords($btn); $gotIt = false; if ($post_id && !empty($img) && !empty($opt_key)) { $fn = "display_{$opt_key}_list"; if (method_exists('MetaSeo_Image_List_Table', $fn)) { //Get list of posts contain this image and its clones $posts = ImageHelper::_get_post_list($post_id, $opt_key); if (count($posts) > 0) { $img_counter = 0; //Now the time to resize the images if ($opt_key === 'resize_image') { $upload_dir = wp_upload_dir(); $metaseo_sizes_optional = get_post_meta($post_id, '_metaseo_sizes_optional', TRUE); if (!is_array($metaseo_sizes_optional)) { $metaseo_sizes_optional = array(); } $attachment_meta_data = wp_get_attachment_metadata($post_id); foreach ($posts as &$post) { foreach ($post['img_after_optm'] as &$img) { $img_counter++; $destination = $upload_dir['basedir'] . '/' . $img['path']; if (@ImageHelper::IResize($img['src_origin'], $img['width'], $img['height'], $destination)) { $size = filesize($destination) / 1024; if ($size > 1024) { $size = $size / 1024; $sizes = 'MB'; } else { $sizes = 'KB'; } $size = @round($size, 1); $img['size'] = $size; $img['sizes'] = $sizes; } $kpart = ImageHelper::IGetPart($img['path']); $key = preg_replace('/\\-(\\d+)x(\\d+)$/i', '-metaseo${1}${2}', $kpart->name); $key = strtolower($key); $file = substr($img['path'], strrpos($img['path'], '/') + 1); if (!in_array($key, array_keys($metaseo_sizes_optional))) { $metaseo_sizes_optional[$key] = array('url' => $img['src'], 'width' => $img['width'], 'height' => $img['height'], 'orientation' => 'landscape'); } if (!isset($attachment_meta_data['sizes'][$key])) { $attachment_meta_data['sizes'][$key] = array('file' => $file, 'width' => $img['width'], 'height' => $img['height'], 'mime-type' => 'image/jpeg'); } } } wp_update_attachment_metadata($post_id, $attachment_meta_data); update_post_meta($post_id, '_metaseo_sizes_optional', $metaseo_sizes_optional); } elseif ($opt_key === 'fix_metas') { $toEdit = false; $pIDs = array(); foreach ($posts as $ID => &$post) { $img_counter += count($post['meta']); foreach ($post['meta'] as $order => $meta) { if ($meta['type']['alt'] == '' || $meta['type']['title'] == '') { $toEdit = true; } if ($meta['type']['alt'] != '' && $meta['type']['title'] != '') { $pIDs[$ID][] = $order; } } } if ($toEdit === true) { foreach ($pIDs as $ID => $orders) { foreach ($orders as $order) { unset($posts[$ID]['meta'][$order]); if ($img_counter > 0) { $img_counter--; } } if (empty($posts[$ID]['meta'])) { unset($posts[$ID]); } } } } //----------------------------- } } } //This is a bit crazy but could give more exact information if (count($posts) > 1) { $p = ' in ' . count($posts) . ' posts '; } else { $p = ''; } if (isset($img_counter) and $img_counter > 1) { $im = ' images '; } else { if (!isset($img_counter)) { $img_counter = 0; } $im = ' image '; } self::$fn($post_id, $posts, $img_counter, $p, $im); wp_die(); }