Skip to content

Instantly share code, notes, and snippets.

@deltafactory
Created October 2, 2013 04:57
Show Gist options
  • Save deltafactory/6789297 to your computer and use it in GitHub Desktop.
Save deltafactory/6789297 to your computer and use it in GitHub Desktop.
Fix stored URLs for Lightbox assets in NextGEN Gallery 2.x. If you find that your lightbox images are missing or are pointing to the old location for the site, then this script will help.
<?php
/*
INSTRUCTIONS:
Use at your own risk. Backup your database before continuing.
1. Copy code to a file in the root of your website.
2. Change YOUR_SITE_ROOT to a value that makes sense.
3. Execute by visiting the page. Verify before/after results.
4. Change MAKE_CHANGES_TO_SITE to true and execute it again.
*/
/*** Change this to the URL of your Wordpress installation, without the trailing slash. ***/
define( 'YOUR_SITE_ROOT', 'http://yoursiteurl.com' );
/*** When the results have been confirmed, change this to true to modify data. ***/
define( 'MAKE_CHANGES_TO_SITE', false );
/*** No need to edit below here. ***/
require( 'wp-load.php' ); // Load the WordPress environment
header( 'Content-type: text/plain' ); // Set text output for easier debugging/readability.
fix_ngg_lightbox(); // Run the fix
function fix_ngg_lightbox() {
global $wpdb;
// Find the row in question, if it exists.
$post = $wpdb->get_row(
"SELECT ID, post_title, post_content
FROM $wpdb->posts
WHERE post_type='lightbox_library' AND post_title='lightbox'"
);
if ( !$post )
exit( 'Lightbox library post not found.' );
// Decode blob to proper object. Done twice to avoid shared reference.
$data_before = json_decode( base64_decode( $post->post_content ) );
$data = json_decode( base64_decode( $post->post_content ) );
$base_url = untrailingslashit( YOUR_SITE_ROOT );
$data->values->nextgen_lightbox_loading_img_url = $base_url . '/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/lightbox/static/jquery.lightbox/lightbox-ico-loading.gif';
$data->values->nextgen_lightbox_close_btn_url = $base_url . '/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/lightbox/static/jquery.lightbox/lightbox-btn-close.gif';
$data->values->nextgen_lightbox_btn_prev_url = $base_url . '/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/lightbox/static/jquery.lightbox/lightbox-btn-prev.gif';
$data->values->nextgen_lightbox_btn_next_url = $base_url . '/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/lightbox/static/jquery.lightbox/lightbox-btn-next.gif';
$data->values->nextgen_lightbox_blank_img_url = $base_url . '/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/lightbox/static/jquery.lightbox/lightbox-blank.gif';
$post_content = $post_content_filtered = base64_encode( json_encode( $data ) );
echo "\n\n";
if ( MAKE_CHANGES_TO_SITE ) {
$wpdb->update( $wpdb->posts, compact( 'post_content', 'post_content_filtered' ), array( 'ID' => $post->ID ) );
echo '*** Done.';
} else {
echo '*** No data is being changed. Verify the results and change the constant "MAKE_CHANGES_TO_SITE" to "true" and re-run the script to commit.';
}
echo "\n\n";
echo "Before:\n";
print_r( $data_before );
echo "\nAfter:\n";
print_r( $data );
}
@deltafactory
Copy link
Author

Thanks for the continued feedback guys. I'm sure it's helpful for others who discover this. It's too bad that Photocrati hasn't really felt it necessary to fix the problem within the plugin itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment