function gllr_update_image()
 {
     global $wpdb;
     check_ajax_referer(plugin_basename(__FILE__), 'gllr_ajax_nonce_field');
     $action = isset($_REQUEST['action1']) ? $_REQUEST['action1'] : "";
     $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : "";
     switch ($action) {
         case 'get_all_attachment':
             $result_parent_id = $wpdb->get_results($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s", 'gallery'), ARRAY_N);
             $array_parent_id = array();
             while (list($key, $val) = each($result_parent_id)) {
                 $array_parent_id[] = $val[0];
             }
             $string_parent_id = implode(",", $array_parent_id);
             $result_attachment_id = $wpdb->get_results("SELECT `ID` FROM " . $wpdb->posts . " WHERE `post_type` = 'attachment' AND `post_mime_type` LIKE 'image%' AND `post_parent` IN (" . $string_parent_id . ")");
             echo json_encode($result_attachment_id);
             break;
         case 'update_image':
             $metadata = wp_get_attachment_metadata($id);
             $uploads = wp_upload_dir();
             $path = $uploads['basedir'] . "/" . $metadata['file'];
             require_once ABSPATH . 'wp-admin/includes/image.php';
             $metadata_new = gllr_wp_generate_attachment_metadata($id, $path, $metadata);
             wp_update_attachment_metadata($id, array_merge($metadata, $metadata_new));
             break;
         case 'update_options':
             add_option('gllr_images_update', '1', '', 'no');
             break;
     }
     die;
 }
Пример #2
0
 function gllr_update_image()
 {
     global $wpdb;
     check_ajax_referer(plugin_basename(__FILE__), 'gllr_ajax_nonce_field');
     $action = isset($_REQUEST['action1']) ? $_REQUEST['action1'] : "";
     $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : "";
     switch ($action) {
         case 'get_all_attachment':
             $result_parent_id = $wpdb->get_results($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE `post_type` = %s", 'gallery'), ARRAY_N);
             $array_parent_id = array();
             while (list($key, $val) = each($result_parent_id)) {
                 $array_parent_id[] = $val[0];
             }
             $string_parent_id = implode(",", $array_parent_id);
             $metas = $wpdb->get_results($wpdb->prepare("SELECT `meta_value` FROM {$wpdb->postmeta} WHERE `meta_key` = %s AND `post_id` IN (" . $string_parent_id . ")", '_gallery_images'), ARRAY_A);
             $result_attachment_id = '';
             foreach ($metas as $key => $value) {
                 if (!empty($value['meta_value'])) {
                     $result_attachment_id .= $value['meta_value'] . ',';
                 }
             }
             $result_attachment_id_array = explode(",", rtrim($result_attachment_id, ','));
             echo json_encode(array_unique($result_attachment_id_array));
             break;
         case 'update_image':
             $metadata = wp_get_attachment_metadata($id);
             $uploads = wp_upload_dir();
             $path = $uploads['basedir'] . "/" . $metadata['file'];
             require_once ABSPATH . 'wp-admin/includes/image.php';
             $metadata_new = gllr_wp_generate_attachment_metadata($id, $path, $metadata);
             wp_update_attachment_metadata($id, array_merge($metadata, $metadata_new));
             break;
     }
     die;
 }