Upfront data base64encoded in db. How to change images?

How to change images in Upfront theme installed on a site via database since the data is base64 encoded?
We're managing a lot of sites that are being built locally by the developers and moved online so URLs are pointing to the "dev" sites instead of "live" sites and we cannot edit all the images and resources manually on each site via Upfront Editor.

  • Ivan

    Hi David Harris !

    You could try adding the following snippet in a MU plugin ( more info about MU plugins is here )

    function wpmu_upfront_change_domain() {
    	$old_domain = 'http://domain.com';
    	$new_domain = 'https://new-domain.net';
    	$old_domain = str_replace( '"', '', json_encode( $old_domain ) );
    	$new_domain = str_replace( '"', '', json_encode( $new_domain ) );
    	$search[] = $old_domain;
    	$search[] = str_replace( array( 'http:', 'https:' ), '', $old_domain );
    	$replace[] = $new_domain;
    	$replace[] = str_replace( array( 'http:', 'https:' ), '', $new_domain );
    	global $wpdb;
    	$options = $wpdb->get_results( "SELECT option_id, option_value FROM {$wpdb->options} WHERE option_name like 'uf-%'", ARRAY_A );
    	foreach ( $options as $option ) {
    		$new_value = str_replace( $search, $replace, $option['option_value'] );
    		if ( $option['option_value'] != $new_value ) {
    			$wpdb->update( $wpdb->options, array( 'option_value' => $new_value ), array( 'option_id' => $option['option_id'] ) );
    add_action( 'plugins_loaded', 'wpmu_upfront_change_domain' );

    Note: you should replace $old_domain and $new_domain variables to your current domains.
    NOTE: you should create backup before adding this snippet to your site.
    After adding this MU plugin - open any page of your site, then delete the MU plugin and check URLs for images.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.