BeAPI / acf-options-for-polylang

A WordPress plugin for adding ACF options page support for Polylang.
https://wordpress.org/plugins/acf-options-for-polylang/
Other
168 stars 28 forks source link

Manipulate data from one lang to an other one #39

Open davidfaber opened 5 years ago

davidfaber commented 5 years ago

Hi there, Thank you so much for this awesome plugin. One thing though.... I recently added it to an existing site of mine and I came up with an SQL-Script that does two things:

  1. It moves all stored data from "All languages" to en_GB
  2. It copies existing fields to a new language (de_DE) in my case

I think this can be very useful for other users too, e.g. if add the plugin to an existing site or you add a new language and don't want to start from 0 with your settings.

Also it cleans up the "All languages"-data, which could be a good solution for Issue #37

If you tell me where and how you would like that information in your Readme, I am very happy to make the changes and open an Pull request for it.

The MySQL:

# Rename current options
UPDATE {YOUR_TABLE_PREFIX}options SET option_name = CONCAT('options_en_GB', TRIM(LEADING 'options' FROM option_name)) WHERE option_name LIKE 'options%';
UPDATE {YOUR_TABLE_PREFIX}options SET option_name = CONCAT('_options_en_GB', TRIM(LEADING '_options' FROM option_name)) WHERE option_name LIKE '_options%';

# Duplicate options
CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM {YOUR_TABLE_PREFIX}options WHERE option_name LIKE 'options%' OR option_name LIKE '_options%';
UPDATE tmptable_1 SET option_id = NULL;
UPDATE tmptable_1 SET option_name = CONCAT('options_de_DE', TRIM(Leading 'options_en_GB' FROM option_name)) WHERE option_name LIKE 'options%';
UPDATE tmptable_1 SET option_name = CONCAT('_options_de_DE', TRIM(Leading '_options_en_GB' FROM option_name)) WHERE option_name LIKE '_options%';
INSERT INTO {YOUR_TABLE_PREFIX}options SELECT * FROM tmptable_1;
DROP TEMPORARY TABLE IF EXISTS tmptable_1;

# Show the results
SELECT * FROM {YOUR_TABLE_PREFIX}options WHERE option_name LIKE 'options%' OR option_name LIKE '_options%';

Thanks, David

MaximeCulea commented 5 years ago

Thank you David,

You summed up everything perfectly.

I have to take a look.

MaximeCulea commented 5 years ago

It seems nice.

I will make a wp cli command to :

davidfaber commented 5 years ago

That sounds like a lovely idea!

1ucay commented 4 years ago

Hi, can you add as link to right metabox?