{"id":19389080,"url":"https://github.com/interconnectit/required-fields","last_synced_at":"2026-05-16T10:32:58.099Z","repository":{"id":5523144,"uuid":"6724911","full_name":"interconnectit/required-fields","owner":"interconnectit","description":"Adds an extensible API and some basic settings to WordPress to make standard fields on the post edit screen required before a post can be published.","archived":false,"fork":false,"pushed_at":"2015-09-10T14:25:26.000Z","size":863,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-03T20:22:13.397Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/interconnectit.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}},"created_at":"2012-11-16T17:04:20.000Z","updated_at":"2021-01-19T10:48:19.000Z","dependencies_parsed_at":"2022-09-03T06:00:31.474Z","dependency_job_id":null,"html_url":"https://github.com/interconnectit/required-fields","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/interconnectit/required-fields","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interconnectit%2Frequired-fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interconnectit%2Frequired-fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interconnectit%2Frequired-fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interconnectit%2Frequired-fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/interconnectit","download_url":"https://codeload.github.com/interconnectit/required-fields/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interconnectit%2Frequired-fields/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33098798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-10T10:15:17.602Z","updated_at":"2026-05-16T10:32:58.074Z","avatar_url":"https://github.com/interconnectit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"ICIT Required Fields\n===============\n\nAdds an extensible API and some basic settings to WordPress to make standard fields on the post edit screen required before a post can be published.\n\n## Usage\n\nHead to the **Writing** settings page and scroll to the bottom. There you will find boxes to check to make certain fields required when a user adds or edits a post or page.\n\nThe default options are:\n\n* require title\n* require content\n* require custom excerpt\n* require non default category\n* require tags\n* require featured image\n* minimum size for featured images\n\n![alt text](http://interconnectit.com/cc-assets/required-fields/screenshot-1.png \"Admin screenshot\")\n\nWhen you add or edit a post and it doesn't meet the requirements the relevant fields will be highlighted.\n\n![alt text](http://interconnectit.com/cc-assets/required-fields/screenshot-2.png \"Post edit screenshot\")\n\n### NEW\n\nAs of version 1.6.0 you can choose to make the required fields into warnings. The validation message will serve to nag the users however they won't prevent a post from being published.\n\n## API\n\nThere is an API to add/remove your own required fields too:\n\n**`register_required_field( name, message [, callback [, post types [, highlight [, soft ] ] ] ] )`**\n\n```php\n/**\n * Registers a field as required for a post to be published.\n * The default callback checks if the value of the post data or\n * post meta field corresponding to the $name is empty or not.\n *\n * Use on admin_init or any hook after plugins_loaded\n *\n * @param string \t\t\t$name          \tThe post data array key or custom field key eg: 'post_title', 'my_meta_key'\n * @param string \t\t\t$message       \tThe error message to display if validation fails\n * @param bool|callback \t$validation_cb \tA callback that returns true if the field value is ok. If false defaults to a\n * \t\t\t\t\t\t\t\t\t\t\tnot empty test. Takes 2 args, $value and $postarr\n * @param string|array \t\t$post_type     \tThe post type or post types to run the validation on\n * @param string \t\t\t$highlight \t\tCSS selector to highlight on validation fail eg. '#titlediv'\n * @param bool \t\t\t\t$soft \t\t\tIf true displays the validation as a warning. Failure does not block publishing\n * @return void\n */\n\nregister_required_field( $name, $message, $validation_cb, $post_types, $highlight, $soft );\n```\n\nThe entire `$_POST` array is available as the second argument to your validation functions so you have\naccess to everything you would ever need.\n\nA custom callback example:\n\n```php\nregister_required_field(\n\t'twitter',\n\t'Please enter a twitter username for the site before publishing',\n\tfunction( $value, $postarr ) {\n\n\t\t$site_twitter = get_option( 'site_twitter' );\n\t\tif ( $site_twitter )\n\t\t\treturn true;\n\n\t\t// do not publish if there's no twitter account set\n\t\treturn false;\n\t},\n\tarray( 'post', 'custom_post_type' )\n);\n```\n\nThe `$postarr` argument array gives you access to the taxonomy data being posted as well as many other\nuseful values. Use the network panel in your browser console to examine what `$_POST` data is available.\n\n**`unregister_required_field( name, message [, post types ] )`**\n\n```php\n/**\n * Unregisters a field validation. Should be used on admin_init\n *\n * @param string \t\t\t\t$name          \tThe post data array key or custom field key eg: 'post_title', 'my_meta_key'\n * @param bool|callback|string \t$validation_cb \tThe callback to remove. If false removes the default not empty check. If 'all' removes all validations for $name\n * @param string|array \t\t\t$post_type     \tThe post type or post types to remove the validation from\n * @return void\n */\n\nunregister_required_field( $name, $validation_cb, $post_types );\n```\n\n### Multiple validations\n\nYou can call `register_required_field()` against the same `$name` as many times as you want. They are non\ndestructive so will have a cumulative effect. You can unregister existing validations too.\n\n```php\nregister_required_field( 'post_title', 'Title must be filled in' );\nregister_required_field( 'post_title', 'Title must contain a number', 'check_for_number' );\nregister_required_field( 'post_title', 'Title must be at least 2 words', 'check_word_count' );\n```\n\n### Adding options to settings screen\n\nThere are plenty of hooks available to modify the behaviour of this plugin. One such hook allows you to\nextend the writing settings available to administrators in the settings.\n\nThe following is an example of adding an option to require a page template to be set for pages.\n\n```php\nadd_filter( 'required_fields_settings', 'my_required_fields_settings' );\n\nfunction my_required_fields_settings( $fields ) {\n\n\t$fields[ 'my_page_setting' ] = array(\n\t\t'title' =\u003e __( 'Template' ), \t\t\t\t\t\t\t\t\t\t// The setting field label\n\t\t'setting_cb' =\u003e 'intval', \t\t\t\t\t\t\t\t\t\t\t// The setting field validation (see register_setting())\n\t\t'setting_field' =\u003e array( 'required_fields', 'checkbox_field' ), \t// A built in checkbox field\n\t\t'setting_description' =\u003e '',\n\t\t'name' =\u003e 'page_template',\t\t\t\t\t\t\t\t\t\t\t// The $_POST field to check\n\t\t'message' =\u003e __( 'You should select a page template before publishing.' ),\n\t\t'validation_cb' =\u003e 'has_page_template', \t\t\t\t\t\t\t// custom validation callback\n\t\t'post_type' =\u003e 'page'\t\t\t\t\t\t\t\t\t\t\t\t// post type for validation\n\t\t'highlight' =\u003e '#page_template' \t\t\t\t\t\t\t\t\t// CSS selector to highlight on fail\n\t);\n\n\treturn $fields;\n}\n\n// check $value is not empty and not set to 'default'\nfunction has_page_template( $value, $postarr ) {\n\treturn ! empty( $value ) \u0026\u0026 $value !== 'default';\n}\n```\n\n### Highlighting fields with an error\n\nIn the above example you should note that the `highlight` option contains a CSS selector targeting the error\nfield.\n\nIf you do this the plugin will highlight the field or section that matches the selectors. Clicking on the\nerror message will scroll the page to the field that has an error and shake it to make it clear what needs\nto be actioned.\n\n### Limiting the length of titles and content\n\nYou can limit the minimum and maximum number of characters in the titles and content of your posts and pages by copying\nthe following code into the functions.php file of your theme, and changing the numbers and operators to match your needs.\n\n```php\nif ( function_exists( 'register_required_field' ) ) {\n\nfunction check_title_length( $value, $postarr ) {\n   return strlen( $value ) \u003e= 20;\n}\n\nfunction check_content_length( $value, $postarr ) {\n   return strlen( strip_tags( $value ) ) \u003e= 200;\n}\n\nregister_required_field( 'post_title', 'The title must be at least 20 characters long', 'check_title_length', array( 'post' ), '#titlediv' );\nregister_required_field( 'post_content', 'Your content must be at least 200 characters long', 'check_content_length', array( 'post' ), '#postdivrich' );\n}\n```\n\n### Make connections required with Posts 2 Posts plugin\n\nYou can make connections required using the plugin API, you can add the following code to your themes functions.php where\nyou register your posts type connections\n\n```php\nregister_required_field(\n    'p2p_connections',\n    'Connections are required before publishing', \n    false, \n    array( 'post' ), \n    '#p2p-from-posts_to_pages' \n);\n```\n\n## Thanks!\n\nAny questions or problem give me a shout on Twitter [@sanchothefat](https://twitter.com/sanchothefat)\n\n## License\n\nGPL v3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterconnectit%2Frequired-fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finterconnectit%2Frequired-fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterconnectit%2Frequired-fields/lists"}