carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Fields not being saved when post_format = standard condition is present

Open geowrgetudor opened this issue 5 years ago • 1 comments

Version

  • Carbon Fields: 3.1.2
  • WordPress: 5.2.2
  • PHP: 7.3.7

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';

geowrgetudor avatar Aug 21 '19 08:08 geowrgetudor

is this fixed yet ?

SohanChotia avatar Apr 12 '24 01:04 SohanChotia