Forum Replies Created

Viewing 15 replies - 31 through 45 (of 161 total)
  • Plugin Author htmlBurger

    (@htmlburger)

    Hey Mario,

    Thanks for the kind words, we are glad that you like the plugin!

    We don’t have a dedicated update function (yet!), but the storage technique of Carbon Fields is not very complicated. In your situation you can just do a post meta update, for example:

    If your field declaration is

    
    Container::make( 'post_meta', __( 'Post Settings', 'crb' ) )
        ->add_fields( array(
            Field::make( 'text', 'crb_unique_key' ),
        ));
    

    The post meta key that will be stored in the database will be _crb_unique_key, so you can update it using

    
    update_post_meta( $post_id, '_crb_unique_key', 'my unique key generated by gravity forms' );
    

    Hope this helps. If you have further questions don’t hesitate to ask.

    Cheers!

    Plugin Author htmlBurger

    (@htmlburger)

    Hi @alexadark

    You can use the vertical tabs by simply calling:

    ->set_layout('tabbed-vertical')

    In the new version ->set_layout('tabbed') will:

    * issue a warning that the tabbed layout is deprecated
    * fallback to tabbed-horizontal

    To address the problem, just replace calls to tabbed to tabbed-horizontal.

    Plugin Author htmlBurger

    (@htmlburger)

    Hi @alexadark,

    For your problem one approach is to make multiple containers, just keep in mind that the container names should be unique. Example:

    
    Container::make( 'post_meta', 'Home Blockquote' )
             ->show_on_page( (int) get_option( 'page_on_front' ) )
    
    Container::make( 'post_meta', 'Work Blockquote' )
             ->show_on_post_type( 'work' )
    
    Container::make( 'post_meta', 'About Blockquote' )
             ->show_on_template( 'templates/about.php' )
    

    Hope this helps.

    Plugin Author htmlBurger

    (@htmlburger)

    Hey @sirojuntle, thanks for the suggestion.

    This is a common feature request and a bit tricky one to implement, so I can’t say when/if we will add it. There is an open ticket in Github where you can follow the progress: https://github.com/htmlburger/carbon-fields/issues/15

    Plugin Author htmlBurger

    (@htmlburger)

    Hi @luhrayuh,

    Can you please provide the code for the Carbon Container that is causing the problem?

    Plugin Author htmlBurger

    (@htmlburger)

    Hi @meshsmith!

    Can you please provide a little bit more information about the error you got? Please include the exact error message.

    Also, please let us know what PHP version you’re using.

    Thanks!

    Plugin Author htmlBurger

    (@htmlburger)

    Hi @alexadark,

    Here is a simpler solution to fetch the meta value for the currently queried term:

    carbon_get_term_meta( get_queried_object_id(), 'crb_hero_tax_image' );

    Function Reference: get_queried_object_id()

    • This reply was modified 8 years, 1 month ago by htmlBurger.
    Plugin Author htmlBurger

    (@htmlburger)

    Hi @jonwaldstein,

    You have to handle each complex group separately. If you have a two columns layout and a full-width layout and both can have a full-width option you can do the following:

    Container::make( 'post_meta', 'Custom Data' )
    	->show_on_post_type( 'page' )
    	->add_fields( array(
    		Field::make( 'complex', 'crb_layouts' )
    			->add_fields( 'two_column_layout', array(
    				Field::make( 'checkbox', 'full_width_section' ),
    				Field::make( 'rich_text', 'column_left' )->set_width(50),
    				Field::make( 'rich_text', 'column_right' )->set_width(50),
    			) )
    			->add_fields( 'full_width_layout', array(
    				Field::make( 'checkbox', 'full_width_section' ),
    				Field::make( 'rich_text', 'column' ),
    			)),
     ) );
    function zgm_print_layout($layout) {
    	?>
    	<div class="section <?php echo $layout['full_width_section'] ? 'container-fluid' : 'container'; ?>">
    		<div class="row">
    			<?php if ( $layout['_type'] === '_two_column_layout' ): ?>
    				<div class="col-sm-6">
    					<?php echo $layout['column_left']; ?>
    				</div>
    				<div class="col-sm-6">
    					<?php echo $layout['column_right']; ?>
    				</div>
    			<?php elseif ( $layout['_type'] === '_full_width_layout' ): ?>
    				<div class="col">
    					<?php echo $layout['column']; ?>
    				</div>
    			<?php endif ?>
    		</div>
    	</div>
    	<?php
    }

    Hope this helps.

    Plugin Author htmlBurger

    (@htmlburger)

    Hi @martnick,

    This behavior is by design. The Conditional functionality is meant to be used only to improve User Experience.

    Imagine the following use-case.

    You need to add Credentials options for a service, which has both “Sandbox” and “Live” environments, e.g. PayPal. For both of these environments, you will have two options “Client ID” and “Secret Key”. In addition to these, you have another option “Choose Environment”.

    function crb_environment_conditional_logic( $environment ) {
        return array(
            array(
                'field' => 'paypal_environment',
                'value' => $environment,
            ),
        ),
    }
    
    Container::make( 'theme_options', 'PayPal Settings' )
        ->add_fields( array(
            Field::make( 'select', 'paypal_environment', 'Choose Environment' )
                ->add_options( array(
                    'live'    => 'Live',
                    'sandbox' => 'Sandbox',
                ) ),
    
            Field::make( 'text', 'paypal_live_clientid', 'Live Client ID' )
                ->set_conditional_logic( crb_environment_conditional_logic( 'live' ) ),
            Field::make( 'text', 'paypal_live_secret_key', 'Live Secret Key' )
                ->set_conditional_logic( crb_environment_conditional_logic( 'live' ) ),
    
            Field::make( 'text', 'paypal_sandbox_clientid', 'Sandbox Client ID' )
                ->set_conditional_logic( crb_environment_conditional_logic( 'sandbox' ) ),
            Field::make( 'text', 'paypal_sandbox_secret_key', 'Sandbox Secret Key' )
                ->set_conditional_logic( crb_environment_conditional_logic( 'sandbox' ) ),
        ) );

    So, basically if you change the Environment, only the associated Credentials options will be displayed. However, if the Conditional Logic stores only the visible fields in Database, the Administrator will have to update the fields every time He wants to test in Sandbox and again when switching to Live, which will be inconvenient.

    In addition, you will still have to perform a check in your code to get the correct Environment Credentials. Not storing the invisible options it Database won’t affect your code.

    —-

    However, given your example, it makes more sense to use two Complex Groups instead of conditional logic. This will look like this:

    Container::make( 'theme_options', 'Plugin Roles Options' )
        ->set_page_parent('Plugin Options');
        ->add_fields( array(
            Field::make( 'complex', 'role_add_field', 'Role Fields' )
                ->add_fields( 'Text', array(
                    Field::make('text', $field_code . 'label', 'Label'),
                    Field::make('text', $field_code . 'code', 'Code Name')->set_required(true),
                    Field::make('text', $field_code . 'placeholder', 'Placeholder Value'),
                    Field::make('text', $field_code . 'default_value', 'Default Value'),
                ) )
                ->add_fields( 'Select', array(
                    Field::make('text', $field_code . 'label', 'Label'),
                    Field::make('text', $field_code . 'code', 'Code Name')->set_required(true),
                    Field::make('complex', $field_code .'options')->add_fields(array(
                        Field::make('text', $field_code . 'option_key', 'Key')->set_width(50)->set_required(true),
                        Field::make('text', $field_code . 'option_value', 'Value')->set_width(50)->set_required(true),
                ) ),
        ) )

    For more information about Multiple Complex Groups, please head to the Documentation – https://carbonfields.net/docs/complex-field-multiple-groups/

    Let us know if this solves your issue.

    Plugin Author htmlBurger

    (@htmlburger)

    No problem, you are welcome!

    Plugin Author htmlBurger

    (@htmlburger)

    @martnick Did you try adding an exit; after the closing pre?

    Plugin Author htmlBurger

    (@htmlburger)

    Hey @martnick,

    Interesting use case! You can approach this in two ways:

    1. Make the field names dynamic by adding the user id as a suffix:

    $user_id = get_current_user_id();
    Field::make( 'checkbox', 'crb_some_option_' . $user_id, __( 'Some Option', 'crb' ) ),

    You can also make a function that builds the meta names for you just for convenience.

    2. Modify the container datastore (not really recommended, but a possible solution):

    use Carbon_Fields\Container\Container;
    use Carbon_Fields\Field\Field;
    use Carbon_Fields\Datastore\User_Meta_Datastore;
    
    $users_datastore = new User_Meta_Datastore();
    $users_datastore->set_id( get_current_user_id() );
    
    $theme_options = Container::make( 'theme_options', __( 'Theme Options', 'crb' ) );
    $theme_options->set_datastore( $users_datastore );
    
    $theme_options
    	->add_fields( array(
    		Field::make( 'header_scripts', 'crb_header_script', __( 'Header Script', 'crb' ) ),
    		Field::make( 'footer_scripts', 'crb_footer_script', __( 'Footer Script', 'crb' ) ),
    	) );

    Hope this helps.

    Plugin Author htmlBurger

    (@htmlburger)

    Hi @martnick,

    The hook is actually firing at the proper time, but the $user_data part is misleading because its not holding the actual user input. We will most likely remove that variable to avoid confusion.

    If your goal is to retrieve the user input, try using the $_POST variable.
    Hope this helps.

    Plugin Author htmlBurger

    (@htmlburger)

    @alexadark, you can make a field builder function that populates the complex field with the needed groups. Maybe something like:

    Container::make( 'post_meta', 'layouts' )
    	->show_on_post_type( 'page' )
    	->show_on_template( 'builder-page.php' )
    	->add_fields( array(
    		crb_get_layouts_complex_field( 'crb_block_layouts' )
    	) );
    
    function crb_get_layouts_complex_field( $name ) {
    	$active_layouts = (array) carbon_get_theme_option('crb_active_layouts');
    
    	$complex = Field::make( 'complex', $name );
    
    	$fields = array(
    		'text_area' => array(
    			// fields for text area
    		),
    
    		'slider' => array(
    			// fields for slider
    		),
    	);
    
    	foreach ($active_layouts as $layout) {
    		if ( empty( $fields[$layout] ) ) {
    			continue;
    		}
    
    		$complex->add_fields( $layout, $fields[$layout] );
    	}
    
    	return $complex;
    }
    Plugin Author htmlBurger

    (@htmlburger)

    Hey @dewy,

    At the moment, you can’t have 2 instances of carbon fields, you need to check if the plugin is already active before including the second instance. You can also check this tread. We will try to solve this problem in a future version.

    Hope this helps.

Viewing 15 replies - 31 through 45 (of 161 total)