{"id":15040445,"url":"https://github.com/automattic/custom-metadata","last_synced_at":"2025-04-09T12:06:02.787Z","repository":{"id":49176016,"uuid":"2309765","full_name":"Automattic/custom-metadata","owner":"Automattic","description":"A WordPress plugin that provides an easy way to add custom fields to your object types (post, pages, custom post types, users)","archived":false,"fork":false,"pushed_at":"2023-08-27T16:21:06.000Z","size":649,"stargazers_count":192,"open_issues_count":44,"forks_count":47,"subscribers_count":133,"default_branch":"main","last_synced_at":"2025-04-05T00:02:05.129Z","etag":null,"topics":["wordpress","wordpress-plugin","wpvip-plugin"],"latest_commit_sha":null,"homepage":"https://wordpress.org/plugins/custom-metadata/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Automattic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-09-01T19:16:47.000Z","updated_at":"2024-11-24T23:42:29.000Z","dependencies_parsed_at":"2024-10-01T02:40:58.488Z","dependency_job_id":"fbe1f6ec-8870-4bb3-b723-2aa21d82c6e9","html_url":"https://github.com/Automattic/custom-metadata","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automattic%2Fcustom-metadata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automattic%2Fcustom-metadata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automattic%2Fcustom-metadata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Automattic%2Fcustom-metadata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Automattic","download_url":"https://codeload.github.com/Automattic/custom-metadata/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress","wordpress-plugin","wpvip-plugin"],"created_at":"2024-09-24T20:44:37.520Z","updated_at":"2025-04-09T12:06:02.760Z","avatar_url":"https://github.com/Automattic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom Metadata Manager for WordPress\n\nThis code-only developer WordPress plugin allows you to add custom fields to your object types (post, pages, custom post types, users)\n\nThis is a WordPress Plugin. We sync changes between github and the [WordPress.org plugin repository](http://wordpress.org/extend/plugins/custom-metadata/). Why? Because collaboration is made much easier on github :)\n\n**NOTE**: The plugin requires WordPress 3.5+\n\n\n# Installation\n\n1. Install through the WordPress admin or upload the plugin folder to your `/wp-content/plugins/` directory\n2. Activate the plugin through the 'Plugins' menu in WordPress\n3. Add the necessary code to register your custom groups and fields to your functions.php or plugin.\n4. Enjoy!\n\n# Frequently Asked Questions\n\n\n## Why a code-based approach instead of a UI?\n\nBecause the UI thing has [been](http://wordpress.org/extend/plugins/verve-meta-boxes/) [done](http://wordpress.org/extend/plugins/fresh-page/) [before](http://wordpress.org/extend/plugins/pods/). And this more closely aligns with the existing WordPress approach of registering new types of content (post types, taxonomies, etc.)\n\nThis is also a developer feature, aimed towards site builders. And real developers don't need UIs ;)\n\n(But really, though, the main benefit of this fact comes into play when you're working with multiple environments, i.e. development/local, qa/staging, production. This approach makes it easy to replicate UIs and features without having to worry about database synchronization and other crazy things.)\n\nFor another really well-done, really powerful code-based plugin for managing custom fields, check out [Easy Custom Fields](http://wordpress.org/extend/plugins/easy-custom-fields/) and the [Custom Metaboxes and Fields For WordPress Class](https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress).\n\n\n## Why isn't the function just `add_metadata_field`? Do you really need the stupid `x_`?\n\nWe're being good and [\"namespacing\" our public functions](http://andrewnacin.com/2010/05/11/in-wordpress-prefix-everything/). You should too.\n\n\n## How do I use this plugin?\n\nThere are usage instructions below\n\n# Changelog\n\n## 0.8 (currently under development)\n\n* added ability to group several fields as a `multifield`; see `x_add_metadata_multifield()`, props @greatislander, @rinatkhaziev and @PhilippSchreiber for their contributions there\n* allow field types that save as multiples but don't display as cloneable or multiples\n* added the `taxonomy_checkbox` and `taxonomy_multi_select` field types, props @greatislander\n* made use of the `selected()` and `checked()` functions in WordPress instead of clumsy if statements\n* limit or exclude groups and fields using a custom callback\n* adjusted the copyright to include 2013 and to list \"The Contributors\" instead of specific individuals\n* adjusted the list of contributors in the plugin\n* adjusted the plugin URL and removed the donate URL\n* adjusted files for code standards\n* fixed PHP warning with empty values for date fields\n* moved filtering of instance vars to `init` instead of on `construct` which runs too early\n* added new field types: `number`, `email`, `telephone`, `datetimepicker`, `timepicker` and `link` (which uses the WP link manager)\n* added ability to add default value for certain field types\n* added ability to set placeholder for certain fields\n* updated the examples file\n* rewrote the `upload` field to use the media manager from WordPress 3.5+. Note the `upload` field is now `readonly` by default (but can be set to `false` when you setup the field)\n* updated JavaScript to be up to standard with coding standards and be fully compatible with jQuery 1.9+\n* replaced chosen.js with select2.js\n* reformat and clean up css file\n* added ability for groups to display a description\n* added ability to limit capabilities for entire groups using `required_cap`\n* convert plugin class to singleton\n\n## 0.7\n\n* added the ability to have readonly fields with the new `readonly` paramater\n\n## 0.6\n\n* note: the plugin now requires WordPress 3.3+ (chiefly for the wysiwyg \u0026 datepicker fields)\n* update/clean-up the examples file\n* properly enqueue admin css for WP 3.3+\n* added a filter for the `CUSTOM_METADATA_MANAGER_URL` constant\n* fix fields not appearing when editing users in WP 3.3+ (props @FolioVision)\n* now passing the `$value` for a `display_callback` (props @FolioVision)\n* use the new `wp_editor()` function (since WP 3.3+) instead of `the_editor()` (now deprecated)\n* wysiwyg fields are no longer cloneable (may be revisited in a future version)\n* note: metaboxes that have a wysiwyg field will break when moved, this is not a bug per-se (may be revisited in a future version)\n* password fields are now cloneable\n* added filters for most of the plugin's internal variables\n* now using WordPress' built-in jQuery UI for the datepicker field\n* updated the screenshots\n* updated the instructions in readme.txt\n\n## 0.5.7\n\n* pass additional params for `display_callback`\n\n## 0.5.6\n\n* fix bugs with datepicker\n\n## 0.5.5\n\n* remove all whitespace\n* fix some bugs with the tinymce field\n\n## 0.5.4\n\n* fix display_callback for fields\n\n## 0.5.3\n\n* removed php opening shorttags `\u003c?` in favor of regular `\u003c?php` tags, which caused parse errors on some servers\n\n## 0.5.2\n\n* better tiny mce implementation and added html/visual switch\n* small css fixes and added inline documentation\n* moved `DEFINE`s in to `admin_init` so that they can be filtered more easily\n\n## 0.5.1\n\n* Bug fix with group context on add meta box\n* Remove few lines of old code left-over from 0.4\n\n## 0.5\n\n* Making the changes from 0.4 public\n* Removed ability to generate option pages; after further consideration this is out of scope for this project\n* Removed attachment_list field, useless\n* Dates now save as unix timestamp\n* Taxonomy fields now save as both a custom field and as their proper taxonomy (will consider adding the ability to enable/disable this in a future version)\n* Multiplied fields no longer save as a serialized array, instead they save as multiple metadata with the same key (metadata api supports multiples!) - remember to set the last param to false to get multiple values.\n* NOTE: currently multiplied fields will display out of order after saving, however this should not affect anything else other than the admin, should be fixed soon\n* Other small improvements\n\n## 0.4\n\n* Enhanced the code which generates the different field types\n* Added new types: `password`, `upload`, `wysiwyg`, `datepicker`, `taxonomy_select`, `taxonomy_radio`, `attachment_list`\n* Added field multiplication ability\n* Metadata is now deleted if a value is empty\n* Can now also generate option pages which use a metabox interface\n\n## 0.3\n\n* Can now limit or exclude fields or groups from specific ids\n* Added updated screenshots and new code samples!\n* Bug fix: the custom display examples weren't working well\n* Bug fix: fields not showing on \"Add New\" page. Thanks Jan Fabry!\n* Bug fix: fields not showing on \"My Profile\" page. Thanks Mike Tew!\n\n## 0.2\n\n* Added a textarea field type\n* Added support for comments (you can now specify comments as an object type)\n* Added basic styling for fields so that they look nice\n\n## 0.1\n\n* Initial release\n\n# Usage\n\n### Object Types\n\nThe main idea behind this plugin is to have a single API to work with regardless of the object type. Currently, Custom Metadata Manager works with `user`, `comment` and any built-in or custom post types, e.g. `post`, `page`, etc.\n\n### Registering your fields\n\nFor the sake of performance (and to avoid potential race conditions), always register your custom fields in the `custom_metadata_manager_admin_init` hook. This way your front-end doesn't get bogged down with unnecessary processing and you can be sure that your fields will be registered safely. Here's a code sample:\n\n```php\nadd_action( 'custom_metadata_manager_init_metadata', 'my_theme_init_custom_fields' );\n\nfunction my_theme_init_custom_fields() {\n\tx_add_metadata_field( 'my_field', array( 'user', 'post' ) );\n}\n```\n\n### Getting the data\n\nYou can get the data as you normally would using the `get_metadata` function. Custom Metadata manager stores all data using the WordPress metadata APIs using the slug name you provide. That way, even if you decide to deactivate this wonderful plugin, your data is safe and accessible. For options, you can use `get_option`.\n\nExample:\n\n```php\n$value = get_metadata( 'post', get_the_ID(), 'featured', true ); // Returns post metadata value for the field 'featured'\n```\n\n### Adding Metadata Groups\n\nA group is essentially a metabox that groups together multiple fields. Register the group before any fields\n\n```php\nx_add_metadata_group( $slug, $object_types, $args );\n```\n\n\n#### Parameters\n\n* `$slug` (string) The key under which the metadata will be stored.\n* `$object_types` (string|array) The object types to which this field should be added. Supported: post, page, any custom post type, user, comment.\n\n\n#### Options and Overrides\n\n```php\n$args = array(\n\t'label' =\u003e $group_slug, // Label for the group\n\t'context' =\u003e 'normal', // (post only)\n\t'priority' =\u003e 'default', // (post only)\n\t'autosave' =\u003e false, // (post only) Should the group be saved in autosave? NOT IMPLEMENTED YET!\n\t'exclude' =\u003e '', // see below for details\n\t'include' =\u003e '', // see below for details\n);\n```\n\n### Adding Metadata Fields\n\n`x_add_metadata_field( $slug, $object_types, $args );`\n\n\n#### Parameters\n\n* `$slug` (string) The key under which the metadata will be stored. For post_types, prefix the slug with an underscore (e.g. `_hidden`) to hide it from the the Custom Fields box.\n* `$object_types` (string|array) The object types to which this field should be added. Supported: post, page, any custom post type, user, comment.\n\n\n####  Options and Overrides\n\n```php\n$args = array(\n\t'group' =\u003e '', // The slug of group the field should be added to. This needs to be registered with x_add_metadata_group first.\n\t'field_type' =\u003e 'text', // The type of field; 'text', 'textarea', 'password', 'checkbox', 'radio', 'select', 'upload', 'wysiwyg', 'datepicker', 'taxonomy_select', 'taxonomy_radio'\n\t'label' =\u003e '', // Label for the field\n\t'description' =\u003e '', // Description of the field, displayed below the input\n\t'values' =\u003e array(), // Values for select and radio buttons. Associative array\n\t'display_callback' =\u003e '', // Callback to custom render the field\n\t'sanitize_callback' =\u003e '', // Callback to sanitize data before it's saved\n\t'display_column' =\u003e false, // Add the field to the columns when viewing all posts\n\t'display_column_callback' =\u003e '', // Callback to render output for the custom column\n\t'required_cap' =\u003e '', // The cap required to view and edit the field\n\t'exclude' =\u003e '', // see below for details\n\t'include' =\u003e '', // see below for details\n\t'multiple' =\u003e false, // true or false, can the field be duplicated with a click of a button?\n\t'readonly' =\u003e false, // makes the field be readonly (works with text, textarea, password, upload and datepicker fields)\n);\n```\n\n####  Include / Exclude\n\nYou can exclude fields and groups from specific object. For example, with the following, field-1 will show up for all posts except post #123:\n\n```php\n$args = array(\n\t'exclude' =\u003e 123\n);\nx_add_metadata_field( 'field-1', 'post', $args );\n```\n\nAlternatively, you can limit (\"include\") fields and groups to specific objects. The following will ''only'' show group-1 to post #456:\n\n```php\n$args = array(\n\t'include' =\u003e 123\n);\nx_add_metadata_group( 'group-1', 'post', $args );\n```\n\nYou can pass in an array of IDs:\n\n```php\n$args = array(\n\t'include' =\u003e array( 123, 456, 789 );\n);\n```\n\nWith multiple object types, you can pass in an associative array:\n\n```php\n$args = array(\n\t'exclude' =\u003e array(\n\t\t'post' =\u003e 123,\n\t\t'user' =\u003e array( 123, 456, 789 )\n\t)\n);\n```\nYou can also pass in a callback to programattically include or exclude posts:\n\n```php\n$args = array(\n\t'exclude' =\u003e function( $thing_slug, $thing, $object_type, $object_id, $object_slug ) {\n\t\t// exclude from all posts that are in the aside category.\n\t\treturn in_category( 'aside', $object_id );\n\t}\n);\n```\n\n```php\n$args = array(\n\t'include' =\u003e function( $thing_slug, $thing, $object_type, $object_id, $object_slug ) {\n\t\t// include for posts that are not published.\n\t\t$post = get_post( $object_id );\n\t\treturn 'publish' != $post-\u003epost_status;\n\t}\n);\n```\n\n# Examples\n\nFor examples, please see the [custom_metadata_examples.php](https://github.com/jkudish/custom-metadata/blob/master/custom_metadata_examples.php) file included with the plugin. Add a constant to your wp-config.php called `CUSTOM_METADATA_MANAGER_DEBUG` with a value of `true` to see it in action:\n\n`define( 'CUSTOM_METADATA_MANAGER_DEBUG', true );`\n\n\n# License\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, write to:\n\nFree Software Foundation, Inc.\n51 Franklin Street, Fifth Floor,\nBoston, MA\n02110-1301, USA.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautomattic%2Fcustom-metadata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautomattic%2Fcustom-metadata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautomattic%2Fcustom-metadata/lists"}