Download the PHP package wpify/custom-fields without Composer

On this page you can find all versions of the php package wpify/custom-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package custom-fields

WPify Custom Fields

This library provides custom fields for WordPress and WooCommerce via simple API. The custom fields are stored in plain metadata so that you can access them via standard WordPress functionality. The frontend is written in React.js and has no dependencies in PHP. The library also doesn't include React itself but uses react as a dependency from WordPress. Therefore, the library is small and fast but requires at least WordPress 5.3.

Overview

At the moment, you can add custom fields to the following locations:

The custom fields themselves use the standard HTML inputs, so it's recommended to use Google Chrome or Firefox to use the custom fields. This allows having a small footprint and a speedy frontend for the custom fields. You have available wide variety of custom field types:

Some fields also allow multiple values. You can also sort the values via drag&drop.

Advanced usage:

Requirements

Development requirements

If you want to help with the development of the library, feel free to extend that. In addition to the requirements above, you will need also:

Example: Hello custom fields

The following example shows you how to add custom fields to a page and read the data.

  1. Require the library in your plugin via composer: composer require wpify/custom-fields

  2. Include composer autoloader in your plugin: include_once __DIR__ . '/vendor/autoload.php';

  3. Create a new metabox with some text field:

That's it :)

Implementations

How to add custom fields to post type?

The example above shows the minimalistic example of how to add a metabox. Let's extend that with full list of options. In snippet above, you can see all the options with their default values:

Arguments

Please keep in mind that to have custom fields in the post type. For custom post type, add custom-fields in supports array in register_post_type function, or use add_post_type_support function to add support to some existing post type.

Reading the custom fields

To read the data, you can use simply built-in functions:

Links

How to add custom fields to the taxonomy term?

The functionality adds the meta box both on add and edit screen of taxonomy term:

Arguments

Reading the custom fields

To read the data, you can use simply built-in functions:

Links

How to create an options page with custom fields?

With this library, you can create options pages with ease on the top or second level. There are used core function add_menu_page or add_submenu_page under the hood.

Arguments

Reading the custom fields

Links

How to add custom fields to WooCommerce settings?

If you want to easily add the settings tab or section to the WooCommerce → Settings, you can easily do that with the following piece of code:

Arguments

Reading the settings fields

The WooCommerce settings is stores as standard options and you can read it as follows:

Links

How to add custom fields to the product options?

Product options is a great place where to put the custom fields. You can define it as follows:

Arguments

Reading the custom fields

The product options are stored as post meta, so you can read the data the same way as any other post meta:

Links

How to add custom fields to WooCommerce order with HPOS enabled?

Use Order metabox to add metaboxes to WooCommerce Orders with HPOS enabled. You can define it as follows

Arguments See create_metabox arguments.

Reading the custom fields

The order meta is stored using the standard WooCommerce CRUD functions, so you can read the data the same way as any other order meta:

Links

How to add custom fields to the product variations?

You can add custom fields to product variations as well. You can define it as follows:

Arguments

Reading the custom fields

The product options are stored as post meta, so you can read the data the same way as any other post meta:

Links

How to add custom fields to the membership plan options?

WooCommerce Membership plan options works similarly to product options. You can define it as follows:

Arguments

Reading the custom fields

The membership plan options are stored as post meta, so you can read the data the same way as any other post meta:

Links

How to generate Gutenberg block with custom fields?

You can easily generate blocks that will use the custom fields interface. if you want to replace default custom fields interface with your own, simply set the editor_script and editor_style attributes with handle of your registered script and style. Every registered block also have wcf attribute, that contains the definition of the custom fields used in the block.

Arguments

Move attributes to sidebar

If you want to move the particular attribute of the block to the sidebar, add an option to item 'position' => 'inspector'.

Links

Example

How to add custom fields to the user?

The functionality adds options to the user:

Arguments

Reading the custom fields

To read the data, you can use simply built-in functions:

Links

How to add custom fields to comments?

You can also easily add custom fields to comments:

Arguments

See post metabox for available arguments.

Reading the custom fields

To read the data, you can use simply built-in functions:

Links

Custom fields definition

In examples above, only one custom field were shown. But you can define more than just text fields. There are many field types to use. All the fields has some the following attributes in common:

Common attributes

Attachment field type attachment, multi_attachment

Additional attributes

Checkbox field type checkbox

Additional attributes

Code editor field type code

Additional attributes

Color field type color

Date field type date

Date and time field type datetime

E-mail field type email

Group field type group, multi_group

Singular groups group

Group field doesn't have any visual representation, but groups fields into one field. Here is an example of defining the group field in options page:

The result is following:

;

We can now set some values and access the data:

The code above will generate following array:

The groups can also be nested to get much more complicated data structures than in the example above.

Repeated groups multi_group

If we change the field type in example above to multi_group, we'll get a different result:

The value in the custom field will be as follows:

As you can see, you can add a new group with any fields inside it, move the group by drag&drop, and delete group items.

Additional attributes

HTML field type html

Additional attributes

Inner Blocks field type inner_blocks

Inner Blocks are limited in usage, please follow:

Additional attributes

Link field type link

Field that returns an array array( 'url' => '', 'label' => '', 'target' => null, 'post' => null )

Additional attributes

Mapy.cz field type mapycz

Shows the search box for location and map, where the user can set some location. The output is an object with the following shape:

Month field type month

Number field type number

Password field type password

Post field type post, multi_post

Allows selecting posts from a particular post type.

Additional attributes

Select field type select, multi_select

The select field can accept options asynchronously from API (recommended) or inline from option attribute. Each option must be an associative array with label and value keys.

Additional attributes

Example

Phone number field type tel

Additional attributes

Textarea field type textarea

Text field type text

Time field type time

Title field type title

Toggle field type toggle

Additional attributes

URL field type url

Week field type week

WYSIWYG fields type wysiwyg

This field gives you the TinyMCE editor, that enables you edit the HTML visualy!

Additional attributes

Extending the field types

You can extend the custom field types with your own:

  1. Create a React component with the field:

  2. Register the field:

  3. Register the parser and sanitizer (if needed)

See the code in src/Parser.php and src/Sanitizer.php for filters.

Bedrock support

If you use Bedrock, the custom fields by default won't work, because the vendor folder is outside of the docroot and assets needed for WCF are in the vendor folder. The solution to this is move the WCF to the document root. To enable that, require "mnsami/composer-custom-directory-installer" that enables installation particular packages to another location:

composer require mnsami/composer-custom-directory-installer

After that, you can specify location in your composer.json

Run composer update and WCF is installed in web/app/vendor/wpify/custom-fields folder. You can then inicialize WCF as follows:

Advanced usage - conditional custom fields

You can customize custom fields based on data. Let's say when the user selects the white colour, you want to show background color field. That's possible thanks to filters on frontend, you can define the following in your javascript:

This approach has some caveats:

You can also use the filter wcf_field_props, that allows you modify e.g. classnames of the field.

The code above will add test-class to the field with ID test_field in options page with slug some-test-menu-slug.

Advanced usage - custom getters and setters

If you want to retrieve or save the field value from/to a non-default location, you can easily override the getter and setter with callback_get and callback_set arguments.

Arguments

The following example demonstrates saving and retrieving post meta field with get_option and update_option functions.


All versions of custom-fields with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.33
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wpify/custom-fields contains the following files

Loading the files please wait ....