{"id":657,"date":"2025-05-23T15:26:28","date_gmt":"2025-05-23T19:26:28","guid":{"rendered":"https:\/\/harmonicdesign.ca\/?p=657"},"modified":"2025-05-23T15:26:29","modified_gmt":"2025-05-23T19:26:29","slug":"hdfields-documentation","status":"publish","type":"post","link":"https:\/\/harmonicdesign.ca\/hdfields-documentation\/","title":{"rendered":"HDFields Documentation"},"content":{"rendered":"\n<p>HDFields is a WordPress settings and form management system that forces clean and intuitive design, while maintaining strict adherence to WordPress core standards and security.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a Settings form with HDFields<\/h2>\n\n\n\n<p>The best way to create a settings page or form with HDFields is to start by creating a new class. If you are creating a settings page, then something like <code>_hd_settings<\/code> would be a good class name, replacing <code>hd<\/code> with a relevant prefix for your project.<\/p>\n\n\n\n<p>Inside the constructor <code>__construct<\/code>, I like to call a method <code>fields<\/code> that returns and sets a public array of the form fields and their structure. I usually write the form fields in JSON format, then parse as an array for easier writing.<\/p>\n\n\n\n<p>The form can then be displayed with a <code>display<\/code> method, inside of which checks for user permissions, enqueues the needed styles and scripts for HDFields (<code>hdfields\/style.css<\/code> and <code>hdfields\/script.js<\/code>), and then finally calls the HDFields <code>display<\/code> method.<\/p>\n\n\n\n<p>Example code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$fields = new _hd_fields($fields, $savedData);\necho $fields->display();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Saving Data<\/h2>\n\n\n\n<p>To save data, start by passing the fields and data to the <code>_hd_fields<\/code> class. You can then run the <code>get_values<\/code> method (passing <code>false<\/code> as a parameter) to get clean, sanitized data back and ready to save however you need (such as <code>update_meta<\/code>, or <code>update_option<\/code>). It is also a good idea to check for user permissions before saving any data.<\/p>\n\n\n\n<p>Example code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$data = new _hd_fields($fields, $dataToSave);\n$data = $data->get_values(false);\nupdate_option(\"hdq_settings\", $data);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>HDFields is a WordPress settings and form management system that forces clean and intuitive design, while maintaining strict adherence to WordPress core standards and security. Creating a Settings form with HDFields The best way to create a settings page or form with HDFields is to start by creating a new class. If you are creating [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-657","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/posts\/657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/comments?post=657"}],"version-history":[{"count":10,"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/posts\/657\/revisions"}],"predecessor-version":[{"id":667,"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/posts\/657\/revisions\/667"}],"wp:attachment":[{"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/media?parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/categories?post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/harmonicdesign.ca\/hdapi\/wp\/v2\/tags?post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}