WordPress.org

Ready to get started?Download WordPress

Forums

Image Widget
Widgets disappears during a server change (7 posts)

  1. gmasson
    Member
    Posted 3 years ago #

    The widget's plugin disappears during a server change, I have no image widget in my sidebars.. any idea?

  2. FreestyleMD
    Member
    Posted 3 years ago #

    I just came here looking for the answer to the very same problem

  3. FreestyleMD
    Member
    Posted 3 years ago #

    I mnaged to get round the problem by updating all domain references except the ones for the image widget in the options table.

    Then, going through the dashboard to the widgets area I opened up each instance of the image widget and clicked save twice, which made the image re-appear. A quick check in the options table showed that the url of the image had been updated.

    If I tried to make this change directly in the table, then the widget would disappear completely from the widget area.

    Hopefully this will give someone enough clues to enable this to be sorted out a little more elegantly in future.?

  4. bknatterud
    Member
    Posted 2 years ago #

    I would really like to be able to update the links directly in the database without the widget disappearing. How can I do this? What am I missing or not updating correctly to make the widget disappear when updating the links directly in the database?

  5. cdmckay
    Member
    Posted 2 years ago #

    Ok, I figured out the problem. It has to do with how the PHP serialize() function works.

    Basically, your widget is stored in the wp_options table as a serialized array (the option_name for the Image Widget is widget_widget_sp_image). So, for example, here's how a string looks serialized:

    s:51:"http://localhost/example/wp-content/uploads/foo.png"

    Now, when you move to your production server, you typically do a mass replace of localhost/example with example.com. That changes the length of the above string from 51 to 45. But your search replace doesn't change that so you get this:

    s:51:"http://example.com/wp-content/uploads/foo.png"

    ...which can't be unserialized by the PHP unserialize() function. Thus, when WordPress tries to unserialize the content, unserialize fails and the widgets don't show. What's worse, if you go to the Widget area in the Admin, the Image Widget data is deleted.

    The solution is to count the number of characters in the new url, and update the string length:

    s:45:"http://example.com/wp-content/uploads/foo.png"

    I've tested this and it works.

  6. sillyname
    Member
    Posted 2 years ago #

    Great explanation, thank you.

    That explains why a simple search and replace fails and destroys the widget. Unfortunately if you are using say 50 of these widgets, all of them with different file names, then you have 50 different string lengths.

    May as well click the save button (once) on each widget, 50 clicks and you're done. To change the string values you must count (manually I assume) each instance, then change the value on each image url string.

    Unless, you have a code snippet that will count the array string and correct the the values automatically. I'd be very interested in that (respectfully), as I have much more than 50.

    Again thanks for the time and explanation.

  7. Bülent Gavazov
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic