question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Fields for Posts

See original GitHub issue

Within the top 15 requested features on the Ghost Feature Wishlist, this feature has been waiting for some love since 2015.

I volunteer to help out with this feature’s development.

Brief Overview

Ghost is one of the most customizable publishing platform for the general public out there, and sports most of the major benefits of all its competitors. However, every now and then comes a blogger with a vision for a design, and that vision requires complete customization of the fields on the core model objects. Think, featured image subtitle, featured link as replacement for image_ (video content, tweet, facebook embed, soundcloud), and even more. With the advent of apps, this feature will most likely gain further support as the custom fields will be readily accessible just like any other fields on the core model objects. It is most likely that apps will seek to alter the content and/or the structure of the database, and to allow such behaviour will result in a maintenance mess. Hence it is important to allow such customization now with proper separation of concerns so that later features can use its power at the fullest.

Feature Details

Custom Fields Themselves

  • Custom Fields should be implemented as fields that are available across all objects of a model, with each instance/row having its own value for the said property.
  • Each core model affected should have its own set of custom fields defined by the user, without commonality with each other.
  • Custom Fields should be easily accessible from the block helpers used in the hbs templates
  • Custom Fields should be easily usable by non-technical personnel so that the widest audience possible be able to use them.

Core Models Affected

Iteration 1

  • Post

Iteration 2

  • User (gender, sexual orientation, age, behance/deviantart/instagram/some social media, etc can be seen as potential use cases)

Other Models

I do not foresee the need for any extra custom fields on other models at the moment. If anybody has a very good use case, I’ll update this section accordingly.

Proposed UI Workflow

I am no designer, but here is what I came up with.

  1. Custom Fields are to be accessible from the General Settings (general.hbs) view

custom fields settings closed

  1. Custom Fields are to be added/removed dynamically and easily. Type of the field (Number, Text, Boolean) can be specified for later retrieval and parsing by the model

custom fields settings expanded

  1. Each post has access to the Custom Field menu through its Settings menu

new story custom fields nav

  1. Each post has its own value for the Custom Fields that can be specified in their Custom Field menu

new story custom fields menu

Scope of the changes

After my preliminary analysis of the codebase yesterday, here is what I gathered:

Ghost

  • core/server/models/custom-field is to be created as a table representing the custom-fields for each other linked table (see below)
  • core/server/models/custom-field-value is to be created as a table representing the values associated to each core model object which has the said custom fields (see below)
  • core/server/models/post and core/server/models/user are to be modified to allow read, mutation, deletion of custom fields.
  • core/server/helpers/post_class and core/server/helpers/author are to be potentially modified to include the custom field helper
  • core/server/helpers/custom helper has to be created to allow users to template using the custom block helper and output helper
  • core/server/api/* API endpoints have to be modified accordingly to support modification of the custom field and custom field value models. It is undetermined at the moment whether this should be done through the posts and users endpoints or through the settings endpoint.

Quick DB Class Diagram

Class Diagram

Ghost-Admin

General Settings Page

  • app/controllers/general Unclear whether modifications should be done on this file. It does play a significant role however in contacting the server to update the settings under the General page (general.hbs)
  • app/templates/settings/general.hbs Modify the layout to include the new custom field settings. Will require the creation of a new component for the layout shown in the second mockup.
  • app/models/setting Include a new field to validate on the model. Will require the creation of a new ember-data Transform in order to support and validate the custom field.

Editor Page

  • app/mixins/editor-base-controller May need modification to allow mutation and save of the custom fields
  • app/components/gh-posts-settings-menu Modify to include the design seen in screens 3 and 4. May require the creation of an extra components for dynamically generating the list of custom fields on screen 4.
  • app/models/post Include a new field to validate on the model. Will require the creation of a new ember-data Transform in order to support and validate the custom field values.

Expected Time Investment

Activity Estimate Conservative Estimate
Supplementary Analysis 3h 6h
Implementation (Ghost) 10h 20h
Testing (Ghost) 10h 20h
Implementation (Ghost Admin) 10h 20h
Testing (Ghost Admin) 4h 8h
TOTAL 37h 74h

This is undoubtedly a large epic, and would benefit from being undertaken by multiple individuals / be broken down in smaller user stories.

Drawbacks

  • Potential bottleneck on the CustomField / CustomFIeldValue table if accesses are done often. With proper caching practice should not be problematic however.
  • Requires changes to large portion of the Ghost/Ghost-Admin software
  • Increases maintenance debt by increasing the codebase
  • Feature may not be necessary for a large portion of the target market but nevertheless eases a significant portion of the user base and facilitates future symbiosis of apps

Alternatives

  • Custom install on self-hosted version
  • Front-end with external database
  • Apps with ability to modify existing database structure (and potentially requiring reboot for each new modification)

It is an understatement to say that this list of alternatives is unsatisfying. Friends, the future without custom fields is dire 😱

Let us not allow ourselves to follow such a dark path.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:73
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

44reactions
etxcommented, Jan 15, 2018

Lack of custom fields drove me away from ghost unfortunately. I know it’s definitely not a simple undertaking.

27reactions
philippefutureboycommented, Sep 18, 2017

I can understand your point. I send you love. I suggest we wait and see what others think. On my side I am truly confident that this feature will make some people smile 😄 👽 🔮

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Fields – WordPress.org Forums
WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as metadata....
Read more >
How to Add Custom Fields to Your WordPress Posts
Custom fields are a somewhat more advanced WordPress feature that lets you add extra information to specific posts. That information is called ' ......
Read more >
Adding fields to Posts - ACF
The Advanced Custom Fields plugin makes it very easy to add custom fields to a Post, please follow the steps below. From the...
Read more >
Beginner's Guide to Custom Fields in WordPress - ThemeIsle
With custom fields, you can create a place in the editor to add a specific type of information to each of your posts...
Read more >
How to Use Native Custom Fields in WordPress (and 5 Useful ...
Custom Fields in WordPress are arbitrary bits of data that you can apply to Posts, Pages, and Custom Post Types in WordPress.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found