Code Monkey home page Code Monkey logo

carbon-fields's Introduction

Carbon Fields Build Status Scrutinizer Code Quality Code Coverage Gitter chat

About

Carbon Fields - developer-oriented library for WordPress custom fields for all types of WordPress content.

Carbon fields can be used as a composer package for easy creation of custom fields in the WordPress administration panel.

Custom fields can be created for post types, taxonomy terms, users, comments, options, navigation menus and even widgets.

Supports PHP 5.6.20 or higher.

Quickstart

See Quickstart

Documentation & Other Resources

carbon-fields's People

Contributors

2c-gstoqnov avatar 9585999 avatar alpanayotov avatar atanas-dev avatar atanas2create avatar dependabot[bot] avatar elvishp2006 avatar emandiev avatar emohamed avatar georgehtmlburger avatar ggeorgiev96 avatar hellosiyan avatar holmar avatar htmlburger-git avatar htmlburger-ng avatar iamntz avatar jorostoyanov avatar kamenarov avatar lstoyanoff avatar m1r0 avatar nlemoine avatar peac36 avatar pedro-mendonca avatar pkostadinov-2create avatar ppetrov2create avatar thomas-figved avatar tocreatedev avatar tyxla avatar vvasilev- avatar yuliyan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

carbon-fields's Issues

Checkbox return value should be boolean?

I've noticed that the checkbox field returns yes as it's value, shouldn't it be better a boolean value? I imagine that changing this will break old code so probably there is nothing to do. At least this can go to the wishlist of the next major version… :-)

Useless mysql queries

Hi guys,

Thanks for a nice plugin!
I was wondering why these 3 db queries (see the attachment) fire on every admin page, is there any way to prevent them and execute only when it's needed?

screen shot 2016-09-03 at 10 55 43 am

Thanks,
E

[bug] - WordPress subdirectory

Hi!

Great project! It seems to gather everything that I ever wanted.

Playing around with it, I'm experiencing a bug with the stack I'm using and which is quite popular among WordPress developers. Carbon Fields can't load any assets when WordPress is in a subdirectory (see https://github.com/roots/bedrock, https://github.com/wecodemore/wpstarter, https://github.com/bueltge/WordPress-Starter, there are many more).
The plugin/package URL only works when using WordPress in a traditional way, if used in a subdirectory, the URL guessing/defining code returns a wrong URL (returns directory instead of url).
https://github.com/htmlburger/carbon-fields/blob/master/carbon-fields.php#L11

Maybe you could take advantage of the method used in ACF to guess the right URL:
https://github.com/elliotcondon/acf/blob/master/acf.php#L115

Let me know if I can help.

Complex Fields not saved on falsy field values

When adding complex fields and not giving their subfields any input the whole complex field item is missing after saving. This also occurs when the only input field in the group is a checkbox that is not ticked (i.e. is falsy).

Why would you need empty complex fields anyway, you might ask? Well, we use complex fields as modules (previously in ACF we used flexible content fields) and some modules do not have any data. Example: a divider module that just renders a line and doesn't need data attached. Of course you can solve it via dummy values but that just doesn't seem right.

Visual GUI improvement

Some developers and designers at our agency would like to enhance the overall UI of the plugin by styling the CSS accordingly. If you are open for those improvements we'd like to issue a pull request once we are done. However, this only makes sense for us if the changes will be integrated into your main repository in the long run. Please let us know if this is ok for you.

Documentation colors & WCAG

Hi, first of all. Thank you so much for creating the custom field plugin that the Wordpress community needed! I is a joy to use.

One small request, on your website you have very small, light gray text.
This is not very readable, and I'm guessing if I think it's hard to read someone else might find it impossible.

I checked both the body text, and the code examples with green on gray. And both fail WCAG 2.0 tests.
IMO you should aim to pass WCAG 2.0 AAA tests for contrast on text like documentation.
As it not only makes it accessible to everyone, but more usable for everyone if you spend a couple of hours reading it :)

Thanks again.

Coding standards

I noticed many files containing whites paces at the end of lines. Would you consider adding adhering to coding standards? Using PHP CodeSniffer for example?

Widget doesn't work in the Customizer

Hello,

I have used the code of your documentation to create a widget, it works well in the widget page but bug in the Customizer.

