An open API service indexing awesome lists of open source software.

https://github.com/arraypress/edd-register-fields

A comprehensive library for registering custom fields in Easy Digital Downloads admin interface.
https://github.com/arraypress/edd-register-fields

Last synced: 12 days ago
JSON representation

A comprehensive library for registering custom fields in Easy Digital Downloads admin interface.

Awesome Lists containing this project

README

          

# EDD Register Fields - Custom Field Registration for Easy Digital Downloads

Add custom fields to Easy Digital Downloads download editor, pricing options, and sidebar metaboxes with a simple, clean API.

## Installation

```bash
composer require arraypress/edd-register-fields
```

## Basic Usage

### Download Settings Fields

Add custom fields to the download settings tab:

```php
// Register custom download settings fields
edd_register_download_settings_fields( [
'product_settings' => [
'title' => 'Product Settings',
'description' => 'Additional product configuration options',
'fields' => [
'is_featured' => [
'type' => 'checkbox_toggle',
'label' => 'Featured Product',
'description' => 'Mark this product as featured',
'default' => false
],
'product_weight' => [
'type' => 'number',
'label' => 'Weight (for sorting)',
'description' => 'Higher numbers appear first',
'default' => 0,
'attributes' => [
'min' => 0,
'max' => 9999
]
]
]
]
] );
```

### Single Price Options

Add fields that appear when variable pricing is disabled:

```php
// Register single price option fields
edd_register_single_price_fields( [
'license_options' => [
'fields' => [
'site_limit' => [
'type' => 'number',
'label' => 'Site Limit',
'default' => 1,
'prefix' => 'Max:',
'suffix' => 'sites'
],
'includes_support' => [
'type' => 'checkbox_toggle',
'label' => 'Includes Support',
'default' => true
]
]
]
] );
```

### Variable Price Options

Add fields to each variable price row:

```php
// Register variable price fields
edd_register_variable_price_fields( [
'license_tiers' => [
'title' => 'License Options',
'fields' => [
'is_popular' => [
'type' => 'checkbox_toggle',
'label' => 'Popular',
'default' => false
],
'license_limit' => [
'type' => 'number',
'label' => 'Site Limit',
'default' => 1,
'attributes' => [
'min' => 1,
'max' => 999
]
]
]
]
] );
```

### Sidebar Metaboxes

Add custom metaboxes to the download editor sidebar:

```php
// Register sidebar metaboxes
edd_register_sidebar_metaboxes( [
'seo_settings' => [
'title' => 'SEO Settings',
'priority' => 'high',
'sections' => [
'meta_options' => [
'title' => 'Meta Options',
'fields' => [
'meta_title' => [
'type' => 'text',
'label' => 'Custom Meta Title',
'class' => 'widefat'
],
'exclude_sitemap' => [
'type' => 'checkbox_toggle',
'label' => 'Exclude from Sitemap',
'default' => false
]
]
]
]
]
] );
```

### Custom Sections

Register custom sections with configurable fields:

```php
// Register custom sections
edd_register_sections( [
'custom_section' => CustomSection::class
] );

// Example custom section class
class CustomSection extends ArrayPress\EDD\Fields\ConfigurableSection {

protected $id = 'custom_section';
protected $priority = 25;
protected $icon = 'admin-tools';

protected function get_section_config(): array {
return [
'title' => 'Custom Section',
'fields' => [
'custom_field' => [
'type' => 'text',
'label' => 'Custom Field',
'description' => 'A custom field example',
'default' => ''
]
]
];
}
}
```

## Field Types

| Type | Description | Example |
|------|-------------|---------|
| `text` | Text input | `'type' => 'text'` |
| `textarea` | Multi-line text | `'type' => 'textarea'` |
| `number` | Number input | `'type' => 'number'` |
| `email` | Email input | `'type' => 'email'` |
| `url` | URL input | `'type' => 'url'` |
| `select` | Dropdown select | `'type' => 'select'` |
| `checkbox` | Checkbox | `'type' => 'checkbox'` |
| `checkbox_toggle` | EDD toggle | `'type' => 'checkbox_toggle'` |
| `radio` | Radio buttons | `'type' => 'radio'` |
| `currency` | Currency input | `'type' => 'currency'` |
| `color` | Color picker | `'type' => 'color'` |

## Field Options

### Common Options

| Option | Description | Example |
|--------|-------------|---------|
| `type` | Field type | `'text'` |
| `label` | Field label | `'Product Name'` |
| `description` | Help text | `'Enter the product name'` |
| `default` | Default value | `'Default value'` |
| `required` | Required field | `true` |
| `class` | CSS classes | `'regular-text'` |
| `attributes` | HTML attributes | `['min' => 0, 'max' => 100]` |

### Select/Radio Options

```php
'product_type' => [
'type' => 'select',
'label' => 'Product Type',
'options' => [
'digital' => 'Digital Product',
'physical' => 'Physical Product',
'service' => 'Service'
],
'default' => 'digital'
]
```

### Number Fields

```php
'priority' => [
'type' => 'number',
'label' => 'Priority',
'default' => 0,
'attributes' => [
'min' => 0,
'max' => 100,
'step' => 5
]
]
```

## Requirements

- PHP 7.4+
- WordPress 5.0+
- Easy Digital Downloads 3.0+

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the GPL-2.0-or-later License.

## Support

- [Documentation](https://github.com/arraypress/edd-register-fields)
- [Issue Tracker](https://github.com/arraypress/edd-register-fields/issues)