Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save johnleblanc/28294471dbc5c74a8fb8 to your computer and use it in GitHub Desktop.
Update NextGEN Gallery 2.0.53 Lightbox Paths (CSS, JS and Images) Find lightbox_library post_type within WP Posts table
<?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://www.example.com' );
define( 'YOUR_OLD_SITE_ROOT', 'http://staging.example.com' );
/*** When the results have been confirmed, change this to true to modify data. ***/
define( 'MAKE_CHANGES_TO_SITE', FALSE );
define( 'FIX_CSS_AND_JS', 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';
$css = (string) $data->css_stylesheets;
$js = (string) $data->scripts;
$find = (string) YOUR_OLD_SITE_ROOT;
$replace = (string) YOUR_SITE_ROOT;
if ( FIX_CSS_AND_JS ) {
// Search/Replace CSS and JS References
$data->css_stylesheets = str_replace($find, $replace, $css);
$data->scripts = str_replace($find, $replace, $js);
}
$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 );
}
@johnleblanc
Copy link
Author

Assumes standard WP_PLUGIN_URL (Global Find/Replace within the dB is a much better fix)
I have duplicates within my lightbox_library custom post types, but won't bother researching where they came from yet.

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