htmlBurger
Forum Replies Created
-
Forum: Plugins
In reply to: [Carbon Fields] Updating fields with PHP functions?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 usingupdate_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!
Forum: Plugins
In reply to: [Carbon Fields] vertical tabsHi @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 totabbed-horizontal
To address the problem, just replace calls to
tabbed
totabbed-horizontal
.Forum: Plugins
In reply to: [Carbon Fields] Custom fields on certain pages onlyHi @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.
Forum: Plugins
In reply to: [Carbon Fields] Association relationship working both waysHey @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
Forum: Plugins
In reply to: [Carbon Fields] Screen Options are checked incorrectlyHi @luhrayuh,
Can you please provide the code for the Carbon Container that is causing the problem?
Forum: Plugins
In reply to: [Carbon Fields] Using framework in plugin in my pluginHi @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!
Forum: Plugins
In reply to: [Carbon Fields] term_meta custom fieldsHi @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.
Forum: Plugins
In reply to: [Carbon Fields] Custom Functions To Access Complex Data DynamicallyHi @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.
Forum: Plugins
In reply to: [Carbon Fields] Complex field with relations, adding extra rows to dbHi @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.
Forum: Plugins
In reply to: [Carbon Fields] After save theme hook not workingNo problem, you are welcome!
Forum: Plugins
In reply to: [Carbon Fields] After save theme hook not working@martnick Did you try adding an
exit;
after the closingpre
?Forum: Plugins
In reply to: [Carbon Fields] User Container on custom pagesHey @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.
Forum: Plugins
In reply to: [Carbon Fields] After save theme hook not workingHi @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.Forum: Plugins
In reply to: [Carbon Fields] Activate fields conditionally@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; }
Forum: Plugins
In reply to: [Carbon Fields] conflict with a custom plugin