wp-papi / papi

:rocket: WordPress Page Type API with custom fields
https://wp-papi.github.io
MIT License
263 stars 32 forks source link

Link property doesn't show saved values #173

Closed entr closed 8 years ago

entr commented 8 years ago

I can't get link property to work inside a group. Please note I haven't tested it NOT being in a group.

What I expected

The link admin control to be populated with saved data. Instead it shows as empty in both tested Papi version. The meta is saved though.

What happened instead

In Papi 3.1.0-beta2 the meta is saved with group prefix, which according to documentation seems wrong (don't know if docs are up to date for 3.1).

From wp_post_custom():

  'cta_button' => 
    array (size=1)
      0 => string '1' (length=1)
  'cta_button_0_cta_btn_link' => 
    array (size=1)
      0 => string 'a:5:{s:16:"cta_btn_link_url";s:29:"http://project.dev/test-page/";s:18:"cta_btn_link_title";s:0:"";s:19:"cta_btn_link_target";s:5:"_self";s:20:"cta_btn_link_post_id";i:119;s:12:"cta_btn_link";i:1;}' (length=197)

In Papi 3.0.7 meta seems to be saved under right meta keys however my admin control is still showing as empty after save.

From wp_post_custom():

  'cta_btn_link_url' => 
    array (size=1)
      0 => string 'http://project.dev/test-page/' (length=29)
  'cta_btn_link_target' => 
    array (size=1)
      0 => string '_self' (length=5)
  'cta_btn_link_post_id' => 
    array (size=1)
      0 => string '117' (length=3)
  'cta_btn_link' => 
    array (size=1)
      0 => string '1' (length=1)

Steps to reproduce


      papi_property([
        'type' => 'group',
        'title' => __( 'CTA Button' ),
        'description' => __( 'Setup Call-to-Action button at the bottom' ),
        'settings' => [
          'items' => [
            papi_property([
              'type' => 'link',
              'slug' => 'cta_btn_link',
              'title' => __('Button link'),
              'sidebar' => false,
            ]),
            ...
          ]
        ],
      ]),

What versions of softwares are you using?

frozzare commented 8 years ago

The documentation for Papi 3 isn't the right documentation for Papi 3.1. The changelog for Papi 3.1 says that the group property has been changed. Will take a look at why link property don't work with a group.

frozzare commented 8 years ago

The group property in 3.x isn't so good and it will be a big thing to fix it in another way than it is fixed in 3.1. I would recommend to use 3.1 if possible or use another property right now until 3.1 is out.

The bug that caused the link property bug in 3.1 was a bug with the repeater and the conversion of child properties (e.g repeater in repeater). The link property values did look like a child property for the repeater class and when the values didn't had the expected values it did fail.

This is now fixed in master branch and will be out in the next beta or the final release.

entr commented 8 years ago

Any thoughts on the 3.0 not showing current/saved values in link property? I'm talking admin UI. I can confirm meta is saved.

frozzare commented 8 years ago

Yep, the property can't be loaded right since it's in a group, but the property isn't saved within a group so right now it's a missmatch between the saved data and how it would be render and that is changed in 3.1 and it will be some changes from how the data is saved between 3.0 and 3.1. It wouldn't be so good to do this change in a patch release.

entr commented 8 years ago

Thanks. So if I need group working right now I need to require dev-master ?

frozzare commented 8 years ago

Yes, that's the case.

entr commented 8 years ago

I'm also experiencing an issue with a group inside a repeater. Only the first group (in first repeater item) is processed/saved properly. Don't know if it's officially supported though. I'm posting it here since it might be related.

frozzare commented 8 years ago

It's not supported yet.

frozzare commented 8 years ago

If you want you can try the fix for group property inside repeater property. It should be fixed in master branch now.

entr commented 8 years ago

Thanks man, I will and report back tonight.