htmlburger / carbon-fields

WordPress Custom Fields Library ✨
https://carbonfields.net/
Other
1.38k stars 245 forks source link

Fields not being saved when post_format = standard condition is present #754

Open geowrgetudor opened 5 years ago

geowrgetudor commented 5 years ago

Version

Expected Behavior

Fields should get saved for all post formats.

Actual Behavior

Fields are not getting saved for "standard" post format (at least when the where('post_format', '') condition is present).

Container definition

$post_formats = ['standard', 'image', 'gallery'];

// Add same option for different post_formats.
foreach ( $post_formats as $format ) {
                $container = Container::make( 'post_meta', 'Settings' )
                                      ->where( 'post_type', '=', 'post' )
                                      ->where( 'post_format', '=', $format );

                $fields                   = [];
                $fields['some-options'][] = Field::make( 'checkbox', 'option_name_here', esc_html__( 'first option', 'theme-domain' ) )
                                                 ->set_default_value( 'yes' );

                // more fields here

                foreach ( $fields as $key => $props ) {
                    if ( isset( $tabs[ $key ] ) ) {
                        $container->add_tab( $tabs[ $key ], $props );
                    }
                }
            }

Steps to Reproduce the Problem

  1. Add fields for a post_format standard
  2. Save the post
  3. Refresh. Fields won't be saved. If you check the database there will be no post meta for the given post id

Comments

I think this happens because by default get_post_format() returns false for the standard post format and given the fact that we pass the where('post_format', $format) condition it's not fulfilling the Carbon_Fields\Container\Condition\Post_Format_Condition is_fulfilled() method, which checks for empty string for post format "standard'.

Fixed it by checking for 'standard' instead of empty string in Carbon_Fields\Container\Condition\Post_Format_Condition Before:

$format = ( $format ) ? $format : '';

After:

$format = ( $format ) ? $format : 'standard';
SohanChotia commented 6 months ago

is this fixed yet ?