Tested on a clean WP 4.5 install with no other plugins activated and 2016 theme.
Linux (Ubuntu 16.04 and FF)

See the result in the screenshot joined.

widget

Option to save complex fields as one postmeta field

When using complex fields excessively, they soon generate a vast number of postmeta UPDATE-queries when saved in the backend. This makes saving slow and consumes a lot of resources. On the other hand retrieving sub-fields of complex fields is rarely needing. Mostly all data has to be selected and looped through.
One approach is to save all data in a serialized way in one postmeta field per complex field either by adding a saving-type-option ("one field" vs. "per sub field") to the complex type or adding a new field type.

(Remark: We use complex fields for storing page content modules. E.g. 30 modules á 10 fields each create 300 field operations.)

PHP Fatal Error when installed with composer alongside wordpress

When installing wordpress and carbon-fields both through composer, when attempting the wordpress install process PHP throws a fatal error:

PHP Fatal error:  Call to undefined function trailingslashit() in /.../vendor/htmlburger/carbon-fields/carbon-fields.php on line 13

This is because carbon-fields expects to be installed in a location where wordpress is fully installed by use of the wordpress function trailingslashit().

A quick fix might be to check the existence of wordpress ( or perhaps just trailingslashit() ) and return if not found.

Fatal Error Installing via Composer on Bedrock

When installing via composer on a Roots / Bedrock project.

Fatal error: Call to undefined function trailingslashit() in /srv/www/influencebydesign/htdocs/vendor/htmlburger/carbon-fields/carbon-fields.php on line 13

Options Page Container

I'm developing a plugin using Carbon Fields, and I think there's an important feature missing. I want to add a Options Page that is not a Theme Options page.

This menu item should be able to be a parent of any other WordPress admin menu, like Options or even a Custom Post Type menu.

I tried to use Theme Options Container for this, but I can only create top menu items (or submenu items that are childs of other Carbon Container page), I can't create a sub menu item of any other non Carbon Fields menu item.

Is there any time line for this feature?

Thanks!

show_on_page() doesn't work without show_on_post_type('page') first

I am trying to register a container for a page with path "menukort" like this:

Container::make('post_meta', 'Allergener og kalorieindhold')
    ->show_on_page('menukort')
    ->add_fields(array(
        // pass
    ));

And unless I add show_on_post_type('page') before show_on_page, the container does not appear on the page.

I expect the container to automatically figure out that it needs to be displayed on a page post type, if I tell it to show_on_page.

pre-populating complex fields with set_min()

By setting ->set_min() I thought a complex field would be pre-populated with declared minimum amount of field rows. But even with ->set_required(true) the user must add a row himself. If this is the intended behavior I found it counterintuitive or at least it lacks this little step of comfort. If it isn’t, It’s perhaps a bug.

On the other hand I’m perhaps missing cases where it is better not to setup the field-rows for the user. In this case could you point me to a solution for pre-populting complex fields with a certain amount of rows (empty of course ;)? Thanks!

Select field set_options doesn't work with numeric keys

When using a select field with set_options or add_options any numeric keys in the associative array are not retained in the generated select field.

Example select field:

Field::make('select', 'user', 'User')
    ->set_options(array(
        3 => 'John Smith',
        7 => 'Jane Doe'
    )),

Results in a select like this:

<select>
    <option value="0">John Smith</option>
    <option value="1">Jane Doe</option>
</option>

Expected result would be to maintain the key values whether they are a string or a number. The same behaviour is seen if using numeric string keys like "3" and "7" in the associative array.

Carbon fields v1.1

Add pre-populated pallets for color field

Currently, Iris colorpicker ( color field ) uses default set of palettes: palettes: true
But it accepts the array of pre-defined palettes: palettes: ['#125', '#459', '#78b', '#ab0', '#de3', '#f0f']

Lets consider pre-populate palettes set based on latest used colors by current user.
This data could be saved, for example, as hidden user meta or just in global $_SESSION variable.

Complex Field: add `collapse()` option

Maybe it's interesting to collapse the fields by default, at least in the case that the developer has defined a custom header template (#27). The idea is to hide clutter to make it cleaner for the user.

Somewhat related to #41 (add collapse all button).


Edit: changed issue title, it would be better to just add a flag as mentioned by @m1r0 instead of assuming that if there is a template the field should collapse.

It's better to disable fields rather then hide when Conditional Logic is applied

