• Resolved Hugo

    (@goncalveshugo)


    Hi!
    First off i’d like to say thanks for this great kickass plugin!
    I′m starting to use it in some projects and its amazing.

    I’m having a bit of a problem with copying metas to a translation, already used it with Advanced Custom Fields, and works great, but now i’m using it with Custom Fields Creator, which is a field group repeater, and although it makes the copy of the meta_value for this one, it also adds extra info at the beginning and the end, and gets a foreach error.

    Also took a look at this filter (pll_copy_post_metas) to see if there could be some more info i could squeeze out, but really can’t understand why this happens.

    Thanx!

    https://www.ads-software.com/extend/plugins/polylang/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Chouby

    (@chouby)

    Could you be more precise? What are these extra info? Which foreach is broken? How did you use pll_copy_post_metas?

    Thread Starter Hugo

    (@goncalveshugo)

    Ok, i’ll try to.
    Thanx for the ready reply!

    I’m using Custom Fields Creator as i said above. Also as i earlier, this is working smooth with ACF, so must be something specific to field groups or something.

    In it, i’m using groups of fields to be repeated, in one of the situations i’m using an inline listing of a team, with the following fields: name, image, position.

    Once you create a new repeater group, you define a meta for it. That’s the one i use when calling pll_copy_post_metas, in this case beeing called team, somewhere near the bottom of functions.php:

    function copy_post_metas($metas) {
      $result = array_merge($metas, array('team'));
      return $result;
    }
    add_filter('pll_copy_post_metas', 'copy_post_metas');

    In the original list everything goes well this is recorded database in the meta_value:

    a:2:{i:0;a:3:{s:4:"name";s:8:"John Doe";s:6:"image";s:3:"486";s:6:"position";s:13:"Some Position";}i:1;a:3:{s:4:"name";s:8:"Jane Doe";s:6:"image";s:3:"488";s:6:"position";s:14:"Other Position";}}

    However, in the copied list in the translated page you get this in the database under meta_value with these extra s:193:” and “; : …

    s:193:"a:2:{i:0;a:3:{s:4:"name";s:8:"John Doe";s:6:"image";s:3:"486";s:6:"position";s:13:"Some Position";}i:1;a:3:{s:4:"name";s:8:"Jane Doe";s:6:"image";s:3:"488";s:6:"position";s:14:"Other Position";}}";

    … and in the admin you get this error in the inline list as a result:

    Warning: Invalid argument supplied for foreach() in C:\wamp\www\something\wp-content\plugins\custom-fields-creator\wordpress-creation-kit-api\wordpress-creation-kit.php on line 448

    Once you clean that s:193:” and “; by hand, everything goes ok.

    I screened around in your admin-filters.php file, only to find that the $value beeing pushed in the add_post_meta($tr_id, $key, $value); is sending the data perfectly.

    Have no idea where that initial and ending extra info is coming from, numbers change, they are not consistent with any other data, have no idea for now of what they are. s:193:” and “;.

    Thanx!

    Plugin Author Chouby

    (@chouby)

    OK I understand. Your meta has multiple values, which currently is not supported by Polylang. So instead of copying an array of values, it copies it as a string (the s, here with 193 characters). This is probably added by WordPress itself in the function add_post_meta

    Thread Starter Hugo

    (@goncalveshugo)

    Ok, i think i nailed it!

    The Culprit:
    add_post_meta/Parameters

    $meta_value
    (mixed) (required)
    The value of the custom field you will add. An array will be serialized into a string.

    The Hero:
    maybe_unserialize

    Unserialize value only if it was serialized.

    Of course this should require a better way to integrate, perhaps some hook, but for now to solve this issue i’m botching your admin-filters.php file(hate doing this), until i find a better solution ??

    Replaced this in line 386 and 455:
    add_post_meta($tr_id, $key, $value);

    with:
    add_post_meta($tr_id, $key, maybe_unserialize($value));

    If you know of a hook i can use, please let me know.

    Thanx!

    Plugin Author Chouby

    (@chouby)

    Fantastic! I will rather include the ‘maybe_unserialize’ into Polylang v0.9

    I should have read the documentation for get_post_custom more carefully.

    Thread Starter Hugo

    (@goncalveshugo)

    Great, nice to hear that!
    Keep up the good work. ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Polylang] pll_copy_post_metas’ is closed to new replies.