Last active
August 29, 2015 14:02
-
-
Save norcross/df2381dcfff55de95982 to your computer and use it in GitHub Desktop.
code to fix shit for WPEC gallery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wpsc_update_product_gallery_tab(obj){ | |
var output; | |
output = '<div id="wpsc_product_gallery">'; | |
output += '<ul>'; | |
for (var i = 0; i < obj.length; i++){ | |
output += '<li>'; | |
output += '<img src="' + obj[i].sizes.thumbnail.url + '">'; | |
output += '<input type="hidden" name="wpsc-product-gallery-imgs[]" value="' + obj[i].id + '">'; // new item to include hidden field with ID | |
output += '</li>'; | |
} | |
output += '</ul>'; | |
output += '<div class="clear"></div>'; | |
output += '</div>'; | |
jQuery('#wpsc_product_gallery').replaceWith(output); | |
wpsc_update_product_details_metabox_live_title(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* We really need to either bake this functionality in for 3.9.0 or rip it out into Gold Cart or something else. | |
* So not awesome to have this exposed and unusable. | |
* | |
* @param WP_Post $post Product | |
* @return void | |
*/ | |
function wpsc_product_gallery( $post ) { | |
$upload_iframe_src = esc_url( get_upload_iframe_src( 'image', $post->ID ) ); | |
$images = wpsc_get_admin_product_gallery( $post->ID ); // new function call to get images from meta field | |
$output = '<div id="wpsc_product_gallery">'; | |
$output .= '<ul>'; | |
if ( $images ) { | |
foreach ( $images as $image_id ) { | |
$output .= '<li>'; | |
$output .= '<img src="' . wp_get_attachment_thumb_url( absint( $image_id ) ) . '">'; | |
$output .= '<input type="hidden" name="wpsc-product-gallery-imgs[]" value="' . absint( $image_id ) . '">'; // new item to include hidden field with ID | |
$output .= '</li>'; | |
} | |
} | |
$output .= '</ul>'; | |
$output .= '<div class="clear"></div>'; | |
$output .= '</div>'; | |
$output .= '<p class="hide-if-no-js">'; | |
$output .= '<a class="button button-small thickbox" title="' . esc_attr__( 'Manage Product Image Gallery...', 'wpsc' ).'" href="' . $upload_iframe_src . '" id="wpsc-manage-product-gallery">'; | |
$output .= esc_html__( 'Manage Product Image Gallery...', 'wpsc' ); | |
$output .= '</a>'; | |
$output .= '</p>'; | |
echo $output; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//****************************************************************************************** | |
// start the engine | |
//****************************************************************************************** | |
jQuery(document).ready( function($) { | |
//****************************************************************************************** | |
// make the image gallery drag / drop / sort | |
//****************************************************************************************** | |
$( 'div#wpsc_product_gallery' ).each(function() { | |
$( this ).find( 'ul' ).sortable({ | |
cursor: 'move', | |
revert: 300, | |
}).disableSelection(); | |
}); | |
//****************************************************************************************** | |
// we are done here. go home | |
//****************************************************************************************** | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* call my functions */ | |
add_action ( 'save_post', 'wpec_new_gallery_save' ); | |
add_action ( 'admin_enqueue_scripts', 'wpec_new_gallery_script' ); | |
/** | |
* [wpec_new_gallery_save description] | |
* @param [type] $post_id [description] | |
* @return [type] [description] | |
*/ | |
function wpec_new_gallery_save( $post_id ) { | |
// make sure we aren't using autosave | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
return $post_id; | |
} | |
// run our post type check | |
if ( 'wpsc-product' !== get_post_type( $post_id ) ) { | |
return $post_id; | |
} | |
// and make sure the user has the ability to do shit | |
if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
return $post_id; | |
} | |
// all clear. get data via $_POST and cast as an array | |
if ( ! empty( $_POST['wpsc-product-gallery-imgs'] ) ) { | |
$image_ids = (array) $_POST['wpsc-product-gallery-imgs']; | |
update_post_meta( $post_id, '_wpsc_product_gallery', $image_ids ); | |
} else { | |
delete_post_meta( $post_id, '_wpsc_product_gallery' ); | |
} | |
} | |
/** | |
* [wpec_new_gallery_script description] | |
* @param [type] $hook [description] | |
* @return [type] [description] | |
*/ | |
function wpec_new_gallery_script( $hook ) { | |
$screen = get_current_screen(); | |
// load media on individual items | |
if ( is_object( $screen ) && $screen->base == 'post' && $screen->post_type == 'wpsc-product' ) { | |
wp_enqueue_script( 'wpec-fix-shit', plugins_url('js/wpec-fix-shit.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable' ), null, true ); | |
} | |
} | |
/** | |
* [wpsc_get_admin_product_gallery description] | |
* @param integer $post_id [description] | |
* @return [type] [description] | |
*/ | |
function wpsc_get_admin_product_gallery( $post_id = 0 ) { | |
$meta = get_post_meta( $post_id, '_wpsc_product_gallery', true ); | |
// no custom gallery was created, so return nothing | |
if ( ! $meta ) { | |
return; | |
} | |
// now make sure the IDs present are actual images | |
foreach( $meta as $key => $image_id ) { | |
if ( get_post_type( $image_id ) !== 'attachment' ) { | |
unset( $meta[$key] ); | |
} | |
} | |
// send it back | |
if ( ! empty( $meta ) ) { | |
return $meta; | |
} | |
// nothing left. | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## notes regarding changes made to WPEC core files ## | |
#### wpsc-admin/js/admin.js | |
* line 574: added hidden field to output | |
#### wpsc-admin/includes/display-items-functions.php | |
* line 883: used new wpsc_get_admin_product_gallery function | |
* line 891: added hidden field with output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
may be worth adding a small amount of CSS for the image hovering and also possibly an ajax call to update the gallery meta when dragging is complete.