Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Allow post field control labels to be defined in register_post_type() #195

Merged
merged 4 commits into from
Jul 5, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions js/customize-post-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,12 @@
*/
addTitleControl: function() {
var section = this, control, setting = api( section.id );
var postTypeObj = api.Posts.data.postTypes[ section.params.post_type ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgedeon minor thing, but in the cases where you define a new var postTypeObj in your patch, could you just add postTypeObj to the existing list of variables declared? We're generally having only one single var statement in our code I believe. So you could change this and other instances to:

var section = this, control, setting = api( section.id ), postTypeObj;
postTypeObj = api.Posts.data.postTypes[ section.params.post_type ];

control = new api.controlConstructor.dynamic( section.id + '[post_title]', {
params: {
section: section.id,
priority: 10,
label: api.Posts.data.l10n.fieldTitleLabel,
label: postTypeObj.labels.title_field ? postTypeObj.labels.title_field : api.Posts.data.l10n.fieldTitleLabel,
active: true,
settings: {
'default': setting.id
Expand Down Expand Up @@ -335,11 +336,12 @@
*/
addSlugControl: function() {
var section = this, control, setting = api( section.id );
var postTypeObj = api.Posts.data.postTypes[ section.params.post_type ];
control = new api.controlConstructor.dynamic( section.id + '[post_name]', {
params: {
section: section.id,
priority: 15,
label: api.Posts.data.l10n.fieldSlugLabel,
label: postTypeObj.labels.slug_field ? postTypeObj.labels.slug_field : api.Posts.data.l10n.fieldSlugLabel,
active: true,
settings: {
'default': setting.id
Expand Down Expand Up @@ -383,6 +385,7 @@
*/
addPostStatusControl: function() {
var section = this, control, setting = api( section.id ), sectionContainer, sectionTitle;
var postTypeObj = api.Posts.data.postTypes[ section.params.post_type ];

sectionContainer = section.container.closest( '.accordion-section' );
sectionTitle = sectionContainer.find( '.accordion-section-title:first' );
Expand All @@ -391,7 +394,7 @@
params: {
section: section.id,
priority: 20,
label: api.Posts.data.l10n.fieldPostStatusLabel,
label: postTypeObj.labels.status_field ? postTypeObj.labels.status_field : api.Posts.data.l10n.fieldPostStatusLabel,
active: true,
settings: {
'default': setting.id
Expand Down Expand Up @@ -477,12 +480,13 @@
dragbar = $( '#customize-posts-content-editor-dragbar' ),
collapse = $( '.collapse-sidebar' ),
resizeHeight;
var postTypeObj = api.Posts.data.postTypes[ section.params.post_type ];

control = new api.controlConstructor.dynamic( section.id + '[post_content]', {
params: {
section: section.id,
priority: 25,
label: api.Posts.data.l10n.fieldContentLabel,
label: postTypeObj.labels.content_field ? postTypeObj.labels.content_field : api.Posts.data.l10n.fieldContentLabel,
active: true,
settings: {
'default': setting.id
Expand Down Expand Up @@ -729,11 +733,12 @@
*/
addExcerptControl: function() {
var section = this, control, setting = api( section.id );
var postTypeObj = api.Posts.data.postTypes[ section.params.post_type ];
control = new api.controlConstructor.dynamic( section.id + '[post_excerpt]', {
params: {
section: section.id,
priority: 30,
label: api.Posts.data.l10n.fieldExcerptLabel,
label: postTypeObj.labels.excerpt_field ? postTypeObj.labels.excerpt_field : api.Posts.data.l10n.fieldExcerptLabel,
active: true,
settings: {
'default': setting.id
Expand Down Expand Up @@ -771,7 +776,7 @@
params: {
section: section.id,
priority: 60,
label: api.Posts.data.l10n.fieldDiscussionLabel,
label: postTypeObj.labels.discussion_field ? postTypeObj.labels.discussion_field : api.Posts.data.l10n.fieldDiscusionLabel,
active: true,
settings: {
'default': setting.id
Expand Down Expand Up @@ -803,11 +808,12 @@
*/
addAuthorControl: function() {
var section = this, control, setting = api( section.id );
var postTypeObj = api.Posts.data.postTypes[ section.params.post_type ];
control = new api.controlConstructor.dynamic( section.id + '[post_author]', {
params: {
section: section.id,
priority: 70,
label: api.Posts.data.l10n.fieldAuthorLabel,
label: postTypeObj.labels.author_field ? postTypeObj.labels.author_field : api.Posts.data.l10n.fieldAuthorLabel,
active: true,
settings: {
'default': setting.id
Expand Down