Hi there,
I have a proposition to change behaviour of Fields when Conditional Logic is applied. I think, it's better to just disable fields.
e.g. :

Field::make('select', 'crb_show_socials', 'Show Socials')
    ->add_options(array(
        'yes' => 'Yes',
        'no' => 'No',
)),
Field::make('text', 'crb_facebook', 'Facebook URL')
    ->set_conditional_logic(array(
        'relation' => 'AND', 
        array(
           'field' => 'crb_show_socials',
           'value' => 'yes', 
           'compare' => '=', 
       )
)),

disabled field

I'm not an expert in UX, but when you have a few more things in a Field and they just disappear changing height of page and position of other fields, It may be disrupting. Especially, when on place of field that disappeared, jumps field with a similar name.

How to create tabbed theme option panel

Hi

Just saw the plugin . I have used Option tree for many years but this plugin seems interesting . I was able to create theme option panel . How can I create tabbed group/option panel?

RichText field TinyMCE initialization bug

The TinyMCE editor initialization fails with the following code:

Container::make( 'post_meta', __( 'Profile' ) )
    ->add_fields( array(
        Field::make( 'rich_text', 'first_name', __( 'First Name' ) )
            ->set_width( 50 ),
        Field::make( 'rich_text', 'last_name', __( 'Last Name' ) )
            ->set_width( 50 ),
    ) );

It only fails on the first RichText field.

If a third field is added - the initialization is OK.

Carbon JSON data encoding/escaping bug

In some rare cases, user input can prevent the plugin from rendering and potentially break the backend.

For example adding <!-- <script (with a space at the end) as a field value will break the JSON data and prevent the plugin from initialization.

This happens because wp_localize_script doesn't use a CDATA with maximum compatibility. More info about the problem here.

Add new field types (email, url) or regex validation

It would be interesting to have more options to constraint the user input, useful for email, url… fields. Maybe the most versatile option would be to add a regex validation option to the "text" field. CF could add some constants for the most commonly used regexes (CF_EMAIL_REGEX, CF_URL_REGEX…).

In the case of adding regex validation I imagine that we should provide the JS version, since there is no real server side validation of the input. (is there?)

Another issue might be the visual feedback of the errors as noted in #60.

Give better feedback when required fields are missing

When the user clicks on "Update" and there are errors we should give some feedback, otherwise the user might miss the errors, especially when the forms are down outside the visible area.

A notice just below the "Update" box would be ideal.

Carbon-fields + bedrock & sage (wproot)

Good morning,

I have a problem with this torque of technologies. I use bedrock with sage theme of wproot. When i download Carbon fields via composer, i have a error 500 on my website after composer update.

In my log apache i have this :
[Wed Mar 02 10:05:07.170780 2016] [:error] [pid 6110] [client 127.0.0.1:33616] PHP Fatal error: Call to undefined function Carbon_Fields\untrailingslashit() in /home/jb/projets/aljt/vendor/htmlburger/carbon-fields/carbon-fields.php on line 11

