Keep Settings When Changing URL - Wordpress - Theme: Adventure - Organic Theme

2

I'm having problems theme settings when changing the URL of a wordpress site using the Organic Theme's Adventure theme.

I made some scripts to change the functions in the database, which is ok! And it works with other themes perfectly.

However, the theme Adventure from the Organic Themes company uses a single column of the wp_options table to store the settings.

Every time I change the url (with a different size) the theme settings are lost.

I noticed that they work with a strange pattern (to my limited knowledge), storing the theme settings in a single column, using the link size to generate the settings.

Here's how you set it in the option_value column:

s:12:"header_image";s:62:"http://www.yoursite.com.br/wp-content/uploads/2015/06/logo.jpg";

Notice that the number after the s: represents the length of the string ahead: s:62: is the length of the string logo.jpg p>

Changing the url to link I have to adjust not only the url but the size indicated in s:XX .

Does anyone know of any way to do this update? Via plugin or code?

It takes a lot of time to redo the theme settings, and if the site is restored, it will be unconfigured for a few minutes until the theme setting is completely redone (again).

Thank you!

    
asked by anonymous 11.09.2015 / 21:09

2 answers

1

I developed a bash script to solve the problem.

Below is the script in full:

#!/bin/bash

# 1. Dados Gerais

# 1.1 URL
URL_OLD=http://very_old_url.com.br
URL_NEW=http://novo_url.com.br

# 1.2 Database
USER=db_user
PASS=db_pass
DATABASE=db_name
WP_TABLE=un_options
WP_FIELD=option_value
THEME=theme_mods_organic_adventure-child

# 2. Configurações iniciais

# 2.1 Diferença de tamanho das URL´s
VAL=$(( ${#URL_OLD} - ${#URL_NEW} ))

# 2.2 Valor atual no banco de dados
RESULT=$(mysql -u $USER -p$PASS $DATABASE -s -N -e 'SELECT '$WP_FIELD' FROM '$WP_TABLE' WHERE option_name="'$THEME'";')

# 2.3 Matrix com todos os índices que possuem ocorrência de 'http://' no banco de dados
if [[ $RESULT == *"http://"* ]]; then
    MUDAR=($(echo $RESULT | grep -b -o http | awk 'BEGIN {FS=":"}{print $1}'))
fi

# 2.4 Loop para mudar o tamanho no banco de dados
for i in "${MUDAR[@]}"
do
    # 2.4.1 Busca o campo atual
    STR=${RESULT:$i-8:14}

    # 2.4.2 Busca o tamanho atual
    TAM=$( echo $STR | egrep -o "[0-9]*" )

    # 2.4.3 Roda a função se o valor for menor que 3... se for maior tem de ajustar essa parte @TODO
    if [[ ${#TAM} < 3 ]]; then
        nTAM=$(($TAM-$VAL))             # New lenght
        nSTR=${STR/$TAM/$nTAM}          # Fix the Current Number
        RESULT=${RESULT/$STR/$nSTR}     # Update the string
    fi
done

# 3. Grava no banco de dados

# 3.1 Prepara a string com barra antes das aspas duplas para gravar no mysql
RESULT=$( echo $RESULT | sed -e 's/\"/\"/g' )

# 3.2 Atualiza o banco de dados com as novas configurações
mysql -u $USER -p$PASS $DATABASE -s -N -e 'UPDATE '$WP_TABLE' SET '$WP_FIELD'="'${RESULT}'" WHERE option_name="'$THEME'";'

return

I hope it will be helpful to someone as well. To use scirpt only change the settings in field '1'.

Thank you!

    
14.09.2015 / 13:38
1

To modify URLs in the database you must always take into account the error-free change of serialized values, as in your example:

s:12:"header_image";s:62:"http://www.yoursite.com.br/wp-content/uploads/2015/06/logo.jpg";

I usually use the WordPress Serialized PHP Search Replace Tool when the need is simple.

If you are automating the process, then you will need PHP functions serialize() and < a href="https://secure.php.net/manual/pt_BR/function.unserialize.php"> unserialize() .

    
13.09.2015 / 04:10