Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const form = {
},
'scheduled_date',
'password',
'sticky',
],
},
'date',
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/dataviews/store/private-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
scheduledDateField,
formatField,
postContentInfoField,
stickyField,
} from '@wordpress/fields';
import {
altTextField,
Expand Down Expand Up @@ -285,6 +286,7 @@ export const registerPostTypeSchema =
postTypeConfig.supports?.editor &&
postContentInfoField,
passwordField,
postTypeConfig.slug === 'post' && stickyField,
postTypeConfig.supports?.editor &&
postTypeConfig.viewable &&
postPreviewField,
Expand Down
4 changes: 4 additions & 0 deletions packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ Slug field for BasePost.

Status field for BasePost.

### stickyField

Sticky field for BasePost.

### templateField

Template field for BasePost.
Expand Down
1 change: 1 addition & 0 deletions packages/fields/src/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export { default as notesField } from './notes';
export { default as excerptField } from './excerpt';
export { default as formatField } from './format';
export { default as postContentInfoField } from './post-content-info';
export { default as stickyField } from './sticky';
26 changes: 26 additions & 0 deletions packages/fields/src/fields/sticky/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* WordPress dependencies
*/
import type { Field } from '@wordpress/dataviews';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import type { BasePost } from '../../types';

const stickyField: Field< BasePost > = {
id: 'sticky',
type: 'boolean',
label: __( 'Sticky' ),
description: __( 'Pin this post to the top of the blog.' ),
enableSorting: false,
enableHiding: false,
isVisible: ( item ) => !! item._links?.[ 'wp:action-sticky' ],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is interesting. Once the config is moved to the server, we can remove this isVisible check and just check the actual user permission to decide whether to include the field or not in the endpoint.

filterBy: false,
};

/**
* Sticky field for BasePost.
*/
export default stickyField;
1 change: 1 addition & 0 deletions packages/fields/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface BasePost extends CommonPost {
ping_status?: 'open' | 'closed';
link?: string;
slug?: string;
sticky?: boolean;
permalink_template?: string;
date?: string;
modified?: string;
Expand Down
Loading