Bedrock create this structure of project :

  • config
    • environnement
    • application.php
  • vendor (with carbons-fields)
  • web
    • app (content of my app with plugins)
      • languages
      • mu-plugins
      • plugins
      • themes
      • uploads
    • wp (core wordpress, i don't need touch anything in this folder)

All functions of wordpress is not detected in vendor > htmlburger > carbon-fields > ...

Have you got idea for check this problem ?

Term Meta Styling Issue

There is a CSS issue on the "Add New Term" page, when we have a complex field with groups. The default styling prevents the dropdown from showing. Image attached.
carbon-bug_03

Solution: #13

Add Field->help_text_position method

In some (or all) cases, having the help text appear below the Field label instead of below the Field UI would make for a better UX. Especially for fields that are rather tall (the relationship/association field).

Perhaps a potential option would be to have a help_text_position method that takes either 'top' or 'bottom' that places the help text accordingly.

I can't retrieve images.

I am pretty new to this plugin so bear with me, it might be a dumb question.
I cannot retrieve the image url from the options page.

this is the code i used in the post-meta:
Container::make('theme_options', 'Theme Options') ->add_tab(__('Header'), array( Field::make('text', 'page_title_header', 'Titlu'), Field::make('image', 'crb_bg_image','Header Background'), ))

And this is where i tried retrieving that url and it showed nothing:
<img src="<?php echo carbon_get_theme_option('crb_bg_image'); ?>" alt=" ">

And when i looked in the inspect element section it said this:
<img src="16" alt=" ">

So it retrieved a 16 instead of the actual url. Am I doing something wrong?

Ability to save all Theme Options as a Array

Feature Request: Would be a cool feature to be able to save all Theme Options as an Array in the Database vs single entries. Perhaps this was done for specific reason - but performance wise (On bigger sites) it would be more beneficial retrieving 1 object vs lots of little ones.

Relationship Field: one2one and one2many

Right now relationship field works as one2many field even when using set_max(1). I could use a select field and populate it with the CPT that I want to link… but it's not as convenient as the relationship field.

Few ideas:

  • make relationship field act as one2one when set_max(1). Also it could show only a dropdown instead of the two lists.
  • create another field for one2one relationships.

Ideally it should return [id1, id2, …] instead of [[id1], [id2], …].

Reusing Relationship Field inside Nested Section

I am using a sections layout to make a modular theme. I have my sections displaying on the default page template, but I also wish to embed the sections inside of other sections using multiple complex types.
image

However the problem is that even though it displays the section in the backend and I can interract with it, when I update the post, the value doesn't get saved.
image

Filter for field names

It would be nice to have a filter for the field names on both the factory methods and the carbon_get_theme_option / carbon_get_*_meta functions.

Example use case: a prefix/suffix can easily be added to the field name when setting and retrieving values on multi language sites (if, for example, the site was not initially multi-language) without rewriting all the fields.

User Meta Container shows only for "administrator" role

In my installation I have 3 roles: administrator, member and ex_member.
Some fields I want to show for all of them, and some only for administrator role.
Tried to ->show_on_user_role('member'), but It doesn't show for user with member role.

Issue with javascript hiding the container

Hello, I'm attempting to show a Container on a page that has the taxonomy term of "slider" in a custom taxonomy of "layouts". The Container shows up in the DOM but gets hidden by javascript. I think the source is containers.js in the checkVisibility function. On line 668 it checks if termId is in the terms array. However, my terms array is coming up empty for some reason. Here's the code where I make my Container:
// Image slider
Container::make('post_meta', 'Image Slider')
->show_on_post_type('page')
->show_on_taxonomy_term('slider', 'layouts')
->add_fields(array(
Field::make('complex', 'image_slider')->add_fields(array(
Field::make('text', 'title'),
Field::make('text', 'subtitle'),
Field::make('image', 'photo')->set_value_type('url'),
))
));
Do you have any idea what the issue might be? Is there a step I'm missing? Here's the code where I create my custom taxonomy:
$labels = array(
'name' => _x( 'Layouts', 'taxonomy general name' ),
'singular_name' => _x( 'Layout', 'taxonomy singular name' ),
'search_items' => __( 'Search Layouts' ),
'popular_items' => __( 'Popular Layouts' ),
'all_items' => __( 'All Layouts' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Layout' ),
'update_item' => __( 'Update Layout' ),
'add_new_item' => __( 'Add New Layout' ),
'new_item_name' => __( 'New Layout Name' ),
'separate_items_with_commas' => __( 'Separate topics with commas' ),
'add_or_remove_items' => __( 'Add or remove topics' ),
'choose_from_most_used' => __( 'Choose from the most used topics' ),
'menu_name' => __( 'Layouts' ),
);

register_taxonomy('layouts','page',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'layouts' ),
));

wp_set_object_terms( get_option( 'page_on_front' ), 'slider', 'layouts' );

[field] - Image field value

When using image field, the value saved is an absolute URL. I think saving the image ID would probably be more appropriate:

  • It does not rely on a domain name (getting image URL from an ID will work event the domain has changed)
  • It leaves the choice of choosing a size when displaying the image in a template
  • It allows to retrieve metadata attached to the image file
    etc.

Textdomain is wrong for GlotPress

In order for the plugin to be properly localised, it should use the carbon-fields textdomain instead of the current one (carbon_fields).

What is the best way to contribute a new translation?

I would like to use carbon fields for a German project. Therefore I'd like to add a German translation.

Of course I could simply download the pot file and contribute the new translation. I just wanted to ask if you considered to use a service like Transifex? I really like the interface they provide, plus it enables the community to update and contribute translations with minimal effort.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.